@lokalise/node-core 10.0.0-RC1 → 10.0.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.
Files changed (89) hide show
  1. package/README.md +16 -60
  2. package/dist/index.d.ts +12 -7
  3. package/dist/index.js +19 -14
  4. package/dist/index.js.map +1 -1
  5. package/dist/src/errors/InternalError.d.ts +1 -0
  6. package/dist/src/errors/InternalError.js +3 -1
  7. package/dist/src/errors/InternalError.js.map +1 -1
  8. package/dist/src/errors/PublicNonRecoverableError.d.ts +1 -0
  9. package/dist/src/errors/PublicNonRecoverableError.js +3 -1
  10. package/dist/src/errors/PublicNonRecoverableError.js.map +1 -1
  11. package/dist/src/errors/errorTypeGuards.d.ts +2 -2
  12. package/dist/src/errors/errorTypeGuards.js +5 -4
  13. package/dist/src/errors/errorTypeGuards.js.map +1 -1
  14. package/dist/src/errors/globalErrorHandler.d.ts +8 -7
  15. package/dist/src/errors/globalErrorHandler.js +15 -16
  16. package/dist/src/errors/globalErrorHandler.js.map +1 -1
  17. package/dist/src/errors/publicErrors.d.ts +5 -4
  18. package/dist/src/errors/publicErrors.js +15 -1
  19. package/dist/src/errors/publicErrors.js.map +1 -1
  20. package/dist/src/logging/commonLogger.d.ts +17 -0
  21. package/dist/src/logging/commonLogger.js +3 -0
  22. package/dist/src/logging/commonLogger.js.map +1 -0
  23. package/dist/src/observability/observabilityTypes.d.ts +22 -0
  24. package/dist/src/observability/observabilityTypes.js +3 -0
  25. package/dist/src/observability/observabilityTypes.js.map +1 -0
  26. package/dist/src/utils/checksumUtils.d.ts +7 -0
  27. package/dist/src/utils/checksumUtils.js +38 -0
  28. package/dist/src/utils/checksumUtils.js.map +1 -0
  29. package/dist/src/utils/encryptionUtility.d.ts +21 -0
  30. package/dist/src/utils/encryptionUtility.js +58 -0
  31. package/dist/src/utils/encryptionUtility.js.map +1 -0
  32. package/dist/src/utils/hashUtils.d.ts +9 -0
  33. package/dist/src/utils/hashUtils.js +19 -0
  34. package/dist/src/utils/hashUtils.js.map +1 -0
  35. package/dist/src/utils/objectUtils.d.ts +17 -0
  36. package/dist/src/utils/objectUtils.js +58 -1
  37. package/dist/src/utils/objectUtils.js.map +1 -1
  38. package/dist/src/utils/streamUtils.d.ts +38 -0
  39. package/dist/src/utils/streamUtils.js +85 -0
  40. package/dist/src/utils/streamUtils.js.map +1 -0
  41. package/package.json +20 -26
  42. package/dist/index.cjs +0 -898
  43. package/dist/index.d.cts +0 -304
  44. package/dist/index.d.mts +0 -304
  45. package/dist/index.mjs +0 -848
  46. package/dist/src/config/ConfigScope.spec.d.ts +0 -1
  47. package/dist/src/config/ConfigScope.spec.js +0 -587
  48. package/dist/src/config/ConfigScope.spec.js.map +0 -1
  49. package/dist/src/config/configTransformers.spec.d.ts +0 -1
  50. package/dist/src/config/configTransformers.spec.js +0 -28
  51. package/dist/src/config/configTransformers.spec.js.map +0 -1
  52. package/dist/src/errors/PublicNonRecoverableError.spec.d.ts +0 -1
  53. package/dist/src/errors/PublicNonRecoverableError.spec.js +0 -13
  54. package/dist/src/errors/PublicNonRecoverableError.spec.js.map +0 -1
  55. package/dist/src/errors/ResponseStatusError.d.ts +0 -7
  56. package/dist/src/errors/ResponseStatusError.js +0 -27
  57. package/dist/src/errors/ResponseStatusError.js.map +0 -1
  58. package/dist/src/errors/errorTypeGuards.spec.d.ts +0 -1
  59. package/dist/src/errors/errorTypeGuards.spec.js +0 -23
  60. package/dist/src/errors/errorTypeGuards.spec.js.map +0 -1
  61. package/dist/src/errors/globalErrorHandler.spec.d.ts +0 -1
  62. package/dist/src/errors/globalErrorHandler.spec.js +0 -30
  63. package/dist/src/errors/globalErrorHandler.spec.js.map +0 -1
  64. package/dist/src/http/httpClient.d.ts +0 -50
  65. package/dist/src/http/httpClient.js +0 -180
  66. package/dist/src/http/httpClient.js.map +0 -1
  67. package/dist/src/http/httpClient.spec.d.ts +0 -1
  68. package/dist/src/http/httpClient.spec.js +0 -777
  69. package/dist/src/http/httpClient.spec.js.map +0 -1
  70. package/dist/src/http/mock-data/mockProduct1.json +0 -12
  71. package/dist/src/http/mock-data/mockProductsLimit3.json +0 -38
  72. package/dist/src/logging/loggerConfigResolver.spec.d.ts +0 -1
  73. package/dist/src/logging/loggerConfigResolver.spec.js +0 -34
  74. package/dist/src/logging/loggerConfigResolver.spec.js.map +0 -1
  75. package/dist/src/utils/arrayUtils.spec.d.ts +0 -1
  76. package/dist/src/utils/arrayUtils.spec.js +0 -60
  77. package/dist/src/utils/arrayUtils.spec.js.map +0 -1
  78. package/dist/src/utils/objectUtils.spec.d.ts +0 -1
  79. package/dist/src/utils/objectUtils.spec.js +0 -612
  80. package/dist/src/utils/objectUtils.spec.js.map +0 -1
  81. package/dist/src/utils/typeUtils.spec.d.ts +0 -1
  82. package/dist/src/utils/typeUtils.spec.js +0 -115
  83. package/dist/src/utils/typeUtils.spec.js.map +0 -1
  84. package/dist/src/utils/waitUtils.spec.d.ts +0 -1
  85. package/dist/src/utils/waitUtils.spec.js +0 -50
  86. package/dist/src/utils/waitUtils.spec.js.map +0 -1
  87. package/dist/vitest.config.d.ts +0 -2
  88. package/dist/vitest.config.js +0 -34
  89. package/dist/vitest.config.js.map +0 -1
package/dist/index.d.cts DELETED
@@ -1,304 +0,0 @@
1
- import { Readable } from 'stream';
2
- import { Client, FormData } from 'undici';
3
- import { RetryConfig, RequestResult } from 'undici-retry';
4
- import { ZodSchema } from 'zod';
5
- import * as pino from 'pino';
6
- import { LoggerOptions } from 'pino';
7
-
8
- type Left<T> = {
9
- error: T;
10
- result?: never;
11
- };
12
- type Right<U> = {
13
- error?: never;
14
- result: U;
15
- };
16
- /**
17
- * Either is a functional programming type which is used to communicate errors happening in potentially recoverable scenarios.
18
- * It can return either an error (Left side) or a resolved result (Right side), but not both.
19
- * It is up to caller of the function to handle received error or throw (Public)NonRecoverableError if it cannot.
20
- *
21
- * @see {@link https://antman-does-software.com/stop-catching-errors-in-typescript-use-the-either-type-to-make-your-code-predictable Further reading on motivation for Either type}
22
- */
23
- type Either<T, U> = NonNullable<Left<T> | Right<U>>;
24
- /***
25
- * Variation of Either, which may or may not have Error set, but always has Result
26
- */
27
- type DefiniteEither<T, U> = {
28
- error?: T;
29
- result: U;
30
- };
31
- declare const isFailure: <T, U>(e: Either<T, U>) => e is Left<T>;
32
- declare const isSuccess: <T, U>(e: Either<T, U>) => e is Right<U>;
33
- declare const failure: <T>(error: T) => Left<T>;
34
- declare const success: <U>(result: U) => Right<U>;
35
-
36
- type RecordObject = Record<string, any>;
37
- type HttpRequestContext = {
38
- reqId: string;
39
- };
40
- type ResponseSchema<Output = any> = {
41
- parse(data: unknown): Output;
42
- };
43
- type RequestOptions<T> = {
44
- headers?: RecordObject;
45
- query?: RecordObject;
46
- timeout: number | undefined;
47
- throwOnError?: boolean;
48
- reqContext?: HttpRequestContext;
49
- safeParseJson?: boolean;
50
- blobResponseBody?: boolean;
51
- requestLabel: string;
52
- disableKeepAlive?: boolean;
53
- retryConfig?: RetryConfig;
54
- clientOptions?: Client.Options;
55
- responseSchema?: ResponseSchema<T>;
56
- validateResponse: boolean;
57
- };
58
- type Response<T> = {
59
- body: T;
60
- headers: RecordObject;
61
- statusCode: number;
62
- };
63
- declare function sendGet<T>(client: Client, path: string, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
64
- declare function sendDelete<T>(client: Client, path: string, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
65
- declare function sendPost<T>(client: Client, path: string, body: RecordObject | undefined, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
66
- declare function sendPostBinary<T>(client: Client, path: string, body: Buffer | Uint8Array | Readable | FormData | null, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
67
- declare function sendPut<T>(client: Client, path: string, body: RecordObject | undefined, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
68
- declare function sendPutBinary<T>(client: Client, path: string, body: Buffer | Uint8Array | Readable | FormData | null, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
69
- declare function sendPatch<T>(client: Client, path: string, body: RecordObject | undefined, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
70
- declare function buildClient(baseUrl: string, clientOptions?: Client.Options): Client;
71
- declare const httpClient: {
72
- get: typeof sendGet;
73
- post: typeof sendPost;
74
- put: typeof sendPut;
75
- patch: typeof sendPatch;
76
- del: typeof sendDelete;
77
- };
78
-
79
- type ErrorDetails = Record<string, unknown>;
80
- type InternalErrorParams<T = ErrorDetails> = {
81
- message: string;
82
- errorCode: string;
83
- details?: T;
84
- };
85
- declare class InternalError<T = ErrorDetails> extends Error {
86
- readonly details?: T;
87
- readonly errorCode: string;
88
- constructor(params: InternalErrorParams<T>);
89
- }
90
-
91
- type PublicNonRecoverableErrorParams = {
92
- message: string;
93
- errorCode: string;
94
- details?: ErrorDetails;
95
- httpStatusCode?: number;
96
- };
97
- /**
98
- * This error is returned to the consumer of API
99
- */
100
- declare class PublicNonRecoverableError extends Error {
101
- readonly details?: ErrorDetails;
102
- readonly errorCode: string;
103
- readonly httpStatusCode: number;
104
- constructor(params: PublicNonRecoverableErrorParams);
105
- }
106
-
107
- declare class ResponseStatusError extends InternalError {
108
- readonly response: RequestResult<any>;
109
- readonly isResponseStatusError = true;
110
- constructor(requestResult: RequestResult<any>, requestLabel?: string);
111
- }
112
-
113
- declare function isResponseStatusError(entity: unknown): entity is ResponseStatusError;
114
-
115
- type EnvValueValidator<InputType> = (value: InputType) => boolean;
116
- type EnvValueTransformer<InputType, OutputType> = (value: InputType) => OutputType;
117
- type RedisConfig = {
118
- host: string;
119
- /**
120
- * An integer from 0 to 15, inclusive
121
- */
122
- db: number;
123
- port: number;
124
- username?: string;
125
- password?: string;
126
- commandTimeout?: number;
127
- connectTimeout?: number;
128
- useTls: boolean;
129
- };
130
- type AppConfig = {
131
- port: number;
132
- bindAddress: string;
133
- logLevel: string;
134
- nodeEnv: 'production' | 'development' | 'test';
135
- appEnv: 'production' | 'development' | 'staging';
136
- };
137
-
138
- type EnvType = {
139
- [key: string]: string | undefined;
140
- };
141
- declare class ConfigScope {
142
- private env;
143
- constructor(envOverride?: EnvType);
144
- updateEnv(): void;
145
- getMandatoryInteger(param: string): number;
146
- getMandatory(param: string): string;
147
- getMandatoryOneOf<const T>(param: string, supportedValues: T[]): T;
148
- getMandatoryValidatedInteger(param: string, validator: EnvValueValidator<number>): number;
149
- getOptionalNullable<T extends string | null | undefined>(param: string, defaultValue: T): T | string;
150
- getOptional(param: string, defaultValue: string): string;
151
- getOptionalInteger(param: string, defaultValue: number): number;
152
- getOptionalNullableInteger<T extends number | null | undefined>(param: string, defaultValue: T): T | number;
153
- getOptionalOneOf<const T extends string>(param: string, defaultValue: T, supportedValues: T[]): T;
154
- getOptionalValidated(param: string, defaultValue: string, validator: EnvValueValidator<string>): string;
155
- getOptionalValidatedInteger(param: string, defaultValue: number, validator: EnvValueValidator<number>): number;
156
- getOptionalTransformed(param: string, defaultValue: string, transformer: (value: string) => string): string;
157
- getOptionalNullableTransformed<T extends string | undefined>(param: string, defaultValue: T, transformer: (value: T | string) => T | string): T | string;
158
- getMandatoryTransformed(param: string, transformer: (value: string) => string): string;
159
- getOptionalBoolean(param: string, defaultValue: boolean): boolean;
160
- getMandatoryJsonObject<T extends object>(param: string, schema: ZodSchema<T>): T;
161
- getOptionalNullableJsonObject<T extends object, Z extends T | null | undefined>(param: string, schema: ZodSchema<T>, defaultValue: Z): Z;
162
- getOptionalJsonObject<T extends object>(param: string, schema: ZodSchema<T>, defaultValue: T): T;
163
- isProduction(): boolean;
164
- isDevelopment(): boolean;
165
- isTest(): boolean;
166
- private validateSchema;
167
- }
168
-
169
- declare const ensureClosingSlashTransformer: EnvValueTransformer<string | undefined | null, string>;
170
-
171
- declare const createRangeValidator: (greaterOrEqualThan: number, lessOrEqualThan: number) => EnvValueValidator<number>;
172
-
173
- declare function chunk<T>(array: T[], chunkSize: number): T[][];
174
- declare function callChunked<Item>(chunkSize: number, array: readonly Item[], processFn: (arrayChunk: Item[]) => Promise<unknown>): Promise<void>;
175
- /**
176
- * Return a copy of the given array without null or undefined values
177
- */
178
- declare function removeNullish<const T>(array: readonly (T | null | undefined)[]): T[];
179
- /**
180
- * Return a copy of the given array without falsy values (eg: false, 0, '', null, undefined)
181
- */
182
- declare function removeFalsy<const T>(array: readonly (T | null | undefined | 0 | '' | false)[]): T[];
183
-
184
- type RecordKeyType = string | number | symbol;
185
- declare function copyWithoutUndefined<T extends Record<RecordKeyType, unknown>, TargetRecordType = Pick<T, {
186
- [Prop in keyof T]: T[Prop] extends null | undefined ? never : Prop;
187
- }[keyof T]>>(originalValue: T): TargetRecordType;
188
- declare function pick<T, K extends string | number | symbol>(source: T, propNames: readonly K[]): Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>;
189
- declare function pickWithoutUndefined<T, K extends string | number | symbol>(source: T, propNames: readonly K[]): Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>;
190
- declare function isEmptyObject(params: Record<string, unknown>): boolean;
191
- type KeysMatching<T, V> = {
192
- [K in keyof T]: T[K] extends V ? K : never;
193
- }[keyof T];
194
- /**
195
- * @param array The array of objects to be grouped.
196
- * @param selector The key used for grouping the objects.
197
- * @returns An object where the keys are unique values from the given selector and the values are the corresponding objects from the array.
198
- */
199
- declare function groupBy<T extends object, K extends KeysMatching<T, RecordKeyType | null | undefined>>(array: T[], selector: K): Record<RecordKeyType, T[]>;
200
- /**
201
- * @param array The array of objects to be grouped.
202
- * @param selector The key used for grouping the objects.
203
- * @returns An object where the keys are unique values from the given selector and the value is the
204
- * corresponding object from the array.
205
- * @throws InternalError If a duplicated value is found for the given selector.
206
- */
207
- declare function groupByUnique<T extends object, K extends KeysMatching<T, RecordKeyType | null | undefined>>(array: T[], selector: K): Record<RecordKeyType, T>;
208
- type DatesAsString<T> = T extends Date ? string : ExactlyLikeWithDateAsString<T>;
209
- type ExactlyLikeWithDateAsString<T> = T extends object ? {
210
- [K in keyof T]: DatesAsString<T[K]>;
211
- } : T;
212
- declare function convertDateFieldsToIsoString<Input extends object>(object: Input): ExactlyLikeWithDateAsString<Input>;
213
- declare function convertDateFieldsToIsoString<Input extends object>(object: Input[]): ExactlyLikeWithDateAsString<Input>[];
214
- /**
215
- * Return a deep clone copy of an object.
216
- *
217
- * Please Note: This uses structuredClone, which has the limitations of these restricted Types: functions,
218
- * Error objects, WeakMap, WeakSet, DOM nodes, and certain other browser-specific objects like Window.
219
- */
220
- declare function deepClone<T extends object | undefined | null>(object: T): T;
221
-
222
- type StandardizedError = {
223
- code: string;
224
- message: string;
225
- };
226
- declare function hasMessage(maybe: unknown): maybe is {
227
- message: string;
228
- };
229
- declare function isObject(maybeObject: unknown): maybeObject is Record<PropertyKey, unknown>;
230
- declare function isStandardizedError(error: unknown): error is StandardizedError;
231
- declare function isInternalError(error: unknown): error is InternalError;
232
- declare function isPublicNonRecoverableError(error: unknown): error is PublicNonRecoverableError;
233
-
234
- type AppLoggerConfig = {
235
- logLevel: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent';
236
- nodeEnv: 'production' | 'development' | 'test';
237
- base?: Record<string, unknown>;
238
- };
239
- type MonorepoAppLoggerConfig = AppLoggerConfig & {
240
- targetFile?: string;
241
- append?: boolean;
242
- };
243
- declare function resolveMonorepoLoggerConfiguration(appConfig: MonorepoAppLoggerConfig): LoggerOptions;
244
- declare function resolveLoggerConfiguration(appConfig: AppLoggerConfig): LoggerOptions;
245
-
246
- /**
247
- * Generic interface for resolving specific kind of errors based on something that was thrown during execution
248
- */
249
- type ErrorResolver = {
250
- processError: (thrownError: unknown) => InternalError;
251
- };
252
- interface ErrorReport {
253
- error: Error;
254
- context?: Record<string, unknown>;
255
- }
256
- type ErrorReporter = {
257
- report: (errorReport: ErrorReport) => void;
258
- };
259
-
260
- declare const globalLogger: pino.Logger<never>;
261
- declare function resolveGlobalErrorLogObject(err: unknown, correlationID?: string): string | {
262
- correlationID: string | undefined;
263
- type: string;
264
- message: string;
265
- stack: string;
266
- raw: Error;
267
- cause?: undefined;
268
- };
269
- declare function executeAndHandleGlobalErrors<T>(operation: () => T): T;
270
- declare function executeAsyncAndHandleGlobalErrors<T>(operation: () => Promise<T>, stopOnError?: boolean): Promise<T | undefined>;
271
- declare function executeSettleAllAndHandleGlobalErrors(promises: Promise<unknown>[], stopOnError?: boolean): Promise<PromiseSettledResult<unknown>[]>;
272
-
273
- type MayOmit<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
274
-
275
- type FreeformRecord = Record<string, any>;
276
-
277
- type CommonErrorParams = {
278
- message: string;
279
- details?: FreeformRecord;
280
- };
281
- type OptionalMessageErrorParams = {
282
- message?: string;
283
- details?: FreeformRecord;
284
- };
285
- type ValidationError = {
286
- message: string;
287
- path: string[];
288
- };
289
- declare class RequestValidationError extends PublicNonRecoverableError {
290
- constructor(errors: ValidationError[]);
291
- }
292
- declare class AccessDeniedError extends PublicNonRecoverableError {
293
- constructor(params: CommonErrorParams);
294
- }
295
- declare class EntityNotFoundError extends PublicNonRecoverableError {
296
- constructor(params: CommonErrorParams);
297
- }
298
- declare class AuthFailedError extends PublicNonRecoverableError {
299
- constructor(params?: OptionalMessageErrorParams);
300
- }
301
-
302
- declare const waitAndRetry: <T>(predicateFn: () => T, sleepTime?: number, maxRetryCount?: number) => Promise<T>;
303
-
304
- export { AccessDeniedError, type AppConfig, type AppLoggerConfig, AuthFailedError, type CommonErrorParams, ConfigScope, type Either, EntityNotFoundError, type EnvValueTransformer, type EnvValueValidator, type ErrorDetails, type ErrorReport, type ErrorReporter, type ErrorResolver, type FreeformRecord, type HttpRequestContext, InternalError, type InternalErrorParams, type MayOmit, type MonorepoAppLoggerConfig, type OptionalMessageErrorParams, PublicNonRecoverableError, type PublicNonRecoverableErrorParams, type RedisConfig, type RequestOptions, RequestValidationError, type Response, type ResponseSchema, ResponseStatusError, type StandardizedError, type ValidationError, buildClient, callChunked, chunk, convertDateFieldsToIsoString, copyWithoutUndefined, createRangeValidator, deepClone, ensureClosingSlashTransformer, executeAndHandleGlobalErrors, executeAsyncAndHandleGlobalErrors, executeSettleAllAndHandleGlobalErrors, failure, globalLogger, groupBy, groupByUnique, hasMessage, httpClient, isEmptyObject, isFailure, isInternalError, isObject, isPublicNonRecoverableError, isResponseStatusError, isStandardizedError, isSuccess, pick, pickWithoutUndefined, removeFalsy, removeNullish, resolveGlobalErrorLogObject, resolveLoggerConfiguration, resolveMonorepoLoggerConfiguration, sendDelete, sendGet, sendPatch, sendPost, sendPostBinary, sendPut, sendPutBinary, success, waitAndRetry };
package/dist/index.d.mts DELETED
@@ -1,304 +0,0 @@
1
- import { Readable } from 'stream';
2
- import { Client, FormData } from 'undici';
3
- import { RetryConfig, RequestResult } from 'undici-retry';
4
- import { ZodSchema } from 'zod';
5
- import * as pino from 'pino';
6
- import { LoggerOptions } from 'pino';
7
-
8
- type Left<T> = {
9
- error: T;
10
- result?: never;
11
- };
12
- type Right<U> = {
13
- error?: never;
14
- result: U;
15
- };
16
- /**
17
- * Either is a functional programming type which is used to communicate errors happening in potentially recoverable scenarios.
18
- * It can return either an error (Left side) or a resolved result (Right side), but not both.
19
- * It is up to caller of the function to handle received error or throw (Public)NonRecoverableError if it cannot.
20
- *
21
- * @see {@link https://antman-does-software.com/stop-catching-errors-in-typescript-use-the-either-type-to-make-your-code-predictable Further reading on motivation for Either type}
22
- */
23
- type Either<T, U> = NonNullable<Left<T> | Right<U>>;
24
- /***
25
- * Variation of Either, which may or may not have Error set, but always has Result
26
- */
27
- type DefiniteEither<T, U> = {
28
- error?: T;
29
- result: U;
30
- };
31
- declare const isFailure: <T, U>(e: Either<T, U>) => e is Left<T>;
32
- declare const isSuccess: <T, U>(e: Either<T, U>) => e is Right<U>;
33
- declare const failure: <T>(error: T) => Left<T>;
34
- declare const success: <U>(result: U) => Right<U>;
35
-
36
- type RecordObject = Record<string, any>;
37
- type HttpRequestContext = {
38
- reqId: string;
39
- };
40
- type ResponseSchema<Output = any> = {
41
- parse(data: unknown): Output;
42
- };
43
- type RequestOptions<T> = {
44
- headers?: RecordObject;
45
- query?: RecordObject;
46
- timeout: number | undefined;
47
- throwOnError?: boolean;
48
- reqContext?: HttpRequestContext;
49
- safeParseJson?: boolean;
50
- blobResponseBody?: boolean;
51
- requestLabel: string;
52
- disableKeepAlive?: boolean;
53
- retryConfig?: RetryConfig;
54
- clientOptions?: Client.Options;
55
- responseSchema?: ResponseSchema<T>;
56
- validateResponse: boolean;
57
- };
58
- type Response<T> = {
59
- body: T;
60
- headers: RecordObject;
61
- statusCode: number;
62
- };
63
- declare function sendGet<T>(client: Client, path: string, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
64
- declare function sendDelete<T>(client: Client, path: string, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
65
- declare function sendPost<T>(client: Client, path: string, body: RecordObject | undefined, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
66
- declare function sendPostBinary<T>(client: Client, path: string, body: Buffer | Uint8Array | Readable | FormData | null, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
67
- declare function sendPut<T>(client: Client, path: string, body: RecordObject | undefined, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
68
- declare function sendPutBinary<T>(client: Client, path: string, body: Buffer | Uint8Array | Readable | FormData | null, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
69
- declare function sendPatch<T>(client: Client, path: string, body: RecordObject | undefined, options?: Partial<RequestOptions<T>>): Promise<DefiniteEither<RequestResult<unknown>, RequestResult<T>>>;
70
- declare function buildClient(baseUrl: string, clientOptions?: Client.Options): Client;
71
- declare const httpClient: {
72
- get: typeof sendGet;
73
- post: typeof sendPost;
74
- put: typeof sendPut;
75
- patch: typeof sendPatch;
76
- del: typeof sendDelete;
77
- };
78
-
79
- type ErrorDetails = Record<string, unknown>;
80
- type InternalErrorParams<T = ErrorDetails> = {
81
- message: string;
82
- errorCode: string;
83
- details?: T;
84
- };
85
- declare class InternalError<T = ErrorDetails> extends Error {
86
- readonly details?: T;
87
- readonly errorCode: string;
88
- constructor(params: InternalErrorParams<T>);
89
- }
90
-
91
- type PublicNonRecoverableErrorParams = {
92
- message: string;
93
- errorCode: string;
94
- details?: ErrorDetails;
95
- httpStatusCode?: number;
96
- };
97
- /**
98
- * This error is returned to the consumer of API
99
- */
100
- declare class PublicNonRecoverableError extends Error {
101
- readonly details?: ErrorDetails;
102
- readonly errorCode: string;
103
- readonly httpStatusCode: number;
104
- constructor(params: PublicNonRecoverableErrorParams);
105
- }
106
-
107
- declare class ResponseStatusError extends InternalError {
108
- readonly response: RequestResult<any>;
109
- readonly isResponseStatusError = true;
110
- constructor(requestResult: RequestResult<any>, requestLabel?: string);
111
- }
112
-
113
- declare function isResponseStatusError(entity: unknown): entity is ResponseStatusError;
114
-
115
- type EnvValueValidator<InputType> = (value: InputType) => boolean;
116
- type EnvValueTransformer<InputType, OutputType> = (value: InputType) => OutputType;
117
- type RedisConfig = {
118
- host: string;
119
- /**
120
- * An integer from 0 to 15, inclusive
121
- */
122
- db: number;
123
- port: number;
124
- username?: string;
125
- password?: string;
126
- commandTimeout?: number;
127
- connectTimeout?: number;
128
- useTls: boolean;
129
- };
130
- type AppConfig = {
131
- port: number;
132
- bindAddress: string;
133
- logLevel: string;
134
- nodeEnv: 'production' | 'development' | 'test';
135
- appEnv: 'production' | 'development' | 'staging';
136
- };
137
-
138
- type EnvType = {
139
- [key: string]: string | undefined;
140
- };
141
- declare class ConfigScope {
142
- private env;
143
- constructor(envOverride?: EnvType);
144
- updateEnv(): void;
145
- getMandatoryInteger(param: string): number;
146
- getMandatory(param: string): string;
147
- getMandatoryOneOf<const T>(param: string, supportedValues: T[]): T;
148
- getMandatoryValidatedInteger(param: string, validator: EnvValueValidator<number>): number;
149
- getOptionalNullable<T extends string | null | undefined>(param: string, defaultValue: T): T | string;
150
- getOptional(param: string, defaultValue: string): string;
151
- getOptionalInteger(param: string, defaultValue: number): number;
152
- getOptionalNullableInteger<T extends number | null | undefined>(param: string, defaultValue: T): T | number;
153
- getOptionalOneOf<const T extends string>(param: string, defaultValue: T, supportedValues: T[]): T;
154
- getOptionalValidated(param: string, defaultValue: string, validator: EnvValueValidator<string>): string;
155
- getOptionalValidatedInteger(param: string, defaultValue: number, validator: EnvValueValidator<number>): number;
156
- getOptionalTransformed(param: string, defaultValue: string, transformer: (value: string) => string): string;
157
- getOptionalNullableTransformed<T extends string | undefined>(param: string, defaultValue: T, transformer: (value: T | string) => T | string): T | string;
158
- getMandatoryTransformed(param: string, transformer: (value: string) => string): string;
159
- getOptionalBoolean(param: string, defaultValue: boolean): boolean;
160
- getMandatoryJsonObject<T extends object>(param: string, schema: ZodSchema<T>): T;
161
- getOptionalNullableJsonObject<T extends object, Z extends T | null | undefined>(param: string, schema: ZodSchema<T>, defaultValue: Z): Z;
162
- getOptionalJsonObject<T extends object>(param: string, schema: ZodSchema<T>, defaultValue: T): T;
163
- isProduction(): boolean;
164
- isDevelopment(): boolean;
165
- isTest(): boolean;
166
- private validateSchema;
167
- }
168
-
169
- declare const ensureClosingSlashTransformer: EnvValueTransformer<string | undefined | null, string>;
170
-
171
- declare const createRangeValidator: (greaterOrEqualThan: number, lessOrEqualThan: number) => EnvValueValidator<number>;
172
-
173
- declare function chunk<T>(array: T[], chunkSize: number): T[][];
174
- declare function callChunked<Item>(chunkSize: number, array: readonly Item[], processFn: (arrayChunk: Item[]) => Promise<unknown>): Promise<void>;
175
- /**
176
- * Return a copy of the given array without null or undefined values
177
- */
178
- declare function removeNullish<const T>(array: readonly (T | null | undefined)[]): T[];
179
- /**
180
- * Return a copy of the given array without falsy values (eg: false, 0, '', null, undefined)
181
- */
182
- declare function removeFalsy<const T>(array: readonly (T | null | undefined | 0 | '' | false)[]): T[];
183
-
184
- type RecordKeyType = string | number | symbol;
185
- declare function copyWithoutUndefined<T extends Record<RecordKeyType, unknown>, TargetRecordType = Pick<T, {
186
- [Prop in keyof T]: T[Prop] extends null | undefined ? never : Prop;
187
- }[keyof T]>>(originalValue: T): TargetRecordType;
188
- declare function pick<T, K extends string | number | symbol>(source: T, propNames: readonly K[]): Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>;
189
- declare function pickWithoutUndefined<T, K extends string | number | symbol>(source: T, propNames: readonly K[]): Pick<T, Exclude<keyof T, Exclude<keyof T, K>>>;
190
- declare function isEmptyObject(params: Record<string, unknown>): boolean;
191
- type KeysMatching<T, V> = {
192
- [K in keyof T]: T[K] extends V ? K : never;
193
- }[keyof T];
194
- /**
195
- * @param array The array of objects to be grouped.
196
- * @param selector The key used for grouping the objects.
197
- * @returns An object where the keys are unique values from the given selector and the values are the corresponding objects from the array.
198
- */
199
- declare function groupBy<T extends object, K extends KeysMatching<T, RecordKeyType | null | undefined>>(array: T[], selector: K): Record<RecordKeyType, T[]>;
200
- /**
201
- * @param array The array of objects to be grouped.
202
- * @param selector The key used for grouping the objects.
203
- * @returns An object where the keys are unique values from the given selector and the value is the
204
- * corresponding object from the array.
205
- * @throws InternalError If a duplicated value is found for the given selector.
206
- */
207
- declare function groupByUnique<T extends object, K extends KeysMatching<T, RecordKeyType | null | undefined>>(array: T[], selector: K): Record<RecordKeyType, T>;
208
- type DatesAsString<T> = T extends Date ? string : ExactlyLikeWithDateAsString<T>;
209
- type ExactlyLikeWithDateAsString<T> = T extends object ? {
210
- [K in keyof T]: DatesAsString<T[K]>;
211
- } : T;
212
- declare function convertDateFieldsToIsoString<Input extends object>(object: Input): ExactlyLikeWithDateAsString<Input>;
213
- declare function convertDateFieldsToIsoString<Input extends object>(object: Input[]): ExactlyLikeWithDateAsString<Input>[];
214
- /**
215
- * Return a deep clone copy of an object.
216
- *
217
- * Please Note: This uses structuredClone, which has the limitations of these restricted Types: functions,
218
- * Error objects, WeakMap, WeakSet, DOM nodes, and certain other browser-specific objects like Window.
219
- */
220
- declare function deepClone<T extends object | undefined | null>(object: T): T;
221
-
222
- type StandardizedError = {
223
- code: string;
224
- message: string;
225
- };
226
- declare function hasMessage(maybe: unknown): maybe is {
227
- message: string;
228
- };
229
- declare function isObject(maybeObject: unknown): maybeObject is Record<PropertyKey, unknown>;
230
- declare function isStandardizedError(error: unknown): error is StandardizedError;
231
- declare function isInternalError(error: unknown): error is InternalError;
232
- declare function isPublicNonRecoverableError(error: unknown): error is PublicNonRecoverableError;
233
-
234
- type AppLoggerConfig = {
235
- logLevel: 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent';
236
- nodeEnv: 'production' | 'development' | 'test';
237
- base?: Record<string, unknown>;
238
- };
239
- type MonorepoAppLoggerConfig = AppLoggerConfig & {
240
- targetFile?: string;
241
- append?: boolean;
242
- };
243
- declare function resolveMonorepoLoggerConfiguration(appConfig: MonorepoAppLoggerConfig): LoggerOptions;
244
- declare function resolveLoggerConfiguration(appConfig: AppLoggerConfig): LoggerOptions;
245
-
246
- /**
247
- * Generic interface for resolving specific kind of errors based on something that was thrown during execution
248
- */
249
- type ErrorResolver = {
250
- processError: (thrownError: unknown) => InternalError;
251
- };
252
- interface ErrorReport {
253
- error: Error;
254
- context?: Record<string, unknown>;
255
- }
256
- type ErrorReporter = {
257
- report: (errorReport: ErrorReport) => void;
258
- };
259
-
260
- declare const globalLogger: pino.Logger<never>;
261
- declare function resolveGlobalErrorLogObject(err: unknown, correlationID?: string): string | {
262
- correlationID: string | undefined;
263
- type: string;
264
- message: string;
265
- stack: string;
266
- raw: Error;
267
- cause?: undefined;
268
- };
269
- declare function executeAndHandleGlobalErrors<T>(operation: () => T): T;
270
- declare function executeAsyncAndHandleGlobalErrors<T>(operation: () => Promise<T>, stopOnError?: boolean): Promise<T | undefined>;
271
- declare function executeSettleAllAndHandleGlobalErrors(promises: Promise<unknown>[], stopOnError?: boolean): Promise<PromiseSettledResult<unknown>[]>;
272
-
273
- type MayOmit<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
274
-
275
- type FreeformRecord = Record<string, any>;
276
-
277
- type CommonErrorParams = {
278
- message: string;
279
- details?: FreeformRecord;
280
- };
281
- type OptionalMessageErrorParams = {
282
- message?: string;
283
- details?: FreeformRecord;
284
- };
285
- type ValidationError = {
286
- message: string;
287
- path: string[];
288
- };
289
- declare class RequestValidationError extends PublicNonRecoverableError {
290
- constructor(errors: ValidationError[]);
291
- }
292
- declare class AccessDeniedError extends PublicNonRecoverableError {
293
- constructor(params: CommonErrorParams);
294
- }
295
- declare class EntityNotFoundError extends PublicNonRecoverableError {
296
- constructor(params: CommonErrorParams);
297
- }
298
- declare class AuthFailedError extends PublicNonRecoverableError {
299
- constructor(params?: OptionalMessageErrorParams);
300
- }
301
-
302
- declare const waitAndRetry: <T>(predicateFn: () => T, sleepTime?: number, maxRetryCount?: number) => Promise<T>;
303
-
304
- export { AccessDeniedError, type AppConfig, type AppLoggerConfig, AuthFailedError, type CommonErrorParams, ConfigScope, type Either, EntityNotFoundError, type EnvValueTransformer, type EnvValueValidator, type ErrorDetails, type ErrorReport, type ErrorReporter, type ErrorResolver, type FreeformRecord, type HttpRequestContext, InternalError, type InternalErrorParams, type MayOmit, type MonorepoAppLoggerConfig, type OptionalMessageErrorParams, PublicNonRecoverableError, type PublicNonRecoverableErrorParams, type RedisConfig, type RequestOptions, RequestValidationError, type Response, type ResponseSchema, ResponseStatusError, type StandardizedError, type ValidationError, buildClient, callChunked, chunk, convertDateFieldsToIsoString, copyWithoutUndefined, createRangeValidator, deepClone, ensureClosingSlashTransformer, executeAndHandleGlobalErrors, executeAsyncAndHandleGlobalErrors, executeSettleAllAndHandleGlobalErrors, failure, globalLogger, groupBy, groupByUnique, hasMessage, httpClient, isEmptyObject, isFailure, isInternalError, isObject, isPublicNonRecoverableError, isResponseStatusError, isStandardizedError, isSuccess, pick, pickWithoutUndefined, removeFalsy, removeNullish, resolveGlobalErrorLogObject, resolveLoggerConfiguration, resolveMonorepoLoggerConfiguration, sendDelete, sendGet, sendPatch, sendPost, sendPostBinary, sendPut, sendPutBinary, success, waitAndRetry };