@metriport/shared 0.9.7 → 0.9.8
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/common/__tests__/retry.test.js +190 -19
- package/dist/common/__tests__/retry.test.js.map +1 -1
- package/dist/common/array.d.ts +1 -1
- package/dist/common/array.d.ts.map +1 -1
- package/dist/common/array.js +3 -0
- package/dist/common/array.js.map +1 -1
- package/dist/common/file-downloader.d.ts +14 -0
- package/dist/common/file-downloader.d.ts.map +1 -0
- package/dist/common/file-downloader.js +63 -0
- package/dist/common/file-downloader.js.map +1 -0
- package/dist/common/http.d.ts +42 -0
- package/dist/common/http.d.ts.map +1 -0
- package/dist/common/http.js +83 -0
- package/dist/common/http.js.map +1 -0
- package/dist/common/retry-with-backoff.d.ts +27 -0
- package/dist/common/retry-with-backoff.d.ts.map +1 -0
- package/dist/common/retry-with-backoff.js +47 -0
- package/dist/common/retry-with-backoff.js.map +1 -0
- package/dist/common/retry.d.ts +49 -26
- package/dist/common/retry.d.ts.map +1 -1
- package/dist/common/retry.js +85 -34
- package/dist/common/retry.js.map +1 -1
- package/dist/common/stream.d.ts +6 -0
- package/dist/common/stream.d.ts.map +1 -0
- package/dist/common/stream.js +18 -0
- package/dist/common/stream.js.map +1 -0
- package/dist/common/uuid.d.ts +2 -0
- package/dist/common/uuid.d.ts.map +1 -0
- package/dist/common/uuid.js +5 -0
- package/dist/common/uuid.js.map +1 -0
- package/dist/error/shared.d.ts +1 -1
- package/dist/error/shared.d.ts.map +1 -1
- package/dist/error/shared.js +7 -2
- package/dist/error/shared.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/index.js.map +1 -1
- package/dist/net/__tests__/another.d.ts +1 -0
- package/dist/net/__tests__/another.d.ts.map +1 -0
- package/dist/net/__tests__/another.js +2 -0
- package/dist/net/__tests__/another.js.map +1 -0
- package/dist/net/__tests__/http.test.d.ts +2 -0
- package/dist/net/__tests__/http.test.d.ts.map +1 -0
- package/dist/net/__tests__/http.test.js +102 -0
- package/dist/net/__tests__/http.test.js.map +1 -0
- package/dist/net/__tests__/retry.test.d.ts +2 -0
- package/dist/net/__tests__/retry.test.d.ts.map +1 -0
- package/dist/net/__tests__/retry.test.js +158 -0
- package/dist/net/__tests__/retry.test.js.map +1 -0
- package/dist/net/error.d.ts +19 -0
- package/dist/net/error.d.ts.map +1 -0
- package/dist/net/error.js +49 -0
- package/dist/net/error.js.map +1 -0
- package/dist/net/net.d.ts +2 -0
- package/dist/net/net.d.ts.map +1 -0
- package/dist/net/net.js +16 -0
- package/dist/net/net.js.map +1 -0
- package/dist/net/retry-with-backoff.d.ts +42 -0
- package/dist/net/retry-with-backoff.d.ts.map +1 -0
- package/dist/net/retry-with-backoff.js +83 -0
- package/dist/net/retry-with-backoff.js.map +1 -0
- package/dist/net/retry.d.ts +28 -0
- package/dist/net/retry.d.ts.map +1 -0
- package/dist/net/retry.js +57 -0
- package/dist/net/retry.js.map +1 -0
- package/dist/net/stream.d.ts +6 -0
- package/dist/net/stream.d.ts.map +1 -0
- package/dist/net/stream.js +18 -0
- package/dist/net/stream.js.map +1 -0
- package/package.json +2 -2
package/dist/common/retry.d.ts
CHANGED
|
@@ -1,37 +1,60 @@
|
|
|
1
|
+
export declare const defaultOptions: Required<ExecuteWithRetriesOptions<unknown>>;
|
|
2
|
+
export type ExecuteWithRetriesOptions<T> = {
|
|
3
|
+
/** The intitial delay in milliseconds. Defaults to 10ms. */
|
|
4
|
+
initialDelay?: number;
|
|
5
|
+
/** The maximum delay in milliseconds. Defaults to Infinity. */
|
|
6
|
+
maxDelay?: number;
|
|
7
|
+
/**
|
|
8
|
+
* Determines how the backoff is calculated.
|
|
9
|
+
* Defaults to 2 (exponential backoff).
|
|
10
|
+
* Set to 0 to disable backoff.
|
|
11
|
+
*/
|
|
12
|
+
backoffMultiplier?: number;
|
|
13
|
+
/** The maximum number of retries. Defaults to 10. */
|
|
14
|
+
maxAttempts?: number;
|
|
15
|
+
/** Function to determine if the error should be retried. Defaults to always retry. */
|
|
16
|
+
shouldRetry?: (result: T | undefined, error: unknown, attempt: number) => boolean | Promise<boolean>;
|
|
17
|
+
/** Function to determine if the result should be retried. Defaults to always retry. */
|
|
18
|
+
/** Function to determine how long to wait before the next retry. It should not be changed. */
|
|
19
|
+
getTimeToWait?: (params: GetTimeToWaitParams) => number;
|
|
20
|
+
/** Function to log details about the execution */
|
|
21
|
+
log?: typeof console.log;
|
|
22
|
+
};
|
|
23
|
+
export type GetTimeToWaitParams = {
|
|
24
|
+
initialDelay: number;
|
|
25
|
+
backoffMultiplier: number;
|
|
26
|
+
attempt: number;
|
|
27
|
+
maxDelay: number;
|
|
28
|
+
};
|
|
1
29
|
/**
|
|
2
|
-
* Executes a function with retries
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* If the function
|
|
30
|
+
* Executes a function with retries and backoff with jitter.
|
|
31
|
+
* Decides whether or not to retry based on the `shouldRetry()` function parameter - by default
|
|
32
|
+
* it only retries on error.
|
|
33
|
+
* If the function doesn't throw errors and `shouldRetry` returns true, it will return the last
|
|
34
|
+
* function's result when it reaches the maximum attempts.
|
|
35
|
+
* It retries up to maxAttempts-1, waiting between each retry.
|
|
36
|
+
* If the function throws an error on the last attempt, it will throw the error.
|
|
37
|
+
* If the function succeeds and `shouldRetry` returns false, it will return the function's result.
|
|
6
38
|
*
|
|
7
39
|
* @param fn the function to be executed
|
|
8
|
-
* @param
|
|
9
|
-
*
|
|
10
|
-
* @param log the logger to use, defaults to console.log
|
|
40
|
+
* @param options the options to be used; see `ExecuteWithRetriesOptions` for components and
|
|
41
|
+
* `defaultOptions` for defaults.
|
|
11
42
|
* @returns the result of calling the `fn` function
|
|
43
|
+
* @see https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
|
12
44
|
*/
|
|
13
|
-
export declare function
|
|
14
|
-
|
|
15
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
16
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
17
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
18
|
-
}): Promise<K>;
|
|
45
|
+
export declare function executeWithRetries<T>(fn: () => Promise<T>, options?: ExecuteWithRetriesOptions<T>): Promise<T>;
|
|
46
|
+
export declare function defaultGetTimeToWait({ initialDelay, backoffMultiplier, attempt, maxDelay, }: GetTimeToWaitParams): number;
|
|
19
47
|
/**
|
|
20
|
-
* Executes a function with retries. If the function throws an error, it will retry
|
|
21
|
-
* up to
|
|
22
|
-
* If the function throws an error on the last
|
|
48
|
+
* Executes a function with retries and backoff with jitter. If the function throws an error, it will retry
|
|
49
|
+
* up to maxAttempts-1, waiting between each retry.
|
|
50
|
+
* If the function throws an error on the last attempt, it will return `undefined`.
|
|
23
51
|
* If the function succeeds, it will return the result.
|
|
24
52
|
*
|
|
25
53
|
* @param fn the function to be executed
|
|
26
|
-
* @param
|
|
27
|
-
*
|
|
28
|
-
* @
|
|
29
|
-
* @
|
|
54
|
+
* @param options the options to be used; see `ExecuteWithRetriesOptions` for components and
|
|
55
|
+
* `defaultOptions` for defaults.
|
|
56
|
+
* @returns the result of calling the `fn` function
|
|
57
|
+
* @see https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
|
30
58
|
*/
|
|
31
|
-
export declare function
|
|
32
|
-
(...data: any[]): void;
|
|
33
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
34
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
35
|
-
(message?: any, ...optionalParams: any[]): void;
|
|
36
|
-
}): Promise<K | undefined>;
|
|
59
|
+
export declare function executeWithRetriesSafe<T>(fn: () => Promise<T>, options?: Partial<ExecuteWithRetriesOptions<T>>): Promise<T | undefined>;
|
|
37
60
|
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/common/retry.ts"],"names":[],"mappings":"
|
|
1
|
+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;;;;;;;GAWG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,EAC5C,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAC,CAAC,CAAC,GAC9C,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CASxB"}
|
package/dist/common/retry.js
CHANGED
|
@@ -1,60 +1,111 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.executeWithRetries = exports.
|
|
4
|
-
const
|
|
3
|
+
exports.executeWithRetriesSafe = exports.defaultGetTimeToWait = exports.executeWithRetries = exports.defaultOptions = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
const metriport_error_1 = require("../error/metriport-error");
|
|
6
|
+
const shared_1 = require("../error/shared");
|
|
5
7
|
const sleep_1 = require("./sleep");
|
|
8
|
+
function defaultShouldRetry(_, error) {
|
|
9
|
+
if (error)
|
|
10
|
+
return true;
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
exports.defaultOptions = {
|
|
14
|
+
initialDelay: 10,
|
|
15
|
+
maxDelay: Infinity,
|
|
16
|
+
backoffMultiplier: 2,
|
|
17
|
+
maxAttempts: 10,
|
|
18
|
+
shouldRetry: defaultShouldRetry,
|
|
19
|
+
getTimeToWait: defaultGetTimeToWait,
|
|
20
|
+
log: console.log,
|
|
21
|
+
};
|
|
6
22
|
/**
|
|
7
|
-
* Executes a function with retries
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* If the function
|
|
23
|
+
* Executes a function with retries and backoff with jitter.
|
|
24
|
+
* Decides whether or not to retry based on the `shouldRetry()` function parameter - by default
|
|
25
|
+
* it only retries on error.
|
|
26
|
+
* If the function doesn't throw errors and `shouldRetry` returns true, it will return the last
|
|
27
|
+
* function's result when it reaches the maximum attempts.
|
|
28
|
+
* It retries up to maxAttempts-1, waiting between each retry.
|
|
29
|
+
* If the function throws an error on the last attempt, it will throw the error.
|
|
30
|
+
* If the function succeeds and `shouldRetry` returns false, it will return the function's result.
|
|
11
31
|
*
|
|
12
32
|
* @param fn the function to be executed
|
|
13
|
-
* @param
|
|
14
|
-
*
|
|
15
|
-
* @param log the logger to use, defaults to console.log
|
|
33
|
+
* @param options the options to be used; see `ExecuteWithRetriesOptions` for components and
|
|
34
|
+
* `defaultOptions` for defaults.
|
|
16
35
|
* @returns the result of calling the `fn` function
|
|
36
|
+
* @see https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
|
17
37
|
*/
|
|
18
|
-
async function
|
|
19
|
-
|
|
20
|
-
|
|
38
|
+
async function executeWithRetries(fn, options = exports.defaultOptions) {
|
|
39
|
+
const actualOptions = { ...exports.defaultOptions, ...options };
|
|
40
|
+
const { initialDelay, maxDelay, backoffMultiplier, maxAttempts: _maxAttempts, shouldRetry, getTimeToWait, log, } = actualOptions;
|
|
41
|
+
const context = "executeWithRetries";
|
|
42
|
+
const maxAttempts = Math.max(_maxAttempts, 1);
|
|
43
|
+
let attempt = 0;
|
|
44
|
+
while (++attempt <= maxAttempts) {
|
|
21
45
|
try {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
46
|
+
const result = await fn();
|
|
47
|
+
if (await shouldRetry(result, undefined, attempt)) {
|
|
48
|
+
if (attempt >= maxAttempts) {
|
|
49
|
+
log(`[${context}] Gave up after ${attempt} attempts.`);
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
log(`[${context}] Retrying... (attempt: ${attempt})`);
|
|
29
53
|
continue;
|
|
30
54
|
}
|
|
31
|
-
|
|
32
|
-
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
const msg = `[${context}] Error: ${(0, shared_1.errorToString)(error)}`;
|
|
59
|
+
if (attempt >= maxAttempts) {
|
|
60
|
+
log(`${msg}, gave up after ${attempt} attempts.`);
|
|
61
|
+
throw error;
|
|
62
|
+
}
|
|
63
|
+
if (!(await shouldRetry(undefined, error, attempt))) {
|
|
64
|
+
log(`${msg}, should not retry (after ${attempt} attempts).`);
|
|
65
|
+
throw error;
|
|
66
|
+
}
|
|
67
|
+
log(`${msg}, retrying... (attempt: ${attempt})`);
|
|
68
|
+
const timeToWait = getTimeToWait({ initialDelay, backoffMultiplier, attempt, maxDelay });
|
|
69
|
+
await (0, sleep_1.sleep)(timeToWait);
|
|
33
70
|
}
|
|
34
71
|
}
|
|
35
|
-
throw new
|
|
72
|
+
throw new metriport_error_1.MetriportError("Unreachable code", undefined, {
|
|
73
|
+
attempt,
|
|
74
|
+
maxAttempts,
|
|
75
|
+
context,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
exports.executeWithRetries = executeWithRetries;
|
|
79
|
+
function defaultGetTimeToWait({ initialDelay, backoffMultiplier, attempt, maxDelay, }) {
|
|
80
|
+
if (backoffMultiplier < 1)
|
|
81
|
+
return initialDelay;
|
|
82
|
+
const temp = Math.min(initialDelay * Math.pow(backoffMultiplier, attempt), maxDelay);
|
|
83
|
+
const timeToWait = temp / 2 + (0, lodash_1.random)(0, temp / 2);
|
|
84
|
+
return timeToWait;
|
|
36
85
|
}
|
|
37
|
-
exports.
|
|
86
|
+
exports.defaultGetTimeToWait = defaultGetTimeToWait;
|
|
38
87
|
/**
|
|
39
|
-
* Executes a function with retries. If the function throws an error, it will retry
|
|
40
|
-
* up to
|
|
41
|
-
* If the function throws an error on the last
|
|
88
|
+
* Executes a function with retries and backoff with jitter. If the function throws an error, it will retry
|
|
89
|
+
* up to maxAttempts-1, waiting between each retry.
|
|
90
|
+
* If the function throws an error on the last attempt, it will return `undefined`.
|
|
42
91
|
* If the function succeeds, it will return the result.
|
|
43
92
|
*
|
|
44
93
|
* @param fn the function to be executed
|
|
45
|
-
* @param
|
|
46
|
-
*
|
|
47
|
-
* @
|
|
48
|
-
* @
|
|
94
|
+
* @param options the options to be used; see `ExecuteWithRetriesOptions` for components and
|
|
95
|
+
* `defaultOptions` for defaults.
|
|
96
|
+
* @returns the result of calling the `fn` function
|
|
97
|
+
* @see https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
|
|
49
98
|
*/
|
|
50
|
-
async function
|
|
99
|
+
async function executeWithRetriesSafe(fn, options) {
|
|
100
|
+
const actualOptions = { ...exports.defaultOptions, ...options };
|
|
101
|
+
const { log } = actualOptions;
|
|
51
102
|
try {
|
|
52
|
-
return await
|
|
103
|
+
return await executeWithRetries(fn, options);
|
|
53
104
|
}
|
|
54
105
|
catch (e) {
|
|
55
|
-
log(`Error
|
|
106
|
+
log(`[executeWithRetriesSafe] Error: ${(0, shared_1.errorToString)(e)}`);
|
|
56
107
|
return undefined;
|
|
57
108
|
}
|
|
58
109
|
}
|
|
59
|
-
exports.
|
|
110
|
+
exports.executeWithRetriesSafe = executeWithRetriesSafe;
|
|
60
111
|
//# sourceMappingURL=retry.js.map
|
package/dist/common/retry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/common/retry.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../../src/common/retry.ts"],"names":[],"mappings":";;;AAAA,mCAAgC;AAChC,8DAA0D;AAC1D,4CAAgD;AAChD,mCAAgC;AAEhC,SAAS,kBAAkB,CAAI,CAAgB,EAAE,KAAc;IAC7D,IAAI,KAAK;QAAE,OAAO,IAAI,CAAC;IACvB,OAAO,KAAK,CAAC;AACf,CAAC;AAEY,QAAA,cAAc,GAAiD;IAC1E,YAAY,EAAE,EAAE;IAChB,QAAQ,EAAE,QAAQ;IAClB,iBAAiB,EAAE,CAAC;IACpB,WAAW,EAAE,EAAE;IACf,WAAW,EAAE,kBAAkB;IAC/B,aAAa,EAAE,oBAAoB;IACnC,GAAG,EAAE,OAAO,CAAC,G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AAE,CAAC,CAAC;QAC3D,OAAO,SAAS,CAAC;KAClB;AACH,CAAC;AAZD,wDAYC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
3
|
+
import * as stream from "stream";
|
|
4
|
+
export declare function streamToBuffer(stream: stream.Readable): Promise<Buffer>;
|
|
5
|
+
export declare function streamToString(stream: stream.Readable): Promise<String>;
|
|
6
|
+
//# sourceMappingURL=stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/common/stream.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAO7E;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,CAG7E"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.streamToString = exports.streamToBuffer = void 0;
|
|
4
|
+
async function streamToBuffer(stream) {
|
|
5
|
+
const buffer = Array();
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
stream.on("data", chunk => buffer.push(Buffer.from(chunk)));
|
|
8
|
+
stream.on("error", err => reject(err));
|
|
9
|
+
stream.on("end", () => resolve(Buffer.concat(buffer)));
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
exports.streamToBuffer = streamToBuffer;
|
|
13
|
+
async function streamToString(stream) {
|
|
14
|
+
const buffer = await streamToBuffer(stream);
|
|
15
|
+
return buffer.toString();
|
|
16
|
+
}
|
|
17
|
+
exports.streamToString = streamToString;
|
|
18
|
+
//# sourceMappingURL=stream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/common/stream.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,cAAc,CAAC,MAAuB;IAC1D,MAAM,MAAM,GAAG,KAAK,EAAO,CAAC;IAC5B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC5D,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QACvC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACzD,CAAC,CAAC,CAAC;AACL,CAAC;AAPD,wCAOC;AAEM,KAAK,UAAU,cAAc,CAAC,MAAuB;IAC1D,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAHD,wCAGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.d.ts","sourceRoot":"","sources":["../../src/common/uuid.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,QAAmB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uuid.js","sourceRoot":"","sources":["../../src/common/uuid.ts"],"names":[],"mappings":";;;AAAa,QAAA,SAAS,GAAG,gBAAgB,CAAC"}
|
package/dist/error/shared.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type ErrorToStringOptions = {
|
|
|
2
2
|
detailed: boolean;
|
|
3
3
|
};
|
|
4
4
|
export declare function errorToString(err: unknown, options?: ErrorToStringOptions): string;
|
|
5
|
-
export declare function genericErrorToString(err:
|
|
5
|
+
export declare function genericErrorToString(err: any): string;
|
|
6
6
|
export declare function detailedErrorToString(err: any): string;
|
|
7
7
|
export declare function getErrorMessage(error: unknown): string;
|
|
8
8
|
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/error/shared.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,GAAG;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzD,wBAAgB,aAAa,CAC3B,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE,oBAAyC,GACjD,MAAM,CAKR;
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/error/shared.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,oBAAoB,GAAG;IAAE,QAAQ,EAAE,OAAO,CAAA;CAAE,CAAC;AAEzD,wBAAgB,aAAa,CAC3B,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE,oBAAyC,GACjD,MAAM,CAKR;AAGD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAOrD;AAGD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM,CAYtD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,UAE7C"}
|
package/dist/error/shared.js
CHANGED
|
@@ -9,13 +9,18 @@ function errorToString(err, options = { detailed: true }) {
|
|
|
9
9
|
return genericErrorToString(err);
|
|
10
10
|
}
|
|
11
11
|
exports.errorToString = errorToString;
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
13
|
function genericErrorToString(err) {
|
|
13
|
-
|
|
14
|
+
const msg = "message" in err ? err.message : String(err);
|
|
15
|
+
const code = "code" in err ? err.code : undefined;
|
|
16
|
+
const status = "response" in err ? err.response.status : undefined;
|
|
17
|
+
const suffix = code && status ? ` (${code} - ${status})` : code || status ? ` (${code ?? status})` : "";
|
|
18
|
+
return msg + suffix;
|
|
14
19
|
}
|
|
15
20
|
exports.genericErrorToString = genericErrorToString;
|
|
16
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
22
|
function detailedErrorToString(err) {
|
|
18
|
-
const thisErrorMessage = err
|
|
23
|
+
const thisErrorMessage = genericErrorToString(err);
|
|
19
24
|
// this can lead to multi-line
|
|
20
25
|
const additionalInfo = err.additionalInfo
|
|
21
26
|
? (0, node_util_1.inspect)(err.additionalInfo, { compact: true, breakLength: undefined })
|
package/dist/error/shared.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/error/shared.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAIpC,SAAgB,aAAa,CAC3B,GAAY,EACZ,UAAgC,EAAE,QAAQ,EAAE,IAAI,EAAE;IAElD,IAAI,OAAO,CAAC,QAAQ,EAAE;QACpB,OAAO,qBAAqB,CAAC,GAAG,CAAC,CAAC;KACnC;IACD,OAAO,oBAAoB,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AARD,sCAQC;AAED,SAAgB,oBAAoB,CAAC,
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/error/shared.ts"],"names":[],"mappings":";;;AAAA,yCAAoC;AAIpC,SAAgB,aAAa,CAC3B,GAAY,EACZ,UAAgC,EAAE,QAAQ,EAAE,IAAI,EAAE;IAElD,IAAI,OAAO,CAAC,QAAQ,EAAE;QACpB,OAAO,qBAAqB,CAAC,GAAG,CAAC,CAAC;KACnC;IACD,OAAO,oBAAoB,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AARD,sCAQC;AAED,8DAA8D;AAC9D,SAAgB,oBAAoB,CAAC,GAAQ;IAC3C,MAAM,GAAG,GAAG,SAAS,IAAI,GAAG,CAAC,CAA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AC;AACJ,CAAC;AAZD,sDAYC;AAED,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAFD,0CAEC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { isValidUrl } from "./common/net";
|
|
|
9
9
|
export { normalizeOid } from "./common/normalize-oid";
|
|
10
10
|
export { normalizeZipCode } from "./common/normalize-zip";
|
|
11
11
|
export { PurposeOfUse } from "./common/purpose-of-use";
|
|
12
|
-
export
|
|
12
|
+
export * from "./common/retry";
|
|
13
13
|
export { sleep } from "./common/sleep";
|
|
14
14
|
export { limitStringLength } from "./common/string";
|
|
15
15
|
export { AtLeastOne, stringToBoolean } from "./common/types";
|
|
@@ -21,5 +21,7 @@ export { NotFoundError } from "./error/not-found";
|
|
|
21
21
|
export { errorToString } from "./error/shared";
|
|
22
22
|
export * as medical from "./medical";
|
|
23
23
|
export * from "./net/file-downloader";
|
|
24
|
+
export * from "./net/retry";
|
|
24
25
|
export * from "./net/url";
|
|
26
|
+
export * from "./net/error";
|
|
25
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,4BAA4B,EAAE,MAAM,gBAAgB,CAAC;AAC9D,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AA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,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,OAAO,MAAM,WAAW,CAAC;AACrC,cAAc,uBAAuB,CAAC;AACtC,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.medical = exports.errorToString = exports.NotFoundError = exports.MetriportError = exports.BadRequestError = exports.metriportCompanyDetails = exports.validateNPI = exports.stringToBoolean = exports.limitStringLength = exports.sleep = exports.
|
|
29
|
+
exports.medical = exports.errorToString = exports.NotFoundError = exports.MetriportError = exports.BadRequestError = exports.metriportCompanyDetails = exports.validateNPI = exports.stringToBoolean = exports.limitStringLength = exports.sleep = exports.PurposeOfUse = exports.normalizeZipCode = exports.normalizeOid = exports.isValidUrl = exports.metriportOrganization = exports.emptyFunction = exports.getDomainFromEmailWithoutTld = exports.optionalDateSchema = exports.dateSchema = exports.isTrue = exports.toArray = void 0;
|
|
30
30
|
var array_1 = require("./common/array");
|
|
31
31
|
Object.defineProperty(exports, "toArray", { enumerable: true, get: function () { return array_1.toArray; } });
|
|
32
32
|
var boolean_1 = require("./common/boolean");
|
|
@@ -49,9 +49,7 @@ var normalize_zip_1 = require("./common/normalize-zip");
|
|
|
49
49
|
Object.defineProperty(exports, "normalizeZipCode", { enumerable: true, get: function () { return normalize_zip_1.normalizeZipCode; } });
|
|
50
50
|
var purpose_of_use_1 = require("./common/purpose-of-use");
|
|
51
51
|
Object.defineProperty(exports, "PurposeOfUse", { enumerable: true, get: function () { return purpose_of_use_1.PurposeOfUse; } });
|
|
52
|
-
|
|
53
|
-
Object.defineProperty(exports, "executeWithRetries", { enumerable: true, get: function () { return retry_1.executeWithRetries; } });
|
|
54
|
-
Object.defineProperty(exports, "executeWithRetriesOrFail", { enumerable: true, get: function () { return retry_1.executeWithRetriesOrFail; } });
|
|
52
|
+
__exportStar(require("./common/retry"), exports);
|
|
55
53
|
var sleep_1 = require("./common/sleep");
|
|
56
54
|
Object.defineProperty(exports, "sleep", { enumerable: true, get: function () { return sleep_1.sleep; } });
|
|
57
55
|
var string_1 = require("./common/string");
|
|
@@ -72,5 +70,7 @@ var shared_1 = require("./error/shared");
|
|
|
72
70
|
Object.defineProperty(exports, "errorToString", { enumerable: true, get: function () { return shared_1.errorToString; } });
|
|
73
71
|
exports.medical = __importStar(require("./medical"));
|
|
74
72
|
__exportStar(require("./net/file-downloader"), exports);
|
|
73
|
+
__exportStar(require("./net/retry"), exports);
|
|
75
74
|
__exportStar(require("./net/url"), exports);
|
|
75
|
+
__exportStar(require("./net/error"), exports);
|
|
76
76
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAyC;AAAhC,gGAAA,OAAO,OAAA;AAChB,4CAA0C;AAAjC,iGAAA,MAAM,OAAA;AACf,sCAA+D;AAAtD,kGAAA,UAAU,OAAA;AAAE,0GAAA,kBAAkB,OAAA;AACvC,wCAA8D;AAArD,qHAAA,4BAA4B,OAAA;AACrC,mDAAiC;AACjC,4CAAiD;AAAxC,wGAAA,aAAa,OAAA;AACtB,0EAAwE;AAA/D,+HAAA,qBAAqB,OAAA;AAC9B,oCAA0C;AAAjC,iGAAA,UAAU,OAAA;AACnB,wDAAsD;AAA7C,6GAAA,YAAY,OAAA;AACrB,wDAA0D;AAAjD,iHAAA,gBAAgB,OAAA;AACzB,0DAAuD;AAA9C,8GAAA,YAAY,OAAA;AACrB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wCAAyC;AAAhC,gGAAA,OAAO,OAAA;AAChB,4CAA0C;AAAjC,iGAAA,MAAM,OAAA;AACf,sCAA+D;AAAtD,kGAAA,UAAU,OAAA;AAAE,0GAAA,kBAAkB,OAAA;AACvC,wCAA8D;AAArD,qHAAA,4BAA4B,OAAA;AACrC,mDAAiC;AACjC,4CAAiD;AAAxC,wGAAA,aAAa,OAAA;AACtB,0EAAwE;AAA/D,+HAAA,qBAAqB,OAAA;AAC9B,oCAA0C;AAAjC,iGAAA,UAAU,OAAA;AACnB,wDAAsD;AAA7C,6GAAA,YAAY,OAAA;AACrB,wDAA0D;AAAjD,iHAAA,gBAAgB,OAAA;AACzB,0DAAuD;AAA9C,8GAAA,YAAY,OAAA;AACrB,iDAA+B;AAC/B,wCAAuC;AAA9B,8FAAA,KAAK,OAAA;AACd,0CAAoD;AAA3C,2GAAA,iBAAiB,OAAA;AAC1B,wCAA6D;AAAxC,wGAAA,eAAe,OAAA;AACpC,sDAAoD;AAA3C,2GAAA,WAAW,OAAA;AACpB,gDAA6D;AAApD,oHAAA,uBAAuB,OAAA;AAChC,mDAAsD;AAA7C,8GAAA,eAAe,OAAA;AACxB,2DAAyD;AAAhD,iHAAA,cAAc,OAAA;AACvB,+CAAkD;AAAzC,0GAAA,aAAa,OAAA;AACtB,yCAA+C;AAAtC,uGAAA,aAAa,OAAA;AACtB,qDAAqC;AACrC,wDAAsC;AACtC,8CAA4B;AAC5B,4CAA0B;AAC1B,8CAA4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=another.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"another.d.ts","sourceRoot":"","sources":["../../../src/net/__tests__/another.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"another.js","sourceRoot":"","sources":["../../../src/net/__tests__/another.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.test.d.ts","sourceRoot":"","sources":["../../../src/net/__tests__/http.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
4
|
+
const faker_1 = require("@faker-js/faker");
|
|
5
|
+
const axios_1 = require("axios");
|
|
6
|
+
const http_1 = require("../http");
|
|
7
|
+
// describe("executeWithRetries", () => {
|
|
8
|
+
// const fnImpl = async () => {
|
|
9
|
+
// throw new Error("error");
|
|
10
|
+
// };
|
|
11
|
+
// const fn = jest.fn().mockImplementation(fnImpl);
|
|
12
|
+
// it("returns undefined when gets undefined", async () => {
|
|
13
|
+
// await expect(async () =>
|
|
14
|
+
// executeWithRetries(fn, {
|
|
15
|
+
// initialDelay: 10,
|
|
16
|
+
// maxAttempts: 10,
|
|
17
|
+
// })
|
|
18
|
+
// ).rejects.toThrow();
|
|
19
|
+
// expect(fn).toHaveBeenCalledTimes(10);
|
|
20
|
+
// });
|
|
21
|
+
// });
|
|
22
|
+
describe("executeWithHttpRetries", () => {
|
|
23
|
+
const makeFnImplementation = (status) => async () => {
|
|
24
|
+
const error = new axios_1.AxiosError("error");
|
|
25
|
+
const actualStatus = status === undefined ? 500 : status;
|
|
26
|
+
if (actualStatus !== null) {
|
|
27
|
+
error.response = {
|
|
28
|
+
status: actualStatus,
|
|
29
|
+
data: faker_1.faker.lorem.sentence(),
|
|
30
|
+
statusText: faker_1.faker.lorem.sentence(),
|
|
31
|
+
headers: {},
|
|
32
|
+
config: {},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
throw error;
|
|
36
|
+
};
|
|
37
|
+
let fn = jest.fn();
|
|
38
|
+
beforeEach(() => {
|
|
39
|
+
fn.mockImplementation(makeFnImplementation());
|
|
40
|
+
});
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
jest.resetAllMocks();
|
|
43
|
+
});
|
|
44
|
+
// it("returns on first execution when fn does not fail", async () => {
|
|
45
|
+
// const expectedResult = faker.lorem.word();
|
|
46
|
+
// fn.mockImplementationOnce(() => expectedResult);
|
|
47
|
+
// const resp = await executeWithHttpRetries(fn, {
|
|
48
|
+
// initialDelay: 1,
|
|
49
|
+
// maxAttempts: 2,
|
|
50
|
+
// });
|
|
51
|
+
// expect(resp).toEqual(expectedResult);
|
|
52
|
+
// expect(fn).toHaveBeenCalledTimes(1);
|
|
53
|
+
// });
|
|
54
|
+
// it("returns on second execution when fn fails once", async () => {
|
|
55
|
+
// const expectedResult = faker.lorem.word();
|
|
56
|
+
// fn.mockImplementationOnce(makeFnImplementation());
|
|
57
|
+
// fn.mockImplementationOnce(() => expectedResult);
|
|
58
|
+
// const resp = await executeWithHttpRetries(fn, {
|
|
59
|
+
// initialDelay: 1,
|
|
60
|
+
// maxAttempts: 3,
|
|
61
|
+
// });
|
|
62
|
+
// expect(resp).toEqual(expectedResult);
|
|
63
|
+
// expect(fn).toHaveBeenCalledTimes(2);
|
|
64
|
+
// });
|
|
65
|
+
// it("executes until maxAttempts if fn always fails", async () => {
|
|
66
|
+
// await expect(async () =>
|
|
67
|
+
// executeWithHttpRetries(fn, {
|
|
68
|
+
// initialDelay: 1,
|
|
69
|
+
// // maxDelay: 100,
|
|
70
|
+
// // backoffMultiplier: 2,
|
|
71
|
+
// maxAttempts: 5,
|
|
72
|
+
// // httpStatusToRetry: [500],
|
|
73
|
+
// })
|
|
74
|
+
// ).rejects.toThrow();
|
|
75
|
+
// expect(fn).toHaveBeenCalledTimes(5);
|
|
76
|
+
// });
|
|
77
|
+
it("does not retry on 400", async () => {
|
|
78
|
+
fn.mockImplementationOnce(makeFnImplementation(400));
|
|
79
|
+
await expect(async () => (0, http_1.executeWithHttpRetries)(fn, {
|
|
80
|
+
initialDelay: 1,
|
|
81
|
+
maxAttempts: 2,
|
|
82
|
+
})).rejects.toThrow();
|
|
83
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
84
|
+
});
|
|
85
|
+
it("does not retry on 500 when gets array of status without 500", async () => {
|
|
86
|
+
await expect(async () => (0, http_1.executeWithHttpRetries)(fn, {
|
|
87
|
+
initialDelay: 1,
|
|
88
|
+
maxAttempts: 2,
|
|
89
|
+
httpStatusToRetry: [404],
|
|
90
|
+
})).rejects.toThrow();
|
|
91
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
92
|
+
});
|
|
93
|
+
it("retries when AxiosError does not have a response", async () => {
|
|
94
|
+
fn.mockImplementationOnce(makeFnImplementation(null));
|
|
95
|
+
await expect(async () => (0, http_1.executeWithHttpRetries)(fn, {
|
|
96
|
+
initialDelay: 1,
|
|
97
|
+
maxAttempts: 2,
|
|
98
|
+
})).rejects.toThrow();
|
|
99
|
+
expect(fn).toHaveBeenCalledTimes(2);
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
//# sourceMappingURL=http.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.test.js","sourceRoot":"","sources":["../../../src/net/__tests__/http.test.ts"],"names":[],"mappings":";;AAAA,yDAAyD;AACzD,2CAAwC;AACxC,iCAA+D;AAC/D,kCAAqE;AAErE,yCAAyC;AACzC,iCAAiC;AACjC,gCAAgC;AAChC,OAAO;AACP,qDAAqD;AAErD,8DAA8D;AAC9D,+BAA+B;AAC/B,iCAAiC;AACjC,4BAA4B;AAC5B,2BAA2B;AAC3B,WAAW;AACX,2BAA2B;AAC3B,4CAA4C;AAC5C,QAAQ;AACR,MAAM;AAEN,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACtC,MAAM,oBAAoB,GAAG,CAAC,MAAsB,EAAE,EAAE,CAAC,KAAK,IAAI,EAAE;QAClE,MAAM,KAAK,GAAG,IAAI,kBAAU,CAAC,OAAO,CAAC,CAAC;QACtC,MAAM,YAAY,GAAG,MAAM,KAAK,SAAS,CAAC,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