// 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 { ABTest } from '../model/aBTest'; import type { ABTestResponse } from '../model/aBTestResponse'; import type { AddABTestsRequest } from '../model/addABTestsRequest'; import type { EstimateABTestRequest } from '../model/estimateABTestRequest'; import type { EstimateABTestResponse } from '../model/estimateABTestResponse'; import type { ListABTestsResponse } from '../model/listABTestsResponse'; import type { CustomDeleteProps, CustomGetProps, CustomPostProps, CustomPutProps, DeleteABTestProps, GetABTestProps, ListABTestsProps, StopABTestProps, } from '../model/clientMethodProps'; export const apiClientVersion = '5.65.0'; export const REGIONS = ['de', 'us'] as const; export type Region = (typeof REGIONS)[number]; export type RegionOptions = { region?: Region | undefined }; function getDefaultHosts(region?: Region | undefined): Host[] { const url = !region ? 'analytics.algolia.com' : 'analytics.{region}.algolia.com'.replace('{region}', region); return [{ url, accept: 'readWrite', protocol: 'https' }]; } export function createAbtestingClient({ 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: 'Abtesting', 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 endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `POST /3/abtests`. Creates a new A/B test. * * Required API Key ACLs: * - editSettings * * @deprecated * @param addABTestsRequest - The addABTestsRequest object. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ addABTests(addABTestsRequest: AddABTestsRequest, requestOptions?: RequestOptions): Promise { validateRequired('addABTestsRequest', 'addABTests', addABTestsRequest); validateRequired('addABTestsRequest.name', 'addABTests', addABTestsRequest.name); validateRequired('addABTestsRequest.variants', 'addABTests', addABTestsRequest.variants); validateRequired('addABTestsRequest.endAt', 'addABTests', addABTestsRequest.endAt); const requestPath = '/2/abtests'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'POST', path: requestPath, queryParameters, headers, data: addABTestsRequest, }; return transporter.request(request, requestOptions); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `POST /3/abtests`. Creates a new A/B test. * * 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: * - editSettings * * @deprecated * @param addABTestsRequest - The addABTestsRequest object. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see addABTests for the plain version. */ addABTestsWithHTTPInfo( addABTestsRequest: AddABTestsRequest, requestOptions?: RequestOptions, ): Promise> { validateRequired('addABTestsRequest', 'addABTestsWithHTTPInfo', addABTestsRequest); validateRequired('addABTestsRequest.name', 'addABTestsWithHTTPInfo', addABTestsRequest.name); validateRequired('addABTestsRequest.variants', 'addABTestsWithHTTPInfo', addABTestsRequest.variants); validateRequired('addABTestsRequest.endAt', 'addABTestsWithHTTPInfo', addABTestsRequest.endAt); const requestPath = '/2/abtests'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'POST', path: requestPath, queryParameters, headers, data: addABTestsRequest, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * 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); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `DELETE /3/abtests/{id}`. Deletes an A/B test by its ID. * * Required API Key ACLs: * - editSettings * * @deprecated * @param deleteABTest - The deleteABTest object. * @param deleteABTest.id - Unique A/B test identifier. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ deleteABTest({ id }: DeleteABTestProps, requestOptions?: RequestOptions): Promise { validateRequired('id', 'deleteABTest', id); const requestPath = '/2/abtests/{id}'.replace('{id}', encodeURIComponent(id)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'DELETE', path: requestPath, queryParameters, headers, }; return transporter.request(request, requestOptions); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `DELETE /3/abtests/{id}`. Deletes an A/B test by its ID. * * 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: * - editSettings * * @deprecated * @param deleteABTest - The deleteABTest object. * @param deleteABTest.id - Unique A/B test identifier. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see deleteABTest for the plain version. */ deleteABTestWithHTTPInfo( { id }: DeleteABTestProps, requestOptions?: RequestOptions, ): Promise> { validateRequired('id', 'deleteABTestWithHTTPInfo', id); const requestPath = '/2/abtests/{id}'.replace('{id}', encodeURIComponent(id)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'DELETE', path: requestPath, queryParameters, headers, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `POST /3/abtests/estimate`. Given the traffic percentage and the expected effect size, this endpoint estimates the sample size and duration of an A/B test based on historical traffic. * * Required API Key ACLs: * - analytics * * @deprecated * @param estimateABTestRequest - The estimateABTestRequest object. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ estimateABTest( estimateABTestRequest: EstimateABTestRequest, requestOptions?: RequestOptions, ): Promise { validateRequired('estimateABTestRequest', 'estimateABTest', estimateABTestRequest); validateRequired('estimateABTestRequest.configuration', 'estimateABTest', estimateABTestRequest.configuration); validateRequired('estimateABTestRequest.variants', 'estimateABTest', estimateABTestRequest.variants); const requestPath = '/2/abtests/estimate'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'POST', path: requestPath, queryParameters, headers, data: estimateABTestRequest, }; return transporter.request(request, requestOptions); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `POST /3/abtests/estimate`. Given the traffic percentage and the expected effect size, this endpoint estimates the sample size and duration of an A/B test based on historical traffic. * * 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: * - analytics * * @deprecated * @param estimateABTestRequest - The estimateABTestRequest object. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see estimateABTest for the plain version. */ estimateABTestWithHTTPInfo( estimateABTestRequest: EstimateABTestRequest, requestOptions?: RequestOptions, ): Promise> { validateRequired('estimateABTestRequest', 'estimateABTestWithHTTPInfo', estimateABTestRequest); validateRequired( 'estimateABTestRequest.configuration', 'estimateABTestWithHTTPInfo', estimateABTestRequest.configuration, ); validateRequired('estimateABTestRequest.variants', 'estimateABTestWithHTTPInfo', estimateABTestRequest.variants); const requestPath = '/2/abtests/estimate'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'POST', path: requestPath, queryParameters, headers, data: estimateABTestRequest, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `GET /3/abtests/{id}`. Retrieves the details for an A/B test by its ID. * * Required API Key ACLs: * - analytics * * @deprecated * @param getABTest - The getABTest object. * @param getABTest.id - Unique A/B test identifier. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ getABTest({ id }: GetABTestProps, requestOptions?: RequestOptions): Promise { validateRequired('id', 'getABTest', id); const requestPath = '/2/abtests/{id}'.replace('{id}', encodeURIComponent(id)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, queryParameters, headers, }; return transporter.request(request, requestOptions); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `GET /3/abtests/{id}`. Retrieves the details for an A/B test by its ID. * * 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: * - analytics * * @deprecated * @param getABTest - The getABTest object. * @param getABTest.id - Unique A/B test identifier. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see getABTest for the plain version. */ getABTestWithHTTPInfo( { id }: GetABTestProps, requestOptions?: RequestOptions, ): Promise> { validateRequired('id', 'getABTestWithHTTPInfo', id); const requestPath = '/2/abtests/{id}'.replace('{id}', encodeURIComponent(id)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'GET', path: requestPath, queryParameters, headers, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `GET /3/abtests`. Lists all A/B tests you configured for this application. * * Required API Key ACLs: * - analytics * * @deprecated * @param listABTests - The listABTests object. * @param listABTests.offset - Position of the first item to return. * @param listABTests.limit - Number of items to return. * @param listABTests.indexPrefix - Index name prefix. Only A/B tests for indices starting with this string are included in the response. * @param listABTests.indexSuffix - Index name suffix. Only A/B tests for indices ending with this string are included in the response. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ listABTests( { offset, limit, indexPrefix, indexSuffix }: ListABTestsProps = {}, requestOptions: RequestOptions | undefined = undefined, ): Promise { const requestPath = '/2/abtests'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; if (offset !== undefined) { queryParameters['offset'] = offset.toString(); } if (limit !== undefined) { queryParameters['limit'] = limit.toString(); } if (indexPrefix !== undefined) { queryParameters['indexPrefix'] = indexPrefix.toString(); } if (indexSuffix !== undefined) { queryParameters['indexSuffix'] = indexSuffix.toString(); } const request: Request = { method: 'GET', path: requestPath, queryParameters, headers, }; return transporter.request(request, requestOptions); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `GET /3/abtests`. Lists all A/B tests you configured for this application. * * 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: * - analytics * * @deprecated * @param listABTests - The listABTests object. * @param listABTests.offset - Position of the first item to return. * @param listABTests.limit - Number of items to return. * @param listABTests.indexPrefix - Index name prefix. Only A/B tests for indices starting with this string are included in the response. * @param listABTests.indexSuffix - Index name suffix. Only A/B tests for indices ending with this string are included in the response. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see listABTests for the plain version. */ listABTestsWithHTTPInfo( { offset, limit, indexPrefix, indexSuffix }: ListABTestsProps = {}, requestOptions: RequestOptions | undefined = undefined, ): Promise> { const requestPath = '/2/abtests'; const headers: Headers = {}; const queryParameters: QueryParameters = {}; if (offset !== undefined) { queryParameters['offset'] = offset.toString(); } if (limit !== undefined) { queryParameters['limit'] = limit.toString(); } if (indexPrefix !== undefined) { queryParameters['indexPrefix'] = indexPrefix.toString(); } if (indexSuffix !== undefined) { queryParameters['indexSuffix'] = indexSuffix.toString(); } const request: Request = { method: 'GET', path: requestPath, queryParameters, headers, }; return transporter.requestWithHttpInfo(request, requestOptions); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `POST /3/abtests/{id}/stop`. Stops an A/B test by its ID. You can\'t restart stopped A/B tests. * * Required API Key ACLs: * - editSettings * * @deprecated * @param stopABTest - The stopABTest object. * @param stopABTest.id - Unique A/B test identifier. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. */ stopABTest({ id }: StopABTestProps, requestOptions?: RequestOptions): Promise { validateRequired('id', 'stopABTest', id); const requestPath = '/2/abtests/{id}/stop'.replace('{id}', encodeURIComponent(id)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'POST', path: requestPath, queryParameters, headers, }; return transporter.request(request, requestOptions); }, /** * This endpoint is deprecated. Use the A/B Testing API v3 instead. Replaced by `POST /3/abtests/{id}/stop`. Stops an A/B test by its ID. You can\'t restart stopped A/B tests. * * 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: * - editSettings * * @deprecated * @param stopABTest - The stopABTest object. * @param stopABTest.id - Unique A/B test identifier. * @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions. * @see stopABTest for the plain version. */ stopABTestWithHTTPInfo( { id }: StopABTestProps, requestOptions?: RequestOptions, ): Promise> { validateRequired('id', 'stopABTestWithHTTPInfo', id); const requestPath = '/2/abtests/{id}/stop'.replace('{id}', encodeURIComponent(id)); const headers: Headers = {}; const queryParameters: QueryParameters = {}; const request: Request = { method: 'POST', path: requestPath, queryParameters, headers, }; return transporter.requestWithHttpInfo(request, requestOptions); }, }; }