Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@algolia/client-common

Package Overview
Dependencies
Maintainers
3
Versions
237
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.5.3 to 5.6.0

src/__tests__/logger/null-logger.test.ts

71

dist/common.d.ts

@@ -99,2 +99,19 @@ type Cache = {

declare const LogLevelEnum: Readonly<Record<string, LogLevelType>>;
type LogLevelType = 1 | 2 | 3;
type Logger = {
/**
* Logs debug messages.
*/
debug: (message: string, args?: any) => Promise<void>;
/**
* Logs info messages.
*/
info: (message: string, args?: any) => Promise<void>;
/**
* Logs error messages.
*/
error: (message: string, args?: any) => Promise<void>;
};
/**

@@ -232,2 +249,6 @@ * The method of the request.

/**
* The logger instance to send events of the transporter.
*/
logger: Logger;
/**
* The underlying requester used. Should differ

@@ -332,2 +353,19 @@ * depending of the environment where the client

declare function createBrowserLocalStorageCache(options: BrowserLocalStorageOptions): Cache;
declare function createFallbackableCache(options: FallbackableCacheOptions): Cache;
declare function createMemoryCache(options?: MemoryCacheOptions): Cache;
declare function createNullCache(): Cache;
declare const DEFAULT_CONNECT_TIMEOUT_BROWSER = 1000;
declare const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
declare const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
declare const DEFAULT_CONNECT_TIMEOUT_NODE = 2000;
declare const DEFAULT_READ_TIMEOUT_NODE = 5000;
declare const DEFAULT_WRITE_TIMEOUT_NODE = 30000;
declare function createAlgoliaAgent(version: string): AlgoliaAgent;
declare function createAuth(appId: string, apiKey: string, authMode?: AuthMode): {

@@ -350,12 +388,13 @@ readonly headers: () => Headers;

declare function createBrowserLocalStorageCache(options: BrowserLocalStorageOptions): Cache;
type GetAlgoliaAgent = {
algoliaAgents: AlgoliaAgentOptions[];
client: string;
version: string;
};
declare function getAlgoliaAgent({ algoliaAgents, client, version }: GetAlgoliaAgent): AlgoliaAgent;
declare function createFallbackableCache(options: FallbackableCacheOptions): Cache;
declare function createNullLogger(): Logger;
declare function createMemoryCache(options?: MemoryCacheOptions): Cache;
declare function createTransporter({ hosts, hostsCache, baseHeaders, logger, baseQueryParameters, algoliaAgent, timeouts, requester, requestsCache, responsesCache, }: TransporterOptions): Transporter;
declare function createNullCache(): Cache;
declare function createTransporter({ hosts, hostsCache, baseHeaders, baseQueryParameters, algoliaAgent, timeouts, requester, requestsCache, responsesCache, }: TransporterOptions): Transporter;
declare function createStatefulHost(host: Host, status?: StatefulHost['status']): StatefulHost;

@@ -415,18 +454,2 @@

declare function createAlgoliaAgent(version: string): AlgoliaAgent;
type GetAlgoliaAgent = {
algoliaAgents: AlgoliaAgentOptions[];
client: string;
version: string;
};
declare function getAlgoliaAgent({ algoliaAgents, client, version }: GetAlgoliaAgent): AlgoliaAgent;
declare const DEFAULT_CONNECT_TIMEOUT_BROWSER = 1000;
declare const DEFAULT_READ_TIMEOUT_BROWSER = 2000;
declare const DEFAULT_WRITE_TIMEOUT_BROWSER = 30000;
declare const DEFAULT_CONNECT_TIMEOUT_NODE = 2000;
declare const DEFAULT_READ_TIMEOUT_NODE = 5000;
declare const DEFAULT_WRITE_TIMEOUT_NODE = 30000;
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, type IterableOptions, 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, createStatefulHost, createTransporter, deserializeFailure, deserializeSuccess, getAlgoliaAgent, isNetworkError, isRetryable, isSuccess, serializeData, serializeHeaders, serializeQueryParameters, serializeUrl, shuffle, stackFrameWithoutCredentials, stackTraceWithoutCredentials };
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, 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 };

@@ -1,48 +0,1 @@

// src/createAuth.ts
function createAuth(appId, apiKey, authMode = "WithinHeaders") {
const credentials = {
"x-algolia-api-key": apiKey,
"x-algolia-application-id": appId
};
return {
headers() {
return authMode === "WithinHeaders" ? credentials : {};
},
queryParameters() {
return authMode === "WithinQueryParameters" ? credentials : {};
}
};
}
// src/createIterablePromise.ts
function createIterablePromise({
func,
validate,
aggregator,
error,
timeout = () => 0
}) {
const retry = (previousResponse) => {
return new Promise((resolve, reject) => {
func(previousResponse).then((response) => {
if (aggregator) {
aggregator(response);
}
if (validate(response)) {
return resolve(response);
}
if (error && error.validate(response)) {
return reject(new Error(error.message(response)));
}
return setTimeout(() => {
retry(response).then(resolve).catch(reject);
}, timeout());
}).catch((err) => {
reject(err);
});
});
};
return retry();
}
// src/cache/createBrowserLocalStorageCache.ts

@@ -207,2 +160,97 @@ function createBrowserLocalStorageCache(options) {

// src/constants.ts
var DEFAULT_CONNECT_TIMEOUT_BROWSER = 1e3;
var DEFAULT_READ_TIMEOUT_BROWSER = 2e3;
var DEFAULT_WRITE_TIMEOUT_BROWSER = 3e4;
var DEFAULT_CONNECT_TIMEOUT_NODE = 2e3;
var DEFAULT_READ_TIMEOUT_NODE = 5e3;
var DEFAULT_WRITE_TIMEOUT_NODE = 3e4;
// src/createAlgoliaAgent.ts
function createAlgoliaAgent(version) {
const algoliaAgent = {
value: `Algolia for JavaScript (${version})`,
add(options) {
const addedAlgoliaAgent = `; ${options.segment}${options.version !== void 0 ? ` (${options.version})` : ""}`;
if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
}
return algoliaAgent;
}
};
return algoliaAgent;
}
// src/createAuth.ts
function createAuth(appId, apiKey, authMode = "WithinHeaders") {
const credentials = {
"x-algolia-api-key": apiKey,
"x-algolia-application-id": appId
};
return {
headers() {
return authMode === "WithinHeaders" ? credentials : {};
},
queryParameters() {
return authMode === "WithinQueryParameters" ? credentials : {};
}
};
}
// src/createIterablePromise.ts
function createIterablePromise({
func,
validate,
aggregator,
error,
timeout = () => 0
}) {
const retry = (previousResponse) => {
return new Promise((resolve, reject) => {
func(previousResponse).then((response) => {
if (aggregator) {
aggregator(response);
}
if (validate(response)) {
return resolve(response);
}
if (error && error.validate(response)) {
return reject(new Error(error.message(response)));
}
return setTimeout(() => {
retry(response).then(resolve).catch(reject);
}, timeout());
}).catch((err) => {
reject(err);
});
});
};
return retry();
}
// src/getAlgoliaAgent.ts
function getAlgoliaAgent({ algoliaAgents, client, version }) {
const defaultAlgoliaAgent = createAlgoliaAgent(version).add({
segment: client,
version
});
algoliaAgents.forEach((algoliaAgent) => defaultAlgoliaAgent.add(algoliaAgent));
return defaultAlgoliaAgent;
}
// src/logger/createNullLogger.ts
function createNullLogger() {
return {
debug(_message, _args) {
return Promise.resolve();
},
info(_message, _args) {
return Promise.resolve();
},
error(_message, _args) {
return Promise.resolve();
}
};
}
// src/transporter/createStatefulHost.ts

@@ -369,2 +417,3 @@ var EXPIRATION_DELAY = 2 * 60 * 1e3;

baseHeaders,
logger,
baseQueryParameters,

@@ -453,3 +502,3 @@ algoliaAgent,

}
console.log("Retryable failure", stackFrameWithoutCredentials(stackFrame));
logger.info("Retryable failure", stackFrameWithoutCredentials(stackFrame));
await hostsCache.set(host, createStatefulHost(host, response.isTimedOut ? "timed out" : "down"));

@@ -522,2 +571,3 @@ return retry(retryableHosts, getTimeout);

timeouts,
logger,
algoliaAgent,

@@ -533,34 +583,8 @@ baseHeaders,

// src/createAlgoliaAgent.ts
function createAlgoliaAgent(version) {
const algoliaAgent = {
value: `Algolia for JavaScript (${version})`,
add(options) {
const addedAlgoliaAgent = `; ${options.segment}${options.version !== void 0 ? ` (${options.version})` : ""}`;
if (algoliaAgent.value.indexOf(addedAlgoliaAgent) === -1) {
algoliaAgent.value = `${algoliaAgent.value}${addedAlgoliaAgent}`;
}
return algoliaAgent;
}
};
return algoliaAgent;
}
// src/getAlgoliaAgent.ts
function getAlgoliaAgent({ algoliaAgents, client, version }) {
const defaultAlgoliaAgent = createAlgoliaAgent(version).add({
segment: client,
version
});
algoliaAgents.forEach((algoliaAgent) => defaultAlgoliaAgent.add(algoliaAgent));
return defaultAlgoliaAgent;
}
// src/constants.ts
var DEFAULT_CONNECT_TIMEOUT_BROWSER = 1e3;
var DEFAULT_READ_TIMEOUT_BROWSER = 2e3;
var DEFAULT_WRITE_TIMEOUT_BROWSER = 3e4;
var DEFAULT_CONNECT_TIMEOUT_NODE = 2e3;
var DEFAULT_READ_TIMEOUT_NODE = 5e3;
var DEFAULT_WRITE_TIMEOUT_NODE = 3e4;
// src/types/logger.ts
var LogLevelEnum = {
Debug: 1,
Info: 2,
Error: 3
};
export {

@@ -578,2 +602,3 @@ AlgoliaError,

ErrorWithStackTrace,
LogLevelEnum,
RetryError,

@@ -587,2 +612,3 @@ createAlgoliaAgent,

createNullCache,
createNullLogger,
createStatefulHost,

@@ -589,0 +615,0 @@ createTransporter,

@@ -0,8 +1,9 @@

export * from './src/cache';
export * from './src/constants';
export * from './src/createAlgoliaAgent';
export * from './src/createAuth';
export * from './src/createIterablePromise';
export * from './src/cache';
export * from './src/getAlgoliaAgent';
export * from './src/logger';
export * from './src/transporter';
export * from './src/createAlgoliaAgent';
export * from './src/getAlgoliaAgent';
export * from './src/types';
export * from './src/constants';
{
"name": "@algolia/client-common",
"version": "5.5.3",
"version": "5.6.0",
"description": "Common package for the Algolia JavaScript API client.",

@@ -39,3 +39,3 @@ "repository": {

"@types/node": "22.5.5",
"jsdom": "25.0.0",
"jsdom": "25.0.1",
"publint": "0.2.11",

@@ -42,0 +42,0 @@ "ts-node": "10.9.2",

@@ -28,2 +28,3 @@ import type {

baseHeaders,
logger,
baseQueryParameters,

@@ -178,4 +179,3 @@ algoliaAgent,

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

@@ -309,2 +309,3 @@ /**

timeouts,
logger,
algoliaAgent,

@@ -311,0 +312,0 @@ baseHeaders,

@@ -5,3 +5,4 @@ export * from './cache';

export * from './host';
export * from './logger';
export * from './requester';
export * from './transporter';
import type { Cache } from './cache';
import type { Host } from './host';
import type { Logger } from './logger';
import type { Request, Requester, EndRequest, Response } from './requester';

@@ -91,2 +92,7 @@

/**
* The logger instance to send events of the transporter.
*/
logger: Logger;
/**
* The underlying requester used. Should differ

@@ -93,0 +99,0 @@ * depending of the environment where the client

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