ag-common 0.0.328 → 0.0.331
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/index.d.ts
CHANGED
package/dist/common/index.js
CHANGED
|
@@ -14,4 +14,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./const"), exports);
|
|
17
18
|
__exportStar(require("./helpers"), exports);
|
|
@@ -23,6 +23,7 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
23
23
|
* @returns
|
|
24
24
|
*/
|
|
25
25
|
const axiosHelper = ({ verb, url, body, headers, timeout = 30000, retryMax = 0, onStaleAuth, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
|
+
var _a;
|
|
26
27
|
let retry = 0;
|
|
27
28
|
let ret;
|
|
28
29
|
do {
|
|
@@ -70,19 +71,20 @@ const axiosHelper = ({ verb, url, body, headers, timeout = 30000, retryMax = 0,
|
|
|
70
71
|
}
|
|
71
72
|
catch (e) {
|
|
72
73
|
const em = e;
|
|
74
|
+
const c = Number((_a = em.code) !== null && _a !== void 0 ? _a : '500');
|
|
73
75
|
// jwt expired or bad response
|
|
74
76
|
// 403 returned for old token - will be refreshed
|
|
75
|
-
if (
|
|
77
|
+
if (c === 401 || c === 403) {
|
|
76
78
|
(0, log_1.debug)('auth expired');
|
|
77
79
|
onStaleAuth === null || onStaleAuth === void 0 ? void 0 : onStaleAuth();
|
|
78
80
|
retry = retryMax;
|
|
79
81
|
}
|
|
80
|
-
if (retry >= retryMax) {
|
|
82
|
+
if (!common_1.retryHttpCodes.includes(c) || retry >= retryMax) {
|
|
81
83
|
throw em;
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
86
|
retry += 1;
|
|
85
|
-
yield (0, common_1.sleep)(
|
|
87
|
+
yield (0, common_1.sleep)(common_1.retryHttpMs);
|
|
86
88
|
} while (retry <= retryMax);
|
|
87
89
|
throw new Error('unexpected');
|
|
88
90
|
});
|
|
@@ -14,6 +14,7 @@ const cookie_1 = require("../cookie");
|
|
|
14
14
|
const sleep_1 = require("../../../common/helpers/sleep");
|
|
15
15
|
const array_1 = require("../../../common/helpers/array");
|
|
16
16
|
const useLocalStorage_1 = require("../useLocalStorage");
|
|
17
|
+
const const_1 = require("../../../common/const");
|
|
17
18
|
/**
|
|
18
19
|
* get the id_token from provided value, or cookie, or LS
|
|
19
20
|
*/
|
|
@@ -57,7 +58,7 @@ function getIdTokenAuthHeader({ overrideAuth, refreshToken, }) {
|
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
60
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
61
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
61
62
|
const { func, apiUrl, logout, newDefaultApi, headers } = p;
|
|
62
63
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
63
64
|
let error;
|
|
@@ -87,13 +88,13 @@ const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
87
88
|
catch (e) {
|
|
88
89
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
89
90
|
const ae = e;
|
|
90
|
-
const status = (_a = ae.response) === null || _a === void 0 ? void 0 : _a.status;
|
|
91
|
+
const status = (_b = (_a = ae.response) === null || _a === void 0 ? void 0 : _a.status) !== null && _b !== void 0 ? _b : 500;
|
|
91
92
|
const errorMessage = [
|
|
92
93
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
93
|
-
(
|
|
94
|
-
(
|
|
95
|
-
(
|
|
96
|
-
(
|
|
94
|
+
(_e = (_d = (_c = ae.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.toString()) !== null && _e !== void 0 ? _e : '',
|
|
95
|
+
(_h = (_g = (_f = ae.response) === null || _f === void 0 ? void 0 : _f.statusText) === null || _g === void 0 ? void 0 : _g.toString()) !== null && _h !== void 0 ? _h : '',
|
|
96
|
+
(_l = (_k = (_j = ae.response) === null || _j === void 0 ? void 0 : _j.status) === null || _k === void 0 ? void 0 : _k.toString()) !== null && _l !== void 0 ? _l : '',
|
|
97
|
+
(_o = (_m = ae.message) === null || _m === void 0 ? void 0 : _m.toString()) !== null && _o !== void 0 ? _o : '',
|
|
97
98
|
]
|
|
98
99
|
.filter(array_1.notEmpty)
|
|
99
100
|
.sort((a, b) => (a.length < b.length ? -1 : 1))
|
|
@@ -105,13 +106,12 @@ const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
105
106
|
data: undefined,
|
|
106
107
|
};
|
|
107
108
|
}
|
|
108
|
-
if (status
|
|
109
|
+
if (!const_1.retryHttpCodes.includes(status) || errorCount === errorMax) {
|
|
109
110
|
error = Object.assign(Object.assign({}, ae), { message: errorMessage });
|
|
110
111
|
break;
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
|
-
|
|
114
|
-
yield (0, sleep_1.sleep)(2000);
|
|
114
|
+
yield (0, sleep_1.sleep)(const_1.retryHttpMs);
|
|
115
115
|
}
|
|
116
116
|
return Object.assign({ data }, (error && { error }));
|
|
117
117
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.331",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"jsonwebtoken": "8.x",
|
|
23
23
|
"jwks-rsa": "2.x",
|
|
24
24
|
"node-cache": "5.x",
|
|
25
|
-
"openapi-request-validator": "12.0.
|
|
25
|
+
"openapi-request-validator": "12.0.2",
|
|
26
26
|
"react": "18.2.0",
|
|
27
27
|
"react-dom": "18.2.0",
|
|
28
28
|
"react-hot-toast": "2.x",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"styled-components": ">=5"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@babel/core": "7.
|
|
35
|
+
"@babel/core": "7.19.0",
|
|
36
36
|
"@storybook/addon-actions": "6.5.10",
|
|
37
37
|
"@storybook/addon-docs": "6.5.10",
|
|
38
38
|
"@storybook/addon-essentials": "6.5.10",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"@storybook/react": "6.5.10",
|
|
43
43
|
"@storybook/theming": "6.5.10",
|
|
44
44
|
"@types/jsonwebtoken": "8.5.9",
|
|
45
|
-
"@types/node": "18.7.
|
|
46
|
-
"@types/react": "18.0.
|
|
45
|
+
"@types/node": "18.7.16",
|
|
46
|
+
"@types/react": "18.0.19",
|
|
47
47
|
"@types/react-dom": "18.0.6",
|
|
48
48
|
"@types/styled-components": "5.1.26",
|
|
49
49
|
"cross-env": "7.0.3",
|