ag-common 0.0.395 → 0.0.397
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/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/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.js +2 -2
- package/dist/ui/helpers/cookie/set.js +4 -3
- package/dist/ui/helpers/routes.js +2 -2
- package/dist/ui/helpers/useQueryString.js +2 -2
- package/package.json +3 -3
- package/dist/common/helpers/string.d.ts +0 -64
- package/dist/common/helpers/string.js +0 -210
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.enforceDynamoProvisionCap = void 0;
|
|
4
4
|
const log_1 = require("../../common/helpers/log");
|
|
5
5
|
const math_1 = require("../../common/helpers/math");
|
|
6
|
-
const
|
|
6
|
+
const json_1 = require("../../common/helpers/string/json");
|
|
7
|
+
const trim_1 = require("../../common/helpers/string/trim");
|
|
7
8
|
const extractSum = ({ str, regex }) => {
|
|
8
9
|
var _a;
|
|
9
10
|
return (0, math_1.sumArray)(((_a = str
|
|
10
|
-
.match(regex)) === null || _a === void 0 ? void 0 : _a.map((s2) => (0,
|
|
11
|
+
.match(regex)) === null || _a === void 0 ? void 0 : _a.map((s2) => (0, trim_1.trim)(s2.substring(s2.indexOf(':') + 1), ':', ',', ' ')).filter((r) => r && Number(r)).map((r) => Number(r))) || []);
|
|
11
12
|
};
|
|
12
13
|
/** ensure that dynamo tables in stack dont exceed passed in provisioned limits */
|
|
13
14
|
const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, mustEqual = false, }) => {
|
|
@@ -17,7 +18,7 @@ const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, must
|
|
|
17
18
|
}
|
|
18
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
20
|
const t = tables[0];
|
|
20
|
-
const s = (0,
|
|
21
|
+
const s = (0, json_1.safeStringify)(t.node._children.Resource.node.scope);
|
|
21
22
|
const reads = extractSum({ str: s, regex: /readCapacityUnits.*/gim });
|
|
22
23
|
const writes = extractSum({ str: s, regex: /writeCapacityUnits.*/gim });
|
|
23
24
|
(0, log_1.warn)(`dynamo table provisioned reads:${reads}/${readsMax}`);
|
package/dist/api/helpers/sqs.js
CHANGED
|
@@ -14,7 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.sendMessages = exports.setSqs = exports.sqs = void 0;
|
|
16
16
|
const sqs_1 = __importDefault(require("aws-sdk/clients/sqs"));
|
|
17
|
-
const
|
|
17
|
+
const hashCode_1 = require("../../common/helpers/hashCode");
|
|
18
18
|
// eslint-disable-next-line import/no-mutable-exports
|
|
19
19
|
exports.sqs = new sqs_1.default();
|
|
20
20
|
const setSqs = (region) => {
|
|
@@ -26,7 +26,7 @@ const sendMessages = (items, queueUrl) => __awaiter(void 0, void 0, void 0, func
|
|
|
26
26
|
QueueUrl: queueUrl,
|
|
27
27
|
Entries: items.map((i) => ({
|
|
28
28
|
MessageBody: JSON.stringify(i),
|
|
29
|
-
Id: (0,
|
|
29
|
+
Id: (0, hashCode_1.hashCode)(JSON.stringify(i)),
|
|
30
30
|
})),
|
|
31
31
|
};
|
|
32
32
|
const put = yield exports.sqs.sendMessageBatch(req).promise();
|
package/dist/api/helpers/ssm.js
CHANGED
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadSsmStringList = exports.loadSsmString = exports.saveToSsm = void 0;
|
|
4
4
|
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
5
|
-
const
|
|
5
|
+
const base64_1 = require("../../common/helpers/string/base64");
|
|
6
6
|
/**
|
|
7
7
|
* save a value to ssm
|
|
8
8
|
* @param param0
|
|
9
9
|
*/
|
|
10
10
|
const saveToSsm = ({ stack, path, value, }) => {
|
|
11
|
-
const name = (0,
|
|
11
|
+
const name = (0, base64_1.toBase64)(path);
|
|
12
12
|
new aws_cdk_lib_1.aws_ssm.StringParameter(stack, name, {
|
|
13
13
|
allowedPattern: '.*',
|
|
14
14
|
description: `${name} (cdk)`,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.base64ToBinary = exports.arrayBufferToBase64 = void 0;
|
|
4
|
-
const
|
|
4
|
+
const base64_1 = require("./string/base64");
|
|
5
5
|
function toBuffer(ab) {
|
|
6
6
|
const buffer = new Buffer(ab.byteLength);
|
|
7
7
|
const view = new Uint8Array(ab);
|
|
@@ -11,7 +11,7 @@ function toBuffer(ab) {
|
|
|
11
11
|
return buffer;
|
|
12
12
|
}
|
|
13
13
|
function toArrayBuffer(base64) {
|
|
14
|
-
const binary_string = (0,
|
|
14
|
+
const binary_string = (0, base64_1.fromBase64)(base64);
|
|
15
15
|
const len = binary_string.length;
|
|
16
16
|
const bytes = new Uint8Array(len);
|
|
17
17
|
for (let i = 0; i < len; i += 1) {
|
|
@@ -31,7 +31,7 @@ function arrayBufferToBase64(buffer) {
|
|
|
31
31
|
for (let i = 0; i < len; i += 1) {
|
|
32
32
|
binary += String.fromCharCode(bytes[i]);
|
|
33
33
|
}
|
|
34
|
-
return (0,
|
|
34
|
+
return (0, base64_1.toBase64)(binary);
|
|
35
35
|
}
|
|
36
36
|
exports.arrayBufferToBase64 = arrayBufferToBase64;
|
|
37
37
|
/**
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fromBase64 = exports.toBase64 = void 0;
|
|
4
|
+
const toBase64 = (str) => Buffer.from(str).toString('base64');
|
|
5
|
+
exports.toBase64 = toBase64;
|
|
6
|
+
const fromBase64 = (str) => Buffer.from(decodeURIComponent(str), 'base64').toString();
|
|
7
|
+
exports.fromBase64 = fromBase64;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const chunkString: (str: string, length: number) => string[];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* returns >-1 if found
|
|
3
|
+
* @param str
|
|
4
|
+
* @param args
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare function containsInsensitiveIndex({ str, fromLast, }: {
|
|
8
|
+
/**
|
|
9
|
+
* if true, will return highest number. default false
|
|
10
|
+
*/
|
|
11
|
+
fromLast?: boolean;
|
|
12
|
+
str: string;
|
|
13
|
+
}, ...args: string[]): number;
|
|
14
|
+
/**
|
|
15
|
+
* returns true if text is found
|
|
16
|
+
* @param str
|
|
17
|
+
* @param args
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare const containsInsensitive: (str: string, ...args: string[]) => boolean;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.containsInsensitive = exports.containsInsensitiveIndex = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* returns >-1 if found
|
|
6
|
+
* @param str
|
|
7
|
+
* @param args
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
function containsInsensitiveIndex({ str, fromLast = false, }, ...args) {
|
|
11
|
+
if (!str || !args) {
|
|
12
|
+
return -1;
|
|
13
|
+
}
|
|
14
|
+
const largs = args.map((a) => a.toLowerCase());
|
|
15
|
+
const lstr = str.toLowerCase();
|
|
16
|
+
const finds = largs
|
|
17
|
+
.map((arg) => (fromLast ? lstr.lastIndexOf(arg) : lstr.indexOf(arg)))
|
|
18
|
+
.filter((s) => s !== -1)
|
|
19
|
+
.sort();
|
|
20
|
+
if (finds.length === 0) {
|
|
21
|
+
return -1;
|
|
22
|
+
}
|
|
23
|
+
return !fromLast ? finds[0] : finds[finds.length - 1];
|
|
24
|
+
}
|
|
25
|
+
exports.containsInsensitiveIndex = containsInsensitiveIndex;
|
|
26
|
+
/**
|
|
27
|
+
* returns true if text is found
|
|
28
|
+
* @param str
|
|
29
|
+
* @param args
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
const containsInsensitive = (str, ...args) => containsInsensitiveIndex({ str }, ...args) !== -1;
|
|
33
|
+
exports.containsInsensitive = containsInsensitive;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface IGetExtendedStringSegment {
|
|
2
|
+
/** based on original full text */
|
|
3
|
+
outerStart: number;
|
|
4
|
+
/** based on original full text */
|
|
5
|
+
outerEnd: number;
|
|
6
|
+
/** words including the gaps (probably what you want) */
|
|
7
|
+
outerText: string;
|
|
8
|
+
/** the start index of the searched term in outerText */
|
|
9
|
+
innerStart: number;
|
|
10
|
+
/** the end index of the searched term in outerText */
|
|
11
|
+
innerEnd: number;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* will return a piece of text around a found term, and the index it was found
|
|
15
|
+
* @param hay
|
|
16
|
+
* @param needle
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare const getExtendedStringSegment: (hay: string, needle: string, blocksOnEitherSide?: number, gapChars?: string[]) => undefined | IGetExtendedStringSegment;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getExtendedStringSegment = void 0;
|
|
4
|
+
const contains_1 = require("./contains");
|
|
5
|
+
/**
|
|
6
|
+
* will return a piece of text around a found term, and the index it was found
|
|
7
|
+
* @param hay
|
|
8
|
+
* @param needle
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
const getExtendedStringSegment = (hay, needle, blocksOnEitherSide = 5,
|
|
12
|
+
/** can override this if space bounded words are required */
|
|
13
|
+
gapChars = ['\n', '\r\n']) => {
|
|
14
|
+
const fi = (0, contains_1.containsInsensitiveIndex)({ str: hay }, needle);
|
|
15
|
+
if (fi === -1) {
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
let start = fi;
|
|
19
|
+
//we want to extend the partial content back to -(gap) gapChars
|
|
20
|
+
for (let a = 0; a <= blocksOnEitherSide; a += 1) {
|
|
21
|
+
const newstartI = (0, contains_1.containsInsensitiveIndex)({ str: hay.substring(0, start), fromLast: true }, ...gapChars);
|
|
22
|
+
if (newstartI !== -1) {
|
|
23
|
+
start = newstartI;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//and forward
|
|
27
|
+
let end = fi + needle.length;
|
|
28
|
+
for (let a = 0; a <= blocksOnEitherSide; a += 1) {
|
|
29
|
+
const newEndI = (0, contains_1.containsInsensitiveIndex)({ str: hay.substring(end) }, ...gapChars);
|
|
30
|
+
if (newEndI !== -1) {
|
|
31
|
+
end += newEndI + 1;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
const outerText = hay.substring(start, end);
|
|
35
|
+
const innerStart = outerText.toLowerCase().indexOf(needle.toLowerCase());
|
|
36
|
+
return {
|
|
37
|
+
outerStart: start,
|
|
38
|
+
outerEnd: end,
|
|
39
|
+
outerText,
|
|
40
|
+
innerStart,
|
|
41
|
+
innerEnd: innerStart + needle.length,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
exports.getExtendedStringSegment = getExtendedStringSegment;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './base64';
|
|
2
|
+
export * from './chunk';
|
|
3
|
+
export * from './contains';
|
|
4
|
+
export * from './getExtendedStringSegment';
|
|
5
|
+
export * from './json';
|
|
6
|
+
export * from './object';
|
|
7
|
+
export * from './surround';
|
|
8
|
+
export * from './trim';
|
|
9
|
+
export * from './truncate';
|
|
10
|
+
export * from './url';
|
|
@@ -0,0 +1,26 @@
|
|
|
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("./base64"), exports);
|
|
18
|
+
__exportStar(require("./chunk"), exports);
|
|
19
|
+
__exportStar(require("./contains"), exports);
|
|
20
|
+
__exportStar(require("./getExtendedStringSegment"), exports);
|
|
21
|
+
__exportStar(require("./json"), exports);
|
|
22
|
+
__exportStar(require("./object"), exports);
|
|
23
|
+
__exportStar(require("./surround"), exports);
|
|
24
|
+
__exportStar(require("./trim"), exports);
|
|
25
|
+
__exportStar(require("./truncate"), exports);
|
|
26
|
+
__exportStar(require("./url"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeStringify = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* safely handles circular references
|
|
6
|
+
* @param obj
|
|
7
|
+
* @param indent
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
const safeStringify = (obj, indent = 2) => {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
let cache = [];
|
|
13
|
+
const retVal = JSON.stringify(obj, (_key, value) => typeof value === 'object' && value !== null
|
|
14
|
+
? cache.includes(value)
|
|
15
|
+
? undefined // Duplicate reference found, discard key
|
|
16
|
+
: cache.push(value) && value // Store value in our collection
|
|
17
|
+
: value, indent);
|
|
18
|
+
cache = null;
|
|
19
|
+
return retVal;
|
|
20
|
+
};
|
|
21
|
+
exports.safeStringify = safeStringify;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* object to string - can be used for querystring a=b&c=d etc
|
|
3
|
+
* @param raw eg a=b&c=d
|
|
4
|
+
* @param splitKeyValue eg =
|
|
5
|
+
* @param splitKeys eg &
|
|
6
|
+
*/
|
|
7
|
+
export declare function stringToObject(raw: string, splitKeyValue: string, splitKeys: string): Record<string, string>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringToObject = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* object to string - can be used for querystring a=b&c=d etc
|
|
6
|
+
* @param raw eg a=b&c=d
|
|
7
|
+
* @param splitKeyValue eg =
|
|
8
|
+
* @param splitKeys eg &
|
|
9
|
+
*/
|
|
10
|
+
function stringToObject(raw, splitKeyValue, splitKeys) {
|
|
11
|
+
const ret = {};
|
|
12
|
+
if (!stringToObject) {
|
|
13
|
+
return ret;
|
|
14
|
+
}
|
|
15
|
+
raw.split(splitKeys).forEach((set) => {
|
|
16
|
+
const [k, v] = set.split(splitKeyValue);
|
|
17
|
+
if (k) {
|
|
18
|
+
ret[k] = v;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return ret;
|
|
22
|
+
}
|
|
23
|
+
exports.stringToObject = stringToObject;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** surround a substring of text with a value */
|
|
2
|
+
export declare const surround: <T>({ text, start, end, surround, }: {
|
|
3
|
+
text: string;
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
/** contains will be true when between start + end */
|
|
7
|
+
surround: (s: string, contains: boolean) => T;
|
|
8
|
+
}) => T[];
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.surround = void 0;
|
|
4
|
+
/** surround a substring of text with a value */
|
|
5
|
+
const surround = ({ text, start, end, surround, }) => [
|
|
6
|
+
surround(text.slice(0, start), false),
|
|
7
|
+
surround(text.slice(start, end), true),
|
|
8
|
+
surround(text.slice(end), false),
|
|
9
|
+
];
|
|
10
|
+
exports.surround = surround;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.trim = exports.trimSide = void 0;
|
|
4
|
+
function trimSide(str, fromStart = true, ...params) {
|
|
5
|
+
const pstr = params.join('');
|
|
6
|
+
if (!str) {
|
|
7
|
+
return str;
|
|
8
|
+
}
|
|
9
|
+
const ret = str.replace(new RegExp(`[${pstr}]*$`, 'g'), '');
|
|
10
|
+
if (fromStart) {
|
|
11
|
+
return ret.replace(new RegExp(`^[${pstr}]*`, 'g'), '');
|
|
12
|
+
}
|
|
13
|
+
return ret;
|
|
14
|
+
}
|
|
15
|
+
exports.trimSide = trimSide;
|
|
16
|
+
function trim(str, ...params) {
|
|
17
|
+
if (!str) {
|
|
18
|
+
return '';
|
|
19
|
+
}
|
|
20
|
+
str = trimSide(str, true, ...params);
|
|
21
|
+
str = trimSide(str, false, ...params);
|
|
22
|
+
return str;
|
|
23
|
+
}
|
|
24
|
+
exports.trim = trim;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function truncate(str: string | null | undefined, n: number, ellip: string): string | undefined;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.truncate = void 0;
|
|
4
|
+
function truncate(str, n, ellip) {
|
|
5
|
+
if (!str) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return str.length > n ? str.substr(0, n - 1) + ellip : str;
|
|
9
|
+
}
|
|
10
|
+
exports.truncate = truncate;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isValidUrl = exports.niceUrl = void 0;
|
|
4
|
+
const trim_1 = require("./trim");
|
|
5
|
+
/**
|
|
6
|
+
* removes protocol, and trailing slashes
|
|
7
|
+
*/
|
|
8
|
+
const niceUrl = (siteUrl) => {
|
|
9
|
+
if (!siteUrl) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
let niceSiteUrl = siteUrl
|
|
13
|
+
.substring(siteUrl.indexOf(':') + 1)
|
|
14
|
+
.replace('sc-domain:', '')
|
|
15
|
+
.replace('https://', '')
|
|
16
|
+
.replace('http://', '');
|
|
17
|
+
niceSiteUrl = (0, trim_1.trim)(niceSiteUrl, '/');
|
|
18
|
+
return { siteUrl, niceSiteUrl };
|
|
19
|
+
};
|
|
20
|
+
exports.niceUrl = niceUrl;
|
|
21
|
+
function isValidUrl(raw) {
|
|
22
|
+
let url;
|
|
23
|
+
try {
|
|
24
|
+
url = new URL(raw);
|
|
25
|
+
}
|
|
26
|
+
catch (_) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
30
|
+
}
|
|
31
|
+
exports.isValidUrl = isValidUrl;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.DashboardAuthValidation = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
8
|
const log_1 = require("../../../common/helpers/log");
|
|
9
|
-
const
|
|
9
|
+
const base64_1 = require("../../../common/helpers/string/base64");
|
|
10
10
|
const useGranularHook_1 = require("../../helpers/useGranularHook");
|
|
11
11
|
const useQueryString_1 = require("../../helpers/useQueryString");
|
|
12
12
|
const Loader_1 = require("../Loader");
|
|
@@ -41,7 +41,7 @@ const DashboardAuthValidation = ({ rc: { request, pushPath }, cac: { error: auth
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
if (request.url.query.state && isAuthenticated) {
|
|
44
|
-
const decoded = JSON.parse((0,
|
|
44
|
+
const decoded = JSON.parse((0, base64_1.fromBase64)(request.url.query.state));
|
|
45
45
|
if (decoded.redirect) {
|
|
46
46
|
void pushPath(decoded.redirect);
|
|
47
47
|
return { render: react_1.default.createElement(react_1.default.Fragment, null), openApiDisabled: true };
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getSecurityLine = void 0;
|
|
7
7
|
const react_1 = __importDefault(require("react"));
|
|
8
|
-
const string_1 = require("../../../../../common/helpers/string");
|
|
9
8
|
const common_1 = require("../../helpers/common");
|
|
10
9
|
const getSecurityLine = (p, { operation }) => {
|
|
11
10
|
const sec = (0, common_1.getSecurity)(p, { operation });
|
|
@@ -20,9 +19,8 @@ const getSecurityLine = (p, { operation }) => {
|
|
|
20
19
|
react_1.default.createElement("span", null, "--header "),
|
|
21
20
|
react_1.default.createElement(common_1.Highlight, null,
|
|
22
21
|
"'",
|
|
23
|
-
|
|
24
|
-
":",
|
|
25
|
-
' ',
|
|
22
|
+
sec.name,
|
|
23
|
+
": ",
|
|
26
24
|
react_1.default.createElement(common_1.Highlight2, null, p.apiKey || '(API KEY)'),
|
|
27
25
|
"'"))),
|
|
28
26
|
};
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.Curl = void 0;
|
|
7
7
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
8
8
|
const react_1 = __importDefault(require("react"));
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const array_1 = require("../../../../common/helpers/array");
|
|
10
|
+
const common_1 = require("../helpers/common");
|
|
11
11
|
const joinJsx_1 = require("../helpers/joinJsx");
|
|
12
12
|
const getCurlLines_1 = require("./helpers/getCurlLines");
|
|
13
13
|
const Base = styled_1.default.div `
|
|
@@ -22,13 +22,13 @@ const Curl = ({ ops, p, }) => {
|
|
|
22
22
|
verb.toUpperCase()),
|
|
23
23
|
react_1.default.createElement(react_1.default.Fragment, null,
|
|
24
24
|
"--url ",
|
|
25
|
-
react_1.default.createElement(
|
|
25
|
+
react_1.default.createElement(common_1.Highlight, null,
|
|
26
26
|
"'",
|
|
27
27
|
fullApiUrl,
|
|
28
28
|
"'")),
|
|
29
29
|
...(headerLines || []),
|
|
30
30
|
bodyLine,
|
|
31
|
-
].filter(
|
|
31
|
+
].filter(array_1.notEmpty);
|
|
32
32
|
return react_1.default.createElement(Base, null, (0, joinJsx_1.joinJsxWithSlash)(rows));
|
|
33
33
|
};
|
|
34
34
|
exports.Curl = Curl;
|
|
@@ -6,8 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getRequestOptions = void 0;
|
|
7
7
|
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
8
8
|
const react_1 = __importDefault(require("react"));
|
|
9
|
-
const common_1 = require("
|
|
10
|
-
const common_2 = require("../../helpers/common");
|
|
9
|
+
const common_1 = require("../../helpers/common");
|
|
11
10
|
const joinJsx_1 = require("../../helpers/joinJsx");
|
|
12
11
|
const rb = react_1.default.createElement(react_1.default.Fragment, null, "}");
|
|
13
12
|
const lb = react_1.default.createElement(react_1.default.Fragment, null, "{");
|
|
@@ -15,28 +14,28 @@ const Lpad = styled_1.default.div `
|
|
|
15
14
|
padding-left: 0.5rem;
|
|
16
15
|
`;
|
|
17
16
|
const getRequestOptions = (p, ops) => {
|
|
18
|
-
const { nice } = (0,
|
|
17
|
+
const { nice } = (0, common_1.getBodyJson)(p) || {};
|
|
19
18
|
if (!nice) {
|
|
20
19
|
return undefined;
|
|
21
20
|
}
|
|
22
|
-
const sec = (0,
|
|
21
|
+
const sec = (0, common_1.getSecurity)(p, ops);
|
|
23
22
|
const h1 = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
24
23
|
' ',
|
|
25
|
-
react_1.default.createElement(
|
|
24
|
+
react_1.default.createElement(common_1.Highlight, null, "'Content-Type'"),
|
|
26
25
|
":",
|
|
27
26
|
' ',
|
|
28
|
-
react_1.default.createElement(
|
|
27
|
+
react_1.default.createElement(common_1.Highlight, null, "'application/json'")));
|
|
29
28
|
let h2;
|
|
30
29
|
if (sec) {
|
|
31
30
|
h2 = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
32
31
|
' ',
|
|
33
|
-
react_1.default.createElement(
|
|
32
|
+
react_1.default.createElement(common_1.Highlight, null,
|
|
34
33
|
"'",
|
|
35
|
-
|
|
34
|
+
sec.name,
|
|
36
35
|
"'"),
|
|
37
36
|
":",
|
|
38
37
|
' ',
|
|
39
|
-
react_1.default.createElement(
|
|
38
|
+
react_1.default.createElement(common_1.Highlight, null,
|
|
40
39
|
"'",
|
|
41
40
|
p.apiKey || '(API KEY)',
|
|
42
41
|
"'")));
|
|
@@ -49,9 +48,9 @@ const getRequestOptions = (p, ops) => {
|
|
|
49
48
|
","));
|
|
50
49
|
const body = (react_1.default.createElement(react_1.default.Fragment, null,
|
|
51
50
|
"body: ",
|
|
52
|
-
react_1.default.createElement(
|
|
51
|
+
react_1.default.createElement(common_1.Highlight2, null, "JSON"),
|
|
53
52
|
".",
|
|
54
|
-
react_1.default.createElement(
|
|
53
|
+
react_1.default.createElement(common_1.Highlight, null, "stringify"),
|
|
55
54
|
"(",
|
|
56
55
|
nice,
|
|
57
56
|
")"));
|
|
@@ -60,7 +59,7 @@ const getRequestOptions = (p, ops) => {
|
|
|
60
59
|
lb,
|
|
61
60
|
react_1.default.createElement(Lpad, null,
|
|
62
61
|
"method: ",
|
|
63
|
-
react_1.default.createElement(
|
|
62
|
+
react_1.default.createElement(common_1.Highlight, null,
|
|
64
63
|
"'",
|
|
65
64
|
ops.verb.toUpperCase(),
|
|
66
65
|
"'"),
|
|
@@ -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}`;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getCookieString = exports.getCookieRawWrapper = void 0;
|
|
4
4
|
const log_1 = require("../../../common/helpers/log");
|
|
5
|
-
const
|
|
5
|
+
const base64_1 = require("../../../common/helpers/string/base64");
|
|
6
6
|
const raw_1 = require("./raw");
|
|
7
7
|
/**
|
|
8
8
|
* read chunks. json parse+unb64
|
|
@@ -35,7 +35,7 @@ function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse: parseR
|
|
|
35
35
|
currentCount += 1;
|
|
36
36
|
}
|
|
37
37
|
try {
|
|
38
|
-
return parse((0,
|
|
38
|
+
return parse((0, base64_1.fromBase64)(raw));
|
|
39
39
|
}
|
|
40
40
|
catch (e) {
|
|
41
41
|
(0, log_1.warn)('cookie error:', e);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setCookieString = exports.setCookieRawWrapper = void 0;
|
|
4
|
-
const
|
|
4
|
+
const base64_1 = require("../../../common/helpers/string/base64");
|
|
5
|
+
const chunk_1 = require("../../../common/helpers/string/chunk");
|
|
5
6
|
const const_1 = require("./const");
|
|
6
7
|
const raw_1 = require("./raw");
|
|
7
8
|
/**
|
|
@@ -20,8 +21,8 @@ function setCookieRawWrapper(p) {
|
|
|
20
21
|
if (!p.value) {
|
|
21
22
|
return;
|
|
22
23
|
}
|
|
23
|
-
const str = (0,
|
|
24
|
-
const chunks = (0,
|
|
24
|
+
const str = (0, base64_1.toBase64)(stringify(p.value));
|
|
25
|
+
const chunks = (0, chunk_1.chunkString)(str, const_1.maxCookieLen);
|
|
25
26
|
for (const index1 in chunks) {
|
|
26
27
|
const chunk = chunks[index1];
|
|
27
28
|
(0, raw_1.setCookie)(Object.assign(Object.assign({}, p), { name: p.name + index1, value: chunk }));
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.397",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"aws-sdk": "2.x",
|
|
20
20
|
"axios": "1.x",
|
|
21
21
|
"constructs": "10.x",
|
|
22
|
-
"jsonwebtoken": "
|
|
22
|
+
"jsonwebtoken": "9.x",
|
|
23
23
|
"jwks-rsa": "3.x",
|
|
24
24
|
"node-cache": "5.x",
|
|
25
25
|
"openapi-request-validator": "12.1.0",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"@storybook/addons": "6.5.15",
|
|
44
44
|
"@storybook/react": "6.5.15",
|
|
45
45
|
"@storybook/theming": "6.5.15",
|
|
46
|
-
"@types/jsonwebtoken": "
|
|
46
|
+
"@types/jsonwebtoken": "9.0.0",
|
|
47
47
|
"@types/node": "18.11.17",
|
|
48
48
|
"@types/react": "18.0.26",
|
|
49
49
|
"@types/react-dom": "18.0.9",
|
|
@@ -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;
|
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isValidUrl = exports.indexOfNumber = exports.stringToObject = exports.chunkString = exports.safeStringify = exports.containsInsensitive = exports.containsInsensitiveIndex = exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = exports.fromBase64 = exports.toBase64 = void 0;
|
|
4
|
-
const toBase64 = (str) => Buffer.from(str).toString('base64');
|
|
5
|
-
exports.toBase64 = toBase64;
|
|
6
|
-
const fromBase64 = (str) => Buffer.from(decodeURIComponent(str), 'base64').toString();
|
|
7
|
-
exports.fromBase64 = fromBase64;
|
|
8
|
-
const csvJSON = (csv) => {
|
|
9
|
-
const lines = csv.split('\n');
|
|
10
|
-
const result = [];
|
|
11
|
-
// NOTE: If your columns contain commas in their values, you'll need
|
|
12
|
-
// to deal with those before doing the next step
|
|
13
|
-
// (you might convert them to &&& or something, then covert them back later)
|
|
14
|
-
// jsfiddle showing the issue https://jsfiddle.net/
|
|
15
|
-
const headers = lines[0].split(',');
|
|
16
|
-
for (let i = 1; i < lines.length; i += 1) {
|
|
17
|
-
const obj = {};
|
|
18
|
-
const currentline = lines[i].split(',');
|
|
19
|
-
for (let j = 0; j < headers.length; j += 1) {
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
21
|
-
// @ts-ignore
|
|
22
|
-
obj[headers[j]] = currentline[j];
|
|
23
|
-
}
|
|
24
|
-
result.push(obj);
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
exports.csvJSON = csvJSON;
|
|
29
|
-
function trimSide(str, fromStart = true, ...params) {
|
|
30
|
-
const pstr = params.join('');
|
|
31
|
-
if (!str) {
|
|
32
|
-
return str;
|
|
33
|
-
}
|
|
34
|
-
const ret = str.replace(new RegExp(`[${pstr}]*$`, 'g'), '');
|
|
35
|
-
if (fromStart) {
|
|
36
|
-
return ret.replace(new RegExp(`^[${pstr}]*`, 'g'), '');
|
|
37
|
-
}
|
|
38
|
-
return ret;
|
|
39
|
-
}
|
|
40
|
-
exports.trimSide = trimSide;
|
|
41
|
-
function trim(str, ...params) {
|
|
42
|
-
if (!str) {
|
|
43
|
-
return '';
|
|
44
|
-
}
|
|
45
|
-
str = trimSide(str, true, ...params);
|
|
46
|
-
str = trimSide(str, false, ...params);
|
|
47
|
-
return str;
|
|
48
|
-
}
|
|
49
|
-
exports.trim = trim;
|
|
50
|
-
function truncate(str, n, ellip) {
|
|
51
|
-
if (!str) {
|
|
52
|
-
return undefined;
|
|
53
|
-
}
|
|
54
|
-
return str.length > n ? str.substr(0, n - 1) + ellip : str;
|
|
55
|
-
}
|
|
56
|
-
exports.truncate = truncate;
|
|
57
|
-
/**
|
|
58
|
-
* removes protocol, and trailing slashes
|
|
59
|
-
*/
|
|
60
|
-
const niceUrl = (siteUrl) => {
|
|
61
|
-
if (!siteUrl) {
|
|
62
|
-
return undefined;
|
|
63
|
-
}
|
|
64
|
-
let niceSiteUrl = siteUrl
|
|
65
|
-
.substring(siteUrl.indexOf(':') + 1)
|
|
66
|
-
.replace('sc-domain:', '')
|
|
67
|
-
.replace('https://', '')
|
|
68
|
-
.replace('http://', '');
|
|
69
|
-
niceSiteUrl = trim(niceSiteUrl, '/');
|
|
70
|
-
return { siteUrl, niceSiteUrl };
|
|
71
|
-
};
|
|
72
|
-
exports.niceUrl = niceUrl;
|
|
73
|
-
/**
|
|
74
|
-
* string -> String
|
|
75
|
-
* @param str
|
|
76
|
-
* @returns
|
|
77
|
-
*/
|
|
78
|
-
function toTitleCase(str) {
|
|
79
|
-
if (!str) {
|
|
80
|
-
return str;
|
|
81
|
-
}
|
|
82
|
-
return str.replace(/\w\S*/g, (txt) => txt && txt.charAt(0).toUpperCase() + txt.substring(1).toLowerCase());
|
|
83
|
-
}
|
|
84
|
-
exports.toTitleCase = toTitleCase;
|
|
85
|
-
/**
|
|
86
|
-
* remove all found params from str
|
|
87
|
-
* @param str
|
|
88
|
-
* @param params allows single chars and/or strings
|
|
89
|
-
* @returns
|
|
90
|
-
*/
|
|
91
|
-
function replaceRemove(str, ...params) {
|
|
92
|
-
const replaceSingles = [];
|
|
93
|
-
const replaceStrings = [];
|
|
94
|
-
params.forEach((p) => {
|
|
95
|
-
if (typeof p !== 'string') {
|
|
96
|
-
throw new Error('trim only supports strings');
|
|
97
|
-
}
|
|
98
|
-
if (p.length === 1) {
|
|
99
|
-
replaceSingles.push(p);
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
replaceStrings.push(p);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
let firstLength = 0;
|
|
106
|
-
let changedLength = 0;
|
|
107
|
-
let ret = str;
|
|
108
|
-
const singleRegex = `[${replaceSingles.join('')}]*`;
|
|
109
|
-
const stringRegex = `(${replaceStrings.map((s) => `(${s})`).join('|')})*`;
|
|
110
|
-
do {
|
|
111
|
-
firstLength = ret.length;
|
|
112
|
-
ret = ret.replace(new RegExp(stringRegex, 'gim'), '');
|
|
113
|
-
ret = ret.replace(new RegExp(singleRegex, 'gim'), '');
|
|
114
|
-
changedLength = ret.length;
|
|
115
|
-
} while (changedLength < firstLength);
|
|
116
|
-
return ret;
|
|
117
|
-
}
|
|
118
|
-
exports.replaceRemove = replaceRemove;
|
|
119
|
-
/**
|
|
120
|
-
* returns >-1 if found
|
|
121
|
-
* @param str
|
|
122
|
-
* @param args
|
|
123
|
-
* @returns
|
|
124
|
-
*/
|
|
125
|
-
function containsInsensitiveIndex({ str, fromLast = false, }, ...args) {
|
|
126
|
-
if (!str || !args) {
|
|
127
|
-
return -1;
|
|
128
|
-
}
|
|
129
|
-
const largs = args.map((a) => a.toLowerCase());
|
|
130
|
-
const lstr = str.toLowerCase();
|
|
131
|
-
const finds = largs
|
|
132
|
-
.map((arg) => (fromLast ? lstr.lastIndexOf(arg) : lstr.indexOf(arg)))
|
|
133
|
-
.filter((s) => s !== -1)
|
|
134
|
-
.sort();
|
|
135
|
-
if (finds.length === 0) {
|
|
136
|
-
return -1;
|
|
137
|
-
}
|
|
138
|
-
return !fromLast ? finds[0] : finds[finds.length - 1];
|
|
139
|
-
}
|
|
140
|
-
exports.containsInsensitiveIndex = containsInsensitiveIndex;
|
|
141
|
-
/**
|
|
142
|
-
* returns true if text is found
|
|
143
|
-
* @param str
|
|
144
|
-
* @param args
|
|
145
|
-
* @returns
|
|
146
|
-
*/
|
|
147
|
-
const containsInsensitive = (str, ...args) => containsInsensitiveIndex({ str }, ...args) !== -1;
|
|
148
|
-
exports.containsInsensitive = containsInsensitive;
|
|
149
|
-
/**
|
|
150
|
-
* safely handles circular references
|
|
151
|
-
* @param obj
|
|
152
|
-
* @param indent
|
|
153
|
-
* @returns
|
|
154
|
-
*/
|
|
155
|
-
const safeStringify = (obj, indent = 2) => {
|
|
156
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
157
|
-
let cache = [];
|
|
158
|
-
const retVal = JSON.stringify(obj, (_key, value) => typeof value === 'object' && value !== null
|
|
159
|
-
? cache.includes(value)
|
|
160
|
-
? undefined // Duplicate reference found, discard key
|
|
161
|
-
: cache.push(value) && value // Store value in our collection
|
|
162
|
-
: value, indent);
|
|
163
|
-
cache = null;
|
|
164
|
-
return retVal;
|
|
165
|
-
};
|
|
166
|
-
exports.safeStringify = safeStringify;
|
|
167
|
-
const chunkString = (str, length) => str.match(new RegExp(`.{1,${length}}`, 'g'));
|
|
168
|
-
exports.chunkString = chunkString;
|
|
169
|
-
/**
|
|
170
|
-
* object to string - can be used for querystring a=b&c=d etc
|
|
171
|
-
* @param raw eg a=b&c=d
|
|
172
|
-
* @param splitKeyValue eg =
|
|
173
|
-
* @param splitKeys eg &
|
|
174
|
-
*/
|
|
175
|
-
function stringToObject(raw, splitKeyValue, splitKeys) {
|
|
176
|
-
const ret = {};
|
|
177
|
-
if (!stringToObject) {
|
|
178
|
-
return ret;
|
|
179
|
-
}
|
|
180
|
-
raw.split(splitKeys).forEach((set) => {
|
|
181
|
-
const [k, v] = set.split(splitKeyValue);
|
|
182
|
-
if (k) {
|
|
183
|
-
ret[k] = v;
|
|
184
|
-
}
|
|
185
|
-
});
|
|
186
|
-
return ret;
|
|
187
|
-
}
|
|
188
|
-
exports.stringToObject = stringToObject;
|
|
189
|
-
const indexOfNumber = (str, char, num = 0) => {
|
|
190
|
-
let ret = -1;
|
|
191
|
-
for (let c = 0; c <= num; c += 1) {
|
|
192
|
-
ret = str.indexOf(char, ret + 1);
|
|
193
|
-
}
|
|
194
|
-
if (ret === -1) {
|
|
195
|
-
return undefined;
|
|
196
|
-
}
|
|
197
|
-
return ret;
|
|
198
|
-
};
|
|
199
|
-
exports.indexOfNumber = indexOfNumber;
|
|
200
|
-
function isValidUrl(raw) {
|
|
201
|
-
let url;
|
|
202
|
-
try {
|
|
203
|
-
url = new URL(raw);
|
|
204
|
-
}
|
|
205
|
-
catch (_) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
return url.protocol === 'http:' || url.protocol === 'https:';
|
|
209
|
-
}
|
|
210
|
-
exports.isValidUrl = isValidUrl;
|