@stackone/transport 2.10.0 → 2.12.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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as redis from "redis";
2
- import { AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
2
+ import { AxiosError, AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
3
3
  import http, { AgentOptions } from "node:http";
4
4
  import https from "node:https";
5
5
  import { Readable } from "node:stream";
@@ -150,6 +150,7 @@ interface ICacheClient<ClientType = unknown> {
150
150
  args: string[];
151
151
  }): Promise<T | null>;
152
152
  loadScript?(script: string): Promise<string | null>;
153
+ scriptExists?(shas: string[]): Promise<boolean[]>;
153
154
  increment?(key: string, cacheTTL: number): Promise<number | null>;
154
155
  decrement?(key: string, cacheTTL: number): Promise<number | null>;
155
156
  subscribe?<T extends boolean = false>(pattern: string, listener: PubSubListener<T>): Promise<boolean>;
@@ -207,6 +208,7 @@ declare class RedisClient implements ICacheClient<RedisClientType> {
207
208
  args: string[];
208
209
  }): Promise<T | null>;
209
210
  loadScript(script: string): Promise<string | null>;
211
+ scriptExists(shas: string[]): Promise<boolean[]>;
210
212
  increment(key: string, cacheTTL: number): Promise<number | null>;
211
213
  decrement(key: string, cacheTTL: number): Promise<number | null>;
212
214
  subscribe<T extends boolean>(pattern: string, listener: PubSubListener<T>): Promise<boolean>;
@@ -249,6 +251,8 @@ declare abstract class ScriptManager<T extends string, S extends ScriptManager<T
249
251
  protected logger: ILogger;
250
252
  protected additionalArgs: unknown[];
251
253
  protected isInitialConnection: boolean;
254
+ protected reloadInProgress: Promise<void> | null;
255
+ protected lastReloadTime: number;
252
256
  protected initInstance({
253
257
  redisClientConfig,
254
258
  cacheClient,
@@ -260,6 +264,7 @@ declare abstract class ScriptManager<T extends string, S extends ScriptManager<T
260
264
  protected abstract additionalInitialization(...args: unknown[]): Promise<void>;
261
265
  protected setupReconnectHandler(): void;
262
266
  protected reloadScripts(): Promise<void>;
267
+ private performReload;
263
268
  protected loadScripts(scripts: Scripts<T>, scriptMap?: Map<T, string>): Promise<void>;
264
269
  protected executeScript<U>(method: T, keys: string[], args: string[]): Promise<U | null>;
265
270
  protected isRedisReady(): boolean;
@@ -349,6 +354,27 @@ declare class RateLimitManager extends ScriptManager<RateLimitMethods, RateLimit
349
354
  }
350
355
  //#endregion
351
356
  //#region src/interceptors/types.d.ts
357
+ type AxiosErrorWithRetryCount = AxiosError & {
358
+ config: InternalAxiosRequestConfig & {
359
+ _retryCount: number;
360
+ requestId: string;
361
+ };
362
+ response: AxiosResponse & {
363
+ config: InternalAxiosRequestConfig & {
364
+ requestId: string;
365
+ };
366
+ };
367
+ };
368
+ type AxiosErrorWithRequestMetadata = AxiosErrorWithRetryCount & {
369
+ config: AxiosErrorWithRetryCount['config'] & {
370
+ requestMetadata: RequestMetadata;
371
+ };
372
+ response: AxiosResponse & {
373
+ config: AxiosErrorWithRetryCount['response']['config'] & {
374
+ requestMetadata: RequestMetadata;
375
+ };
376
+ };
377
+ };
352
378
  type RequestInterceptor = (value: InternalAxiosRequestConfig<unknown>) => InternalAxiosRequestConfig<unknown> | Promise<InternalAxiosRequestConfig<unknown>>;
353
379
  type ResponseInterceptor = (value: AxiosResponse<unknown, unknown>) => AxiosResponse<unknown, unknown> | Promise<AxiosResponse<unknown, unknown>>;
354
380
  type ErrorInterceptor = (error: unknown) => unknown;
@@ -883,6 +909,12 @@ declare class InstanceManager {
883
909
  close(): void;
884
910
  }
885
911
  //#endregion
912
+ //#region src/interceptors/retryError.interceptor.d.ts
913
+ declare const convertError: (response?: Partial<AxiosResponse>, context?: RequestContext, requestConfig?: RequestConfig, logger?: ILogger) => {
914
+ status: number | undefined;
915
+ retryAfter: number | null;
916
+ };
917
+ //#endregion
886
918
  //#region src/memoryStore/index.d.ts
887
919
  declare class MemoryStore<T> implements ICacheClient {
888
920
  private config;
@@ -992,6 +1024,13 @@ declare class SubscriptionManager {
992
1024
  close(): void;
993
1025
  }
994
1026
  //#endregion
1027
+ //#region src/utils/extractRatelimitHeaders.d.ts
1028
+ declare const superNormalizeHeaders: (headers: AxiosResponse["headers"]) => Record<string, number | null>;
1029
+ //#endregion
1030
+ //#region src/utils/retryAfter.d.ts
1031
+ type RetryAfter = string | number | null;
1032
+ declare const getRetryAfterWaitTime: (retryAfter: RetryAfter, maxWaitTime?: number, defaultWaitTime?: number) => number;
1033
+ //#endregion
995
1034
  //#region src/validators/statusCodes.d.ts
996
1035
  declare const isSuccessStatusCode: (status: number | undefined) => boolean;
997
1036
  declare const isFailedStatusCode: (status: number | undefined) => boolean;
@@ -1005,4 +1044,4 @@ type LockEntry = {
1005
1044
  unlock: Unlock;
1006
1045
  };
1007
1046
  //#endregion
1008
- export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
1047
+ export { type AxiosErrorWithRequestMetadata, type AxiosErrorWithRetryCount, CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, convertError, createAuthorizationHeaders, getRetryAfterWaitTime, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, superNormalizeHeaders, translateCustomError };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { n as __name } from "./chunk-hhuvQGXm.mjs";
2
2
  import { z } from "@stackone/utils";
3
3
  import * as redis from "redis";
4
- import { AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
4
+ import { AxiosError, AxiosInstance, AxiosInterceptorOptions, AxiosResponse, CreateAxiosDefaults, InternalAxiosRequestConfig } from "axios";
5
5
  import https from "node:https";
6
6
  import http, { AgentOptions } from "node:http";
7
7
  import { Readable } from "node:stream";
@@ -149,6 +149,7 @@ interface ICacheClient<ClientType = unknown> {
149
149
  args: string[];
150
150
  }): Promise<T | null>;
151
151
  loadScript?(script: string): Promise<string | null>;
152
+ scriptExists?(shas: string[]): Promise<boolean[]>;
152
153
  increment?(key: string, cacheTTL: number): Promise<number | null>;
153
154
  decrement?(key: string, cacheTTL: number): Promise<number | null>;
154
155
  subscribe?<T extends boolean = false>(pattern: string, listener: PubSubListener<T>): Promise<boolean>;
@@ -206,6 +207,7 @@ declare class RedisClient implements ICacheClient<RedisClientType> {
206
207
  args: string[];
207
208
  }): Promise<T | null>;
208
209
  loadScript(script: string): Promise<string | null>;
210
+ scriptExists(shas: string[]): Promise<boolean[]>;
209
211
  increment(key: string, cacheTTL: number): Promise<number | null>;
210
212
  decrement(key: string, cacheTTL: number): Promise<number | null>;
211
213
  subscribe<T extends boolean>(pattern: string, listener: PubSubListener<T>): Promise<boolean>;
@@ -248,6 +250,8 @@ declare abstract class ScriptManager<T extends string, S extends ScriptManager<T
248
250
  protected logger: ILogger;
249
251
  protected additionalArgs: unknown[];
250
252
  protected isInitialConnection: boolean;
253
+ protected reloadInProgress: Promise<void> | null;
254
+ protected lastReloadTime: number;
251
255
  protected initInstance({
252
256
  redisClientConfig,
253
257
  cacheClient,
@@ -259,6 +263,7 @@ declare abstract class ScriptManager<T extends string, S extends ScriptManager<T
259
263
  protected abstract additionalInitialization(...args: unknown[]): Promise<void>;
260
264
  protected setupReconnectHandler(): void;
261
265
  protected reloadScripts(): Promise<void>;
266
+ private performReload;
262
267
  protected loadScripts(scripts: Scripts<T>, scriptMap?: Map<T, string>): Promise<void>;
263
268
  protected executeScript<U>(method: T, keys: string[], args: string[]): Promise<U | null>;
264
269
  protected isRedisReady(): boolean;
@@ -348,6 +353,27 @@ declare class RateLimitManager extends ScriptManager<RateLimitMethods, RateLimit
348
353
  }
349
354
  //#endregion
350
355
  //#region src/interceptors/types.d.ts
356
+ type AxiosErrorWithRetryCount = AxiosError & {
357
+ config: InternalAxiosRequestConfig & {
358
+ _retryCount: number;
359
+ requestId: string;
360
+ };
361
+ response: AxiosResponse & {
362
+ config: InternalAxiosRequestConfig & {
363
+ requestId: string;
364
+ };
365
+ };
366
+ };
367
+ type AxiosErrorWithRequestMetadata = AxiosErrorWithRetryCount & {
368
+ config: AxiosErrorWithRetryCount['config'] & {
369
+ requestMetadata: RequestMetadata;
370
+ };
371
+ response: AxiosResponse & {
372
+ config: AxiosErrorWithRetryCount['response']['config'] & {
373
+ requestMetadata: RequestMetadata;
374
+ };
375
+ };
376
+ };
351
377
  type RequestInterceptor = (value: InternalAxiosRequestConfig<unknown>) => InternalAxiosRequestConfig<unknown> | Promise<InternalAxiosRequestConfig<unknown>>;
352
378
  type ResponseInterceptor = (value: AxiosResponse<unknown, unknown>) => AxiosResponse<unknown, unknown> | Promise<AxiosResponse<unknown, unknown>>;
353
379
  type ErrorInterceptor = (error: unknown) => unknown;
@@ -882,6 +908,12 @@ declare class InstanceManager {
882
908
  close(): void;
883
909
  }
884
910
  //#endregion
911
+ //#region src/interceptors/retryError.interceptor.d.ts
912
+ declare const convertError: (response?: Partial<AxiosResponse>, context?: RequestContext, requestConfig?: RequestConfig, logger?: ILogger) => {
913
+ status: number | undefined;
914
+ retryAfter: number | null;
915
+ };
916
+ //#endregion
885
917
  //#region src/memoryStore/index.d.ts
886
918
  declare class MemoryStore<T> implements ICacheClient {
887
919
  private config;
@@ -991,6 +1023,13 @@ declare class SubscriptionManager {
991
1023
  close(): void;
992
1024
  }
993
1025
  //#endregion
1026
+ //#region src/utils/extractRatelimitHeaders.d.ts
1027
+ declare const superNormalizeHeaders: (headers: AxiosResponse["headers"]) => Record<string, number | null>;
1028
+ //#endregion
1029
+ //#region src/utils/retryAfter.d.ts
1030
+ type RetryAfter = string | number | null;
1031
+ declare const getRetryAfterWaitTime: (retryAfter: RetryAfter, maxWaitTime?: number, defaultWaitTime?: number) => number;
1032
+ //#endregion
994
1033
  //#region src/validators/statusCodes.d.ts
995
1034
  declare const isSuccessStatusCode: (status: number | undefined) => boolean;
996
1035
  declare const isFailedStatusCode: (status: number | undefined) => boolean;
@@ -1004,4 +1043,4 @@ type LockEntry = {
1004
1043
  unlock: Unlock;
1005
1044
  };
1006
1045
  //#endregion
1007
- export { CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, createAuthorizationHeaders, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, translateCustomError };
1046
+ export { type AxiosErrorWithRequestMetadata, type AxiosErrorWithRetryCount, CUSTOM_ERROR_CONFIG_SCHEMA, type ConcurrencyConfig, ConcurrencyManager, type CustomErrorConfig, type ErrorMappingFn, EventClient, HttpClient, HttpClientManager, HttpErrorMessages, type HttpHeaders, type HttpMethod, HttpMethods, type HttpParameters, type HttpQueryParamValue, type HttpQueryParams, type HttpResponse, HttpResponseError, HttpTransportFactory, type ICacheClient, type IHttpClient, type IRequestClient, type InitializedTransportManagers, InstanceManager, type Lock, type LockEntry, LockManager, MemoryStore, type MemoryStoreConfig, type PruneCount, type PubSubListener, type QueryArrayFormat, QueryArrayFormats, QueueManager, type RateLimitConfig, RateLimitManager, RedisClient, type RedisClientConfig, type RedisClientType, RequestClientFactory, type RequestConfig, type RequestContext, type RequestParameter, RequestParameterLocations, ScriptManager, type StreamHttpResponse, SubscriptionManager, type TransportInitializationOptions, type Unlock, buildHttpClientInstance, convertError, createAuthorizationHeaders, getRetryAfterWaitTime, getTransportInstance, getTransportManagers, initializeTransportSystem, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, isTransportSystemReady, parseRequestParameters, serializeHttpResponseError, shutdownTransportSystem, superNormalizeHeaders, translateCustomError };