ag-common 0.0.419 → 0.0.421
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/helpers/api.js +35 -34
- package/dist/api/helpers/aws.js +13 -9
- package/dist/api/helpers/cloudfront.js +24 -7
- package/dist/api/helpers/dynamo.js +134 -85
- package/dist/api/helpers/dynamoInfra.js +19 -14
- package/dist/api/helpers/enforceDynamoProvisionCap.js +18 -14
- package/dist/api/helpers/index.js +30 -14
- package/dist/api/helpers/openApiHelpers.js +37 -34
- package/dist/api/helpers/s3.js +126 -81
- package/dist/api/helpers/ses.js +28 -9
- package/dist/api/helpers/sqs.js +26 -9
- package/dist/api/helpers/ssm.js +14 -8
- package/dist/api/helpers/sts.js +34 -16
- package/dist/api/helpers/validateOpenApi.js +103 -92
- package/dist/api/helpers/validations.js +46 -29
- package/dist/api/index.js +18 -2
- package/dist/api/openapi-prefix.js +38 -25
- package/dist/api/types/aws.js +2 -1
- package/dist/api/types/index.js +17 -1
- package/dist/common/const.js +5 -2
- package/dist/common/helpers/array.js +19 -8
- package/dist/common/helpers/async.js +28 -10
- package/dist/common/helpers/binary.js +10 -5
- package/dist/common/helpers/date.js +25 -14
- package/dist/common/helpers/email.js +11 -5
- package/dist/common/helpers/func.js +7 -3
- package/dist/common/helpers/generator.js +24 -9
- package/dist/common/helpers/groupBy.js +9 -3
- package/dist/common/helpers/hashCode.js +9 -3
- package/dist/common/helpers/i18n.js +17 -9
- package/dist/common/helpers/index.js +34 -18
- package/dist/common/helpers/log.js +28 -16
- package/dist/common/helpers/math.js +21 -9
- package/dist/common/helpers/memo.js +7 -3
- package/dist/common/helpers/object.js +35 -20
- package/dist/common/helpers/random.js +10 -4
- package/dist/common/helpers/secondsInNearest.js +7 -2
- package/dist/common/helpers/sleep.js +5 -1
- package/dist/common/helpers/string/base64.js +7 -2
- package/dist/common/helpers/string/chunk.js +5 -1
- package/dist/common/helpers/string/contains.js +7 -2
- package/dist/common/helpers/string/getExtendedStringSegment.js +9 -5
- package/dist/common/helpers/string/index.js +26 -10
- package/dist/common/helpers/string/json.js +5 -1
- package/dist/common/helpers/string/object.js +5 -1
- package/dist/common/helpers/string/surround.js +5 -1
- package/dist/common/helpers/string/trim.js +7 -2
- package/dist/common/helpers/string/truncate.js +5 -1
- package/dist/common/helpers/string/url.js +9 -4
- package/dist/common/index.js +18 -2
- package/dist/index.js +19 -3
- package/dist/ui/components/BorderGradient/index.js +25 -18
- package/dist/ui/components/Button/index.js +25 -17
- package/dist/ui/components/Chevron/index.js +16 -9
- package/dist/ui/components/Close/index.js +13 -6
- package/dist/ui/components/Confirm/Dialog.js +25 -9
- package/dist/ui/components/Confirm/Modal.js +27 -20
- package/dist/ui/components/Confirm/index.js +19 -3
- package/dist/ui/components/Confirm/types.js +2 -1
- package/dist/ui/components/DropdownList/Base.js +64 -33
- package/dist/ui/components/DropdownList/Dialog.js +24 -8
- package/dist/ui/components/DropdownList/index.js +18 -2
- package/dist/ui/components/DropdownList/types.js +2 -1
- package/dist/ui/components/FlexColumn/index.js +14 -4
- package/dist/ui/components/FlexRow/index.js +14 -4
- package/dist/ui/components/HeadersRaw/index.js +27 -20
- package/dist/ui/components/HorizontalScrollBar/index.js +34 -6
- package/dist/ui/components/Icon/index.js +16 -9
- package/dist/ui/components/Image/index.js +28 -10
- package/dist/ui/components/InfiniteScroll/index.js +50 -18
- package/dist/ui/components/KebabDots/index.js +13 -6
- package/dist/ui/components/Loader/index.js +39 -9
- package/dist/ui/components/Modal/Dialog.js +23 -7
- package/dist/ui/components/Modal/Modal.js +49 -19
- package/dist/ui/components/Modal/index.js +19 -3
- package/dist/ui/components/Modal/types.js +2 -1
- package/dist/ui/components/OpenApiCodeBlock/OpenApiCodeBlock.js +34 -26
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/body.js +19 -12
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/getCurlLines.js +11 -6
- package/dist/ui/components/OpenApiCodeBlock/curl/helpers/security.js +15 -8
- package/dist/ui/components/OpenApiCodeBlock/curl/index.js +21 -14
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/call.js +15 -8
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/getFetchLines.js +8 -3
- package/dist/ui/components/OpenApiCodeBlock/fetch/helpers/req.js +34 -27
- package/dist/ui/components/OpenApiCodeBlock/fetch/index.js +18 -11
- package/dist/ui/components/OpenApiCodeBlock/helpers/common.js +17 -7
- package/dist/ui/components/OpenApiCodeBlock/helpers/joinJsx.js +15 -6
- package/dist/ui/components/OpenApiCodeBlock/index.js +18 -2
- package/dist/ui/components/OpenApiCodeBlock/types.js +2 -1
- package/dist/ui/components/PieChart/index.js +18 -11
- package/dist/ui/components/ProgressBar/index.js +45 -15
- package/dist/ui/components/Prompt/Dialog.js +23 -7
- package/dist/ui/components/Prompt/Modal.js +55 -25
- package/dist/ui/components/Prompt/index.js +18 -2
- package/dist/ui/components/RowOrColumn/index.js +17 -7
- package/dist/ui/components/Search/AutoHideSearchBox.js +56 -24
- package/dist/ui/components/Search/Base.js +52 -21
- package/dist/ui/components/Search/Dialog.js +26 -10
- package/dist/ui/components/Search/Inline.js +10 -3
- package/dist/ui/components/Search/Modal.js +17 -10
- package/dist/ui/components/Search/SearchBox.js +58 -26
- package/dist/ui/components/Search/index.js +23 -7
- package/dist/ui/components/Search/types.js +2 -1
- package/dist/ui/components/Sidebar/index.js +25 -18
- package/dist/ui/components/SparkLine/index.js +27 -17
- package/dist/ui/components/Table/index.js +22 -15
- package/dist/ui/components/TextEdit/CheckboxEdit.js +51 -21
- package/dist/ui/components/TextEdit/ColourEdit.js +44 -17
- package/dist/ui/components/TextEdit/LengthBox.js +12 -5
- package/dist/ui/components/TextEdit/ListboxEdit.js +42 -15
- package/dist/ui/components/TextEdit/RadioGroup.js +43 -13
- package/dist/ui/components/TextEdit/TextEdit.js +78 -48
- package/dist/ui/components/TextEdit/common.js +17 -11
- package/dist/ui/components/TextEdit/index.js +22 -6
- package/dist/ui/components/TextEdit/types.js +2 -1
- package/dist/ui/components/TextWithButton/index.js +40 -10
- package/dist/ui/components/TimelineChart/index.js +24 -14
- package/dist/ui/components/Toast/Cross.js +16 -9
- package/dist/ui/components/Toast/Tick.js +11 -4
- package/dist/ui/components/Toast/Warning.js +15 -8
- package/dist/ui/components/Toast/base.js +65 -33
- package/dist/ui/components/Toast/index.js +18 -2
- package/dist/ui/components/Toast/types.js +2 -1
- package/dist/ui/components/UserImage/index.js +48 -17
- package/dist/ui/components/index.js +46 -30
- package/dist/ui/helpers/axiosHelper.js +39 -25
- package/dist/ui/helpers/browserHelpers.js +22 -7
- package/dist/ui/helpers/callOpenApi/cached.js +37 -18
- package/dist/ui/helpers/callOpenApi/direct.js +59 -46
- package/dist/ui/helpers/callOpenApi/helpers.js +40 -25
- package/dist/ui/helpers/callOpenApi/hook.js +36 -47
- package/dist/ui/helpers/callOpenApi/index.js +21 -5
- package/dist/ui/helpers/callOpenApi/types.js +2 -1
- package/dist/ui/helpers/cognito.js +2 -1
- package/dist/ui/helpers/cookie/const.js +5 -2
- package/dist/ui/helpers/cookie/get.js +14 -13
- package/dist/ui/helpers/cookie/index.js +21 -5
- package/dist/ui/helpers/cookie/raw.js +16 -9
- package/dist/ui/helpers/cookie/set.js +15 -10
- package/dist/ui/helpers/cookie/use.js +16 -23
- package/dist/ui/helpers/date.js +15 -10
- package/dist/ui/helpers/debounce.js +10 -5
- package/dist/ui/helpers/dom.js +13 -6
- package/dist/ui/helpers/extractAttributes.js +7 -2
- package/dist/ui/helpers/index.js +41 -25
- package/dist/ui/helpers/jwt.js +2 -1
- package/dist/ui/helpers/plural.js +5 -1
- package/dist/ui/helpers/routes.js +24 -17
- package/dist/ui/helpers/serviceWorker.js +23 -8
- package/dist/ui/helpers/useContextMenu.js +14 -9
- package/dist/ui/helpers/useElementAttribute.js +7 -3
- package/dist/ui/helpers/useGranularHook.js +10 -5
- package/dist/ui/helpers/useInterval.js +12 -8
- package/dist/ui/helpers/useLocalStorage.js +32 -24
- package/dist/ui/helpers/useLockBodyScroll.js +7 -3
- package/dist/ui/helpers/useOnClickOutside.js +12 -7
- package/dist/ui/helpers/useOnScroll.js +21 -15
- package/dist/ui/helpers/useOverloadPageSearch.js +7 -3
- package/dist/ui/helpers/useQueryString.js +20 -14
- package/dist/ui/helpers/useResize.js +19 -17
- package/dist/ui/helpers/useTimeout.js +9 -5
- package/dist/ui/icons/ChevronRight.js +9 -3
- package/dist/ui/icons/CrossIcon.js +12 -5
- package/dist/ui/icons/Door.js +10 -4
- package/dist/ui/icons/HorizontalDots.js +9 -3
- package/dist/ui/icons/Magnify.js +10 -3
- package/dist/ui/icons/Pencil.js +12 -5
- package/dist/ui/icons/Save.js +11 -4
- package/dist/ui/icons/Undo.js +12 -5
- package/dist/ui/icons/UserOutline.js +9 -3
- package/dist/ui/icons/index.js +25 -9
- package/dist/ui/index.js +20 -4
- package/dist/ui/styles/colours.js +12 -7
- package/dist/ui/styles/common.js +22 -14
- package/dist/ui/styles/index.js +20 -4
- package/dist/ui/styles/media.js +10 -7
- package/dist/ui/styles/standaloneStyles.js +16 -10
- package/package.json +2 -2
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.enforceDynamoProvisionCap = void 0;
|
|
4
|
+
const log_1 = require("../../common/helpers/log");
|
|
5
|
+
const math_1 = require("../../common/helpers/math");
|
|
6
|
+
const json_1 = require("../../common/helpers/string/json");
|
|
7
|
+
const trim_1 = require("../../common/helpers/string/trim");
|
|
8
|
+
const extractSum = ({ str, regex }) => {
|
|
9
|
+
var _a;
|
|
10
|
+
return (0, math_1.sumArray)(((_a = str
|
|
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))) || []);
|
|
12
|
+
};
|
|
10
13
|
/** ensure that dynamo tables in stack dont exceed passed in provisioned limits */
|
|
11
|
-
|
|
14
|
+
const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 25, mustEqual = false, }) => {
|
|
12
15
|
if (!tables || tables.length === 0) {
|
|
13
|
-
warn('error in dynamo FT enforce');
|
|
16
|
+
(0, log_1.warn)('error in dynamo FT enforce');
|
|
14
17
|
return;
|
|
15
18
|
}
|
|
16
19
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
20
|
const t = tables[0];
|
|
18
|
-
const s = safeStringify(t.node._children.Resource.node.scope);
|
|
21
|
+
const s = (0, json_1.safeStringify)(t.node._children.Resource.node.scope);
|
|
19
22
|
const reads = extractSum({ str: s, regex: /readCapacityUnits.*/gim });
|
|
20
23
|
const writes = extractSum({ str: s, regex: /writeCapacityUnits.*/gim });
|
|
21
|
-
warn(`dynamo table provisioned reads:${reads}/${readsMax}`);
|
|
22
|
-
warn(`dynamo table provisioned writes:${writes}/${writesMax}`);
|
|
24
|
+
(0, log_1.warn)(`dynamo table provisioned reads:${reads}/${readsMax}`);
|
|
25
|
+
(0, log_1.warn)(`dynamo table provisioned writes:${writes}/${writesMax}`);
|
|
23
26
|
if (reads > readsMax || writes > writesMax) {
|
|
24
27
|
throw new Error('exceeded dynamo provision cap');
|
|
25
28
|
}
|
|
@@ -27,3 +30,4 @@ export const enforceDynamoProvisionCap = ({ tables, readsMax = 25, writesMax = 2
|
|
|
27
30
|
throw new Error(`dynamo provision cap not met`);
|
|
28
31
|
}
|
|
29
32
|
};
|
|
33
|
+
exports.enforceDynamoProvisionCap = enforceDynamoProvisionCap;
|
|
@@ -1,14 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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("./api"), exports);
|
|
18
|
+
__exportStar(require("./aws"), exports);
|
|
19
|
+
__exportStar(require("./cloudfront"), exports);
|
|
20
|
+
__exportStar(require("./dynamo"), exports);
|
|
21
|
+
__exportStar(require("./dynamoInfra"), exports);
|
|
22
|
+
__exportStar(require("./enforceDynamoProvisionCap"), exports);
|
|
23
|
+
__exportStar(require("./openApiHelpers"), exports);
|
|
24
|
+
__exportStar(require("./s3"), exports);
|
|
25
|
+
__exportStar(require("./ses"), exports);
|
|
26
|
+
__exportStar(require("./sqs"), exports);
|
|
27
|
+
__exportStar(require("./ssm"), exports);
|
|
28
|
+
__exportStar(require("./sts"), exports);
|
|
29
|
+
__exportStar(require("./validateOpenApi"), exports);
|
|
30
|
+
__exportStar(require("./validations"), exports);
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openApiImpl = void 0;
|
|
1
4
|
/* eslint-disable no-new */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
const aws_cdk_lib_1 = require("aws-cdk-lib");
|
|
6
|
+
const array_1 = require("../../common/helpers/array");
|
|
7
|
+
const log_1 = require("../../common/helpers/log");
|
|
5
8
|
// eslint-disable-next-line
|
|
6
9
|
const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]) => ({
|
|
7
10
|
fullPath,
|
|
@@ -9,64 +12,63 @@ const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]
|
|
|
9
12
|
verbs: Object.keys(verbs),
|
|
10
13
|
}));
|
|
11
14
|
const setUpApiGw = ({ stack, NODE_ENV, certificate, shortStackName, r53, cors = {
|
|
12
|
-
allowOrigins:
|
|
13
|
-
allowHeaders:
|
|
15
|
+
allowOrigins: aws_cdk_lib_1.aws_apigateway.Cors.ALL_ORIGINS,
|
|
16
|
+
allowHeaders: aws_cdk_lib_1.aws_apigateway.Cors.DEFAULT_HEADERS,
|
|
14
17
|
}, }) => {
|
|
15
|
-
const api = new
|
|
16
|
-
defaultCorsPreflightOptions: {
|
|
17
|
-
...(cors || {}),
|
|
18
|
-
},
|
|
18
|
+
const api = new aws_cdk_lib_1.aws_apigateway.RestApi(stack, `${shortStackName}-api-${NODE_ENV}`, {
|
|
19
|
+
defaultCorsPreflightOptions: Object.assign({}, (cors || {})),
|
|
19
20
|
});
|
|
20
21
|
if (r53) {
|
|
21
|
-
const dn = new
|
|
22
|
+
const dn = new aws_cdk_lib_1.aws_apigateway.DomainName(stack, 'domain', {
|
|
22
23
|
domainName: r53.apiUrl,
|
|
23
24
|
certificate,
|
|
24
|
-
endpointType:
|
|
25
|
-
securityPolicy:
|
|
25
|
+
endpointType: aws_cdk_lib_1.aws_apigateway.EndpointType.EDGE,
|
|
26
|
+
securityPolicy: aws_cdk_lib_1.aws_apigateway.SecurityPolicy.TLS_1_2,
|
|
26
27
|
mapping: api,
|
|
27
28
|
});
|
|
28
29
|
if (r53.hostedZone) {
|
|
29
|
-
new
|
|
30
|
+
new aws_cdk_lib_1.aws_route53.ARecord(stack, 'ARecord', {
|
|
30
31
|
comment: '(cdk)',
|
|
31
32
|
recordName: r53.apiUrl.substring(0, r53.apiUrl.indexOf('.')),
|
|
32
33
|
zone: r53.hostedZone,
|
|
33
|
-
target:
|
|
34
|
+
target: aws_cdk_lib_1.aws_route53.RecordTarget.fromAlias(new aws_cdk_lib_1.aws_route53_targets.ApiGatewayDomain(dn)),
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
return api;
|
|
38
39
|
};
|
|
39
40
|
const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers, }) => {
|
|
41
|
+
var _a, _b, _c, _d;
|
|
40
42
|
const pathCompute = pathV + '/' + verb;
|
|
41
|
-
const lp = lambdaConfig
|
|
43
|
+
const lp = lambdaConfig === null || lambdaConfig === void 0 ? void 0 : lambdaConfig[pathCompute];
|
|
42
44
|
if (lp) {
|
|
43
45
|
seenPermissions[pathCompute] = true;
|
|
44
46
|
}
|
|
45
47
|
else {
|
|
46
48
|
seenPermissions[pathCompute] = false;
|
|
47
49
|
}
|
|
48
|
-
const def = lambdaConfig
|
|
50
|
+
const def = lambdaConfig === null || lambdaConfig === void 0 ? void 0 : lambdaConfig.default;
|
|
49
51
|
if (def) {
|
|
50
52
|
seenPermissions.default = true;
|
|
51
53
|
}
|
|
52
54
|
//
|
|
53
|
-
const readTables = distinctBy([...(def
|
|
54
|
-
const writeTables = distinctBy([...(def
|
|
55
|
-
const policies = [...(def.policies || []), ...(lp
|
|
56
|
-
const layers = [...(def.layers || []), ...(lp
|
|
57
|
-
const memory = lp
|
|
55
|
+
const readTables = (0, array_1.distinctBy)([...(((_a = def === null || def === void 0 ? void 0 : def.dynamo) === null || _a === void 0 ? void 0 : _a.reads) || []), ...(((_b = lp === null || lp === void 0 ? void 0 : lp.dynamo) === null || _b === void 0 ? void 0 : _b.reads) || [])], (s) => s.shortName);
|
|
56
|
+
const writeTables = (0, array_1.distinctBy)([...(((_c = def === null || def === void 0 ? void 0 : def.dynamo) === null || _c === void 0 ? void 0 : _c.writes) || []), ...(((_d = lp === null || lp === void 0 ? void 0 : lp.dynamo) === null || _d === void 0 ? void 0 : _d.writes) || [])], (s) => s.shortName);
|
|
57
|
+
const policies = [...(def.policies || []), ...((lp === null || lp === void 0 ? void 0 : lp.policies) || [])].filter(array_1.notEmpty);
|
|
58
|
+
const layers = [...(def.layers || []), ...((lp === null || lp === void 0 ? void 0 : lp.layers) || [])].filter(array_1.notEmpty);
|
|
59
|
+
const memory = (lp === null || lp === void 0 ? void 0 : lp.memory) || (def === null || def === void 0 ? void 0 : def.memory) || 128;
|
|
58
60
|
// null forces undefined, undefined forces 5
|
|
59
|
-
let reservedConcurrentExecutions = lp
|
|
61
|
+
let reservedConcurrentExecutions = lp === null || lp === void 0 ? void 0 : lp.reservedConcurrentExecutions;
|
|
60
62
|
if (reservedConcurrentExecutions === undefined) {
|
|
61
|
-
reservedConcurrentExecutions = def
|
|
63
|
+
reservedConcurrentExecutions = def === null || def === void 0 ? void 0 : def.reservedConcurrentExecutions;
|
|
62
64
|
}
|
|
63
65
|
if (reservedConcurrentExecutions === undefined) {
|
|
64
66
|
reservedConcurrentExecutions = 5;
|
|
65
67
|
}
|
|
66
|
-
reservedConcurrentExecutions = reservedConcurrentExecutions
|
|
68
|
+
reservedConcurrentExecutions = reservedConcurrentExecutions !== null && reservedConcurrentExecutions !== void 0 ? reservedConcurrentExecutions : undefined;
|
|
67
69
|
//
|
|
68
|
-
const timeout = Duration.seconds(lp
|
|
69
|
-
let authorizerName = lp
|
|
70
|
+
const timeout = aws_cdk_lib_1.Duration.seconds((lp === null || lp === void 0 ? void 0 : lp.timeoutS) || (def === null || def === void 0 ? void 0 : def.timeoutS) || 30);
|
|
71
|
+
let authorizerName = lp === null || lp === void 0 ? void 0 : lp.authorizerName;
|
|
70
72
|
if (authorizerName === undefined) {
|
|
71
73
|
authorizerName = def.authorizerName;
|
|
72
74
|
}
|
|
@@ -75,8 +77,8 @@ const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers,
|
|
|
75
77
|
}
|
|
76
78
|
const authorizer = !authorizerName
|
|
77
79
|
? undefined
|
|
78
|
-
: authorizers
|
|
79
|
-
const env = {
|
|
80
|
+
: authorizers === null || authorizers === void 0 ? void 0 : authorizers[authorizerName];
|
|
81
|
+
const env = Object.assign(Object.assign({}, (def.env || {})), ((lp === null || lp === void 0 ? void 0 : lp.env) || {}));
|
|
80
82
|
const tables = [...readTables, ...writeTables];
|
|
81
83
|
const environment = env;
|
|
82
84
|
Object.values(tables).forEach((v) => {
|
|
@@ -113,7 +115,7 @@ const addApiPaths = (api, pathList, apiRoots) => {
|
|
|
113
115
|
return apiPath;
|
|
114
116
|
};
|
|
115
117
|
const lambdaNameSafe = (raw) => raw.replace(/[^a-zA-Z0-9-.]/gim, '-').replace(/(-){2,}/gim, '-');
|
|
116
|
-
|
|
118
|
+
const openApiImpl = (p) => {
|
|
117
119
|
if (!p.schema) {
|
|
118
120
|
throw new Error('no openapi schema found');
|
|
119
121
|
}
|
|
@@ -134,9 +136,9 @@ export const openApiImpl = (p) => {
|
|
|
134
136
|
});
|
|
135
137
|
const lambdaName = lambdaNameSafe(`${p.shortStackName}-${fullPath}-${verb}-${NODE_ENV}`);
|
|
136
138
|
const entry = `${endpointsBase}${fullPath}/${verb.toUpperCase()}.ts`;
|
|
137
|
-
const lambdaV = new
|
|
139
|
+
const lambdaV = new aws_cdk_lib_1.aws_lambda_nodejs.NodejsFunction(stack, lambdaName, {
|
|
138
140
|
functionName: lambdaName,
|
|
139
|
-
runtime:
|
|
141
|
+
runtime: aws_cdk_lib_1.aws_lambda.Runtime.NODEJS_16_X,
|
|
140
142
|
handler: 'handler',
|
|
141
143
|
environment: lc.environment,
|
|
142
144
|
memorySize: lc.memory,
|
|
@@ -147,19 +149,19 @@ export const openApiImpl = (p) => {
|
|
|
147
149
|
externalModules: ['aws-sdk', 'aws-lambda'],
|
|
148
150
|
},
|
|
149
151
|
reservedConcurrentExecutions: lc.reservedConcurrentExecutions,
|
|
150
|
-
logRetention:
|
|
152
|
+
logRetention: aws_cdk_lib_1.aws_logs.RetentionDays.FIVE_DAYS,
|
|
151
153
|
layers: lc.layers,
|
|
152
154
|
});
|
|
153
155
|
lc.readTables.forEach((t) => t.table.grantReadData(lambdaV));
|
|
154
156
|
lc.writeTables.forEach((t) => t.table.grantReadWriteData(lambdaV));
|
|
155
157
|
lc.policies.forEach((p1) => lambdaV.addToRolePolicy(p1));
|
|
156
158
|
//
|
|
157
|
-
apiPath.addMethod(verb.toUpperCase(), new
|
|
159
|
+
apiPath.addMethod(verb.toUpperCase(), new aws_cdk_lib_1.aws_apigateway.LambdaIntegration(lambdaV, {}), { authorizer: lc.authorizer });
|
|
158
160
|
});
|
|
159
161
|
});
|
|
160
162
|
Object.keys(lambdaConfig).forEach((k) => {
|
|
161
163
|
if (!seenPermissions[k] || seenPermissions[k] === false) {
|
|
162
|
-
warn(`unused permissions for '${k}', did you mean one of these paths?=`, Object.entries(seenPermissions)
|
|
164
|
+
(0, log_1.warn)(`unused permissions for '${k}', did you mean one of these paths?=`, Object.entries(seenPermissions)
|
|
163
165
|
.filter(([, b]) => !b)
|
|
164
166
|
.map(([f]) => f)
|
|
165
167
|
.join('\n'));
|
|
@@ -167,3 +169,4 @@ export const openApiImpl = (p) => {
|
|
|
167
169
|
}
|
|
168
170
|
});
|
|
169
171
|
};
|
|
172
|
+
exports.openApiImpl = openApiImpl;
|
package/dist/api/helpers/s3.js
CHANGED
|
@@ -1,32 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
12
|
+
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
13
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
14
|
+
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
15
|
+
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
16
|
+
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
|
|
17
|
+
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
18
|
+
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
19
|
+
function fulfill(value) { resume("next", value); }
|
|
20
|
+
function reject(value) { resume("throw", value); }
|
|
21
|
+
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
22
|
+
};
|
|
23
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
7
25
|
};
|
|
8
|
-
|
|
26
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.getPresignedPostURL = exports.listFiles = exports.copyFile = exports.deleteFiles = exports.deleteFile = exports.uploadFile = exports.putS3Object = exports.getS3Objects = exports.getS3Object = exports.setS3 = void 0;
|
|
28
|
+
const s3_1 = __importDefault(require("aws-sdk/clients/s3"));
|
|
29
|
+
const array_1 = require("../../common/helpers/array");
|
|
30
|
+
const log_1 = require("../../common/helpers/log");
|
|
31
|
+
let s3 = new s3_1.default();
|
|
32
|
+
const setS3 = (region) => {
|
|
33
|
+
s3 = new s3_1.default({ region });
|
|
34
|
+
};
|
|
35
|
+
exports.setS3 = setS3;
|
|
36
|
+
const getS3Object = ({ fileurl, }) => __awaiter(void 0, void 0, void 0, function* () { return s3.getObject(fileurl).promise(); });
|
|
37
|
+
exports.getS3Object = getS3Object;
|
|
9
38
|
/** function generator to get s3 files */
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
function getS3Objects({ bucket, keys, }) {
|
|
40
|
+
return __asyncGenerator(this, arguments, function* getS3Objects_1() {
|
|
41
|
+
let toProcess = keys.map((Key) => ({
|
|
42
|
+
Bucket: bucket,
|
|
43
|
+
Key,
|
|
44
|
+
}));
|
|
45
|
+
while (toProcess.length > 0) {
|
|
46
|
+
const { part, rest } = (0, array_1.take)(toProcess, 1);
|
|
47
|
+
toProcess = rest;
|
|
48
|
+
const fileurl = part[0];
|
|
49
|
+
const content = yield __await((0, exports.getS3Object)({ fileurl }));
|
|
50
|
+
const ret1 = {
|
|
51
|
+
bucket: fileurl.Bucket,
|
|
52
|
+
key: fileurl.Key,
|
|
53
|
+
content: content.Body,
|
|
54
|
+
};
|
|
55
|
+
yield yield __await(ret1);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
27
58
|
}
|
|
28
|
-
|
|
29
|
-
|
|
59
|
+
exports.getS3Objects = getS3Objects;
|
|
60
|
+
const putS3Object = ({ Body, Bucket, Key, ContentType, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
61
|
+
const r = yield s3
|
|
30
62
|
.putObject({
|
|
31
63
|
Body,
|
|
32
64
|
Bucket,
|
|
@@ -38,44 +70,49 @@ export const putS3Object = async ({ Body, Bucket, Key, ContentType, }) => {
|
|
|
38
70
|
return { error: r.$response.error.message };
|
|
39
71
|
}
|
|
40
72
|
return {};
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
|
|
73
|
+
});
|
|
74
|
+
exports.putS3Object = putS3Object;
|
|
75
|
+
const uploadFile = ({ Bucket, Key, Body, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
+
const res = yield s3.upload({ Bucket, Key, Body }).promise();
|
|
44
77
|
return res.Location;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
|
|
78
|
+
});
|
|
79
|
+
exports.uploadFile = uploadFile;
|
|
80
|
+
const deleteFile = ({ Bucket, Key, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
|
+
const res = yield s3.deleteObject({ Bucket, Key }).promise();
|
|
48
82
|
if (res.$response.error) {
|
|
49
83
|
return { error: res.$response.error.message };
|
|
50
84
|
}
|
|
51
85
|
return {};
|
|
52
|
-
};
|
|
53
|
-
|
|
86
|
+
});
|
|
87
|
+
exports.deleteFile = deleteFile;
|
|
88
|
+
const deleteFiles = ({ Bucket, Keys, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
var _a;
|
|
54
90
|
let toDelete = Keys.map((Key) => ({ Key }));
|
|
55
91
|
let deleted = 0;
|
|
56
92
|
while (toDelete.length > 0) {
|
|
57
|
-
const { part, rest } = take(toDelete, 900);
|
|
93
|
+
const { part, rest } = (0, array_1.take)(toDelete, 900);
|
|
58
94
|
toDelete = rest;
|
|
59
|
-
const res =
|
|
95
|
+
const res = yield s3
|
|
60
96
|
.deleteObjects({
|
|
61
97
|
Bucket,
|
|
62
98
|
Delete: { Objects: part },
|
|
63
99
|
})
|
|
64
100
|
.promise();
|
|
65
|
-
if (!res.Deleted
|
|
101
|
+
if (!((_a = res.Deleted) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
66
102
|
throw new Error('no deleted files');
|
|
67
103
|
}
|
|
68
104
|
deleted += res.Deleted.length;
|
|
69
105
|
if (res.$response.error) {
|
|
70
106
|
return { error: res.$response.error.message };
|
|
71
107
|
}
|
|
72
|
-
info(`deleted ${deleted} files`);
|
|
108
|
+
(0, log_1.info)(`deleted ${deleted} files`);
|
|
73
109
|
}
|
|
74
110
|
return {};
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
111
|
+
});
|
|
112
|
+
exports.deleteFiles = deleteFiles;
|
|
113
|
+
const copyFile = ({ Bucket, fromKey, toKey, deleteSource = false, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
(0, log_1.debug)(`copying s3 file from ${Bucket}- ${fromKey} to ${toKey}`);
|
|
115
|
+
const res = yield s3
|
|
79
116
|
.copyObject({
|
|
80
117
|
//incl bucket
|
|
81
118
|
CopySource: Bucket + '/' + fromKey,
|
|
@@ -88,39 +125,44 @@ export const copyFile = async ({ Bucket, fromKey, toKey, deleteSource = false, }
|
|
|
88
125
|
return { error: res.$response.error.message };
|
|
89
126
|
}
|
|
90
127
|
if (deleteSource) {
|
|
91
|
-
const df =
|
|
128
|
+
const df = yield (0, exports.deleteFile)({ Bucket, Key: fromKey });
|
|
92
129
|
if (df.error) {
|
|
93
130
|
return { error: df.error };
|
|
94
131
|
}
|
|
95
132
|
}
|
|
96
133
|
return {};
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
134
|
+
});
|
|
135
|
+
exports.copyFile = copyFile;
|
|
136
|
+
function listFiles(bucketName, opt) {
|
|
137
|
+
var _a, _b;
|
|
138
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
139
|
+
try {
|
|
140
|
+
const ret = [];
|
|
141
|
+
let response = {
|
|
142
|
+
IsTruncated: true,
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
144
|
+
};
|
|
145
|
+
while (response.IsTruncated) {
|
|
146
|
+
response = yield s3
|
|
147
|
+
.listObjectsV2({
|
|
148
|
+
Bucket: bucketName,
|
|
149
|
+
ContinuationToken: response.NextContinuationToken,
|
|
150
|
+
Prefix: opt === null || opt === void 0 ? void 0 : opt.prefix,
|
|
151
|
+
})
|
|
152
|
+
.promise();
|
|
153
|
+
(_b = (_a = response.Contents) === null || _a === void 0 ? void 0 : _a.filter((r) => r.Key)) === null || _b === void 0 ? void 0 : _b.map((c) => {
|
|
154
|
+
ret.push(c.Key);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return (0, array_1.distinct)(ret.filter((r) => r));
|
|
116
158
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
159
|
+
catch (err) {
|
|
160
|
+
(0, log_1.error)('Error', err);
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
123
164
|
}
|
|
165
|
+
exports.listFiles = listFiles;
|
|
124
166
|
/**
|
|
125
167
|
* allow uploading of file directly to s3
|
|
126
168
|
* @param param0
|
|
@@ -134,18 +176,21 @@ export async function listFiles(bucketName, opt) {
|
|
|
134
176
|
formData.append('file', file);
|
|
135
177
|
fetch.POST(url,formData)
|
|
136
178
|
*/
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
[
|
|
146
|
-
|
|
147
|
-
|
|
179
|
+
function getPresignedPostURL({ bucket, key, maxMb = 5, }) {
|
|
180
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
181
|
+
const ps = yield s3.createPresignedPost({
|
|
182
|
+
Bucket: bucket,
|
|
183
|
+
Fields: {
|
|
184
|
+
Key: key,
|
|
185
|
+
},
|
|
186
|
+
Expires: 600,
|
|
187
|
+
Conditions: [
|
|
188
|
+
['content-length-range', 0, maxMb * 1049000],
|
|
189
|
+
['starts-with', '$Content-Type', 'image/'],
|
|
190
|
+
],
|
|
191
|
+
});
|
|
192
|
+
const fields = JSON.parse(JSON.stringify(ps.fields));
|
|
193
|
+
return { fields, url: ps.url };
|
|
148
194
|
});
|
|
149
|
-
const fields = JSON.parse(JSON.stringify(ps.fields));
|
|
150
|
-
return { fields, url: ps.url };
|
|
151
195
|
}
|
|
196
|
+
exports.getPresignedPostURL = getPresignedPostURL;
|
package/dist/api/helpers/ses.js
CHANGED
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
5
10
|
};
|
|
6
|
-
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.sendEmails = exports.sendEmail = exports.setSes = exports.ses = void 0;
|
|
16
|
+
const ses_1 = __importDefault(require("aws-sdk/clients/ses"));
|
|
17
|
+
exports.ses = new ses_1.default();
|
|
18
|
+
const setSes = (region) => {
|
|
19
|
+
exports.ses = new ses_1.default({ region });
|
|
20
|
+
};
|
|
21
|
+
exports.setSes = setSes;
|
|
22
|
+
const sendEmail = ({ to, message, subject, sourceArn, from, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
var _a;
|
|
7
24
|
// Create sendEmail params
|
|
8
25
|
const params = {
|
|
9
26
|
Destination: {
|
|
@@ -26,10 +43,12 @@ export const sendEmail = async ({ to, message, subject, sourceArn, from, }) => {
|
|
|
26
43
|
ReplyToAddresses: [from],
|
|
27
44
|
SourceArn: sourceArn,
|
|
28
45
|
};
|
|
29
|
-
const res =
|
|
46
|
+
const res = yield exports.ses.sendEmail(params).promise();
|
|
30
47
|
if (res.$response.error) {
|
|
31
|
-
return { error: res.$response.error
|
|
48
|
+
return { error: (_a = res.$response.error) === null || _a === void 0 ? void 0 : _a.message };
|
|
32
49
|
}
|
|
33
50
|
return {};
|
|
34
|
-
};
|
|
35
|
-
|
|
51
|
+
});
|
|
52
|
+
exports.sendEmail = sendEmail;
|
|
53
|
+
const sendEmails = (emails) => __awaiter(void 0, void 0, void 0, function* () { return Promise.all(emails.map(exports.sendEmail)); });
|
|
54
|
+
exports.sendEmails = sendEmails;
|
package/dist/api/helpers/sqs.js
CHANGED
|
@@ -1,21 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.sendMessages = exports.setSqs = exports.sqs = void 0;
|
|
16
|
+
const sqs_1 = __importDefault(require("aws-sdk/clients/sqs"));
|
|
17
|
+
const hashCode_1 = require("../../common/helpers/hashCode");
|
|
3
18
|
// eslint-disable-next-line import/no-mutable-exports
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
sqs = new
|
|
19
|
+
exports.sqs = new sqs_1.default();
|
|
20
|
+
const setSqs = (region) => {
|
|
21
|
+
exports.sqs = new sqs_1.default({ region });
|
|
7
22
|
};
|
|
8
|
-
|
|
23
|
+
exports.setSqs = setSqs;
|
|
24
|
+
const sendMessages = (items, queueUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
9
25
|
const req = {
|
|
10
26
|
QueueUrl: queueUrl,
|
|
11
27
|
Entries: items.map((i) => ({
|
|
12
28
|
MessageBody: JSON.stringify(i),
|
|
13
|
-
Id: hashCode(JSON.stringify(i)),
|
|
29
|
+
Id: (0, hashCode_1.hashCode)(JSON.stringify(i)),
|
|
14
30
|
})),
|
|
15
31
|
};
|
|
16
|
-
const put =
|
|
32
|
+
const put = yield exports.sqs.sendMessageBatch(req).promise();
|
|
17
33
|
if (put.$response.error && put.$response.error.statusCode) {
|
|
18
34
|
return { error: put.$response.error.message };
|
|
19
35
|
}
|
|
20
36
|
return {};
|
|
21
|
-
};
|
|
37
|
+
});
|
|
38
|
+
exports.sendMessages = sendMessages;
|