// Code generated by OpenAPI Generator (https://openapi-generator.tech), manual changes will be lost - read more on https://github.com/algolia/api-clients-automation. DO NOT EDIT. import type { AlgoliaHttpResponse, CreateClientOptions, Headers, Host, QueryParameters, Request, RequestOptions, } from '@algolia/client-common'; import { createAuth, createTransporter, getAlgoliaAgent, validateRequired } from '@algolia/client-common'; import type { DeleteUserProfileResponse } from '../model/deleteUserProfileResponse'; import type { GetUserTokenResponse } from '../model/getUserTokenResponse'; import type { PersonalizationStrategyParams } from '../model/personalizationStrategyParams'; import type { SetPersonalizationStrategyResponse } from '../model/setPersonalizationStrategyResponse'; import type { CustomDeleteProps, CustomGetProps, CustomPostProps, CustomPutProps, DeleteUserProfileProps, GetUserTokenProfileProps, } from '../model/clientMethodProps'; export const apiClientVersion = '5.65.1'; export const REGIONS = ['eu', 'us'] as const; export type Region = (typeof REGIONS)[number]; export type RegionOptions = { region: Region }; function getDefaultHosts(region: Region): Host[] { const url = 'personalization.{region}.algolia.com'.replace('{region}', region); return [{ url, accept: 'readWrite', protocol: 'https' }]; } export function createPersonalizationClient({ appId: appIdOption, apiKey: apiKeyOption, authMode, algoliaAgents, region: regionOption, ...options }: CreateClientOptions & RegionOptions) { const auth = createAuth(appIdOption, apiKeyOption, authMode); const transporter = createTransporter({ hosts: getDefaultHosts(regionOption), ...options, algoliaAgent: getAlgoliaAgent({ algoliaAgents, client: 'Personalization', version: apiClientVersion, }), baseHeaders: { 'content-type': 'text/plain', ...auth.headers(), ...options.baseHeaders, }, baseQueryParameters: { ...auth.queryParameters(), ...options.baseQueryParameters, }, }); return { transporter, /** * The `appId` currently in use. */ appId: appIdOption, /** * The `apiKey` currently in use. */ apiKey: apiKeyOption, /** * Clears the cache of the transporter for the `requestsCache` and `responsesCache` properties. */ clearCache(): Promise { return Promise.all([transporter.requestsCache.clear(), transporter.responsesCache.clear()]).then(() => undefined); }, /** * Get the value of the `algoliaAgent`, used by our libraries internally and telemetry system. */ get _ua(): string { return transporter.algoliaAgent.value; }, /** * Adds a `segment` to the `x-algolia-agent` sent with every requests. * * @param segment - The algolia agent (user-agent) segment to add. * @param version - The version of the agent. */ addAlgoliaAgent(segment: string, version?: string | undefined): void { transporter.algoliaAgent.add({ segment, version }); }, /** * Helper method to switch the API key used to authenticate the requests. * * @param params - Method params. * @param params.apiKey - The new API Key to use. */ setClientApiKey({ apiKey }: { apiKey: string }): void { if (!authMode || authMode === 'WithinHeaders') { transporter.baseHeaders['x-algolia-api-key'] = apiKey; } else { transporter.baseQueryParameters['x-algolia-api-key'] = apiKey; } }, /** * This method lets you send requests to the Algolia REST API. * @param customDelete - The customDelete object. * @param customDelete.path - Path of the endpoint, for example `1/newFeature`. * @param customDelete.parameters - Query parameters to apply to the current query. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ customDelete( { path, parameters }: CustomDeleteProps, requestOptions?: RequestOptions, ): Promise> { validateRequired('path', 'customDelete', path); const requestPath = '/{path}'.replace('{path}', path); const headers: Headers = {}; const queryParameters: QueryParameters = parameters ? parameters : {}; const request: Request = { method: 'DELETE', path: requestPath, queryParameters, headers, }; return transporter.request(request, requestOptions); }, /** * This method lets you send requests to the Algolia REST API. * * Resolves with the full HTTP response information: status code, headers (when the requester captures them), raw body and deserialized data. Bypasses the requests and responses caches: always performs the API call. * @param customDelete - The customDelete object. * @param customDelete.path - Path of the endpoint, for example `1/newFeature`. * @param customDelete.parameters - Query parameters to apply to the current query. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see customDelete for the plain version. */ customDeleteWithHTTPInfo( { path, parameters }: CustomDeleteProps, requestOptions?: RequestOptions, ): Promise>> { validateRequired('path', 'customDeleteWithHTTPInfo', path); const requestPath = '/{path}'.replace('{path}', path); const headers: Headers = {}; const queryParameters: QueryParameters = parameters ? parameters : {}; const request: Request = { method: 'DELETE', path: requestPath, queryParameters, headers, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * This method lets you send requests to the Algolia REST API. * @param customGet - The customGet object. * @param customGet.path - Path of the endpoint, for example `1/newFeature`. * @param customGet.parameters - Query parameters to apply to the current query. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ customGet({ path, parameters }: CustomGetProps, requestOptions?: RequestOptions): Promise> { validateRequired('path', 'customGet', path); const requestPath = '/{path}'.replace('{path}', path); const headers: Headers = {}; const queryParameters: QueryParameters = parameters ? parameters : {}; const request: Request = { method: 'GET', path: requestPath, queryParameters, headers, }; return transporter.request(request, requestOptions); }, /** * This method lets you send requests to the Algolia REST API. * * Resolves with the full HTTP response information: status code, headers (when the requester captures them), raw body and deserialized data. Bypasses the requests and responses caches: always performs the API call. * @param customGet - The customGet object. * @param customGet.path - Path of the endpoint, for example `1/newFeature`. * @param customGet.parameters - Query parameters to apply to the current query. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see customGet for the plain version. */ customGetWithHTTPInfo( { path, parameters }: CustomGetProps, requestOptions?: RequestOptions, ): Promise>> { validateRequired('path', 'customGetWithHTTPInfo', path); const requestPath = '/{path}'.replace('{path}', path); const headers: Headers = {}; const queryParameters: QueryParameters = parameters ? parameters : {}; const request: Request = { method: 'GET', path: requestPath, queryParameters, headers, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * This method lets you send requests to the Algolia REST API. * @param customPost - The customPost object. * @param customPost.path - Path of the endpoint, for example `1/newFeature`. * @param customPost.parameters - Query parameters to apply to the current query. * @param customPost.body - Parameters to send with the custom request. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ customPost( { path, parameters, body }: CustomPostProps, requestOptions?: RequestOptions, ): Promise> { validateRequired('path', 'customPost', path); const requestPath = '/{path}'.replace('{path}', path); const headers: Headers = {}; const queryParameters: QueryParameters = parameters ? parameters : {}; const request: Request = { method: 'POST', path: requestPath, queryParameters, headers, data: body ? body : {}, }; return transporter.request(request, requestOptions); }, /** * This method lets you send requests to the Algolia REST API. * * Resolves with the full HTTP response information: status code, headers (when the requester captures them), raw body and deserialized data. Bypasses the requests and responses caches: always performs the API call. * @param customPost - The customPost object. * @param customPost.path - Path of the endpoint, for example `1/newFeature`. * @param customPost.parameters - Query parameters to apply to the current query. * @param customPost.body - Parameters to send with the custom request. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see customPost for the plain version. */ customPostWithHTTPInfo( { path, parameters, body }: CustomPostProps, requestOptions?: RequestOptions, ): Promise>> { validateRequired('path', 'customPostWithHTTPInfo', path); const requestPath = '/{path}'.replace('{path}', path); const headers: Headers = {}; const queryParameters: QueryParameters = parameters ? parameters : {}; const request: Request = { method: 'POST', path: requestPath, queryParameters, headers, data: body ? body : {}, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * This method lets you send requests to the Algolia REST API. * @param customPut - The customPut object. * @param customPut.path - Path of the endpoint, for example `1/newFeature`. * @param customPut.parameters - Query parameters to apply to the current query. * @param customPut.body - Parameters to send with the custom request. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ customPut( { path, parameters, body }: CustomPutProps, requestOptions?: RequestOptions, ): Promise> { validateRequired('path', 'customPut', path); const requestPath = '/{path}'.replace('{path}', path); const headers: Headers = {}; const queryParameters: QueryParameters = parameters ? parameters : {}; const request: Request = { method: 'PUT', path: requestPath, queryParameters, headers, data: body ? body : {}, }; return transporter.request(request, requestOptions); }, /** * This method lets you send requests to the Algolia REST API. * * Resolves with the full HTTP response information: status code, headers (when the requester captures them), raw body and deserialized data. Bypasses the requests and responses caches: always performs the API call. * @param customPut - The customPut object. * @param customPut.path - Path of the endpoint, for example `1/newFeature`. * @param customPut.parameters - Query parameters to apply to the current query. * @param customPut.body - Parameters to send with the custom request. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see customPut for the plain version. */ customPutWithHTTPInfo( { path, parameters, body }: CustomPutProps, requestOptions?: RequestOptions, ): Promise>> { validateRequired('path', 'customPutWithHTTPInfo', path); const requestPath = '/{path}'.replace('{path}', path); const headers: Headers = {}; const queryParameters: QueryParameters = parameters ? parameters : {}; const request: Request = { method: 'PUT', path: requestPath, queryParameters, headers, data: body ? body : {}, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * Deletes a user profile. The response includes a date and time when the user profile can safely be considered deleted. * * Required API Key ACLs: * - recommendation * @param deleteUserProfile - The deleteUserProfile object. * @param deleteUserProfile.userToken - Unique identifier representing a user for which to fetch the personalization profile. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ deleteUserProfile( { userToken }: DeleteUserProfileProps, requestOptions?: RequestOptions, ): Promise { validateRequired('userToken', 'deleteUserProfile', userToken); const requestPath = '/1/profiles/{userToken}'.replace('{userToken}', encodeURIComponent(userToken)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'DELETE', path: requestPath, queryParameters, headers, }; return transporter.request(request, requestOptions); }, /** * Deletes a user profile. The response includes a date and time when the user profile can safely be considered deleted. * * Resolves with the full HTTP response information: status code, headers (when the requester captures them), raw body and deserialized data. Bypasses the requests and responses caches: always performs the API call. * * Required API Key ACLs: * - recommendation * @param deleteUserProfile - The deleteUserProfile object. * @param deleteUserProfile.userToken - Unique identifier representing a user for which to fetch the personalization profile. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see deleteUserProfile for the plain version. */ deleteUserProfileWithHTTPInfo( { userToken }: DeleteUserProfileProps, requestOptions?: RequestOptions, ): Promise> { validateRequired('userToken', 'deleteUserProfileWithHTTPInfo', userToken); const requestPath = '/1/profiles/{userToken}'.replace('{userToken}', encodeURIComponent(userToken)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'DELETE', path: requestPath, queryParameters, headers, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * Retrieves the current personalization strategy. * * Required API Key ACLs: * - recommendation * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ getPersonalizationStrategy(requestOptions?: RequestOptions | undefined): Promise { const requestPath = '/1/strategies/personalization'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, queryParameters, headers, }; return transporter.request(request, requestOptions); }, /** * Retrieves the current personalization strategy. * * Resolves with the full HTTP response information: status code, headers (when the requester captures them), raw body and deserialized data. Bypasses the requests and responses caches: always performs the API call. * * Required API Key ACLs: * - recommendation * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see getPersonalizationStrategy for the plain version. */ getPersonalizationStrategyWithHTTPInfo( requestOptions?: RequestOptions | undefined, ): Promise> { const requestPath = '/1/strategies/personalization'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, queryParameters, headers, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * Retrieves a user profile and their affinities for different facets. * * Required API Key ACLs: * - recommendation * @param getUserTokenProfile - The getUserTokenProfile object. * @param getUserTokenProfile.userToken - Unique identifier representing a user for which to fetch the personalization profile. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ getUserTokenProfile( { userToken }: GetUserTokenProfileProps, requestOptions?: RequestOptions, ): Promise { validateRequired('userToken', 'getUserTokenProfile', userToken); const requestPath = '/1/profiles/personalization/{userToken}'.replace( '{userToken}', encodeURIComponent(userToken), ); const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, queryParameters, headers, }; return transporter.request(request, requestOptions); }, /** * Retrieves a user profile and their affinities for different facets. * * Resolves with the full HTTP response information: status code, headers (when the requester captures them), raw body and deserialized data. Bypasses the requests and responses caches: always performs the API call. * * Required API Key ACLs: * - recommendation * @param getUserTokenProfile - The getUserTokenProfile object. * @param getUserTokenProfile.userToken - Unique identifier representing a user for which to fetch the personalization profile. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see getUserTokenProfile for the plain version. */ getUserTokenProfileWithHTTPInfo( { userToken }: GetUserTokenProfileProps, requestOptions?: RequestOptions, ): Promise> { validateRequired('userToken', 'getUserTokenProfileWithHTTPInfo', userToken); const requestPath = '/1/profiles/personalization/{userToken}'.replace( '{userToken}', encodeURIComponent(userToken), ); const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, queryParameters, headers, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * Creates a new personalization strategy. * * Required API Key ACLs: * - recommendation * @param personalizationStrategyParams - The personalizationStrategyParams object. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ setPersonalizationStrategy( personalizationStrategyParams: PersonalizationStrategyParams, requestOptions?: RequestOptions, ): Promise { validateRequired('personalizationStrategyParams', 'setPersonalizationStrategy', personalizationStrategyParams); validateRequired( 'personalizationStrategyParams.eventsScoring', 'setPersonalizationStrategy', personalizationStrategyParams.eventsScoring, ); validateRequired( 'personalizationStrategyParams.facetsScoring', 'setPersonalizationStrategy', personalizationStrategyParams.facetsScoring, ); validateRequired( 'personalizationStrategyParams.personalizationImpact', 'setPersonalizationStrategy', personalizationStrategyParams.personalizationImpact, ); const requestPath = '/1/strategies/personalization'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'POST', path: requestPath, queryParameters, headers, data: personalizationStrategyParams, }; return transporter.request(request, requestOptions); }, /** * Creates a new personalization strategy. * * Resolves with the full HTTP response information: status code, headers (when the requester captures them), raw body and deserialized data. Bypasses the requests and responses caches: always performs the API call. * * Required API Key ACLs: * - recommendation * @param personalizationStrategyParams - The personalizationStrategyParams object. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see setPersonalizationStrategy for the plain version. */ setPersonalizationStrategyWithHTTPInfo( personalizationStrategyParams: PersonalizationStrategyParams, requestOptions?: RequestOptions, ): Promise> { validateRequired( 'personalizationStrategyParams', 'setPersonalizationStrategyWithHTTPInfo', personalizationStrategyParams, ); validateRequired( 'personalizationStrategyParams.eventsScoring', 'setPersonalizationStrategyWithHTTPInfo', personalizationStrategyParams.eventsScoring, ); validateRequired( 'personalizationStrategyParams.facetsScoring', 'setPersonalizationStrategyWithHTTPInfo', personalizationStrategyParams.facetsScoring, ); validateRequired( 'personalizationStrategyParams.personalizationImpact', 'setPersonalizationStrategyWithHTTPInfo', personalizationStrategyParams.personalizationImpact, ); const requestPath = '/1/strategies/personalization'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'POST', path: requestPath, queryParameters, headers, data: personalizationStrategyParams, }; return transporter.requestWithHttpInfo(request, requestOptions); }, }; }