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