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