ag-common 0.0.394 → 0.0.396
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 +1 -1
- package/dist/api/helpers/enforceDynamoProvisionCap.js +4 -3
- package/dist/api/helpers/sqs.js +2 -2
- package/dist/api/helpers/ssm.js +2 -2
- package/dist/common/helpers/binary.js +3 -3
- package/dist/common/helpers/string/base64.d.ts +2 -0
- package/dist/common/helpers/string/base64.js +7 -0
- package/dist/common/helpers/string/chunk.d.ts +1 -0
- package/dist/common/helpers/string/chunk.js +5 -0
- package/dist/common/helpers/string/contains.d.ts +20 -0
- package/dist/common/helpers/string/contains.js +33 -0
- package/dist/common/helpers/string/getExtendedStringSegment.d.ts +19 -0
- package/dist/common/helpers/string/getExtendedStringSegment.js +44 -0
- package/dist/common/helpers/string/index.d.ts +10 -0
- package/dist/common/helpers/string/index.js +26 -0
- package/dist/common/helpers/string/json.d.ts +7 -0
- package/dist/common/helpers/string/json.js +21 -0
- package/dist/common/helpers/string/object.d.ts +7 -0
- package/dist/common/helpers/string/object.js +23 -0
- package/dist/common/helpers/string/surround.d.ts +8 -0
- package/dist/common/helpers/string/surround.js +10 -0
- package/dist/common/helpers/string/trim.d.ts +2 -0
- package/dist/common/helpers/string/trim.js +24 -0
- package/dist/common/helpers/string/truncate.d.ts +1 -0
- package/dist/common/helpers/string/truncate.js +10 -0
- package/dist/common/helpers/string/url.d.ts +9 -0
- package/dist/common/helpers/string/url.js +31 -0
- package/dist/ui/components/Confirm/Modal.js +1 -1
- package/dist/ui/components/DashboardAuthValidation/index.js +2 -2
- package/dist/ui/components/HeadersRaw/index.js +1 -1
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +2 -4
- package/dist/ui/components/OpenApiCodeBlock/curl/index.js +4 -4
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +11 -12
- package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +13 -3
- package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +2 -2
- package/dist/ui/components/Prompt/Modal.js +1 -1
- package/dist/ui/components/Search/AutoHideSearchBox.js +2 -2
- package/dist/ui/components/Search/Base.js +2 -2
- package/dist/ui/components/Search/Dialog.js +2 -2
- package/dist/ui/components/Search/SearchBox.js +4 -3
- package/dist/ui/components/Toast/base.js +2 -2
- package/dist/ui/helpers/axiosHelper.js +4 -3
- package/dist/ui/helpers/callOpenApi/cached.js +4 -4
- package/dist/ui/helpers/cookie/get.d.ts +0 -4
- package/dist/ui/helpers/cookie/get.js +6 -21
- package/dist/ui/helpers/cookie/index.d.ts +1 -0
- package/dist/ui/helpers/cookie/index.js +1 -0
- package/dist/ui/helpers/cookie/raw.d.ts +26 -0
- package/dist/ui/helpers/cookie/raw.js +67 -0
- package/dist/ui/helpers/cookie/set.d.ts +0 -1
- package/dist/ui/helpers/cookie/set.js +8 -43
- package/dist/ui/helpers/routes.js +2 -2
- package/dist/ui/helpers/useQueryString.js +2 -2
- package/package.json +1 -1
- package/dist/common/helpers/string.d.ts +0 -64
- package/dist/common/helpers/string.js +0 -210
|
@@ -5,20 +5,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getSecurity = exports.getBodyJson = exports.getOperation = exports.Highlight2 = exports.Highlight = void 0;
|
|
7
7
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
8
|
-
const common_1 = require("../../../../common");
|
|
9
8
|
exports.Highlight = styled_1.default.span `
|
|
10
9
|
color: green;
|
|
10
|
+
text-transform: capitalize;
|
|
11
11
|
`;
|
|
12
12
|
exports.Highlight2 = styled_1.default.span `
|
|
13
13
|
color: indianred;
|
|
14
14
|
`;
|
|
15
|
+
const indexOfNumber = (str, char, num = 0) => {
|
|
16
|
+
let ret = -1;
|
|
17
|
+
for (let c = 0; c <= num; c += 1) {
|
|
18
|
+
ret = str.indexOf(char, ret + 1);
|
|
19
|
+
}
|
|
20
|
+
if (ret === -1) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
return ret;
|
|
24
|
+
};
|
|
15
25
|
const getApiUrl = (p) => {
|
|
16
26
|
return p.schema.servers[0].url;
|
|
17
27
|
};
|
|
18
28
|
const getFunctionName = (p) => {
|
|
19
29
|
let ret = p.funcF.toString();
|
|
20
30
|
const i1 = ret.indexOf('.') + 1;
|
|
21
|
-
const i2 =
|
|
31
|
+
const i2 = indexOfNumber(ret, '(', 1);
|
|
22
32
|
ret = ret.substring(i1, i2);
|
|
23
33
|
return ret;
|
|
24
34
|
};
|
|
@@ -44,7 +54,7 @@ const getOperation = (p) => {
|
|
|
44
54
|
exports.getOperation = getOperation;
|
|
45
55
|
const getBodyJson = (p) => {
|
|
46
56
|
const body = p.funcF.toString();
|
|
47
|
-
const bstart =
|
|
57
|
+
const bstart = indexOfNumber(body, '(', 1);
|
|
48
58
|
const bend = !bstart ? undefined : body.lastIndexOf(')');
|
|
49
59
|
if (!bstart || !bend) {
|
|
50
60
|
return undefined;
|
|
@@ -5,10 +5,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.joinJsxWithComma = exports.joinJsxWithSlash = exports.joinJsx = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const
|
|
8
|
+
const array_1 = require("../../../../common/helpers/array");
|
|
9
9
|
const joinJsx = (items, sep) => {
|
|
10
10
|
const ret = [];
|
|
11
|
-
items.filter(
|
|
11
|
+
items.filter(array_1.notEmpty).forEach((i, index) => {
|
|
12
12
|
ret.push(i);
|
|
13
13
|
if (index !== items.length - 1) {
|
|
14
14
|
for (const s of sep) {
|
|
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.AutoHideSearchBox = void 0;
|
|
30
30
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
31
31
|
const react_1 = __importStar(require("react"));
|
|
32
|
-
const
|
|
32
|
+
const useGranularHook_1 = require("../../helpers/useGranularHook");
|
|
33
33
|
const icons_1 = require("../../icons");
|
|
34
34
|
const styles_1 = require("../../styles");
|
|
35
35
|
const SearchBox_1 = require("./SearchBox");
|
|
@@ -68,7 +68,7 @@ const SearchBoxStyled = (0, styled_1.default)(SearchBox_1.SearchBox) `
|
|
|
68
68
|
const AutoHideSearchBox = (p) => {
|
|
69
69
|
const [open, setOpen] = (0, react_1.useState)(!!p.searchText);
|
|
70
70
|
const textEditRef = (0, react_1.createRef)();
|
|
71
|
-
(0,
|
|
71
|
+
(0, useGranularHook_1.useGranularEffect)(() => {
|
|
72
72
|
var _a;
|
|
73
73
|
const newOpen = !!p.searchText;
|
|
74
74
|
if (newOpen !== open) {
|
|
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.SearchBase = void 0;
|
|
30
30
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
31
31
|
const react_1 = __importStar(require("react"));
|
|
32
|
-
const
|
|
32
|
+
const array_1 = require("../../../common/helpers/array");
|
|
33
33
|
const styles_1 = require("../../styles");
|
|
34
34
|
const SearchBox_1 = require("./SearchBox");
|
|
35
35
|
const Base = styled_1.default.div `
|
|
@@ -77,7 +77,7 @@ const SearchBase = (p) => {
|
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
const filteredItemsRaw = p.displayItems.filter((i) => p.willDisplayItem(searchText, i));
|
|
80
|
-
const { part: filteredItems } = (0,
|
|
80
|
+
const { part: filteredItems } = (0, array_1.take)(filteredItemsRaw, maxDisplayItems);
|
|
81
81
|
const showText = (_d = (_c = (_b = p.texts) === null || _b === void 0 ? void 0 : _b.totalItems) === null || _c === void 0 ? void 0 : _c.call(_b, filteredItems.length, p.displayItems.length)) !== null && _d !== void 0 ? _d : `Showing ${filteredItems.length} out of ${p.displayItems.length} total
|
|
82
82
|
items`;
|
|
83
83
|
return (react_1.default.createElement(Base, { className: p.className },
|
|
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.SearchDialog = void 0;
|
|
16
16
|
const react_1 = __importDefault(require("react"));
|
|
17
17
|
const client_1 = require("react-dom/client");
|
|
18
|
-
const
|
|
18
|
+
const log_1 = require("../../../common/helpers/log");
|
|
19
19
|
const Modal_1 = require("./Modal");
|
|
20
20
|
/**
|
|
21
21
|
* opens a searchmodal programatically, and resolves to either undefined, or the selected item
|
|
@@ -28,7 +28,7 @@ const SearchDialog = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
28
28
|
return new Promise((res) => {
|
|
29
29
|
const idName = 'ag-search-dialog';
|
|
30
30
|
if (document.body.querySelectorAll('#' + idName).length !== 0) {
|
|
31
|
-
(0,
|
|
31
|
+
(0, log_1.error)('searchDialog already open');
|
|
32
32
|
res(undefined);
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
@@ -29,7 +29,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.SearchBox = void 0;
|
|
30
30
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
31
31
|
const react_1 = __importStar(require("react"));
|
|
32
|
-
const
|
|
32
|
+
const debounce_1 = require("../../helpers/debounce");
|
|
33
|
+
const dom_1 = require("../../helpers/dom");
|
|
33
34
|
const icons_1 = require("../../icons");
|
|
34
35
|
const styles_1 = require("../../styles");
|
|
35
36
|
const TextEdit_1 = require("../TextEdit");
|
|
@@ -81,9 +82,9 @@ exports.SearchBox = (0, react_1.forwardRef)((p, ref) => {
|
|
|
81
82
|
var _a;
|
|
82
83
|
(_a = textEditRef === null || textEditRef === void 0 ? void 0 : textEditRef.current) === null || _a === void 0 ? void 0 : _a.setValue(p.searchText);
|
|
83
84
|
}, [p.searchText, textEditRef]);
|
|
84
|
-
return (react_1.default.createElement(Base, Object.assign({ "data-type": "search", className: p.className }, (0,
|
|
85
|
+
return (react_1.default.createElement(Base, Object.assign({ "data-type": "search", className: p.className }, (0, dom_1.filterDataProps)(p)),
|
|
85
86
|
react_1.default.createElement(TextEdit_1.TextEdit, { ref: textEditRef, placeholder: p.placeholderText, defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(MagnifyIcon, { onClick: () => { var _a; return p.setSearchText(((_a = textEditRef === null || textEditRef === void 0 ? void 0 : textEditRef.current) === null || _a === void 0 ? void 0 : _a.getValue()) || '', true); } },
|
|
86
|
-
react_1.default.createElement(icons_1.Magnify, null)), noGrow: true, allowUndo: false, onClickOutsideWithNoValue: null, onSubmit: (v, enterPressed) => (0,
|
|
87
|
+
react_1.default.createElement(icons_1.Magnify, null)), noGrow: true, allowUndo: false, onClickOutsideWithNoValue: null, onSubmit: (v, enterPressed) => (0, debounce_1.debounce)(() => {
|
|
87
88
|
p.setSearchText(v, enterPressed);
|
|
88
89
|
}, { key: 'pagesearch', time: 200 }), defaultValue: p.defaultValue }),
|
|
89
90
|
p.searchText && (react_1.default.createElement(CrossIconStyled, { onClick: () => {
|
|
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.ToastProvider = exports.Toast = exports.ToastContext = void 0;
|
|
30
30
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
31
31
|
const react_1 = __importStar(require("react"));
|
|
32
|
-
const
|
|
32
|
+
const random_1 = require("../../../common/helpers/random");
|
|
33
33
|
const ProgressBar_1 = require("../ProgressBar");
|
|
34
34
|
const Cross_1 = require("./Cross");
|
|
35
35
|
const Tick_1 = require("./Tick");
|
|
@@ -138,7 +138,7 @@ const ToastProvider = ({ children, providerOptions, }) => {
|
|
|
138
138
|
const [toasts, setToasts] = (0, react_1.useState)([]);
|
|
139
139
|
const addToast = (message, options) => setToasts((currentToasts) => [
|
|
140
140
|
...currentToasts,
|
|
141
|
-
{ id: (0,
|
|
141
|
+
{ id: (0, random_1.random)(10000).toString(), message, options },
|
|
142
142
|
]);
|
|
143
143
|
const close = (id) => setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
144
144
|
const contextValue = (0, react_1.useMemo)(() => ({ addToast }), []);
|
|
@@ -14,9 +14,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.axiosHelper = void 0;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const
|
|
17
|
+
const const_1 = require("../../common/const");
|
|
18
18
|
const log_1 = require("../../common/helpers/log");
|
|
19
19
|
const object_1 = require("../../common/helpers/object");
|
|
20
|
+
const sleep_1 = require("../../common/helpers/sleep");
|
|
20
21
|
/**
|
|
21
22
|
*
|
|
22
23
|
* @param body accepts object or json, and passes as-is
|
|
@@ -80,12 +81,12 @@ const axiosHelper = ({ verb, url, body, headers, timeout = 30000, retryMax = 0,
|
|
|
80
81
|
onStaleAuth === null || onStaleAuth === void 0 ? void 0 : onStaleAuth();
|
|
81
82
|
retry = retryMax;
|
|
82
83
|
}
|
|
83
|
-
if (!
|
|
84
|
+
if (!const_1.retryHttpCodes.includes(c) || retry >= retryMax) {
|
|
84
85
|
throw em;
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
retry += 1;
|
|
88
|
-
yield (0,
|
|
89
|
+
yield (0, sleep_1.sleep)(const_1.retryHttpMs);
|
|
89
90
|
} while (retry <= retryMax);
|
|
90
91
|
throw new Error('unexpected');
|
|
91
92
|
});
|
|
@@ -14,8 +14,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.callOpenApiCached = exports.callOpenApiCachedRaw = exports.setOpenApiCacheRaw = void 0;
|
|
16
16
|
const node_cache_1 = __importDefault(require("node-cache"));
|
|
17
|
-
const
|
|
18
|
-
const
|
|
17
|
+
const hashCode_1 = require("../../../common/helpers/hashCode");
|
|
18
|
+
const base64_1 = require("../../../common/helpers/string/base64");
|
|
19
19
|
const direct_1 = require("./direct");
|
|
20
20
|
let callOpenApiCache;
|
|
21
21
|
/**
|
|
@@ -27,10 +27,10 @@ function getCacheKey({ cacheKey, overrideAuth, ssrCacheItems, }) {
|
|
|
27
27
|
const authkeyPrefix1 = (0, direct_1.getIdTokenAuthHeaderRaw)({
|
|
28
28
|
overrideAuth: overrideAuth,
|
|
29
29
|
});
|
|
30
|
-
const authPref = !authkeyPrefix1 ? '' : (0,
|
|
30
|
+
const authPref = !authkeyPrefix1 ? '' : (0, hashCode_1.hashCode)((0, base64_1.toBase64)(authkeyPrefix1));
|
|
31
31
|
const ssrCachePref = !ssrCacheItems
|
|
32
32
|
? ''
|
|
33
|
-
: (0,
|
|
33
|
+
: (0, hashCode_1.hashCode)((0, base64_1.toBase64)(JSON.stringify(ssrCacheItems)));
|
|
34
34
|
let cacheKeyRet;
|
|
35
35
|
if (cacheKey) {
|
|
36
36
|
cacheKeyRet = `${cacheKey}||${authPref}||${ssrCachePref}`;
|
|
@@ -1,24 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCookieString = exports.getCookieRawWrapper =
|
|
3
|
+
exports.getCookieString = exports.getCookieRawWrapper = void 0;
|
|
4
4
|
const log_1 = require("../../../common/helpers/log");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
function getCookieRaw({ name, cookieDocument, }) {
|
|
8
|
-
const nameeq = `${name}=`;
|
|
9
|
-
const ca1 = cookieDocument || (typeof window !== 'undefined' && document.cookie);
|
|
10
|
-
if (!ca1 || !(ca1 === null || ca1 === void 0 ? void 0 : ca1.trim())) {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
const ca = ca1.split(';').map((t) => t.trim());
|
|
14
|
-
const c = ca.find((c2) => c2.startsWith(nameeq));
|
|
15
|
-
if (c) {
|
|
16
|
-
const raw = c.substr(nameeq.length, c.length);
|
|
17
|
-
return raw;
|
|
18
|
-
}
|
|
19
|
-
return undefined;
|
|
20
|
-
}
|
|
21
|
-
exports.getCookieRaw = getCookieRaw;
|
|
5
|
+
const base64_1 = require("../../../common/helpers/string/base64");
|
|
6
|
+
const raw_1 = require("./raw");
|
|
22
7
|
/**
|
|
23
8
|
* read chunks. json parse+unb64
|
|
24
9
|
* parse defaults to JSON.parse. must change if want if type is not an object!
|
|
@@ -39,7 +24,7 @@ function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse: parseR
|
|
|
39
24
|
let currentCount = 0;
|
|
40
25
|
// eslint-disable-next-line no-constant-condition
|
|
41
26
|
while (true) {
|
|
42
|
-
const newv =
|
|
27
|
+
const newv = (0, raw_1.getCookie)({
|
|
43
28
|
name: name + currentCount,
|
|
44
29
|
cookieDocument,
|
|
45
30
|
});
|
|
@@ -50,11 +35,11 @@ function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse: parseR
|
|
|
50
35
|
currentCount += 1;
|
|
51
36
|
}
|
|
52
37
|
try {
|
|
53
|
-
return parse((0,
|
|
38
|
+
return parse((0, base64_1.fromBase64)(raw));
|
|
54
39
|
}
|
|
55
40
|
catch (e) {
|
|
56
41
|
(0, log_1.warn)('cookie error:', e);
|
|
57
|
-
(0,
|
|
42
|
+
(0, raw_1.wipeCookies)(name);
|
|
58
43
|
return defaultValue;
|
|
59
44
|
}
|
|
60
45
|
}
|
|
@@ -16,5 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./const"), exports);
|
|
18
18
|
__exportStar(require("./get"), exports);
|
|
19
|
+
__exportStar(require("./raw"), exports);
|
|
19
20
|
__exportStar(require("./set"), exports);
|
|
20
21
|
__exportStar(require("./use"), exports);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* parse cookie string into key values
|
|
3
|
+
* @param cookieString
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export declare const getAllCookies: (cookieString?: string) => Record<string, string>;
|
|
7
|
+
/** get a cookie by name*/
|
|
8
|
+
export declare const getCookie: ({ name, cookieDocument, }: {
|
|
9
|
+
name: string;
|
|
10
|
+
cookieDocument?: string | undefined;
|
|
11
|
+
}) => string;
|
|
12
|
+
/**
|
|
13
|
+
* expiryDays <0 will delete
|
|
14
|
+
* @param param0
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function setCookie({ name, value, expiryDays, }: {
|
|
18
|
+
name: string;
|
|
19
|
+
value: string;
|
|
20
|
+
/**
|
|
21
|
+
* defaults to 1
|
|
22
|
+
*/
|
|
23
|
+
expiryDays?: number;
|
|
24
|
+
}): void;
|
|
25
|
+
/** delete all non httponly cookies */
|
|
26
|
+
export declare function wipeCookies(name: string): void;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.wipeCookies = exports.setCookie = exports.getCookie = exports.getAllCookies = void 0;
|
|
4
|
+
const log_1 = require("../../../common/helpers/log");
|
|
5
|
+
const const_1 = require("./const");
|
|
6
|
+
/**
|
|
7
|
+
* parse cookie string into key values
|
|
8
|
+
* @param cookieString
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
const getAllCookies = (cookieString) => {
|
|
12
|
+
const cookieKeyValuePairs = {};
|
|
13
|
+
if (!cookieString) {
|
|
14
|
+
return cookieKeyValuePairs;
|
|
15
|
+
}
|
|
16
|
+
// Split the cookie string into an array of strings
|
|
17
|
+
const cookieArr = cookieString.split(';');
|
|
18
|
+
// Loop through the array of strings
|
|
19
|
+
for (let i = 0; i < cookieArr.length; i++) {
|
|
20
|
+
// Split each string into an array of key and value
|
|
21
|
+
const cookieKeyValue = cookieArr[i].split('=');
|
|
22
|
+
// Add the key value pair to the object
|
|
23
|
+
cookieKeyValuePairs[cookieKeyValue[0].trim()] = cookieKeyValue[1].trim();
|
|
24
|
+
}
|
|
25
|
+
return cookieKeyValuePairs;
|
|
26
|
+
};
|
|
27
|
+
exports.getAllCookies = getAllCookies;
|
|
28
|
+
/** get a cookie by name*/
|
|
29
|
+
const getCookie = ({ name, cookieDocument, }) => { var _a; return (_a = (0, exports.getAllCookies)(cookieDocument)) === null || _a === void 0 ? void 0 : _a[name]; };
|
|
30
|
+
exports.getCookie = getCookie;
|
|
31
|
+
/**
|
|
32
|
+
* expiryDays <0 will delete
|
|
33
|
+
* @param param0
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
function setCookie({ name, value, expiryDays = 1, }) {
|
|
37
|
+
if (typeof window === undefined) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const d = new Date();
|
|
41
|
+
d.setTime(d.getTime() + expiryDays * 24 * 60 * 60 * 1000);
|
|
42
|
+
const expires = `expires=${!value || expiryDays < 0 ? const_1.expireDate : d.toUTCString()}`;
|
|
43
|
+
document.cookie = `${name}=${!value ? '' : value};${expires};path=/; SameSite=Strict; Secure`;
|
|
44
|
+
}
|
|
45
|
+
exports.setCookie = setCookie;
|
|
46
|
+
/** delete all non httponly cookies */
|
|
47
|
+
function wipeCookies(name) {
|
|
48
|
+
if (typeof window === 'undefined') {
|
|
49
|
+
(0, log_1.warn)('cant wipe cookies on server');
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
let currentCount = 0;
|
|
53
|
+
// eslint-disable-next-line no-constant-condition
|
|
54
|
+
while (true) {
|
|
55
|
+
if ((0, exports.getCookie)({
|
|
56
|
+
name: name + currentCount,
|
|
57
|
+
cookieDocument: '',
|
|
58
|
+
})) {
|
|
59
|
+
setCookie({ name: name + currentCount, value: '', expiryDays: -1 });
|
|
60
|
+
currentCount += 1;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.wipeCookies = wipeCookies;
|
|
@@ -1,45 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setCookieString = exports.setCookieRawWrapper =
|
|
4
|
-
const
|
|
5
|
-
const
|
|
3
|
+
exports.setCookieString = exports.setCookieRawWrapper = void 0;
|
|
4
|
+
const base64_1 = require("../../../common/helpers/string/base64");
|
|
5
|
+
const chunk_1 = require("../../../common/helpers/string/chunk");
|
|
6
6
|
const const_1 = require("./const");
|
|
7
|
-
const
|
|
8
|
-
/**
|
|
9
|
-
* expiryDays <0 will delete
|
|
10
|
-
* @param param0
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
function setCookieRaw({ name, value, expiryDays = 1, }) {
|
|
14
|
-
if (typeof window === undefined) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const d = new Date();
|
|
18
|
-
d.setTime(d.getTime() + expiryDays * 24 * 60 * 60 * 1000);
|
|
19
|
-
const expires = `expires=${!value || expiryDays < 0 ? const_1.expireDate : d.toUTCString()}`;
|
|
20
|
-
document.cookie = `${name}=${!value ? '' : value};${expires};path=/; SameSite=Strict; Secure`;
|
|
21
|
-
}
|
|
22
|
-
function wipeCookies(name) {
|
|
23
|
-
if (typeof window === 'undefined') {
|
|
24
|
-
(0, log_1.warn)('cant wipe cookies on server');
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
let currentCount = 0;
|
|
28
|
-
// eslint-disable-next-line no-constant-condition
|
|
29
|
-
while (true) {
|
|
30
|
-
if ((0, get_1.getCookieRaw)({
|
|
31
|
-
name: name + currentCount,
|
|
32
|
-
cookieDocument: '',
|
|
33
|
-
})) {
|
|
34
|
-
setCookieRaw({ name: name + currentCount, value: '', expiryDays: -1 });
|
|
35
|
-
currentCount += 1;
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.wipeCookies = wipeCookies;
|
|
7
|
+
const raw_1 = require("./raw");
|
|
43
8
|
/**
|
|
44
9
|
* json+b64 incoming. chunk. write chunks
|
|
45
10
|
* @param p
|
|
@@ -52,15 +17,15 @@ function setCookieRawWrapper(p) {
|
|
|
52
17
|
}
|
|
53
18
|
return JSON.stringify(s);
|
|
54
19
|
};
|
|
55
|
-
wipeCookies(p.name);
|
|
20
|
+
(0, raw_1.wipeCookies)(p.name);
|
|
56
21
|
if (!p.value) {
|
|
57
22
|
return;
|
|
58
23
|
}
|
|
59
|
-
const str = (0,
|
|
60
|
-
const chunks = (0,
|
|
24
|
+
const str = (0, base64_1.toBase64)(stringify(p.value));
|
|
25
|
+
const chunks = (0, chunk_1.chunkString)(str, const_1.maxCookieLen);
|
|
61
26
|
for (const index1 in chunks) {
|
|
62
27
|
const chunk = chunks[index1];
|
|
63
|
-
|
|
28
|
+
(0, raw_1.setCookie)(Object.assign(Object.assign({}, p), { name: p.name + index1, value: chunk }));
|
|
64
29
|
}
|
|
65
30
|
}
|
|
66
31
|
exports.setCookieRawWrapper = setCookieRawWrapper;
|
|
@@ -4,7 +4,7 @@ exports.getServerReq = exports.getClientOrServerReqHref = void 0;
|
|
|
4
4
|
const url_1 = require("url");
|
|
5
5
|
const i18n_1 = require("../../common/helpers/i18n");
|
|
6
6
|
const object_1 = require("../../common/helpers/object");
|
|
7
|
-
const
|
|
7
|
+
const object_2 = require("../../common/helpers/string/object");
|
|
8
8
|
const calculateServerHref = ({ host, pathname, }) => {
|
|
9
9
|
if (!host) {
|
|
10
10
|
return undefined;
|
|
@@ -59,7 +59,7 @@ const getClientOrServerReqHref = ({ url: { href, query, protocol }, forceServer
|
|
|
59
59
|
path: `${parsed.path}${parsed.hash || ''}`,
|
|
60
60
|
pathname: parsed.pathname || '',
|
|
61
61
|
protocol: protocol || '',
|
|
62
|
-
query: Object.assign(Object.assign({}, query), (0,
|
|
62
|
+
query: Object.assign(Object.assign({}, query), (0, object_2.stringToObject)(parsed.query || '', '=', '&')),
|
|
63
63
|
};
|
|
64
64
|
return {
|
|
65
65
|
url,
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useQueryStringSingle = exports.useQueryStringArray = exports.useQueryStringRaw = exports.isServer = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
-
const
|
|
5
|
+
const log_1 = require("../../common/helpers/log");
|
|
6
6
|
const object_1 = require("../../common/helpers/object");
|
|
7
7
|
exports.isServer = typeof window === 'undefined';
|
|
8
8
|
/**
|
|
@@ -31,7 +31,7 @@ const useQueryStringRaw = ({ name, queryValues, defaultValue, stringify, parse,
|
|
|
31
31
|
window.history.replaceState({}, '', loc);
|
|
32
32
|
}
|
|
33
33
|
else {
|
|
34
|
-
(0,
|
|
34
|
+
(0, log_1.info)('cant change url params on server');
|
|
35
35
|
}
|
|
36
36
|
setStateRaw(v);
|
|
37
37
|
};
|
package/package.json
CHANGED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
export declare const toBase64: (str: string) => string;
|
|
2
|
-
export declare const fromBase64: (str: string) => string;
|
|
3
|
-
export declare const csvJSON: (csv: string) => {}[];
|
|
4
|
-
export declare function trimSide(str: string, fromStart?: boolean, ...params: string[]): string;
|
|
5
|
-
export declare function trim(str: string, ...params: string[]): string;
|
|
6
|
-
export declare function truncate(str: string | null | undefined, n: number, ellip: string): string | undefined;
|
|
7
|
-
export interface ISite {
|
|
8
|
-
siteUrl: string;
|
|
9
|
-
niceSiteUrl: string;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* removes protocol, and trailing slashes
|
|
13
|
-
*/
|
|
14
|
-
export declare const niceUrl: (siteUrl: string) => ISite | undefined;
|
|
15
|
-
/**
|
|
16
|
-
* string -> String
|
|
17
|
-
* @param str
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
export declare function toTitleCase(str: string): string;
|
|
21
|
-
/**
|
|
22
|
-
* remove all found params from str
|
|
23
|
-
* @param str
|
|
24
|
-
* @param params allows single chars and/or strings
|
|
25
|
-
* @returns
|
|
26
|
-
*/
|
|
27
|
-
export declare function replaceRemove(str: string, ...params: string[]): string;
|
|
28
|
-
/**
|
|
29
|
-
* returns >-1 if found
|
|
30
|
-
* @param str
|
|
31
|
-
* @param args
|
|
32
|
-
* @returns
|
|
33
|
-
*/
|
|
34
|
-
export declare function containsInsensitiveIndex({ str, fromLast, }: {
|
|
35
|
-
/**
|
|
36
|
-
* if true, will return highest number. default false
|
|
37
|
-
*/
|
|
38
|
-
fromLast?: boolean;
|
|
39
|
-
str: string;
|
|
40
|
-
}, ...args: string[]): number;
|
|
41
|
-
/**
|
|
42
|
-
* returns true if text is found
|
|
43
|
-
* @param str
|
|
44
|
-
* @param args
|
|
45
|
-
* @returns
|
|
46
|
-
*/
|
|
47
|
-
export declare const containsInsensitive: (str: string, ...args: string[]) => boolean;
|
|
48
|
-
/**
|
|
49
|
-
* safely handles circular references
|
|
50
|
-
* @param obj
|
|
51
|
-
* @param indent
|
|
52
|
-
* @returns
|
|
53
|
-
*/
|
|
54
|
-
export declare const safeStringify: (obj: unknown, indent?: number) => string;
|
|
55
|
-
export declare const chunkString: (str: string, length: number) => string[];
|
|
56
|
-
/**
|
|
57
|
-
* object to string - can be used for querystring a=b&c=d etc
|
|
58
|
-
* @param raw eg a=b&c=d
|
|
59
|
-
* @param splitKeyValue eg =
|
|
60
|
-
* @param splitKeys eg &
|
|
61
|
-
*/
|
|
62
|
-
export declare function stringToObject(raw: string, splitKeyValue: string, splitKeys: string): Record<string, string>;
|
|
63
|
-
export declare const indexOfNumber: (str: string, char: string, num?: number) => number | undefined;
|
|
64
|
-
export declare function isValidUrl(raw: string): boolean;
|