From 9a401b2a541746792f63c72428d07c0712698d14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Velarde?= Date: Wed, 1 Feb 2023 13:52:30 +0100 Subject: [PATCH] Provide unified CLIENT_ID for metrics --- CHANGELOG.md | 2 ++ packages/react-api/__tests__/api/tilejson.test.js | 3 ++- packages/react-api/src/api/SQL.js | 7 +++---- packages/react-api/src/api/common.js | 2 ++ packages/react-api/src/api/tilejson.js | 4 ++-- packages/react-api/src/hooks/useCartoLayerProps.js | 3 ++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f30e9fd6f..6fdbe0e19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/packages/react-api/__tests__/api/tilejson.test.js b/packages/react-api/__tests__/api/tilejson.test.js index eab743f4f..a9ba021a1 100644 --- a/packages/react-api/__tests__/api/tilejson.test.js +++ b/packages/react-api/__tests__/api/tilejson.test.js @@ -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(); @@ -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__', diff --git a/packages/react-api/src/api/SQL.js b/packages/react-api/src/api/SQL.js index 85aaf617e..524883e28 100644 --- a/packages/react-api/src/api/SQL.js +++ b/packages/react-api/src/api/SQL.js @@ -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}'; /** @@ -79,7 +78,7 @@ function createRequest({ const { apiVersion = API_VERSIONS.V2 } = credentials; const rawParams = { - client: CLIENT, + client: CLIENT_ID, q: query?.trim(), ...otherOptions }; @@ -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 = { diff --git a/packages/react-api/src/api/common.js b/packages/react-api/src/api/common.js index e3f581c13..f056251a6 100644 --- a/packages/react-api/src/api/common.js +++ b/packages/react-api/src/api/common.js @@ -60,3 +60,5 @@ export async function makeCall({ url, credentials, opts }) { return data; } + +export const CLIENT_ID = 'carto-for-react'; diff --git a/packages/react-api/src/api/tilejson.js b/packages/react-api/src/api/tilejson.js index d2d5027d6..766cb7da4 100644 --- a/packages/react-api/src/api/tilejson.js +++ b/packages/react-api/src/api/tilejson.js @@ -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/'; @@ -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'); diff --git a/packages/react-api/src/hooks/useCartoLayerProps.js b/packages/react-api/src/hooks/useCartoLayerProps.js index 39faa267e..de9326c46 100644 --- a/packages/react-api/src/hooks/useCartoLayerProps.js +++ b/packages/react-api/src/hooks/useCartoLayerProps.js @@ -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, @@ -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,