@augustofarnese/client-common 5.49.1-patched.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/common.cjs +706 -0
- package/dist/common.cjs.map +1 -0
- package/dist/common.d.cts +467 -0
- package/dist/common.d.ts +467 -0
- package/dist/common.js +641 -0
- package/dist/common.js.map +1 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/cache/createBrowserLocalStorageCache.ts","../src/cache/createNullCache.ts","../src/cache/createFallbackableCache.ts","../src/cache/createMemoryCache.ts","../src/constants.ts","../src/createAlgoliaAgent.ts","../src/createAuth.ts","../src/createIterablePromise.ts","../src/getAlgoliaAgent.ts","../src/logger/createNullLogger.ts","../src/transporter/createStatefulHost.ts","../src/transporter/errors.ts","../src/transporter/helpers.ts","../src/transporter/responses.ts","../src/transporter/stackTrace.ts","../src/transporter/createTransporter.ts","../src/types/logger.ts"],"sourcesContent":["export * from './cache';\nexport * from './constants';\nexport * from './createAlgoliaAgent';\nexport * from './createAuth';\nexport * from './createIterablePromise';\nexport * from './getAlgoliaAgent';\nexport * from './logger';\nexport * from './transporter';\nexport * from './types';\n","import type { BrowserLocalStorageCacheItem, BrowserLocalStorageOptions, Cache, CacheEvents } from '../types';\n\nexport function createBrowserLocalStorageCache(options: BrowserLocalStorageOptions): Cache {\n let storage: Storage;\n // We've changed the namespace to avoid conflicts with v4, as this version is a huge breaking change\n const namespaceKey = `algolia-client-js-${options.key}`;\n\n function getStorage(): Storage {\n if (storage === undefined) {\n storage = options.localStorage || window.localStorage;\n }\n\n return storage;\n }\n\n function getNamespace<TValue>(): Record<string, TValue> {\n return JSON.parse(getStorage().getItem(namespaceKey) || '{}');\n }\n\n function setNamespace(namespace: Record<string, any>): void {\n getStorage().setItem(namespaceKey, JSON.stringify(namespace));\n }\n\n function removeOutdatedCacheItems(): void {\n const timeToLive = options.timeToLive ? options.timeToLive * 1000 : null;\n const namespace = getNamespace<BrowserLocalStorageCacheItem>();\n\n const filteredNamespaceWithoutOldFormattedCacheItems = Object.fromEntries(\n Object.entries(namespace).filter(([, cacheItem]) => {\n return cacheItem.timestamp !== undefined;\n }),\n );\n\n setNamespace(filteredNamespaceWithoutOldFormattedCacheItems);\n\n if (!timeToLive) {\n return;\n }\n\n const filteredNamespaceWithoutExpiredItems = Object.fromEntries(\n Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(([, cacheItem]) => {\n const currentTimestamp = new Date().getTime();\n const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;\n\n return !isExpired;\n }),\n );\n\n setNamespace(filteredNamespaceWithoutExpiredItems);\n }\n\n return {\n get<TValue>(\n key: Record<string, any> | string,\n defaultValue: () => Promise<TValue>,\n events: CacheEvents<TValue> = {\n miss: () => Promise.resolve(),\n },\n ): Promise<TValue> {\n return Promise.resolve()\n .then(() => {\n removeOutdatedCacheItems();\n\n return getNamespace<Promise<BrowserLocalStorageCacheItem>>()[JSON.stringify(key)];\n })\n .then((value) => {\n return Promise.all([value ? value.value : defaultValue(), value !== undefined]);\n })\n .then(([value, exists]) => {\n return Promise.all([value, exists || events.miss(value)]);\n })\n .then(([value]) => value);\n },\n\n set<TValue>(key: Record<string, any> | string, value: TValue): Promise<TValue> {\n return Promise.resolve().then(() => {\n const namespace = getNamespace();\n\n namespace[JSON.stringify(key)] = {\n timestamp: new Date().getTime(),\n value,\n };\n\n getStorage().setItem(namespaceKey, JSON.stringify(namespace));\n\n return value;\n });\n },\n\n delete(key: Record<string, any> | string): Promise<void> {\n return Promise.resolve().then(() => {\n const namespace = getNamespace();\n\n delete namespace[JSON.stringify(key)];\n\n getStorage().setItem(namespaceKey, JSON.stringify(namespace));\n });\n },\n\n clear(): Promise<void> {\n return Promise.resolve().then(() => {\n getStorage().removeItem(namespaceKey);\n });\n },\n };\n}\n","import type { Cache, CacheEvents } from '../types';\n\nexport function createNullCache(): Cache {\n return {\n get<TValue>(\n _key: Record<string, any> | string,\n defaultValue: () => Promise<TValue>,\n events: CacheEvents<TValue> = {\n miss: (): Promise<void> => Promise.resolve(),\n },\n ): Promise<TValue> {\n const value = defaultValue();\n\n return value.then((result) => Promise.all([result, events.miss(result)])).then(([result]) => result);\n },\n\n set<TValue>(_key: Record<string, any> | string, value: TValue): Promise<TValue> {\n return Promise.resolve(value);\n },\n\n delete(_key: Record<string, any> | string): Promise<void> {\n return Promise.resolve();\n },\n\n clear(): Promise<void> {\n return Promise.resolve();\n },\n };\n}\n","import type { Cache, CacheEvents, FallbackableCacheOptions } from '../types';\nimport { createNullCache } from './createNullCache';\n\nexport function createFallbackableCache(options: FallbackableCacheOptions): Cache {\n const caches = [...options.caches];\n const current = caches.shift();\n\n if (current === undefined) {\n return createNullCache();\n }\n\n return {\n get<TValue>(\n key: Record<string, any> | string,\n defaultValue: () => Promise<TValue>,\n events: CacheEvents<TValue> = {\n miss: (): Promise<void> => Promise.resolve(),\n },\n ): Promise<TValue> {\n return current.get(key, defaultValue, events).catch(() => {\n return createFallbackableCache({ caches }).get(key, defaultValue, events);\n });\n },\n\n set<TValue>(key: Record<string, any> | string, value: TValue): Promise<TValue> {\n return current.set(key, value).catch(() => {\n return createFallbackableCache({ caches }).set(key, value);\n });\n },\n\n delete(key: Record<string, any> | string): Promise<void> {\n return current.delete(key).catch(() => {\n return createFallbackableCache({ caches }).delete(key);\n });\n },\n\n clear(): Promise<void> {\n return current.clear().catch(() => {\n return createFallbackableCache({ caches }).clear();\n });\n },\n };\n}\n","import type { Cache, CacheEvents, MemoryCacheOptions } from '../types';\n\nexport function createMemoryCache(options: MemoryCacheOptions = { serializable: true }): Cache {\n let cache: Record<string, any> = {};\n\n return {\n get<TValue>(\n key: Record<string, any> | string,\n defaultValue: () => Promise<TValue>,\n events: CacheEvents<TValue> = {\n miss: (): Promise<void> => Promise.resolve(),\n },\n ): Promise<TValue> {\n const keyAsString = JSON.stringify(key);\n\n if (keyAsString in cache) {\n return Promise.resolve(options.serializable ? JSON.parse(cache[keyAsString]) : cache[keyAsString]);\n }\n\n const promise = defaultValue();\n\n return promise.then((value: TValue) => events.miss(value)).then(() => promise);\n },\n\n set<TValue>(key: Record<string, any> | string, value: TValue): Promise<TValue> {\n cache[JSON.stringify(key)] = options.serializable ? JSON.stringify(value) : value;\n\n return Promise.resolve(value);\n },\n\n delete(key: Record<string, unknown> | string): Promise<void> {\n delete cache[JSON.stringify(key)];\n\n return Promise.resolve();\n },\n\n clear(): Promise<void> {\n cache = {};\n\n return Promise.resolve();\n },\n };\n}\n","export const DEFAULT_CONNECT_TIMEOUT_BROWSER = 1000;\nexport const DEFAULT_READ_TIMEOUT_BROWSER = 2000;\nexport const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;\n\nexport const DEFAULT_CONNECT_TIMEOUT_NODE = 2000;\nexport const DEFAULT_READ_TIMEOUT_NODE = 5000;\nexport const DEFAULT_WRITE_TIMEOUT_NODE = 30000;\n","import type { AlgoliaAgent, AlgoliaAgentOptions } from './types';\n\nexport function createAlgoliaAgent(version: string): AlgoliaAgent {\n const algoliaAgent = {\n value: `Algolia for JavaScript (${version})`,\n add(options: AlgoliaAgentOptions): AlgoliaAgent {\n const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;\n\n if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {\n algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;\n }\n\n return algoliaAgent;\n },\n };\n\n return algoliaAgent;\n}\n","import type { AuthMode, Headers, QueryParameters } from './types';\n\nexport function createAuth(\n appId: string,\n apiKey: string,\n authMode: AuthMode = 'WithinHeaders',\n): {\n readonly headers: () => Headers;\n readonly queryParameters: () => QueryParameters;\n} {\n const credentials = {\n 'x-algolia-api-key': apiKey,\n 'x-algolia-application-id': appId,\n };\n\n return {\n headers(): Headers {\n return authMode === 'WithinHeaders' ? credentials : {};\n },\n\n queryParameters(): QueryParameters {\n return authMode === 'WithinQueryParameters' ? credentials : {};\n },\n };\n}\n","import type { CreateIterablePromise } from './types/createIterablePromise';\n\n/**\n * Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.\n *\n * @param createIterator - The createIterator options.\n * @param createIterator.func - The function to run, which returns a promise.\n * @param createIterator.validate - The validator function. It receives the resolved return of `func`.\n * @param createIterator.aggregator - The function that runs right after the `func` method has been executed, allows you to do anything with the response before `validate`.\n * @param createIterator.error - The `validate` condition to throw an error, and its message.\n * @param createIterator.timeout - The function to decide how long to wait between iterations.\n */\nexport function createIterablePromise<TResponse>({\n func,\n validate,\n aggregator,\n error,\n timeout = (): number => 0,\n}: CreateIterablePromise<TResponse>): Promise<TResponse> {\n const retry = (previousResponse?: TResponse | undefined): Promise<TResponse> => {\n return new Promise<TResponse>((resolve, reject) => {\n func(previousResponse)\n .then(async (response) => {\n if (aggregator) {\n await aggregator(response);\n }\n\n if (await validate(response)) {\n return resolve(response);\n }\n\n if (error && (await error.validate(response))) {\n return reject(new Error(await error.message(response)));\n }\n\n return setTimeout(\n () => {\n retry(response).then(resolve).catch(reject);\n },\n await timeout(),\n );\n })\n .catch((err) => {\n reject(err);\n });\n });\n };\n\n return retry();\n}\n","import { createAlgoliaAgent } from './createAlgoliaAgent';\nimport type { AlgoliaAgent, AlgoliaAgentOptions } from './types';\n\nexport type GetAlgoliaAgent = {\n algoliaAgents: AlgoliaAgentOptions[];\n client: string;\n version: string;\n};\n\nexport function getAlgoliaAgent({ algoliaAgents, client, version }: GetAlgoliaAgent): AlgoliaAgent {\n const defaultAlgoliaAgent = createAlgoliaAgent(version).add({\n segment: client,\n version,\n });\n\n algoliaAgents.forEach((algoliaAgent) => defaultAlgoliaAgent.add(algoliaAgent));\n\n return defaultAlgoliaAgent;\n}\n","import type { Logger } from '../types/logger';\n\nexport function createNullLogger(): Logger {\n return {\n debug(_message: string, _args?: any | undefined): Promise<void> {\n return Promise.resolve();\n },\n info(_message: string, _args?: any | undefined): Promise<void> {\n return Promise.resolve();\n },\n error(_message: string, _args?: any | undefined): Promise<void> {\n return Promise.resolve();\n },\n };\n}\n","import type { Host, StatefulHost } from '../types';\n\n// By default, API Clients at Algolia have expiration delay of 5 mins.\n// In the JavaScript client, we have 2 mins.\nconst EXPIRATION_DELAY = 2 * 60 * 1000;\n\nexport function createStatefulHost(host: Host, status: StatefulHost['status'] = 'up'): StatefulHost {\n const lastUpdate = Date.now();\n\n function isUp(): boolean {\n return status === 'up' || Date.now() - lastUpdate > EXPIRATION_DELAY;\n }\n\n function isTimedOut(): boolean {\n return status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY;\n }\n\n return { ...host, status, lastUpdate, isUp, isTimedOut };\n}\n","import type { Response, StackFrame } from '../types';\n\nexport class AlgoliaError extends Error {\n override name: string = 'AlgoliaError';\n\n constructor(message: string, name: string) {\n super(message);\n\n if (name) {\n this.name = name;\n }\n }\n}\n\nexport class IndexNotFoundError extends AlgoliaError {\n constructor(indexName: string) {\n super(`${indexName} does not exist`, 'IndexNotFoundError');\n }\n}\n\nexport class IndicesInSameAppError extends AlgoliaError {\n constructor() {\n super('Indices are in the same application. Use operationIndex instead.', 'IndicesInSameAppError');\n }\n}\n\nexport class IndexAlreadyExistsError extends AlgoliaError {\n constructor(indexName: string) {\n super(`${indexName} index already exists.`, 'IndexAlreadyExistsError');\n }\n}\n\nexport class ErrorWithStackTrace extends AlgoliaError {\n stackTrace: StackFrame[];\n\n constructor(message: string, stackTrace: StackFrame[], name: string) {\n super(message, name);\n // the array and object should be frozen to reflect the stackTrace at the time of the error\n this.stackTrace = stackTrace;\n }\n}\n\nexport class RetryError extends ErrorWithStackTrace {\n constructor(stackTrace: StackFrame[]) {\n super(\n 'Unreachable hosts - your application id may be incorrect. If the error persists, please visit our help center https://alg.li/support-unreachable-hosts or reach out to the Algolia Support team: https://alg.li/support',\n stackTrace,\n 'RetryError',\n );\n }\n}\n\nexport class ApiError extends ErrorWithStackTrace {\n status: number;\n\n constructor(message: string, status: number, stackTrace: StackFrame[], name = 'ApiError') {\n super(message, stackTrace, name);\n this.status = status;\n }\n}\n\nexport class DeserializationError extends AlgoliaError {\n response: Response;\n\n constructor(message: string, response: Response) {\n super(message, 'DeserializationError');\n this.response = response;\n }\n}\n\nexport type DetailedErrorWithMessage = {\n message: string;\n label: string;\n};\n\nexport type DetailedErrorWithTypeID = {\n id: string;\n type: string;\n name?: string | undefined;\n};\n\nexport type DetailedError = {\n code: string;\n details?: DetailedErrorWithMessage[] | DetailedErrorWithTypeID[] | undefined;\n};\n\n// DetailedApiError is only used by the ingestion client to return more informative error, other clients will use ApiClient.\nexport class DetailedApiError extends ApiError {\n error: DetailedError;\n\n constructor(message: string, status: number, error: DetailedError, stackTrace: StackFrame[]) {\n super(message, status, stackTrace, 'DetailedApiError');\n this.error = error;\n }\n}\n","import type { Headers, Host, QueryParameters, Request, RequestOptions, Response, StackFrame } from '../types';\nimport { ApiError, DeserializationError, DetailedApiError } from './errors';\n\nexport function shuffle<TData>(array: TData[]): TData[] {\n const shuffledArray = array;\n\n for (let c = array.length - 1; c > 0; c--) {\n const b = Math.floor(Math.random() * (c + 1));\n const a = array[c];\n\n shuffledArray[c] = array[b];\n shuffledArray[b] = a;\n }\n\n return shuffledArray;\n}\n\nexport function serializeUrl(host: Host, path: string, queryParameters: QueryParameters): string {\n const queryParametersAsString = serializeQueryParameters(queryParameters);\n let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${\n path.charAt(0) === '/' ? path.substring(1) : path\n }`;\n\n if (queryParametersAsString.length) {\n url += `?${queryParametersAsString}`;\n }\n\n return url;\n}\n\nexport function serializeQueryParameters(parameters: QueryParameters): string {\n return Object.keys(parameters)\n .filter((key) => parameters[key] !== undefined)\n .sort()\n .map(\n (key) =>\n `${key}=${encodeURIComponent(\n Object.prototype.toString.call(parameters[key]) === '[object Array]'\n ? parameters[key].join(',')\n : parameters[key],\n ).replace(/\\+/g, '%20')}`,\n )\n .join('&');\n}\n\nexport function serializeData(request: Request, requestOptions: RequestOptions): string | undefined {\n if (request.method === 'GET' || (request.data === undefined && requestOptions.data === undefined)) {\n return undefined;\n }\n\n const data = Array.isArray(request.data) ? request.data : { ...request.data, ...requestOptions.data };\n\n return JSON.stringify(data);\n}\n\nexport function serializeHeaders(\n baseHeaders: Headers,\n requestHeaders: Headers,\n requestOptionsHeaders?: Headers | undefined,\n): Headers {\n const headers: Headers = {\n Accept: 'application/json',\n ...baseHeaders,\n ...requestHeaders,\n ...requestOptionsHeaders,\n };\n const serializedHeaders: Headers = {};\n\n Object.keys(headers).forEach((header) => {\n const value = headers[header];\n serializedHeaders[header.toLowerCase()] = value;\n });\n\n return serializedHeaders;\n}\n\nexport function deserializeSuccess<TObject>(response: Response): TObject {\n try {\n return JSON.parse(response.content);\n } catch (e) {\n throw new DeserializationError((e as Error).message, response);\n }\n}\n\nexport function deserializeFailure({ content, status }: Response, stackFrame: StackFrame[]): Error {\n try {\n const parsed = JSON.parse(content);\n if ('error' in parsed) {\n return new DetailedApiError(parsed.message, status, parsed.error, stackFrame);\n }\n return new ApiError(parsed.message, status, stackFrame);\n } catch {\n // ..\n }\n return new ApiError(content, status, stackFrame);\n}\n","import type { Response } from '../types';\n\nexport function isNetworkError({ isTimedOut, status }: Omit<Response, 'content'>): boolean {\n return !isTimedOut && ~~status === 0;\n}\n\nexport function isRetryable({ isTimedOut, status }: Omit<Response, 'content'>): boolean {\n return isTimedOut || isNetworkError({ isTimedOut, status }) || (~~(status / 100) !== 2 && ~~(status / 100) !== 4);\n}\n\nexport function isSuccess({ status }: Pick<Response, 'status'>): boolean {\n return ~~(status / 100) === 2;\n}\n","import type { Headers, StackFrame } from '../types';\n\nexport function stackTraceWithoutCredentials(stackTrace: StackFrame[]): StackFrame[] {\n return stackTrace.map((stackFrame) => stackFrameWithoutCredentials(stackFrame));\n}\n\nexport function stackFrameWithoutCredentials(stackFrame: StackFrame): StackFrame {\n const modifiedHeaders: Headers = stackFrame.request.headers['x-algolia-api-key']\n ? { 'x-algolia-api-key': '*****' }\n : {};\n\n return {\n ...stackFrame,\n request: {\n ...stackFrame.request,\n headers: {\n ...stackFrame.request.headers,\n ...modifiedHeaders,\n },\n },\n };\n}\n","import type {\n EndRequest,\n Host,\n QueryParameters,\n Request,\n RequestOptions,\n Response,\n StackFrame,\n Transporter,\n TransporterOptions,\n} from '../types';\nimport { createStatefulHost } from './createStatefulHost';\nimport { RetryError } from './errors';\nimport { deserializeFailure, deserializeSuccess, serializeData, serializeHeaders, serializeUrl } from './helpers';\nimport { isRetryable, isSuccess } from './responses';\nimport { stackFrameWithoutCredentials, stackTraceWithoutCredentials } from './stackTrace';\n\ntype RetryableOptions = {\n hosts: Host[];\n getTimeout: (retryCount: number, timeout: number) => number;\n};\n\nexport function createTransporter({\n hosts,\n hostsCache,\n baseHeaders,\n logger,\n baseQueryParameters,\n algoliaAgent,\n timeouts,\n requester,\n requestsCache,\n responsesCache,\n}: TransporterOptions): Transporter {\n async function createRetryableOptions(compatibleHosts: Host[]): Promise<RetryableOptions> {\n const statefulHosts = await Promise.all(\n compatibleHosts.map((compatibleHost) => {\n return hostsCache.get(compatibleHost, () => {\n return Promise.resolve(createStatefulHost(compatibleHost));\n });\n }),\n );\n const hostsUp = statefulHosts.filter((host) => host.isUp());\n const hostsTimedOut = statefulHosts.filter((host) => host.isTimedOut());\n\n // Note, we put the hosts that previously timed out on the end of the list.\n const hostsAvailable = [...hostsUp, ...hostsTimedOut];\n const compatibleHostsAvailable = hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;\n\n return {\n hosts: compatibleHostsAvailable,\n getTimeout(timeoutsCount: number, baseTimeout: number): number {\n /**\n * Imagine that you have 4 hosts, if timeouts will increase\n * on the following way: 1 (timed out) > 4 (timed out) > 5 (200).\n *\n * Note that, the very next request, we start from the previous timeout.\n *\n * 5 (timed out) > 6 (timed out) > 7 ...\n *\n * This strategy may need to be reviewed, but is the strategy on the our\n * current v3 version.\n */\n const timeoutMultiplier =\n hostsTimedOut.length === 0 && timeoutsCount === 0 ? 1 : hostsTimedOut.length + 3 + timeoutsCount;\n\n return timeoutMultiplier * baseTimeout;\n },\n };\n }\n\n async function retryableRequest<TResponse>(\n request: Request,\n requestOptions: RequestOptions,\n isRead: boolean,\n ): Promise<TResponse> {\n const stackTrace: StackFrame[] = [];\n\n /**\n * First we prepare the payload that do not depend from hosts.\n */\n const data = serializeData(request, requestOptions);\n const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);\n\n // On `GET`, the data is proxied to query parameters.\n const dataQueryParameters: QueryParameters =\n request.method === 'GET'\n ? {\n ...request.data,\n ...requestOptions.data,\n }\n : {};\n\n const queryParameters: QueryParameters = {\n ...baseQueryParameters,\n ...request.queryParameters,\n ...dataQueryParameters,\n };\n\n if (algoliaAgent.value) {\n queryParameters['x-algolia-agent'] = algoliaAgent.value;\n }\n\n if (requestOptions && requestOptions.queryParameters) {\n for (const key of Object.keys(requestOptions.queryParameters)) {\n // We want to keep `undefined` and `null` values,\n // but also avoid stringifying `object`s, as they are\n // handled in the `serializeUrl` step right after.\n if (\n !requestOptions.queryParameters[key] ||\n Object.prototype.toString.call(requestOptions.queryParameters[key]) === '[object Object]'\n ) {\n queryParameters[key] = requestOptions.queryParameters[key];\n } else {\n queryParameters[key] = requestOptions.queryParameters[key].toString();\n }\n }\n }\n\n let timeoutsCount = 0;\n\n const retry = async (\n retryableHosts: Host[],\n getTimeout: (timeoutsCount: number, timeout: number) => number,\n ): Promise<TResponse> => {\n /**\n * We iterate on each host, until there is no host left.\n */\n const host = retryableHosts.pop();\n if (host === undefined) {\n throw new RetryError(stackTraceWithoutCredentials(stackTrace));\n }\n\n const timeout = { ...timeouts, ...requestOptions.timeouts };\n\n const payload: EndRequest = {\n data,\n headers,\n method: request.method,\n url: serializeUrl(host, request.path, queryParameters),\n connectTimeout: getTimeout(timeoutsCount, timeout.connect),\n responseTimeout: getTimeout(timeoutsCount, isRead ? timeout.read : timeout.write),\n };\n\n /**\n * The stackFrame is pushed to the stackTrace so we\n * can have information about onRetry and onFailure\n * decisions.\n */\n const pushToStackTrace = (response: Response): StackFrame => {\n const stackFrame: StackFrame = {\n request: payload,\n response,\n host,\n triesLeft: retryableHosts.length,\n };\n\n stackTrace.push(stackFrame);\n\n return stackFrame;\n };\n\n const response = await requester.send(payload);\n\n if (isRetryable(response)) {\n const stackFrame = pushToStackTrace(response);\n\n // If response is a timeout, we increase the number of timeouts so we can increase the timeout later.\n if (response.isTimedOut) {\n timeoutsCount++;\n }\n /**\n * Failures are individually sent to the logger, allowing\n * the end user to debug / store stack frames even\n * when a retry error does not happen.\n */\n logger.info('Retryable failure', stackFrameWithoutCredentials(stackFrame));\n\n /**\n * We also store the state of the host in failure cases. If the host, is\n * down it will remain down for the next 2 minutes. In a timeout situation,\n * this host will be added end of the list of hosts on the next request.\n */\n await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));\n\n return retry(retryableHosts, getTimeout);\n }\n\n if (isSuccess(response)) {\n return deserializeSuccess(response);\n }\n\n pushToStackTrace(response);\n throw deserializeFailure(response, stackTrace);\n };\n\n /**\n * Finally, for each retryable host perform request until we got a non\n * retryable response. Some notes here:\n *\n * 1. The reverse here is applied so we can apply a `pop` later on => more performant.\n * 2. We also get from the retryable options a timeout multiplier that is tailored\n * for the current context.\n */\n const compatibleHosts = hosts.filter(\n (host) => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'),\n );\n const options = await createRetryableOptions(compatibleHosts);\n\n return retry([...options.hosts].reverse(), options.getTimeout);\n }\n\n function createRequest<TResponse>(request: Request, requestOptions: RequestOptions = {}): Promise<TResponse> {\n const createRetryableRequest = (): Promise<TResponse> => {\n /**\n * Then, we prepare a function factory that contains the construction of\n * the retryable request. At this point, we may *not* perform the actual\n * request. But we want to have the function factory ready.\n */\n return retryableRequest<TResponse>(request, requestOptions, isRead);\n };\n\n /**\n * A read request is either a `GET` request, or a request that we make\n * via the `read` transporter (e.g. `search`).\n */\n const isRead = request.useReadTransporter || request.method === 'GET';\n\n /**\n * Once we have the function factory ready, we need to determine of the\n * request is \"cacheable\" - should be cached. Note that, once again,\n * the user can force this option.\n */\n const cacheable = requestOptions.cacheable || request.cacheable;\n\n /**\n * If is not \"cacheable\", we immediately trigger the retryable request, no\n * need to check cache implementations.\n */\n if (cacheable !== true) {\n return createRetryableRequest();\n }\n\n /**\n * If the request is \"cacheable\", we need to first compute the key to ask\n * the cache implementations if this request is on progress or if the\n * response already exists on the cache.\n */\n const key = {\n request,\n requestOptions,\n transporter: {\n queryParameters: baseQueryParameters,\n headers: baseHeaders,\n },\n };\n\n /**\n * With the computed key, we first ask the responses cache\n * implementation if this request was been resolved before.\n */\n return responsesCache.get(\n key,\n () => {\n /**\n * If the request has never resolved before, we actually ask if there\n * is a current request with the same key on progress.\n */\n return requestsCache.get(key, () =>\n /**\n * Finally, if there is no request in progress with the same key,\n * this `createRetryableRequest()` will actually trigger the\n * retryable request.\n */\n requestsCache\n .set(key, createRetryableRequest())\n .then(\n (response) => Promise.all([requestsCache.delete(key), response]),\n (err) => Promise.all([requestsCache.delete(key), Promise.reject(err)]),\n )\n .then(([_, response]) => response),\n );\n },\n {\n /**\n * Of course, once we get this response back from the server, we\n * tell response cache to actually store the received response\n * to be used later.\n */\n miss: (response) => responsesCache.set(key, response),\n },\n );\n }\n\n return {\n hostsCache,\n requester,\n timeouts,\n logger,\n algoliaAgent,\n baseHeaders,\n baseQueryParameters,\n hosts,\n request: createRequest,\n requestsCache,\n responsesCache,\n };\n}\n","export const LogLevelEnum: Readonly<Record<string, LogLevelType>> = {\n Debug: 1,\n Info: 2,\n Error: 3,\n};\n\nexport type LogLevelType = 1 | 2 | 3;\n\nexport type Logger = {\n /**\n * Logs debug messages.\n */\n debug: (message: string, args?: any | undefined) => Promise<void>;\n\n /**\n * Logs info messages.\n */\n info: (message: string, args?: any | undefined) => Promise<void>;\n\n /**\n * Logs error messages.\n */\n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AI,CAAC,cAAc,OAAO,GAAG,GAAG,QAAQ,OAAO,GAAG,CAAC,CAAC;AAAA,YACvE,EACC,KAAK,CAAC,CAAC,GAAG,QAAQ,MAAM,QAAQ;AAAA;AAAA,QACrC;AAAA,MACF;AAAA,MACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAME,MAAM,CAAC,aAAa,eAAe,IAAI,KAAK,QAAQ;AAAA,MACtD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,IACA;AAAA,EACF;AACF;;;ACnTO,IAAM,eAAuD;AAAA,EAClE,OAAO;AAAA,EACP,MAAM;AAAA,EACN,OAAO;AACT;","names":["response"]}
|
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
type Cache = {
|
|
2
|
+
/**
|
|
3
|
+
* Gets the value of the given `key`.
|
|
4
|
+
*/
|
|
5
|
+
get: <TValue>(key: Record<string, any> | string, defaultValue: () => Promise<TValue>, events?: CacheEvents<TValue> | undefined) => Promise<TValue>;
|
|
6
|
+
/**
|
|
7
|
+
* Sets the given value with the given `key`.
|
|
8
|
+
*/
|
|
9
|
+
set: <TValue>(key: Record<string, any> | string, value: TValue) => Promise<TValue>;
|
|
10
|
+
/**
|
|
11
|
+
* Deletes the given `key`.
|
|
12
|
+
*/
|
|
13
|
+
delete: (key: Record<string, any> | string) => Promise<void>;
|
|
14
|
+
/**
|
|
15
|
+
* Clears the cache.
|
|
16
|
+
*/
|
|
17
|
+
clear: () => Promise<void>;
|
|
18
|
+
};
|
|
19
|
+
type CacheEvents<TValue> = {
|
|
20
|
+
/**
|
|
21
|
+
* The callback when the given `key` is missing from the cache.
|
|
22
|
+
*/
|
|
23
|
+
miss: (value: TValue) => Promise<any>;
|
|
24
|
+
};
|
|
25
|
+
type MemoryCacheOptions = {
|
|
26
|
+
/**
|
|
27
|
+
* If keys and values should be serialized using `JSON.stringify`.
|
|
28
|
+
*/
|
|
29
|
+
serializable?: boolean | undefined;
|
|
30
|
+
};
|
|
31
|
+
type BrowserLocalStorageOptions = {
|
|
32
|
+
/**
|
|
33
|
+
* The cache key.
|
|
34
|
+
*/
|
|
35
|
+
key: string;
|
|
36
|
+
/**
|
|
37
|
+
* The time to live for each cached item in seconds.
|
|
38
|
+
*/
|
|
39
|
+
timeToLive?: number | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* The native local storage implementation.
|
|
42
|
+
*/
|
|
43
|
+
localStorage?: Storage | undefined;
|
|
44
|
+
};
|
|
45
|
+
type BrowserLocalStorageCacheItem = {
|
|
46
|
+
/**
|
|
47
|
+
* The cache item creation timestamp.
|
|
48
|
+
*/
|
|
49
|
+
timestamp: number;
|
|
50
|
+
/**
|
|
51
|
+
* The cache item value.
|
|
52
|
+
*/
|
|
53
|
+
value: any;
|
|
54
|
+
};
|
|
55
|
+
type FallbackableCacheOptions = {
|
|
56
|
+
/**
|
|
57
|
+
* List of caches order by priority.
|
|
58
|
+
*/
|
|
59
|
+
caches: Cache[];
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
type Host = {
|
|
63
|
+
/**
|
|
64
|
+
* The host URL.
|
|
65
|
+
*/
|
|
66
|
+
url: string;
|
|
67
|
+
/**
|
|
68
|
+
* The accepted transporter.
|
|
69
|
+
*/
|
|
70
|
+
accept: 'read' | 'readWrite' | 'write';
|
|
71
|
+
/**
|
|
72
|
+
* The protocol of the host URL.
|
|
73
|
+
*/
|
|
74
|
+
protocol: 'http' | 'https';
|
|
75
|
+
/**
|
|
76
|
+
* The port of the host URL.
|
|
77
|
+
*/
|
|
78
|
+
port?: number | undefined;
|
|
79
|
+
};
|
|
80
|
+
type StatefulHost = Host & {
|
|
81
|
+
/**
|
|
82
|
+
* The status of the host.
|
|
83
|
+
*/
|
|
84
|
+
status: 'down' | 'timed out' | 'up';
|
|
85
|
+
/**
|
|
86
|
+
* The last update of the host status, used to compare with the expiration delay.
|
|
87
|
+
*/
|
|
88
|
+
lastUpdate: number;
|
|
89
|
+
/**
|
|
90
|
+
* Returns whether the host is up or not.
|
|
91
|
+
*/
|
|
92
|
+
isUp: () => boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Returns whether the host is timed out or not.
|
|
95
|
+
*/
|
|
96
|
+
isTimedOut: () => boolean;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
declare const LogLevelEnum: Readonly<Record<string, LogLevelType>>;
|
|
100
|
+
type LogLevelType = 1 | 2 | 3;
|
|
101
|
+
type Logger = {
|
|
102
|
+
/**
|
|
103
|
+
* Logs debug messages.
|
|
104
|
+
*/
|
|
105
|
+
debug: (message: string, args?: any | undefined) => Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Logs info messages.
|
|
108
|
+
*/
|
|
109
|
+
info: (message: string, args?: any | undefined) => Promise<void>;
|
|
110
|
+
/**
|
|
111
|
+
* Logs error messages.
|
|
112
|
+
*/
|
|
113
|
+
error: (message: string, args?: any | undefined) => Promise<void>;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
type Headers = Record<string, string>;
|
|
117
|
+
type QueryParameters = Record<string, any>;
|
|
118
|
+
/**
|
|
119
|
+
* The method of the request.
|
|
120
|
+
*/
|
|
121
|
+
type Method = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT';
|
|
122
|
+
type Request = {
|
|
123
|
+
method: Method;
|
|
124
|
+
/**
|
|
125
|
+
* The path of the REST API to send the request to.
|
|
126
|
+
*/
|
|
127
|
+
path: string;
|
|
128
|
+
queryParameters: QueryParameters;
|
|
129
|
+
data?: Array<Record<string, any>> | Record<string, any> | undefined;
|
|
130
|
+
headers: Headers;
|
|
131
|
+
/**
|
|
132
|
+
* If the given request should persist on the cache. Keep in mind,
|
|
133
|
+
* that some methods may have this option enabled by default.
|
|
134
|
+
*/
|
|
135
|
+
cacheable?: boolean | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* Some POST methods in the Algolia REST API uses the `read` transporter.
|
|
138
|
+
* This information is defined at the spec level.
|
|
139
|
+
*/
|
|
140
|
+
useReadTransporter?: boolean | undefined;
|
|
141
|
+
};
|
|
142
|
+
type EndRequest = Pick<Request, 'headers' | 'method'> & {
|
|
143
|
+
/**
|
|
144
|
+
* The full URL of the REST API.
|
|
145
|
+
*/
|
|
146
|
+
url: string;
|
|
147
|
+
/**
|
|
148
|
+
* The connection timeout, in milliseconds.
|
|
149
|
+
*/
|
|
150
|
+
connectTimeout: number;
|
|
151
|
+
/**
|
|
152
|
+
* The response timeout, in milliseconds.
|
|
153
|
+
*/
|
|
154
|
+
responseTimeout: number;
|
|
155
|
+
data?: string | undefined;
|
|
156
|
+
};
|
|
157
|
+
type Response = {
|
|
158
|
+
/**
|
|
159
|
+
* The body of the response.
|
|
160
|
+
*/
|
|
161
|
+
content: string;
|
|
162
|
+
/**
|
|
163
|
+
* Whether the API call is timed out or not.
|
|
164
|
+
*/
|
|
165
|
+
isTimedOut: boolean;
|
|
166
|
+
/**
|
|
167
|
+
* The HTTP status code of the response.
|
|
168
|
+
*/
|
|
169
|
+
status: number;
|
|
170
|
+
};
|
|
171
|
+
type Requester = {
|
|
172
|
+
/**
|
|
173
|
+
* Sends the given `request` to the server.
|
|
174
|
+
*/
|
|
175
|
+
send: (request: EndRequest) => Promise<Response>;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
type RequestOptions = Pick<Request, 'cacheable'> & {
|
|
179
|
+
/**
|
|
180
|
+
* Custom timeout for the request. Note that, in normal situations
|
|
181
|
+
* the given timeout will be applied. But the transporter layer may
|
|
182
|
+
* increase this timeout if there is need for it.
|
|
183
|
+
*/
|
|
184
|
+
timeouts?: Partial<Timeouts> | undefined;
|
|
185
|
+
/**
|
|
186
|
+
* Custom headers for the request. This headers are
|
|
187
|
+
* going to be merged the transporter headers.
|
|
188
|
+
*/
|
|
189
|
+
headers?: Headers | undefined;
|
|
190
|
+
/**
|
|
191
|
+
* Custom query parameters for the request. This query parameters are
|
|
192
|
+
* going to be merged the transporter query parameters.
|
|
193
|
+
*/
|
|
194
|
+
queryParameters?: QueryParameters | undefined;
|
|
195
|
+
/**
|
|
196
|
+
* Custom data for the request. This data is
|
|
197
|
+
* going to be merged the transporter data.
|
|
198
|
+
*/
|
|
199
|
+
data?: Array<Record<string, any>> | Record<string, any> | undefined;
|
|
200
|
+
};
|
|
201
|
+
type StackFrame = {
|
|
202
|
+
request: EndRequest;
|
|
203
|
+
response: Response;
|
|
204
|
+
host: Host;
|
|
205
|
+
triesLeft: number;
|
|
206
|
+
};
|
|
207
|
+
type AlgoliaAgentOptions = {
|
|
208
|
+
/**
|
|
209
|
+
* The segment. Usually the integration name.
|
|
210
|
+
*/
|
|
211
|
+
segment: string;
|
|
212
|
+
/**
|
|
213
|
+
* The version. Usually the integration version.
|
|
214
|
+
*/
|
|
215
|
+
version?: string | undefined;
|
|
216
|
+
};
|
|
217
|
+
type AlgoliaAgent = {
|
|
218
|
+
/**
|
|
219
|
+
* The raw value of the user agent.
|
|
220
|
+
*/
|
|
221
|
+
value: string;
|
|
222
|
+
/**
|
|
223
|
+
* Mutates the current user agent adding the given user agent options.
|
|
224
|
+
*/
|
|
225
|
+
add: (options: AlgoliaAgentOptions) => AlgoliaAgent;
|
|
226
|
+
};
|
|
227
|
+
type Timeouts = {
|
|
228
|
+
/**
|
|
229
|
+
* Timeout in milliseconds before the connection is established.
|
|
230
|
+
*/
|
|
231
|
+
connect: number;
|
|
232
|
+
/**
|
|
233
|
+
* Timeout in milliseconds before reading the response on a read request.
|
|
234
|
+
*/
|
|
235
|
+
read: number;
|
|
236
|
+
/**
|
|
237
|
+
* Timeout in milliseconds before reading the response on a write request.
|
|
238
|
+
*/
|
|
239
|
+
write: number;
|
|
240
|
+
};
|
|
241
|
+
type TransporterOptions = {
|
|
242
|
+
/**
|
|
243
|
+
* The cache of the hosts. Usually used to persist
|
|
244
|
+
* the state of the host when its down.
|
|
245
|
+
*/
|
|
246
|
+
hostsCache: Cache;
|
|
247
|
+
/**
|
|
248
|
+
* The logger instance to send events of the transporter.
|
|
249
|
+
*/
|
|
250
|
+
logger: Logger;
|
|
251
|
+
/**
|
|
252
|
+
* The underlying requester used. Should differ
|
|
253
|
+
* depending of the environment where the client
|
|
254
|
+
* will be used.
|
|
255
|
+
*/
|
|
256
|
+
requester: Requester;
|
|
257
|
+
/**
|
|
258
|
+
* Cache used to store in-flight requests.
|
|
259
|
+
* When a request is marked as `cacheable`, its returned Promise
|
|
260
|
+
* is stored in this cache so that identical requests can share
|
|
261
|
+
* the same Promise before it resolves.
|
|
262
|
+
*
|
|
263
|
+
* @warning
|
|
264
|
+
* The provided cache **must not** serialize stored values.
|
|
265
|
+
*
|
|
266
|
+
* Since in-flight requests are stored as Promises (which cannot be
|
|
267
|
+
* serialized to JSON), using a serializing cache will cause failures.
|
|
268
|
+
*
|
|
269
|
+
* Make sure to use a non-serializing cache implementation, such as `createMemoryCache({ serializable: false })` or to disable request caching with `createNullCache()`
|
|
270
|
+
*/
|
|
271
|
+
requestsCache: Cache;
|
|
272
|
+
/**
|
|
273
|
+
* The cache of the responses. When requests are
|
|
274
|
+
* `cacheable`, the returned responses persists
|
|
275
|
+
* in this cache to shared in similar requests.
|
|
276
|
+
*/
|
|
277
|
+
responsesCache: Cache;
|
|
278
|
+
/**
|
|
279
|
+
* The timeouts used by the requester. The transporter
|
|
280
|
+
* layer may increase this timeouts as defined on the
|
|
281
|
+
* retry strategy.
|
|
282
|
+
*/
|
|
283
|
+
timeouts: Timeouts;
|
|
284
|
+
/**
|
|
285
|
+
* The hosts used by the requester.
|
|
286
|
+
*/
|
|
287
|
+
hosts: Host[];
|
|
288
|
+
/**
|
|
289
|
+
* The headers used by the requester. The transporter
|
|
290
|
+
* layer may add some extra headers during the request
|
|
291
|
+
* for the user agent, and others.
|
|
292
|
+
*/
|
|
293
|
+
baseHeaders: Headers;
|
|
294
|
+
/**
|
|
295
|
+
* The query parameters used by the requester. The transporter
|
|
296
|
+
* layer may add some extra headers during the request
|
|
297
|
+
* for the user agent, and others.
|
|
298
|
+
*/
|
|
299
|
+
baseQueryParameters: QueryParameters;
|
|
300
|
+
/**
|
|
301
|
+
* The user agent used. Sent on query parameters.
|
|
302
|
+
*/
|
|
303
|
+
algoliaAgent: AlgoliaAgent;
|
|
304
|
+
};
|
|
305
|
+
type Transporter = TransporterOptions & {
|
|
306
|
+
/**
|
|
307
|
+
* Performs a request.
|
|
308
|
+
* The `baseRequest` and `baseRequestOptions` will be merged accordingly.
|
|
309
|
+
*/
|
|
310
|
+
request: <TResponse>(baseRequest: Request, baseRequestOptions?: RequestOptions) => Promise<TResponse>;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
type AuthMode = 'WithinHeaders' | 'WithinQueryParameters';
|
|
314
|
+
type OverriddenTransporterOptions = 'baseHeaders' | 'baseQueryParameters' | 'hosts';
|
|
315
|
+
type CreateClientOptions = Omit<TransporterOptions, OverriddenTransporterOptions | 'algoliaAgent'> & Partial<Pick<TransporterOptions, OverriddenTransporterOptions>> & {
|
|
316
|
+
appId: string;
|
|
317
|
+
apiKey: string;
|
|
318
|
+
authMode?: AuthMode | undefined;
|
|
319
|
+
algoliaAgents: AlgoliaAgentOptions[];
|
|
320
|
+
};
|
|
321
|
+
type ClientOptions = Partial<Omit<CreateClientOptions, 'apiKey' | 'appId'>>;
|
|
322
|
+
|
|
323
|
+
type IterableOptions<TResponse> = Partial<{
|
|
324
|
+
/**
|
|
325
|
+
* The function that runs right after the API call has been resolved, allows you to do anything with the response before `validate`.
|
|
326
|
+
*/
|
|
327
|
+
aggregator: (response: TResponse) => unknown | PromiseLike<unknown>;
|
|
328
|
+
/**
|
|
329
|
+
* The `validate` condition to throw an error and its message.
|
|
330
|
+
*/
|
|
331
|
+
error: {
|
|
332
|
+
/**
|
|
333
|
+
* The function to validate the error condition.
|
|
334
|
+
*/
|
|
335
|
+
validate: (response: TResponse) => boolean | PromiseLike<boolean>;
|
|
336
|
+
/**
|
|
337
|
+
* The error message to throw.
|
|
338
|
+
*/
|
|
339
|
+
message: (response: TResponse) => string | PromiseLike<string>;
|
|
340
|
+
};
|
|
341
|
+
/**
|
|
342
|
+
* The function to decide how long to wait between iterations.
|
|
343
|
+
*/
|
|
344
|
+
timeout: () => number | PromiseLike<number>;
|
|
345
|
+
}>;
|
|
346
|
+
type CreateIterablePromise<TResponse> = IterableOptions<TResponse> & {
|
|
347
|
+
/**
|
|
348
|
+
* The function to run, which returns a promise.
|
|
349
|
+
*
|
|
350
|
+
* The `previousResponse` parameter (`undefined` on the first call) allows you to build your request with incremental logic, to iterate on `page` or `cursor` for example.
|
|
351
|
+
*/
|
|
352
|
+
func: (previousResponse?: TResponse | undefined) => Promise<TResponse>;
|
|
353
|
+
/**
|
|
354
|
+
* The validator function. It receive the resolved return of the API call.
|
|
355
|
+
*/
|
|
356
|
+
validate: (response: TResponse) => boolean | PromiseLike<boolean>;
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
declare function createBrowserLocalStorageCache(options: BrowserLocalStorageOptions): Cache;
|
|
360
|
+
|
|
361
|
+
declare function createFallbackableCache(options: FallbackableCacheOptions): Cache;
|
|
362
|
+
|
|
363
|
+
declare function createMemoryCache(options?: MemoryCacheOptions): Cache;
|
|
364
|
+
|
|
365
|
+
declare function createNullCache(): Cache;
|
|
366
|
+
|
|
367
|
+
declare const DEFAULT_CONNECT_TIMEOUT_BROWSER = 1000;
|
|
368
|
+
declare const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
|
|
369
|
+
declare const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
|
|
370
|
+
declare const DEFAULT_CONNECT_TIMEOUT_NODE = 2000;
|
|
371
|
+
declare const DEFAULT_READ_TIMEOUT_NODE = 5000;
|
|
372
|
+
declare const DEFAULT_WRITE_TIMEOUT_NODE = 30000;
|
|
373
|
+
|
|
374
|
+
declare function createAlgoliaAgent(version: string): AlgoliaAgent;
|
|
375
|
+
|
|
376
|
+
declare function createAuth(appId: string, apiKey: string, authMode?: AuthMode): {
|
|
377
|
+
readonly headers: () => Headers;
|
|
378
|
+
readonly queryParameters: () => QueryParameters;
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Helper: Returns the promise of a given `func` to iterate on, based on a given `validate` condition.
|
|
383
|
+
*
|
|
384
|
+
* @param createIterator - The createIterator options.
|
|
385
|
+
* @param createIterator.func - The function to run, which returns a promise.
|
|
386
|
+
* @param createIterator.validate - The validator function. It receives the resolved return of `func`.
|
|
387
|
+
* @param createIterator.aggregator - The function that runs right after the `func` method has been executed, allows you to do anything with the response before `validate`.
|
|
388
|
+
* @param createIterator.error - The `validate` condition to throw an error, and its message.
|
|
389
|
+
* @param createIterator.timeout - The function to decide how long to wait between iterations.
|
|
390
|
+
*/
|
|
391
|
+
declare function createIterablePromise<TResponse>({ func, validate, aggregator, error, timeout, }: CreateIterablePromise<TResponse>): Promise<TResponse>;
|
|
392
|
+
|
|
393
|
+
type GetAlgoliaAgent = {
|
|
394
|
+
algoliaAgents: AlgoliaAgentOptions[];
|
|
395
|
+
client: string;
|
|
396
|
+
version: string;
|
|
397
|
+
};
|
|
398
|
+
declare function getAlgoliaAgent({ algoliaAgents, client, version }: GetAlgoliaAgent): AlgoliaAgent;
|
|
399
|
+
|
|
400
|
+
declare function createNullLogger(): Logger;
|
|
401
|
+
|
|
402
|
+
declare function createStatefulHost(host: Host, status?: StatefulHost['status']): StatefulHost;
|
|
403
|
+
|
|
404
|
+
declare function createTransporter({ hosts, hostsCache, baseHeaders, logger, baseQueryParameters, algoliaAgent, timeouts, requester, requestsCache, responsesCache, }: TransporterOptions): Transporter;
|
|
405
|
+
|
|
406
|
+
declare class AlgoliaError extends Error {
|
|
407
|
+
name: string;
|
|
408
|
+
constructor(message: string, name: string);
|
|
409
|
+
}
|
|
410
|
+
declare class IndexNotFoundError extends AlgoliaError {
|
|
411
|
+
constructor(indexName: string);
|
|
412
|
+
}
|
|
413
|
+
declare class IndicesInSameAppError extends AlgoliaError {
|
|
414
|
+
constructor();
|
|
415
|
+
}
|
|
416
|
+
declare class IndexAlreadyExistsError extends AlgoliaError {
|
|
417
|
+
constructor(indexName: string);
|
|
418
|
+
}
|
|
419
|
+
declare class ErrorWithStackTrace extends AlgoliaError {
|
|
420
|
+
stackTrace: StackFrame[];
|
|
421
|
+
constructor(message: string, stackTrace: StackFrame[], name: string);
|
|
422
|
+
}
|
|
423
|
+
declare class RetryError extends ErrorWithStackTrace {
|
|
424
|
+
constructor(stackTrace: StackFrame[]);
|
|
425
|
+
}
|
|
426
|
+
declare class ApiError extends ErrorWithStackTrace {
|
|
427
|
+
status: number;
|
|
428
|
+
constructor(message: string, status: number, stackTrace: StackFrame[], name?: string);
|
|
429
|
+
}
|
|
430
|
+
declare class DeserializationError extends AlgoliaError {
|
|
431
|
+
response: Response;
|
|
432
|
+
constructor(message: string, response: Response);
|
|
433
|
+
}
|
|
434
|
+
type DetailedErrorWithMessage = {
|
|
435
|
+
message: string;
|
|
436
|
+
label: string;
|
|
437
|
+
};
|
|
438
|
+
type DetailedErrorWithTypeID = {
|
|
439
|
+
id: string;
|
|
440
|
+
type: string;
|
|
441
|
+
name?: string | undefined;
|
|
442
|
+
};
|
|
443
|
+
type DetailedError = {
|
|
444
|
+
code: string;
|
|
445
|
+
details?: DetailedErrorWithMessage[] | DetailedErrorWithTypeID[] | undefined;
|
|
446
|
+
};
|
|
447
|
+
declare class DetailedApiError extends ApiError {
|
|
448
|
+
error: DetailedError;
|
|
449
|
+
constructor(message: string, status: number, error: DetailedError, stackTrace: StackFrame[]);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
declare function shuffle<TData>(array: TData[]): TData[];
|
|
453
|
+
declare function serializeUrl(host: Host, path: string, queryParameters: QueryParameters): string;
|
|
454
|
+
declare function serializeQueryParameters(parameters: QueryParameters): string;
|
|
455
|
+
declare function serializeData(request: Request, requestOptions: RequestOptions): string | undefined;
|
|
456
|
+
declare function serializeHeaders(baseHeaders: Headers, requestHeaders: Headers, requestOptionsHeaders?: Headers | undefined): Headers;
|
|
457
|
+
declare function deserializeSuccess<TObject>(response: Response): TObject;
|
|
458
|
+
declare function deserializeFailure({ content, status }: Response, stackFrame: StackFrame[]): Error;
|
|
459
|
+
|
|
460
|
+
declare function isNetworkError({ isTimedOut, status }: Omit<Response, 'content'>): boolean;
|
|
461
|
+
declare function isRetryable({ isTimedOut, status }: Omit<Response, 'content'>): boolean;
|
|
462
|
+
declare function isSuccess({ status }: Pick<Response, 'status'>): boolean;
|
|
463
|
+
|
|
464
|
+
declare function stackTraceWithoutCredentials(stackTrace: StackFrame[]): StackFrame[];
|
|
465
|
+
declare function stackFrameWithoutCredentials(stackFrame: StackFrame): StackFrame;
|
|
466
|
+
|
|
467
|
+
export { type AlgoliaAgent, type AlgoliaAgentOptions, AlgoliaError, ApiError, type AuthMode, type BrowserLocalStorageCacheItem, type BrowserLocalStorageOptions, type Cache, type CacheEvents, type ClientOptions, type CreateClientOptions, type CreateIterablePromise, DEFAULT_CONNECT_TIMEOUT_BROWSER, DEFAULT_CONNECT_TIMEOUT_NODE, DEFAULT_READ_TIMEOUT_BROWSER, DEFAULT_READ_TIMEOUT_NODE, DEFAULT_WRITE_TIMEOUT_BROWSER, DEFAULT_WRITE_TIMEOUT_NODE, DeserializationError, DetailedApiError, type DetailedError, type DetailedErrorWithMessage, type DetailedErrorWithTypeID, type EndRequest, ErrorWithStackTrace, type FallbackableCacheOptions, type GetAlgoliaAgent, type Headers, type Host, IndexAlreadyExistsError, IndexNotFoundError, IndicesInSameAppError, type IterableOptions, LogLevelEnum, type LogLevelType, type Logger, type MemoryCacheOptions, type Method, type QueryParameters, type Request, type RequestOptions, type Requester, type Response, RetryError, type StackFrame, type StatefulHost, type Timeouts, type Transporter, type TransporterOptions, createAlgoliaAgent, createAuth, createBrowserLocalStorageCache, createFallbackableCache, createIterablePromise, createMemoryCache, createNullCache, createNullLogger, createStatefulHost, createTransporter, deserializeFailure, deserializeSuccess, getAlgoliaAgent, isNetworkError, isRetryable, isSuccess, serializeData, serializeHeaders, serializeQueryParameters, serializeUrl, shuffle, stackFrameWithoutCredentials, stackTraceWithoutCredentials };
|