@metriport/shared 0.9.8 → 0.10.0-alpha.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/common/__tests__/retry.test.js +2 -2
- package/dist/common/__tests__/retry.test.js.map +1 -1
- package/dist/common/retry.d.ts +1 -0
- package/dist/common/retry.d.ts.map +1 -1
- package/dist/common/retry.js +8 -2
- package/dist/common/retry.js.map +1 -1
- package/dist/common/string.d.ts +1 -0
- package/dist/common/string.d.ts.map +1 -1
- package/dist/common/string.js +5 -1
- package/dist/common/string.js.map +1 -1
- package/dist/domain/contact/__tests__/phone.test.d.ts +2 -0
- package/dist/domain/contact/__tests__/phone.test.d.ts.map +1 -0
- package/dist/domain/contact/__tests__/phone.test.js +162 -0
- package/dist/domain/contact/__tests__/phone.test.js.map +1 -0
- package/dist/domain/contact/phone.d.ts +19 -0
- package/dist/domain/contact/phone.d.ts.map +1 -0
- package/dist/domain/contact/phone.js +49 -0
- package/dist/domain/contact/phone.js.map +1 -0
- package/dist/index.d.ts +3 -2
- 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__/axios.d.ts +43 -0
- package/dist/net/__tests__/axios.d.ts.map +1 -0
- package/dist/net/__tests__/axios.js +103 -0
- package/dist/net/__tests__/axios.js.map +1 -0
- package/dist/net/__tests__/retry.test.js +246 -147
- package/dist/net/__tests__/retry.test.js.map +1 -1
- package/dist/net/error.d.ts +11 -8
- package/dist/net/error.d.ts.map +1 -1
- package/dist/net/error.js +8 -1
- package/dist/net/error.js.map +1 -1
- package/dist/net/retry.d.ts +2 -0
- package/dist/net/retry.d.ts.map +1 -1
- package/dist/net/retry.js +50 -5
- package/dist/net/retry.js.map +1 -1
- package/package.json +2 -2
- package/dist/common/file-downloader.d.ts +0 -14
- package/dist/common/file-downloader.d.ts.map +0 -1
- package/dist/common/file-downloader.js +0 -63
- package/dist/common/file-downloader.js.map +0 -1
- package/dist/common/http.d.ts +0 -42
- package/dist/common/http.d.ts.map +0 -1
- package/dist/common/http.js +0 -83
- package/dist/common/http.js.map +0 -1
- package/dist/common/retry-with-backoff.d.ts +0 -27
- package/dist/common/retry-with-backoff.d.ts.map +0 -1
- package/dist/common/retry-with-backoff.js +0 -47
- package/dist/common/retry-with-backoff.js.map +0 -1
- package/dist/common/stream.d.ts +0 -6
- package/dist/common/stream.d.ts.map +0 -1
- package/dist/common/stream.js +0 -18
- package/dist/common/stream.js.map +0 -1
- package/dist/common/uuid.d.ts +0 -2
- package/dist/common/uuid.d.ts.map +0 -1
- package/dist/common/uuid.js +0 -5
- package/dist/common/uuid.js.map +0 -1
- package/dist/net/__tests__/another.d.ts +0 -1
- package/dist/net/__tests__/another.d.ts.map +0 -1
- package/dist/net/__tests__/another.js +0 -2
- package/dist/net/__tests__/another.js.map +0 -1
- package/dist/net/__tests__/http.test.d.ts +0 -2
- package/dist/net/__tests__/http.test.d.ts.map +0 -1
- package/dist/net/__tests__/http.test.js +0 -102
- package/dist/net/__tests__/http.test.js.map +0 -1
- package/dist/net/net.d.ts +0 -2
- package/dist/net/net.d.ts.map +0 -1
- package/dist/net/net.js +0 -16
- package/dist/net/net.js.map +0 -1
- package/dist/net/retry-with-backoff.d.ts +0 -42
- package/dist/net/retry-with-backoff.d.ts.map +0 -1
- package/dist/net/retry-with-backoff.js +0 -83
- package/dist/net/retry-with-backoff.js.map +0 -1
- package/dist/net/stream.d.ts +0 -6
- package/dist/net/stream.d.ts.map +0 -1
- package/dist/net/stream.js +0 -18
- package/dist/net/stream.js.map +0 -1
package/dist/net/net.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"net.d.ts","sourceRoot":"","sources":["../../src/net/net.ts"],"names":[],"mappings":"AAAA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAQ3D"}
|
package/dist/net/net.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidUrl = void 0;
|
|
4
|
-
function isValidUrl(url) {
|
|
5
|
-
if (!url)
|
|
6
|
-
return false;
|
|
7
|
-
try {
|
|
8
|
-
new URL(url);
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
catch (e) {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
exports.isValidUrl = isValidUrl;
|
|
16
|
-
//# sourceMappingURL=net.js.map
|
package/dist/net/net.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"net.js","sourceRoot":"","sources":["../../src/net/net.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU,CAAC,GAAuB;IAChD,IAAI,CAAC,GAAG;QAAE,OAAO,KAAK,CAAC;IACvB,IAAI;QACF,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;QACb,OAAO,IAAI,CAAC;KACb;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AARD,gCAQC"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export type ExecuteWithRetriesOptions = {
|
|
2
|
-
/** The intitial delay in milliseconds. Defaults to 100ms. */
|
|
3
|
-
initialDelay: number;
|
|
4
|
-
/** The maximum delay in milliseconds, optional. Defaults to Infinity. */
|
|
5
|
-
maxDelay: number;
|
|
6
|
-
/**
|
|
7
|
-
* Determines how the backoff is determined.
|
|
8
|
-
* It's unlikely that you would change that.
|
|
9
|
-
* Defaults to 2 (each retry waits double of what the previous one did).
|
|
10
|
-
*/
|
|
11
|
-
backoffMultiplier: number;
|
|
12
|
-
/** The maximum number of retries. Defaults to 10. */
|
|
13
|
-
maxAttempts: number;
|
|
14
|
-
shouldRetry: (error: unknown, attempt: number) => boolean | Promise<boolean>;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* TODO WIP
|
|
18
|
-
* TODO WIP
|
|
19
|
-
* TODO WIP
|
|
20
|
-
* TODO WIP
|
|
21
|
-
*
|
|
22
|
-
* @param fn
|
|
23
|
-
* @param options
|
|
24
|
-
* @returns
|
|
25
|
-
*/
|
|
26
|
-
export declare function executeWithRetries<T>(fn: () => Promise<T>, options?: Partial<ExecuteWithRetriesOptions>): Promise<T>;
|
|
27
|
-
export type ExecuteWithHttpRetriesOptions = ExecuteWithRetriesOptions & {
|
|
28
|
-
/** The HTTP status codes to retry. See `defaultOptions` for defaults. */
|
|
29
|
-
httpStatusToRetry: number[];
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* TODO WIP
|
|
33
|
-
* TODO WIP
|
|
34
|
-
* TODO WIP
|
|
35
|
-
* TODO WIP
|
|
36
|
-
*
|
|
37
|
-
* @param fn
|
|
38
|
-
* @param options
|
|
39
|
-
* @returns
|
|
40
|
-
*/
|
|
41
|
-
export declare function executeWithHttpRetries<T>(fn: () => Promise<T>, options?: Partial<ExecuteWithHttpRetriesOptions>): Promise<T>;
|
|
42
|
-
//# sourceMappingURL=retry-with-backoff.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retry-with-backoff.d.ts","sourceRoot":"","sources":["../../src/net/retry-with-backoff.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,yBAAyB,GAAG;IACtC,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,yEAAyE;IACzE,QAAQ,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qDAAqD;IACrD,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,KAAK,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC9E,CAAC;AAUF;;;;;;;;;GASG;AACH,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,GAAE,OAAO,CAAC,yBAAyB,CAAkB,GAC3D,OAAO,CAAC,CAAC,CAAC,CA2BZ;AAED,MAAM,MAAM,6BAA6B,GAAG,yBAAyB,GAAG;IACtE,yEAAyE;IACzE,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B,CAAC;AAYF;;;;;;;;;GASG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,EAC5C,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,GAAE,OAAO,CAAC,6BAA6B,CAAkB,GAC/D,OAAO,CAAC,CAAC,CAAC,CAWZ"}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.executeWithHttpRetries = exports.executeWithRetries = void 0;
|
|
7
|
-
const shared_1 = require("@metriport/shared");
|
|
8
|
-
const axios_1 = __importDefault(require("axios"));
|
|
9
|
-
const http_status_1 = __importDefault(require("http-status"));
|
|
10
|
-
const lodash_1 = require("lodash");
|
|
11
|
-
const defaultOptions = {
|
|
12
|
-
initialDelay: 100,
|
|
13
|
-
maxDelay: Infinity,
|
|
14
|
-
backoffMultiplier: 2,
|
|
15
|
-
maxAttempts: 10,
|
|
16
|
-
shouldRetry: (_error, _attempt) => true,
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* TODO WIP
|
|
20
|
-
* TODO WIP
|
|
21
|
-
* TODO WIP
|
|
22
|
-
* TODO WIP
|
|
23
|
-
*
|
|
24
|
-
* @param fn
|
|
25
|
-
* @param options
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
async function executeWithRetries(fn, options = defaultOptions) {
|
|
29
|
-
const actualOptions = { ...defaultOptions, ...options };
|
|
30
|
-
const { initialDelay, maxDelay, backoffMultiplier, maxAttempts: _maxAttempts, shouldRetry, } = actualOptions;
|
|
31
|
-
const maxAttempts = Math.max(_maxAttempts, 1);
|
|
32
|
-
let attempt = 0;
|
|
33
|
-
while (++attempt <= maxAttempts + 1) {
|
|
34
|
-
try {
|
|
35
|
-
return await fn();
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
if (attempt >= maxAttempts) {
|
|
39
|
-
throw error;
|
|
40
|
-
}
|
|
41
|
-
if (!(await shouldRetry(error, attempt))) {
|
|
42
|
-
throw error;
|
|
43
|
-
}
|
|
44
|
-
const temp = Math.min(initialDelay * backoffMultiplier * attempt, maxDelay);
|
|
45
|
-
const timeToWait = temp / 2 + (0, lodash_1.random)(0, temp / 2);
|
|
46
|
-
await (0, shared_1.sleep)(timeToWait);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
throw new shared_1.MetriportError("Unreachable code", undefined, { attempt, maxRetries: maxAttempts });
|
|
50
|
-
}
|
|
51
|
-
exports.executeWithRetries = executeWithRetries;
|
|
52
|
-
const defaultHttpRetryOptions = {
|
|
53
|
-
...defaultOptions,
|
|
54
|
-
httpStatusToRetry: [
|
|
55
|
-
http_status_1.default.INTERNAL_SERVER_ERROR,
|
|
56
|
-
http_status_1.default.BAD_GATEWAY,
|
|
57
|
-
http_status_1.default.SERVICE_UNAVAILABLE,
|
|
58
|
-
http_status_1.default.GATEWAY_TIMEOUT,
|
|
59
|
-
],
|
|
60
|
-
};
|
|
61
|
-
/**
|
|
62
|
-
* TODO WIP
|
|
63
|
-
* TODO WIP
|
|
64
|
-
* TODO WIP
|
|
65
|
-
* TODO WIP
|
|
66
|
-
*
|
|
67
|
-
* @param fn
|
|
68
|
-
* @param options
|
|
69
|
-
* @returns
|
|
70
|
-
*/
|
|
71
|
-
async function executeWithHttpRetries(fn, options = defaultOptions) {
|
|
72
|
-
const actualOptions = { ...defaultHttpRetryOptions, ...options };
|
|
73
|
-
const { httpStatusToRetry } = actualOptions;
|
|
74
|
-
return executeWithRetries(fn, {
|
|
75
|
-
...actualOptions,
|
|
76
|
-
shouldRetry: (error, _attempt) => {
|
|
77
|
-
const responseStatus = axios_1.default.isAxiosError(error) && error.response?.status ? error.response.status : 500;
|
|
78
|
-
return httpStatusToRetry.includes(responseStatus);
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
exports.executeWithHttpRetries = executeWithHttpRetries;
|
|
83
|
-
//# sourceMappingURL=retry-with-backoff.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retry-with-backoff.js","sourceRoot":"","sources":["../../src/net/retry-with-backoff.ts"],"names":[],"mappings":";;;;;;AAAA,8CAA0D;AAC1D,kDAA0B;AAC1B,8DAAqC;AACrC,mCAAgC;AAkBhC,MAAM,cAAc,GAA8B;IAChD,YAAY,EAAE,GAAG;IACjB,QAAQ,EAAE,QAAQ;IAClB,iBAAiB,EAAE,CAAC;IACpB,WAAW,EAAE,EAAE;IACf,WAAW,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,CAAC,IAAI;CACxC,CAAC;AAEF;;;;;;;;;GASG;AACI,KAAK,UAAU,kBAAkB,CACtC,EAAoB,EACpB,UAA8C,cAAc;IAE5D,MAAM,aAAa,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC;IACxD,MAAM,EACJ,YAAY,EACZ,QAAQ,EACR,iBAAiB,EACjB,WAAW,EAAE,YAAY,EACzB,WAAW,GACZ,GAAG,aAAa,CAAC;IAClB,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC;IAC9C,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,OAAO,EAAE,OAAO,IAAI,WAAW,GAAG,CAAC,EAAE;QACnC,IAAI;YACF,OAAO,MAAM,EAAE,EAAE,CAAC;SACnB;QAAC,OAA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K,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;YACpF,OAAO,iBAAiB,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;QACpD,CAAC;KACF,CAAC,CAAC;AACL,CAAC;AAdD,wDAcC"}
|
package/dist/net/stream.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
import * as stream from "stream";
|
|
4
|
-
export declare function streamToBuffer(stream: stream.Stream): Promise<Buffer>;
|
|
5
|
-
export declare function streamToString(stream: stream.Stream): Promise<String>;
|
|
6
|
-
//# sourceMappingURL=stream.d.ts.map
|
package/dist/net/stream.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../src/net/stream.ts"],"names":[],"mappings":";;AAAA,OAAO,KAAK,MAAM,MAAM,QAAQ,CAAC;AAEjC,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAO3E;AAED,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG3E"}
|
package/dist/net/stream.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.streamToString = exports.streamToBuffer = void 0;
|
|
4
|
-
async function streamToBuffer(stream) {
|
|
5
|
-
const buffers = Array();
|
|
6
|
-
return new Promise((resolve, reject) => {
|
|
7
|
-
stream.on("data", chunk => buffers.push(Buffer.from(chunk)));
|
|
8
|
-
stream.on("error", err => reject(err));
|
|
9
|
-
stream.on("end", () => resolve(Buffer.concat(buffers)));
|
|
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
|
package/dist/net/stream.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream.js","sourceRoot":"","sources":["../../src/net/stream.ts"],"names":[],"mappings":";;;AAEO,KAAK,UAAU,cAAc,CAAC,MAAqB;IACxD,MAAM,OAAO,GAAG,KAAK,EAAO,CAAC;IAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QAC7D,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,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACL,CAAC;AAPD,wCAOC;AAEM,KAAK,UAAU,cAAc,CAAC,MAAqB;IACxD,MAAM,MAAM,GAAG,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC;IAC5C,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC3B,CAAC;AAHD,wCAGC"}
|