diff --git a/clients/algoliasearch-client-javascript/packages/client-abtesting/builds/browser.ts b/clients/algoliasearch-client-javascript/packages/client-abtesting/builds/browser.ts index ba25fb6fc6..69931b4968 100644 --- a/clients/algoliasearch-client-javascript/packages/client-abtesting/builds/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/client-abtesting/builds/browser.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createFallbackableCache, @@ -18,7 +15,7 @@ export function abtestingApi( appId: string, apiKey: string, region?: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): AbtestingApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -40,14 +37,19 @@ export function abtestingApi( requester: options?.requester ?? createXhrRequester(), userAgents: [{ segment: 'Browser' }], authMode: 'WithinQueryParameters', - responsesCache: createMemoryCache(), - requestsCache: createMemoryCache({ serializable: false }), - hostsCache: createFallbackableCache({ - caches: [ - createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), - createMemoryCache(), - ], - }), + responsesCache: options?.responsesCache ?? createMemoryCache(), + requestsCache: + options?.requestsCache ?? createMemoryCache({ serializable: false }), + hostsCache: + options?.hostsCache ?? + createFallbackableCache({ + caches: [ + createBrowserLocalStorageCache({ + key: `${apiClientVersion}-${appId}`, + }), + createMemoryCache(), + ], + }), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-abtesting/builds/node.ts b/clients/algoliasearch-client-javascript/packages/client-abtesting/builds/node.ts index 408f7ae690..5fd7a725c3 100644 --- a/clients/algoliasearch-client-javascript/packages/client-abtesting/builds/node.ts +++ b/clients/algoliasearch-client-javascript/packages/client-abtesting/builds/node.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createNullCache, @@ -17,7 +14,7 @@ export function abtestingApi( appId: string, apiKey: string, region?: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): AbtestingApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -38,9 +35,9 @@ export function abtestingApi( }, requester: options?.requester ?? createHttpRequester(), userAgents: [{ segment: 'Node.js', version: process.versions.node }], - responsesCache: createNullCache(), - requestsCache: createNullCache(), - hostsCache: createMemoryCache(), + responsesCache: options?.responsesCache ?? createNullCache(), + requestsCache: options?.requestsCache ?? createNullCache(), + hostsCache: options?.hostsCache ?? createMemoryCache(), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts b/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts index 31ee1ec37e..49a5e40758 100644 --- a/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts +++ b/clients/algoliasearch-client-javascript/packages/client-abtesting/src/abtestingApi.ts @@ -8,6 +8,8 @@ import type { Headers, Host, Request, + RequestOptions, + QueryParameters, } from '@experimental-api-clients-automation/client-common'; import type { ABTest } from '../model/aBTest'; @@ -67,11 +69,12 @@ export function createAbtestingApi( * @param addABTestsRequest - The addABTestsRequest object. */ function addABTests( - addABTestsRequest: AddABTestsRequest + addABTestsRequest: AddABTestsRequest, + requestOptions?: RequestOptions ): Promise { const requestPath = '/2/abtests'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!addABTestsRequest) { throw new Error( @@ -101,10 +104,14 @@ export function createAbtestingApi( data: addABTestsRequest, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -116,17 +123,16 @@ export function createAbtestingApi( * @param del.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param del.body - The parameters to send with the custom request. */ - function del({ - path, - parameters, - body, - }: DelProps): Promise> { + function del( + { path, parameters, body }: DelProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `del`.'); @@ -142,10 +148,14 @@ export function createAbtestingApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -155,13 +165,16 @@ export function createAbtestingApi( * @param deleteABTest - The deleteABTest object. * @param deleteABTest.id - The A/B test ID. */ - function deleteABTest({ id }: DeleteABTestProps): Promise { + function deleteABTest( + { id }: DeleteABTestProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/abtests/{id}'.replace( '{id}', encodeURIComponent(String(id)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!id) { throw new Error( @@ -174,10 +187,14 @@ export function createAbtestingApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -188,13 +205,16 @@ export function createAbtestingApi( * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. * @param get.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. */ - function get({ path, parameters }: GetProps): Promise> { + function get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `get`.'); @@ -209,10 +229,14 @@ export function createAbtestingApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -222,13 +246,16 @@ export function createAbtestingApi( * @param getABTest - The getABTest object. * @param getABTest.id - The A/B test ID. */ - function getABTest({ id }: GetABTestProps): Promise { + function getABTest( + { id }: GetABTestProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/abtests/{id}'.replace( '{id}', encodeURIComponent(String(id)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!id) { throw new Error('Parameter `id` is required when calling `getABTest`.'); @@ -239,10 +266,14 @@ export function createAbtestingApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -253,13 +284,13 @@ export function createAbtestingApi( * @param listABTests.offset - Position of the starting record. Used for paging. 0 is the first record. * @param listABTests.limit - Number of records to return. Limit is the size of the page. */ - function listABTests({ - offset, - limit, - }: ListABTestsProps): Promise { + function listABTests( + { offset, limit }: ListABTestsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/abtests'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (offset !== undefined) { queryParameters.offset = offset.toString(); @@ -274,10 +305,14 @@ export function createAbtestingApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -289,17 +324,16 @@ export function createAbtestingApi( * @param post.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param post.body - The parameters to send with the custom request. */ - function post({ - path, - parameters, - body, - }: PostProps): Promise> { + function post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `post`.'); @@ -315,10 +349,14 @@ export function createAbtestingApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -330,17 +368,16 @@ export function createAbtestingApi( * @param put.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param put.body - The parameters to send with the custom request. */ - function put({ - path, - parameters, - body, - }: PutProps): Promise> { + function put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `put`.'); @@ -356,10 +393,14 @@ export function createAbtestingApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -369,13 +410,16 @@ export function createAbtestingApi( * @param stopABTest - The stopABTest object. * @param stopABTest.id - The A/B test ID. */ - function stopABTest({ id }: StopABTestProps): Promise { + function stopABTest( + { id }: StopABTestProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/abtests/{id}/stop'.replace( '{id}', encodeURIComponent(String(id)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!id) { throw new Error('Parameter `id` is required when calling `stopABTest`.'); @@ -386,10 +430,14 @@ export function createAbtestingApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } return { diff --git a/clients/algoliasearch-client-javascript/packages/client-analytics/builds/browser.ts b/clients/algoliasearch-client-javascript/packages/client-analytics/builds/browser.ts index 2f5fbcae07..cf5e81e09d 100644 --- a/clients/algoliasearch-client-javascript/packages/client-analytics/builds/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/client-analytics/builds/browser.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createFallbackableCache, @@ -18,7 +15,7 @@ export function analyticsApi( appId: string, apiKey: string, region?: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): AnalyticsApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -40,14 +37,19 @@ export function analyticsApi( requester: options?.requester ?? createXhrRequester(), userAgents: [{ segment: 'Browser' }], authMode: 'WithinQueryParameters', - responsesCache: createMemoryCache(), - requestsCache: createMemoryCache({ serializable: false }), - hostsCache: createFallbackableCache({ - caches: [ - createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), - createMemoryCache(), - ], - }), + responsesCache: options?.responsesCache ?? createMemoryCache(), + requestsCache: + options?.requestsCache ?? createMemoryCache({ serializable: false }), + hostsCache: + options?.hostsCache ?? + createFallbackableCache({ + caches: [ + createBrowserLocalStorageCache({ + key: `${apiClientVersion}-${appId}`, + }), + createMemoryCache(), + ], + }), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-analytics/builds/node.ts b/clients/algoliasearch-client-javascript/packages/client-analytics/builds/node.ts index 11fd640888..1f922cd3ff 100644 --- a/clients/algoliasearch-client-javascript/packages/client-analytics/builds/node.ts +++ b/clients/algoliasearch-client-javascript/packages/client-analytics/builds/node.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createNullCache, @@ -17,7 +14,7 @@ export function analyticsApi( appId: string, apiKey: string, region?: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): AnalyticsApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -38,9 +35,9 @@ export function analyticsApi( }, requester: options?.requester ?? createHttpRequester(), userAgents: [{ segment: 'Node.js', version: process.versions.node }], - responsesCache: createNullCache(), - requestsCache: createNullCache(), - hostsCache: createMemoryCache(), + responsesCache: options?.responsesCache ?? createNullCache(), + requestsCache: options?.requestsCache ?? createNullCache(), + hostsCache: options?.hostsCache ?? createMemoryCache(), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts b/clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts index 146b1ff8b4..146d97cade 100644 --- a/clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts +++ b/clients/algoliasearch-client-javascript/packages/client-analytics/src/analyticsApi.ts @@ -8,6 +8,8 @@ import type { Headers, Host, Request, + RequestOptions, + QueryParameters, } from '@experimental-api-clients-automation/client-common'; import type { GetAverageClickPositionResponse } from '../model/getAverageClickPositionResponse'; @@ -82,17 +84,16 @@ export function createAnalyticsApi( * @param del.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param del.body - The parameters to send with the custom request. */ - function del({ - path, - parameters, - body, - }: DelProps): Promise> { + function del( + { path, parameters, body }: DelProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `del`.'); @@ -108,10 +109,14 @@ export function createAnalyticsApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -122,13 +127,16 @@ export function createAnalyticsApi( * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. * @param get.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. */ - function get({ path, parameters }: GetProps): Promise> { + function get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `get`.'); @@ -143,10 +151,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -159,15 +171,13 @@ export function createAnalyticsApi( * @param getAverageClickPosition.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getAverageClickPosition.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getAverageClickPosition({ - index, - startDate, - endDate, - tags, - }: GetAverageClickPositionProps): Promise { + function getAverageClickPosition( + { index, startDate, endDate, tags }: GetAverageClickPositionProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/clicks/averageClickPosition'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -196,10 +206,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -212,15 +226,13 @@ export function createAnalyticsApi( * @param getClickPositions.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getClickPositions.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getClickPositions({ - index, - startDate, - endDate, - tags, - }: GetClickPositionsProps): Promise { + function getClickPositions( + { index, startDate, endDate, tags }: GetClickPositionsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/clicks/positions'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -249,10 +261,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -265,15 +281,13 @@ export function createAnalyticsApi( * @param getClickThroughRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getClickThroughRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getClickThroughRate({ - index, - startDate, - endDate, - tags, - }: GetClickThroughRateProps): Promise { + function getClickThroughRate( + { index, startDate, endDate, tags }: GetClickThroughRateProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/clicks/clickThroughRate'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -302,10 +316,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -318,15 +336,13 @@ export function createAnalyticsApi( * @param getConversationRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getConversationRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getConversationRate({ - index, - startDate, - endDate, - tags, - }: GetConversationRateProps): Promise { + function getConversationRate( + { index, startDate, endDate, tags }: GetConversationRateProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/conversions/conversionRate'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -355,10 +371,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -371,15 +391,13 @@ export function createAnalyticsApi( * @param getNoClickRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getNoClickRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getNoClickRate({ - index, - startDate, - endDate, - tags, - }: GetNoClickRateProps): Promise { + function getNoClickRate( + { index, startDate, endDate, tags }: GetNoClickRateProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/searches/noClickRate'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -408,10 +426,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -424,15 +446,13 @@ export function createAnalyticsApi( * @param getNoResultsRate.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getNoResultsRate.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getNoResultsRate({ - index, - startDate, - endDate, - tags, - }: GetNoResultsRateProps): Promise { + function getNoResultsRate( + { index, startDate, endDate, tags }: GetNoResultsRateProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/searches/noResultRate'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -461,10 +481,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -477,15 +501,13 @@ export function createAnalyticsApi( * @param getSearchesCount.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getSearchesCount.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getSearchesCount({ - index, - startDate, - endDate, - tags, - }: GetSearchesCountProps): Promise { + function getSearchesCount( + { index, startDate, endDate, tags }: GetSearchesCountProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/searches/count'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -514,10 +536,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -532,17 +558,20 @@ export function createAnalyticsApi( * @param getSearchesNoClicks.offset - Position of the starting record. Used for paging. 0 is the first record. * @param getSearchesNoClicks.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getSearchesNoClicks({ - index, - startDate, - endDate, - limit, - offset, - tags, - }: GetSearchesNoClicksProps): Promise { + function getSearchesNoClicks( + { + index, + startDate, + endDate, + limit, + offset, + tags, + }: GetSearchesNoClicksProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/searches/noClicks'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -579,10 +608,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -597,17 +630,20 @@ export function createAnalyticsApi( * @param getSearchesNoResults.offset - Position of the starting record. Used for paging. 0 is the first record. * @param getSearchesNoResults.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getSearchesNoResults({ - index, - startDate, - endDate, - limit, - offset, - tags, - }: GetSearchesNoResultsProps): Promise { + function getSearchesNoResults( + { + index, + startDate, + endDate, + limit, + offset, + tags, + }: GetSearchesNoResultsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/searches/noResults'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -644,10 +680,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -657,10 +697,13 @@ export function createAnalyticsApi( * @param getStatus - The getStatus object. * @param getStatus.index - The index name to target. */ - function getStatus({ index }: GetStatusProps): Promise { + function getStatus( + { index }: GetStatusProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/status'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -677,10 +720,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -695,17 +742,13 @@ export function createAnalyticsApi( * @param getTopCountries.offset - Position of the starting record. Used for paging. 0 is the first record. * @param getTopCountries.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getTopCountries({ - index, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopCountriesProps): Promise { + function getTopCountries( + { index, startDate, endDate, limit, offset, tags }: GetTopCountriesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/countries'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -742,10 +785,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -761,18 +808,21 @@ export function createAnalyticsApi( * @param getTopFilterAttributes.offset - Position of the starting record. Used for paging. 0 is the first record. * @param getTopFilterAttributes.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getTopFilterAttributes({ - index, - search, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopFilterAttributesProps): Promise { + function getTopFilterAttributes( + { + index, + search, + startDate, + endDate, + limit, + offset, + tags, + }: GetTopFilterAttributesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/filters'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -813,10 +863,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -833,22 +887,25 @@ export function createAnalyticsApi( * @param getTopFilterForAttribute.offset - Position of the starting record. Used for paging. 0 is the first record. * @param getTopFilterForAttribute.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getTopFilterForAttribute({ - attribute, - index, - search, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopFilterForAttributeProps): Promise { + function getTopFilterForAttribute( + { + attribute, + index, + search, + startDate, + endDate, + limit, + offset, + tags, + }: GetTopFilterForAttributeProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/filters/{attribute}'.replace( '{attribute}', encodeURIComponent(String(attribute)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!attribute) { throw new Error( @@ -895,10 +952,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -914,18 +975,21 @@ export function createAnalyticsApi( * @param getTopFiltersNoResults.offset - Position of the starting record. Used for paging. 0 is the first record. * @param getTopFiltersNoResults.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getTopFiltersNoResults({ - index, - search, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopFiltersNoResultsProps): Promise { + function getTopFiltersNoResults( + { + index, + search, + startDate, + endDate, + limit, + offset, + tags, + }: GetTopFiltersNoResultsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/filters/noResults'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -966,10 +1030,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -986,19 +1054,22 @@ export function createAnalyticsApi( * @param getTopHits.offset - Position of the starting record. Used for paging. 0 is the first record. * @param getTopHits.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getTopHits({ - index, - search, - clickAnalytics, - startDate, - endDate, - limit, - offset, - tags, - }: GetTopHitsProps): Promise { + function getTopHits( + { + index, + search, + clickAnalytics, + startDate, + endDate, + limit, + offset, + tags, + }: GetTopHitsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/hits'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -1043,10 +1114,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1064,20 +1139,23 @@ export function createAnalyticsApi( * @param getTopSearches.offset - Position of the starting record. Used for paging. 0 is the first record. * @param getTopSearches.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getTopSearches({ - index, - clickAnalytics, - startDate, - endDate, - orderBy, - direction, - limit, - offset, - tags, - }: GetTopSearchesProps): Promise { + function getTopSearches( + { + index, + clickAnalytics, + startDate, + endDate, + orderBy, + direction, + limit, + offset, + tags, + }: GetTopSearchesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/searches'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -1126,10 +1204,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1142,15 +1224,13 @@ export function createAnalyticsApi( * @param getUsersCount.endDate - The upper bound timestamp (a date, a string like \"2006-01-02\") of the period to analyze. * @param getUsersCount.tags - Filter metrics on the provided tags. Each tag must correspond to an analyticsTags set at search time. Multiple tags can be combined with the operators OR and AND. If a tag contains characters like spaces or parentheses, it should be URL encoded. */ - function getUsersCount({ - index, - startDate, - endDate, - tags, - }: GetUsersCountProps): Promise { + function getUsersCount( + { index, startDate, endDate, tags }: GetUsersCountProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/2/users/count'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!index) { throw new Error( @@ -1179,10 +1259,14 @@ export function createAnalyticsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1194,17 +1278,16 @@ export function createAnalyticsApi( * @param post.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param post.body - The parameters to send with the custom request. */ - function post({ - path, - parameters, - body, - }: PostProps): Promise> { + function post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `post`.'); @@ -1220,10 +1303,14 @@ export function createAnalyticsApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1235,17 +1322,16 @@ export function createAnalyticsApi( * @param put.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param put.body - The parameters to send with the custom request. */ - function put({ - path, - parameters, - body, - }: PutProps): Promise> { + function put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `put`.'); @@ -1261,10 +1347,14 @@ export function createAnalyticsApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } return { diff --git a/clients/algoliasearch-client-javascript/packages/client-insights/builds/browser.ts b/clients/algoliasearch-client-javascript/packages/client-insights/builds/browser.ts index 8c150ecc46..00257fce8b 100644 --- a/clients/algoliasearch-client-javascript/packages/client-insights/builds/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/client-insights/builds/browser.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createFallbackableCache, @@ -18,7 +15,7 @@ export function insightsApi( appId: string, apiKey: string, region?: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): InsightsApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -40,14 +37,19 @@ export function insightsApi( requester: options?.requester ?? createXhrRequester(), userAgents: [{ segment: 'Browser' }], authMode: 'WithinQueryParameters', - responsesCache: createMemoryCache(), - requestsCache: createMemoryCache({ serializable: false }), - hostsCache: createFallbackableCache({ - caches: [ - createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), - createMemoryCache(), - ], - }), + responsesCache: options?.responsesCache ?? createMemoryCache(), + requestsCache: + options?.requestsCache ?? createMemoryCache({ serializable: false }), + hostsCache: + options?.hostsCache ?? + createFallbackableCache({ + caches: [ + createBrowserLocalStorageCache({ + key: `${apiClientVersion}-${appId}`, + }), + createMemoryCache(), + ], + }), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-insights/builds/node.ts b/clients/algoliasearch-client-javascript/packages/client-insights/builds/node.ts index b8ae29edd1..c68540b5d6 100644 --- a/clients/algoliasearch-client-javascript/packages/client-insights/builds/node.ts +++ b/clients/algoliasearch-client-javascript/packages/client-insights/builds/node.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createNullCache, @@ -17,7 +14,7 @@ export function insightsApi( appId: string, apiKey: string, region?: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): InsightsApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -38,9 +35,9 @@ export function insightsApi( }, requester: options?.requester ?? createHttpRequester(), userAgents: [{ segment: 'Node.js', version: process.versions.node }], - responsesCache: createNullCache(), - requestsCache: createNullCache(), - hostsCache: createMemoryCache(), + responsesCache: options?.responsesCache ?? createNullCache(), + requestsCache: options?.requestsCache ?? createNullCache(), + hostsCache: options?.hostsCache ?? createMemoryCache(), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts b/clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts index 034e3749ef..287ab96175 100644 --- a/clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts +++ b/clients/algoliasearch-client-javascript/packages/client-insights/src/insightsApi.ts @@ -8,6 +8,8 @@ import type { Headers, Host, Request, + RequestOptions, + QueryParameters, } from '@experimental-api-clients-automation/client-common'; import type { InsightEvents } from '../model/insightEvents'; @@ -67,17 +69,16 @@ export function createInsightsApi( * @param del.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param del.body - The parameters to send with the custom request. */ - function del({ - path, - parameters, - body, - }: DelProps): Promise> { + function del( + { path, parameters, body }: DelProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `del`.'); @@ -93,10 +94,14 @@ export function createInsightsApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -107,13 +112,16 @@ export function createInsightsApi( * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. * @param get.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. */ - function get({ path, parameters }: GetProps): Promise> { + function get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `get`.'); @@ -128,10 +136,14 @@ export function createInsightsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -143,17 +155,16 @@ export function createInsightsApi( * @param post.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param post.body - The parameters to send with the custom request. */ - function post({ - path, - parameters, - body, - }: PostProps): Promise> { + function post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `post`.'); @@ -169,10 +180,14 @@ export function createInsightsApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -182,11 +197,12 @@ export function createInsightsApi( * @param insightEvents - The insightEvents object. */ function pushEvents( - insightEvents: InsightEvents + insightEvents: InsightEvents, + requestOptions?: RequestOptions ): Promise { const requestPath = '/1/events'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!insightEvents) { throw new Error( @@ -206,10 +222,14 @@ export function createInsightsApi( data: insightEvents, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -221,17 +241,16 @@ export function createInsightsApi( * @param put.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param put.body - The parameters to send with the custom request. */ - function put({ - path, - parameters, - body, - }: PutProps): Promise> { + function put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `put`.'); @@ -247,10 +266,14 @@ export function createInsightsApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } return { addUserAgent, del, get, post, pushEvents, put }; diff --git a/clients/algoliasearch-client-javascript/packages/client-personalization/builds/browser.ts b/clients/algoliasearch-client-javascript/packages/client-personalization/builds/browser.ts index a0ed171bcb..1b3313ba4a 100644 --- a/clients/algoliasearch-client-javascript/packages/client-personalization/builds/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/client-personalization/builds/browser.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createFallbackableCache, @@ -21,7 +18,7 @@ export function personalizationApi( appId: string, apiKey: string, region: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): PersonalizationApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -47,14 +44,19 @@ export function personalizationApi( requester: options?.requester ?? createXhrRequester(), userAgents: [{ segment: 'Browser' }], authMode: 'WithinQueryParameters', - responsesCache: createMemoryCache(), - requestsCache: createMemoryCache({ serializable: false }), - hostsCache: createFallbackableCache({ - caches: [ - createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), - createMemoryCache(), - ], - }), + responsesCache: options?.responsesCache ?? createMemoryCache(), + requestsCache: + options?.requestsCache ?? createMemoryCache({ serializable: false }), + hostsCache: + options?.hostsCache ?? + createFallbackableCache({ + caches: [ + createBrowserLocalStorageCache({ + key: `${apiClientVersion}-${appId}`, + }), + createMemoryCache(), + ], + }), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-personalization/builds/node.ts b/clients/algoliasearch-client-javascript/packages/client-personalization/builds/node.ts index a9d0a7876f..15f62a133f 100644 --- a/clients/algoliasearch-client-javascript/packages/client-personalization/builds/node.ts +++ b/clients/algoliasearch-client-javascript/packages/client-personalization/builds/node.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createNullCache, @@ -17,7 +14,7 @@ export function personalizationApi( appId: string, apiKey: string, region: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): PersonalizationApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -42,9 +39,9 @@ export function personalizationApi( }, requester: options?.requester ?? createHttpRequester(), userAgents: [{ segment: 'Node.js', version: process.versions.node }], - responsesCache: createNullCache(), - requestsCache: createNullCache(), - hostsCache: createMemoryCache(), + responsesCache: options?.responsesCache ?? createNullCache(), + requestsCache: options?.requestsCache ?? createNullCache(), + hostsCache: options?.hostsCache ?? createMemoryCache(), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts b/clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts index e8d2121d19..b55784c3e0 100644 --- a/clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts +++ b/clients/algoliasearch-client-javascript/packages/client-personalization/src/personalizationApi.ts @@ -8,6 +8,8 @@ import type { Headers, Host, Request, + RequestOptions, + QueryParameters, } from '@experimental-api-clients-automation/client-common'; import type { DeleteUserProfileResponse } from '../model/deleteUserProfileResponse'; @@ -67,17 +69,16 @@ export function createPersonalizationApi( * @param del.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param del.body - The parameters to send with the custom request. */ - function del({ - path, - parameters, - body, - }: DelProps): Promise> { + function del( + { path, parameters, body }: DelProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `del`.'); @@ -93,10 +94,14 @@ export function createPersonalizationApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -106,15 +111,16 @@ export function createPersonalizationApi( * @param deleteUserProfile - The deleteUserProfile object. * @param deleteUserProfile.userToken - UserToken representing the user for which to fetch the Personalization profile. */ - function deleteUserProfile({ - userToken, - }: DeleteUserProfileProps): Promise { + function deleteUserProfile( + { userToken }: DeleteUserProfileProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/profiles/{userToken}'.replace( '{userToken}', encodeURIComponent(String(userToken)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!userToken) { throw new Error( @@ -127,10 +133,14 @@ export function createPersonalizationApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -141,13 +151,16 @@ export function createPersonalizationApi( * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. * @param get.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. */ - function get({ path, parameters }: GetProps): Promise> { + function get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `get`.'); @@ -162,10 +175,14 @@ export function createPersonalizationApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -173,20 +190,26 @@ export function createPersonalizationApi( * * @summary Get the current personalization strategy. */ - function getPersonalizationStrategy(): Promise { + function getPersonalizationStrategy( + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/strategies/personalization'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -196,15 +219,16 @@ export function createPersonalizationApi( * @param getUserTokenProfile - The getUserTokenProfile object. * @param getUserTokenProfile.userToken - UserToken representing the user for which to fetch the Personalization profile. */ - function getUserTokenProfile({ - userToken, - }: GetUserTokenProfileProps): Promise { + function getUserTokenProfile( + { userToken }: GetUserTokenProfileProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/profiles/personalization/{userToken}'.replace( '{userToken}', encodeURIComponent(String(userToken)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!userToken) { throw new Error( @@ -217,10 +241,14 @@ export function createPersonalizationApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -232,17 +260,16 @@ export function createPersonalizationApi( * @param post.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param post.body - The parameters to send with the custom request. */ - function post({ - path, - parameters, - body, - }: PostProps): Promise> { + function post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `post`.'); @@ -258,10 +285,14 @@ export function createPersonalizationApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -273,17 +304,16 @@ export function createPersonalizationApi( * @param put.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param put.body - The parameters to send with the custom request. */ - function put({ - path, - parameters, - body, - }: PutProps): Promise> { + function put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `put`.'); @@ -299,10 +329,14 @@ export function createPersonalizationApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -312,11 +346,12 @@ export function createPersonalizationApi( * @param personalizationStrategyParams - The personalizationStrategyParams object. */ function setPersonalizationStrategy( - personalizationStrategyParams: PersonalizationStrategyParams + personalizationStrategyParams: PersonalizationStrategyParams, + requestOptions?: RequestOptions ): Promise { const requestPath = '/1/strategies/personalization'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!personalizationStrategyParams) { throw new Error( @@ -346,10 +381,14 @@ export function createPersonalizationApi( data: personalizationStrategyParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } return { diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/builds/browser.ts b/clients/algoliasearch-client-javascript/packages/client-predict/builds/browser.ts index 554df3ed91..1f0d80bc1a 100644 --- a/clients/algoliasearch-client-javascript/packages/client-predict/builds/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/client-predict/builds/browser.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createFallbackableCache, @@ -17,7 +14,7 @@ export * from '../src/predictApi'; export function predictApi( appId: string, apiKey: string, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): PredictApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -38,14 +35,19 @@ export function predictApi( requester: options?.requester ?? createXhrRequester(), userAgents: [{ segment: 'Browser' }], authMode: 'WithinQueryParameters', - responsesCache: createMemoryCache(), - requestsCache: createMemoryCache({ serializable: false }), - hostsCache: createFallbackableCache({ - caches: [ - createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), - createMemoryCache(), - ], - }), + responsesCache: options?.responsesCache ?? createMemoryCache(), + requestsCache: + options?.requestsCache ?? createMemoryCache({ serializable: false }), + hostsCache: + options?.hostsCache ?? + createFallbackableCache({ + caches: [ + createBrowserLocalStorageCache({ + key: `${apiClientVersion}-${appId}`, + }), + createMemoryCache(), + ], + }), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/builds/node.ts b/clients/algoliasearch-client-javascript/packages/client-predict/builds/node.ts index 449c5b3c74..c1d7d8ae7e 100644 --- a/clients/algoliasearch-client-javascript/packages/client-predict/builds/node.ts +++ b/clients/algoliasearch-client-javascript/packages/client-predict/builds/node.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createNullCache, @@ -16,7 +13,7 @@ export * from '../src/predictApi'; export function predictApi( appId: string, apiKey: string, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): PredictApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -36,9 +33,9 @@ export function predictApi( }, requester: options?.requester ?? createHttpRequester(), userAgents: [{ segment: 'Node.js', version: process.versions.node }], - responsesCache: createNullCache(), - requestsCache: createNullCache(), - hostsCache: createMemoryCache(), + responsesCache: options?.responsesCache ?? createNullCache(), + requestsCache: options?.requestsCache ?? createNullCache(), + hostsCache: options?.hostsCache ?? createMemoryCache(), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts b/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts index 589dd1fb9d..c087243e13 100644 --- a/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts +++ b/clients/algoliasearch-client-javascript/packages/client-predict/src/predictApi.ts @@ -8,6 +8,8 @@ import type { Headers, Host, Request, + RequestOptions, + QueryParameters, } from '@experimental-api-clients-automation/client-common'; import type { FetchUserProfileResponse } from '../model/fetchUserProfileResponse'; @@ -61,17 +63,16 @@ export function createPredictApi(options: CreateClientOptions) { * @param del.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param del.body - The parameters to send with the custom request. */ - function del({ - path, - parameters, - body, - }: DelProps): Promise> { + function del( + { path, parameters, body }: DelProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `del`.'); @@ -87,10 +88,14 @@ export function createPredictApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -101,16 +106,16 @@ export function createPredictApi(options: CreateClientOptions) { * @param fetchUserProfile.userID - User ID for authenticated users or cookie ID for non-authenticated repeated users (visitors). * @param fetchUserProfile.params - The params object. */ - function fetchUserProfile({ - userID, - params, - }: FetchUserProfileProps): Promise { + function fetchUserProfile( + { userID, params }: FetchUserProfileProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/users/{userID}/fetch'.replace( '{userID}', encodeURIComponent(String(userID)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!userID) { throw new Error( @@ -130,10 +135,14 @@ export function createPredictApi(options: CreateClientOptions) { data: params, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -144,13 +153,16 @@ export function createPredictApi(options: CreateClientOptions) { * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. * @param get.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. */ - function get({ path, parameters }: GetProps): Promise> { + function get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `get`.'); @@ -165,10 +177,14 @@ export function createPredictApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -180,17 +196,16 @@ export function createPredictApi(options: CreateClientOptions) { * @param post.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param post.body - The parameters to send with the custom request. */ - function post({ - path, - parameters, - body, - }: PostProps): Promise> { + function post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `post`.'); @@ -206,10 +221,14 @@ export function createPredictApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -221,17 +240,16 @@ export function createPredictApi(options: CreateClientOptions) { * @param put.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param put.body - The parameters to send with the custom request. */ - function put({ - path, - parameters, - body, - }: PutProps): Promise> { + function put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `put`.'); @@ -247,10 +265,14 @@ export function createPredictApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } return { addUserAgent, del, fetchUserProfile, get, post, put }; diff --git a/clients/algoliasearch-client-javascript/packages/client-query-suggestions/builds/browser.ts b/clients/algoliasearch-client-javascript/packages/client-query-suggestions/builds/browser.ts index 2c1170df3c..3026198954 100644 --- a/clients/algoliasearch-client-javascript/packages/client-query-suggestions/builds/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/client-query-suggestions/builds/browser.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createFallbackableCache, @@ -21,7 +18,7 @@ export function querySuggestionsApi( appId: string, apiKey: string, region: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): QuerySuggestionsApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -47,14 +44,19 @@ export function querySuggestionsApi( requester: options?.requester ?? createXhrRequester(), userAgents: [{ segment: 'Browser' }], authMode: 'WithinQueryParameters', - responsesCache: createMemoryCache(), - requestsCache: createMemoryCache({ serializable: false }), - hostsCache: createFallbackableCache({ - caches: [ - createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), - createMemoryCache(), - ], - }), + responsesCache: options?.responsesCache ?? createMemoryCache(), + requestsCache: + options?.requestsCache ?? createMemoryCache({ serializable: false }), + hostsCache: + options?.hostsCache ?? + createFallbackableCache({ + caches: [ + createBrowserLocalStorageCache({ + key: `${apiClientVersion}-${appId}`, + }), + createMemoryCache(), + ], + }), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-query-suggestions/builds/node.ts b/clients/algoliasearch-client-javascript/packages/client-query-suggestions/builds/node.ts index dd6e81d1ae..1f2c18879a 100644 --- a/clients/algoliasearch-client-javascript/packages/client-query-suggestions/builds/node.ts +++ b/clients/algoliasearch-client-javascript/packages/client-query-suggestions/builds/node.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createNullCache, @@ -17,7 +14,7 @@ export function querySuggestionsApi( appId: string, apiKey: string, region: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): QuerySuggestionsApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -42,9 +39,9 @@ export function querySuggestionsApi( }, requester: options?.requester ?? createHttpRequester(), userAgents: [{ segment: 'Node.js', version: process.versions.node }], - responsesCache: createNullCache(), - requestsCache: createNullCache(), - hostsCache: createMemoryCache(), + responsesCache: options?.responsesCache ?? createNullCache(), + requestsCache: options?.requestsCache ?? createNullCache(), + hostsCache: options?.hostsCache ?? createMemoryCache(), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts b/clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts index 40136361bb..2acb338017 100644 --- a/clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts +++ b/clients/algoliasearch-client-javascript/packages/client-query-suggestions/src/querySuggestionsApi.ts @@ -8,6 +8,8 @@ import type { Headers, Host, Request, + RequestOptions, + QueryParameters, } from '@experimental-api-clients-automation/client-common'; import type { LogFile } from '../model/logFile'; @@ -67,11 +69,12 @@ export function createQuerySuggestionsApi( * @param querySuggestionsIndexWithIndexParam - The querySuggestionsIndexWithIndexParam object. */ function createConfig( - querySuggestionsIndexWithIndexParam: QuerySuggestionsIndexWithIndexParam + querySuggestionsIndexWithIndexParam: QuerySuggestionsIndexWithIndexParam, + requestOptions?: RequestOptions ): Promise { const requestPath = '/1/configs'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!querySuggestionsIndexWithIndexParam) { throw new Error( @@ -85,10 +88,14 @@ export function createQuerySuggestionsApi( data: querySuggestionsIndexWithIndexParam, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -100,17 +107,16 @@ export function createQuerySuggestionsApi( * @param del.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param del.body - The parameters to send with the custom request. */ - function del({ - path, - parameters, - body, - }: DelProps): Promise> { + function del( + { path, parameters, body }: DelProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `del`.'); @@ -126,10 +132,14 @@ export function createQuerySuggestionsApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -139,15 +149,16 @@ export function createQuerySuggestionsApi( * @param deleteConfig - The deleteConfig object. * @param deleteConfig.indexName - The index in which to perform the request. */ - function deleteConfig({ - indexName, - }: DeleteConfigProps): Promise { + function deleteConfig( + { indexName }: DeleteConfigProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/configs/{indexName}'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -160,10 +171,14 @@ export function createQuerySuggestionsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -174,13 +189,16 @@ export function createQuerySuggestionsApi( * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. * @param get.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. */ - function get({ path, parameters }: GetProps): Promise> { + function get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `get`.'); @@ -195,10 +213,14 @@ export function createQuerySuggestionsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -206,20 +228,26 @@ export function createQuerySuggestionsApi( * * @summary Get all the configurations of Query Suggestions. */ - function getAllConfigs(): Promise { + function getAllConfigs( + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/configs'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -229,15 +257,16 @@ export function createQuerySuggestionsApi( * @param getConfig - The getConfig object. * @param getConfig.indexName - The index in which to perform the request. */ - function getConfig({ - indexName, - }: GetConfigProps): Promise { + function getConfig( + { indexName }: GetConfigProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/configs/{indexName}'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -250,10 +279,14 @@ export function createQuerySuggestionsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -263,15 +296,16 @@ export function createQuerySuggestionsApi( * @param getConfigStatus - The getConfigStatus object. * @param getConfigStatus.indexName - The index in which to perform the request. */ - function getConfigStatus({ - indexName, - }: GetConfigStatusProps): Promise { + function getConfigStatus( + { indexName }: GetConfigStatusProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/configs/{indexName}/status'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -284,10 +318,14 @@ export function createQuerySuggestionsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -297,13 +335,16 @@ export function createQuerySuggestionsApi( * @param getLogFile - The getLogFile object. * @param getLogFile.indexName - The index in which to perform the request. */ - function getLogFile({ indexName }: GetLogFileProps): Promise { + function getLogFile( + { indexName }: GetLogFileProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/logs/{indexName}'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -316,10 +357,14 @@ export function createQuerySuggestionsApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -331,17 +376,16 @@ export function createQuerySuggestionsApi( * @param post.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param post.body - The parameters to send with the custom request. */ - function post({ - path, - parameters, - body, - }: PostProps): Promise> { + function post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `post`.'); @@ -357,10 +401,14 @@ export function createQuerySuggestionsApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -372,17 +420,16 @@ export function createQuerySuggestionsApi( * @param put.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param put.body - The parameters to send with the custom request. */ - function put({ - path, - parameters, - body, - }: PutProps): Promise> { + function put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `put`.'); @@ -398,10 +445,14 @@ export function createQuerySuggestionsApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -412,16 +463,16 @@ export function createQuerySuggestionsApi( * @param updateConfig.indexName - The index in which to perform the request. * @param updateConfig.querySuggestionsIndexParam - The querySuggestionsIndexParam object. */ - function updateConfig({ - indexName, - querySuggestionsIndexParam, - }: UpdateConfigProps): Promise { + function updateConfig( + { indexName, querySuggestionsIndexParam }: UpdateConfigProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/configs/{indexName}'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -447,10 +498,14 @@ export function createQuerySuggestionsApi( data: querySuggestionsIndexParam, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } return { diff --git a/clients/algoliasearch-client-javascript/packages/client-search/builds/browser.ts b/clients/algoliasearch-client-javascript/packages/client-search/builds/browser.ts index 434f060f26..142f48d8e0 100644 --- a/clients/algoliasearch-client-javascript/packages/client-search/builds/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/client-search/builds/browser.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createFallbackableCache, @@ -17,7 +14,7 @@ export * from '../src/searchApi'; export function searchApi( appId: string, apiKey: string, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): SearchApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -38,14 +35,19 @@ export function searchApi( requester: options?.requester ?? createXhrRequester(), userAgents: [{ segment: 'Browser' }], authMode: 'WithinQueryParameters', - responsesCache: createMemoryCache(), - requestsCache: createMemoryCache({ serializable: false }), - hostsCache: createFallbackableCache({ - caches: [ - createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), - createMemoryCache(), - ], - }), + responsesCache: options?.responsesCache ?? createMemoryCache(), + requestsCache: + options?.requestsCache ?? createMemoryCache({ serializable: false }), + hostsCache: + options?.hostsCache ?? + createFallbackableCache({ + caches: [ + createBrowserLocalStorageCache({ + key: `${apiClientVersion}-${appId}`, + }), + createMemoryCache(), + ], + }), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-search/builds/node.ts b/clients/algoliasearch-client-javascript/packages/client-search/builds/node.ts index d8ea7010b6..2f1d3eaa7c 100644 --- a/clients/algoliasearch-client-javascript/packages/client-search/builds/node.ts +++ b/clients/algoliasearch-client-javascript/packages/client-search/builds/node.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createNullCache, @@ -16,7 +13,7 @@ export * from '../src/searchApi'; export function searchApi( appId: string, apiKey: string, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): SearchApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -36,9 +33,9 @@ export function searchApi( }, requester: options?.requester ?? createHttpRequester(), userAgents: [{ segment: 'Node.js', version: process.versions.node }], - responsesCache: createNullCache(), - requestsCache: createNullCache(), - hostsCache: createMemoryCache(), + responsesCache: options?.responsesCache ?? createNullCache(), + requestsCache: options?.requestsCache ?? createNullCache(), + hostsCache: options?.hostsCache ?? createMemoryCache(), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts b/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts index 4d1cbcea83..ff934c1087 100644 --- a/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts +++ b/clients/algoliasearch-client-javascript/packages/client-search/src/searchApi.ts @@ -9,6 +9,8 @@ import type { Headers, Host, Request, + RequestOptions, + QueryParameters, } from '@experimental-api-clients-automation/client-common'; import type { AddApiKeyResponse } from '../model/addApiKeyResponse'; @@ -140,10 +142,13 @@ export function createSearchApi(options: CreateClientOptions) { * @summary Create a new API key. * @param apiKey - The apiKey object. */ - function addApiKey(apiKey: ApiKey): Promise { + function addApiKey( + apiKey: ApiKey, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/keys'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!apiKey) { throw new Error( @@ -163,10 +168,14 @@ export function createSearchApi(options: CreateClientOptions) { data: apiKey, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -178,16 +187,15 @@ export function createSearchApi(options: CreateClientOptions) { * @param addOrUpdateObject.objectID - Unique identifier of an object. * @param addOrUpdateObject.body - The Algolia object. */ - function addOrUpdateObject({ - indexName, - objectID, - body, - }: AddOrUpdateObjectProps): Promise { + function addOrUpdateObject( + { indexName, objectID, body }: AddOrUpdateObjectProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/{objectID}' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{objectID}', encodeURIComponent(String(objectID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -213,10 +221,14 @@ export function createSearchApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -225,10 +237,13 @@ export function createSearchApi(options: CreateClientOptions) { * @summary Add a single source. * @param source - The source to add. */ - function appendSource(source: Source): Promise { + function appendSource( + source: Source, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/security/sources/append'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!source) { throw new Error( @@ -242,10 +257,14 @@ export function createSearchApi(options: CreateClientOptions) { data: source, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -256,13 +275,13 @@ export function createSearchApi(options: CreateClientOptions) { * @param assignUserId.xAlgoliaUserID - UserID to assign. * @param assignUserId.assignUserIdParams - The assignUserIdParams object. */ - function assignUserId({ - xAlgoliaUserID, - assignUserIdParams, - }: AssignUserIdProps): Promise { + function assignUserId( + { xAlgoliaUserID, assignUserIdParams }: AssignUserIdProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/clusters/mapping'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!xAlgoliaUserID) { throw new Error( @@ -292,10 +311,14 @@ export function createSearchApi(options: CreateClientOptions) { data: assignUserIdParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -306,16 +329,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param batch.indexName - The index in which to perform the request. * @param batch.batchWriteParams - The batchWriteParams object. */ - function batch({ - indexName, - batchWriteParams, - }: BatchProps): Promise { + function batch( + { indexName, batchWriteParams }: BatchProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/batch'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -335,10 +358,14 @@ export function createSearchApi(options: CreateClientOptions) { data: batchWriteParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -349,13 +376,13 @@ export function createSearchApi(options: CreateClientOptions) { * @param batchAssignUserIds.xAlgoliaUserID - UserID to assign. * @param batchAssignUserIds.batchAssignUserIdsParams - The batchAssignUserIdsParams object. */ - function batchAssignUserIds({ - xAlgoliaUserID, - batchAssignUserIdsParams, - }: BatchAssignUserIdsProps): Promise { + function batchAssignUserIds( + { xAlgoliaUserID, batchAssignUserIdsParams }: BatchAssignUserIdsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/clusters/mapping/batch'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!xAlgoliaUserID) { throw new Error( @@ -390,10 +417,14 @@ export function createSearchApi(options: CreateClientOptions) { data: batchAssignUserIdsParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -404,16 +435,19 @@ export function createSearchApi(options: CreateClientOptions) { * @param batchDictionaryEntries.dictionaryName - The dictionary to search in. * @param batchDictionaryEntries.batchDictionaryEntriesParams - The batchDictionaryEntriesParams object. */ - function batchDictionaryEntries({ - dictionaryName, - batchDictionaryEntriesParams, - }: BatchDictionaryEntriesProps): Promise { + function batchDictionaryEntries( + { + dictionaryName, + batchDictionaryEntriesParams, + }: BatchDictionaryEntriesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/dictionaries/{dictionaryName}/batch'.replace( '{dictionaryName}', encodeURIComponent(String(dictionaryName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!dictionaryName) { throw new Error( @@ -439,10 +473,14 @@ export function createSearchApi(options: CreateClientOptions) { data: batchDictionaryEntriesParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -455,18 +493,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param batchRules.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. * @param batchRules.clearExistingRules - When true, existing Rules are cleared before adding this batch. When false, existing Rules are kept. */ - function batchRules({ - indexName, - rule, - forwardToReplicas, - clearExistingRules, - }: BatchRulesProps): Promise { + function batchRules( + { indexName, rule, forwardToReplicas, clearExistingRules }: BatchRulesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/rules/batch'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -494,10 +530,14 @@ export function createSearchApi(options: CreateClientOptions) { data: rule, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -508,16 +548,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param browse.indexName - The index in which to perform the request. * @param browse.browseRequest - The browseRequest object. */ - function browse({ - indexName, - browseRequest, - }: BrowseProps): Promise { + function browse( + { indexName, browseRequest }: BrowseProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/browse'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -531,10 +571,14 @@ export function createSearchApi(options: CreateClientOptions) { data: browseRequest, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -545,16 +589,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param clearAllSynonyms.indexName - The index in which to perform the request. * @param clearAllSynonyms.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. */ - function clearAllSynonyms({ - indexName, - forwardToReplicas, - }: ClearAllSynonymsProps): Promise { + function clearAllSynonyms( + { indexName, forwardToReplicas }: ClearAllSynonymsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/synonyms/clear'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -571,10 +615,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -584,15 +632,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param clearObjects - The clearObjects object. * @param clearObjects.indexName - The index in which to perform the request. */ - function clearObjects({ - indexName, - }: ClearObjectsProps): Promise { + function clearObjects( + { indexName }: ClearObjectsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/clear'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -605,10 +654,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -619,16 +672,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param clearRules.indexName - The index in which to perform the request. * @param clearRules.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. */ - function clearRules({ - indexName, - forwardToReplicas, - }: ClearRulesProps): Promise { + function clearRules( + { indexName, forwardToReplicas }: ClearRulesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/rules/clear'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -645,10 +698,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -660,17 +717,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param del.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param del.body - The parameters to send with the custom request. */ - function del({ - path, - parameters, - body, - }: DelProps): Promise> { + function del( + { path, parameters, body }: DelProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `del`.'); @@ -686,10 +742,14 @@ export function createSearchApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -699,15 +759,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param deleteApiKey - The deleteApiKey object. * @param deleteApiKey.key - API Key string. */ - function deleteApiKey({ - key, - }: DeleteApiKeyProps): Promise { + function deleteApiKey( + { key }: DeleteApiKeyProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/keys/{key}'.replace( '{key}', encodeURIComponent(String(key)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!key) { throw new Error( @@ -720,10 +781,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -734,16 +799,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param deleteBy.indexName - The index in which to perform the request. * @param deleteBy.searchParams - The searchParams object. */ - function deleteBy({ - indexName, - searchParams, - }: DeleteByProps): Promise { + function deleteBy( + { indexName, searchParams }: DeleteByProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/deleteByQuery'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -763,10 +828,14 @@ export function createSearchApi(options: CreateClientOptions) { data: searchParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -776,15 +845,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param deleteIndex - The deleteIndex object. * @param deleteIndex.indexName - The index in which to perform the request. */ - function deleteIndex({ - indexName, - }: DeleteIndexProps): Promise { + function deleteIndex( + { indexName }: DeleteIndexProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -797,10 +867,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -811,15 +885,15 @@ export function createSearchApi(options: CreateClientOptions) { * @param deleteObject.indexName - The index in which to perform the request. * @param deleteObject.objectID - Unique identifier of an object. */ - function deleteObject({ - indexName, - objectID, - }: DeleteObjectProps): Promise { + function deleteObject( + { indexName, objectID }: DeleteObjectProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/{objectID}' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{objectID}', encodeURIComponent(String(objectID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -838,10 +912,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -853,16 +931,15 @@ export function createSearchApi(options: CreateClientOptions) { * @param deleteRule.objectID - Unique identifier of an object. * @param deleteRule.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. */ - function deleteRule({ - indexName, - objectID, - forwardToReplicas, - }: DeleteRuleProps): Promise { + function deleteRule( + { indexName, objectID, forwardToReplicas }: DeleteRuleProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/rules/{objectID}' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{objectID}', encodeURIComponent(String(objectID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -885,10 +962,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -898,15 +979,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param deleteSource - The deleteSource object. * @param deleteSource.source - The IP range of the source. */ - function deleteSource({ - source, - }: DeleteSourceProps): Promise { + function deleteSource( + { source }: DeleteSourceProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/security/sources/{source}'.replace( '{source}', encodeURIComponent(String(source)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!source) { throw new Error( @@ -919,10 +1001,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -934,16 +1020,15 @@ export function createSearchApi(options: CreateClientOptions) { * @param deleteSynonym.objectID - Unique identifier of an object. * @param deleteSynonym.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. */ - function deleteSynonym({ - indexName, - objectID, - forwardToReplicas, - }: DeleteSynonymProps): Promise { + function deleteSynonym( + { indexName, objectID, forwardToReplicas }: DeleteSynonymProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/synonyms/{objectID}' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{objectID}', encodeURIComponent(String(objectID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -966,10 +1051,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -980,13 +1069,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. * @param get.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. */ - function get({ path, parameters }: GetProps): Promise> { + function get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `get`.'); @@ -1001,10 +1093,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1014,13 +1110,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param getApiKey - The getApiKey object. * @param getApiKey.key - API Key string. */ - function getApiKey({ key }: GetApiKeyProps): Promise { + function getApiKey( + { key }: GetApiKeyProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/keys/{key}'.replace( '{key}', encodeURIComponent(String(key)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!key) { throw new Error('Parameter `key` is required when calling `getApiKey`.'); @@ -1031,10 +1130,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1042,20 +1145,26 @@ export function createSearchApi(options: CreateClientOptions) { * * @summary List dictionaries supported per language. */ - function getDictionaryLanguages(): Promise<{ [key: string]: Languages }> { + function getDictionaryLanguages( + requestOptions?: RequestOptions + ): Promise<{ [key: string]: Languages }> { const requestPath = '/1/dictionaries/*/languages'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1063,20 +1172,26 @@ export function createSearchApi(options: CreateClientOptions) { * * @summary Retrieve dictionaries settings. The API stores languages whose standard entries are disabled. Fetch settings does not return false values. */ - function getDictionarySettings(): Promise { + function getDictionarySettings( + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/dictionaries/*/settings'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1089,15 +1204,13 @@ export function createSearchApi(options: CreateClientOptions) { * @param getLogs.indexName - Index for which log entries should be retrieved. When omitted, log entries are retrieved across all indices. * @param getLogs.type - Type of log entries to retrieve. When omitted, all log entries are retrieved. */ - function getLogs({ - offset, - length, - indexName, - type, - }: GetLogsProps): Promise { + function getLogs( + { offset, length, indexName, type }: GetLogsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/logs'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (offset !== undefined) { queryParameters.offset = offset.toString(); @@ -1120,10 +1233,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1135,16 +1252,15 @@ export function createSearchApi(options: CreateClientOptions) { * @param getObject.objectID - Unique identifier of an object. * @param getObject.attributesToRetrieve - List of attributes to retrieve. If not specified, all retrievable attributes are returned. */ - function getObject({ - indexName, - objectID, - attributesToRetrieve, - }: GetObjectProps): Promise<{ [key: string]: string }> { + function getObject( + { indexName, objectID, attributesToRetrieve }: GetObjectProps, + requestOptions?: RequestOptions + ): Promise<{ [key: string]: string }> { const requestPath = '/1/indexes/{indexName}/{objectID}' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{objectID}', encodeURIComponent(String(objectID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -1167,10 +1283,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1180,11 +1300,12 @@ export function createSearchApi(options: CreateClientOptions) { * @param getObjectsParams - The getObjectsParams object. */ function getObjects( - getObjectsParams: GetObjectsParams + getObjectsParams: GetObjectsParams, + requestOptions?: RequestOptions ): Promise { const requestPath = '/1/indexes/*/objects'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!getObjectsParams) { throw new Error( @@ -1198,10 +1319,14 @@ export function createSearchApi(options: CreateClientOptions) { data: getObjectsParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1212,12 +1337,15 @@ export function createSearchApi(options: CreateClientOptions) { * @param getRule.indexName - The index in which to perform the request. * @param getRule.objectID - Unique identifier of an object. */ - function getRule({ indexName, objectID }: GetRuleProps): Promise { + function getRule( + { indexName, objectID }: GetRuleProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/rules/{objectID}' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{objectID}', encodeURIComponent(String(objectID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -1236,10 +1364,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1249,15 +1381,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param getSettings - The getSettings object. * @param getSettings.indexName - The index in which to perform the request. */ - function getSettings({ - indexName, - }: GetSettingsProps): Promise { + function getSettings( + { indexName }: GetSettingsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/settings'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -1270,10 +1403,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1281,20 +1418,24 @@ export function createSearchApi(options: CreateClientOptions) { * * @summary List all allowed sources. */ - function getSources(): Promise { + function getSources(requestOptions?: RequestOptions): Promise { const requestPath = '/1/security/sources'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1305,15 +1446,15 @@ export function createSearchApi(options: CreateClientOptions) { * @param getSynonym.indexName - The index in which to perform the request. * @param getSynonym.objectID - Unique identifier of an object. */ - function getSynonym({ - indexName, - objectID, - }: GetSynonymProps): Promise { + function getSynonym( + { indexName, objectID }: GetSynonymProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/synonyms/{objectID}' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{objectID}', encodeURIComponent(String(objectID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -1332,10 +1473,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1346,15 +1491,15 @@ export function createSearchApi(options: CreateClientOptions) { * @param getTask.indexName - The index in which to perform the request. * @param getTask.taskID - Unique identifier of an task. Numeric value (up to 64bits). */ - function getTask({ - indexName, - taskID, - }: GetTaskProps): Promise { + function getTask( + { indexName, taskID }: GetTaskProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/task/{taskID}' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{taskID}', encodeURIComponent(String(taskID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -1371,10 +1516,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1382,20 +1531,26 @@ export function createSearchApi(options: CreateClientOptions) { * * @summary Get top userID. */ - function getTopUserIds(): Promise { + function getTopUserIds( + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/clusters/mapping/top'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1405,13 +1560,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param getUserId - The getUserId object. * @param getUserId.userID - UserID to assign. */ - function getUserId({ userID }: GetUserIdProps): Promise { + function getUserId( + { userID }: GetUserIdProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/clusters/mapping/{userID}'.replace( '{userID}', encodeURIComponent(String(userID)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!userID) { throw new Error( @@ -1424,10 +1582,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1437,12 +1599,13 @@ export function createSearchApi(options: CreateClientOptions) { * @param hasPendingMappings - The hasPendingMappings object. * @param hasPendingMappings.getClusters - Whether to get clusters or not. */ - function hasPendingMappings({ - getClusters, - }: HasPendingMappingsProps): Promise { + function hasPendingMappings( + { getClusters }: HasPendingMappingsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/clusters/mapping/pending'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (getClusters !== undefined) { queryParameters.getClusters = getClusters.toString(); @@ -1453,10 +1616,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1464,20 +1631,26 @@ export function createSearchApi(options: CreateClientOptions) { * * @summary Get the full list of API Keys. */ - function listApiKeys(): Promise { + function listApiKeys( + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/keys'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1485,20 +1658,26 @@ export function createSearchApi(options: CreateClientOptions) { * * @summary List clusters. */ - function listClusters(): Promise { + function listClusters( + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/clusters'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1508,12 +1687,13 @@ export function createSearchApi(options: CreateClientOptions) { * @param listIndices - The listIndices object. * @param listIndices.page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). */ - function listIndices({ - page, - }: ListIndicesProps): Promise { + function listIndices( + { page }: ListIndicesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (page !== undefined) { queryParameters.page = page.toString(); @@ -1524,10 +1704,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1538,13 +1722,13 @@ export function createSearchApi(options: CreateClientOptions) { * @param listUserIds.page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). * @param listUserIds.hitsPerPage - Maximum number of objects to retrieve. */ - function listUserIds({ - page, - hitsPerPage, - }: ListUserIdsProps): Promise { + function listUserIds( + { page, hitsPerPage }: ListUserIdsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/clusters/mapping'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (page !== undefined) { queryParameters.page = page.toString(); @@ -1559,10 +1743,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1572,11 +1760,12 @@ export function createSearchApi(options: CreateClientOptions) { * @param batchParams - The batchParams object. */ function multipleBatch( - batchParams: BatchParams + batchParams: BatchParams, + requestOptions?: RequestOptions ): Promise { const requestPath = '/1/indexes/*/batch'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!batchParams) { throw new Error( @@ -1590,10 +1779,14 @@ export function createSearchApi(options: CreateClientOptions) { data: batchParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1603,11 +1796,12 @@ export function createSearchApi(options: CreateClientOptions) { * @param multipleQueriesParams - The multipleQueriesParams object. */ function multipleQueries( - multipleQueriesParams: MultipleQueriesParams + multipleQueriesParams: MultipleQueriesParams, + requestOptions?: RequestOptions ): Promise { const requestPath = '/1/indexes/*/queries'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!multipleQueriesParams) { throw new Error( @@ -1627,10 +1821,14 @@ export function createSearchApi(options: CreateClientOptions) { data: multipleQueriesParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1641,16 +1839,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param operationIndex.indexName - The index in which to perform the request. * @param operationIndex.operationIndexParams - The operationIndexParams object. */ - function operationIndex({ - indexName, - operationIndexParams, - }: OperationIndexProps): Promise { + function operationIndex( + { indexName, operationIndexParams }: OperationIndexProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/operation'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -1681,10 +1879,14 @@ export function createSearchApi(options: CreateClientOptions) { data: operationIndexParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1697,17 +1899,20 @@ export function createSearchApi(options: CreateClientOptions) { * @param partialUpdateObject.attributeOrBuiltInOperation - List of attributes to update. * @param partialUpdateObject.createIfNotExists - Creates the record if it does not exist yet. */ - function partialUpdateObject({ - indexName, - objectID, - attributeOrBuiltInOperation, - createIfNotExists, - }: PartialUpdateObjectProps): Promise { + function partialUpdateObject( + { + indexName, + objectID, + attributeOrBuiltInOperation, + createIfNotExists, + }: PartialUpdateObjectProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/{objectID}/partial' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{objectID}', encodeURIComponent(String(objectID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -1737,10 +1942,14 @@ export function createSearchApi(options: CreateClientOptions) { data: attributeOrBuiltInOperation, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1752,17 +1961,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param post.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param post.body - The parameters to send with the custom request. */ - function post({ - path, - parameters, - body, - }: PostProps): Promise> { + function post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `post`.'); @@ -1778,10 +1986,14 @@ export function createSearchApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1793,17 +2005,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param put.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param put.body - The parameters to send with the custom request. */ - function put({ - path, - parameters, - body, - }: PutProps): Promise> { + function put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `put`.'); @@ -1819,10 +2030,14 @@ export function createSearchApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1832,15 +2047,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param removeUserId - The removeUserId object. * @param removeUserId.userID - UserID to assign. */ - function removeUserId({ - userID, - }: RemoveUserIdProps): Promise { + function removeUserId( + { userID }: RemoveUserIdProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/clusters/mapping/{userID}'.replace( '{userID}', encodeURIComponent(String(userID)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!userID) { throw new Error( @@ -1853,10 +2069,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1866,12 +2086,13 @@ export function createSearchApi(options: CreateClientOptions) { * @param replaceSources - The replaceSources object. * @param replaceSources.source - The sources to allow. */ - function replaceSources({ - source, - }: ReplaceSourcesProps): Promise { + function replaceSources( + { source }: ReplaceSourcesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/security/sources'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!source) { throw new Error( @@ -1885,10 +2106,14 @@ export function createSearchApi(options: CreateClientOptions) { data: source, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1898,15 +2123,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param restoreApiKey - The restoreApiKey object. * @param restoreApiKey.key - API Key string. */ - function restoreApiKey({ - key, - }: RestoreApiKeyProps): Promise { + function restoreApiKey( + { key }: RestoreApiKeyProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/keys/{key}/restore'.replace( '{key}', encodeURIComponent(String(key)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!key) { throw new Error( @@ -1919,10 +2145,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1933,16 +2163,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param saveObject.indexName - The index in which to perform the request. * @param saveObject.body - The Algolia record. */ - function saveObject({ - indexName, - body, - }: SaveObjectProps): Promise { + function saveObject( + { indexName, body }: SaveObjectProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -1962,10 +2192,14 @@ export function createSearchApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -1978,17 +2212,15 @@ export function createSearchApi(options: CreateClientOptions) { * @param saveRule.rule - The rule object. * @param saveRule.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. */ - function saveRule({ - indexName, - objectID, - rule, - forwardToReplicas, - }: SaveRuleProps): Promise { + function saveRule( + { indexName, objectID, rule, forwardToReplicas }: SaveRuleProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/rules/{objectID}' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{objectID}', encodeURIComponent(String(objectID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -2027,10 +2259,14 @@ export function createSearchApi(options: CreateClientOptions) { data: rule, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2043,17 +2279,15 @@ export function createSearchApi(options: CreateClientOptions) { * @param saveSynonym.synonymHit - The synonymHit object. * @param saveSynonym.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. */ - function saveSynonym({ - indexName, - objectID, - synonymHit, - forwardToReplicas, - }: SaveSynonymProps): Promise { + function saveSynonym( + { indexName, objectID, synonymHit, forwardToReplicas }: SaveSynonymProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/synonyms/{objectID}' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{objectID}', encodeURIComponent(String(objectID))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -2089,10 +2323,14 @@ export function createSearchApi(options: CreateClientOptions) { data: synonymHit, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2105,18 +2343,21 @@ export function createSearchApi(options: CreateClientOptions) { * @param saveSynonyms.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. * @param saveSynonyms.replaceExistingSynonyms - Replace all synonyms of the index with the ones sent with this request. */ - function saveSynonyms({ - indexName, - synonymHit, - forwardToReplicas, - replaceExistingSynonyms, - }: SaveSynonymsProps): Promise { + function saveSynonyms( + { + indexName, + synonymHit, + forwardToReplicas, + replaceExistingSynonyms, + }: SaveSynonymsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/synonyms/batch'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -2145,10 +2386,14 @@ export function createSearchApi(options: CreateClientOptions) { data: synonymHit, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2159,16 +2404,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param search.indexName - The index in which to perform the request. * @param search.searchParams - The searchParams object. */ - function search({ - indexName, - searchParams, - }: SearchProps): Promise { + function search( + { indexName, searchParams }: SearchProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/query'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -2188,10 +2433,14 @@ export function createSearchApi(options: CreateClientOptions) { data: searchParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2202,16 +2451,19 @@ export function createSearchApi(options: CreateClientOptions) { * @param searchDictionaryEntries.dictionaryName - The dictionary to search in. * @param searchDictionaryEntries.searchDictionaryEntriesParams - The searchDictionaryEntriesParams object. */ - function searchDictionaryEntries({ - dictionaryName, - searchDictionaryEntriesParams, - }: SearchDictionaryEntriesProps): Promise { + function searchDictionaryEntries( + { + dictionaryName, + searchDictionaryEntriesParams, + }: SearchDictionaryEntriesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/dictionaries/{dictionaryName}/search'.replace( '{dictionaryName}', encodeURIComponent(String(dictionaryName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!dictionaryName) { throw new Error( @@ -2237,10 +2489,14 @@ export function createSearchApi(options: CreateClientOptions) { data: searchDictionaryEntriesParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2252,16 +2508,19 @@ export function createSearchApi(options: CreateClientOptions) { * @param searchForFacetValues.facetName - The facet name. * @param searchForFacetValues.searchForFacetValuesRequest - The searchForFacetValuesRequest object. */ - function searchForFacetValues({ - indexName, - facetName, - searchForFacetValuesRequest, - }: SearchForFacetValuesProps): Promise { + function searchForFacetValues( + { + indexName, + facetName, + searchForFacetValuesRequest, + }: SearchForFacetValuesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/facets/{facetName}/query' .replace('{indexName}', encodeURIComponent(String(indexName))) .replace('{facetName}', encodeURIComponent(String(facetName))); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -2281,10 +2540,14 @@ export function createSearchApi(options: CreateClientOptions) { data: searchForFacetValuesRequest, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2295,16 +2558,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param searchRules.indexName - The index in which to perform the request. * @param searchRules.searchRulesParams - The searchRulesParams object. */ - function searchRules({ - indexName, - searchRulesParams, - }: SearchRulesProps): Promise { + function searchRules( + { indexName, searchRulesParams }: SearchRulesProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/rules/search'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -2324,10 +2587,14 @@ export function createSearchApi(options: CreateClientOptions) { data: searchRulesParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2341,19 +2608,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param searchSynonyms.page - Requested page (zero-based). When specified, will retrieve a specific page; the page size is implicitly set to 100. When null, will retrieve all indices (no pagination). * @param searchSynonyms.hitsPerPage - Maximum number of objects to retrieve. */ - function searchSynonyms({ - indexName, - query, - type, - page, - hitsPerPage, - }: SearchSynonymsProps): Promise { + function searchSynonyms( + { indexName, query, type, page, hitsPerPage }: SearchSynonymsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/synonyms/search'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -2382,10 +2646,14 @@ export function createSearchApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2395,11 +2663,12 @@ export function createSearchApi(options: CreateClientOptions) { * @param searchUserIdsParams - The searchUserIdsParams object. */ function searchUserIds( - searchUserIdsParams: SearchUserIdsParams + searchUserIdsParams: SearchUserIdsParams, + requestOptions?: RequestOptions ): Promise { const requestPath = '/1/clusters/mapping/search'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!searchUserIdsParams) { throw new Error( @@ -2419,10 +2688,14 @@ export function createSearchApi(options: CreateClientOptions) { data: searchUserIdsParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2432,11 +2705,12 @@ export function createSearchApi(options: CreateClientOptions) { * @param dictionarySettingsParams - The dictionarySettingsParams object. */ function setDictionarySettings( - dictionarySettingsParams: DictionarySettingsParams + dictionarySettingsParams: DictionarySettingsParams, + requestOptions?: RequestOptions ): Promise { const requestPath = '/1/dictionaries/*/settings'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!dictionarySettingsParams) { throw new Error( @@ -2456,10 +2730,14 @@ export function createSearchApi(options: CreateClientOptions) { data: dictionarySettingsParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2471,17 +2749,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param setSettings.indexSettings - The indexSettings object. * @param setSettings.forwardToReplicas - When true, changes are also propagated to replicas of the given indexName. */ - function setSettings({ - indexName, - indexSettings, - forwardToReplicas, - }: SetSettingsProps): Promise { + function setSettings( + { indexName, indexSettings, forwardToReplicas }: SetSettingsProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/indexes/{indexName}/settings'.replace( '{indexName}', encodeURIComponent(String(indexName)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!indexName) { throw new Error( @@ -2505,10 +2782,14 @@ export function createSearchApi(options: CreateClientOptions) { data: indexSettings, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -2519,16 +2800,16 @@ export function createSearchApi(options: CreateClientOptions) { * @param updateApiKey.key - API Key string. * @param updateApiKey.apiKey - The apiKey object. */ - function updateApiKey({ - key, - apiKey, - }: UpdateApiKeyProps): Promise { + function updateApiKey( + { key, apiKey }: UpdateApiKeyProps, + requestOptions?: RequestOptions + ): Promise { const requestPath = '/1/keys/{key}'.replace( '{key}', encodeURIComponent(String(key)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!key) { throw new Error( @@ -2554,10 +2835,14 @@ export function createSearchApi(options: CreateClientOptions) { data: apiKey, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } return { diff --git a/clients/algoliasearch-client-javascript/packages/client-sources/builds/browser.ts b/clients/algoliasearch-client-javascript/packages/client-sources/builds/browser.ts index bcc946cd85..94405910cc 100644 --- a/clients/algoliasearch-client-javascript/packages/client-sources/builds/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/client-sources/builds/browser.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createFallbackableCache, @@ -18,7 +15,7 @@ export function sourcesApi( appId: string, apiKey: string, region: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): SourcesApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -44,14 +41,19 @@ export function sourcesApi( requester: options?.requester ?? createXhrRequester(), userAgents: [{ segment: 'Browser' }], authMode: 'WithinQueryParameters', - responsesCache: createMemoryCache(), - requestsCache: createMemoryCache({ serializable: false }), - hostsCache: createFallbackableCache({ - caches: [ - createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), - createMemoryCache(), - ], - }), + responsesCache: options?.responsesCache ?? createMemoryCache(), + requestsCache: + options?.requestsCache ?? createMemoryCache({ serializable: false }), + hostsCache: + options?.hostsCache ?? + createFallbackableCache({ + caches: [ + createBrowserLocalStorageCache({ + key: `${apiClientVersion}-${appId}`, + }), + createMemoryCache(), + ], + }), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-sources/builds/node.ts b/clients/algoliasearch-client-javascript/packages/client-sources/builds/node.ts index 6e09ab081b..c74d8a385c 100644 --- a/clients/algoliasearch-client-javascript/packages/client-sources/builds/node.ts +++ b/clients/algoliasearch-client-javascript/packages/client-sources/builds/node.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createNullCache, @@ -17,7 +14,7 @@ export function sourcesApi( appId: string, apiKey: string, region: Region, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): SourcesApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -42,9 +39,9 @@ export function sourcesApi( }, requester: options?.requester ?? createHttpRequester(), userAgents: [{ segment: 'Node.js', version: process.versions.node }], - responsesCache: createNullCache(), - requestsCache: createNullCache(), - hostsCache: createMemoryCache(), + responsesCache: options?.responsesCache ?? createNullCache(), + requestsCache: options?.requestsCache ?? createNullCache(), + hostsCache: options?.hostsCache ?? createMemoryCache(), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/client-sources/src/sourcesApi.ts b/clients/algoliasearch-client-javascript/packages/client-sources/src/sourcesApi.ts index eb249efe4c..db66435eb4 100644 --- a/clients/algoliasearch-client-javascript/packages/client-sources/src/sourcesApi.ts +++ b/clients/algoliasearch-client-javascript/packages/client-sources/src/sourcesApi.ts @@ -8,6 +8,8 @@ import type { Headers, Host, Request, + RequestOptions, + QueryParameters, } from '@experimental-api-clients-automation/client-common'; import type { PostIngestUrlResponse } from '../model/postIngestUrlResponse'; @@ -65,17 +67,16 @@ export function createSourcesApi( * @param del.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param del.body - The parameters to send with the custom request. */ - function del({ - path, - parameters, - body, - }: DelProps): Promise> { + function del( + { path, parameters, body }: DelProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `del`.'); @@ -91,10 +92,14 @@ export function createSourcesApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -105,13 +110,16 @@ export function createSourcesApi( * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. * @param get.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. */ - function get({ path, parameters }: GetProps): Promise> { + function get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `get`.'); @@ -126,10 +134,14 @@ export function createSourcesApi( path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -141,17 +153,16 @@ export function createSourcesApi( * @param post.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param post.body - The parameters to send with the custom request. */ - function post({ - path, - parameters, - body, - }: PostProps): Promise> { + function post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `post`.'); @@ -167,10 +178,14 @@ export function createSourcesApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -180,11 +195,12 @@ export function createSourcesApi( * @param postURLJob - The postURLJob object. */ function postIngestUrl( - postURLJob: PostURLJob + postURLJob: PostURLJob, + requestOptions?: RequestOptions ): Promise { const requestPath = '/1/ingest/url'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!postURLJob) { throw new Error( @@ -214,10 +230,14 @@ export function createSourcesApi( data: postURLJob, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -229,17 +249,16 @@ export function createSourcesApi( * @param put.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param put.body - The parameters to send with the custom request. */ - function put({ - path, - parameters, - body, - }: PutProps): Promise> { + function put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `put`.'); @@ -255,10 +274,14 @@ export function createSourcesApi( data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } return { addUserAgent, del, get, post, postIngestUrl, put }; diff --git a/clients/algoliasearch-client-javascript/packages/recommend/builds/browser.ts b/clients/algoliasearch-client-javascript/packages/recommend/builds/browser.ts index b4adfe3a3a..0c39721dc9 100644 --- a/clients/algoliasearch-client-javascript/packages/recommend/builds/browser.ts +++ b/clients/algoliasearch-client-javascript/packages/recommend/builds/browser.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createFallbackableCache, @@ -17,7 +14,7 @@ export * from '../src/recommendApi'; export function recommendApi( appId: string, apiKey: string, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): RecommendApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -38,14 +35,19 @@ export function recommendApi( requester: options?.requester ?? createXhrRequester(), userAgents: [{ segment: 'Browser' }], authMode: 'WithinQueryParameters', - responsesCache: createMemoryCache(), - requestsCache: createMemoryCache({ serializable: false }), - hostsCache: createFallbackableCache({ - caches: [ - createBrowserLocalStorageCache({ key: `${apiClientVersion}-${appId}` }), - createMemoryCache(), - ], - }), + responsesCache: options?.responsesCache ?? createMemoryCache(), + requestsCache: + options?.requestsCache ?? createMemoryCache({ serializable: false }), + hostsCache: + options?.hostsCache ?? + createFallbackableCache({ + caches: [ + createBrowserLocalStorageCache({ + key: `${apiClientVersion}-${appId}`, + }), + createMemoryCache(), + ], + }), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/recommend/builds/node.ts b/clients/algoliasearch-client-javascript/packages/recommend/builds/node.ts index ad49f4c8bb..91d9c28918 100644 --- a/clients/algoliasearch-client-javascript/packages/recommend/builds/node.ts +++ b/clients/algoliasearch-client-javascript/packages/recommend/builds/node.ts @@ -1,7 +1,4 @@ -import type { - Host, - Requester, -} from '@experimental-api-clients-automation/client-common'; +import type { InitClientOptions } from '@experimental-api-clients-automation/client-common'; import { createMemoryCache, createNullCache, @@ -16,7 +13,7 @@ export * from '../src/recommendApi'; export function recommendApi( appId: string, apiKey: string, - options?: { requester?: Requester; hosts?: Host[] } + options?: InitClientOptions ): RecommendApi { if (!appId) { throw new Error('`appId` is missing.'); @@ -36,9 +33,9 @@ export function recommendApi( }, requester: options?.requester ?? createHttpRequester(), userAgents: [{ segment: 'Node.js', version: process.versions.node }], - responsesCache: createNullCache(), - requestsCache: createNullCache(), - hostsCache: createMemoryCache(), + responsesCache: options?.responsesCache ?? createNullCache(), + requestsCache: options?.requestsCache ?? createNullCache(), + hostsCache: options?.hostsCache ?? createMemoryCache(), ...options, }); } diff --git a/clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts b/clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts index 9f852c119a..2fdfc4c8ee 100644 --- a/clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts +++ b/clients/algoliasearch-client-javascript/packages/recommend/src/recommendApi.ts @@ -9,6 +9,8 @@ import type { Headers, Host, Request, + RequestOptions, + QueryParameters, } from '@experimental-api-clients-automation/client-common'; import type { GetRecommendationsParams } from '../model/getRecommendationsParams'; @@ -87,17 +89,16 @@ export function createRecommendApi(options: CreateClientOptions) { * @param del.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param del.body - The parameters to send with the custom request. */ - function del({ - path, - parameters, - body, - }: DelProps): Promise> { + function del( + { path, parameters, body }: DelProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `del`.'); @@ -113,10 +114,14 @@ export function createRecommendApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -127,13 +132,16 @@ export function createRecommendApi(options: CreateClientOptions) { * @param get.path - The path of the API endpoint to target, anything after the /1 needs to be specified. * @param get.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. */ - function get({ path, parameters }: GetProps): Promise> { + function get( + { path, parameters }: GetProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `get`.'); @@ -148,10 +156,14 @@ export function createRecommendApi(options: CreateClientOptions) { path: requestPath, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -161,11 +173,12 @@ export function createRecommendApi(options: CreateClientOptions) { * @param getRecommendationsParams - The getRecommendationsParams object. */ function getRecommendations( - getRecommendationsParams: GetRecommendationsParams + getRecommendationsParams: GetRecommendationsParams, + requestOptions?: RequestOptions ): Promise { const requestPath = '/1/indexes/*/recommendations'; - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!getRecommendationsParams) { throw new Error( @@ -185,10 +198,14 @@ export function createRecommendApi(options: CreateClientOptions) { data: getRecommendationsParams, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -200,17 +217,16 @@ export function createRecommendApi(options: CreateClientOptions) { * @param post.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param post.body - The parameters to send with the custom request. */ - function post({ - path, - parameters, - body, - }: PostProps): Promise> { + function post( + { path, parameters, body }: PostProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `post`.'); @@ -226,10 +242,14 @@ export function createRecommendApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } /** @@ -241,17 +261,16 @@ export function createRecommendApi(options: CreateClientOptions) { * @param put.parameters - URL-encoded query string. Force some query parameters to be applied for each query made with this API key. * @param put.body - The parameters to send with the custom request. */ - function put({ - path, - parameters, - body, - }: PutProps): Promise> { + function put( + { path, parameters, body }: PutProps, + requestOptions?: RequestOptions + ): Promise> { const requestPath = '/1{path}'.replace( '{path}', encodeURIComponent(String(path)) ); - const headers: Headers = { Accept: 'application/json' }; - const queryParameters: Record = {}; + const headers: Headers = {}; + const queryParameters: QueryParameters = {}; if (!path) { throw new Error('Parameter `path` is required when calling `put`.'); @@ -267,10 +286,14 @@ export function createRecommendApi(options: CreateClientOptions) { data: body, }; - return transporter.request(request, { - queryParameters, - headers, - }); + return transporter.request( + request, + { + queryParameters, + headers, + }, + requestOptions + ); } return { addUserAgent, del, get, getRecommendations, post, put };