ag-common 0.0.419 → 0.0.421
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/api/helpers/api.js +35 -34
- package/dist/api/helpers/aws.js +13 -9
- package/dist/api/helpers/cloudfront.js +24 -7
- package/dist/api/helpers/dynamo.js +134 -85
- package/dist/api/helpers/dynamoInfra.js +19 -14
- package/dist/api/helpers/enforceDynamoProvisionCap.js +18 -14
- package/dist/api/helpers/index.js +30 -14
- package/dist/api/helpers/openApiHelpers.js +37 -34
- package/dist/api/helpers/s3.js +126 -81
- package/dist/api/helpers/ses.js +28 -9
- package/dist/api/helpers/sqs.js +26 -9
- package/dist/api/helpers/ssm.js +14 -8
- package/dist/api/helpers/sts.js +34 -16
- package/dist/api/helpers/validateOpenApi.js +103 -92
- package/dist/api/helpers/validations.js +46 -29
- package/dist/api/index.js +18 -2
- package/dist/api/openapi-prefix.js +38 -25
- package/dist/api/types/aws.js +2 -1
- package/dist/api/types/index.js +17 -1
- package/dist/common/const.js +5 -2
- package/dist/common/helpers/array.js +19 -8
- package/dist/common/helpers/async.js +28 -10
- package/dist/common/helpers/binary.js +10 -5
- package/dist/common/helpers/date.js +25 -14
- package/dist/common/helpers/email.js +11 -5
- package/dist/common/helpers/func.js +7 -3
- package/dist/common/helpers/generator.js +24 -9
- package/dist/common/helpers/groupBy.js +9 -3
- package/dist/common/helpers/hashCode.js +9 -3
- package/dist/common/helpers/i18n.js +17 -9
- package/dist/common/helpers/index.js +34 -18
- package/dist/common/helpers/log.js +28 -16
- package/dist/common/helpers/math.js +21 -9
- package/dist/common/helpers/memo.js +7 -3
- package/dist/common/helpers/object.js +35 -20
- package/dist/common/helpers/random.js +10 -4
- package/dist/common/helpers/secondsInNearest.js +7 -2
- package/dist/common/helpers/sleep.js +5 -1
- package/dist/common/helpers/string/base64.js +7 -2
- package/dist/common/helpers/string/chunk.js +5 -1
- package/dist/common/helpers/string/contains.js +7 -2
- package/dist/common/helpers/string/getExtendedStringSegment.js +9 -5
- package/dist/common/helpers/string/index.js +26 -10
- package/dist/common/helpers/string/json.js +5 -1
- package/dist/common/helpers/string/object.js +5 -1
- package/dist/common/helpers/string/surround.js +5 -1
- package/dist/common/helpers/string/trim.js +7 -2
- package/dist/common/helpers/string/truncate.js +5 -1
- package/dist/common/helpers/string/url.js +9 -4
- package/dist/common/index.js +18 -2
- package/dist/index.js +19 -3
- package/dist/ui/components/BorderGradient/index.js +25 -18
- package/dist/ui/components/Button/index.js +25 -17
- package/dist/ui/components/Chevron/index.js +16 -9
- package/dist/ui/components/Close/index.js +13 -6
- package/dist/ui/components/Confirm/Dialog.js +25 -9
- package/dist/ui/components/Confirm/Modal.js +27 -20
- package/dist/ui/components/Confirm/index.js +19 -3
- package/dist/ui/components/Confirm/types.js +2 -1
- package/dist/ui/components/DropdownList/Base.js +64 -33
- package/dist/ui/components/DropdownList/Dialog.js +24 -8
- package/dist/ui/components/DropdownList/index.js +18 -2
- package/dist/ui/components/DropdownList/types.js +2 -1
- package/dist/ui/components/FlexColumn/index.js +14 -4
- package/dist/ui/components/FlexRow/index.js +14 -4
- package/dist/ui/components/HeadersRaw/index.js +27 -20
- package/dist/ui/components/HorizontalScrollBar/index.js +34 -6
- package/dist/ui/components/Icon/index.js +16 -9
- package/dist/ui/components/Image/index.js +28 -10
- package/dist/ui/components/InfiniteScroll/index.js +50 -18
- package/dist/ui/components/KebabDots/index.js +13 -6
- package/dist/ui/components/Loader/index.js +39 -9
- package/dist/ui/components/Modal/Dialog.js +23 -7
- package/dist/ui/components/Modal/Modal.js +49 -19
- package/dist/ui/components/Modal/index.js +19 -3
- package/dist/ui/components/Modal/types.js +2 -1
- package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +34 -26
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +19 -12
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +11 -6
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +15 -8
- package/dist/ui/components/OpenApiCodeBlock/curl/index.js +21 -14
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +15 -8
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +8 -3
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +34 -27
- package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +18 -11
- package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +17 -7
- package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +15 -6
- package/dist/ui/components/OpenApiCodeBlock/index.js +18 -2
- package/dist/ui/components/OpenApiCodeBlock/types.js +2 -1
- package/dist/ui/components/PieChart/index.js +18 -11
- package/dist/ui/components/ProgressBar/index.js +45 -15
- package/dist/ui/components/Prompt/Dialog.js +23 -7
- package/dist/ui/components/Prompt/Modal.js +55 -25
- package/dist/ui/components/Prompt/index.js +18 -2
- package/dist/ui/components/RowOrColumn/index.js +17 -7
- package/dist/ui/components/Search/AutoHideSearchBox.js +56 -24
- package/dist/ui/components/Search/Base.js +52 -21
- package/dist/ui/components/Search/Dialog.js +26 -10
- package/dist/ui/components/Search/Inline.js +10 -3
- package/dist/ui/components/Search/Modal.js +17 -10
- package/dist/ui/components/Search/SearchBox.js +58 -26
- package/dist/ui/components/Search/index.js +23 -7
- package/dist/ui/components/Search/types.js +2 -1
- package/dist/ui/components/Sidebar/index.js +25 -18
- package/dist/ui/components/SparkLine/index.js +27 -17
- package/dist/ui/components/Table/index.js +22 -15
- package/dist/ui/components/TextEdit/CheckboxEdit.js +51 -21
- package/dist/ui/components/TextEdit/ColourEdit.js +44 -17
- package/dist/ui/components/TextEdit/LengthBox.js +12 -5
- package/dist/ui/components/TextEdit/ListboxEdit.js +42 -15
- package/dist/ui/components/TextEdit/RadioGroup.js +43 -13
- package/dist/ui/components/TextEdit/TextEdit.js +78 -48
- package/dist/ui/components/TextEdit/common.js +17 -11
- package/dist/ui/components/TextEdit/index.js +22 -6
- package/dist/ui/components/TextEdit/types.js +2 -1
- package/dist/ui/components/TextWithButton/index.js +40 -10
- package/dist/ui/components/TimelineChart/index.js +24 -14
- package/dist/ui/components/Toast/Cross.js +16 -9
- package/dist/ui/components/Toast/Tick.js +11 -4
- package/dist/ui/components/Toast/Warning.js +15 -8
- package/dist/ui/components/Toast/base.js +65 -33
- package/dist/ui/components/Toast/index.js +18 -2
- package/dist/ui/components/Toast/types.js +2 -1
- package/dist/ui/components/UserImage/index.js +48 -17
- package/dist/ui/components/index.js +46 -30
- package/dist/ui/helpers/axiosHelper.js +39 -25
- package/dist/ui/helpers/browserHelpers.js +22 -7
- package/dist/ui/helpers/callOpenApi/cached.js +37 -18
- package/dist/ui/helpers/callOpenApi/direct.js +59 -46
- package/dist/ui/helpers/callOpenApi/helpers.js +40 -25
- package/dist/ui/helpers/callOpenApi/hook.js +36 -47
- package/dist/ui/helpers/callOpenApi/index.js +21 -5
- package/dist/ui/helpers/callOpenApi/types.js +2 -1
- package/dist/ui/helpers/cognito.js +2 -1
- package/dist/ui/helpers/cookie/const.js +5 -2
- package/dist/ui/helpers/cookie/get.js +14 -13
- package/dist/ui/helpers/cookie/index.js +21 -5
- package/dist/ui/helpers/cookie/raw.js +16 -9
- package/dist/ui/helpers/cookie/set.js +15 -10
- package/dist/ui/helpers/cookie/use.js +16 -23
- package/dist/ui/helpers/date.js +15 -10
- package/dist/ui/helpers/debounce.js +10 -5
- package/dist/ui/helpers/dom.js +13 -6
- package/dist/ui/helpers/extractAttributes.js +7 -2
- package/dist/ui/helpers/index.js +41 -25
- package/dist/ui/helpers/jwt.js +2 -1
- package/dist/ui/helpers/plural.js +5 -1
- package/dist/ui/helpers/routes.js +24 -17
- package/dist/ui/helpers/serviceWorker.js +23 -8
- package/dist/ui/helpers/useContextMenu.js +14 -9
- package/dist/ui/helpers/useElementAttribute.js +7 -3
- package/dist/ui/helpers/useGranularHook.js +10 -5
- package/dist/ui/helpers/useInterval.js +12 -8
- package/dist/ui/helpers/useLocalStorage.js +32 -24
- package/dist/ui/helpers/useLockBodyScroll.js +7 -3
- package/dist/ui/helpers/useOnClickOutside.js +12 -7
- package/dist/ui/helpers/useOnScroll.js +21 -15
- package/dist/ui/helpers/useOverloadPageSearch.js +7 -3
- package/dist/ui/helpers/useQueryString.js +20 -14
- package/dist/ui/helpers/useResize.js +19 -17
- package/dist/ui/helpers/useTimeout.js +9 -5
- package/dist/ui/icons/ChevronRight.js +9 -3
- package/dist/ui/icons/CrossIcon.js +12 -5
- package/dist/ui/icons/Door.js +10 -4
- package/dist/ui/icons/HorizontalDots.js +9 -3
- package/dist/ui/icons/Magnify.js +10 -3
- package/dist/ui/icons/Pencil.js +12 -5
- package/dist/ui/icons/Save.js +11 -4
- package/dist/ui/icons/Undo.js +12 -5
- package/dist/ui/icons/UserOutline.js +9 -3
- package/dist/ui/icons/index.js +25 -9
- package/dist/ui/index.js +20 -4
- package/dist/ui/styles/colours.js +12 -7
- package/dist/ui/styles/common.js +22 -14
- package/dist/ui/styles/index.js +20 -4
- package/dist/ui/styles/media.js +10 -7
- package/dist/ui/styles/standaloneStyles.js +16 -10
- package/package.json +2 -2
|
@@ -1,7 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.callOpenApiCached = exports.callOpenApiCachedRaw = exports.setOpenApiCacheRaw = void 0;
|
|
16
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
17
|
+
const hashCode_1 = require("../../../common/helpers/hashCode");
|
|
18
|
+
const base64_1 = require("../../../common/helpers/string/base64");
|
|
19
|
+
const direct_1 = require("./direct");
|
|
5
20
|
let callOpenApiCache;
|
|
6
21
|
/**
|
|
7
22
|
* cache differs per user and per SSR provided data
|
|
@@ -9,44 +24,46 @@ let callOpenApiCache;
|
|
|
9
24
|
* @returns
|
|
10
25
|
*/
|
|
11
26
|
function getCacheKey({ cacheKey, overrideAuth, ssrCacheItems, }) {
|
|
12
|
-
const authkeyPrefix1 = getIdTokenAuthHeaderRaw({
|
|
27
|
+
const authkeyPrefix1 = (0, direct_1.getIdTokenAuthHeaderRaw)({
|
|
13
28
|
overrideAuth: overrideAuth,
|
|
14
29
|
});
|
|
15
|
-
const authPref = !authkeyPrefix1 ? '' : hashCode(toBase64(authkeyPrefix1));
|
|
30
|
+
const authPref = !authkeyPrefix1 ? '' : (0, hashCode_1.hashCode)((0, base64_1.toBase64)(authkeyPrefix1));
|
|
16
31
|
const ssrCachePref = !ssrCacheItems
|
|
17
32
|
? ''
|
|
18
|
-
: hashCode(toBase64(JSON.stringify(ssrCacheItems)));
|
|
33
|
+
: (0, hashCode_1.hashCode)((0, base64_1.toBase64)(JSON.stringify(ssrCacheItems)));
|
|
19
34
|
let cacheKeyRet;
|
|
20
35
|
if (cacheKey) {
|
|
21
36
|
cacheKeyRet = `${cacheKey}||${authPref}||${ssrCachePref}`;
|
|
22
37
|
}
|
|
23
38
|
return cacheKeyRet;
|
|
24
39
|
}
|
|
25
|
-
|
|
40
|
+
const setOpenApiCacheRaw = (p, data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
26
41
|
const userPrefixedCacheKey = getCacheKey(p);
|
|
27
42
|
if (!userPrefixedCacheKey) {
|
|
28
43
|
return;
|
|
29
44
|
}
|
|
30
45
|
if (!callOpenApiCache) {
|
|
31
|
-
callOpenApiCache = new
|
|
46
|
+
callOpenApiCache = new node_cache_1.default({ stdTTL: p.cacheTtl || 120 });
|
|
32
47
|
}
|
|
33
48
|
callOpenApiCache.set(userPrefixedCacheKey, data);
|
|
34
|
-
};
|
|
49
|
+
});
|
|
50
|
+
exports.setOpenApiCacheRaw = setOpenApiCacheRaw;
|
|
35
51
|
/**
|
|
36
52
|
* sync call to callOpenApiCache.
|
|
37
53
|
* @param p
|
|
38
54
|
* @returns undefined if no cache item
|
|
39
55
|
*/
|
|
40
|
-
|
|
56
|
+
const callOpenApiCachedRaw = (p) => {
|
|
57
|
+
var _a, _b, _c;
|
|
41
58
|
const userPrefixedCacheKey = getCacheKey(p);
|
|
42
59
|
if (!userPrefixedCacheKey) {
|
|
43
60
|
return undefined;
|
|
44
61
|
}
|
|
45
62
|
if (!callOpenApiCache) {
|
|
46
|
-
callOpenApiCache = new
|
|
63
|
+
callOpenApiCache = new node_cache_1.default({ stdTTL: p.cacheTtl || 120 });
|
|
47
64
|
}
|
|
48
65
|
//get ssr cache value
|
|
49
|
-
const ssrCached = p.ssrCacheItems
|
|
66
|
+
const ssrCached = (_c = (_b = (_a = p.ssrCacheItems) === null || _a === void 0 ? void 0 : _a.find((s) => s.cacheKey === p.cacheKey)) === null || _b === void 0 ? void 0 : _b.prefillData) === null || _c === void 0 ? void 0 : _c.data;
|
|
50
67
|
//if we have ssr cache and there is no existing cache then set
|
|
51
68
|
if (!callOpenApiCache.get(userPrefixedCacheKey) && ssrCached) {
|
|
52
69
|
callOpenApiCache.set(userPrefixedCacheKey, ssrCached);
|
|
@@ -58,15 +75,17 @@ export const callOpenApiCachedRaw = (p) => {
|
|
|
58
75
|
}
|
|
59
76
|
return { data };
|
|
60
77
|
};
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
exports.callOpenApiCachedRaw = callOpenApiCachedRaw;
|
|
79
|
+
const callOpenApiCached = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const raw = (0, exports.callOpenApiCachedRaw)(p);
|
|
63
81
|
if (raw) {
|
|
64
82
|
return raw;
|
|
65
83
|
}
|
|
66
|
-
const resp =
|
|
84
|
+
const resp = yield (0, direct_1.callOpenApi)(p);
|
|
67
85
|
if (resp.error) {
|
|
68
86
|
return { error: resp.error, data: undefined };
|
|
69
87
|
}
|
|
70
|
-
|
|
88
|
+
yield (0, exports.setOpenApiCacheRaw)(p, resp.data);
|
|
71
89
|
return resp;
|
|
72
|
-
};
|
|
90
|
+
});
|
|
91
|
+
exports.callOpenApiCached = callOpenApiCached;
|
|
@@ -1,47 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.callOpenApi = exports.getIdTokenAuthHeaderRaw = void 0;
|
|
13
|
+
const axios_1 = require("axios");
|
|
14
|
+
const const_1 = require("../../../common/const");
|
|
15
|
+
const array_1 = require("../../../common/helpers/array");
|
|
16
|
+
const sleep_1 = require("../../../common/helpers/sleep");
|
|
17
|
+
const cookie_1 = require("../cookie");
|
|
18
|
+
const useLocalStorage_1 = require("../useLocalStorage");
|
|
7
19
|
/**
|
|
8
20
|
* get the id_token from provided value, or cookie, or LS
|
|
9
21
|
*/
|
|
10
|
-
|
|
22
|
+
function getIdTokenAuthHeaderRaw({ overrideAuth, }) {
|
|
23
|
+
var _a;
|
|
11
24
|
let idToken;
|
|
12
25
|
//if override supplied will only use that and not refresh
|
|
13
|
-
if (overrideAuth
|
|
14
|
-
idToken = overrideAuth
|
|
26
|
+
if (overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token) {
|
|
27
|
+
idToken = overrideAuth === null || overrideAuth === void 0 ? void 0 : overrideAuth.id_token;
|
|
15
28
|
}
|
|
16
29
|
else {
|
|
17
|
-
idToken = getCookieString({
|
|
30
|
+
idToken = (0, cookie_1.getCookieString)({
|
|
18
31
|
name: 'id_token',
|
|
19
32
|
defaultValue: '',
|
|
20
33
|
});
|
|
21
34
|
if (!idToken) {
|
|
22
|
-
const userLs = getLocalStorageItem('user', undefined);
|
|
23
|
-
if (userLs
|
|
35
|
+
const userLs = (0, useLocalStorage_1.getLocalStorageItem)('user', undefined);
|
|
36
|
+
if ((_a = userLs === null || userLs === void 0 ? void 0 : userLs.jwt) === null || _a === void 0 ? void 0 : _a.id_token) {
|
|
24
37
|
idToken = userLs.jwt.id_token;
|
|
25
38
|
}
|
|
26
39
|
}
|
|
27
40
|
}
|
|
28
41
|
return idToken;
|
|
29
42
|
}
|
|
43
|
+
exports.getIdTokenAuthHeaderRaw = getIdTokenAuthHeaderRaw;
|
|
30
44
|
/**
|
|
31
45
|
* get id_token, and then refresh
|
|
32
46
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
47
|
+
function getIdTokenAuthHeader({ overrideAuth, refreshToken, }) {
|
|
48
|
+
var _a, _b;
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
let idToken = getIdTokenAuthHeaderRaw({ overrideAuth });
|
|
51
|
+
//if we have a cookie token, can try to refresh
|
|
52
|
+
if (idToken) {
|
|
53
|
+
const updated = yield refreshToken();
|
|
54
|
+
if ((_a = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _a === void 0 ? void 0 : _a.id_token) {
|
|
55
|
+
idToken = (_b = updated === null || updated === void 0 ? void 0 : updated.jwt) === null || _b === void 0 ? void 0 : _b.id_token;
|
|
56
|
+
}
|
|
40
57
|
}
|
|
41
|
-
|
|
42
|
-
|
|
58
|
+
return idToken;
|
|
59
|
+
});
|
|
43
60
|
}
|
|
44
|
-
|
|
61
|
+
const callOpenApi = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
45
63
|
const { func, apiUrl, logout, newDefaultApi, headers } = p;
|
|
46
64
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
47
65
|
let error;
|
|
@@ -52,11 +70,11 @@ export const callOpenApi = async (p) => {
|
|
|
52
70
|
middleware: [],
|
|
53
71
|
};
|
|
54
72
|
//comes from either id_token cookie OR auth override param
|
|
55
|
-
const idToken =
|
|
56
|
-
if (headers
|
|
73
|
+
const idToken = yield getIdTokenAuthHeader(p);
|
|
74
|
+
if (headers === null || headers === void 0 ? void 0 : headers.authorization) {
|
|
57
75
|
config.baseOptions.headers.authorization = headers.authorization.toString();
|
|
58
76
|
}
|
|
59
|
-
else if (headers
|
|
77
|
+
else if ((headers === null || headers === void 0 ? void 0 : headers.authorization) === undefined && idToken) {
|
|
60
78
|
config.baseOptions.headers.authorization = `Bearer ${idToken}`;
|
|
61
79
|
}
|
|
62
80
|
if (config.baseOptions.headers.authorization) {
|
|
@@ -64,10 +82,7 @@ export const callOpenApi = async (p) => {
|
|
|
64
82
|
{
|
|
65
83
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
84
|
pre: (oldFetchParams) => {
|
|
67
|
-
oldFetchParams.init.headers = {
|
|
68
|
-
authorization: config.baseOptions.headers.authorization,
|
|
69
|
-
...oldFetchParams.init.headers,
|
|
70
|
-
};
|
|
85
|
+
oldFetchParams.init.headers = Object.assign({ authorization: config.baseOptions.headers.authorization }, oldFetchParams.init.headers);
|
|
71
86
|
},
|
|
72
87
|
},
|
|
73
88
|
];
|
|
@@ -79,26 +94,26 @@ export const callOpenApi = async (p) => {
|
|
|
79
94
|
errorCount += 1;
|
|
80
95
|
try {
|
|
81
96
|
// eslint-disable-next-line no-await-in-loop
|
|
82
|
-
const resp =
|
|
97
|
+
const resp = yield func(cl);
|
|
83
98
|
if (resp.status < 400) {
|
|
84
99
|
data = resp.data;
|
|
85
100
|
break;
|
|
86
101
|
}
|
|
87
|
-
throw new AxiosError(resp.statusText, resp.status
|
|
102
|
+
throw new axios_1.AxiosError(resp.statusText, ((_a = resp.status) === null || _a === void 0 ? void 0 : _a.toString()) || '500');
|
|
88
103
|
}
|
|
89
104
|
catch (e) {
|
|
90
105
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
91
106
|
const ae = e;
|
|
92
|
-
const status = Number(ae.code
|
|
107
|
+
const status = Number((_d = (_b = ae.code) !== null && _b !== void 0 ? _b : (_c = ae.response) === null || _c === void 0 ? void 0 : _c.status) !== null && _d !== void 0 ? _d : 500);
|
|
93
108
|
const errorMessage = [
|
|
94
|
-
ae.status
|
|
109
|
+
(_e = ae.status) !== null && _e !== void 0 ? _e : '',
|
|
95
110
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
96
|
-
ae.response
|
|
97
|
-
ae.response
|
|
98
|
-
ae.response
|
|
99
|
-
ae.message
|
|
111
|
+
(_h = (_g = (_f = ae.response) === null || _f === void 0 ? void 0 : _f.data) === null || _g === void 0 ? void 0 : _g.toString()) !== null && _h !== void 0 ? _h : '',
|
|
112
|
+
(_l = (_k = (_j = ae.response) === null || _j === void 0 ? void 0 : _j.statusText) === null || _k === void 0 ? void 0 : _k.toString()) !== null && _l !== void 0 ? _l : '',
|
|
113
|
+
(_p = (_o = (_m = ae.response) === null || _m === void 0 ? void 0 : _m.status) === null || _o === void 0 ? void 0 : _o.toString()) !== null && _p !== void 0 ? _p : '',
|
|
114
|
+
(_r = (_q = ae.message) === null || _q === void 0 ? void 0 : _q.toString()) !== null && _r !== void 0 ? _r : '',
|
|
100
115
|
]
|
|
101
|
-
.filter(notEmpty)
|
|
116
|
+
.filter(array_1.notEmpty)
|
|
102
117
|
.sort((a, b) => (a.length < b.length ? -1 : 1))
|
|
103
118
|
.join('\n');
|
|
104
119
|
if (status === 403 || status === 401) {
|
|
@@ -108,15 +123,13 @@ export const callOpenApi = async (p) => {
|
|
|
108
123
|
data: undefined,
|
|
109
124
|
};
|
|
110
125
|
}
|
|
111
|
-
if (!retryHttpCodes.includes(status) || errorCount === errorMax) {
|
|
112
|
-
error = {
|
|
126
|
+
if (!const_1.retryHttpCodes.includes(status) || errorCount === errorMax) {
|
|
127
|
+
error = Object.assign(Object.assign({}, ae), { message: errorMessage });
|
|
113
128
|
break;
|
|
114
129
|
}
|
|
115
130
|
}
|
|
116
|
-
|
|
131
|
+
yield (0, sleep_1.sleep)(const_1.retryHttpMs);
|
|
117
132
|
}
|
|
118
|
-
return {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
};
|
|
122
|
-
};
|
|
133
|
+
return Object.assign({ data }, (error && { error }));
|
|
134
|
+
});
|
|
135
|
+
exports.callOpenApi = callOpenApi;
|
|
@@ -1,32 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.apiResponseToAxiosResponse = void 0;
|
|
13
|
+
const array_1 = require("../../../common/helpers/array");
|
|
2
14
|
/**
|
|
3
15
|
* shim to convert raw response to an axios style response.
|
|
4
16
|
* must convert all DefaultClass requests to the Raw equivalent
|
|
5
17
|
* @param p
|
|
6
18
|
* @returns
|
|
7
19
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
20
|
+
const apiResponseToAxiosResponse = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
21
|
+
return p()
|
|
22
|
+
.then((r) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
const r1 = {
|
|
24
|
+
status: r.raw.status,
|
|
25
|
+
statusText: r.raw.statusText,
|
|
26
|
+
data: yield r.value(),
|
|
27
|
+
headers: (0, array_1.arrayToObject)(Object.entries(r.raw.headers), (s) => s[0], (s) => s[1]),
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
config: {},
|
|
30
|
+
};
|
|
31
|
+
return r1;
|
|
32
|
+
}))
|
|
33
|
+
.catch((e) => {
|
|
34
|
+
const er = e;
|
|
35
|
+
const ret = {
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
37
|
+
data: undefined,
|
|
38
|
+
status: er.status,
|
|
39
|
+
statusText: er.statusText,
|
|
40
|
+
headers: (0, array_1.arrayToObject)(Object.entries(er.headers), (s) => s[0], (s) => s[1]),
|
|
41
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
42
|
+
config: {},
|
|
43
|
+
};
|
|
44
|
+
return ret;
|
|
45
|
+
});
|
|
32
46
|
});
|
|
47
|
+
exports.apiResponseToAxiosResponse = apiResponseToAxiosResponse;
|
|
@@ -1,57 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.useCallOpenApi = void 0;
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const useGranularHook_1 = require("../useGranularHook");
|
|
15
|
+
const cached_1 = require("./cached");
|
|
16
|
+
const direct_1 = require("./direct");
|
|
5
17
|
const defaultState = (p,
|
|
6
18
|
/**
|
|
7
19
|
* default false
|
|
8
20
|
*/
|
|
9
21
|
noSsr = false) => {
|
|
22
|
+
var _a;
|
|
10
23
|
const cachedData = noSsr
|
|
11
24
|
? undefined
|
|
12
|
-
: callOpenApiCachedRaw({
|
|
13
|
-
return {
|
|
14
|
-
data: undefined,
|
|
15
|
-
datetime: 0,
|
|
16
|
-
loadcount: 0,
|
|
17
|
-
loading: false,
|
|
18
|
-
...(cachedData && { data: cachedData }),
|
|
19
|
-
loaded: !!cachedData,
|
|
20
|
-
};
|
|
25
|
+
: (_a = (0, cached_1.callOpenApiCachedRaw)(Object.assign(Object.assign({}, p), { onlyCached: true }))) === null || _a === void 0 ? void 0 : _a.data;
|
|
26
|
+
return Object.assign(Object.assign({ data: undefined, datetime: 0, loadcount: 0, loading: false }, (cachedData && { data: cachedData })), { loaded: !!cachedData });
|
|
21
27
|
};
|
|
22
28
|
/**
|
|
23
29
|
* hooks+cached call to callOpenApi
|
|
24
30
|
* @param p
|
|
25
31
|
* @returns
|
|
26
32
|
*/
|
|
27
|
-
|
|
33
|
+
const useCallOpenApi = (inConfig) => {
|
|
28
34
|
/** response from hook */
|
|
29
|
-
const [resp, setResp] = useState(defaultState(inConfig));
|
|
35
|
+
const [resp, setResp] = (0, react_1.useState)(defaultState(inConfig));
|
|
30
36
|
/** config about hook*/
|
|
31
|
-
const [config, setConfig] = useState(inConfig);
|
|
32
|
-
useGranularEffect(() => {
|
|
37
|
+
const [config, setConfig] = (0, react_1.useState)(inConfig);
|
|
38
|
+
(0, useGranularHook_1.useGranularEffect)(() => {
|
|
33
39
|
if (JSON.stringify(config) !== JSON.stringify(inConfig)) {
|
|
34
40
|
setConfig(inConfig);
|
|
35
41
|
setResp(defaultState(inConfig, true));
|
|
36
42
|
}
|
|
37
43
|
}, [inConfig], [resp, setResp, config, setConfig]);
|
|
38
|
-
const reFetch =
|
|
44
|
+
const reFetch = (0, react_1.useCallback)(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
45
|
const newdate = new Date().getTime();
|
|
40
|
-
const newresp =
|
|
46
|
+
const newresp = yield (0, direct_1.callOpenApi)(config);
|
|
41
47
|
setResp((d) => {
|
|
42
|
-
let newState = {
|
|
43
|
-
...d,
|
|
44
|
-
loaded: true,
|
|
45
|
-
loading: false,
|
|
46
|
-
};
|
|
48
|
+
let newState = Object.assign(Object.assign({}, d), { loaded: true, loading: false });
|
|
47
49
|
if (newdate > d.datetime) {
|
|
48
|
-
newState = {
|
|
49
|
-
...newresp,
|
|
50
|
-
loaded: true,
|
|
51
|
-
loading: false,
|
|
52
|
-
loadcount: d.loadcount + 1,
|
|
53
|
-
datetime: newdate,
|
|
54
|
-
};
|
|
50
|
+
newState = Object.assign(Object.assign({}, newresp), { loaded: true, loading: false, loadcount: d.loadcount + 1, datetime: newdate });
|
|
55
51
|
}
|
|
56
52
|
if (JSON.stringify(d) !== JSON.stringify(newState)) {
|
|
57
53
|
return newState;
|
|
@@ -60,30 +56,23 @@ export const useCallOpenApi = (inConfig) => {
|
|
|
60
56
|
return d;
|
|
61
57
|
}
|
|
62
58
|
});
|
|
63
|
-
}, [config]);
|
|
64
|
-
useEffect(() => {
|
|
59
|
+
}), [config]);
|
|
60
|
+
(0, react_1.useEffect)(() => {
|
|
65
61
|
const { error, loaded, loading, loadcount } = resp;
|
|
66
62
|
const ng = config.disabled || loaded || loading || (error && loadcount > 2);
|
|
67
63
|
if (ng) {
|
|
68
64
|
return;
|
|
69
65
|
}
|
|
70
|
-
setResp((d) => ({
|
|
66
|
+
setResp((d) => (Object.assign(Object.assign({}, d), { loading: true })));
|
|
71
67
|
void reFetch();
|
|
72
68
|
}, [config.disabled, reFetch, resp]);
|
|
73
|
-
return {
|
|
74
|
-
...resp,
|
|
75
|
-
reFetch,
|
|
76
|
-
setData: async (p) => {
|
|
69
|
+
return Object.assign(Object.assign({}, resp), { reFetch, setData: (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
70
|
//wipe cache, or might revert
|
|
78
|
-
|
|
71
|
+
yield (0, cached_1.setOpenApiCacheRaw)(config, undefined);
|
|
79
72
|
//ensure datetime is changed, or might get overwritten
|
|
80
|
-
setResp((x) => ({
|
|
81
|
-
...x,
|
|
82
|
-
datetime: new Date().getTime(),
|
|
83
|
-
data: typeof p === 'function'
|
|
73
|
+
setResp((x) => (Object.assign(Object.assign({}, x), { datetime: new Date().getTime(), data: typeof p === 'function'
|
|
84
74
|
? p(x.data)
|
|
85
|
-
: p
|
|
86
|
-
|
|
87
|
-
},
|
|
88
|
-
};
|
|
75
|
+
: p })));
|
|
76
|
+
}) });
|
|
89
77
|
};
|
|
78
|
+
exports.useCallOpenApi = useCallOpenApi;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./cached"), exports);
|
|
18
|
+
__exportStar(require("./direct"), exports);
|
|
19
|
+
__exportStar(require("./helpers"), exports);
|
|
20
|
+
__exportStar(require("./hook"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maxCookieLen = exports.expireDate = void 0;
|
|
4
|
+
exports.expireDate = 'Thu, 01 Jan 1970 00:00:00 UTC';
|
|
5
|
+
exports.maxCookieLen = 4000;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCookieString = exports.getCookieRawWrapper = void 0;
|
|
4
|
+
const log_1 = require("../../../common/helpers/log");
|
|
5
|
+
const base64_1 = require("../../../common/helpers/string/base64");
|
|
6
|
+
const raw_1 = require("./raw");
|
|
4
7
|
/**
|
|
5
8
|
* read chunks. json parse+unb64
|
|
6
9
|
* parse defaults to JSON.parse. must change if want if type is not an object!
|
|
7
10
|
* @param param0
|
|
8
11
|
* @returns
|
|
9
12
|
*/
|
|
10
|
-
|
|
13
|
+
function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse: parseRaw, }) {
|
|
11
14
|
const parse = (s) => {
|
|
12
15
|
if (!s) {
|
|
13
16
|
return defaultValue;
|
|
@@ -21,7 +24,7 @@ export function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse:
|
|
|
21
24
|
let currentCount = 0;
|
|
22
25
|
// eslint-disable-next-line no-constant-condition
|
|
23
26
|
while (true) {
|
|
24
|
-
const newv = getCookie({
|
|
27
|
+
const newv = (0, raw_1.getCookie)({
|
|
25
28
|
name: name + currentCount,
|
|
26
29
|
cookieDocument,
|
|
27
30
|
});
|
|
@@ -32,16 +35,14 @@ export function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse:
|
|
|
32
35
|
currentCount += 1;
|
|
33
36
|
}
|
|
34
37
|
try {
|
|
35
|
-
return parse(fromBase64(raw));
|
|
38
|
+
return parse((0, base64_1.fromBase64)(raw));
|
|
36
39
|
}
|
|
37
40
|
catch (e) {
|
|
38
|
-
warn('cookie error:', e);
|
|
39
|
-
wipeCookies(name);
|
|
41
|
+
(0, log_1.warn)('cookie error:', e);
|
|
42
|
+
(0, raw_1.wipeCookies)(name);
|
|
40
43
|
return defaultValue;
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
defaultValue: p.defaultValue || '',
|
|
47
|
-
});
|
|
46
|
+
exports.getCookieRawWrapper = getCookieRawWrapper;
|
|
47
|
+
const getCookieString = (p) => getCookieRawWrapper(Object.assign(Object.assign({}, p), { parse: (s) => s, defaultValue: p.defaultValue || '' }));
|
|
48
|
+
exports.getCookieString = getCookieString;
|
|
@@ -1,5 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./const"), exports);
|
|
18
|
+
__exportStar(require("./get"), exports);
|
|
19
|
+
__exportStar(require("./raw"), exports);
|
|
20
|
+
__exportStar(require("./set"), exports);
|
|
21
|
+
__exportStar(require("./use"), exports);
|