Socket
Socket
Sign inDemoInstall

@algolia/client-common

Package Overview
Dependencies
Maintainers
3
Versions
219
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/client-common - npm Package Compare versions

Comparing version 5.1.1 to 5.2.1

11

dist/client-common.esm.node.js

@@ -432,3 +432,3 @@ function createAuth(appId, apiKey, authMode = 'WithinHeaders') {

return new ApiError(parsed.message, status, stackFrame);
} catch (e) {
} catch {
// ..

@@ -561,3 +561,6 @@ }

}
let responseTimeout = isRead ? requestOptions.timeouts?.read || timeouts.read : requestOptions.timeouts?.write || timeouts.write;
const timeout = {
...timeouts,
...requestOptions.timeouts
};
const payload = {

@@ -568,4 +571,4 @@ data,

url: serializeUrl(host, request.path, queryParameters),
connectTimeout: getTimeout(timeoutsCount, requestOptions.timeouts?.connect || timeouts.connect),
responseTimeout: getTimeout(timeoutsCount, responseTimeout)
connectTimeout: getTimeout(timeoutsCount, timeout.connect),
responseTimeout: getTimeout(timeoutsCount, isRead ? timeout.read : timeout.write)
};

@@ -572,0 +575,0 @@ /**

@@ -6,3 +6,3 @@ import type { Requester } from './types';

};
export declare function createEchoRequester({ getURL, status, }: EchoRequesterParams): Requester;
export declare function createEchoRequester({ getURL, status }: EchoRequesterParams): Requester;
//# sourceMappingURL=createEchoRequester.d.ts.map

@@ -7,3 +7,3 @@ import type { AlgoliaAgentOptions, AlgoliaAgent } from './types';

};
export declare function getAlgoliaAgent({ algoliaAgents, client, version, }: GetAlgoliaAgent): AlgoliaAgent;
export declare function getAlgoliaAgent({ algoliaAgents, client, version }: GetAlgoliaAgent): AlgoliaAgent;
//# sourceMappingURL=getAlgoliaAgent.d.ts.map
import type { Response } from '../types';
export declare function isNetworkError({ isTimedOut, status, }: Omit<Response, 'content'>): boolean;
export declare function isRetryable({ isTimedOut, status, }: Omit<Response, 'content'>): boolean;
export declare function isNetworkError({ isTimedOut, status }: Omit<Response, 'content'>): boolean;
export declare function isRetryable({ isTimedOut, status }: Omit<Response, 'content'>): boolean;
export declare function isSuccess({ status }: Pick<Response, 'status'>): boolean;
//# sourceMappingURL=responses.d.ts.map
{
"name": "@algolia/client-common",
"version": "5.1.1",
"version": "5.2.1",
"description": "Common package for the Algolia JavaScript API client.",

@@ -26,9 +26,9 @@ "repository": {

"devDependencies": {
"@babel/preset-env": "7.25.3",
"@babel/preset-env": "7.25.4",
"@babel/preset-typescript": "7.24.7",
"@types/jest": "29.5.12",
"@types/node": "20.14.14",
"@types/node": "22.5.0",
"jest": "29.7.0",
"jest-environment-jsdom": "29.7.0",
"ts-jest": "29.2.4",
"ts-jest": "29.2.5",
"typescript": "5.5.4"

@@ -35,0 +35,0 @@ },

@@ -29,5 +29,3 @@ import { createBrowserLocalStorageCache } from '../../cache';

expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
{ bar: 1 }
);
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 1 });
expect(missMock.mock.calls.length).toBe(1);

@@ -37,5 +35,3 @@

expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
{ foo: 2 }
);
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ foo: 2 });
expect(missMock.mock.calls.length).toBe(1);

@@ -56,3 +52,3 @@ });

miss: () => Promise.resolve(missMock()),
})
}),
).toMatchObject({ bar: 1 });

@@ -71,5 +67,3 @@

expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
{ bar: 2 }
);
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
expect(missMock.mock.calls.length).toBe(1);

@@ -90,3 +84,3 @@ });

miss: () => Promise.resolve(missMock()),
})
}),
).toMatchObject({ bar: 2 });

@@ -110,3 +104,3 @@

miss: () => Promise.resolve(missMock()),
})
}),
).toMatchObject({ bar: 2 });

@@ -120,4 +114,3 @@

it('do throws localstorage exceptions on access', async () => {
const message =
"Failed to read the 'localStorage' property from 'Window': Access is denied for this document.";
const message = "Failed to read the 'localStorage' property from 'Window': Access is denied for this document.";
const cache = createBrowserLocalStorageCache(

@@ -135,4 +128,4 @@ new Proxy(

},
}
)
},
),
);

@@ -144,8 +137,4 @@ const key = { foo: 'bar' };

await expect(cache.delete(key)).rejects.toEqual(new DOMException(message));
await expect(cache.set(key, value)).rejects.toEqual(
new DOMException(message)
);
await expect(
cache.get(key, () => Promise.resolve(fallback))
).rejects.toEqual(new DOMException(message));
await expect(cache.set(key, value)).rejects.toEqual(new DOMException(message));
await expect(cache.get(key, () => Promise.resolve(fallback))).rejects.toEqual(new DOMException(message));
});

@@ -165,5 +154,3 @@

await expect(cache.set(key, value)).rejects.toEqual(new Error(message));
await expect(
cache.get(key, () => Promise.resolve(fallback))
).rejects.toEqual(new Error(message));
await expect(cache.get(key, () => Promise.resolve(fallback))).rejects.toEqual(new Error(message));
});

@@ -188,10 +175,6 @@

const localStorageValue = localStorage.getItem(
`algolia-client-js-${version}`
);
const localStorageValue = localStorage.getItem(`algolia-client-js-${version}`);
expect(JSON.parse(localStorageValue ? localStorageValue : '{}')).toEqual(
expectedValue
);
expect(JSON.parse(localStorageValue ? localStorageValue : '{}')).toEqual(expectedValue);
});
});

@@ -19,7 +19,5 @@ import { createMemoryCache } from '../../cache';

expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
{
bar: 1,
}
);
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({
bar: 1,
});

@@ -29,5 +27,3 @@ await cache.set({ key: 'foo' }, { foo: 2 });

expect(missMock.mock.calls.length).toBe(1);
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
{ foo: 2 }
);
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ foo: 2 });
expect(missMock.mock.calls.length).toBe(1);

@@ -59,5 +55,3 @@ });

expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
{ bar: 2 }
);
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
expect(missMock.mock.calls.length).toBe(1);

@@ -74,5 +68,3 @@ });

expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
{ bar: 2 }
);
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
expect(missMock.mock.calls.length).toBe(1);

@@ -89,7 +81,5 @@ });

expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject(
{ bar: 2 }
);
expect(await cache.get({ key: 'foo' }, defaultValue, events)).toMatchObject({ bar: 2 });
expect(missMock.mock.calls.length).toBe(1);
});
});

@@ -21,7 +21,5 @@ import { createNullCache } from '../../cache';

expect(await cache.get({ key: 'key' }, defaultValue, events)).toMatchObject(
{
bar: 12,
}
);
expect(await cache.get({ key: 'key' }, defaultValue, events)).toMatchObject({
bar: 12,
});

@@ -34,7 +32,5 @@ expect(missMock.mock.calls.length).toBe(1);

expect(await cache.get({ foo: 'foo' }, defaultValue, events)).toMatchObject(
{
bar: 12,
}
);
expect(await cache.get({ foo: 'foo' }, defaultValue, events)).toMatchObject({
bar: 12,
});

@@ -41,0 +37,0 @@ expect(missMock.mock.calls.length).toBe(1);

@@ -159,5 +159,3 @@ import { createIterablePromise } from '../createIterablePromise';

await expect(promise).rejects.toEqual(
expect.objectContaining({ message: 'nope' })
);
await expect(promise).rejects.toEqual(expect.objectContaining({ message: 'nope' }));
});

@@ -182,5 +180,3 @@

await expect(promise).rejects.toEqual(
expect.objectContaining({ message: 'nope' })
);
await expect(promise).rejects.toEqual(expect.objectContaining({ message: 'nope' }));
});

@@ -209,3 +205,3 @@

message: 'Error is thrown: 3/3',
})
}),
);

@@ -236,3 +232,3 @@ expect(calls).toBe(MAX_RETRIES);

message: 'Error is thrown: 3/3',
})
}),
);

@@ -239,0 +235,0 @@ expect(calls).toBe(MAX_RETRIES);

@@ -1,11 +0,4 @@

import type {
BrowserLocalStorageCacheItem,
BrowserLocalStorageOptions,
Cache,
CacheEvents,
} from '../types';
import type { BrowserLocalStorageCacheItem, BrowserLocalStorageOptions, Cache, CacheEvents } from '../types';
export function createBrowserLocalStorageCache(
options: BrowserLocalStorageOptions
): Cache {
export function createBrowserLocalStorageCache(options: BrowserLocalStorageOptions): Cache {
let storage: Storage;

@@ -38,3 +31,3 @@ // We've changed the namespace to avoid conflicts with v4, as this version is a huge breaking change

return cacheItem.timestamp !== undefined;
})
}),
);

@@ -49,10 +42,8 @@

const filteredNamespaceWithoutExpiredItems = Object.fromEntries(
Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(
([, cacheItem]) => {
const currentTimestamp = new Date().getTime();
const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;
Object.entries(filteredNamespaceWithoutOldFormattedCacheItems).filter(([, cacheItem]) => {
const currentTimestamp = new Date().getTime();
const isExpired = cacheItem.timestamp + timeToLive < currentTimestamp;
return !isExpired;
}
)
return !isExpired;
}),
);

@@ -69,3 +60,3 @@

miss: () => Promise.resolve(),
}
},
): Promise<TValue> {

@@ -76,11 +67,6 @@ return Promise.resolve()

return getNamespace<Promise<BrowserLocalStorageCacheItem>>()[
JSON.stringify(key)
];
return getNamespace<Promise<BrowserLocalStorageCacheItem>>()[JSON.stringify(key)];
})
.then((value) => {
return Promise.all([
value ? value.value : defaultValue(),
value !== undefined,
]);
return Promise.all([value ? value.value : defaultValue(), value !== undefined]);
})

@@ -93,6 +79,3 @@ .then(([value, exists]) => {

set<TValue>(
key: Record<string, any> | string,
value: TValue
): Promise<TValue> {
set<TValue>(key: Record<string, any> | string, value: TValue): Promise<TValue> {
return Promise.resolve().then(() => {

@@ -99,0 +82,0 @@ const namespace = getNamespace();

@@ -5,5 +5,3 @@ import type { FallbackableCacheOptions, Cache, CacheEvents } from '../types';

export function createFallbackableCache(
options: FallbackableCacheOptions
): Cache {
export function createFallbackableCache(options: FallbackableCacheOptions): Cache {
const caches = [...options.caches];

@@ -22,17 +20,10 @@ const current = caches.shift();

miss: (): Promise<void> => Promise.resolve(),
}
},
): Promise<TValue> {
return current.get(key, defaultValue, events).catch(() => {
return createFallbackableCache({ caches }).get(
key,
defaultValue,
events
);
return createFallbackableCache({ caches }).get(key, defaultValue, events);
});
},
set<TValue>(
key: Record<string, any> | string,
value: TValue
): Promise<TValue> {
set<TValue>(key: Record<string, any> | string, value: TValue): Promise<TValue> {
return current.set(key, value).catch(() => {

@@ -39,0 +30,0 @@ return createFallbackableCache({ caches }).set(key, value);

import type { Cache, CacheEvents, MemoryCacheOptions } from '../types';
export function createMemoryCache(
options: MemoryCacheOptions = { serializable: true }
): Cache {
export function createMemoryCache(options: MemoryCacheOptions = { serializable: true }): Cache {
let cache: Record<string, any> = {};

@@ -14,3 +12,3 @@

miss: (): Promise<void> => Promise.resolve(),
}
},
): Promise<TValue> {

@@ -20,7 +18,3 @@ const keyAsString = JSON.stringify(key);

if (keyAsString in cache) {
return Promise.resolve(
options.serializable
? JSON.parse(cache[keyAsString])
: cache[keyAsString]
);
return Promise.resolve(options.serializable ? JSON.parse(cache[keyAsString]) : cache[keyAsString]);
}

@@ -30,14 +24,7 @@

return promise
.then((value: TValue) => events.miss(value))
.then(() => promise);
return promise.then((value: TValue) => events.miss(value)).then(() => promise);
},
set<TValue>(
key: Record<string, any> | string,
value: TValue
): Promise<TValue> {
cache[JSON.stringify(key)] = options.serializable
? JSON.stringify(value)
: value;
set<TValue>(key: Record<string, any> | string, value: TValue): Promise<TValue> {
cache[JSON.stringify(key)] = options.serializable ? JSON.stringify(value) : value;

@@ -44,0 +31,0 @@ return Promise.resolve(value);

@@ -10,15 +10,10 @@ import type { Cache, CacheEvents } from '../types';

miss: (): Promise<void> => Promise.resolve(),
}
},
): Promise<TValue> {
const value = defaultValue();
return value
.then((result) => Promise.all([result, events.miss(result)]))
.then(([result]) => result);
return value.then((result) => Promise.all([result, events.miss(result)])).then(([result]) => result);
},
set<TValue>(
_key: Record<string, any> | string,
value: TValue
): Promise<TValue> {
set<TValue>(_key: Record<string, any> | string, value: TValue): Promise<TValue> {
return Promise.resolve(value);

@@ -25,0 +20,0 @@ },

@@ -7,5 +7,3 @@ import type { AlgoliaAgentOptions, AlgoliaAgent } from './types';

add(options: AlgoliaAgentOptions): AlgoliaAgent {
const addedAlgoliaAgent = `; ${options.segment}${
options.version !== undefined ? ` (${options.version})` : ''
}`;
const addedAlgoliaAgent = `; ${options.segment}${options.version !== undefined ? ` (${options.version})` : ''}`;

@@ -12,0 +10,0 @@ if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {

@@ -6,3 +6,3 @@ import type { AuthMode, Headers, QueryParameters } from './types';

apiKey: string,
authMode: AuthMode = 'WithinHeaders'
authMode: AuthMode = 'WithinHeaders',
): {

@@ -9,0 +9,0 @@ readonly headers: () => Headers;

@@ -42,4 +42,3 @@ import type { EchoResponse, EndRequest, Requester, Response } from './types';

algoliaAgent,
searchParams:
Object.keys(searchParams).length === 0 ? undefined : searchParams,
searchParams: Object.keys(searchParams).length === 0 ? undefined : searchParams,
path: pathname,

@@ -49,10 +48,5 @@ };

export function createEchoRequester({
getURL,
status = 200,
}: EchoRequesterParams): Requester {
export function createEchoRequester({ getURL, status = 200 }: EchoRequesterParams): Requester {
function send(request: EndRequest): Promise<Response> {
const { host, searchParams, algoliaAgent, path } = getUrlParams(
getURL(request.url)
);
const { host, searchParams, algoliaAgent, path } = getUrlParams(getURL(request.url));

@@ -59,0 +53,0 @@ const content: EchoResponse = {

@@ -10,7 +10,3 @@ import { createAlgoliaAgent } from './createAlgoliaAgent';

export function getAlgoliaAgent({
algoliaAgents,
client,
version,
}: GetAlgoliaAgent): AlgoliaAgent {
export function getAlgoliaAgent({ algoliaAgents, client, version }: GetAlgoliaAgent): AlgoliaAgent {
const defaultAlgoliaAgent = createAlgoliaAgent(version).add({

@@ -21,7 +17,5 @@ segment: client,

algoliaAgents.forEach((algoliaAgent) =>
defaultAlgoliaAgent.add(algoliaAgent)
);
algoliaAgents.forEach((algoliaAgent) => defaultAlgoliaAgent.add(algoliaAgent));
return defaultAlgoliaAgent;
}

@@ -7,6 +7,3 @@ import type { Host, StatefulHost } from '../types';

export function createStatefulHost(
host: Host,
status: StatefulHost['status'] = 'up'
): StatefulHost {
export function createStatefulHost(host: Host, status: StatefulHost['status'] = 'up'): StatefulHost {
const lastUpdate = Date.now();

@@ -19,5 +16,3 @@

function isTimedOut(): boolean {
return (
status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY
);
return status === 'timed out' && Date.now() - lastUpdate <= EXPIRATION_DELAY;
}

@@ -24,0 +19,0 @@

@@ -15,14 +15,5 @@ import type {

import { RetryError } from './errors';
import {
deserializeFailure,
deserializeSuccess,
serializeData,
serializeHeaders,
serializeUrl,
} from './helpers';
import { deserializeFailure, deserializeSuccess, serializeData, serializeHeaders, serializeUrl } from './helpers';
import { isRetryable, isSuccess } from './responses';
import {
stackTraceWithoutCredentials,
stackFrameWithoutCredentials,
} from './stackTrace';
import { stackTraceWithoutCredentials, stackFrameWithoutCredentials } from './stackTrace';

@@ -45,5 +36,3 @@ type RetryableOptions = {

}: TransporterOptions): Transporter {
async function createRetryableOptions(
compatibleHosts: Host[]
): Promise<RetryableOptions> {
async function createRetryableOptions(compatibleHosts: Host[]): Promise<RetryableOptions> {
const statefulHosts = await Promise.all(

@@ -54,3 +43,3 @@ compatibleHosts.map((compatibleHost) => {

});
})
}),
);

@@ -62,4 +51,3 @@ const hostsUp = statefulHosts.filter((host) => host.isUp());

const hostsAvailable = [...hostsUp, ...hostsTimedOut];
const compatibleHostsAvailable =
hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;
const compatibleHostsAvailable = hostsAvailable.length > 0 ? hostsAvailable : compatibleHosts;

@@ -81,5 +69,3 @@ return {

const timeoutMultiplier =
hostsTimedOut.length === 0 && timeoutsCount === 0
? 1
: hostsTimedOut.length + 3 + timeoutsCount;
hostsTimedOut.length === 0 && timeoutsCount === 0 ? 1 : hostsTimedOut.length + 3 + timeoutsCount;

@@ -94,3 +80,3 @@ return timeoutMultiplier * baseTimeout;

requestOptions: RequestOptions,
isRead = true
isRead = true,
): Promise<TResponse> {

@@ -103,7 +89,3 @@ const stackTrace: StackFrame[] = [];

const data = serializeData(request, requestOptions);
const headers = serializeHeaders(
baseHeaders,
request.headers,
requestOptions.headers
);
const headers = serializeHeaders(baseHeaders, request.headers, requestOptions.headers);

@@ -136,5 +118,3 @@ // On `GET`, the data is proxied to query parameters.

!requestOptions.queryParameters[key] ||
Object.prototype.toString.call(
requestOptions.queryParameters[key]
) === '[object Object]'
Object.prototype.toString.call(requestOptions.queryParameters[key]) === '[object Object]'
) {

@@ -152,3 +132,3 @@ queryParameters[key] = requestOptions.queryParameters[key];

retryableHosts: Host[],
getTimeout: (timeoutsCount: number, timeout: number) => number
getTimeout: (timeoutsCount: number, timeout: number) => number,
): Promise<TResponse> => {

@@ -163,3 +143,3 @@ /**

let responseTimeout = isRead ? requestOptions.timeouts?.read || timeouts.read : requestOptions.timeouts?.write || timeouts.write;
const timeout = { ...timeouts, ...requestOptions.timeouts };

@@ -171,4 +151,4 @@ const payload: EndRequest = {

url: serializeUrl(host, request.path, queryParameters),
connectTimeout: getTimeout(timeoutsCount, requestOptions.timeouts?.connect || timeouts.connect),
responseTimeout: getTimeout(timeoutsCount, responseTimeout),
connectTimeout: getTimeout(timeoutsCount, timeout.connect),
responseTimeout: getTimeout(timeoutsCount, isRead ? timeout.read : timeout.write),
};

@@ -209,6 +189,3 @@

// eslint-disable-next-line no-console -- this will be fixed by exposing a `logger` to the transporter
console.log(
'Retryable failure',
stackFrameWithoutCredentials(stackFrame)
);
console.log('Retryable failure', stackFrameWithoutCredentials(stackFrame));

@@ -220,6 +197,3 @@ /**

*/
await hostsCache.set(
host,
createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down')
);
await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? 'timed out' : 'down'));

@@ -246,5 +220,3 @@ return retry(retryableHosts, getTimeout);

const compatibleHosts = hosts.filter(
(host) =>
host.accept === 'readWrite' ||
(isRead ? host.accept === 'read' : host.accept === 'write')
(host) => host.accept === 'readWrite' || (isRead ? host.accept === 'read' : host.accept === 'write'),
);

@@ -256,6 +228,3 @@ const options = await createRetryableOptions(compatibleHosts);

function createRequest<TResponse>(
request: Request,
requestOptions: RequestOptions = {}
): Promise<TResponse> {
function createRequest<TResponse>(request: Request, requestOptions: RequestOptions = {}): Promise<TResponse> {
/**

@@ -333,6 +302,5 @@ * A read request is either a `GET` request, or a request that we make

(response) => Promise.all([requestsCache.delete(key), response]),
(err) =>
Promise.all([requestsCache.delete(key), Promise.reject(err)])
(err) => Promise.all([requestsCache.delete(key), Promise.reject(err)]),
)
.then(([_, response]) => response)
.then(([_, response]) => response),
);

@@ -347,3 +315,3 @@ },

miss: (response) => responsesCache.set(key, response),
}
},
);

@@ -350,0 +318,0 @@ }

@@ -30,3 +30,3 @@ import type { Response, StackFrame } from '../types';

stackTrace,
'RetryError'
'RetryError',
);

@@ -39,8 +39,3 @@ }

constructor(
message: string,
status: number,
stackTrace: StackFrame[],
name = 'ApiError'
) {
constructor(message: string, status: number, stackTrace: StackFrame[], name = 'ApiError') {
super(message, stackTrace, name);

@@ -80,8 +75,3 @@ this.status = status;

constructor(
message: string,
status: number,
error: DetailedError,
stackTrace: StackFrame[]
) {
constructor(message: string, status: number, error: DetailedError, stackTrace: StackFrame[]) {
super(message, status, stackTrace, 'DetailedApiError');

@@ -88,0 +78,0 @@ this.error = error;

@@ -1,10 +0,2 @@

import type {
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
Response,
StackFrame,
} from '../types';
import type { Headers, Host, QueryParameters, Request, RequestOptions, Response, StackFrame } from '../types';

@@ -27,7 +19,3 @@ import { ApiError, DeserializationError, DetailedApiError } from './errors';

export function serializeUrl(
host: Host,
path: string,
queryParameters: QueryParameters
): string {
export function serializeUrl(host: Host, path: string, queryParameters: QueryParameters): string {
const queryParametersAsString = serializeQueryParameters(queryParameters);

@@ -54,4 +42,4 @@ let url = `${host.protocol}://${host.url}${host.port ? `:${host.port}` : ''}/${

? parameters[key].join(',')
: parameters[key]
).replaceAll('+', '%20')}`
: parameters[key],
).replaceAll('+', '%20')}`,
)

@@ -61,16 +49,8 @@ .join('&');

export function serializeData(
request: Request,
requestOptions: RequestOptions
): string | undefined {
if (
request.method === 'GET' ||
(request.data === undefined && requestOptions.data === undefined)
) {
export function serializeData(request: Request, requestOptions: RequestOptions): string | undefined {
if (request.method === 'GET' || (request.data === undefined && requestOptions.data === undefined)) {
return undefined;
}
const data = Array.isArray(request.data)
? request.data
: { ...request.data, ...requestOptions.data };
const data = Array.isArray(request.data) ? request.data : { ...request.data, ...requestOptions.data };

@@ -83,3 +63,3 @@ return JSON.stringify(data);

requestHeaders: Headers,
requestOptionsHeaders?: Headers
requestOptionsHeaders?: Headers,
): Headers {

@@ -110,18 +90,10 @@ const headers: Headers = {

export function deserializeFailure(
{ content, status }: Response,
stackFrame: StackFrame[]
): Error {
export function deserializeFailure({ content, status }: Response, stackFrame: StackFrame[]): Error {
try {
const parsed = JSON.parse(content);
if ('error' in parsed) {
return new DetailedApiError(
parsed.message,
status,
parsed.error,
stackFrame
);
return new DetailedApiError(parsed.message, status, parsed.error, stackFrame);
}
return new ApiError(parsed.message, status, stackFrame);
} catch (e) {
} catch {
// ..

@@ -128,0 +100,0 @@ }

import type { Response } from '../types';
export function isNetworkError({
isTimedOut,
status,
}: Omit<Response, 'content'>): boolean {
export function isNetworkError({ isTimedOut, status }: Omit<Response, 'content'>): boolean {
return !isTimedOut && ~~status === 0;
}
export function isRetryable({
isTimedOut,
status,
}: Omit<Response, 'content'>): boolean {
return (
isTimedOut ||
isNetworkError({ isTimedOut, status }) ||
(~~(status / 100) !== 2 && ~~(status / 100) !== 4)
);
export function isRetryable({ isTimedOut, status }: Omit<Response, 'content'>): boolean {
return isTimedOut || isNetworkError({ isTimedOut, status }) || (~~(status / 100) !== 2 && ~~(status / 100) !== 4);
}

@@ -20,0 +10,0 @@

import type { Headers, StackFrame } from '../types';
export function stackTraceWithoutCredentials(
stackTrace: StackFrame[]
): StackFrame[] {
return stackTrace.map((stackFrame) =>
stackFrameWithoutCredentials(stackFrame)
);
export function stackTraceWithoutCredentials(stackTrace: StackFrame[]): StackFrame[] {
return stackTrace.map((stackFrame) => stackFrameWithoutCredentials(stackFrame));
}
export function stackFrameWithoutCredentials(
stackFrame: StackFrame
): StackFrame {
const modifiedHeaders: Headers = stackFrame.request.headers[
'x-algolia-api-key'
]
export function stackFrameWithoutCredentials(stackFrame: StackFrame): StackFrame {
const modifiedHeaders: Headers = stackFrame.request.headers['x-algolia-api-key']
? { 'x-algolia-api-key': '*****' }

@@ -18,0 +10,0 @@ : {};

@@ -8,3 +8,3 @@ export type Cache = {

defaultValue: () => Promise<TValue>,
events?: CacheEvents<TValue>
events?: CacheEvents<TValue>,
) => Promise<TValue>;

@@ -15,6 +15,3 @@

*/
set: <TValue>(
key: Record<string, any> | string,
value: TValue
) => Promise<TValue>;
set: <TValue>(key: Record<string, any> | string, value: TValue) => Promise<TValue>;

@@ -21,0 +18,0 @@ /**

@@ -5,11 +5,5 @@ import type { AlgoliaAgentOptions, TransporterOptions } from './transporter';

type OverriddenTransporterOptions =
| 'baseHeaders'
| 'baseQueryParameters'
| 'hosts';
type OverriddenTransporterOptions = 'baseHeaders' | 'baseQueryParameters' | 'hosts';
export type CreateClientOptions = Omit<
TransporterOptions,
OverriddenTransporterOptions | 'algoliaAgent'
> &
export type CreateClientOptions = Omit<TransporterOptions, OverriddenTransporterOptions | 'algoliaAgent'> &
Partial<Pick<TransporterOptions, OverriddenTransporterOptions>> & {

@@ -22,4 +16,2 @@ appId: string;

export type ClientOptions = Partial<
Omit<CreateClientOptions, 'apiKey' | 'appId'>
>;
export type ClientOptions = Partial<Omit<CreateClientOptions, 'apiKey' | 'appId'>>;

@@ -149,6 +149,3 @@ import type { Cache } from './cache';

*/
request: <TResponse>(
baseRequest: Request,
baseRequestOptions?: RequestOptions
) => Promise<TResponse>;
request: <TResponse>(baseRequest: Request, baseRequestOptions?: RequestOptions) => Promise<TResponse>;
};

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc