From f05c7d9a26bcdec537a372abeadfa00df516d4cc Mon Sep 17 00:00:00 2001 From: algolia-bot Date: Fri, 6 Sep 2024 12:42:15 +0000 Subject: [PATCH] fix(javascript): type definition and template cleanup (generated) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/algolia/api-clients-automation/pull/3656 Co-authored-by: algolia-bot Co-authored-by: Clément Vannicatte --- packages/algoliasearch/builds/browser.ts | 111 ++++------- packages/algoliasearch/builds/models.ts | 6 +- packages/algoliasearch/builds/node.ts | 161 ++++----------- packages/algoliasearch/lite/builds/browser.ts | 10 +- packages/algoliasearch/lite/builds/node.ts | 10 +- packages/algoliasearch/lite/src/liteClient.ts | 53 ++--- packages/client-abtesting/builds/browser.ts | 15 +- packages/client-abtesting/builds/node.ts | 15 +- .../client-abtesting/src/abtestingClient.ts | 69 +++---- packages/client-analytics/builds/browser.ts | 15 +- packages/client-analytics/builds/node.ts | 15 +- .../client-analytics/src/analyticsClient.ts | 120 ++++++------ packages/client-insights/builds/browser.ts | 15 +- packages/client-insights/builds/node.ts | 15 +- .../client-insights/src/insightsClient.ts | 59 +++--- .../client-personalization/builds/browser.ts | 15 +- .../client-personalization/builds/node.ts | 15 +- .../src/personalizationClient.ts | 63 +++--- .../builds/browser.ts | 15 +- .../client-query-suggestions/builds/node.ts | 15 +- .../src/querySuggestionsClient.ts | 69 +++---- packages/client-search/builds/browser.ts | 10 +- packages/client-search/builds/node.ts | 21 +- .../client-search/model/clientMethodProps.ts | 5 + packages/client-search/src/searchClient.ts | 179 ++++++++--------- packages/client-usage/builds/browser.ts | 10 +- packages/client-usage/builds/node.ts | 10 +- packages/client-usage/src/usageClient.ts | 60 +++--- packages/ingestion/builds/browser.ts | 15 +- packages/ingestion/builds/node.ts | 15 +- packages/ingestion/src/ingestionClient.ts | 184 +++++++++--------- packages/monitoring/builds/browser.ts | 10 +- packages/monitoring/builds/node.ts | 10 +- packages/monitoring/src/monitoringClient.ts | 73 +++---- packages/recommend/builds/browser.ts | 10 +- packages/recommend/builds/node.ts | 10 +- packages/recommend/src/recommendClient.ts | 65 ++++--- 37 files changed, 729 insertions(+), 839 deletions(-) diff --git a/packages/algoliasearch/builds/browser.ts b/packages/algoliasearch/builds/browser.ts index 9a551d3f9..7b03ea409 100644 --- a/packages/algoliasearch/builds/browser.ts +++ b/packages/algoliasearch/builds/browser.ts @@ -4,34 +4,28 @@ import type { AbtestingClient, Region as AbtestingRegion } from '@algolia/client import { abtestingClient } from '@algolia/client-abtesting'; import type { AnalyticsClient, Region as AnalyticsRegion } from '@algolia/client-analytics'; import { analyticsClient } from '@algolia/client-analytics'; -import { - DEFAULT_CONNECT_TIMEOUT_BROWSER, - DEFAULT_READ_TIMEOUT_BROWSER, - DEFAULT_WRITE_TIMEOUT_BROWSER, - createBrowserLocalStorageCache, - createFallbackableCache, - createMemoryCache, -} from '@algolia/client-common'; import type { ClientOptions } from '@algolia/client-common'; import type { PersonalizationClient, Region as PersonalizationRegion } from '@algolia/client-personalization'; import { personalizationClient } from '@algolia/client-personalization'; +import type { SearchClient } from '@algolia/client-search'; import { searchClient } from '@algolia/client-search'; import type { RecommendClient } from '@algolia/recommend'; import { recommendClient } from '@algolia/recommend'; -import { createXhrRequester } from '@algolia/requester-browser-xhr'; import type { InitClientOptions, InitClientRegion } from './models'; -import { apiClientVersion } from './models'; export * from './models'; -/** - * The client type. - */ -export type Algoliasearch = ReturnType; +export type Algoliasearch = SearchClient & { + initRecommend: (initOptions: InitClientOptions) => RecommendClient; + initAnalytics: (initOptions: InitClientOptions & InitClientRegion) => AnalyticsClient; + initAbtesting: (initOptions: InitClientOptions & InitClientRegion) => AbtestingClient; + initPersonalization: ( + initOptions: InitClientOptions & Required>, + ) => PersonalizationClient; +}; -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions) { +export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions): Algoliasearch { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } @@ -39,65 +33,46 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt if (!apiKey || typeof apiKey !== 'string') { throw new Error('`apiKey` is missing.'); } - function initRecommend(initOptions: InitClientOptions = {}): RecommendClient { - return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options); - } - - function initAnalytics(initOptions: InitClientOptions & InitClientRegion = {}): AnalyticsClient { - return analyticsClient( - initOptions.appId || appId, - initOptions.apiKey || apiKey, - initOptions.region, - initOptions.options, - ); - } - - function initAbtesting(initOptions: InitClientOptions & InitClientRegion = {}): AbtestingClient { - return abtestingClient( - initOptions.appId || appId, - initOptions.apiKey || apiKey, - initOptions.region, - initOptions.options, - ); - } - - function initPersonalization( - initOptions: InitClientOptions & Required>, - ): PersonalizationClient { - return personalizationClient( - initOptions.appId || appId, - initOptions.apiKey || apiKey, - initOptions.region, - initOptions.options, - ); - } return { - ...searchClient(appId, apiKey, { - timeouts: { - connect: DEFAULT_CONNECT_TIMEOUT_BROWSER, - read: DEFAULT_READ_TIMEOUT_BROWSER, - write: DEFAULT_WRITE_TIMEOUT_BROWSER, - }, - requester: createXhrRequester(), - algoliaAgents: [{ segment: 'Browser' }], - authMode: 'WithinQueryParameters', - responsesCache: createMemoryCache(), - requestsCache: createMemoryCache({ serializable: false }), - hostsCache: createFallbackableCache({ - caches: [createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), createMemoryCache()], - }), - ...options, - }), + ...searchClient(appId, apiKey, options), /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { return this.transporter.algoliaAgent.value; }, - initAbtesting, - initAnalytics, - initPersonalization, - initRecommend, + initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => { + return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options); + }, + + initAnalytics: (initOptions: InitClientOptions & InitClientRegion = {}): AnalyticsClient => { + return analyticsClient( + initOptions.appId || appId, + initOptions.apiKey || apiKey, + initOptions.region, + initOptions.options, + ); + }, + + initAbtesting: (initOptions: InitClientOptions & InitClientRegion = {}): AbtestingClient => { + return abtestingClient( + initOptions.appId || appId, + initOptions.apiKey || apiKey, + initOptions.region, + initOptions.options, + ); + }, + + initPersonalization: ( + initOptions: InitClientOptions & Required>, + ): PersonalizationClient => { + return personalizationClient( + initOptions.appId || appId, + initOptions.apiKey || apiKey, + initOptions.region, + initOptions.options, + ); + }, }; } diff --git a/packages/algoliasearch/builds/models.ts b/packages/algoliasearch/builds/models.ts index 2d3d93ee8..9ed71e4b4 100644 --- a/packages/algoliasearch/builds/models.ts +++ b/packages/algoliasearch/builds/models.ts @@ -1,6 +1,6 @@ // Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. -import type { Region as ABTestingRegion } from '@algolia/client-abtesting'; +import type { Region as AbTestingRegion } from '@algolia/client-abtesting'; import type { Region as AnalyticsRegion } from '@algolia/client-analytics'; import type { ClientOptions } from '@algolia/client-common'; import type { @@ -79,7 +79,7 @@ import type { } from '@algolia/client-search'; import { apiClientVersion } from '@algolia/client-search'; -type Region = ABTestingRegion | AnalyticsRegion; +type Region = AbTestingRegion | AnalyticsRegion; export * from '@algolia/client-search'; export * from '@algolia/recommend'; @@ -161,7 +161,7 @@ export { TypoToleranceEnum, Value, AnalyticsRegion, - ABTestingRegion, + AbTestingRegion, Region, apiClientVersion, }; diff --git a/packages/algoliasearch/builds/node.ts b/packages/algoliasearch/builds/node.ts index 5dad6cf77..7b03ea409 100644 --- a/packages/algoliasearch/builds/node.ts +++ b/packages/algoliasearch/builds/node.ts @@ -1,43 +1,31 @@ // Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. -import { createHmac } from 'node:crypto'; - import type { AbtestingClient, Region as AbtestingRegion } from '@algolia/client-abtesting'; import { abtestingClient } from '@algolia/client-abtesting'; import type { AnalyticsClient, Region as AnalyticsRegion } from '@algolia/client-analytics'; import { analyticsClient } from '@algolia/client-analytics'; -import { - DEFAULT_CONNECT_TIMEOUT_NODE, - DEFAULT_READ_TIMEOUT_NODE, - DEFAULT_WRITE_TIMEOUT_NODE, - createMemoryCache, - createNullCache, - serializeQueryParameters, -} from '@algolia/client-common'; import type { ClientOptions } from '@algolia/client-common'; import type { PersonalizationClient, Region as PersonalizationRegion } from '@algolia/client-personalization'; import { personalizationClient } from '@algolia/client-personalization'; +import type { SearchClient } from '@algolia/client-search'; import { searchClient } from '@algolia/client-search'; import type { RecommendClient } from '@algolia/recommend'; import { recommendClient } from '@algolia/recommend'; -import { createHttpRequester } from '@algolia/requester-node-http'; -import type { - InitClientOptions, - InitClientRegion, - GenerateSecuredApiKeyOptions, - GetSecuredApiKeyRemainingValidityOptions, -} from './models'; +import type { InitClientOptions, InitClientRegion } from './models'; export * from './models'; -/** - * The client type. - */ -export type Algoliasearch = ReturnType; +export type Algoliasearch = SearchClient & { + initRecommend: (initOptions: InitClientOptions) => RecommendClient; + initAnalytics: (initOptions: InitClientOptions & InitClientRegion) => AnalyticsClient; + initAbtesting: (initOptions: InitClientOptions & InitClientRegion) => AbtestingClient; + initPersonalization: ( + initOptions: InitClientOptions & Required>, + ) => PersonalizationClient; +}; -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions) { +export function algoliasearch(appId: string, apiKey: string, options?: ClientOptions): Algoliasearch { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } @@ -45,117 +33,46 @@ export function algoliasearch(appId: string, apiKey: string, options?: ClientOpt if (!apiKey || typeof apiKey !== 'string') { throw new Error('`apiKey` is missing.'); } - function initRecommend(initOptions: InitClientOptions = {}): RecommendClient { - return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options); - } - - function initAnalytics(initOptions: InitClientOptions & InitClientRegion = {}): AnalyticsClient { - return analyticsClient( - initOptions.appId || appId, - initOptions.apiKey || apiKey, - initOptions.region, - initOptions.options, - ); - } - - function initAbtesting(initOptions: InitClientOptions & InitClientRegion = {}): AbtestingClient { - return abtestingClient( - initOptions.appId || appId, - initOptions.apiKey || apiKey, - initOptions.region, - initOptions.options, - ); - } - - function initPersonalization( - initOptions: InitClientOptions & Required>, - ): PersonalizationClient { - return personalizationClient( - initOptions.appId || appId, - initOptions.apiKey || apiKey, - initOptions.region, - initOptions.options, - ); - } return { - ...searchClient(appId, apiKey, { - timeouts: { - connect: DEFAULT_CONNECT_TIMEOUT_NODE, - read: DEFAULT_READ_TIMEOUT_NODE, - write: DEFAULT_WRITE_TIMEOUT_NODE, - }, - requester: createHttpRequester(), - algoliaAgents: [{ segment: 'Node.js', version: process.versions.node }], - responsesCache: createNullCache(), - requestsCache: createNullCache(), - hostsCache: createMemoryCache(), - ...options, - }), + ...searchClient(appId, apiKey, options), /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { return this.transporter.algoliaAgent.value; }, - initAbtesting, - initAnalytics, - initPersonalization, - initRecommend, - /** - * Helper: Generates a secured API key based on the given `parentApiKey` and given `restrictions`. - * - * @summary Helper: Generates a secured API key based on the given `parentApiKey` and given `restrictions`. - * @param generateSecuredApiKey - The `generateSecuredApiKey` object. - * @param generateSecuredApiKey.parentApiKey - The base API key from which to generate the new secured one. - * @param generateSecuredApiKey.restrictions - A set of properties defining the restrictions of the secured API key. - */ - generateSecuredApiKey({ parentApiKey, restrictions = {} }: GenerateSecuredApiKeyOptions): string { - let mergedRestrictions = restrictions; - if (restrictions.searchParams) { - // merge searchParams with the root restrictions - mergedRestrictions = { - ...restrictions, - ...restrictions.searchParams, - }; - - delete mergedRestrictions.searchParams; - } - - mergedRestrictions = Object.keys(mergedRestrictions) - .sort() - .reduce( - (acc, key) => { - // eslint-disable-next-line no-param-reassign - acc[key] = (mergedRestrictions as any)[key]; - return acc; - }, - {} as Record, - ); - - const queryParameters = serializeQueryParameters(mergedRestrictions); - return Buffer.from( - createHmac('sha256', parentApiKey).update(queryParameters).digest('hex') + queryParameters, - ).toString('base64'); + initRecommend: (initOptions: InitClientOptions = {}): RecommendClient => { + return recommendClient(initOptions.appId || appId, initOptions.apiKey || apiKey, initOptions.options); }, - /** - * Helper: Retrieves the remaining validity of the previous generated `securedApiKey`, the `ValidUntil` parameter must have been provided. - * - * @summary Helper: Retrieves the remaining validity of the previous generated `secured_api_key`, the `ValidUntil` parameter must have been provided. - * @param getSecuredApiKeyRemainingValidity - The `getSecuredApiKeyRemainingValidity` object. - * @param getSecuredApiKeyRemainingValidity.securedApiKey - The secured API key generated with the `generateSecuredApiKey` method. - */ - getSecuredApiKeyRemainingValidity({ securedApiKey }: GetSecuredApiKeyRemainingValidityOptions): number { - const decodedString = Buffer.from(securedApiKey, 'base64').toString('ascii'); - const regex = /validUntil=(\d+)/; - const match = decodedString.match(regex); + initAnalytics: (initOptions: InitClientOptions & InitClientRegion = {}): AnalyticsClient => { + return analyticsClient( + initOptions.appId || appId, + initOptions.apiKey || apiKey, + initOptions.region, + initOptions.options, + ); + }, - if (match === null) { - throw new Error('validUntil not found in given secured api key.'); - } + initAbtesting: (initOptions: InitClientOptions & InitClientRegion = {}): AbtestingClient => { + return abtestingClient( + initOptions.appId || appId, + initOptions.apiKey || apiKey, + initOptions.region, + initOptions.options, + ); + }, - return parseInt(match[1], 10) - Math.round(new Date().getTime() / 1000); + initPersonalization: ( + initOptions: InitClientOptions & Required>, + ): PersonalizationClient => { + return personalizationClient( + initOptions.appId || appId, + initOptions.apiKey || apiKey, + initOptions.region, + initOptions.options, + ); }, }; } diff --git a/packages/algoliasearch/lite/builds/browser.ts b/packages/algoliasearch/lite/builds/browser.ts index b89d0a7f9..4e97da690 100644 --- a/packages/algoliasearch/lite/builds/browser.ts +++ b/packages/algoliasearch/lite/builds/browser.ts @@ -13,16 +13,12 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import { createLiteClient, apiClientVersion } from '../src/liteClient'; +export type LiteClient = ReturnType; + export { apiClientVersion } from '../src/liteClient'; export * from '../model'; -/** - * The client type. - */ -export type LiteClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function liteClient(appId: string, apiKey: string, options?: ClientOptions) { +export function liteClient(appId: string, apiKey: string, options?: ClientOptions): LiteClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/algoliasearch/lite/builds/node.ts b/packages/algoliasearch/lite/builds/node.ts index 3d0cb0796..4fe0c3f12 100644 --- a/packages/algoliasearch/lite/builds/node.ts +++ b/packages/algoliasearch/lite/builds/node.ts @@ -12,16 +12,12 @@ import { createHttpRequester } from '@algolia/requester-node-http'; import { createLiteClient } from '../src/liteClient'; +export type LiteClient = ReturnType; + export { apiClientVersion } from '../src/liteClient'; export * from '../model'; -/** - * The client type. - */ -export type LiteClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function liteClient(appId: string, apiKey: string, options?: ClientOptions) { +export function liteClient(appId: string, apiKey: string, options?: ClientOptions): LiteClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/algoliasearch/lite/src/liteClient.ts b/packages/algoliasearch/lite/src/liteClient.ts index 0c337abdb..6678dc02d 100644 --- a/packages/algoliasearch/lite/src/liteClient.ts +++ b/packages/algoliasearch/lite/src/liteClient.ts @@ -68,27 +68,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -99,14 +98,16 @@ export function createLiteClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -116,7 +117,7 @@ export function createLiteClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -126,7 +127,7 @@ export function createLiteClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** * Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets. @@ -188,7 +189,7 @@ export function createLiteClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -235,7 +236,7 @@ export function createLiteClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -298,7 +299,7 @@ export function createLiteClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-abtesting/builds/browser.ts b/packages/client-abtesting/builds/browser.ts index 98ea9ea05..5f56756ac 100644 --- a/packages/client-abtesting/builds/browser.ts +++ b/packages/client-abtesting/builds/browser.ts @@ -14,16 +14,17 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import type { Region } from '../src/abtestingClient'; import { createAbtestingClient, apiClientVersion, REGIONS } from '../src/abtestingClient'; +export type AbtestingClient = ReturnType; + export { apiClientVersion, Region } from '../src/abtestingClient'; export * from '../model'; -/** - * The client type. - */ -export type AbtestingClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function abtestingClient(appId: string, apiKey: string, region?: Region, options?: ClientOptions) { +export function abtestingClient( + appId: string, + apiKey: string, + region?: Region, + options?: ClientOptions, +): AbtestingClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-abtesting/builds/node.ts b/packages/client-abtesting/builds/node.ts index de4a28482..44e7253c5 100644 --- a/packages/client-abtesting/builds/node.ts +++ b/packages/client-abtesting/builds/node.ts @@ -13,16 +13,17 @@ import { createHttpRequester } from '@algolia/requester-node-http'; import type { Region } from '../src/abtestingClient'; import { createAbtestingClient, REGIONS } from '../src/abtestingClient'; +export type AbtestingClient = ReturnType; + export { apiClientVersion, Region } from '../src/abtestingClient'; export * from '../model'; -/** - * The client type. - */ -export type AbtestingClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function abtestingClient(appId: string, apiKey: string, region?: Region, options?: ClientOptions) { +export function abtestingClient( + appId: string, + apiKey: string, + region?: Region, + options?: ClientOptions, +): AbtestingClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-abtesting/src/abtestingClient.ts b/packages/client-abtesting/src/abtestingClient.ts index f21ccd799..e5b16acf6 100644 --- a/packages/client-abtesting/src/abtestingClient.ts +++ b/packages/client-abtesting/src/abtestingClient.ts @@ -48,27 +48,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -79,14 +78,16 @@ export function createAbtestingClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -96,7 +97,7 @@ export function createAbtestingClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -106,7 +107,7 @@ export function createAbtestingClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** @@ -145,7 +146,7 @@ export function createAbtestingClient({ data: addABTestsRequest, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -175,7 +176,7 @@ export function createAbtestingClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -202,7 +203,7 @@ export function createAbtestingClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -234,7 +235,7 @@ export function createAbtestingClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -266,7 +267,7 @@ export function createAbtestingClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -295,7 +296,7 @@ export function createAbtestingClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -324,7 +325,7 @@ export function createAbtestingClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -350,10 +351,10 @@ export function createAbtestingClient({ if (offset !== undefined) { queryParameters.offset = offset.toString(); } - if (limit !== undefined) { queryParameters.limit = limit.toString(); } + if (indexPrefix !== undefined) { queryParameters.indexPrefix = indexPrefix.toString(); } @@ -368,7 +369,7 @@ export function createAbtestingClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -413,7 +414,7 @@ export function createAbtestingClient({ data: scheduleABTestsRequest, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -442,7 +443,7 @@ export function createAbtestingClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-analytics/builds/browser.ts b/packages/client-analytics/builds/browser.ts index 718cbb101..9d2218e5e 100644 --- a/packages/client-analytics/builds/browser.ts +++ b/packages/client-analytics/builds/browser.ts @@ -14,16 +14,17 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import type { Region } from '../src/analyticsClient'; import { createAnalyticsClient, apiClientVersion, REGIONS } from '../src/analyticsClient'; +export type AnalyticsClient = ReturnType; + export { apiClientVersion, Region } from '../src/analyticsClient'; export * from '../model'; -/** - * The client type. - */ -export type AnalyticsClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function analyticsClient(appId: string, apiKey: string, region?: Region, options?: ClientOptions) { +export function analyticsClient( + appId: string, + apiKey: string, + region?: Region, + options?: ClientOptions, +): AnalyticsClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-analytics/builds/node.ts b/packages/client-analytics/builds/node.ts index 3c0b18fb8..2a09abb42 100644 --- a/packages/client-analytics/builds/node.ts +++ b/packages/client-analytics/builds/node.ts @@ -13,16 +13,17 @@ import { createHttpRequester } from '@algolia/requester-node-http'; import type { Region } from '../src/analyticsClient'; import { createAnalyticsClient, REGIONS } from '../src/analyticsClient'; +export type AnalyticsClient = ReturnType; + export { apiClientVersion, Region } from '../src/analyticsClient'; export * from '../model'; -/** - * The client type. - */ -export type AnalyticsClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function analyticsClient(appId: string, apiKey: string, region?: Region, options?: ClientOptions) { +export function analyticsClient( + appId: string, + apiKey: string, + region?: Region, + options?: ClientOptions, +): AnalyticsClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-analytics/src/analyticsClient.ts b/packages/client-analytics/src/analyticsClient.ts index 617b403ed..dbbb2d8de 100644 --- a/packages/client-analytics/src/analyticsClient.ts +++ b/packages/client-analytics/src/analyticsClient.ts @@ -78,27 +78,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -109,14 +108,16 @@ export function createAnalyticsClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -126,7 +127,7 @@ export function createAnalyticsClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -136,7 +137,7 @@ export function createAnalyticsClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** @@ -166,7 +167,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -193,7 +194,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -225,7 +226,7 @@ export function createAnalyticsClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -257,7 +258,7 @@ export function createAnalyticsClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -304,7 +305,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -341,7 +342,6 @@ export function createAnalyticsClient({ if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } - if (tags !== undefined) { queryParameters.tags = tags.toString(); } @@ -353,7 +353,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -400,7 +400,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -434,6 +434,7 @@ export function createAnalyticsClient({ if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } + if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } @@ -448,7 +449,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -484,6 +485,7 @@ export function createAnalyticsClient({ if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } + if (tags !== undefined) { queryParameters.tags = tags.toString(); } @@ -495,7 +497,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -531,7 +533,6 @@ export function createAnalyticsClient({ if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } - if (tags !== undefined) { queryParameters.tags = tags.toString(); } @@ -543,7 +544,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -573,6 +574,7 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } + if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } @@ -590,7 +592,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -638,7 +640,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -668,6 +670,7 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } + if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } @@ -686,7 +689,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -716,14 +719,12 @@ 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 (tags !== undefined) { queryParameters.tags = tags.toString(); } @@ -735,7 +736,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -764,7 +765,6 @@ export function createAnalyticsClient({ const requestPath = '/2/searches/noClicks'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; - if (index !== undefined) { queryParameters.index = index.toString(); } @@ -777,6 +777,7 @@ export function createAnalyticsClient({ if (limit !== undefined) { queryParameters.limit = limit.toString(); } + if (offset !== undefined) { queryParameters.offset = offset.toString(); } @@ -791,7 +792,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -829,10 +830,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(); } @@ -847,7 +848,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -879,7 +880,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -908,10 +909,10 @@ export function createAnalyticsClient({ const requestPath = '/2/countries'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; - if (index !== undefined) { queryParameters.index = index.toString(); } + if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } @@ -935,7 +936,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -968,20 +969,19 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } - if (search !== undefined) { queryParameters.search = search.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(); } @@ -996,7 +996,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1037,7 +1037,6 @@ export function createAnalyticsClient({ if (search !== undefined) { queryParameters.search = search.toString(); } - if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } @@ -1050,7 +1049,6 @@ export function createAnalyticsClient({ if (offset !== undefined) { queryParameters.offset = offset.toString(); } - if (tags !== undefined) { queryParameters.tags = tags.toString(); } @@ -1062,7 +1060,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1095,7 +1093,6 @@ export function createAnalyticsClient({ if (index !== undefined) { queryParameters.index = index.toString(); } - if (search !== undefined) { queryParameters.search = search.toString(); } @@ -1122,7 +1119,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1160,10 +1157,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(); } @@ -1173,10 +1170,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(); } @@ -1191,7 +1188,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1257,6 +1254,7 @@ export function createAnalyticsClient({ if (direction !== undefined) { queryParameters.direction = direction.toString(); } + if (limit !== undefined) { queryParameters.limit = limit.toString(); } @@ -1274,7 +1272,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1323,7 +1321,7 @@ export function createAnalyticsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-insights/builds/browser.ts b/packages/client-insights/builds/browser.ts index 18c8d66a7..3a73accbb 100644 --- a/packages/client-insights/builds/browser.ts +++ b/packages/client-insights/builds/browser.ts @@ -14,16 +14,17 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import type { Region } from '../src/insightsClient'; import { createInsightsClient, apiClientVersion, REGIONS } from '../src/insightsClient'; +export type InsightsClient = ReturnType; + export { apiClientVersion, Region } from '../src/insightsClient'; export * from '../model'; -/** - * The client type. - */ -export type InsightsClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function insightsClient(appId: string, apiKey: string, region?: Region, options?: ClientOptions) { +export function insightsClient( + appId: string, + apiKey: string, + region?: Region, + options?: ClientOptions, +): InsightsClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-insights/builds/node.ts b/packages/client-insights/builds/node.ts index 5d96eaf04..23acbbbec 100644 --- a/packages/client-insights/builds/node.ts +++ b/packages/client-insights/builds/node.ts @@ -13,16 +13,17 @@ import { createHttpRequester } from '@algolia/requester-node-http'; import type { Region } from '../src/insightsClient'; import { createInsightsClient, REGIONS } from '../src/insightsClient'; +export type InsightsClient = ReturnType; + export { apiClientVersion, Region } from '../src/insightsClient'; export * from '../model'; -/** - * The client type. - */ -export type InsightsClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function insightsClient(appId: string, apiKey: string, region?: Region, options?: ClientOptions) { +export function insightsClient( + appId: string, + apiKey: string, + region?: Region, + options?: ClientOptions, +): InsightsClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-insights/src/insightsClient.ts b/packages/client-insights/src/insightsClient.ts index 2d9ffac84..0dba9b4e3 100644 --- a/packages/client-insights/src/insightsClient.ts +++ b/packages/client-insights/src/insightsClient.ts @@ -41,27 +41,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -72,14 +71,16 @@ export function createInsightsClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -89,7 +90,7 @@ export function createInsightsClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -99,7 +100,7 @@ export function createInsightsClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** @@ -129,7 +130,7 @@ export function createInsightsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -156,7 +157,7 @@ export function createInsightsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -188,7 +189,7 @@ export function createInsightsClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -220,7 +221,7 @@ export function createInsightsClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -246,7 +247,7 @@ export function createInsightsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -276,7 +277,7 @@ export function createInsightsClient({ data: insightsEvents, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-personalization/builds/browser.ts b/packages/client-personalization/builds/browser.ts index 494c06855..5d0535fbd 100644 --- a/packages/client-personalization/builds/browser.ts +++ b/packages/client-personalization/builds/browser.ts @@ -14,16 +14,17 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import type { Region } from '../src/personalizationClient'; import { createPersonalizationClient, apiClientVersion, REGIONS } from '../src/personalizationClient'; +export type PersonalizationClient = ReturnType; + export { apiClientVersion, Region } from '../src/personalizationClient'; export * from '../model'; -/** - * The client type. - */ -export type PersonalizationClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function personalizationClient(appId: string, apiKey: string, region: Region, options?: ClientOptions) { +export function personalizationClient( + appId: string, + apiKey: string, + region: Region, + options?: ClientOptions, +): PersonalizationClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-personalization/builds/node.ts b/packages/client-personalization/builds/node.ts index 26ebb74d4..f6498a447 100644 --- a/packages/client-personalization/builds/node.ts +++ b/packages/client-personalization/builds/node.ts @@ -13,16 +13,17 @@ import { createHttpRequester } from '@algolia/requester-node-http'; import type { Region } from '../src/personalizationClient'; import { createPersonalizationClient, REGIONS } from '../src/personalizationClient'; +export type PersonalizationClient = ReturnType; + export { apiClientVersion, Region } from '../src/personalizationClient'; export * from '../model'; -/** - * The client type. - */ -export type PersonalizationClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function personalizationClient(appId: string, apiKey: string, region: Region, options?: ClientOptions) { +export function personalizationClient( + appId: string, + apiKey: string, + region: Region, + options?: ClientOptions, +): PersonalizationClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-personalization/src/personalizationClient.ts b/packages/client-personalization/src/personalizationClient.ts index 375635e7d..d63274d3c 100644 --- a/packages/client-personalization/src/personalizationClient.ts +++ b/packages/client-personalization/src/personalizationClient.ts @@ -44,27 +44,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -75,14 +74,16 @@ export function createPersonalizationClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -92,7 +93,7 @@ export function createPersonalizationClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -102,7 +103,7 @@ export function createPersonalizationClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** @@ -132,7 +133,7 @@ export function createPersonalizationClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -159,7 +160,7 @@ export function createPersonalizationClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -191,7 +192,7 @@ export function createPersonalizationClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -223,7 +224,7 @@ export function createPersonalizationClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -255,7 +256,7 @@ export function createPersonalizationClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -278,7 +279,7 @@ export function createPersonalizationClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -313,7 +314,7 @@ export function createPersonalizationClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -363,7 +364,7 @@ export function createPersonalizationClient({ data: personalizationStrategyParams, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-query-suggestions/builds/browser.ts b/packages/client-query-suggestions/builds/browser.ts index 30a40c33c..ec264e0a3 100644 --- a/packages/client-query-suggestions/builds/browser.ts +++ b/packages/client-query-suggestions/builds/browser.ts @@ -14,16 +14,17 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import type { Region } from '../src/querySuggestionsClient'; import { createQuerySuggestionsClient, apiClientVersion, REGIONS } from '../src/querySuggestionsClient'; +export type QuerySuggestionsClient = ReturnType; + export { apiClientVersion, Region } from '../src/querySuggestionsClient'; export * from '../model'; -/** - * The client type. - */ -export type QuerySuggestionsClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function querySuggestionsClient(appId: string, apiKey: string, region: Region, options?: ClientOptions) { +export function querySuggestionsClient( + appId: string, + apiKey: string, + region: Region, + options?: ClientOptions, +): QuerySuggestionsClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-query-suggestions/builds/node.ts b/packages/client-query-suggestions/builds/node.ts index 9c3488e0a..efcefbd23 100644 --- a/packages/client-query-suggestions/builds/node.ts +++ b/packages/client-query-suggestions/builds/node.ts @@ -13,16 +13,17 @@ import { createHttpRequester } from '@algolia/requester-node-http'; import type { Region } from '../src/querySuggestionsClient'; import { createQuerySuggestionsClient, REGIONS } from '../src/querySuggestionsClient'; +export type QuerySuggestionsClient = ReturnType; + export { apiClientVersion, Region } from '../src/querySuggestionsClient'; export * from '../model'; -/** - * The client type. - */ -export type QuerySuggestionsClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function querySuggestionsClient(appId: string, apiKey: string, region: Region, options?: ClientOptions) { +export function querySuggestionsClient( + appId: string, + apiKey: string, + region: Region, + options?: ClientOptions, +): QuerySuggestionsClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-query-suggestions/src/querySuggestionsClient.ts b/packages/client-query-suggestions/src/querySuggestionsClient.ts index 32f1ccc5d..14ccd54b3 100644 --- a/packages/client-query-suggestions/src/querySuggestionsClient.ts +++ b/packages/client-query-suggestions/src/querySuggestionsClient.ts @@ -48,27 +48,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -79,14 +78,16 @@ export function createQuerySuggestionsClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -96,7 +97,7 @@ export function createQuerySuggestionsClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -106,7 +107,7 @@ export function createQuerySuggestionsClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** @@ -138,7 +139,7 @@ export function createQuerySuggestionsClient({ data: configurationWithIndex, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -168,7 +169,7 @@ export function createQuerySuggestionsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -195,7 +196,7 @@ export function createQuerySuggestionsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -227,7 +228,7 @@ export function createQuerySuggestionsClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -259,7 +260,7 @@ export function createQuerySuggestionsClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -288,7 +289,7 @@ export function createQuerySuggestionsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -311,7 +312,7 @@ export function createQuerySuggestionsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -340,7 +341,7 @@ export function createQuerySuggestionsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -369,7 +370,7 @@ export function createQuerySuggestionsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -398,7 +399,7 @@ export function createQuerySuggestionsClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -440,7 +441,7 @@ export function createQuerySuggestionsClient({ data: configuration, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-search/builds/browser.ts b/packages/client-search/builds/browser.ts index e8f97503c..b9cb8f887 100644 --- a/packages/client-search/builds/browser.ts +++ b/packages/client-search/builds/browser.ts @@ -13,16 +13,12 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import { createSearchClient, apiClientVersion } from '../src/searchClient'; +export type SearchClient = ReturnType; + export { apiClientVersion } from '../src/searchClient'; export * from '../model'; -/** - * The client type. - */ -export type SearchClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function searchClient(appId: string, apiKey: string, options?: ClientOptions) { +export function searchClient(appId: string, apiKey: string, options?: ClientOptions): SearchClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-search/builds/node.ts b/packages/client-search/builds/node.ts index b7671344e..9362dd187 100644 --- a/packages/client-search/builds/node.ts +++ b/packages/client-search/builds/node.ts @@ -13,19 +13,19 @@ import { } from '@algolia/client-common'; import { createHttpRequester } from '@algolia/requester-node-http'; -import type { GenerateSecuredApiKeyOptions, GetSecuredApiKeyRemainingValidityOptions } from '../model'; +import type { + GenerateSecuredApiKeyOptions, + GetSecuredApiKeyRemainingValidityOptions, + SearchClientNodeHelpers, +} from '../model'; import { createSearchClient } from '../src/searchClient'; +export type SearchClient = ReturnType & SearchClientNodeHelpers; + export { apiClientVersion } from '../src/searchClient'; export * from '../model'; -/** - * The client type. - */ -export type SearchClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function searchClient(appId: string, apiKey: string, options?: ClientOptions) { +export function searchClient(appId: string, apiKey: string, options?: ClientOptions): SearchClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } @@ -50,7 +50,6 @@ export function searchClient(appId: string, apiKey: string, options?: ClientOpti hostsCache: createMemoryCache(), ...options, }), - /** * Helper: Generates a secured API key based on the given `parentApiKey` and given `restrictions`. * @@ -59,7 +58,7 @@ export function searchClient(appId: string, apiKey: string, options?: ClientOpti * @param generateSecuredApiKey.parentApiKey - The base API key from which to generate the new secured one. * @param generateSecuredApiKey.restrictions - A set of properties defining the restrictions of the secured API key. */ - generateSecuredApiKey({ parentApiKey, restrictions = {} }: GenerateSecuredApiKeyOptions): string { + generateSecuredApiKey: ({ parentApiKey, restrictions = {} }: GenerateSecuredApiKeyOptions): string => { let mergedRestrictions = restrictions; if (restrictions.searchParams) { // merge searchParams with the root restrictions @@ -95,7 +94,7 @@ export function searchClient(appId: string, apiKey: string, options?: ClientOpti * @param getSecuredApiKeyRemainingValidity - The `getSecuredApiKeyRemainingValidity` object. * @param getSecuredApiKeyRemainingValidity.securedApiKey - The secured API key generated with the `generateSecuredApiKey` method. */ - getSecuredApiKeyRemainingValidity({ securedApiKey }: GetSecuredApiKeyRemainingValidityOptions): number { + getSecuredApiKeyRemainingValidity: ({ securedApiKey }: GetSecuredApiKeyRemainingValidityOptions): number => { const decodedString = Buffer.from(securedApiKey, 'base64').toString('ascii'); const regex = /validUntil=(\d+)/; const match = decodedString.match(regex); diff --git a/packages/client-search/model/clientMethodProps.ts b/packages/client-search/model/clientMethodProps.ts index 9eb60ca42..4de7d1a01 100644 --- a/packages/client-search/model/clientMethodProps.ts +++ b/packages/client-search/model/clientMethodProps.ts @@ -803,6 +803,11 @@ export type GetSecuredApiKeyRemainingValidityOptions = { securedApiKey: string; }; +export type SearchClientNodeHelpers = { + generateSecuredApiKey: (opts: GenerateSecuredApiKeyOptions) => string; + getSecuredApiKeyRemainingValidity: (opts: GetSecuredApiKeyRemainingValidityOptions) => number; +}; + export type DeleteObjectsOptions = Pick & { /** * The objectIDs to delete. diff --git a/packages/client-search/src/searchClient.ts b/packages/client-search/src/searchClient.ts index 70efdb33f..dc1b81da1 100644 --- a/packages/client-search/src/searchClient.ts +++ b/packages/client-search/src/searchClient.ts @@ -174,27 +174,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -205,14 +204,16 @@ export function createSearchClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -222,7 +223,7 @@ export function createSearchClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -232,7 +233,7 @@ export function createSearchClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** @@ -733,7 +734,7 @@ export function createSearchClient({ data: apiKey, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -778,7 +779,7 @@ export function createSearchClient({ data: body, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -811,7 +812,7 @@ export function createSearchClient({ data: source, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -857,7 +858,7 @@ export function createSearchClient({ data: assignUserIdParams, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -893,7 +894,7 @@ export function createSearchClient({ data: batchWriteParams, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -942,7 +943,7 @@ export function createSearchClient({ data: batchAssignUserIdsParams, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -989,7 +990,7 @@ export function createSearchClient({ data: batchDictionaryEntriesParams, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1020,7 +1021,7 @@ export function createSearchClient({ data: browseParams ? browseParams : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1049,7 +1050,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1085,7 +1086,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1121,7 +1122,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1151,7 +1152,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1178,7 +1179,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1210,7 +1211,7 @@ export function createSearchClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1242,7 +1243,7 @@ export function createSearchClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1271,7 +1272,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1309,7 +1310,7 @@ export function createSearchClient({ data: deleteByParams, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1338,7 +1339,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1377,7 +1378,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1409,6 +1410,7 @@ export function createSearchClient({ .replace('{objectID}', encodeURIComponent(objectID)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (forwardToReplicas !== undefined) { queryParameters.forwardToReplicas = forwardToReplicas.toString(); } @@ -1420,7 +1422,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1449,7 +1451,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1492,7 +1494,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1518,7 +1520,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1547,7 +1549,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1570,7 +1572,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1593,7 +1595,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1619,10 +1621,10 @@ export function createSearchClient({ if (offset !== undefined) { queryParameters.offset = offset.toString(); } - if (length !== undefined) { queryParameters.length = length.toString(); } + if (indexName !== undefined) { queryParameters.indexName = indexName.toString(); } @@ -1637,7 +1639,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1669,7 +1671,6 @@ export function createSearchClient({ .replace('{objectID}', encodeURIComponent(objectID)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; - if (attributesToRetrieve !== undefined) { queryParameters.attributesToRetrieve = attributesToRetrieve.toString(); } @@ -1681,7 +1682,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1716,7 +1717,7 @@ export function createSearchClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1752,7 +1753,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1781,7 +1782,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1804,7 +1805,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1840,7 +1841,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1876,7 +1877,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1899,7 +1900,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1928,7 +1929,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1959,7 +1960,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1982,7 +1983,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2005,7 +2006,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2040,7 +2041,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2064,7 +2065,6 @@ export function createSearchClient({ if (page !== undefined) { queryParameters.page = page.toString(); } - if (hitsPerPage !== undefined) { queryParameters.hitsPerPage = hitsPerPage.toString(); } @@ -2076,7 +2076,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2106,7 +2106,7 @@ export function createSearchClient({ data: batchParams, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2151,7 +2151,7 @@ export function createSearchClient({ data: operationIndexParams, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2200,7 +2200,7 @@ export function createSearchClient({ data: attributesToUpdate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2229,7 +2229,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2259,7 +2259,7 @@ export function createSearchClient({ data: source, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2288,7 +2288,7 @@ export function createSearchClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2323,7 +2323,7 @@ export function createSearchClient({ data: body, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2364,6 +2364,7 @@ export function createSearchClient({ .replace('{objectID}', encodeURIComponent(objectID)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (forwardToReplicas !== undefined) { queryParameters.forwardToReplicas = forwardToReplicas.toString(); } @@ -2376,7 +2377,7 @@ export function createSearchClient({ data: rule, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2423,7 +2424,7 @@ export function createSearchClient({ data: rules, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2467,6 +2468,7 @@ export function createSearchClient({ .replace('{objectID}', encodeURIComponent(objectID)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (forwardToReplicas !== undefined) { queryParameters.forwardToReplicas = forwardToReplicas.toString(); } @@ -2479,7 +2481,7 @@ export function createSearchClient({ data: synonymHit, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2510,6 +2512,7 @@ export function createSearchClient({ const requestPath = '/1/indexes/{indexName}/synonyms/batch'.replace('{indexName}', encodeURIComponent(indexName)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (forwardToReplicas !== undefined) { queryParameters.forwardToReplicas = forwardToReplicas.toString(); } @@ -2525,7 +2528,7 @@ export function createSearchClient({ data: synonymHit, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2588,7 +2591,7 @@ export function createSearchClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2639,7 +2642,7 @@ export function createSearchClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2682,7 +2685,7 @@ export function createSearchClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2718,7 +2721,7 @@ export function createSearchClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2754,7 +2757,7 @@ export function createSearchClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2793,7 +2796,7 @@ export function createSearchClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2831,7 +2834,7 @@ export function createSearchClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2869,7 +2872,7 @@ export function createSearchClient({ data: dictionarySettingsParams, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2911,7 +2914,7 @@ export function createSearchClient({ data: indexSettings, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2950,7 +2953,7 @@ export function createSearchClient({ data: apiKey, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; } diff --git a/packages/client-usage/builds/browser.ts b/packages/client-usage/builds/browser.ts index 09583319b..e29efe755 100644 --- a/packages/client-usage/builds/browser.ts +++ b/packages/client-usage/builds/browser.ts @@ -13,16 +13,12 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import { createUsageClient, apiClientVersion } from '../src/usageClient'; +export type UsageClient = ReturnType; + export { apiClientVersion } from '../src/usageClient'; export * from '../model'; -/** - * The client type. - */ -export type UsageClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function usageClient(appId: string, apiKey: string, options?: ClientOptions) { +export function usageClient(appId: string, apiKey: string, options?: ClientOptions): UsageClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-usage/builds/node.ts b/packages/client-usage/builds/node.ts index 554889c1c..a94eef922 100644 --- a/packages/client-usage/builds/node.ts +++ b/packages/client-usage/builds/node.ts @@ -12,16 +12,12 @@ import { createHttpRequester } from '@algolia/requester-node-http'; import { createUsageClient } from '../src/usageClient'; +export type UsageClient = ReturnType; + export { apiClientVersion } from '../src/usageClient'; export * from '../model'; -/** - * The client type. - */ -export type UsageClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function usageClient(appId: string, apiKey: string, options?: ClientOptions) { +export function usageClient(appId: string, apiKey: string, options?: ClientOptions): UsageClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/client-usage/src/usageClient.ts b/packages/client-usage/src/usageClient.ts index 863323a89..5a71e7a70 100644 --- a/packages/client-usage/src/usageClient.ts +++ b/packages/client-usage/src/usageClient.ts @@ -35,27 +35,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -66,14 +65,16 @@ export function createUsageClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -83,7 +84,7 @@ export function createUsageClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -93,7 +94,7 @@ export function createUsageClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** @@ -123,7 +124,7 @@ export function createUsageClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -150,7 +151,7 @@ export function createUsageClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -182,7 +183,7 @@ export function createUsageClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -214,7 +215,7 @@ export function createUsageClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -259,6 +260,7 @@ export function createUsageClient({ if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } + if (granularity !== undefined) { queryParameters.granularity = granularity.toString(); } @@ -270,7 +272,7 @@ export function createUsageClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -320,7 +322,7 @@ export function createUsageClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; } diff --git a/packages/ingestion/builds/browser.ts b/packages/ingestion/builds/browser.ts index 97dd8b381..5a0f5e685 100644 --- a/packages/ingestion/builds/browser.ts +++ b/packages/ingestion/builds/browser.ts @@ -14,6 +14,8 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import type { Region } from '../src/ingestionClient'; import { createIngestionClient, apiClientVersion, REGIONS } from '../src/ingestionClient'; +export type IngestionClient = ReturnType; + export { apiClientVersion, Region, @@ -23,13 +25,12 @@ export { } from '../src/ingestionClient'; export * from '../model'; -/** - * The client type. - */ -export type IngestionClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function ingestionClient(appId: string, apiKey: string, region: Region, options?: ClientOptions) { +export function ingestionClient( + appId: string, + apiKey: string, + region: Region, + options?: ClientOptions, +): IngestionClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/ingestion/builds/node.ts b/packages/ingestion/builds/node.ts index 78863d25e..f11600894 100644 --- a/packages/ingestion/builds/node.ts +++ b/packages/ingestion/builds/node.ts @@ -13,6 +13,8 @@ import { createHttpRequester } from '@algolia/requester-node-http'; import type { Region } from '../src/ingestionClient'; import { createIngestionClient, REGIONS } from '../src/ingestionClient'; +export type IngestionClient = ReturnType; + export { apiClientVersion, Region, @@ -22,13 +24,12 @@ export { } from '../src/ingestionClient'; export * from '../model'; -/** - * The client type. - */ -export type IngestionClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function ingestionClient(appId: string, apiKey: string, region: Region, options?: ClientOptions) { +export function ingestionClient( + appId: string, + apiKey: string, + region: Region, + options?: ClientOptions, +): IngestionClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/ingestion/src/ingestionClient.ts b/packages/ingestion/src/ingestionClient.ts index 29b0ab116..269708659 100644 --- a/packages/ingestion/src/ingestionClient.ts +++ b/packages/ingestion/src/ingestionClient.ts @@ -158,27 +158,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -189,14 +188,16 @@ export function createIngestionClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -206,7 +207,7 @@ export function createIngestionClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -216,7 +217,7 @@ export function createIngestionClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** @@ -260,7 +261,7 @@ export function createIngestionClient({ data: authenticationCreate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -304,7 +305,7 @@ export function createIngestionClient({ data: destinationCreate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -342,7 +343,7 @@ export function createIngestionClient({ data: sourceCreate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -378,7 +379,7 @@ export function createIngestionClient({ data: taskCreate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -417,7 +418,7 @@ export function createIngestionClient({ data: taskCreate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -453,7 +454,7 @@ export function createIngestionClient({ data: transformationCreate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -483,7 +484,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -510,7 +511,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -542,7 +543,7 @@ export function createIngestionClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -574,7 +575,7 @@ export function createIngestionClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -611,7 +612,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -648,7 +649,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -679,7 +680,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -705,7 +706,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -731,7 +732,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -763,7 +764,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -794,7 +795,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -825,7 +826,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -856,7 +857,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -887,7 +888,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -934,7 +935,7 @@ export function createIngestionClient({ data: generateTransformationCodePayload, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -971,7 +972,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1005,7 +1006,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1043,7 +1044,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1074,7 +1075,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1105,7 +1106,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1136,7 +1137,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1167,7 +1168,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1204,7 +1205,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1231,6 +1232,7 @@ export function createIngestionClient({ const requestPath = '/1/authentications'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (itemsPerPage !== undefined) { queryParameters.itemsPerPage = itemsPerPage.toString(); } @@ -1240,6 +1242,7 @@ export function createIngestionClient({ if (type !== undefined) { queryParameters.type = type.toString(); } + if (platform !== undefined) { queryParameters.platform = platform.toString(); } @@ -1257,7 +1260,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1311,7 +1314,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1345,13 +1348,14 @@ export function createIngestionClient({ const requestPath = '/1/runs/{runID}/events'.replace('{runID}', encodeURIComponent(runID)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (itemsPerPage !== undefined) { queryParameters.itemsPerPage = itemsPerPage.toString(); } - if (page !== undefined) { queryParameters.page = page.toString(); } + if (status !== undefined) { queryParameters.status = status.toString(); } @@ -1364,6 +1368,7 @@ export function createIngestionClient({ if (order !== undefined) { queryParameters.order = order.toString(); } + if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } @@ -1378,7 +1383,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1411,16 +1416,17 @@ export function createIngestionClient({ if (itemsPerPage !== undefined) { queryParameters.itemsPerPage = itemsPerPage.toString(); } + if (page !== undefined) { queryParameters.page = page.toString(); } - if (status !== undefined) { queryParameters.status = status.toString(); } if (type !== undefined) { queryParameters.type = type.toString(); } + if (taskID !== undefined) { queryParameters.taskID = taskID.toString(); } @@ -1434,7 +1440,6 @@ export function createIngestionClient({ if (startDate !== undefined) { queryParameters.startDate = startDate.toString(); } - if (endDate !== undefined) { queryParameters.endDate = endDate.toString(); } @@ -1446,7 +1451,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1476,19 +1481,20 @@ export function createIngestionClient({ if (itemsPerPage !== undefined) { queryParameters.itemsPerPage = itemsPerPage.toString(); } - if (page !== undefined) { queryParameters.page = page.toString(); } if (type !== undefined) { queryParameters.type = type.toString(); } + if (authenticationID !== undefined) { queryParameters.authenticationID = authenticationID.toString(); } if (sort !== undefined) { queryParameters.sort = sort.toString(); } + if (order !== undefined) { queryParameters.order = order.toString(); } @@ -1500,7 +1506,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1539,6 +1545,7 @@ export function createIngestionClient({ if (action !== undefined) { queryParameters.action = action.toString(); } + if (enabled !== undefined) { queryParameters.enabled = enabled.toString(); } @@ -1566,7 +1573,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1605,13 +1612,13 @@ export function createIngestionClient({ 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(); } @@ -1621,6 +1628,7 @@ export function createIngestionClient({ if (sort !== undefined) { queryParameters.sort = sort.toString(); } + if (order !== undefined) { queryParameters.order = order.toString(); } @@ -1632,7 +1640,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1657,7 +1665,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1682,13 +1690,13 @@ export function createIngestionClient({ const requestPath = '/1/transformations'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; + if (itemsPerPage !== undefined) { queryParameters.itemsPerPage = itemsPerPage.toString(); } if (page !== undefined) { queryParameters.page = page.toString(); } - if (sort !== undefined) { queryParameters.sort = sort.toString(); } @@ -1703,7 +1711,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1747,7 +1755,7 @@ export function createIngestionClient({ data: pushTaskPayload, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1783,7 +1791,7 @@ export function createIngestionClient({ data: runSourcePayload ? runSourcePayload : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1814,7 +1822,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1845,7 +1853,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1885,7 +1893,7 @@ export function createIngestionClient({ data: authenticationSearch, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1920,7 +1928,7 @@ export function createIngestionClient({ data: destinationSearch, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1955,7 +1963,7 @@ export function createIngestionClient({ data: sourceSearch, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -1990,7 +1998,7 @@ export function createIngestionClient({ data: taskSearch, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2025,7 +2033,7 @@ export function createIngestionClient({ data: taskSearch, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2065,7 +2073,7 @@ export function createIngestionClient({ data: transformationSearch, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2099,7 +2107,7 @@ export function createIngestionClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2140,7 +2148,7 @@ export function createIngestionClient({ data: transformationTry, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2192,7 +2200,7 @@ export function createIngestionClient({ data: transformationTry, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2235,7 +2243,7 @@ export function createIngestionClient({ data: authenticationUpdate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2278,7 +2286,7 @@ export function createIngestionClient({ data: destinationUpdate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2318,7 +2326,7 @@ export function createIngestionClient({ data: sourceUpdate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2350,7 +2358,7 @@ export function createIngestionClient({ data: taskUpdate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2385,7 +2393,7 @@ export function createIngestionClient({ data: taskUpdate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2430,7 +2438,7 @@ export function createIngestionClient({ data: transformationCreate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2460,7 +2468,7 @@ export function createIngestionClient({ data: sourceCreate ? sourceCreate : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -2500,7 +2508,7 @@ export function createIngestionClient({ data: sourceUpdate, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; } diff --git a/packages/monitoring/builds/browser.ts b/packages/monitoring/builds/browser.ts index 1eaa63cd4..99197be7e 100644 --- a/packages/monitoring/builds/browser.ts +++ b/packages/monitoring/builds/browser.ts @@ -13,16 +13,12 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import { createMonitoringClient, apiClientVersion } from '../src/monitoringClient'; +export type MonitoringClient = ReturnType; + export { apiClientVersion } from '../src/monitoringClient'; export * from '../model'; -/** - * The client type. - */ -export type MonitoringClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function monitoringClient(appId: string, apiKey: string, options?: ClientOptions) { +export function monitoringClient(appId: string, apiKey: string, options?: ClientOptions): MonitoringClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/monitoring/builds/node.ts b/packages/monitoring/builds/node.ts index 6ac3eead7..6b27f4c47 100644 --- a/packages/monitoring/builds/node.ts +++ b/packages/monitoring/builds/node.ts @@ -12,16 +12,12 @@ import { createHttpRequester } from '@algolia/requester-node-http'; import { createMonitoringClient } from '../src/monitoringClient'; +export type MonitoringClient = ReturnType; + export { apiClientVersion } from '../src/monitoringClient'; export * from '../model'; -/** - * The client type. - */ -export type MonitoringClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function monitoringClient(appId: string, apiKey: string, options?: ClientOptions) { +export function monitoringClient(appId: string, apiKey: string, options?: ClientOptions): MonitoringClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/monitoring/src/monitoringClient.ts b/packages/monitoring/src/monitoringClient.ts index 5ac8bd7bf..b3151b2f8 100644 --- a/packages/monitoring/src/monitoringClient.ts +++ b/packages/monitoring/src/monitoringClient.ts @@ -44,27 +44,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -75,14 +74,16 @@ export function createMonitoringClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -92,7 +93,7 @@ export function createMonitoringClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -102,7 +103,7 @@ export function createMonitoringClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** @@ -132,7 +133,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -159,7 +160,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -191,7 +192,7 @@ export function createMonitoringClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -223,7 +224,7 @@ export function createMonitoringClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -252,7 +253,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -278,7 +279,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -298,7 +299,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -327,7 +328,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -353,7 +354,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -386,7 +387,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -415,7 +416,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -435,7 +436,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -455,7 +456,7 @@ export function createMonitoringClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; } diff --git a/packages/recommend/builds/browser.ts b/packages/recommend/builds/browser.ts index 96da26562..346814107 100644 --- a/packages/recommend/builds/browser.ts +++ b/packages/recommend/builds/browser.ts @@ -13,16 +13,12 @@ import { createXhrRequester } from '@algolia/requester-browser-xhr'; import { createRecommendClient, apiClientVersion } from '../src/recommendClient'; +export type RecommendClient = ReturnType; + export { apiClientVersion } from '../src/recommendClient'; export * from '../model'; -/** - * The client type. - */ -export type RecommendClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function recommendClient(appId: string, apiKey: string, options?: ClientOptions) { +export function recommendClient(appId: string, apiKey: string, options?: ClientOptions): RecommendClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/recommend/builds/node.ts b/packages/recommend/builds/node.ts index 4bd89f555..725216a7f 100644 --- a/packages/recommend/builds/node.ts +++ b/packages/recommend/builds/node.ts @@ -12,16 +12,12 @@ import { createHttpRequester } from '@algolia/requester-node-http'; import { createRecommendClient } from '../src/recommendClient'; +export type RecommendClient = ReturnType; + export { apiClientVersion } from '../src/recommendClient'; export * from '../model'; -/** - * The client type. - */ -export type RecommendClient = ReturnType; - -// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -export function recommendClient(appId: string, apiKey: string, options?: ClientOptions) { +export function recommendClient(appId: string, apiKey: string, options?: ClientOptions): RecommendClient { if (!appId || typeof appId !== 'string') { throw new Error('`appId` is missing.'); } diff --git a/packages/recommend/src/recommendClient.ts b/packages/recommend/src/recommendClient.ts index 903f1b413..b83cb75c9 100644 --- a/packages/recommend/src/recommendClient.ts +++ b/packages/recommend/src/recommendClient.ts @@ -74,27 +74,26 @@ 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, + 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, + }, + }), /** * The `appId` currently in use. @@ -105,14 +104,16 @@ export function createRecommendClient({ * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { - return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); + return Promise.all([this.transporter.requestsCache.clear(), this.transporter.responsesCache.clear()]).then( + () => undefined, + ); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { - return transporter.algoliaAgent.value; + return this.transporter.algoliaAgent.value; }, /** @@ -122,7 +123,7 @@ export function createRecommendClient({ * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string): void { - transporter.algoliaAgent.add({ segment, version }); + this.transporter.algoliaAgent.add({ segment, version }); }, /** @@ -132,7 +133,7 @@ export function createRecommendClient({ * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { - transporter.baseHeaders['x-algolia-api-key'] = apiKey; + this.transporter.baseHeaders['x-algolia-api-key'] = apiKey; }, /** @@ -162,7 +163,7 @@ export function createRecommendClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -189,7 +190,7 @@ export function createRecommendClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -221,7 +222,7 @@ export function createRecommendClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -253,7 +254,7 @@ export function createRecommendClient({ data: body ? body : {}, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -298,7 +299,7 @@ export function createRecommendClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -343,7 +344,7 @@ export function createRecommendClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -388,7 +389,7 @@ export function createRecommendClient({ headers, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -435,7 +436,7 @@ export function createRecommendClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, /** @@ -478,7 +479,7 @@ export function createRecommendClient({ cacheable: true, }; - return transporter.request(request, requestOptions); + return this.transporter.request(request, requestOptions); }, }; }