ag-common 0.0.161 → 0.0.164
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ILambdaConfigs } from '../types';
|
|
2
2
|
import { Construct } from 'constructs';
|
|
3
3
|
import { aws_certificatemanager as certmgr, aws_route53 as route53 } from 'aws-cdk-lib';
|
|
4
|
+
import { TokenAuthorizer } from 'aws-cdk-lib/aws-apigateway/lib/authorizers/lambda';
|
|
4
5
|
export declare const openApiImpl: (p: {
|
|
5
6
|
schema: unknown;
|
|
6
7
|
stack: Construct;
|
|
@@ -20,4 +21,8 @@ export declare const openApiImpl: (p: {
|
|
|
20
21
|
allowOrigins: string[];
|
|
21
22
|
allowHeaders: string[];
|
|
22
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* dictionary of named authorizer functions. these names are to be used in the lambdaConfig param
|
|
26
|
+
*/
|
|
27
|
+
authorizers?: Record<string, TokenAuthorizer>;
|
|
23
28
|
}) => void;
|
|
@@ -33,7 +33,7 @@ const setUpApiGw = ({ stack, NODE_ENV, baseUrl, certificate, hostedZone, shortSt
|
|
|
33
33
|
});
|
|
34
34
|
return api;
|
|
35
35
|
};
|
|
36
|
-
const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, }) => {
|
|
36
|
+
const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers, }) => {
|
|
37
37
|
var _a, _b, _c, _d;
|
|
38
38
|
const pathCompute = pathV + '/' + verb;
|
|
39
39
|
const lp = lambdaConfig === null || lambdaConfig === void 0 ? void 0 : lambdaConfig[pathCompute];
|
|
@@ -52,13 +52,30 @@ const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, }) => {
|
|
|
52
52
|
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);
|
|
53
53
|
const policies = [...(def.policies || []), ...((lp === null || lp === void 0 ? void 0 : lp.policies) || [])].filter(array_1.notEmpty);
|
|
54
54
|
const layers = [...(def.layers || []), ...((lp === null || lp === void 0 ? void 0 : lp.layers) || [])].filter(array_1.notEmpty);
|
|
55
|
+
let authorizerName = lp === null || lp === void 0 ? void 0 : lp.authorizerName;
|
|
56
|
+
if (authorizerName === undefined) {
|
|
57
|
+
authorizerName = def.authorizerName;
|
|
58
|
+
}
|
|
59
|
+
if (authorizerName && (!authorizers || !authorizers[authorizerName])) {
|
|
60
|
+
throw new Error('unseen auth name:' + authorizerName);
|
|
61
|
+
}
|
|
62
|
+
const authorizer = !authorizerName
|
|
63
|
+
? undefined
|
|
64
|
+
: authorizers === null || authorizers === void 0 ? void 0 : authorizers[authorizerName];
|
|
55
65
|
const env = Object.assign(Object.assign({}, (def.env || {})), ((lp === null || lp === void 0 ? void 0 : lp.env) || {}));
|
|
56
66
|
const tables = [...readTables, ...writeTables];
|
|
57
67
|
const environment = env;
|
|
58
68
|
Object.values(tables).forEach((v) => {
|
|
59
69
|
environment[v.shortName] = v.table.tableName;
|
|
60
70
|
});
|
|
61
|
-
return {
|
|
71
|
+
return {
|
|
72
|
+
environment,
|
|
73
|
+
readTables,
|
|
74
|
+
writeTables,
|
|
75
|
+
policies,
|
|
76
|
+
layers,
|
|
77
|
+
authorizer,
|
|
78
|
+
};
|
|
62
79
|
};
|
|
63
80
|
const addApiPaths = (api, pathList, apiRoots) => {
|
|
64
81
|
let pathBuild = '';
|
|
@@ -91,11 +108,12 @@ const openApiImpl = (p) => {
|
|
|
91
108
|
paths.forEach(({ fullPath, verbs, pathList }) => {
|
|
92
109
|
const apiPath = addApiPaths(api, pathList, apiRoots);
|
|
93
110
|
verbs.forEach((verb) => {
|
|
94
|
-
const { environment, readTables, writeTables, policies, layers } = setupLambda({
|
|
111
|
+
const { environment, readTables, writeTables, policies, layers, authorizer, } = setupLambda({
|
|
95
112
|
lambdaConfig,
|
|
96
113
|
pathV: fullPath,
|
|
97
114
|
verb,
|
|
98
115
|
seenPermissions,
|
|
116
|
+
authorizers: p.authorizers,
|
|
99
117
|
});
|
|
100
118
|
const lambdaName = lambdaNameSafe(`${p.shortStackName}-${fullPath}-${verb}-${NODE_ENV}`);
|
|
101
119
|
const entry = `${endpointsBase}${fullPath}/${verb.toUpperCase()}.ts`;
|
|
@@ -119,7 +137,7 @@ const openApiImpl = (p) => {
|
|
|
119
137
|
writeTables.forEach((t) => t.table.grantReadWriteData(lambdaV));
|
|
120
138
|
policies.forEach((p1) => lambdaV.addToRolePolicy(p1));
|
|
121
139
|
//
|
|
122
|
-
apiPath.addMethod(verb.toUpperCase(), new aws_cdk_lib_1.aws_apigateway.LambdaIntegration(lambdaV, {}));
|
|
140
|
+
apiPath.addMethod(verb.toUpperCase(), new aws_cdk_lib_1.aws_apigateway.LambdaIntegration(lambdaV, {}), { authorizer });
|
|
123
141
|
});
|
|
124
142
|
});
|
|
125
143
|
Object.keys(lambdaConfig).forEach((k) => {
|
|
@@ -25,7 +25,14 @@ export interface ILambdaConfig {
|
|
|
25
25
|
policies?: iam.PolicyStatement[];
|
|
26
26
|
env?: Record<string, string>;
|
|
27
27
|
layers?: lambda.ILayerVersion[];
|
|
28
|
+
/**
|
|
29
|
+
* use the name of the lambda authorizer passed in in the openApiImpl config
|
|
30
|
+
*/
|
|
31
|
+
authorizerName?: string;
|
|
28
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* 'default' will be applied to all functions
|
|
35
|
+
*/
|
|
29
36
|
export interface ILambdaConfigs {
|
|
30
37
|
[pathHyphenVerb: string]: ILambdaConfig & {
|
|
31
38
|
default?: ILambdaConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.164",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"aws-cdk-lib": "2.x",
|
|
17
|
-
"aws-sdk": "2.
|
|
17
|
+
"aws-sdk": "2.1080.0",
|
|
18
18
|
"axios": "0.26.0",
|
|
19
19
|
"constructs": "10.x",
|
|
20
20
|
"jsonwebtoken": "8.5.1",
|
|
@@ -29,15 +29,15 @@
|
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/jsonwebtoken": "8.5.8",
|
|
32
|
-
"@types/node": "17.0.
|
|
32
|
+
"@types/node": "17.0.21",
|
|
33
33
|
"@types/react": "17.0.39",
|
|
34
34
|
"@types/react-dom": "17.0.11",
|
|
35
|
-
"@types/styled-components": "5.1.
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "5.12.
|
|
37
|
-
"@typescript-eslint/parser": "5.12.
|
|
35
|
+
"@types/styled-components": "5.1.23",
|
|
36
|
+
"@typescript-eslint/eslint-plugin": "5.12.1",
|
|
37
|
+
"@typescript-eslint/parser": "5.12.1",
|
|
38
38
|
"eslint": "8.9.0",
|
|
39
39
|
"eslint-config-airbnb-typescript": "16.1.0",
|
|
40
|
-
"eslint-config-prettier": "8.
|
|
40
|
+
"eslint-config-prettier": "8.4.0",
|
|
41
41
|
"eslint-config-react-app": "7.0.0",
|
|
42
42
|
"eslint-plugin-import": "2.25.4",
|
|
43
43
|
"eslint-plugin-jsx-a11y": "6.5.1",
|