@metriport/shared 0.9.8 → 0.9.9
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__/demographics.test.d.ts +2 -0
- package/dist/domain/contact/__tests__/demographics.test.d.ts.map +1 -0
- package/dist/domain/contact/__tests__/demographics.test.js +46 -0
- package/dist/domain/contact/__tests__/demographics.test.js.map +1 -0
- 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
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.errorWithCauseAxiosError = exports.makeAxiosResponse = exports.mockAxios = void 0;
|
|
27
|
+
const axios_1 = __importStar(require("axios"));
|
|
28
|
+
jest.mock("axios");
|
|
29
|
+
function mockAxios() {
|
|
30
|
+
const mockedAxios = jest.mocked(axios_1.default);
|
|
31
|
+
return {
|
|
32
|
+
axios: mockedAxios.mockImplementation(),
|
|
33
|
+
get: mockedAxios.get.mockImplementation(),
|
|
34
|
+
post: mockedAxios.post.mockImplementation(),
|
|
35
|
+
put: mockedAxios.put.mockImplementation(),
|
|
36
|
+
delete: mockedAxios.delete.mockImplementation(),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
exports.mockAxios = mockAxios;
|
|
40
|
+
function makeAxiosResponse({ method, status, data, statusText, headers, config, }) {
|
|
41
|
+
return {
|
|
42
|
+
status: status ?? 200,
|
|
43
|
+
data: data ?? {},
|
|
44
|
+
statusText: statusText ?? "OK",
|
|
45
|
+
headers: headers ?? {},
|
|
46
|
+
config: config ?? {
|
|
47
|
+
headers: new axios_1.AxiosHeaders(),
|
|
48
|
+
method: method ?? "get",
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
exports.makeAxiosResponse = makeAxiosResponse;
|
|
53
|
+
exports.errorWithCauseAxiosError = {
|
|
54
|
+
errorType: "Error",
|
|
55
|
+
errorMessage: "CW - Error downloading document",
|
|
56
|
+
cause: {
|
|
57
|
+
errorType: "Error",
|
|
58
|
+
errorMessage: "Error retrieve document",
|
|
59
|
+
cause: {
|
|
60
|
+
message: "connect ETIMEDOUT 107.21.162.233:443",
|
|
61
|
+
name: "Error",
|
|
62
|
+
stack: "Error: connect ETIMEDOUT 107.21.162.233:443...",
|
|
63
|
+
code: "ETIMEDOUT",
|
|
64
|
+
status: null,
|
|
65
|
+
isAxiosError: true,
|
|
66
|
+
},
|
|
67
|
+
additionalInfo: {
|
|
68
|
+
headers: {
|
|
69
|
+
Authorization: "Bearer ...",
|
|
70
|
+
},
|
|
71
|
+
inputUrl: "https://rest.api.commonwellalliance.org/v2/Binary/xxxxxx",
|
|
72
|
+
outputStream: "[object]",
|
|
73
|
+
},
|
|
74
|
+
stack: [
|
|
75
|
+
"Error: Error retrieve document",
|
|
76
|
+
" at Object.retrieve (/opt/nodejs/node_modules/@metriport/commonwell-sdk/dist/client/document.js:64:15)",
|
|
77
|
+
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
|
|
78
|
+
" at async executeWithRetries (/opt/nodejs/node_modules/@metriport/shared/dist/common/retry.js:46:28)",
|
|
79
|
+
" at async DocumentDownloaderLocal.downloadDocumentFromCW (/opt/nodejs/node_modules/@metriport/core/dist/external/commonwell/document/document-downloader-local.js:225:13)",
|
|
80
|
+
" at async DocumentDownloaderLocal.downloadFromCommonwellIntoS3 (/opt/nodejs/node_modules/@metriport/core/dist/external/commonwell/document/document-downloader-local.js:188:9)",
|
|
81
|
+
" at async executeWithRetries (/opt/nodejs/node_modules/@metriport/shared/dist/common/retry.js:46:28)",
|
|
82
|
+
" at async DocumentDownloaderLocal.download (/opt/nodejs/node_modules/@metriport/core/dist/external/commonwell/document/document-downloader-local.js:58:30)",
|
|
83
|
+
" at async /var/task/document-downloader.js:79:20",
|
|
84
|
+
" at async Runtime.handler (/opt/nodejs/node_modules/@sentry/serverless/cjs/awslambda.js:280:12)",
|
|
85
|
+
],
|
|
86
|
+
},
|
|
87
|
+
additionalInfo: {
|
|
88
|
+
documentLocation: "https://rest.api.commonwellalliance.org/v2/Binary/xxxxxx",
|
|
89
|
+
details: "Error retrieve document ({ headers: { Authorization: 'Bearer ...' }, inputUrl: 'https://rest.api.commonwellalliance.org/v2/Binary/xxxxxx', outputStream: '[object]' }); caused by connect ETIMEDOUT 107.21.162.233:443 (ETIMEDOUT); caused by connect ETIMEDOUT 107.21.162.233:443 (ETIMEDOUT)",
|
|
90
|
+
},
|
|
91
|
+
status: 500,
|
|
92
|
+
stack: [
|
|
93
|
+
"Error: CW - Error downloading document",
|
|
94
|
+
" at DocumentDownloaderLocal.downloadDocumentFromCW (/opt/nodejs/node_modules/@metriport/core/dist/external/commonwell/document/document-downloader-local.js:244:19)",
|
|
95
|
+
" at process.processTicksAndRejections (node:internal/process/task_queues:95:5)",
|
|
96
|
+
" at async DocumentDownloaderLocal.downloadFromCommonwellIntoS3 (/opt/nodejs/node_modules/@metriport/core/dist/external/commonwell/document/document-downloader-local.js:188:9)",
|
|
97
|
+
" at async executeWithRetries (/opt/nodejs/node_modules/@metriport/shared/dist/common/retry.js:46:28)",
|
|
98
|
+
" at async DocumentDownloaderLocal.download (/opt/nodejs/node_modules/@metriport/core/dist/external/commonwell/document/document-downloader-local.js:58:30)",
|
|
99
|
+
" at async /var/task/document-downloader.js:79:20",
|
|
100
|
+
" at async Runtime.handler (/opt/nodejs/node_modules/@sentry/serverless/cjs/awslambda.js:280:12)",
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
//# sourceMappingURL=axios.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"axios.js","sourceRoot":"","sources":["../../../src/net/__tests__/axios.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA2D;AAC3D,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAEnB,SAAgB,SAAS;IACvB,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,eAAK,CAAC,CAAC;IACvC,OAAO;QACL,KAAK,EAAE,WAAW,CAAC,kBAAkB,EAAE;QACvC,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,kBAAkB,EAAE;QACzC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,kBAAkB,EAAE;QAC3C,GAAG,EAAE,WAAW,CAAC,GAAG,CAAC,kBAAkB,EAAE;QACzC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,kBAAkB,EAAE;KAChD,CAAC;AACJ,CAAC;AATD,8BASC;AAED,SAAgB,iBAAiB,CAAC,EAChC,MAAM,EACN,MAAM,EACN,IAAI,EACJ,UAAU,EACV,OAAO,EACP,MAAM,GAGP;IACC,OAAO;QACL,MAAM,EAAE,MAAM,IAAI,GAAG;QACrB,IAAI,EAAE,IAAI,IAAI,EAAE;QAChB,UAAU,EAAE,UAAU,IAAI,IAAI;QAC9B,OAAO,EAAE,OAAO,IAAI,EAAE;QACtB,MAAM,EAAE,MAAM,IAAI;YAChB,OAAO,EAAE,IAAI,oBAAY,EAAE;YAC3B,MAAM,EAAE,MAAM,IAAI,KAAK;SACxB;KACF,CAAC;AACJ,CAAC;AApBD,8CAoBC;AAEY,QAAA,wBAAwB,GAAG;IACtC,SAAS,EAAE,OAAO;IAClB,YAAY,EAAE,iCAAiC;IAC/C,KAAK,EAAE;QACL,SAAS,EAAE,OAAO;QAClB,YAAY,EAAE,yBAAyB;QACvC,KAAK,EAAE;YACL,OAAO,EAAE,sCAAsC;YAC/C,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,gDAAgD;YACvD,IAAI,EAAE,WAAW;YACjB,MAAM,EAAE,IAAI;YACZ,YAAY,EAAE,IAAI;SACnB;QACD,cAAc,EAAE;YACd,OAAO,EAAE;gBACP,aAAa,EAAE,YAAY;aAC5B;YACD,QAAQ,EAAE,0DAA0D;YACpE,YAAY,EAAE,UAAU;SACzB;QACD,KAAK,EAAE;YACL,gCAAgC;YAChC,2GAA2G;YAC3G,mFAAmF;YACnF,yGAAyG;YACzG,8KAA8K;YAC9K,mLAAmL;YACnL,yGAAyG;YACzG,+JAA+J;YAC/J,qDAAqD;YACrD,oGAAoG;SACrG;KACF;IACD,cAAc,EAAE;QACd,gBAAgB,EAAE,0DAA0D;QAC5E,OAAO,EACL,gSAAgS;KACnS;IACD,MAAM,EAAE,GAAG;IACX,KAAK,EAAE;QACL,wCAAwC;QACxC,wKAAwK;QACxK,mFAAmF;QACnF,mLAAmL;QACnL,yGAAyG;QACzG,+JAA+J;QAC/J,qDAAqD;QACrD,oGAAoG;KACrG;CACF,CAAC"}
|
|
@@ -1,158 +1,257 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
4
27
|
const faker_1 = require("@faker-js/faker");
|
|
5
28
|
const axios_1 = require("axios");
|
|
29
|
+
const retry = __importStar(require("../../common/retry"));
|
|
30
|
+
const metriport_error_1 = require("../../error/metriport-error");
|
|
6
31
|
const retry_1 = require("../retry");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
jest.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
32
|
+
const axios_2 = require("./axios");
|
|
33
|
+
describe("net retry", () => {
|
|
34
|
+
describe("executeWithNetworkRetries", () => {
|
|
35
|
+
const fn = jest.fn();
|
|
36
|
+
afterEach(() => {
|
|
37
|
+
jest.resetAllMocks();
|
|
38
|
+
});
|
|
39
|
+
it("returns when no error", async () => {
|
|
40
|
+
const expectedResult = faker_1.faker.lorem.word();
|
|
41
|
+
fn.mockImplementation(() => expectedResult);
|
|
42
|
+
const resp = await (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
43
|
+
initialDelay: 1,
|
|
44
|
+
maxAttempts: 2,
|
|
45
|
+
});
|
|
46
|
+
expect(resp).toEqual(expectedResult);
|
|
47
|
+
});
|
|
48
|
+
it("retries on ECONNREFUSED", async () => {
|
|
49
|
+
fn.mockImplementation(() => {
|
|
50
|
+
const error = new axios_1.AxiosError("mock error");
|
|
51
|
+
error.code = "ECONNREFUSED";
|
|
52
|
+
throw error;
|
|
53
|
+
});
|
|
54
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
55
|
+
initialDelay: 1,
|
|
56
|
+
maxAttempts: 2,
|
|
57
|
+
})).rejects.toThrow();
|
|
58
|
+
expect(fn).toHaveBeenCalledTimes(2);
|
|
59
|
+
});
|
|
60
|
+
it("retries on ECONNRESET", async () => {
|
|
61
|
+
fn.mockImplementation(() => {
|
|
62
|
+
const error = new axios_1.AxiosError("mock error");
|
|
63
|
+
error.code = "ECONNRESET";
|
|
64
|
+
throw error;
|
|
65
|
+
});
|
|
66
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
67
|
+
initialDelay: 1,
|
|
68
|
+
maxAttempts: 2,
|
|
69
|
+
})).rejects.toThrow();
|
|
70
|
+
expect(fn).toHaveBeenCalledTimes(2);
|
|
71
|
+
});
|
|
72
|
+
it("does not retry on AxiosError.ETIMEDOUT", async () => {
|
|
73
|
+
fn.mockImplementation(() => {
|
|
74
|
+
const error = new axios_1.AxiosError("mock error");
|
|
75
|
+
error.code = "ETIMEDOUT";
|
|
76
|
+
throw error;
|
|
77
|
+
});
|
|
78
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
79
|
+
initialDelay: 1,
|
|
80
|
+
maxAttempts: 2,
|
|
81
|
+
})).rejects.toThrow();
|
|
82
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
83
|
+
});
|
|
84
|
+
it("does not retry on AxiosError.ECONNABORTED", async () => {
|
|
85
|
+
fn.mockImplementation(() => {
|
|
86
|
+
const error = new axios_1.AxiosError("mock error");
|
|
87
|
+
error.code = "ECONNABORTED";
|
|
88
|
+
throw error;
|
|
89
|
+
});
|
|
90
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
91
|
+
initialDelay: 1,
|
|
92
|
+
maxAttempts: 2,
|
|
93
|
+
})).rejects.toThrow();
|
|
94
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
95
|
+
});
|
|
96
|
+
it("does not retry on ECONNREFUSED when gets array of status without ECONNREFUSED", async () => {
|
|
97
|
+
fn.mockImplementation(() => {
|
|
98
|
+
const error = new axios_1.AxiosError("mock error");
|
|
99
|
+
error.code = "ECONNREFUSED";
|
|
100
|
+
throw error;
|
|
101
|
+
});
|
|
102
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
103
|
+
initialDelay: 1,
|
|
104
|
+
maxAttempts: 2,
|
|
105
|
+
httpCodesToRetry: ["ECONNRESET"],
|
|
106
|
+
})).rejects.toThrow();
|
|
107
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
108
|
+
});
|
|
109
|
+
it("does not retry on ECONNRESET when gets array of status without ECONNRESET", async () => {
|
|
110
|
+
fn.mockImplementation(() => {
|
|
111
|
+
const error = new axios_1.AxiosError("mock error");
|
|
112
|
+
error.code = "ECONNRESET";
|
|
113
|
+
throw error;
|
|
114
|
+
});
|
|
115
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
116
|
+
initialDelay: 1,
|
|
117
|
+
maxAttempts: 2,
|
|
118
|
+
httpCodesToRetry: ["ECONNREFUSED"],
|
|
119
|
+
})).rejects.toThrow();
|
|
120
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
121
|
+
});
|
|
122
|
+
it("does not retry when error is not AxiosError", async () => {
|
|
123
|
+
fn.mockImplementation(() => {
|
|
124
|
+
throw new Error("mock error");
|
|
125
|
+
});
|
|
126
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
127
|
+
initialDelay: 1,
|
|
128
|
+
maxAttempts: 2,
|
|
129
|
+
})).rejects.toThrow();
|
|
130
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
131
|
+
});
|
|
132
|
+
it("does not retry when retryOnTimeout is false and error is timeout", async () => {
|
|
133
|
+
fn.mockImplementation(() => {
|
|
134
|
+
const error = new axios_1.AxiosError("mock error");
|
|
135
|
+
error.code = axios_1.AxiosError.ETIMEDOUT;
|
|
136
|
+
throw error;
|
|
137
|
+
});
|
|
138
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
139
|
+
initialDelay: 1,
|
|
140
|
+
maxAttempts: 2,
|
|
141
|
+
retryOnTimeout: false,
|
|
142
|
+
})).rejects.toThrow();
|
|
143
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
144
|
+
});
|
|
145
|
+
it("does not retry when retryOnTimeout is empty and error is timeout", async () => {
|
|
146
|
+
fn.mockImplementation(() => {
|
|
147
|
+
const error = new axios_1.AxiosError("mock error");
|
|
148
|
+
error.code = axios_1.AxiosError.ETIMEDOUT;
|
|
149
|
+
throw error;
|
|
150
|
+
});
|
|
151
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
152
|
+
initialDelay: 1,
|
|
153
|
+
maxAttempts: 2,
|
|
154
|
+
})).rejects.toThrow();
|
|
155
|
+
expect(fn).toHaveBeenCalledTimes(1);
|
|
156
|
+
});
|
|
157
|
+
it("retries when retryOnTimeout is true and error is timeout", async () => {
|
|
158
|
+
fn.mockImplementation(() => {
|
|
159
|
+
const error = new axios_1.AxiosError("mock error");
|
|
160
|
+
error.code = axios_1.AxiosError.ETIMEDOUT;
|
|
161
|
+
throw error;
|
|
162
|
+
});
|
|
163
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
164
|
+
initialDelay: 1,
|
|
165
|
+
maxAttempts: 2,
|
|
166
|
+
retryOnTimeout: true,
|
|
167
|
+
})).rejects.toThrow();
|
|
168
|
+
expect(fn).toHaveBeenCalledTimes(2);
|
|
169
|
+
});
|
|
170
|
+
it("retries when retryOnTimeout is false and error is timeout and httpCodesToRetry contains timeout code", async () => {
|
|
171
|
+
fn.mockImplementation(() => {
|
|
172
|
+
const error = new axios_1.AxiosError("mock error");
|
|
173
|
+
error.code = axios_1.AxiosError.ETIMEDOUT;
|
|
174
|
+
throw error;
|
|
175
|
+
});
|
|
176
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
177
|
+
initialDelay: 1,
|
|
178
|
+
maxAttempts: 2,
|
|
179
|
+
retryOnTimeout: false,
|
|
180
|
+
httpCodesToRetry: [axios_1.AxiosError.ETIMEDOUT],
|
|
181
|
+
})).rejects.toThrow();
|
|
182
|
+
expect(fn).toHaveBeenCalledTimes(2);
|
|
183
|
+
});
|
|
184
|
+
it("retries when 429 Too Many Requests and uses modified delay", async () => {
|
|
185
|
+
const spyDefaultGetTimeToWait = jest.spyOn(retry, "defaultGetTimeToWait");
|
|
186
|
+
fn.mockImplementation(() => {
|
|
187
|
+
const error = new axios_1.AxiosError("mock error");
|
|
188
|
+
error.response = {
|
|
189
|
+
status: 429,
|
|
190
|
+
data: {},
|
|
191
|
+
statusText: "Too Many Requests",
|
|
192
|
+
headers: {},
|
|
193
|
+
config: {
|
|
194
|
+
headers: new axios_1.AxiosHeaders(),
|
|
195
|
+
method: "post",
|
|
196
|
+
url: "",
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
throw error;
|
|
200
|
+
});
|
|
201
|
+
await expect(async () => (0, retry_1.executeWithNetworkRetries)(fn, {
|
|
202
|
+
initialDelay: 1,
|
|
203
|
+
maxAttempts: 2,
|
|
204
|
+
})).rejects.toThrow();
|
|
205
|
+
expect(fn).toHaveBeenCalledTimes(2);
|
|
206
|
+
expect(spyDefaultGetTimeToWait).toHaveBeenCalledWith(expect.objectContaining({
|
|
207
|
+
initialDelay: 3,
|
|
208
|
+
}));
|
|
209
|
+
});
|
|
129
210
|
});
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
211
|
+
describe("getHttpCodeFromError", () => {
|
|
212
|
+
it("returns undefined when error is not Axios", async () => {
|
|
213
|
+
const resp = (0, retry_1.getHttpCodeFromError)(new Error("something"));
|
|
214
|
+
expect(resp).toBeFalsy();
|
|
215
|
+
});
|
|
216
|
+
it("returns code when error is Axios", async () => {
|
|
217
|
+
const expectedCode = faker_1.faker.lorem.word();
|
|
218
|
+
const error = new axios_1.AxiosError("something");
|
|
219
|
+
error.code = expectedCode;
|
|
220
|
+
const resp = (0, retry_1.getHttpCodeFromError)(error);
|
|
221
|
+
expect(resp).toEqual(expectedCode);
|
|
222
|
+
});
|
|
223
|
+
it("returns code when error is not axios but the cause is", async () => {
|
|
224
|
+
const expectedCode = faker_1.faker.lorem.word();
|
|
225
|
+
const error = new axios_1.AxiosError("something");
|
|
226
|
+
error.code = expectedCode;
|
|
227
|
+
const resp = (0, retry_1.getHttpCodeFromError)(new metriport_error_1.MetriportError("something", error));
|
|
228
|
+
expect(resp).toEqual(expectedCode);
|
|
229
|
+
});
|
|
230
|
+
it("returns code when error is not axios but the 2nd cause is", async () => {
|
|
231
|
+
const expectedCode = "ETIMEDOUT";
|
|
232
|
+
const resp = (0, retry_1.getHttpCodeFromError)(axios_2.errorWithCauseAxiosError);
|
|
233
|
+
expect(resp).toEqual(expectedCode);
|
|
234
|
+
});
|
|
142
235
|
});
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
})
|
|
155
|
-
|
|
236
|
+
describe("getHttpStatusFromError", () => {
|
|
237
|
+
it("returns undefined when error is not Axios", async () => {
|
|
238
|
+
const resp = (0, retry_1.getHttpStatusFromError)(new Error("something"));
|
|
239
|
+
expect(resp).toBeFalsy();
|
|
240
|
+
});
|
|
241
|
+
it("returns status when error is Axios", async () => {
|
|
242
|
+
const expectedStatus = faker_1.faker.number.int();
|
|
243
|
+
const error = new axios_1.AxiosError("something");
|
|
244
|
+
error.response = (0, axios_2.makeAxiosResponse)({ status: expectedStatus });
|
|
245
|
+
const resp = (0, retry_1.getHttpStatusFromError)(error);
|
|
246
|
+
expect(resp).toEqual(expectedStatus);
|
|
247
|
+
});
|
|
248
|
+
it("returns status when error is not axios but the cause is", async () => {
|
|
249
|
+
const expectedStatus = faker_1.faker.number.int();
|
|
250
|
+
const error = new axios_1.AxiosError("something");
|
|
251
|
+
error.response = (0, axios_2.makeAxiosResponse)({ status: expectedStatus });
|
|
252
|
+
const resp = (0, retry_1.getHttpStatusFromError)(new metriport_error_1.MetriportError("something", error));
|
|
253
|
+
expect(resp).toEqual(expectedStatus);
|
|
254
|
+
});
|
|
156
255
|
});
|
|
157
256
|
});
|
|
158
257
|
//# sourceMappingURL=retry.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retry.test.js","sourceRoot":"","sources":["../../../src/net/__tests__/retry.test.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"retry.test.js","sourceRoot":"","sources":["../../../src/net/__tests__/retry.test.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yDAAyD;AACzD,2CAAwC;AACxC,iCAAiD;AACjD,0DAA4C;AAC5C,iEAA6D;AAC7D,oCAAmG;AACnG,mCAAsE;AAEtE,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,QAAQ,CAAC,2BAA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WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;YAC5E,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACvC,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/net/error.d.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
export declare const nodeConnRefusedErrorCodes:
|
|
1
|
+
export declare const nodeConnRefusedErrorCodes: readonly ["ECONNREFUSED", "ECONNRESET"];
|
|
2
2
|
export type NodeConnRefusedNetworkError = (typeof nodeConnRefusedErrorCodes)[number];
|
|
3
|
-
export declare const nodeTimeoutErrorCodes:
|
|
3
|
+
export declare const nodeTimeoutErrorCodes: readonly ["ETIMEDOUT"];
|
|
4
4
|
export type NodeTimeoutNetworkError = (typeof nodeTimeoutErrorCodes)[number];
|
|
5
|
-
export
|
|
6
|
-
export
|
|
5
|
+
export declare const nodeNetworkErrorCodes: readonly ["ECONNREFUSED", "ECONNRESET", "ETIMEDOUT", "ENOTFOUND"];
|
|
6
|
+
export type NodeNetworkError = (typeof nodeNetworkErrorCodes)[number];
|
|
7
|
+
export declare const axiosTimeoutErrorCodes: readonly ["ECONNABORTED", "ETIMEDOUT"];
|
|
7
8
|
export type AxiosTimeoutError = (typeof axiosTimeoutErrorCodes)[number];
|
|
8
|
-
export declare const axiosResponseErrorCodes:
|
|
9
|
+
export declare const axiosResponseErrorCodes: readonly ["ERR_BAD_RESPONSE"];
|
|
9
10
|
export type AxiosResponseError = (typeof axiosResponseErrorCodes)[number];
|
|
10
|
-
export
|
|
11
|
-
export
|
|
11
|
+
export declare const axiosNetworkErrors: readonly ["ERR_BAD_RESPONSE", "ECONNABORTED", "ETIMEDOUT"];
|
|
12
|
+
export type AxiosNetworkError = (typeof axiosNetworkErrors)[number];
|
|
13
|
+
export declare const networkTimeoutErrors: ("ETIMEDOUT" | "ECONNABORTED")[];
|
|
12
14
|
export type NetworkTimeoutError = (typeof networkTimeoutErrors)[number];
|
|
13
|
-
export
|
|
15
|
+
export declare const networkErrors: readonly ["ECONNREFUSED", "ECONNRESET", "ETIMEDOUT", "ENOTFOUND", "ERR_BAD_RESPONSE", "ECONNABORTED", "ETIMEDOUT"];
|
|
16
|
+
export type NetworkError = (typeof networkErrors)[number];
|
|
14
17
|
export declare function getNetworkErrorDetails(error: unknown): {
|
|
15
18
|
details: string;
|
|
16
19
|
code: string | undefined;
|
package/dist/net/error.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/net/error.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/net/error.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,yBAAyB,yCAA0C,CAAC;AACjF,MAAM,MAAM,2BAA2B,GAAG,CAAC,OAAO,yBAAyB,CAAC,CAAC,MAAM,CAAC,CAAC;AAErF,eAAO,MAAM,qBAAqB,wBAAyB,CAAC;AAC5D,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE7E,eAAO,MAAM,qBAAqB,mEAIxB,CAAC;AACX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAItE,eAAO,MAAM,sBAAsB,wCAA2D,CAAC;AAC/F,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,eAAO,MAAM,uBAAuB,+BAAyC,CAAC;AAC9E,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1E,eAAO,MAAM,kBAAkB,4DAAmE,CAAC;AACnG,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAIpE,eAAO,MAAM,oBAAoB,kCAAwD,CAAC;AAC1F,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,eAAO,MAAM,aAAa,oHAA6D,CAAC;AACxF,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AAE1D,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B,CAUA"}
|
package/dist/net/error.js
CHANGED
|
@@ -23,17 +23,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getNetworkErrorDetails = exports.networkTimeoutErrors = exports.axiosResponseErrorCodes = exports.axiosTimeoutErrorCodes = exports.nodeTimeoutErrorCodes = exports.nodeConnRefusedErrorCodes = void 0;
|
|
26
|
+
exports.getNetworkErrorDetails = exports.networkErrors = exports.networkTimeoutErrors = exports.axiosNetworkErrors = exports.axiosResponseErrorCodes = exports.axiosTimeoutErrorCodes = exports.nodeNetworkErrorCodes = exports.nodeTimeoutErrorCodes = exports.nodeConnRefusedErrorCodes = void 0;
|
|
27
27
|
const axios_1 = __importStar(require("axios"));
|
|
28
28
|
const shared_1 = require("../error/shared");
|
|
29
29
|
// https://nodejs.org/docs/latest-v18.x/api/errors.html#common-system-errors
|
|
30
30
|
exports.nodeConnRefusedErrorCodes = ["ECONNREFUSED", "ECONNRESET"];
|
|
31
31
|
exports.nodeTimeoutErrorCodes = ["ETIMEDOUT"];
|
|
32
|
+
exports.nodeNetworkErrorCodes = [
|
|
33
|
+
...exports.nodeConnRefusedErrorCodes,
|
|
34
|
+
...exports.nodeTimeoutErrorCodes,
|
|
35
|
+
"ENOTFOUND",
|
|
36
|
+
];
|
|
32
37
|
// Axios error codes that are timeout errors
|
|
33
38
|
exports.axiosTimeoutErrorCodes = [axios_1.AxiosError.ECONNABORTED, axios_1.AxiosError.ETIMEDOUT];
|
|
34
39
|
exports.axiosResponseErrorCodes = [axios_1.AxiosError.ERR_BAD_RESPONSE];
|
|
40
|
+
exports.axiosNetworkErrors = [...exports.axiosResponseErrorCodes, ...exports.axiosTimeoutErrorCodes];
|
|
35
41
|
// General Network errors
|
|
36
42
|
exports.networkTimeoutErrors = [...exports.nodeTimeoutErrorCodes, ...exports.axiosTimeoutErrorCodes];
|
|
43
|
+
exports.networkErrors = [...exports.nodeNetworkErrorCodes, ...exports.axiosNetworkErrors];
|
|
37
44
|
function getNetworkErrorDetails(error) {
|
|
38
45
|
const details = (0, shared_1.errorToString)(error);
|
|
39
46
|
if (axios_1.default.isAxiosError(error)) {
|