@stackone/transport 1.7.0 → 1.8.1

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.
Files changed (34) hide show
  1. package/dist/index.d.mts +399 -0
  2. package/dist/index.d.ts +399 -0
  3. package/dist/index.js +793 -1
  4. package/dist/index.mjs +755 -0
  5. package/package.json +23 -6
  6. package/dist/index.es.mjs +0 -1
  7. package/dist/types/authorization/authorizationHeaders.d.ts +0 -4
  8. package/dist/types/authorization/types.d.ts +0 -12
  9. package/dist/types/cacheClient/types.d.ts +0 -31
  10. package/dist/types/customErrors/index.d.ts +0 -3
  11. package/dist/types/customErrors/schemas.d.ts +0 -17
  12. package/dist/types/customErrors/types.d.ts +0 -4
  13. package/dist/types/errors/httpResponseError.d.ts +0 -6
  14. package/dist/types/httpClient/httpClient.d.ts +0 -37
  15. package/dist/types/httpClient/httpClientManager.d.ts +0 -10
  16. package/dist/types/httpClient/types.d.ts +0 -57
  17. package/dist/types/index.d.ts +0 -17
  18. package/dist/types/instanceManager/constants.d.ts +0 -1
  19. package/dist/types/instanceManager/index.d.ts +0 -15
  20. package/dist/types/lockManager/index.d.ts +0 -9
  21. package/dist/types/lockManager/types.d.ts +0 -6
  22. package/dist/types/memoryStore/constants.d.ts +0 -12
  23. package/dist/types/memoryStore/index.d.ts +0 -42
  24. package/dist/types/memoryStore/types.d.ts +0 -19
  25. package/dist/types/parsers/requestParameters.d.ts +0 -3
  26. package/dist/types/parsers/types.d.ts +0 -7
  27. package/dist/types/redisClient/index.d.ts +0 -69
  28. package/dist/types/redisClient/types.d.ts +0 -31
  29. package/dist/types/requestClient/requestClientFactory.d.ts +0 -4
  30. package/dist/types/requestClient/restClient.d.ts +0 -13
  31. package/dist/types/requestClient/types.d.ts +0 -14
  32. package/dist/types/scriptManager/index.d.ts +0 -21
  33. package/dist/types/scriptManager/types.d.ts +0 -8
  34. package/dist/types/validators/statusCodes.d.ts +0 -3
@@ -0,0 +1,399 @@
1
+ import { z } from "zod";
2
+ import { AxiosInstance } from "axios";
3
+ import https from "https";
4
+ import { ILogger } from "@stackone/logger";
5
+
6
+ //#region src/authorization/types.d.ts
7
+ type BasicAuthorizationParams = {
8
+ type: 'basic';
9
+ username?: string;
10
+ password?: string;
11
+ encoding?: string;
12
+ };
13
+ type BearerAuthorizationParams = {
14
+ type: 'bearer';
15
+ token: string;
16
+ includeBearer?: boolean;
17
+ };
18
+ //#endregion
19
+ //#region src/authorization/authorizationHeaders.d.ts
20
+ declare const createAuthorizationHeaders: (authenticationParams: BasicAuthorizationParams | BearerAuthorizationParams) => {
21
+ authorization: string;
22
+ };
23
+ //#endregion
24
+ //#region src/customErrors/schemas.d.ts
25
+ declare const CUSTOM_ERROR_CONFIG_SCHEMA: z.ZodObject<{
26
+ receivedStatus: z.ZodNumber;
27
+ targetStatus: z.ZodNumber;
28
+ message: z.ZodOptional<z.ZodString>;
29
+ condition: z.ZodOptional<z.ZodString>;
30
+ }, "strip", z.ZodTypeAny, {
31
+ receivedStatus: number;
32
+ targetStatus: number;
33
+ message?: string | undefined;
34
+ condition?: string | undefined;
35
+ }, {
36
+ receivedStatus: number;
37
+ targetStatus: number;
38
+ message?: string | undefined;
39
+ condition?: string | undefined;
40
+ }>;
41
+ //#endregion
42
+ //#region src/customErrors/types.d.ts
43
+ type CustomErrorConfig = z.infer<typeof CUSTOM_ERROR_CONFIG_SCHEMA>;
44
+ declare const HttpErrorMessages: Record<number, string>;
45
+ //#endregion
46
+ //#region src/httpClient/types.d.ts
47
+ type HttpHeaders = {
48
+ [key: string]: string;
49
+ };
50
+ type HttpQueryParams = {
51
+ [key: string]: string;
52
+ };
53
+ declare const HttpMethods: readonly ["get", "post", "put", "delete", "patch"];
54
+ type HttpMethod = (typeof HttpMethods)[number];
55
+ type HttpResponse<T = any> = {
56
+ data: T;
57
+ status: number;
58
+ headers: HttpHeaders;
59
+ requestUrl: string;
60
+ responseType?: string;
61
+ responseTime?: Date;
62
+ message?: string;
63
+ };
64
+ type HttpParameters = {
65
+ query: HttpQueryParams;
66
+ body: Record<string, unknown>;
67
+ headers: HttpHeaders;
68
+ };
69
+ interface IHttpClient {
70
+ request<P, T>({
71
+ headers,
72
+ url,
73
+ method,
74
+ queryParams,
75
+ maxRedirects,
76
+ responseType,
77
+ cacheTTL,
78
+ context,
79
+ payload,
80
+ httpsAgent
81
+ }: {
82
+ headers?: HttpHeaders;
83
+ url: string;
84
+ method?: HttpMethod;
85
+ queryParams?: HttpQueryParams;
86
+ maxRedirects?: number;
87
+ responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text';
88
+ cacheTTL?: number;
89
+ context?: unknown;
90
+ payload?: P;
91
+ httpsAgent?: https.Agent;
92
+ }): Promise<HttpResponse<T>>;
93
+ get<T>({
94
+ headers,
95
+ url,
96
+ queryParams,
97
+ maxRedirects,
98
+ cacheTTL,
99
+ context
100
+ }: {
101
+ headers?: HttpHeaders;
102
+ url: string;
103
+ queryParams?: HttpQueryParams;
104
+ maxRedirects?: number;
105
+ cacheTTL?: number;
106
+ context?: unknown;
107
+ }): Promise<HttpResponse<T>>;
108
+ post<P, T>({
109
+ headers,
110
+ url,
111
+ maxRedirects,
112
+ cacheTTL,
113
+ context,
114
+ payload
115
+ }: {
116
+ headers?: HttpHeaders;
117
+ url: string;
118
+ maxRedirects?: number;
119
+ cacheTTL?: number;
120
+ context?: unknown;
121
+ payload?: P;
122
+ }): Promise<HttpResponse<T>>;
123
+ }
124
+ //#endregion
125
+ //#region src/errors/httpResponseError.d.ts
126
+ declare class HttpResponseError extends Error {
127
+ readonly response: HttpResponse;
128
+ constructor(response: HttpResponse, message?: string);
129
+ toString(): string;
130
+ }
131
+ //#endregion
132
+ //#region src/httpClient/httpClient.d.ts
133
+ declare class HttpClient implements IHttpClient {
134
+ #private;
135
+ constructor({
136
+ transportInstance
137
+ }?: {
138
+ transportInstance?: AxiosInstance;
139
+ });
140
+ request<P, T>({
141
+ headers,
142
+ url,
143
+ method,
144
+ queryParams,
145
+ maxRedirects,
146
+ responseType,
147
+ cacheTTL,
148
+ context,
149
+ payload,
150
+ httpsAgent
151
+ }: {
152
+ headers?: HttpHeaders;
153
+ url: string;
154
+ method?: HttpMethod;
155
+ queryParams?: HttpQueryParams;
156
+ maxRedirects?: number;
157
+ responseType?: 'arraybuffer' | 'blob' | 'document' | 'json' | 'text';
158
+ cacheTTL?: number;
159
+ context?: unknown;
160
+ payload?: P;
161
+ httpsAgent?: https.Agent;
162
+ }): Promise<HttpResponse<T>>;
163
+ get<T>({
164
+ headers,
165
+ url,
166
+ queryParams,
167
+ maxRedirects,
168
+ cacheTTL,
169
+ context
170
+ }: {
171
+ headers?: HttpHeaders;
172
+ url: string;
173
+ queryParams?: HttpQueryParams;
174
+ maxRedirects?: number;
175
+ cacheTTL?: number;
176
+ context?: unknown;
177
+ }): Promise<HttpResponse<T>>;
178
+ post<P, T>({
179
+ headers,
180
+ url,
181
+ maxRedirects,
182
+ cacheTTL,
183
+ context,
184
+ payload
185
+ }: {
186
+ headers?: HttpHeaders;
187
+ url: string;
188
+ maxRedirects?: number;
189
+ cacheTTL?: number;
190
+ context?: unknown;
191
+ payload?: P;
192
+ }): Promise<HttpResponse<T>>;
193
+ }
194
+ //#endregion
195
+ //#region src/httpClient/httpClientManager.d.ts
196
+ declare const buildHttpClientInstance: () => IHttpClient;
197
+ declare class HttpClientManager {
198
+ private static httpClientInstance;
199
+ static getInstance({
200
+ getHttpClient
201
+ }?: {
202
+ getHttpClient?: typeof buildHttpClientInstance;
203
+ }): Promise<IHttpClient>;
204
+ static resetInstance(): void;
205
+ }
206
+ //#endregion
207
+ //#region src/instanceManager/index.d.ts
208
+ declare class InstanceManager {
209
+ private static instance;
210
+ private static logger;
211
+ private dataStore;
212
+ private constructor();
213
+ static getInstance(logger?: ILogger): InstanceManager;
214
+ private initialize;
215
+ get<T>(key: string): Promise<T | null>;
216
+ set<T>(key: string, value: T, cacheTTL?: number): Promise<boolean>;
217
+ private ensureReady;
218
+ isReady(): boolean;
219
+ close(): void;
220
+ }
221
+ //#endregion
222
+ //#region src/lockManager/index.d.ts
223
+ declare class LockManager {
224
+ private locks;
225
+ constructor();
226
+ withLock<T>(key: string, operation: () => Promise<T>): Promise<T>;
227
+ lock(key: string): Promise<void>;
228
+ unlock(key: string): void;
229
+ queueLength(key: string): number | undefined;
230
+ close(): void;
231
+ }
232
+ //#endregion
233
+ //#region src/cacheClient/types.d.ts
234
+ interface ICacheClient<ClientType = unknown> {
235
+ getData<T>(key: string): Promise<T | null>;
236
+ listData<T>({
237
+ partialKey,
238
+ limit,
239
+ cursor
240
+ }: {
241
+ partialKey: string;
242
+ limit?: number;
243
+ cursor?: string;
244
+ }): Promise<{
245
+ items: T[] | null;
246
+ cursor?: string;
247
+ }>;
248
+ setData<T>({
249
+ key,
250
+ value,
251
+ cacheTTL,
252
+ groupKey
253
+ }: {
254
+ key: string;
255
+ value: T;
256
+ cacheTTL: number;
257
+ groupKey?: string;
258
+ }): Promise<boolean>;
259
+ executeScript?<T>({
260
+ sha1,
261
+ keys,
262
+ args
263
+ }: {
264
+ sha1: string;
265
+ keys: string[];
266
+ args: string[];
267
+ }): Promise<T | null>;
268
+ loadScript?(script: string): Promise<string | null>;
269
+ increment?(key: string, cacheTTL: number): Promise<number | null>;
270
+ decrement?(key: string, cacheTTL: number): Promise<number | null>;
271
+ subscribe?<T extends boolean = false>(pattern: string, listener: PubSubListener<T>): Promise<boolean>;
272
+ unsubscribe?(pattern: string): Promise<boolean>;
273
+ publish?(channel: string, message: string): Promise<number | null>;
274
+ getClient?(): ClientType | null;
275
+ deleteData?(key: string): Promise<boolean>;
276
+ }
277
+ type PubSubListener<ReturnsBuffer extends boolean = false> = <T extends (ReturnsBuffer extends true ? Buffer : string)>(message: T, channel: T) => unknown;
278
+ //#endregion
279
+ //#region src/memoryStore/types.d.ts
280
+ interface MemoryStoreConfig<T> {
281
+ instantiator?: string;
282
+ logger?: ILogger;
283
+ dataStore?: Map<string, T>;
284
+ lockManager?: LockManager;
285
+ expiryMap?: Map<string, number>;
286
+ evictionFrequency?: number;
287
+ staleDataThreshold?: number;
288
+ truncateThreshold?: number;
289
+ truncationPercentage?: number;
290
+ typeGuard?: (data: unknown) => data is T;
291
+ dispose?: (key: string, value: T) => Promise<void> | void;
292
+ }
293
+ type PruneCount = {
294
+ dataStoreSize: number;
295
+ prunedDataStoreSize: number;
296
+ };
297
+ //#endregion
298
+ //#region src/memoryStore/index.d.ts
299
+ declare class MemoryStore<T> implements ICacheClient {
300
+ private config;
301
+ private instantiator;
302
+ private dataStore;
303
+ private lockManager;
304
+ private expiryMap;
305
+ private evictionFrequency;
306
+ private staleDataThreshold;
307
+ private truncateThreshold;
308
+ private truncationPercentage;
309
+ private logger?;
310
+ private typeGuard?;
311
+ private dispose?;
312
+ private evictionInterval?;
313
+ private lastAccessedAt;
314
+ constructor(config?: MemoryStoreConfig<T>);
315
+ private initialize;
316
+ getData<U = T>(key: string): Promise<U | null>;
317
+ setData<U = T>({
318
+ key,
319
+ value,
320
+ cacheTTL
321
+ }: {
322
+ key: string;
323
+ value: U;
324
+ cacheTTL?: number;
325
+ }): Promise<boolean>;
326
+ private typeGuardBypass;
327
+ delete(key: string): Promise<boolean>;
328
+ pruneExpiredKeys(): Promise<PruneCount | undefined>;
329
+ private startEvictionTask;
330
+ private stopEvictionTask;
331
+ private updateLastAccessedAt;
332
+ isReady(): boolean;
333
+ close(): void;
334
+ listData<T>({
335
+ partialKey,
336
+ cursor,
337
+ limit
338
+ }: {
339
+ partialKey: string;
340
+ cursor?: string;
341
+ limit: number;
342
+ }): Promise<{
343
+ items: T[] | null;
344
+ cursor?: string;
345
+ }>;
346
+ }
347
+ //#endregion
348
+ //#region src/parsers/types.d.ts
349
+ declare const RequestParameterLocations: readonly ["query", "body", "headers"];
350
+ type RequestParameterLocation = (typeof RequestParameterLocations)[number];
351
+ type RequestParameter = {
352
+ name: string;
353
+ in: RequestParameterLocation;
354
+ value?: unknown;
355
+ };
356
+ //#endregion
357
+ //#region src/parsers/requestParameters.d.ts
358
+ declare const parseRequestParameters: (parameters: RequestParameter[]) => HttpParameters;
359
+ //#endregion
360
+ //#region src/requestClient/types.d.ts
361
+ interface IRequestClient {
362
+ performRequest: ({
363
+ httpClient,
364
+ url,
365
+ method,
366
+ headers,
367
+ body,
368
+ customErrorConfigs
369
+ }: {
370
+ httpClient: IHttpClient;
371
+ url: string;
372
+ method: HttpMethod;
373
+ headers: HttpHeaders;
374
+ queryParams?: HttpQueryParams;
375
+ body: unknown;
376
+ customErrorConfigs?: CustomErrorConfig[];
377
+ }) => Promise<HttpResponse>;
378
+ }
379
+ type RequestClientType = 'rest' | 'soap';
380
+ //#endregion
381
+ //#region src/requestClient/requestClientFactory.d.ts
382
+ declare class RequestClientFactory {
383
+ static build(type?: RequestClientType): IRequestClient;
384
+ }
385
+ //#endregion
386
+ //#region src/validators/statusCodes.d.ts
387
+ declare const isSuccessStatusCode: (status: number | undefined) => boolean;
388
+ declare const isFailedStatusCode: (status: number | undefined) => boolean;
389
+ declare const isInfoStatusCode: (status: number | undefined) => boolean;
390
+ //#endregion
391
+ //#region src/lockManager/types.d.ts
392
+ type Lock = Promise<void>;
393
+ type Unlock = () => void;
394
+ type LockEntry = {
395
+ lock: Lock;
396
+ unlock: Unlock;
397
+ };
398
+ //#endregion
399
+ export { CUSTOM_ERROR_CONFIG_SCHEMA, CustomErrorConfig, HttpClient, HttpClientManager, HttpErrorMessages, HttpHeaders, HttpMethod, HttpMethods, HttpParameters, HttpQueryParams, HttpResponse, HttpResponseError, ICacheClient, IHttpClient, InstanceManager, Lock, LockEntry, LockManager, MemoryStore, MemoryStoreConfig, PruneCount, PubSubListener, RequestClientFactory, RequestParameter, RequestParameterLocations, Unlock, createAuthorizationHeaders, isFailedStatusCode, isInfoStatusCode, isSuccessStatusCode, parseRequestParameters };