ag-common 0.0.183 → 0.0.186
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.
|
@@ -9,6 +9,16 @@ export declare const returnCode: <T>(statusCode: number, body?: T | undefined, e
|
|
|
9
9
|
* @returns stripped record
|
|
10
10
|
*/
|
|
11
11
|
export declare const stripPKs: <T>(record: T, keepPk?: boolean) => T;
|
|
12
|
+
/**
|
|
13
|
+
* generate dynamo PKs.
|
|
14
|
+
* PK = all Ls joined with #
|
|
15
|
+
* PK1 = L1
|
|
16
|
+
* PK2 = L1#L2
|
|
17
|
+
* PK3 = L1#L2#L3
|
|
18
|
+
* ...
|
|
19
|
+
* @param param0
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
12
22
|
export declare const generateDynamoPKS: ({ type, L1, L2, L3, L4, L5, L6, additionalPKValues, }: {
|
|
13
23
|
type: string;
|
|
14
24
|
L1: string;
|
package/dist/api/helpers/api.js
CHANGED
|
@@ -57,14 +57,26 @@ const stripPKs = (record, keepPk = true) => {
|
|
|
57
57
|
return rest;
|
|
58
58
|
};
|
|
59
59
|
exports.stripPKs = stripPKs;
|
|
60
|
+
/**
|
|
61
|
+
* generate dynamo PKs.
|
|
62
|
+
* PK = all Ls joined with #
|
|
63
|
+
* PK1 = L1
|
|
64
|
+
* PK2 = L1#L2
|
|
65
|
+
* PK3 = L1#L2#L3
|
|
66
|
+
* ...
|
|
67
|
+
* @param param0
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
60
70
|
const generateDynamoPKS = ({ type, L1, L2, L3, L4, L5, L6, additionalPKValues, }) => {
|
|
61
71
|
const c = '#';
|
|
62
72
|
const keys = [L1, L2, L3, L4, L5, L6].filter(array_1.notEmpty);
|
|
63
73
|
const additionalPK = additionalPKValues && (additionalPKValues === null || additionalPKValues === void 0 ? void 0 : additionalPKValues.length) > 0
|
|
64
74
|
? `#${additionalPKValues.join(c)}`
|
|
65
75
|
: '';
|
|
66
|
-
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ PK: keys.join(c) + additionalPK, type,
|
|
67
|
-
L1 }, (L2 && { L2 })), (L3 && { L3 })), (L4 && { L4 })), (L5 && { L5 })), (L6 && { L6 })), { PK1: L1
|
|
76
|
+
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({ PK: keys.join(c) + additionalPK, type,
|
|
77
|
+
L1 }, (L2 && { L2 })), (L3 && { L3 })), (L4 && { L4 })), (L5 && { L5 })), (L6 && { L6 })), { PK1: L1 }), (keys.length >= 2 && {
|
|
78
|
+
PK2: [keys[0], keys[1]].join(c),
|
|
79
|
+
})), (keys.length >= 3 && {
|
|
68
80
|
PK3: [keys[0], keys[1], keys[2]].join(c),
|
|
69
81
|
})), (keys.length >= 4 && {
|
|
70
82
|
PK4: [keys[0], keys[1], keys[2], keys[3]].join(c),
|
|
@@ -212,7 +212,19 @@ const getItemsDynamo = ({ tableName, items, }) => __awaiter(void 0, void 0, void
|
|
|
212
212
|
}
|
|
213
213
|
});
|
|
214
214
|
exports.getItemsDynamo = getItemsDynamo;
|
|
215
|
-
const queryDynamo = ({ tableName, pkName, pkValue,
|
|
215
|
+
const queryDynamo = ({ tableName, pkName, pkValue,
|
|
216
|
+
/**
|
|
217
|
+
* default =
|
|
218
|
+
*/
|
|
219
|
+
pkOperator = '=', skName, skValue,
|
|
220
|
+
/**
|
|
221
|
+
* default =
|
|
222
|
+
*/
|
|
223
|
+
skOperator = '=', indexName, count = 1000, startKey: startKeyIn, filterName, filterValue,
|
|
224
|
+
/**
|
|
225
|
+
* default =
|
|
226
|
+
*/
|
|
227
|
+
filterOperator = '=', }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
216
228
|
var _g, _h;
|
|
217
229
|
let startKey = startKeyIn;
|
|
218
230
|
let kce = `#${pkName.toLowerCase()} ${pkOperator} :${pkName.toLowerCase()}`;
|
|
@@ -3,17 +3,19 @@ import { Construct } from 'constructs';
|
|
|
3
3
|
import { aws_certificatemanager as certmgr, aws_route53 as route53 } from 'aws-cdk-lib';
|
|
4
4
|
import { TokenAuthorizer } from 'aws-cdk-lib/aws-apigateway/lib/authorizers/lambda';
|
|
5
5
|
export declare const openApiImpl: (p: {
|
|
6
|
-
schema: unknown;
|
|
7
6
|
stack: Construct;
|
|
7
|
+
/**
|
|
8
|
+
* pass in generated openapi file
|
|
9
|
+
* eg schema: require('common/openapi.generated').default;
|
|
10
|
+
*/
|
|
11
|
+
schema: unknown;
|
|
8
12
|
NODE_ENV: string;
|
|
9
|
-
baseUrl: string;
|
|
10
13
|
endpointsBase: string;
|
|
11
14
|
/**
|
|
12
15
|
* 'default' will be applied to all functions
|
|
13
16
|
*/
|
|
14
17
|
lambdaConfig: ILambdaConfigs;
|
|
15
18
|
certificate: certmgr.ICertificate;
|
|
16
|
-
hostedZone: route53.IHostedZone;
|
|
17
19
|
shortStackName: string;
|
|
18
20
|
/**
|
|
19
21
|
* defaults:
|
|
@@ -28,4 +30,10 @@ export declare const openApiImpl: (p: {
|
|
|
28
30
|
* dictionary of named authorizer functions. these names are to be used in the lambdaConfig param
|
|
29
31
|
*/
|
|
30
32
|
authorizers?: Record<string, TokenAuthorizer>;
|
|
33
|
+
hostedZone: route53.IHostedZone;
|
|
34
|
+
/**
|
|
35
|
+
* A record will be created in hosted zone for the apigw on this path. if undefined, record wont be created
|
|
36
|
+
* eg api.mydomain.com
|
|
37
|
+
*/
|
|
38
|
+
apiUrl?: string;
|
|
31
39
|
}) => void;
|
|
@@ -11,26 +11,28 @@ const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]
|
|
|
11
11
|
pathList: fullPath.split('/').filter((s) => s),
|
|
12
12
|
verbs: Object.keys(verbs),
|
|
13
13
|
}));
|
|
14
|
-
const setUpApiGw = ({ stack, NODE_ENV,
|
|
14
|
+
const setUpApiGw = ({ stack, NODE_ENV, certificate, hostedZone, shortStackName, apiUrl, cors = {
|
|
15
15
|
allowOrigins: aws_cdk_lib_1.aws_apigateway.Cors.ALL_ORIGINS,
|
|
16
16
|
allowHeaders: aws_cdk_lib_1.aws_apigateway.Cors.DEFAULT_HEADERS,
|
|
17
17
|
}, }) => {
|
|
18
18
|
const api = new aws_cdk_lib_1.aws_apigateway.RestApi(stack, `${shortStackName}-api-${NODE_ENV}`, {
|
|
19
19
|
defaultCorsPreflightOptions: Object.assign({}, (cors || {})),
|
|
20
20
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
if (apiUrl) {
|
|
22
|
+
const dn = new aws_cdk_lib_1.aws_apigateway.DomainName(stack, 'domain', {
|
|
23
|
+
domainName: apiUrl,
|
|
24
|
+
certificate,
|
|
25
|
+
endpointType: aws_cdk_lib_1.aws_apigateway.EndpointType.EDGE,
|
|
26
|
+
securityPolicy: aws_cdk_lib_1.aws_apigateway.SecurityPolicy.TLS_1_2,
|
|
27
|
+
mapping: api,
|
|
28
|
+
});
|
|
29
|
+
new aws_cdk_lib_1.aws_route53.ARecord(stack, 'ARecord', {
|
|
30
|
+
comment: '(cdk)',
|
|
31
|
+
recordName: apiUrl.substring(0, apiUrl.indexOf('.')),
|
|
32
|
+
zone: hostedZone,
|
|
33
|
+
target: aws_cdk_lib_1.aws_route53.RecordTarget.fromAlias(new aws_cdk_lib_1.aws_route53_targets.ApiGatewayDomain(dn)),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
34
36
|
return api;
|
|
35
37
|
};
|
|
36
38
|
const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers, }) => {
|
|
@@ -53,6 +55,16 @@ const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers,
|
|
|
53
55
|
const policies = [...(def.policies || []), ...((lp === null || lp === void 0 ? void 0 : lp.policies) || [])].filter(array_1.notEmpty);
|
|
54
56
|
const layers = [...(def.layers || []), ...((lp === null || lp === void 0 ? void 0 : lp.layers) || [])].filter(array_1.notEmpty);
|
|
55
57
|
const memory = (lp === null || lp === void 0 ? void 0 : lp.memory) || (def === null || def === void 0 ? void 0 : def.memory) || 128;
|
|
58
|
+
// null forces undefined, undefined forces 5
|
|
59
|
+
let reservedConcurrentExecutions = lp === null || lp === void 0 ? void 0 : lp.reservedConcurrentExecutions;
|
|
60
|
+
if (reservedConcurrentExecutions === undefined) {
|
|
61
|
+
reservedConcurrentExecutions = def === null || def === void 0 ? void 0 : def.reservedConcurrentExecutions;
|
|
62
|
+
}
|
|
63
|
+
if (reservedConcurrentExecutions === undefined) {
|
|
64
|
+
reservedConcurrentExecutions = 5;
|
|
65
|
+
}
|
|
66
|
+
reservedConcurrentExecutions = reservedConcurrentExecutions !== null && reservedConcurrentExecutions !== void 0 ? reservedConcurrentExecutions : undefined;
|
|
67
|
+
//
|
|
56
68
|
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);
|
|
57
69
|
let authorizerName = lp === null || lp === void 0 ? void 0 : lp.authorizerName;
|
|
58
70
|
if (authorizerName === undefined) {
|
|
@@ -79,6 +91,7 @@ const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers,
|
|
|
79
91
|
authorizer,
|
|
80
92
|
memory,
|
|
81
93
|
timeout,
|
|
94
|
+
reservedConcurrentExecutions,
|
|
82
95
|
};
|
|
83
96
|
};
|
|
84
97
|
const addApiPaths = (api, pathList, apiRoots) => {
|
|
@@ -133,7 +146,7 @@ const openApiImpl = (p) => {
|
|
|
133
146
|
bundling: {
|
|
134
147
|
externalModules: ['aws-sdk', 'aws-lambda'],
|
|
135
148
|
},
|
|
136
|
-
reservedConcurrentExecutions:
|
|
149
|
+
reservedConcurrentExecutions: lc.reservedConcurrentExecutions,
|
|
137
150
|
logRetention: aws_cdk_lib_1.aws_logs.RetentionDays.FIVE_DAYS,
|
|
138
151
|
layers: lc.layers,
|
|
139
152
|
});
|
|
@@ -9,7 +9,7 @@ export interface DYNAMOKEYS {
|
|
|
9
9
|
L5?: string;
|
|
10
10
|
PK: string;
|
|
11
11
|
PK1: string;
|
|
12
|
-
PK2
|
|
12
|
+
PK2?: string;
|
|
13
13
|
PK3?: string;
|
|
14
14
|
PK4?: string;
|
|
15
15
|
}
|
|
@@ -37,6 +37,10 @@ export interface ILambdaConfig {
|
|
|
37
37
|
* lambda memory. defaults to 128
|
|
38
38
|
*/
|
|
39
39
|
memory?: number;
|
|
40
|
+
/**
|
|
41
|
+
* reserved lambda concurrency. defaults to 5. if null, doesnt apply
|
|
42
|
+
*/
|
|
43
|
+
reservedConcurrentExecutions?: number | null;
|
|
40
44
|
}
|
|
41
45
|
/**
|
|
42
46
|
* 'default' will be applied to all functions
|
|
@@ -46,13 +50,14 @@ export interface ILambdaConfigs {
|
|
|
46
50
|
default?: ILambdaConfig;
|
|
47
51
|
};
|
|
48
52
|
}
|
|
53
|
+
export declare type TSkOperator = 'BETWEEN' | '<' | '<=' | '=' | '>=' | '>';
|
|
49
54
|
export interface IQueryDynamo {
|
|
50
55
|
pkName: string;
|
|
51
56
|
pkValue: string | number;
|
|
52
57
|
pkOperator?: string;
|
|
53
58
|
skName?: string;
|
|
54
59
|
skValue?: string | number | string[] | number[];
|
|
55
|
-
skOperator?:
|
|
60
|
+
skOperator?: TSkOperator;
|
|
56
61
|
tableName: string;
|
|
57
62
|
indexName?: string;
|
|
58
63
|
count?: number;
|