diff --git a/packages/algoliasearch/builds/browser.ts b/packages/algoliasearch/builds/browser.ts index 7b03ea409..0faf89df9 100644 --- a/packages/algoliasearch/builds/browser.ts +++ b/packages/algoliasearch/builds/browser.ts @@ -34,13 +34,15 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt throw new Error('`apiKey` is missing.'); } + const client = searchClient(appId, apiKey, options); + return { - ...searchClient(appId, apiKey, options), + ...client, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return client.transporter.algoliaAgent.value; }, initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => { return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options); diff --git a/packages/algoliasearch/builds/node.ts b/packages/algoliasearch/builds/node.ts index 7b03ea409..0faf89df9 100644 --- a/packages/algoliasearch/builds/node.ts +++ b/packages/algoliasearch/builds/node.ts @@ -34,13 +34,15 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt throw new Error('`apiKey` is missing.'); } + const client = searchClient(appId, apiKey, options); + return { - ...searchClient(appId, apiKey, options), + ...client, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return client.transporter.algoliaAgent.value; }, initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => { return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options); diff --git a/packages/algoliasearch/lite/src/liteClient.ts b/packages/algoliasearch/lite/src/liteClient.ts index 11a3bd9af..966e9ccae 100644 --- a/packages/algoliasearch/lite/src/liteClient.ts +++ b/packages/algoliasearch/lite/src/liteClient.ts @@ -68,26 +68,27 @@ export function createLiteClient({ ...options }: CreateClientOptions) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(appIdOption), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'Lite', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(appIdOption), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'Lite', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -98,16 +99,14 @@ export function createLiteClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -117,7 +116,7 @@ export function createLiteClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -128,9 +127,9 @@ export function createLiteClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, /** @@ -193,7 +192,7 @@ export function createLiteClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -240,7 +239,7 @@ export function createLiteClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -303,7 +302,7 @@ export function createLiteClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-abtesting/src/abtestingClient.ts b/packages/client-abtesting/src/abtestingClient.ts index f720b3b1e..519df2429 100644 --- a/packages/client-abtesting/src/abtestingClient.ts +++ b/packages/client-abtesting/src/abtestingClient.ts @@ -48,26 +48,27 @@ export function createAbtestingClient({ ...options }: CreateClientOptions & { region?: Region }) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(regionOption), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'Abtesting', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(regionOption), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'Abtesting', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -78,16 +79,14 @@ export function createAbtestingClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -97,7 +96,7 @@ export function createAbtestingClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -108,9 +107,9 @@ export function createAbtestingClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, @@ -150,7 +149,7 @@ export function createAbtestingClient({ data: addABTestsRequest, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -180,7 +179,7 @@ export function createAbtestingClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -207,7 +206,7 @@ export function createAbtestingClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -239,7 +238,7 @@ export function createAbtestingClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -271,7 +270,7 @@ export function createAbtestingClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -300,7 +299,7 @@ export function createAbtestingClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -329,7 +328,7 @@ export function createAbtestingClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -352,13 +351,14 @@ export function createAbtestingClient({ const requestPath = '/2/abtests'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (offset !== undefined) { queryParameters.offset = offset.toString(); } - if (limit !== undefined) { queryParameters.limit = limit.toString(); } + if (indexPrefix !== undefined) { queryParameters.indexPrefix = indexPrefix.toString(); } @@ -373,7 +373,7 @@ export function createAbtestingClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -418,7 +418,7 @@ export function createAbtestingClient({ data: scheduleABTestsRequest, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -447,7 +447,7 @@ export function createAbtestingClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-analytics/src/analyticsClient.ts b/packages/client-analytics/src/analyticsClient.ts index 7174e75b2..e9c2990f8 100644 --- a/packages/client-analytics/src/analyticsClient.ts +++ b/packages/client-analytics/src/analyticsClient.ts @@ -78,26 +78,27 @@ export function createAnalyticsClient({ ...options }: CreateClientOptions & { region?: Region }) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(regionOption), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'Analytics', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(regionOption), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'Analytics', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -108,16 +109,14 @@ export function createAnalyticsClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -127,7 +126,7 @@ export function createAnalyticsClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -138,9 +137,9 @@ export function createAnalyticsClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, @@ -171,7 +170,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -198,7 +197,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -230,7 +229,7 @@ export function createAnalyticsClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -262,7 +261,7 @@ export function createAnalyticsClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -296,7 +295,6 @@ export function createAnalyticsClient({ if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } - if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } @@ -311,7 +309,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -347,7 +345,6 @@ export function createAnalyticsClient({ if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } - if (tags !== undefined) { queryParameters.tags = tags.toString(); } @@ -359,7 +356,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -406,7 +403,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -436,7 +433,6 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } - if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } @@ -454,7 +450,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -484,6 +480,7 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } + if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } @@ -501,7 +498,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -531,10 +528,10 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } - if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } + if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } @@ -549,7 +546,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -579,6 +576,7 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } + if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } @@ -597,7 +595,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -624,6 +622,7 @@ export function createAnalyticsClient({ const requestPath = '/2/conversions/purchaseRate'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (index !== undefined) { queryParameters.index = index.toString(); } @@ -644,7 +643,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -692,7 +691,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -722,9 +721,11 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } + if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } + if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } @@ -739,7 +740,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -771,17 +772,16 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } - if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } - if (limit !== undefined) { queryParameters.limit = limit.toString(); } + if (offset !== undefined) { queryParameters.offset = offset.toString(); } @@ -796,7 +796,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -828,16 +828,17 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } + if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } - if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } if (limit !== undefined) { queryParameters.limit = limit.toString(); } + if (offset !== undefined) { queryParameters.offset = offset.toString(); } @@ -852,7 +853,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -884,7 +885,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -916,17 +917,16 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } - if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } - if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } if (limit !== undefined) { queryParameters.limit = limit.toString(); } + if (offset !== undefined) { queryParameters.offset = offset.toString(); } @@ -941,7 +941,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -971,6 +971,7 @@ export function createAnalyticsClient({ const requestPath = '/2/filters'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (index !== undefined) { queryParameters.index = index.toString(); } @@ -986,6 +987,7 @@ export function createAnalyticsClient({ if (limit !== undefined) { queryParameters.limit = limit.toString(); } + if (offset !== undefined) { queryParameters.offset = offset.toString(); } @@ -1000,7 +1002,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1041,10 +1043,10 @@ export function createAnalyticsClient({ if (search !== undefined) { queryParameters.search = search.toString(); } + if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } - if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } @@ -1065,7 +1067,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1098,6 +1100,7 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } + if (search !== undefined) { queryParameters.search = search.toString(); } @@ -1124,7 +1127,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1162,10 +1165,10 @@ export function createAnalyticsClient({ if (search !== undefined) { queryParameters.search = search.toString(); } + if (clickAnalytics !== undefined) { queryParameters.clickAnalytics = clickAnalytics.toString(); } - if (revenueAnalytics !== undefined) { queryParameters.revenueAnalytics = revenueAnalytics.toString(); } @@ -1175,10 +1178,10 @@ export function createAnalyticsClient({ if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } + if (limit !== undefined) { queryParameters.limit = limit.toString(); } - if (offset !== undefined) { queryParameters.offset = offset.toString(); } @@ -1193,7 +1196,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1259,7 +1262,6 @@ export function createAnalyticsClient({ if (direction !== undefined) { queryParameters.direction = direction.toString(); } - if (limit !== undefined) { queryParameters.limit = limit.toString(); } @@ -1277,7 +1279,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1326,7 +1328,7 @@ export function createAnalyticsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-insights/src/insightsClient.ts b/packages/client-insights/src/insightsClient.ts index 66ba6a0d9..438bdbb79 100644 --- a/packages/client-insights/src/insightsClient.ts +++ b/packages/client-insights/src/insightsClient.ts @@ -41,26 +41,27 @@ export function createInsightsClient({ ...options }: CreateClientOptions & { region?: Region }) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(regionOption), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'Insights', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(regionOption), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'Insights', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -71,16 +72,14 @@ export function createInsightsClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -90,7 +89,7 @@ export function createInsightsClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -101,9 +100,9 @@ export function createInsightsClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, @@ -134,7 +133,7 @@ export function createInsightsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -161,7 +160,7 @@ export function createInsightsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -193,7 +192,7 @@ export function createInsightsClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -225,7 +224,7 @@ export function createInsightsClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -251,7 +250,7 @@ export function createInsightsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -281,7 +280,7 @@ export function createInsightsClient({ data: insightsEvents, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-personalization/src/personalizationClient.ts b/packages/client-personalization/src/personalizationClient.ts index 662f99b73..95a5f9c1c 100644 --- a/packages/client-personalization/src/personalizationClient.ts +++ b/packages/client-personalization/src/personalizationClient.ts @@ -44,26 +44,27 @@ export function createPersonalizationClient({ ...options }: CreateClientOptions & { region: Region }) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(regionOption), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'Personalization', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(regionOption), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'Personalization', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -74,16 +75,14 @@ export function createPersonalizationClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -93,7 +92,7 @@ export function createPersonalizationClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -104,9 +103,9 @@ export function createPersonalizationClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, @@ -137,7 +136,7 @@ export function createPersonalizationClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -164,7 +163,7 @@ export function createPersonalizationClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -196,7 +195,7 @@ export function createPersonalizationClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -228,7 +227,7 @@ export function createPersonalizationClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -260,7 +259,7 @@ export function createPersonalizationClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -283,7 +282,7 @@ export function createPersonalizationClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -318,7 +317,7 @@ export function createPersonalizationClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -368,7 +367,7 @@ export function createPersonalizationClient({ data: personalizationStrategyParams, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-query-suggestions/src/querySuggestionsClient.ts b/packages/client-query-suggestions/src/querySuggestionsClient.ts index 622c32ae2..7b93ae608 100644 --- a/packages/client-query-suggestions/src/querySuggestionsClient.ts +++ b/packages/client-query-suggestions/src/querySuggestionsClient.ts @@ -48,26 +48,27 @@ export function createQuerySuggestionsClient({ ...options }: CreateClientOptions & { region: Region }) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(regionOption), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'QuerySuggestions', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(regionOption), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'QuerySuggestions', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -78,16 +79,14 @@ export function createQuerySuggestionsClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -97,7 +96,7 @@ export function createQuerySuggestionsClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -108,9 +107,9 @@ export function createQuerySuggestionsClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, @@ -143,7 +142,7 @@ export function createQuerySuggestionsClient({ data: configurationWithIndex, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -173,7 +172,7 @@ export function createQuerySuggestionsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -200,7 +199,7 @@ export function createQuerySuggestionsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -232,7 +231,7 @@ export function createQuerySuggestionsClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -264,7 +263,7 @@ export function createQuerySuggestionsClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -293,7 +292,7 @@ export function createQuerySuggestionsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -316,7 +315,7 @@ export function createQuerySuggestionsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -345,7 +344,7 @@ export function createQuerySuggestionsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -374,7 +373,7 @@ export function createQuerySuggestionsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -403,7 +402,7 @@ export function createQuerySuggestionsClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -445,7 +444,7 @@ export function createQuerySuggestionsClient({ data: configuration, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-search/src/searchClient.ts b/packages/client-search/src/searchClient.ts index 4aa87bf8d..f661dbd27 100644 --- a/packages/client-search/src/searchClient.ts +++ b/packages/client-search/src/searchClient.ts @@ -174,26 +174,27 @@ export function createSearchClient({ ...options }: CreateClientOptions) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(appIdOption), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'Search', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(appIdOption), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'Search', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -204,16 +205,14 @@ export function createSearchClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -223,7 +222,7 @@ export function createSearchClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -234,9 +233,9 @@ export function createSearchClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, @@ -738,7 +737,7 @@ export function createSearchClient({ data: apiKey, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -783,7 +782,7 @@ export function createSearchClient({ data: body, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -816,7 +815,7 @@ export function createSearchClient({ data: source, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -862,7 +861,7 @@ export function createSearchClient({ data: assignUserIdParams, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -898,7 +897,7 @@ export function createSearchClient({ data: batchWriteParams, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -947,7 +946,7 @@ export function createSearchClient({ data: batchAssignUserIdsParams, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -994,7 +993,7 @@ export function createSearchClient({ data: batchDictionaryEntriesParams, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1025,7 +1024,7 @@ export function createSearchClient({ data: browseParams ? browseParams : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1054,7 +1053,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1090,7 +1089,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1126,7 +1125,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1156,7 +1155,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1183,7 +1182,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1215,7 +1214,7 @@ export function createSearchClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1247,7 +1246,7 @@ export function createSearchClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1276,7 +1275,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1314,7 +1313,7 @@ export function createSearchClient({ data: deleteByParams, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1343,7 +1342,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1382,7 +1381,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1425,7 +1424,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1454,7 +1453,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1486,6 +1485,7 @@ export function createSearchClient({ .replace('{objectID}', encodeURIComponent(objectID)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (forwardToReplicas !== undefined) { queryParameters.forwardToReplicas = forwardToReplicas.toString(); } @@ -1497,7 +1497,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1523,7 +1523,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1552,7 +1552,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1575,7 +1575,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1598,7 +1598,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1627,7 +1627,6 @@ export function createSearchClient({ if (length !== undefined) { queryParameters.length = length.toString(); } - if (indexName !== undefined) { queryParameters.indexName = indexName.toString(); } @@ -1642,7 +1641,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1674,6 +1673,7 @@ export function createSearchClient({ .replace('{objectID}', encodeURIComponent(objectID)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (attributesToRetrieve !== undefined) { queryParameters.attributesToRetrieve = attributesToRetrieve.toString(); } @@ -1685,7 +1685,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1720,7 +1720,7 @@ export function createSearchClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1756,7 +1756,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1785,7 +1785,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1808,7 +1808,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1844,7 +1844,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1880,7 +1880,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1903,7 +1903,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1932,7 +1932,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1963,7 +1963,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1986,7 +1986,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2009,7 +2009,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2033,6 +2033,7 @@ export function createSearchClient({ if (page !== undefined) { queryParameters.page = page.toString(); } + if (hitsPerPage !== undefined) { queryParameters.hitsPerPage = hitsPerPage.toString(); } @@ -2044,7 +2045,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2065,10 +2066,10 @@ export function createSearchClient({ const requestPath = '/1/clusters/mapping'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (page !== undefined) { queryParameters.page = page.toString(); } - if (hitsPerPage !== undefined) { queryParameters.hitsPerPage = hitsPerPage.toString(); } @@ -2080,7 +2081,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2110,7 +2111,7 @@ export function createSearchClient({ data: batchParams, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2155,7 +2156,7 @@ export function createSearchClient({ data: operationIndexParams, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2192,7 +2193,6 @@ export function createSearchClient({ .replace('{objectID}', encodeURIComponent(objectID)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; - if (createIfNotExists !== undefined) { queryParameters.createIfNotExists = createIfNotExists.toString(); } @@ -2205,7 +2205,7 @@ export function createSearchClient({ data: attributesToUpdate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2234,7 +2234,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2264,7 +2264,7 @@ export function createSearchClient({ data: source, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2293,7 +2293,7 @@ export function createSearchClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2328,7 +2328,7 @@ export function createSearchClient({ data: body, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2369,6 +2369,7 @@ export function createSearchClient({ .replace('{objectID}', encodeURIComponent(objectID)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (forwardToReplicas !== undefined) { queryParameters.forwardToReplicas = forwardToReplicas.toString(); } @@ -2381,7 +2382,7 @@ export function createSearchClient({ data: rule, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2412,10 +2413,10 @@ export function createSearchClient({ const requestPath = '/1/indexes/{indexName}/rules/batch'.replace('{indexName}', encodeURIComponent(indexName)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (forwardToReplicas !== undefined) { queryParameters.forwardToReplicas = forwardToReplicas.toString(); } - if (clearExistingRules !== undefined) { queryParameters.clearExistingRules = clearExistingRules.toString(); } @@ -2428,7 +2429,7 @@ export function createSearchClient({ data: rules, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2484,7 +2485,7 @@ export function createSearchClient({ data: synonymHit, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2530,7 +2531,7 @@ export function createSearchClient({ data: synonymHit, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2593,7 +2594,7 @@ export function createSearchClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2644,7 +2645,7 @@ export function createSearchClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2687,7 +2688,7 @@ export function createSearchClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2723,7 +2724,7 @@ export function createSearchClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2759,7 +2760,7 @@ export function createSearchClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2798,7 +2799,7 @@ export function createSearchClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2836,7 +2837,7 @@ export function createSearchClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2874,7 +2875,7 @@ export function createSearchClient({ data: dictionarySettingsParams, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2916,7 +2917,7 @@ export function createSearchClient({ data: indexSettings, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2955,7 +2956,7 @@ export function createSearchClient({ data: apiKey, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-usage/src/usageClient.ts b/packages/client-usage/src/usageClient.ts index 62b256ae2..e5fbe431d 100644 --- a/packages/client-usage/src/usageClient.ts +++ b/packages/client-usage/src/usageClient.ts @@ -35,26 +35,27 @@ export function createUsageClient({ ...options }: CreateClientOptions) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'Usage', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'Usage', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -65,16 +66,14 @@ export function createUsageClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -84,7 +83,7 @@ export function createUsageClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -95,9 +94,9 @@ export function createUsageClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, @@ -128,7 +127,7 @@ export function createUsageClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -155,7 +154,7 @@ export function createUsageClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -187,7 +186,7 @@ export function createUsageClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -219,7 +218,7 @@ export function createUsageClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -264,7 +263,6 @@ export function createUsageClient({ if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } - if (granularity !== undefined) { queryParameters.granularity = granularity.toString(); } @@ -276,7 +274,7 @@ export function createUsageClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -326,7 +324,7 @@ export function createUsageClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; } diff --git a/packages/ingestion/src/ingestionClient.ts b/packages/ingestion/src/ingestionClient.ts index 8af5ce7d1..c6d2dfce7 100644 --- a/packages/ingestion/src/ingestionClient.ts +++ b/packages/ingestion/src/ingestionClient.ts @@ -158,26 +158,27 @@ export function createIngestionClient({ ...options }: CreateClientOptions & { region: Region }) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(regionOption), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'Ingestion', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(regionOption), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'Ingestion', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -188,16 +189,14 @@ export function createIngestionClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -207,7 +206,7 @@ export function createIngestionClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -218,9 +217,9 @@ export function createIngestionClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, @@ -265,7 +264,7 @@ export function createIngestionClient({ data: authenticationCreate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -309,7 +308,7 @@ export function createIngestionClient({ data: destinationCreate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -347,7 +346,7 @@ export function createIngestionClient({ data: sourceCreate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -383,7 +382,7 @@ export function createIngestionClient({ data: taskCreate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -422,7 +421,7 @@ export function createIngestionClient({ data: taskCreate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -458,7 +457,7 @@ export function createIngestionClient({ data: transformationCreate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -488,7 +487,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -515,7 +514,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -547,7 +546,7 @@ export function createIngestionClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -579,7 +578,7 @@ export function createIngestionClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -616,7 +615,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -653,7 +652,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -684,7 +683,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -710,7 +709,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -736,7 +735,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -768,7 +767,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -799,7 +798,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -830,7 +829,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -861,7 +860,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -892,7 +891,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -939,7 +938,7 @@ export function createIngestionClient({ data: generateTransformationCodePayload, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -976,7 +975,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1010,7 +1009,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1048,7 +1047,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1079,7 +1078,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1110,7 +1109,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1141,7 +1140,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1172,7 +1171,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1209,7 +1208,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1245,14 +1244,13 @@ export function createIngestionClient({ if (type !== undefined) { queryParameters.type = type.toString(); } - if (platform !== undefined) { queryParameters.platform = platform.toString(); } + if (sort !== undefined) { queryParameters.sort = sort.toString(); } - if (order !== undefined) { queryParameters.order = order.toString(); } @@ -1264,7 +1262,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1301,7 +1299,6 @@ export function createIngestionClient({ if (type !== undefined) { queryParameters.type = type.toString(); } - if (authenticationID !== undefined) { queryParameters.authenticationID = authenticationID.toString(); } @@ -1319,7 +1316,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1365,10 +1362,10 @@ export function createIngestionClient({ if (type !== undefined) { queryParameters.type = type.toString(); } - if (sort !== undefined) { queryParameters.sort = sort.toString(); } + if (order !== undefined) { queryParameters.order = order.toString(); } @@ -1386,7 +1383,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1423,7 +1420,6 @@ export function createIngestionClient({ if (page !== undefined) { queryParameters.page = page.toString(); } - if (status !== undefined) { queryParameters.status = status.toString(); } @@ -1454,7 +1450,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1490,7 +1486,6 @@ export function createIngestionClient({ if (type !== undefined) { queryParameters.type = type.toString(); } - if (authenticationID !== undefined) { queryParameters.authenticationID = authenticationID.toString(); } @@ -1509,7 +1504,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1545,17 +1540,16 @@ export function createIngestionClient({ if (page !== undefined) { queryParameters.page = page.toString(); } - if (action !== undefined) { queryParameters.action = action.toString(); } + if (enabled !== undefined) { queryParameters.enabled = enabled.toString(); } if (sourceID !== undefined) { queryParameters.sourceID = sourceID.toString(); } - if (destinationID !== undefined) { queryParameters.destinationID = destinationID.toString(); } @@ -1565,7 +1559,6 @@ export function createIngestionClient({ if (sort !== undefined) { queryParameters.sort = sort.toString(); } - if (order !== undefined) { queryParameters.order = order.toString(); } @@ -1577,7 +1570,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1613,16 +1606,17 @@ export function createIngestionClient({ if (page !== undefined) { queryParameters.page = page.toString(); } - if (action !== undefined) { queryParameters.action = action.toString(); } + if (enabled !== undefined) { queryParameters.enabled = enabled.toString(); } if (sourceID !== undefined) { queryParameters.sourceID = sourceID.toString(); } + if (destinationID !== undefined) { queryParameters.destinationID = destinationID.toString(); } @@ -1632,7 +1626,6 @@ export function createIngestionClient({ if (sort !== undefined) { queryParameters.sort = sort.toString(); } - if (order !== undefined) { queryParameters.order = order.toString(); } @@ -1644,7 +1637,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1669,7 +1662,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1700,6 +1693,7 @@ export function createIngestionClient({ if (page !== undefined) { queryParameters.page = page.toString(); } + if (sort !== undefined) { queryParameters.sort = sort.toString(); } @@ -1714,7 +1708,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1758,7 +1752,7 @@ export function createIngestionClient({ data: pushTaskPayload, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1794,7 +1788,7 @@ export function createIngestionClient({ data: runSourcePayload ? runSourcePayload : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1825,7 +1819,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1856,7 +1850,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1896,7 +1890,7 @@ export function createIngestionClient({ data: authenticationSearch, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1931,7 +1925,7 @@ export function createIngestionClient({ data: destinationSearch, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -1966,7 +1960,7 @@ export function createIngestionClient({ data: sourceSearch, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2001,7 +1995,7 @@ export function createIngestionClient({ data: taskSearch, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2036,7 +2030,7 @@ export function createIngestionClient({ data: taskSearch, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2076,7 +2070,7 @@ export function createIngestionClient({ data: transformationSearch, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2110,7 +2104,7 @@ export function createIngestionClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2151,7 +2145,7 @@ export function createIngestionClient({ data: transformationTry, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2203,7 +2197,7 @@ export function createIngestionClient({ data: transformationTry, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2246,7 +2240,7 @@ export function createIngestionClient({ data: authenticationUpdate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2289,7 +2283,7 @@ export function createIngestionClient({ data: destinationUpdate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2329,7 +2323,7 @@ export function createIngestionClient({ data: sourceUpdate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2361,7 +2355,7 @@ export function createIngestionClient({ data: taskUpdate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2396,7 +2390,7 @@ export function createIngestionClient({ data: taskUpdate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2441,7 +2435,7 @@ export function createIngestionClient({ data: transformationCreate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2471,7 +2465,7 @@ export function createIngestionClient({ data: sourceCreate ? sourceCreate : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -2511,7 +2505,7 @@ export function createIngestionClient({ data: sourceUpdate, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; } diff --git a/packages/monitoring/src/monitoringClient.ts b/packages/monitoring/src/monitoringClient.ts index fe8737a9b..00bd32801 100644 --- a/packages/monitoring/src/monitoringClient.ts +++ b/packages/monitoring/src/monitoringClient.ts @@ -44,26 +44,27 @@ export function createMonitoringClient({ ...options }: CreateClientOptions) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'Monitoring', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'Monitoring', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -74,16 +75,14 @@ export function createMonitoringClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -93,7 +92,7 @@ export function createMonitoringClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -104,9 +103,9 @@ export function createMonitoringClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, @@ -137,7 +136,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -164,7 +163,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -196,7 +195,7 @@ export function createMonitoringClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -228,7 +227,7 @@ export function createMonitoringClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -257,7 +256,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -283,7 +282,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -303,7 +302,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -332,7 +331,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -358,7 +357,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -391,7 +390,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -420,7 +419,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -440,7 +439,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -460,7 +459,7 @@ export function createMonitoringClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; } diff --git a/packages/recommend/src/recommendClient.ts b/packages/recommend/src/recommendClient.ts index 6dd8d8f64..de7d16ad4 100644 --- a/packages/recommend/src/recommendClient.ts +++ b/packages/recommend/src/recommendClient.ts @@ -74,26 +74,27 @@ export function createRecommendClient({ ...options }: CreateClientOptions) { const auth = createAuth(appIdOption, apiKeyOption, authMode); + const transporter = createTransporter({ + hosts: getDefaultHosts(appIdOption), + ...options, + algoliaAgent: getAlgoliaAgent({ + algoliaAgents, + client: 'Recommend', + version: apiClientVersion, + }), + baseHeaders: { + 'content-type': 'text/plain', + ...auth.headers(), + ...options.baseHeaders, + }, + baseQueryParameters: { + ...auth.queryParameters(), + ...options.baseQueryParameters, + }, + }); return { - transporter: createTransporter({ - hosts: getDefaultHosts(appIdOption), - ...options, - algoliaAgent: getAlgoliaAgent({ - algoliaAgents, - client: 'Recommend', - version: apiClientVersion, - }), - baseHeaders: { - 'content-type': 'text/plain', - ...auth.headers(), - ...options.baseHeaders, - }, - baseQueryParameters: { - ...auth.queryParameters(), - ...options.baseQueryParameters, - }, - }), + transporter, /** * The `appId` currently in use. @@ -104,16 +105,14 @@ export function createRecommendClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( - () => undefined, - ); + return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return this.transporter.algoliaAgent.value; + return transporter.algoliaAgent.value; }, /** @@ -123,7 +122,7 @@ export function createRecommendClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - this.transporter.algoliaAgent.add({ segment, version }); + transporter.algoliaAgent.add({ segment, version }); }, /** @@ -134,9 +133,9 @@ export function createRecommendClient({ */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { - this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; + transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { - this.transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; + transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, @@ -167,7 +166,7 @@ export function createRecommendClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -194,7 +193,7 @@ export function createRecommendClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -226,7 +225,7 @@ export function createRecommendClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -258,7 +257,7 @@ export function createRecommendClient({ data: body ? body : {}, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -303,7 +302,7 @@ export function createRecommendClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -348,7 +347,7 @@ export function createRecommendClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -393,7 +392,7 @@ export function createRecommendClient({ headers, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -440,7 +439,7 @@ export function createRecommendClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, /** @@ -483,7 +482,7 @@ export function createRecommendClient({ cacheable: true, }; - return this.transporter.request(request, requestOptions); + return transporter.request(request, requestOptions); }, }; }