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
package/dist/api/helpers/api.js
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.generateDynamoPKS = exports.stripPKs = exports.returnCode = void 0;
|
|
15
1
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
16
2
|
// eslint-disable-next-line
|
|
17
|
-
|
|
18
|
-
const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
|
|
3
|
+
import { notEmpty } from '../../common/helpers/array';
|
|
4
|
+
export const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
|
|
19
5
|
let headers = {
|
|
20
6
|
'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent,User-Agent,Origin',
|
|
21
7
|
'Access-Control-Allow-Methods': '*',
|
|
@@ -23,7 +9,10 @@ const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
|
|
|
23
9
|
'Access-Control-Allow-Credentials': true, // Required for cookies, authorization headers with HTTPS
|
|
24
10
|
};
|
|
25
11
|
if (extraHeaders && Object.keys(extraHeaders).length > 0) {
|
|
26
|
-
headers =
|
|
12
|
+
headers = {
|
|
13
|
+
...headers,
|
|
14
|
+
...extraHeaders,
|
|
15
|
+
};
|
|
27
16
|
}
|
|
28
17
|
return {
|
|
29
18
|
headers,
|
|
@@ -32,7 +21,6 @@ const returnCode = (statusCode, body, extraHeaders, fullSiteUrl) => {
|
|
|
32
21
|
body: (!body ? undefined : JSON.stringify(body, null, 2)),
|
|
33
22
|
};
|
|
34
23
|
};
|
|
35
|
-
exports.returnCode = returnCode;
|
|
36
24
|
/**
|
|
37
25
|
* strip all dynamo generated keys. can optionally keep PK
|
|
38
26
|
* @param record
|
|
@@ -40,14 +28,14 @@ exports.returnCode = returnCode;
|
|
|
40
28
|
* @returns stripped record
|
|
41
29
|
*/
|
|
42
30
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
-
const stripPKs = (record, keepPk = true) => {
|
|
31
|
+
export const stripPKs = (record, keepPk = true) => {
|
|
44
32
|
if (!record) {
|
|
45
33
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
34
|
return null;
|
|
47
35
|
}
|
|
48
36
|
// @ts-ignore
|
|
49
37
|
// eslint-disable-next-line
|
|
50
|
-
const { PK, PK1, PK2, PK3, PK4, PK5, L1, L2, L3, L4, L5, L6, type
|
|
38
|
+
const { PK, PK1, PK2, PK3, PK4, PK5, L1, L2, L3, L4, L5, L6, type, ...rest } = record;
|
|
51
39
|
if (keepPk) {
|
|
52
40
|
//@ts-ignore
|
|
53
41
|
rest.PK = PK;
|
|
@@ -56,7 +44,6 @@ const stripPKs = (record, keepPk = true) => {
|
|
|
56
44
|
// @ts-ignore
|
|
57
45
|
return rest;
|
|
58
46
|
};
|
|
59
|
-
exports.stripPKs = stripPKs;
|
|
60
47
|
/**
|
|
61
48
|
* generate dynamo PKs.
|
|
62
49
|
* PK = all Ls joined with #
|
|
@@ -67,21 +54,33 @@ exports.stripPKs = stripPKs;
|
|
|
67
54
|
* @param param0
|
|
68
55
|
* @returns
|
|
69
56
|
*/
|
|
70
|
-
const generateDynamoPKS = ({ type, L1, L2, L3, L4, L5, L6, additionalPKValues, }) => {
|
|
57
|
+
export const generateDynamoPKS = ({ type, L1, L2, L3, L4, L5, L6, additionalPKValues, }) => {
|
|
71
58
|
const c = '#';
|
|
72
|
-
const keys = [L1, L2, L3, L4, L5, L6].filter(
|
|
73
|
-
const additionalPK = additionalPKValues &&
|
|
59
|
+
const keys = [L1, L2, L3, L4, L5, L6].filter(notEmpty);
|
|
60
|
+
const additionalPK = additionalPKValues && additionalPKValues?.length > 0
|
|
74
61
|
? `#${additionalPKValues.join(c)}`
|
|
75
62
|
: '';
|
|
76
|
-
return
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
63
|
+
return {
|
|
64
|
+
PK: keys.join(c) + additionalPK,
|
|
65
|
+
type,
|
|
66
|
+
L1,
|
|
67
|
+
...(L2 && { L2 }),
|
|
68
|
+
...(L3 && { L3 }),
|
|
69
|
+
...(L4 && { L4 }),
|
|
70
|
+
...(L5 && { L5 }),
|
|
71
|
+
...(L6 && { L6 }),
|
|
72
|
+
PK1: L1,
|
|
73
|
+
...(keys.length >= 2 && {
|
|
74
|
+
PK2: [keys[0], keys[1]].join(c),
|
|
75
|
+
}),
|
|
76
|
+
...(keys.length >= 3 && {
|
|
77
|
+
PK3: [keys[0], keys[1], keys[2]].join(c),
|
|
78
|
+
}),
|
|
79
|
+
...(keys.length >= 4 && {
|
|
80
|
+
PK4: [keys[0], keys[1], keys[2], keys[3]].join(c),
|
|
81
|
+
}),
|
|
82
|
+
...(keys.length >= 5 && {
|
|
83
|
+
PK5: [keys[0], keys[1], keys[2], keys[3], keys[4]].join(c),
|
|
84
|
+
}),
|
|
85
|
+
};
|
|
86
86
|
};
|
|
87
|
-
exports.generateDynamoPKS = generateDynamoPKS;
|
package/dist/api/helpers/aws.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
(
|
|
10
|
-
(0, s3_1.setS3)(region);
|
|
11
|
-
(0, ses_1.setSes)(region);
|
|
12
|
-
(0, sqs_1.setSqs)(region);
|
|
1
|
+
import { setDynamo } from './dynamo';
|
|
2
|
+
import { setS3 } from './s3';
|
|
3
|
+
import { setSes } from './ses';
|
|
4
|
+
import { setSqs } from './sqs';
|
|
5
|
+
export const setAwsRegion = (region) => {
|
|
6
|
+
setDynamo(region);
|
|
7
|
+
setS3(region);
|
|
8
|
+
setSes(region);
|
|
9
|
+
setSqs(region);
|
|
13
10
|
};
|
|
14
|
-
exports.setAwsRegion = setAwsRegion;
|
|
@@ -1,25 +1,9 @@
|
|
|
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
|
-
});
|
|
1
|
+
import CF from 'aws-sdk/clients/cloudfront';
|
|
2
|
+
let cf = new CF();
|
|
3
|
+
export const setCF = (region) => {
|
|
4
|
+
cf = new CF({ region });
|
|
10
5
|
};
|
|
11
|
-
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.invalidateCloudfrontPath = exports.setCF = void 0;
|
|
16
|
-
const cloudfront_1 = __importDefault(require("aws-sdk/clients/cloudfront"));
|
|
17
|
-
let cf = new cloudfront_1.default();
|
|
18
|
-
const setCF = (region) => {
|
|
19
|
-
cf = new cloudfront_1.default({ region });
|
|
20
|
-
};
|
|
21
|
-
exports.setCF = setCF;
|
|
22
|
-
const invalidateCloudfrontPath = ({ path, distributionId, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
6
|
+
export const invalidateCloudfrontPath = async ({ path, distributionId, }) => {
|
|
23
7
|
const params = {
|
|
24
8
|
DistributionId: distributionId,
|
|
25
9
|
InvalidationBatch: {
|
|
@@ -30,6 +14,5 @@ const invalidateCloudfrontPath = ({ path, distributionId, }) => __awaiter(void 0
|
|
|
30
14
|
},
|
|
31
15
|
},
|
|
32
16
|
};
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
exports.invalidateCloudfrontPath = invalidateCloudfrontPath;
|
|
17
|
+
await cf.createInvalidation(params).promise();
|
|
18
|
+
};
|
|
@@ -1,76 +1,42 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.getDynamoUpdates = exports.wipeTable = exports.getDynamoTtlMinutes = exports.getDynamoTtlDays = exports.queryDynamo = exports.getItemsDynamo = exports.getItemDynamo = exports.scan = exports.batchDelete = exports.batchWrite = exports.putDynamo = exports.setDynamo = exports.dynamoDb = void 0;
|
|
36
1
|
/* eslint-disable guard-for-in */
|
|
37
2
|
/* eslint-disable no-restricted-syntax */
|
|
38
3
|
/* eslint-disable no-await-in-loop */
|
|
39
4
|
/* eslint-disable prefer-const */
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
5
|
+
import DynamoDB, { Converter, DocumentClient, } from 'aws-sdk/clients/dynamodb';
|
|
6
|
+
import { chunk, notEmpty, take } from '../../common/helpers/array';
|
|
7
|
+
import { asyncForEach } from '../../common/helpers/async';
|
|
8
|
+
import { debug, error as errorF, info, warn } from '../../common/helpers/log';
|
|
9
|
+
import { sleep } from '../../common/helpers/sleep';
|
|
45
10
|
// eslint-disable-next-line import/no-mutable-exports
|
|
46
|
-
|
|
47
|
-
const setDynamo = (region) => {
|
|
48
|
-
|
|
11
|
+
export let dynamoDb = new DocumentClient();
|
|
12
|
+
export const setDynamo = (region) => {
|
|
13
|
+
dynamoDb = new DocumentClient({ region });
|
|
49
14
|
};
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
15
|
+
export const putDynamo = async (item, tableName, opt) => {
|
|
16
|
+
const params = {
|
|
17
|
+
TableName: tableName,
|
|
53
18
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
|
-
Item: item
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
19
|
+
Item: item,
|
|
20
|
+
...(opt?.pkName && {
|
|
21
|
+
ConditionExpression: `attribute_not_exists(${opt.pkName})`,
|
|
22
|
+
}),
|
|
23
|
+
};
|
|
24
|
+
info(`running dynamo put=${JSON.stringify(params, null, 2)}`);
|
|
58
25
|
// write the todo to the database
|
|
59
|
-
const put =
|
|
26
|
+
const put = await dynamoDb.put(params).promise();
|
|
60
27
|
if (put.$response.error && put.$response.error.statusCode) {
|
|
61
28
|
return { error: put.$response.error.message };
|
|
62
29
|
}
|
|
63
30
|
// put never returns into, so just use what we have already
|
|
64
31
|
return { data: item };
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
let batchWriteRaw = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
+
};
|
|
33
|
+
let batchWriteRaw = async (req) => {
|
|
68
34
|
let count = 0;
|
|
69
35
|
let max = 5;
|
|
70
36
|
// eslint-disable-next-line no-constant-condition
|
|
71
37
|
while (true)
|
|
72
38
|
try {
|
|
73
|
-
const res =
|
|
39
|
+
const res = await dynamoDb
|
|
74
40
|
.batchWrite({
|
|
75
41
|
RequestItems: req,
|
|
76
42
|
})
|
|
@@ -84,7 +50,7 @@ let batchWriteRaw = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
84
50
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
85
51
|
let es = e.toString();
|
|
86
52
|
let msg = es;
|
|
87
|
-
|
|
53
|
+
warn('dynamo write error', msg);
|
|
88
54
|
if (es.indexOf('429') !== -1 ||
|
|
89
55
|
es.indexOf('ProvisionedThroughputExceeded') !== -1) {
|
|
90
56
|
count += 1;
|
|
@@ -96,18 +62,17 @@ let batchWriteRaw = (req) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
96
62
|
if (count >= max) {
|
|
97
63
|
throw e;
|
|
98
64
|
}
|
|
99
|
-
|
|
100
|
-
|
|
65
|
+
warn(`dynamo retry ${count}/${max}`);
|
|
66
|
+
await sleep(2000);
|
|
101
67
|
}
|
|
102
|
-
}
|
|
68
|
+
};
|
|
103
69
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
104
|
-
const batchWrite = (tableName, itemsIn, breakOnError = false) =>
|
|
105
|
-
var _a, _b;
|
|
70
|
+
export const batchWrite = async (tableName, itemsIn, breakOnError = false) => {
|
|
106
71
|
let items = JSON.parse(JSON.stringify(itemsIn));
|
|
107
|
-
|
|
72
|
+
debug(`push to dynamo:${tableName} - count=${itemsIn.length}`);
|
|
108
73
|
const error = [];
|
|
109
74
|
while (items.length > 0) {
|
|
110
|
-
const { part, rest } =
|
|
75
|
+
const { part, rest } = take(items, 25);
|
|
111
76
|
// eslint-disable-next-line no-param-reassign
|
|
112
77
|
items = rest;
|
|
113
78
|
let req = {
|
|
@@ -115,8 +80,8 @@ const batchWrite = (tableName, itemsIn, breakOnError = false) => __awaiter(void
|
|
|
115
80
|
PutRequest: { Item: item },
|
|
116
81
|
})),
|
|
117
82
|
};
|
|
118
|
-
let res =
|
|
119
|
-
const newError =
|
|
83
|
+
let res = await batchWriteRaw(req);
|
|
84
|
+
const newError = res.$response?.error ?? null;
|
|
120
85
|
if (newError) {
|
|
121
86
|
error.push(newError);
|
|
122
87
|
if (breakOnError) {
|
|
@@ -124,20 +89,18 @@ const batchWrite = (tableName, itemsIn, breakOnError = false) => __awaiter(void
|
|
|
124
89
|
}
|
|
125
90
|
}
|
|
126
91
|
}
|
|
127
|
-
if (
|
|
92
|
+
if (error?.length > 0) {
|
|
128
93
|
const me = error.join('\n');
|
|
129
|
-
(
|
|
94
|
+
errorF(`batch write error=${me}`);
|
|
130
95
|
return { error: me };
|
|
131
96
|
}
|
|
132
97
|
return {};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
(0, log_1.info)(`wipe keys dynamo:${tableName} - count=${keys.length}`);
|
|
98
|
+
};
|
|
99
|
+
export const batchDelete = async ({ tableName, breakOnError = true, pkName, keys, rangeName, rangeKeys, }) => {
|
|
100
|
+
info(`wipe keys dynamo:${tableName} - count=${keys.length}`);
|
|
137
101
|
const error = [];
|
|
138
102
|
let breakV = false;
|
|
139
|
-
|
|
140
|
-
var _c, _d;
|
|
103
|
+
await asyncForEach(keys, async (key, i) => {
|
|
141
104
|
if (breakV) {
|
|
142
105
|
return;
|
|
143
106
|
}
|
|
@@ -146,29 +109,28 @@ const batchDelete = ({ tableName, breakOnError = true, pkName, keys, rangeName,
|
|
|
146
109
|
Key: { [pkName]: key },
|
|
147
110
|
};
|
|
148
111
|
if (rangeName) {
|
|
149
|
-
let rangeValue = rangeKeys
|
|
112
|
+
let rangeValue = rangeKeys?.[i];
|
|
150
113
|
if (rangeValue) {
|
|
151
114
|
params.Key[rangeName] = rangeValue;
|
|
152
115
|
}
|
|
153
116
|
}
|
|
154
|
-
const res =
|
|
155
|
-
const newError =
|
|
117
|
+
const res = await dynamoDb.delete(params).promise();
|
|
118
|
+
const newError = res.$response?.error ?? null;
|
|
156
119
|
if (newError) {
|
|
157
120
|
error.push(newError);
|
|
158
121
|
if (breakOnError) {
|
|
159
122
|
breakV = true;
|
|
160
123
|
}
|
|
161
124
|
}
|
|
162
|
-
})
|
|
163
|
-
if (
|
|
125
|
+
});
|
|
126
|
+
if (error?.length > 0) {
|
|
164
127
|
const me = error.join('\n');
|
|
165
|
-
(
|
|
128
|
+
errorF(`batch write error=${me}`);
|
|
166
129
|
return { error: me };
|
|
167
130
|
}
|
|
168
131
|
return {};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
+
};
|
|
133
|
+
export const scan = async (tableName, opt) => {
|
|
172
134
|
const Items = [];
|
|
173
135
|
let ExclusiveStartKey;
|
|
174
136
|
do {
|
|
@@ -176,17 +138,17 @@ const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
176
138
|
TableName: tableName,
|
|
177
139
|
ExclusiveStartKey,
|
|
178
140
|
};
|
|
179
|
-
if (opt
|
|
141
|
+
if (opt?.filter) {
|
|
180
142
|
params.FilterExpression = opt.filter.filterExpression;
|
|
181
143
|
params.ExpressionAttributeNames = opt.filter.attrNames;
|
|
182
144
|
params.ExpressionAttributeValues = opt.filter.attrValues;
|
|
183
145
|
}
|
|
184
|
-
if (opt
|
|
146
|
+
if (opt?.requiredAttributeList) {
|
|
185
147
|
params.ProjectionExpression = opt.requiredAttributeList.join(', ');
|
|
186
148
|
}
|
|
187
149
|
const { Items: newitems, LastEvaluatedKey, $response,
|
|
188
150
|
// eslint-disable-next-line no-await-in-loop
|
|
189
|
-
} =
|
|
151
|
+
} = await dynamoDb.scan(params).promise();
|
|
190
152
|
ExclusiveStartKey = LastEvaluatedKey;
|
|
191
153
|
if ($response.error && $response.error.statusCode) {
|
|
192
154
|
throw new Error($response.error.message);
|
|
@@ -195,29 +157,26 @@ const scan = (tableName, opt) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
195
157
|
Items.push(...newitems.map((r) => r));
|
|
196
158
|
}
|
|
197
159
|
} while (ExclusiveStartKey);
|
|
198
|
-
|
|
160
|
+
info(`dynamo scan against ${tableName} ok, count=${Items?.length}`);
|
|
199
161
|
return Items;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const getItemDynamo = ({ tableName, pkName, pkValue, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
162
|
+
};
|
|
163
|
+
export const getItemDynamo = async ({ tableName, pkName, pkValue, }) => {
|
|
203
164
|
const params = {
|
|
204
165
|
Key: { [pkName]: pkValue },
|
|
205
166
|
TableName: tableName,
|
|
206
167
|
};
|
|
207
168
|
try {
|
|
208
|
-
const res =
|
|
169
|
+
const res = await dynamoDb.get(params).promise();
|
|
209
170
|
const ret = res.Item;
|
|
210
|
-
|
|
171
|
+
debug(`got dynamo getitem=${JSON.stringify(params, null, 2)}`);
|
|
211
172
|
return ret;
|
|
212
173
|
}
|
|
213
174
|
catch (e) {
|
|
214
|
-
(
|
|
175
|
+
errorF(e);
|
|
215
176
|
throw e;
|
|
216
177
|
}
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
220
|
-
var _e, _f;
|
|
178
|
+
};
|
|
179
|
+
export const getItemsDynamo = async ({ tableName, items, }) => {
|
|
221
180
|
const params = {
|
|
222
181
|
RequestItems: {
|
|
223
182
|
[tableName]: {
|
|
@@ -227,11 +186,11 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
|
|
|
227
186
|
},
|
|
228
187
|
},
|
|
229
188
|
};
|
|
230
|
-
const dbRaw = new
|
|
189
|
+
const dbRaw = new DynamoDB({ apiVersion: '2012-10-08' });
|
|
231
190
|
try {
|
|
232
|
-
const res =
|
|
233
|
-
|
|
234
|
-
let ret =
|
|
191
|
+
const res = await dbRaw.batchGetItem(params).promise();
|
|
192
|
+
debug(`got dynamo getitems=${JSON.stringify(res, null, 2)}`);
|
|
193
|
+
let ret = res.Responses?.[tableName]?.map((s) => Converter.unmarshall(s)) ||
|
|
235
194
|
[];
|
|
236
195
|
return ret;
|
|
237
196
|
}
|
|
@@ -241,13 +200,11 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
|
|
|
241
200
|
'\n' +
|
|
242
201
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
243
202
|
e.toString();
|
|
244
|
-
(
|
|
203
|
+
errorF(msg);
|
|
245
204
|
throw e;
|
|
246
205
|
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skValue, skOperator = '=', indexName, count = 1000, startKey: startKeyIn, filterName, filterValue, filterOperator = '=', sortAscending = true, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
250
|
-
var _g;
|
|
206
|
+
};
|
|
207
|
+
export const queryDynamo = async ({ tableName, pkName, pkValue, pkOperator = '=', skName, skValue, skOperator = '=', indexName, count = 1000, startKey: startKeyIn, filterName, filterValue, filterOperator = '=', sortAscending = true, }) => {
|
|
251
208
|
let startKey = startKeyIn;
|
|
252
209
|
let kce = `#${pkName.toLowerCase()} ${pkOperator} :${pkName.toLowerCase()}`;
|
|
253
210
|
const ean = { [`#${pkName.toLowerCase()}`]: pkName };
|
|
@@ -320,36 +277,32 @@ const queryDynamo = ({ tableName, pkName, pkValue, pkOperator = '=', skName, skV
|
|
|
320
277
|
LastEvaluatedKey: lek,
|
|
321
278
|
$response,
|
|
322
279
|
// eslint-disable-next-line no-await-in-loop
|
|
323
|
-
} =
|
|
280
|
+
} = await dynamoDb.query(params).promise());
|
|
324
281
|
}
|
|
325
282
|
catch (e) {
|
|
326
|
-
(
|
|
283
|
+
errorF('error. query params=', JSON.stringify(params), e);
|
|
327
284
|
throw e;
|
|
328
285
|
}
|
|
329
286
|
startKey = lek;
|
|
330
287
|
if ($response.error) {
|
|
331
|
-
(
|
|
288
|
+
errorF('error. query params=', JSON.stringify(params));
|
|
332
289
|
throw new Error($response.error.message);
|
|
333
290
|
}
|
|
334
|
-
|
|
291
|
+
debug(`dynamo query against ${params?.TableName} ok, count=${newitems?.length} ${JSON.stringify(params)}`, ` next startkey=${startKey}`);
|
|
335
292
|
if (newitems) {
|
|
336
293
|
Items.push(...newitems.map((r) => r));
|
|
337
294
|
}
|
|
338
|
-
if (count > 0 && (
|
|
295
|
+
if (count > 0 && (newitems?.length ?? 0) >= count) {
|
|
339
296
|
return { Items, startKey };
|
|
340
297
|
}
|
|
341
298
|
} while (startKey && Object.keys(startKey).length > 0);
|
|
342
299
|
return { Items, startKey: undefined };
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* () {
|
|
350
|
-
var _h;
|
|
351
|
-
const dbRaw = new dynamodb_1.default({ apiVersion: '2012-10-08' });
|
|
352
|
-
let infoV = yield dbRaw
|
|
300
|
+
};
|
|
301
|
+
export const getDynamoTtlDays = (days) => Math.ceil(new Date().getTime() / 1000) + days * 86400;
|
|
302
|
+
export const getDynamoTtlMinutes = (mins) => Math.ceil(new Date().getTime() / 1000) + mins * 60;
|
|
303
|
+
export const wipeTable = async (tableName) => {
|
|
304
|
+
const dbRaw = new DynamoDB({ apiVersion: '2012-10-08' });
|
|
305
|
+
let infoV = await dbRaw
|
|
353
306
|
.describeTable({
|
|
354
307
|
TableName: tableName,
|
|
355
308
|
})
|
|
@@ -364,15 +317,15 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
364
317
|
let all = [];
|
|
365
318
|
let working;
|
|
366
319
|
do {
|
|
367
|
-
working =
|
|
368
|
-
|
|
320
|
+
working = await dbRaw.scan(params).promise();
|
|
321
|
+
working.Items?.forEach((item) => all.push(item));
|
|
369
322
|
params.ExclusiveStartKey = working.LastEvaluatedKey;
|
|
370
323
|
} while (typeof working.LastEvaluatedKey !== 'undefined');
|
|
371
|
-
|
|
324
|
+
warn(`will delete ${all?.length} items from ${tableName}`);
|
|
372
325
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
373
326
|
// @ts-ignore
|
|
374
|
-
const datagr =
|
|
375
|
-
let res =
|
|
327
|
+
const datagr = chunk(all, 25);
|
|
328
|
+
let res = await Promise.all(datagr.map((group) => dbRaw
|
|
376
329
|
.batchWriteItem({
|
|
377
330
|
RequestItems: {
|
|
378
331
|
[`${tableName}`]: group.map((s) => ({
|
|
@@ -386,17 +339,16 @@ const wipeTable = (tableName) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
386
339
|
})
|
|
387
340
|
.promise()));
|
|
388
341
|
let errors = res
|
|
389
|
-
.map((r) =>
|
|
390
|
-
.filter(
|
|
342
|
+
.map((r) => (r?.$response?.error || {})?.message || undefined)
|
|
343
|
+
.filter(notEmpty);
|
|
391
344
|
if (errors.length > 0) {
|
|
392
|
-
(
|
|
345
|
+
errorF('errors=', JSON.stringify(errors));
|
|
393
346
|
return { errors };
|
|
394
347
|
}
|
|
395
|
-
|
|
348
|
+
warn(`cleared table ${tableName}`);
|
|
396
349
|
return {};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
const getDynamoUpdates = (items) => {
|
|
350
|
+
};
|
|
351
|
+
export const getDynamoUpdates = (items) => {
|
|
400
352
|
const cleanedKeys = Object.keys(items).filter((r) => r !== 'PK');
|
|
401
353
|
let UpdateExpression = '';
|
|
402
354
|
const ExpressionAttributeNames = {};
|
|
@@ -410,7 +362,7 @@ const getDynamoUpdates = (items) => {
|
|
|
410
362
|
ExpressionAttributeValues[`:${key}`] = v;
|
|
411
363
|
}
|
|
412
364
|
else {
|
|
413
|
-
|
|
365
|
+
warn(`no value for key:${key}`);
|
|
414
366
|
}
|
|
415
367
|
});
|
|
416
368
|
return {
|
|
@@ -419,4 +371,3 @@ const getDynamoUpdates = (items) => {
|
|
|
419
371
|
ExpressionAttributeValues,
|
|
420
372
|
};
|
|
421
373
|
};
|
|
422
|
-
exports.getDynamoUpdates = getDynamoUpdates;
|
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
5
|
-
const ssm_1 = require("./ssm");
|
|
6
|
-
const generateTableRef = ({ stack, baseKey, hasStream, hasGSI, }) => {
|
|
1
|
+
import { aws_dynamodb as dynamodb, aws_ssm as ssm } from 'aws-cdk-lib';
|
|
2
|
+
import { loadSsmString, loadSsmStringList, saveToSsm } from './ssm';
|
|
3
|
+
export const generateTableRef = ({ stack, baseKey, hasStream, hasGSI, }) => {
|
|
7
4
|
const tableStreamArn = !hasStream
|
|
8
5
|
? undefined
|
|
9
|
-
:
|
|
6
|
+
: loadSsmString({ stack, path: `${baseKey}/streamArn` });
|
|
10
7
|
const globalIndexes = !hasGSI
|
|
11
8
|
? undefined
|
|
12
|
-
:
|
|
13
|
-
const shortName =
|
|
14
|
-
const table =
|
|
15
|
-
tableArn:
|
|
9
|
+
: loadSsmStringList({ stack, path: `${baseKey}/gsi` });
|
|
10
|
+
const shortName = ssm.StringParameter.valueFromLookup(stack, `${baseKey}/shortName`);
|
|
11
|
+
const table = dynamodb.Table.fromTableAttributes(stack, baseKey, {
|
|
12
|
+
tableArn: loadSsmString({ stack, path: `${baseKey}/arn` }),
|
|
16
13
|
tableStreamArn,
|
|
17
14
|
globalIndexes,
|
|
18
15
|
});
|
|
@@ -21,27 +18,25 @@ const generateTableRef = ({ stack, baseKey, hasStream, hasGSI, }) => {
|
|
|
21
18
|
table,
|
|
22
19
|
};
|
|
23
20
|
};
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
(0, ssm_1.saveToSsm)({ stack, path: `${baseKey}/arn`, value: table.tableArn });
|
|
21
|
+
export const generateSSMParams = ({ stack, table, baseKey, gsi, shortName, }) => {
|
|
22
|
+
saveToSsm({ stack, path: `${baseKey}/arn`, value: table.tableArn });
|
|
27
23
|
if (table.tableStreamArn) {
|
|
28
|
-
|
|
24
|
+
saveToSsm({
|
|
29
25
|
stack,
|
|
30
26
|
path: `${baseKey}/streamArn`,
|
|
31
27
|
value: table.tableStreamArn,
|
|
32
28
|
});
|
|
33
29
|
}
|
|
34
|
-
if (gsi &&
|
|
35
|
-
|
|
30
|
+
if (gsi && gsi?.length > 0) {
|
|
31
|
+
saveToSsm({
|
|
36
32
|
stack,
|
|
37
33
|
path: `${baseKey}/gsi`,
|
|
38
34
|
value: gsi.join(','),
|
|
39
35
|
});
|
|
40
36
|
}
|
|
41
|
-
|
|
37
|
+
saveToSsm({
|
|
42
38
|
stack,
|
|
43
39
|
path: `${baseKey}/shortName`,
|
|
44
40
|
value: shortName,
|
|
45
41
|
});
|
|
46
42
|
};
|
|
47
|
-
exports.generateSSMParams = generateSSMParams;
|