aws-lambda-api-tools 0.1.4 → 0.1.6
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/README.md +12 -0
- package/bin/bootstrap-iam.js +3 -0
- package/bin/bootstrap-iam.ts +56 -0
- package/dist/lib/cf-yaml-helper.d.ts +26 -0
- package/dist/lib/cf-yaml-helper.d.ts.map +1 -0
- package/dist/lib/cf-yaml-helper.js +148 -0
- package/dist/lib/cf-yaml-helper.js.map +1 -0
- package/dist/lib/custom-error.d.ts.map +1 -1
- package/dist/lib/custom-error.js.map +1 -1
- package/dist/lib/lambda-route-proxy-entry-handler.d.ts.map +1 -1
- package/dist/lib/lambda-route-proxy-entry-handler.js +8 -3
- package/dist/lib/lambda-route-proxy-entry-handler.js.map +1 -1
- package/dist/lib/lambda-route-proxy-path-not-found.d.ts.map +1 -1
- package/dist/lib/lambda-route-proxy-path-not-found.js +1 -6
- package/dist/lib/lambda-route-proxy-path-not-found.js.map +1 -1
- package/dist/lib/swagger-route-specification-generator.d.ts +13 -73
- package/dist/lib/swagger-route-specification-generator.d.ts.map +1 -1
- package/dist/lib/swagger-route-specification-generator.js +112 -0
- package/dist/lib/swagger-route-specification-generator.js.map +1 -1
- package/package.json +24 -8
package/README.md
CHANGED
|
@@ -231,3 +231,15 @@ Contributions are welcome! Please feel free to submit a Pull Request.
|
|
|
231
231
|
## License
|
|
232
232
|
|
|
233
233
|
MIT
|
|
234
|
+
|
|
235
|
+
## GitHub Actions IAM Setup
|
|
236
|
+
|
|
237
|
+
This package includes a utility to set up IAM OIDC authentication for GitHub Actions so that you can deploy to AWS from your GitHub Actions:
|
|
238
|
+
|
|
239
|
+
```bash
|
|
240
|
+
npx gh-oidc-iam --repo=owner/repo-name [--policy=PolicyName]
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
Options:
|
|
244
|
+
- `--repo`: (Required) Your GitHub repository in the format `owner/repo-name`
|
|
245
|
+
- `--policy`: (Optional) AWS managed policy name to attach to the role. Defaults to 'AdministratorAccess'
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env ts-node
|
|
2
|
+
import * as cdk from 'aws-cdk-lib';
|
|
3
|
+
import * as iam from 'aws-cdk-lib/aws-iam';
|
|
4
|
+
|
|
5
|
+
// Parse command line arguments
|
|
6
|
+
const args = process.argv.slice(2);
|
|
7
|
+
const repoArg = args.find(arg => arg.startsWith('--repo='));
|
|
8
|
+
const policyArg = args.find(arg => arg.startsWith('--policy='));
|
|
9
|
+
|
|
10
|
+
if (!repoArg) {
|
|
11
|
+
console.error('Error: --repo argument is required');
|
|
12
|
+
console.error('Usage: gh-oidc-iam --repo=owner/repo-name [--policy=PolicyName]');
|
|
13
|
+
console.error('Example: gh-oidc-iam --repo=myorg/my-repo --policy=AdministratorAccess');
|
|
14
|
+
process.exit(1);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const repoName = repoArg.split('=')[1];
|
|
18
|
+
const policyName = policyArg ? policyArg.split('=')[1] : 'AdministratorAccess';
|
|
19
|
+
|
|
20
|
+
const app = new cdk.App();
|
|
21
|
+
|
|
22
|
+
class GithubActionsIamStack extends cdk.Stack {
|
|
23
|
+
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
|
|
24
|
+
super(scope, id, props);
|
|
25
|
+
|
|
26
|
+
const githubOidcProvider = new iam.OpenIdConnectProvider(this, 'GithubOidcProvider', {
|
|
27
|
+
url: 'https://token.actions.githubusercontent.com',
|
|
28
|
+
clientIds: ['sts.amazonaws.com'],
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const deploymentRole = new iam.Role(this, 'GithubActionsRole', {
|
|
32
|
+
assumedBy: new iam.WebIdentityPrincipal(
|
|
33
|
+
githubOidcProvider.openIdConnectProviderArn,
|
|
34
|
+
{
|
|
35
|
+
StringEquals: {
|
|
36
|
+
'token.actions.githubusercontent.com:aud': 'sts.amazonaws.com',
|
|
37
|
+
},
|
|
38
|
+
StringLike: {
|
|
39
|
+
'token.actions.githubusercontent.com:sub': `repo:${repoName}:*`,
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
),
|
|
43
|
+
managedPolicies: [
|
|
44
|
+
iam.ManagedPolicy.fromAwsManagedPolicyName(policyName),
|
|
45
|
+
],
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
new cdk.CfnOutput(this, 'RoleArn', {
|
|
49
|
+
value: deploymentRole.roleArn,
|
|
50
|
+
description: 'ARN of role to use in GitHub Actions',
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
new GithubActionsIamStack(app, 'GithubActionsIam');
|
|
56
|
+
app.synth();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parser and schema for CloudFormation YAML template tags.
|
|
3
|
+
*
|
|
4
|
+
* There are some existing modules out there:
|
|
5
|
+
* https://github.com/yyolk/cloudformation-js-yaml-schema
|
|
6
|
+
* https://github.com/KoharaKazuya/js-yaml-schema-cfn
|
|
7
|
+
* But both are poorly documented, with insufficient tests, and don't fully work.
|
|
8
|
+
*
|
|
9
|
+
* This implementation is based on the official AWS python client:
|
|
10
|
+
* https://github.com/aws/aws-cli/blob/develop/awscli/customizations/cloudformation/yamlhelper.py
|
|
11
|
+
*/
|
|
12
|
+
import jsYaml from 'js-yaml';
|
|
13
|
+
/**
|
|
14
|
+
* The actual js-yaml schema, extending the DEFAULT_SAFE_SCHEMA.
|
|
15
|
+
*/
|
|
16
|
+
export declare const schema: jsYaml.Schema;
|
|
17
|
+
/**
|
|
18
|
+
* Convenience function to parse the given yaml input.
|
|
19
|
+
*/
|
|
20
|
+
export declare const parse: (input: any) => unknown;
|
|
21
|
+
/**
|
|
22
|
+
* Convenience function to serialize the given object to Yaml.
|
|
23
|
+
*/
|
|
24
|
+
export declare const dump: (input: any) => string;
|
|
25
|
+
export declare const updateCFYamlPropertyInplace: (pathToYaml: string, propertyPath: string, propertyValue: string) => void;
|
|
26
|
+
//# sourceMappingURL=cf-yaml-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cf-yaml-helper.d.ts","sourceRoot":"","sources":["../../src/lib/cf-yaml-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,MAAM,MAAM,SAAS,CAAC;AAsF5B;;GAEG;AACH,eAAO,MAAM,MAAM,eAGjB,CAAC;AAGH;;GAEG;AACH,eAAO,MAAM,KAAK,UAAW,GAAG,YAA2C,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,IAAI,UAAW,GAAG,WAA2C,CAAC;AAG5E,eAAO,MAAM,2BAA2B,eAAgB,MAAM,gBAAgB,MAAM,iBAAiB,MAAM,SAU1G,CAAC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Parser and schema for CloudFormation YAML template tags.
|
|
4
|
+
*
|
|
5
|
+
* There are some existing modules out there:
|
|
6
|
+
* https://github.com/yyolk/cloudformation-js-yaml-schema
|
|
7
|
+
* https://github.com/KoharaKazuya/js-yaml-schema-cfn
|
|
8
|
+
* But both are poorly documented, with insufficient tests, and don't fully work.
|
|
9
|
+
*
|
|
10
|
+
* This implementation is based on the official AWS python client:
|
|
11
|
+
* https://github.com/aws/aws-cli/blob/develop/awscli/customizations/cloudformation/yamlhelper.py
|
|
12
|
+
*/
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.updateCFYamlPropertyInplace = exports.dump = exports.parse = exports.schema = void 0;
|
|
41
|
+
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
42
|
+
const fs = __importStar(require("fs"));
|
|
43
|
+
const _ = __importStar(require("lodash"));
|
|
44
|
+
/**
|
|
45
|
+
* Split a string on the given separator just once, returning an array of two parts, or null.
|
|
46
|
+
*/
|
|
47
|
+
const splitOne = (str, sep) => {
|
|
48
|
+
let index = str.indexOf(sep);
|
|
49
|
+
return index < 0 ? null : [str.slice(0, index), str.slice(index + sep.length)];
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Returns true if obj is a representation of a CloudFormation intrinsic, i.e. an object with a
|
|
53
|
+
* single property at key keyName.
|
|
54
|
+
*/
|
|
55
|
+
const checkType = (obj, keyName) => {
|
|
56
|
+
return obj && typeof obj === 'object' && Object.keys(obj).length === 1 &&
|
|
57
|
+
obj.hasOwnProperty(keyName);
|
|
58
|
+
};
|
|
59
|
+
const overrides = {
|
|
60
|
+
// ShortHand notation for !GetAtt accepts Resource.Attribute format while the standard notation
|
|
61
|
+
// is to use an array [Resource, Attribute]. Convert shorthand to standard format.
|
|
62
|
+
GetAtt: {
|
|
63
|
+
parse: (data) => typeof data === 'string' ? splitOne(data, '.') : data,
|
|
64
|
+
dump: (data) => data.join('.')
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const applyOverrides = (data, tag, method) => {
|
|
68
|
+
return overrides[tag] ? overrides[tag][method](data) : data;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Generic tag-creating helper. For the given name of the form 'Fn::Something' (or just
|
|
72
|
+
* 'Something'), creates a js-yaml Type object that can parse and dump this type. It creates it
|
|
73
|
+
* for all types of values, for simplicity and because that's how the official Python version
|
|
74
|
+
* works.
|
|
75
|
+
*/
|
|
76
|
+
const makeTagTypes = (name) => {
|
|
77
|
+
const parts = splitOne(name, '::');
|
|
78
|
+
const tag = parts ? parts[1] : name;
|
|
79
|
+
// Translate in the same way for all types, to match Python's generic translation.
|
|
80
|
+
return ['scalar', 'sequence', 'mapping'].map((kind) => new js_yaml_1.default.Type('!' + tag, {
|
|
81
|
+
kind: kind,
|
|
82
|
+
construct: (data) => ({ [name]: applyOverrides(data, tag, 'parse') }),
|
|
83
|
+
predicate: (obj) => checkType(obj, name),
|
|
84
|
+
represent: (obj) => applyOverrides(obj[name], tag, 'dump'),
|
|
85
|
+
}));
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* This list is from
|
|
89
|
+
* http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
|
|
90
|
+
* Note that the Python version handles ANY tag that starts with ! in the same way (translating it
|
|
91
|
+
* to Fn:: prefix, but js-yaml requires listing tags explicitly.
|
|
92
|
+
*/
|
|
93
|
+
const supportedFunctions = [
|
|
94
|
+
'Fn::Base64',
|
|
95
|
+
'Fn::Cidr',
|
|
96
|
+
'Fn::FindInMap',
|
|
97
|
+
'Fn::GetAtt',
|
|
98
|
+
'Fn::GetAZs',
|
|
99
|
+
'Fn::ImportValue',
|
|
100
|
+
'Fn::Join',
|
|
101
|
+
'Fn::Select',
|
|
102
|
+
'Fn::Split',
|
|
103
|
+
'Fn::Sub',
|
|
104
|
+
'Fn::Transform',
|
|
105
|
+
'Ref',
|
|
106
|
+
'Condition',
|
|
107
|
+
'Fn::And',
|
|
108
|
+
'Fn::Equals',
|
|
109
|
+
'Fn::If',
|
|
110
|
+
'Fn::Not',
|
|
111
|
+
'Fn::Or',
|
|
112
|
+
];
|
|
113
|
+
const allTagTypes = [];
|
|
114
|
+
for (let name of supportedFunctions) {
|
|
115
|
+
allTagTypes.push(...makeTagTypes(name));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The actual js-yaml schema, extending the DEFAULT_SAFE_SCHEMA.
|
|
119
|
+
*/
|
|
120
|
+
exports.schema = js_yaml_1.default.CORE_SCHEMA.extend({
|
|
121
|
+
implicit: [],
|
|
122
|
+
explicit: allTagTypes,
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* Convenience function to parse the given yaml input.
|
|
126
|
+
*/
|
|
127
|
+
const parse = (input) => js_yaml_1.default.load(input, { schema: exports.schema });
|
|
128
|
+
exports.parse = parse;
|
|
129
|
+
;
|
|
130
|
+
/**
|
|
131
|
+
* Convenience function to serialize the given object to Yaml.
|
|
132
|
+
*/
|
|
133
|
+
const dump = (input) => js_yaml_1.default.dump(input, { schema: exports.schema });
|
|
134
|
+
exports.dump = dump;
|
|
135
|
+
const updateCFYamlPropertyInplace = (pathToYaml, propertyPath, propertyValue) => {
|
|
136
|
+
try {
|
|
137
|
+
const doc = (0, exports.parse)(fs.readFileSync(pathToYaml, 'utf8'));
|
|
138
|
+
// console.log(`${doc}`);
|
|
139
|
+
_.set(doc, propertyPath, propertyValue);
|
|
140
|
+
fs.writeFileSync(pathToYaml, (0, exports.dump)(doc));
|
|
141
|
+
}
|
|
142
|
+
catch (e) {
|
|
143
|
+
console.log('--- ERROR: Could not perform yaml update. ---');
|
|
144
|
+
console.log(JSON.stringify(e));
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
exports.updateCFYamlPropertyInplace = updateCFYamlPropertyInplace;
|
|
148
|
+
//# sourceMappingURL=cf-yaml-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cf-yaml-helper.js","sourceRoot":"","sources":["../../src/lib/cf-yaml-helper.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,sDAA6B;AAC7B,uCAAyB;AACzB,0CAA4B;AAE3B;;GAEG;AACH,MAAM,QAAQ,GAAG,CAAC,GAAW,EAAE,GAAW,EAAE,EAAE;IAC5C,IAAI,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC;AACjF,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,SAAS,GAAG,CAAC,GAAQ,EAAE,OAAe,EAAE,EAAE;IAC9C,OAAO,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC;QACpE,GAAG,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAC;AAGF,MAAM,SAAS,GAAQ;IACrB,+FAA+F;IAC/F,kFAAkF;IAClF,MAAM,EAAE;QACN,KAAK,EAAE,CAAC,IAAS,EAAE,EAAE,CAAC,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,EAAE,GAA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,CAAC,CAAC;KACzC;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,CAAC;QAC7D,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;KAChC;AACH,CAAC,CAAC;AAVW,QAAA,2BAA2B,+BAUtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-error.d.ts","sourceRoot":"","sources":["../../src/lib/custom-error.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"custom-error.d.ts","sourceRoot":"","sources":["../../src/lib/custom-error.ts"],"names":[],"mappings":"AACE,qBAAa,WAAY,SAAQ,KAAK;IACpC,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;gBAEL,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAM/C,IAAI,cAAc,WAEjB;IAED,IAAa,OAAO,WAEnB;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom-error.js","sourceRoot":"","sources":["../../src/lib/custom-error.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"custom-error.js","sourceRoot":"","sources":["../../src/lib/custom-error.ts"],"names":[],"mappings":";;;AACE,MAAa,WAAY,SAAQ,KAAK;IAIpC,YAAY,OAAe,EAAE,UAAkB;QAC7C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,eAAe,GAAG,UAAU,IAAI,GAAG,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;IAED,IAAI,cAAc;QAChB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC9B,CAAC;IAED,IAAa,OAAO;QAClB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;CACF;AAjBD,kCAiBC;AAAA,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda-route-proxy-entry-handler.d.ts","sourceRoot":"","sources":["../../src/lib/lambda-route-proxy-entry-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAoB,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAYpG,eAAO,MAAM,cAAc,WAAY,WAAW,UAAU,MAAM,QAAQ,MAAM;;MAAkD,WAUjI,CAAC;AAEF,eAAO,MAAM,oBAAoB,mBAA0B,WAAW,YAAY,cAAc,KAAG,QAAQ,GAAG,CAM7G,CAAC;AAEF,eAAO,MAAM,4BAA4B,WAAY,WAAW;;
|
|
1
|
+
{"version":3,"file":"lambda-route-proxy-entry-handler.d.ts","sourceRoot":"","sources":["../../src/lib/lambda-route-proxy-entry-handler.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAEpD,OAAO,EAAE,WAAW,EAAoB,cAAc,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAYpG,eAAO,MAAM,cAAc,WAAY,WAAW,UAAU,MAAM,QAAQ,MAAM;;MAAkD,WAUjI,CAAC;AAEF,eAAO,MAAM,oBAAoB,mBAA0B,WAAW,YAAY,cAAc,KAAG,QAAQ,GAAG,CAM7G,CAAC;AAEF,eAAO,MAAM,4BAA4B,WAAY,WAAW;;oDAgD7D,CAAC"}
|
|
@@ -29,18 +29,23 @@ const getRouteModuleResult = async ({ routeChain }, incoming) => {
|
|
|
29
29
|
exports.getRouteModuleResult = getRouteModuleResult;
|
|
30
30
|
const lambdaRouteProxyEntryHandler = (config, availableRouteModules) => async (event) => {
|
|
31
31
|
console.log(`Event Data: ${JSON.stringify(event)}`);
|
|
32
|
-
const { routeKey, queryStringParameters, pathParameters, body, } = event;
|
|
32
|
+
const { routeKey, queryStringParameters, pathParameters, body, isBase64Encoded, } = event;
|
|
33
33
|
let retVal = {};
|
|
34
34
|
try {
|
|
35
|
-
const [method, path] = routeKey.split(' ');
|
|
35
|
+
const [method = '', path = ''] = routeKey.split(' ');
|
|
36
36
|
if (shouldAuthorizeRoute(config, getRouteConfigEntry(config, method, path))) {
|
|
37
37
|
await (0, authorization_helper_1.authorizeRoute)(event);
|
|
38
38
|
}
|
|
39
39
|
const routeModule = (0, exports.getRouteModule)(config, method, path, availableRouteModules);
|
|
40
|
+
console.log(`isBase64Encoded: ${isBase64Encoded}`);
|
|
41
|
+
console.log(`body: ${body}`);
|
|
42
|
+
const decodedBody = isBase64Encoded ? Buffer.from(body, 'base64').toString('utf-8') : undefined;
|
|
43
|
+
console.log(`decodedBody:
|
|
44
|
+
${decodedBody}`);
|
|
40
45
|
retVal = await (0, exports.getRouteModuleResult)(routeModule, {
|
|
41
46
|
query: queryStringParameters,
|
|
42
47
|
params: pathParameters,
|
|
43
|
-
body: body ? JSON.parse(body) : undefined,
|
|
48
|
+
body: body ? decodedBody || JSON.parse(body) : undefined,
|
|
44
49
|
rawEvent: event,
|
|
45
50
|
});
|
|
46
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda-route-proxy-entry-handler.js","sourceRoot":"","sources":["../../src/lib/lambda-route-proxy-entry-handler.ts"],"names":[],"mappings":";;;AAEA,iDAA6C;AAE7C,iEAAwD;AAExD,MAAM,mBAAmB,GAAG,CAAC,MAAmB,EAAE,MAAc,EAAE,IAAY,EAAE,EAAE,CAChF,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,MAAM,CAAC,WAAW,EAAE,CAAqB,CAAC;AAE9I,MAAM,oBAAoB,GAAG,CAAC,YAAyB,EAAE,gBAAkC,EAAE,EAAE,CAC7F,CAAC,YAAY,CAAC,kBAAkB,IAAI,gBAAgB,CAAC,cAAc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ACZ,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"lambda-route-proxy-path-not-found.d.ts","sourceRoot":"","sources":["../../src/lib/lambda-route-proxy-path-not-found.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAiBhC,eAAO,MAAM,4BAA4B,EAAE,WAG1C,CAAC"}
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.lambdaRouteProxyPathNotFound = void 0;
|
|
4
4
|
const handler = async (input) => {
|
|
5
|
-
console.log('--- NOT FOUND HANDLER ---');
|
|
6
|
-
console.log(input.rawEvent.requestContext.http.method);
|
|
7
5
|
if (input.rawEvent.requestContext.http.method === 'OPTIONS') {
|
|
8
6
|
return {
|
|
9
7
|
statusCode: 200,
|
|
@@ -12,10 +10,7 @@ const handler = async (input) => {
|
|
|
12
10
|
'Access-Control-Allow-Methods': '*',
|
|
13
11
|
'Access-Control-Allow-Headers': '*',
|
|
14
12
|
'Access-Control-Max-Age': 300,
|
|
15
|
-
|
|
16
|
-
'Access-Control-Allow-Credentials': true,
|
|
17
|
-
'Content-Type': 'application/json',
|
|
18
|
-
},
|
|
13
|
+
}
|
|
19
14
|
};
|
|
20
15
|
}
|
|
21
16
|
return { statusCode: 404, body: JSON.stringify('Not found') };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lambda-route-proxy-path-not-found.js","sourceRoot":"","sources":["../../src/lib/lambda-route-proxy-path-not-found.ts"],"names":[],"mappings":";;;AAKA,MAAM,OAAO,GAAG,KAAK,EAAE,KAAqB,EAAgB,EAAE;IAC5D,
|
|
1
|
+
{"version":3,"file":"lambda-route-proxy-path-not-found.js","sourceRoot":"","sources":["../../src/lib/lambda-route-proxy-path-not-found.ts"],"names":[],"mappings":";;;AAKA,MAAM,OAAO,GAAG,KAAK,EAAE,KAAqB,EAAgB,EAAE;IAC5D,IAAI,KAAK,CAAC,QAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,KAAK,SAAS,EAAE;QAC5D,OAAO;YACL,UAAU,EAAE,GAAG;YACf,OAAO,EAAE;gBACP,6BAA6B,EAAE,GAAG;gBAClC,8BAA8B,EAAE,GAAG;gBACnC,8BAA8B,EAAE,GAAG;gBACnC,wBAAwB,EAAE,GAAG;aAC9B;SACF,CAAC;KACH;IACD,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,EAAE,CAAC;AAChE,CAAC,CAAC;AAEW,QAAA,4BAA4B,GAAgB;IACvD,UAAU,EAAE,CAAC,OAAO,CAAC;IACrB,WAAW,EAAE,EAAE;CAChB,CAAC"}
|
|
@@ -1,78 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ComponentsSchema } from 'joi-to-swagger';
|
|
2
|
+
import { ConfigRouteEntry, RouteSchema } from './types-and-interfaces';
|
|
3
3
|
import * as swaggerTypes from './swagger-specification-types';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
handlerPath: string;
|
|
12
|
-
authorizeRoute?: boolean;
|
|
13
|
-
};
|
|
14
|
-
export type RouteConfig = {
|
|
15
|
-
authorizeAllRoutes?: boolean;
|
|
16
|
-
routes: Array<ConfigRouteEntry>;
|
|
17
|
-
};
|
|
18
|
-
export type RouteArguments = {
|
|
19
|
-
params?: any;
|
|
20
|
-
body?: any;
|
|
21
|
-
query?: any;
|
|
22
|
-
form?: any;
|
|
23
|
-
rawEvent?: APIGatewayProxyEventV2;
|
|
24
|
-
routeData?: any;
|
|
25
|
-
};
|
|
26
|
-
export interface RouteSchema {
|
|
27
|
-
params?: {
|
|
28
|
-
[key: string]: Schema<any>;
|
|
29
|
-
};
|
|
30
|
-
query?: {
|
|
31
|
-
[key: string]: Schema<any>;
|
|
32
|
-
};
|
|
33
|
-
form?: {
|
|
34
|
-
[key: string]: Schema<any>;
|
|
4
|
+
type RouteSpecType = {
|
|
5
|
+
path: {
|
|
6
|
+
description: string;
|
|
7
|
+
operationId?: string;
|
|
8
|
+
parameters?: Array<swaggerTypes.ParameterObject>;
|
|
9
|
+
requestBody?: swaggerTypes.RequestBody;
|
|
10
|
+
responses?: Record<string, swaggerTypes.ResponseObject>;
|
|
35
11
|
};
|
|
36
|
-
|
|
37
|
-
|
|
12
|
+
components: {
|
|
13
|
+
schemas: Record<string, ComponentsSchema>;
|
|
38
14
|
};
|
|
39
|
-
responseBody?: Schema<any> | {
|
|
40
|
-
[key: string]: Schema<any>;
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
export interface BaseResponseObject extends swaggerTypes.ResponseObject {
|
|
44
|
-
}
|
|
45
|
-
export interface ResponseError extends swaggerTypes.ResponseObject {
|
|
46
|
-
error: {
|
|
47
|
-
statusCode: string;
|
|
48
|
-
message: string;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
export interface ResponseData extends swaggerTypes.ResponseObject {
|
|
52
|
-
data: any;
|
|
53
|
-
}
|
|
54
|
-
export type ResponseObject<T> = ResponseData | ResponseError;
|
|
55
|
-
export type BaseRouteResponse<T> = {
|
|
56
|
-
[key in '201' | '202' | '203' | '204' | '205' | '206' | '400' | '401' | '402' | '403' | '404' | '405' | '406' | '407' | '408' | '409' | '410' | '411' | '412' | '413' | '414' | '415' | '416' | '417' | '418' | '419']: ResponseObject<T>;
|
|
57
15
|
};
|
|
58
|
-
export
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
export type MiddlewareSchemaInputFunction = (input: RouteSchema) => RouteArguments;
|
|
62
|
-
export type MiddlewareArgumentsInputFunction = (input: RouteArguments) => any;
|
|
63
|
-
export type MiddlewareChain = Array<MiddlewareArgumentsInputFunction>;
|
|
64
|
-
export type RouteModule = {
|
|
65
|
-
routeChain: MiddlewareChain;
|
|
66
|
-
routeSchema: RouteSchema;
|
|
67
|
-
};
|
|
68
|
-
export interface Permission {
|
|
69
|
-
id: string;
|
|
70
|
-
systemPermission: string;
|
|
71
|
-
enabled: boolean;
|
|
72
|
-
humanReadableName: string;
|
|
73
|
-
entity: {
|
|
74
|
-
level: string;
|
|
75
|
-
humanReadableName: string;
|
|
76
|
-
};
|
|
77
|
-
}
|
|
16
|
+
export declare const generateRouteSwaggerSpec: (schema: RouteSchema, routeEntry: ConfigRouteEntry) => RouteSpecType;
|
|
17
|
+
export {};
|
|
78
18
|
//# sourceMappingURL=swagger-route-specification-generator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swagger-route-specification-generator.d.ts","sourceRoot":"","sources":["../../src/lib/swagger-route-specification-generator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"swagger-route-specification-generator.d.ts","sourceRoot":"","sources":["../../src/lib/swagger-route-specification-generator.ts"],"names":[],"mappings":"AACA,OAAqB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,KAAK,YAAY,MAAM,+BAA+B,CAAC;AAE9D,KAAK,aAAa,GAAG;IACnB,IAAI,EAAE;QACJ,WAAW,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;QACjD,WAAW,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC;QACvC,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,cAAc,CAAC,CAAC;KACzD,CAAC;IACF,UAAU,EAAE;QACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;KAC3C,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,wBAAwB,WAAY,WAAW,cAAc,gBAAgB,KAAG,aAsF5F,CAAC"}
|
|
@@ -1,3 +1,115 @@
|
|
|
1
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
2
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.generateRouteSwaggerSpec = void 0;
|
|
30
|
+
const joi = __importStar(require("joi"));
|
|
31
|
+
const joi_to_swagger_1 = __importDefault(require("joi-to-swagger"));
|
|
32
|
+
const generateRouteSwaggerSpec = (schema, routeEntry) => {
|
|
33
|
+
const { requestBody: requestBodyJoiSchema, query: queryJoiSchema, params: pathParamsJoiSchema, responseBody: responseBodyJoiSchema } = { requestBody: {}, query: {}, params: {}, responseBody: {}, ...schema };
|
|
34
|
+
const { description, swaggerMethodName } = routeEntry;
|
|
35
|
+
// console.log('schema:')
|
|
36
|
+
// console.log(schema);
|
|
37
|
+
let parameters = [];
|
|
38
|
+
let requestBody = undefined;
|
|
39
|
+
let responseBody = { description: 'Default response' };
|
|
40
|
+
// let requestBodyRefKey: string | undefined;
|
|
41
|
+
// let responseBodyRefKey: string | undefined;
|
|
42
|
+
let componentSchemas = {};
|
|
43
|
+
if (pathParamsJoiSchema && Object.keys(pathParamsJoiSchema).length > 0) {
|
|
44
|
+
const pathParamsKeys = Object.keys(pathParamsJoiSchema);
|
|
45
|
+
const pathParamsSwaggerParameters = pathParamsKeys.map((key) => ({
|
|
46
|
+
name: key,
|
|
47
|
+
in: 'path',
|
|
48
|
+
required: true,
|
|
49
|
+
schema: (0, joi_to_swagger_1.default)(pathParamsJoiSchema[key]).swagger,
|
|
50
|
+
}));
|
|
51
|
+
parameters = Array().concat(parameters, pathParamsSwaggerParameters);
|
|
52
|
+
}
|
|
53
|
+
if (queryJoiSchema && Object.keys(queryJoiSchema).length > 0) {
|
|
54
|
+
const queryKeys = Object.keys(queryJoiSchema);
|
|
55
|
+
const queryParamsSwaggerParameters = queryKeys.map((key) => {
|
|
56
|
+
const { presence } = queryJoiSchema[key]._flags;
|
|
57
|
+
return {
|
|
58
|
+
name: key,
|
|
59
|
+
in: 'query',
|
|
60
|
+
required: presence === 'required',
|
|
61
|
+
schema: (0, joi_to_swagger_1.default)(queryJoiSchema[key]).swagger,
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
parameters = Array().concat(parameters, queryParamsSwaggerParameters);
|
|
65
|
+
}
|
|
66
|
+
if (requestBodyJoiSchema && Object.keys(requestBodyJoiSchema).length > 0) {
|
|
67
|
+
const { swagger, components: requestComponent } = (0, joi_to_swagger_1.default)(joi.isSchema(requestBodyJoiSchema) ? requestBodyJoiSchema : joi.object(requestBodyJoiSchema));
|
|
68
|
+
requestBody = {
|
|
69
|
+
description: 'Default response body',
|
|
70
|
+
content: {
|
|
71
|
+
'application/json': {
|
|
72
|
+
schema: swagger,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
// console.log(swagger);
|
|
77
|
+
if (swagger.$ref || (swagger.items && swagger.items.$ref)) {
|
|
78
|
+
// requestBodyRefKey = swagger.$ref.split('/').reverse()[0];
|
|
79
|
+
componentSchemas = { ...componentSchemas, ...requestComponent.schemas };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (responseBodyJoiSchema && Object.keys(responseBodyJoiSchema).length > 0) {
|
|
83
|
+
const { swagger, components: responseComponent } = (0, joi_to_swagger_1.default)(joi.isSchema(responseBodyJoiSchema) ? responseBodyJoiSchema : joi.object(responseBodyJoiSchema));
|
|
84
|
+
// console.log(JSON.stringify(j2s, null, 2));
|
|
85
|
+
// console.log(swagger);
|
|
86
|
+
responseBody = {
|
|
87
|
+
description: 'Default response body',
|
|
88
|
+
content: {
|
|
89
|
+
'application/json': {
|
|
90
|
+
schema: swagger,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
if (swagger.$ref || (swagger.items && swagger.items.$ref)) {
|
|
95
|
+
// responseBodyRefKey = swagger.$ref.split('/').reverse()[0];
|
|
96
|
+
componentSchemas = { ...componentSchemas, ...responseComponent.schemas };
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
path: {
|
|
101
|
+
description,
|
|
102
|
+
operationId: swaggerMethodName || undefined,
|
|
103
|
+
parameters,
|
|
104
|
+
requestBody,
|
|
105
|
+
responses: {
|
|
106
|
+
'200': responseBody,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
components: {
|
|
110
|
+
schemas: componentSchemas,
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
exports.generateRouteSwaggerSpec = generateRouteSwaggerSpec;
|
|
3
115
|
//# sourceMappingURL=swagger-route-specification-generator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"swagger-route-specification-generator.js","sourceRoot":"","sources":["../../src/lib/swagger-route-specification-generator.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"swagger-route-specification-generator.js","sourceRoot":"","sources":["../../src/lib/swagger-route-specification-generator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA2B;AAC3B,oEAAgE;AAiBzD,MAAM,wBAAwB,GAAG,CAAC,MAAmB,EAAE,UAA4B,EAAiB,EAAE;IAC3G,MAAM,EAAE,WAAW,EAAE,oBAAoB,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,mBAAmB,EAAE,YAAY,EAAE,qBAAqB,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE,GAAG,MAAM,EAAE,CAAC;IAC/M,MAAM,EAAE,WAAW,EAAE,iBAAiB,EAAE,GAAG,UAAU,CAAC;IACtD,yBAAyB;IACzB,uBAAuB;IACvB,IAAI,UAAU,GAAwC,EAAE,CAAC;IACzD,IAAI,WAAW,GAAyC,SAAS,CAAC;IAClE,IAAI,YAAY,GAAgC,EAAE,WAAW,EAAE,kBAAkB,EAAE,CAAC;IACpF,6CAA6C;IAC7C,8CAA8C;IAC9C,IAAI,gBAAgB,GAAqC,EAAE,CAAC;IAC5D,IAAI,mBAAmB,IAAI,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;QACtE,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QACxD,MAAM,2BAA2B,GAAG,cAAc,CAAC,GAAG,CAA+B,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;YAC7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AAC,CAAC;AAtFW,QAAA,wBAAwB,4BAsFnC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aws-lambda-api-tools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
7
|
-
"generate-oas": "./bin/generate-swagger.js"
|
|
7
|
+
"generate-oas": "./bin/generate-swagger.js",
|
|
8
|
+
"gh-oidc-iam": "./bin/bootstrap-iam.js"
|
|
8
9
|
},
|
|
9
10
|
"types": "dist/index.d.ts",
|
|
10
11
|
"scripts": {
|
|
11
12
|
"build": "tsc",
|
|
12
|
-
"bump-version": "npm run build && npm version patch -m 'Updated version to %s'",
|
|
13
|
+
"bump-version": "npm run build && npm version patch -m 'Updated version to %s [skip ci]'",
|
|
13
14
|
"test": "jest",
|
|
14
|
-
"generate-swagger": "node -r ts-node/register bin/generate-swagger.js"
|
|
15
|
+
"generate-swagger": "node -r ts-node/register bin/generate-swagger.js",
|
|
16
|
+
"---Github Actions Setup---": "",
|
|
17
|
+
"gh-oidc-iam": "cdk --app 'ts-node scripts/bootstrap-iam.ts' deploy GithubActionsIam --require-approval never"
|
|
15
18
|
},
|
|
16
19
|
"repository": {
|
|
17
20
|
"type": "git",
|
|
@@ -33,14 +36,27 @@
|
|
|
33
36
|
"nodemon": "^2.0.22",
|
|
34
37
|
"prettier": "^2.8.8",
|
|
35
38
|
"ts-jest": "^26.5.6",
|
|
36
|
-
"ts-node": "^9.1.1",
|
|
37
39
|
"typescript": "^4.9.5"
|
|
38
40
|
},
|
|
39
41
|
"dependencies": {
|
|
42
|
+
"@types/atob": "^2.1.2",
|
|
43
|
+
"@types/aws-lambda": "^8.10.81",
|
|
44
|
+
"@types/formidable": "^1.2.3",
|
|
45
|
+
"@types/jest": "^26.0.23",
|
|
46
|
+
"@types/js-yaml": "^4.0.5",
|
|
47
|
+
"@types/lodash": "^4.14.182",
|
|
48
|
+
"@types/minimist": "^1.2.2",
|
|
49
|
+
"@types/node-fetch": "^2.5.12",
|
|
40
50
|
"atob": "^2.1.2",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
51
|
+
"aws-cdk-lib": "^2.178.2",
|
|
52
|
+
"axios": "^1.6.3",
|
|
53
|
+
"joi": "^17.12.3",
|
|
54
|
+
"joi-to-swagger": "6.2.0",
|
|
55
|
+
"joi-to-typescript": "^4.11.0",
|
|
56
|
+
"js-yaml": "^4.1.0",
|
|
57
|
+
"lodash": "^4.17.21",
|
|
58
|
+
"minimist": "^1.2.6",
|
|
59
|
+
"ts-node": "^9.1.1"
|
|
44
60
|
},
|
|
45
61
|
"files": [
|
|
46
62
|
"bin",
|