Skip to content

Commit

Permalink
Provide unified CLIENT_ID for metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorVelarde committed Feb 1, 2023
1 parent ecf7369 commit 9a401b2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Not released

- Provide unified CLIENT_ID for metrics [#591](https://github.com/CartoDB/carto-react/pull/591)

## 1.5

### 1.5.0 (2023-01-31)
Expand Down
3 changes: 2 additions & 1 deletion packages/react-api/__tests__/api/tilejson.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getTileJson } from '../../src/api/tilejson';
import { MAP_TYPES, API_VERSIONS } from '@deck.gl/carto';
import { CLIENT_ID } from '@carto/react-api/api/common';

const mockedFetchLayerData = jest.fn();

Expand Down Expand Up @@ -35,7 +36,7 @@ describe('tilejson', () => {
const tilejson = await getTileJson({ source });

expect(mockedFetchLayerData).toBeCalledWith({
clientId: 'carto-for-react',
clientId: CLIENT_ID,
connection: '__test_connection__',
credentials: {
accessToken: '__test_api_key__',
Expand Down
7 changes: 3 additions & 4 deletions packages/react-api/src/api/SQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import { encodeParameter, getRequest, postRequest } from '@carto/react-core';
import { REQUEST_GET_MAX_URL_LENGTH } from '@carto/react-core';
import { API_VERSIONS } from '@deck.gl/carto';

import { dealWithApiError } from './common';
import { dealWithApiError, CLIENT_ID } from './common';

const CLIENT = 'carto-react';
const DEFAULT_USER_COMPONENT_IN_URL = '{user}';

/**
Expand Down Expand Up @@ -79,7 +78,7 @@ function createRequest({
const { apiVersion = API_VERSIONS.V2 } = credentials;

const rawParams = {
client: CLIENT,
client: CLIENT_ID,
q: query?.trim(),
...otherOptions
};
Expand Down Expand Up @@ -117,7 +116,7 @@ function createRequest({
// Post request
const urlParamsForPost =
apiVersion === API_VERSIONS.V3
? [`access_token=${credentials.accessToken}`, `client=${CLIENT}`]
? [`access_token=${credentials.accessToken}`, `client=${CLIENT_ID}`]
: null;

const payload = {
Expand Down
2 changes: 2 additions & 0 deletions packages/react-api/src/api/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ export async function makeCall({ url, credentials, opts }) {

return data;
}

export const CLIENT_ID = 'carto-for-react';
4 changes: 2 additions & 2 deletions packages/react-api/src/api/tilejson.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { checkCredentials } from './common';
import { checkCredentials, CLIENT_ID } from './common';
import { MAP_TYPES, API_VERSIONS, fetchLayerData, FORMATS } from '@deck.gl/carto';
import { _assert as assert } from '@carto/react-core/';

Expand Down Expand Up @@ -30,7 +30,7 @@ export async function getTileJson(props) {
connection: source.connection,
credentials: source.credentials,
format: FORMATS.TILEJSON,
clientId: 'carto-for-react'
clientId: CLIENT_ID
});

assert(format === FORMATS.TILEJSON, 'getTileJson: data is not a tilejson');
Expand Down
3 changes: 2 additions & 1 deletion packages/react-api/src/hooks/useCartoLayerProps.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import useTileFeatures from './useTileFeatures';
import { getDataFilterExtensionProps } from './dataFilterExtensionUtil';
import { getMaskExtensionProps } from './maskExtensionUtil';
import FeaturesDroppedLoader from './FeaturesDroppedLoader';
import { CLIENT_ID } from '../api/common';

export default function useCartoLayerProps({
source,
Expand Down Expand Up @@ -77,7 +78,7 @@ export default function useCartoLayerProps({
type: source?.type,
connection: source?.connection,
credentials: source?.credentials,
clientId: 'carto-for-react',
clientId: CLIENT_ID,
queryParameters: source?.queryParameters,
...dataFilterExtensionProps,
...maskExtensionProps,
Expand Down

0 comments on commit 9a401b2

Please sign in to comment.