aws-lambda-api-tools 0.1.14 → 0.1.16

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.
Files changed (59) hide show
  1. package/README.md +9 -14
  2. package/bin/bootstrap-iam.js +1 -1
  3. package/dist/bin/bootstrap-iam.d.ts +2 -0
  4. package/dist/bin/bootstrap-iam.d.ts.map +1 -0
  5. package/dist/bin/bootstrap-iam.js +81 -0
  6. package/dist/bin/bootstrap-iam.js.map +1 -0
  7. package/dist/bin/cli.d.ts +2 -0
  8. package/dist/bin/cli.d.ts.map +1 -0
  9. package/dist/bin/cli.js +32 -0
  10. package/dist/bin/cli.js.map +1 -0
  11. package/dist/index.d.ts +7 -0
  12. package/dist/index.d.ts.map +1 -0
  13. package/dist/index.js +14 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/lib/authorization-helper.d.ts +3 -0
  16. package/dist/lib/authorization-helper.d.ts.map +1 -0
  17. package/dist/lib/authorization-helper.js +14 -0
  18. package/dist/lib/authorization-helper.js.map +1 -0
  19. package/dist/lib/cf-yaml-helper.d.ts +26 -0
  20. package/dist/lib/cf-yaml-helper.d.ts.map +1 -0
  21. package/dist/lib/cf-yaml-helper.js +148 -0
  22. package/dist/lib/cf-yaml-helper.js.map +1 -0
  23. package/dist/lib/custom-error.d.ts +8 -0
  24. package/dist/lib/custom-error.d.ts.map +1 -0
  25. package/dist/lib/custom-error.js +19 -0
  26. package/dist/lib/custom-error.js.map +1 -0
  27. package/dist/lib/lambda-route-proxy-entry-handler.d.ts +10 -0
  28. package/dist/lib/lambda-route-proxy-entry-handler.d.ts.map +1 -0
  29. package/dist/lib/lambda-route-proxy-entry-handler.js +72 -0
  30. package/dist/lib/lambda-route-proxy-entry-handler.js.map +1 -0
  31. package/dist/lib/lambda-route-proxy-path-not-found.d.ts +3 -0
  32. package/dist/lib/lambda-route-proxy-path-not-found.d.ts.map +1 -0
  33. package/dist/lib/lambda-route-proxy-path-not-found.js +22 -0
  34. package/dist/lib/lambda-route-proxy-path-not-found.js.map +1 -0
  35. package/dist/lib/middlewares/route-module-jwt-validation-middleware.d.ts +4 -0
  36. package/dist/lib/middlewares/route-module-jwt-validation-middleware.d.ts.map +1 -0
  37. package/dist/lib/middlewares/route-module-jwt-validation-middleware.js +32 -0
  38. package/dist/lib/middlewares/route-module-jwt-validation-middleware.js.map +1 -0
  39. package/dist/lib/middlewares/route-module-schema-validation-middleware.d.ts +4 -0
  40. package/dist/lib/middlewares/route-module-schema-validation-middleware.d.ts.map +1 -0
  41. package/dist/lib/middlewares/route-module-schema-validation-middleware.js +72 -0
  42. package/dist/lib/middlewares/route-module-schema-validation-middleware.js.map +1 -0
  43. package/dist/lib/swagger-route-specification-generator.d.ts +18 -0
  44. package/dist/lib/swagger-route-specification-generator.d.ts.map +1 -0
  45. package/dist/lib/swagger-route-specification-generator.js +115 -0
  46. package/dist/lib/swagger-route-specification-generator.js.map +1 -0
  47. package/dist/lib/swagger-specification-types.d.ts +143 -0
  48. package/dist/lib/swagger-specification-types.d.ts.map +1 -0
  49. package/dist/lib/swagger-specification-types.js +3 -0
  50. package/dist/lib/swagger-specification-types.js.map +1 -0
  51. package/dist/lib/types-and-interfaces.d.ts +78 -0
  52. package/dist/lib/types-and-interfaces.d.ts.map +1 -0
  53. package/dist/lib/types-and-interfaces.js +3 -0
  54. package/dist/lib/types-and-interfaces.js.map +1 -0
  55. package/dist/lib/utils.d.ts +2 -0
  56. package/dist/lib/utils.d.ts.map +1 -0
  57. package/dist/lib/utils.js +17 -0
  58. package/dist/lib/utils.js.map +1 -0
  59. package/package.json +1 -1
package/README.md CHANGED
@@ -224,24 +224,10 @@ interface RouteArguments {
224
224
  - Implement proper permission checks
225
225
  - Validate all input data
226
226
 
227
- ## Contributing
228
-
229
- Contributions are welcome! Please feel free to submit a Pull Request.
230
-
231
- ## License
232
-
233
- MIT
234
-
235
227
  ## GitHub Actions IAM Setup
236
228
 
237
229
  This package includes a utility to set up IAM OIDC authentication for GitHub Actions, allowing secure deployments to AWS without storing long-lived credentials.
238
230
 
239
- ### Installation
240
-
241
- ```bash
242
- npm install aws-lambda-api-tools
243
- ```
244
-
245
231
  ### Usage
246
232
 
247
233
  Create or update an IAM stack for GitHub Actions OIDC authentication:
@@ -329,3 +315,12 @@ You can run the command again with different repositories to update the stack:
329
315
  - New repositories will be added to the trust policy
330
316
  - Existing repositories will remain unchanged
331
317
  - The attached policy can be updated by specifying a new --policy value
318
+
319
+
320
+ ## Contributing
321
+
322
+ Contributions are welcome! Please feel free to submit a Pull Request.
323
+
324
+ ## License
325
+
326
+ MIT
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- "use strict";var t=require("aws-cdk-lib"),e=require("aws-cdk-lib/aws-iam"),s=require("child_process");console.log("Starting GitHub OIDC IAM setup...");var i=process.argv.slice(2),c=i.filter(o=>o.startsWith("--repo=")).map(o=>o.split("=")[1]),n=i.find(o=>o.startsWith("--policy="));c.length===0&&(console.error("Error: at least one --repo argument is required"),console.error("Usage: create-gha-iam-stack --repo=owner/repo-name [--repo=owner/another-repo] [--policy=PolicyName]"),console.error("Example: create-gha-iam-stack --repo=myorg/my-repo --repo=myorg/another-repo --policy=AdministratorAccess"),process.exit(1));var a=c,l=n?n.split("=")[1]:"AdministratorAccess";console.log(`Configuring for repositories: ${a.join(", ")}`);console.log(`Using policy: ${l}`);var p=new t.App,r=class extends t.Stack{constructor(m,g,d){super(m,g,d),console.log("Creating OIDC Provider...");let u=new e.CfnOIDCProvider(this,"GithubOidcProvider",{url:"https://token.actions.githubusercontent.com",clientIdList:["sts.amazonaws.com"],thumbprintList:["6938fd4d98bab03faadb97b34396831e3780aea1","1c58a3a8518e8759bf075b76b750d4f2df264fcd"]});console.log("Creating IAM Role...");let y=new e.Role(this,"GithubActionsRole",{assumedBy:new e.WebIdentityPrincipal(u.attrArn,{StringEquals:{"token.actions.githubusercontent.com:aud":"sts.amazonaws.com"},StringLike:{"token.actions.githubusercontent.com:sub":a.map(h=>`repo:${h}:*`)}}),managedPolicies:[e.ManagedPolicy.fromAwsManagedPolicyName(l)]});new t.CfnOutput(this,"RoleArn",{value:y.roleArn,description:"ARN of role to use in GitHub Actions"})}};console.log("Creating CloudFormation stack...");new r(p,"GithubActionsIam");console.log("Synthesizing CloudFormation template...");var f=p.synth();console.log("Starting deployment...");try{let o=["cdk deploy","GithubActionsIam","--require-approval never",`--app "${f.directory}"`].join(" ");console.log(`Executing: ${o}`),(0,s.execSync)(o,{stdio:"inherit",env:{...process.env,AWS_REGION:process.env.AWS_REGION||"us-east-1"}}),console.log("Deployment completed successfully!")}catch(o){console.error("Deployment failed:",o),process.exit(1)}
2
+ "use strict";var t=require("aws-cdk-lib"),e=require("aws-cdk-lib/aws-iam"),n=require("child_process");console.log("Starting GitHub OIDC IAM setup...");var i=process.argv.slice(2),c=i.filter(o=>o.startsWith("--repo=")).map(o=>o.split("=")[1]),s=i.find(o=>o.startsWith("--policy="));c.length===0&&(console.error("Error: at least one --repo argument is required"),console.error("Usage: create-gha-iam-stack --repo=owner/repo-name [--repo=owner/another-repo] [--policy=PolicyName]"),console.error("Example: create-gha-iam-stack --repo=myorg/my-repo --repo=myorg/another-repo --policy=AdministratorAccess"),process.exit(1));var a=c,l=s?s.split("=")[1]:"AdministratorAccess";console.log(`Configuring for repositories: ${a.join(", ")}`);console.log(`Using policy: ${l}`);var p=new t.App,r=class extends t.Stack{constructor(m,g,d){super(m,g,d),console.log("Creating OIDC Provider...");let u=new e.CfnOIDCProvider(this,"GithubOidcProvider",{url:"https://token.actions.githubusercontent.com",clientIdList:["sts.amazonaws.com"],thumbprintList:["6938fd4d98bab03faadb97b34396831e3780aea1","1c58a3a8518e8759bf075b76b750d4f2df264fcd"]});console.log("Creating IAM Role...");let y=new e.Role(this,"GithubActionsRole",{assumedBy:new e.WebIdentityPrincipal(u.attrArn,{StringEquals:{"token.actions.githubusercontent.com:aud":"sts.amazonaws.com"},StringLike:{"token.actions.githubusercontent.com:sub":a.map(h=>`repo:${h}:*`)}}),managedPolicies:[e.ManagedPolicy.fromAwsManagedPolicyName(l)]});new t.CfnOutput(this,"RoleArn",{value:y.roleArn,description:"ARN of role to use in GitHub Actions"})}};console.log("Creating CloudFormation stack...");new r(p,"GithubActionsIam");console.log("Synthesizing CloudFormation template...");var b=p.synth();console.log("Starting deployment...");try{let o=["cdk deploy","GithubActionsIam","--require-approval never",`--app "${b.directory}"`].join(" ");console.log(`Executing: ${o}`),(0,n.execSync)(o,{stdio:"inherit",env:{...process.env,AWS_REGION:process.env.AWS_REGION||"us-east-1"}}),console.log("Deployment completed successfully!")}catch(o){console.error("Deployment failed:",o),process.exit(1)}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=bootstrap-iam.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-iam.d.ts","sourceRoot":"","sources":["../../src/bin/bootstrap-iam.ts"],"names":[],"mappings":""}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const aws_cdk_lib_1 = require("aws-cdk-lib");
4
+ const aws_iam_1 = require("aws-cdk-lib/aws-iam");
5
+ const child_process_1 = require("child_process");
6
+ console.log('Starting GitHub OIDC IAM setup...');
7
+ // Parse command line arguments
8
+ const args = process.argv.slice(2);
9
+ const repoArgs = args.filter(t => t.startsWith("--repo=")).map(t => t.split("=")[1]);
10
+ const policyArg = args.find(t => t.startsWith("--policy="));
11
+ if (repoArgs.length === 0) {
12
+ console.error("Error: at least one --repo argument is required");
13
+ console.error("Usage: create-gha-iam-stack --repo=owner/repo-name [--repo=owner/another-repo] [--policy=PolicyName]");
14
+ console.error("Example: create-gha-iam-stack --repo=myorg/my-repo --repo=myorg/another-repo --policy=AdministratorAccess");
15
+ process.exit(1);
16
+ }
17
+ const repoNames = repoArgs;
18
+ const policyName = policyArg ? policyArg.split("=")[1] : "AdministratorAccess";
19
+ console.log(`Configuring for repositories: ${repoNames.join(", ")}`);
20
+ console.log(`Using policy: ${policyName}`);
21
+ const app = new aws_cdk_lib_1.App();
22
+ class GithubActionsIamStack extends aws_cdk_lib_1.Stack {
23
+ constructor(scope, id, props) {
24
+ super(scope, id, props);
25
+ console.log('Creating OIDC Provider...');
26
+ const githubOidcProvider = new aws_iam_1.CfnOIDCProvider(this, "GithubOidcProvider", {
27
+ url: "https://token.actions.githubusercontent.com",
28
+ clientIdList: ["sts.amazonaws.com"],
29
+ thumbprintList: [
30
+ "6938fd4d98bab03faadb97b34396831e3780aea1",
31
+ "1c58a3a8518e8759bf075b76b750d4f2df264fcd"
32
+ ]
33
+ });
34
+ console.log('Creating IAM Role...');
35
+ const deploymentRole = new aws_iam_1.Role(this, "GithubActionsRole", {
36
+ assumedBy: new aws_iam_1.WebIdentityPrincipal(githubOidcProvider.attrArn, {
37
+ StringEquals: {
38
+ "token.actions.githubusercontent.com:aud": "sts.amazonaws.com"
39
+ },
40
+ StringLike: {
41
+ "token.actions.githubusercontent.com:sub": repoNames.map(repo => `repo:${repo}:*`)
42
+ }
43
+ }),
44
+ managedPolicies: [
45
+ aws_iam_1.ManagedPolicy.fromAwsManagedPolicyName(policyName)
46
+ ]
47
+ });
48
+ new aws_cdk_lib_1.CfnOutput(this, "RoleArn", {
49
+ value: deploymentRole.roleArn,
50
+ description: "ARN of role to use in GitHub Actions"
51
+ });
52
+ }
53
+ }
54
+ console.log('Creating CloudFormation stack...');
55
+ new GithubActionsIamStack(app, "GithubActionsIam");
56
+ console.log('Synthesizing CloudFormation template...');
57
+ const assembly = app.synth();
58
+ // Execute the deployment
59
+ console.log('Starting deployment...');
60
+ try {
61
+ const cdkCommand = [
62
+ 'cdk deploy',
63
+ 'GithubActionsIam',
64
+ '--require-approval never',
65
+ `--app "${assembly.directory}"`,
66
+ ].join(' ');
67
+ console.log(`Executing: ${cdkCommand}`);
68
+ (0, child_process_1.execSync)(cdkCommand, {
69
+ stdio: 'inherit',
70
+ env: {
71
+ ...process.env,
72
+ AWS_REGION: process.env.AWS_REGION || 'us-east-1',
73
+ }
74
+ });
75
+ console.log('Deployment completed successfully!');
76
+ }
77
+ catch (error) {
78
+ console.error('Deployment failed:', error);
79
+ process.exit(1);
80
+ }
81
+ //# sourceMappingURL=bootstrap-iam.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap-iam.js","sourceRoot":"","sources":["../../src/bin/bootstrap-iam.ts"],"names":[],"mappings":";;AAAA,6CAAgE;AAChE,iDAAiG;AACjG,iDAAyC;AAEzC,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;AAEjD,+BAA+B;AAC/B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AACnC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrF,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;AAE5D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;IACzB,OAAO,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;IACjE,OAAO,CAAC,KAAK,CAAC,sGAAsG,CAAC,CAAC;IACtH,OAAO,CAAC,KAAK,CAAC,2GAA2G,CAAC,CAAC;IAC3H,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB;AAED,MAAM,SAAS,GAAG,QAAQ,CAAC;AAC3B,MAAM,UAAU,GAAG,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC;AAE/E,OAAO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AkC,CAAC,CAAC;AAChD,IAAI,qBAAqB,CAAC,GAAG,EAAE,kBAAkB,CAAC,CAAC;AAEnD,OAAO,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;AACvD,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,EAAE,CAAC;AAE7B,yBAAyB;AACzB,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;AACtC,IAAI;IACF,MAAM,UAAU,GAAG;QACjB,YAAY;QACZ,kBAAkB;QAClB,0BAA0B;QAC1B,UAAU,QAAQ,CAAC,SAAS,GAAG;KAChC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEZ,OAAO,CAAC,GAAG,CAAC,cAAc,UAAU,EAAE,CAAC,CAAC;IAExC,IAAA,wBAAQ,EAAC,UAAU,EAAE;QACnB,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE;YACH,GAAG,OAAO,CAAC,GAAG;YACd,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,WAAW;SAClD;KACF,CAAC,CAAC;IAEH,OAAO,CAAC,GAAG,CAAC,oCAAoC,CAAC,CAAC;CACnD;AAAC,OAAO,KAAK,EAAE;IACd,OAAO,CAAC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;IAC3C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/bin/cli.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const commander_1 = require("commander");
4
+ const path_1 = require("path");
5
+ commander_1.program
6
+ .name('aws-lambda-api-tools')
7
+ .description('CLI tools for AWS Lambda and API Gateway')
8
+ .version('0.1.5');
9
+ commander_1.program.command('create-gha-iam-stack')
10
+ .description('Create IAM stack for GitHub Actions OIDC authentication')
11
+ .option('--repo <owner/repo>', 'GitHub repository (owner/repo)', collect, [])
12
+ .option('--policy <name>', 'AWS managed policy name', 'AdministratorAccess')
13
+ .action(async (options) => {
14
+ if (options.repo.length === 0) {
15
+ console.error('Error: at least one --repo argument is required');
16
+ process.exit(1);
17
+ }
18
+ // Convert Commander options to argv format for bootstrap script
19
+ process.argv = [
20
+ process.argv[0],
21
+ process.argv[1],
22
+ ...options.repo.map((repo) => `--repo=${repo}`),
23
+ `--policy=${options.policy}`
24
+ ];
25
+ require((0, path_1.join)(__dirname, 'bootstrap-iam.js'));
26
+ });
27
+ // Helper function to collect multiple --repo options
28
+ function collect(value, previous) {
29
+ return previous.concat([value]);
30
+ }
31
+ commander_1.program.parse();
32
+ //# sourceMappingURL=cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.js","sourceRoot":"","sources":["../../src/bin/cli.ts"],"names":[],"mappings":";;AAAA,yCAAoC;AACpC,+BAA4B;AAE5B,mBAAO;KACJ,IAAI,CAAC,sBAAsB,CAAC;KAC5B,WAAW,CAAC,0CAA0C,CAAC;KACvD,OAAO,CAAC,OAAO,CAAC,CAAC;AAEpB,mBAAO,CAAC,OAAO,CAAC,sBAAsB,CAAC;KACpC,WAAW,CAAC,yDAAyD,CAAC;KACtE,MAAM,CAAC,qBAAqB,EAAE,gCAAgC,EAAE,OAAO,EAAE,EAAE,CAAC;KAC5E,MAAM,CAAC,iBAAiB,EAAE,yBAAyB,EAAE,qBAAqB,CAAC;KAC3E,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE;IACxB,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QAC7B,OAAO,CAAC,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACjE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;KACjB;IAED,gEAAgE;IAChE,OAAO,CAAC,IAAI,GAAG;QACb,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACf,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACf,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,UAAU,IAAI,EAAE,CAAC;QACvD,YAAY,OAAO,CAAC,MAAM,EAAE;KAC7B,CAAC;IACF,OAAO,CAAC,IAAA,WAAI,EAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC,CAAC;AAC/C,CAAC,CAAC,CAAC;AAEL,qDAAqD;AACrD,SAAS,OAAO,CAAC,KAAa,EAAE,QAAkB;IAChD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAClC,CAAC;AAED,mBAAO,CAAC,KAAK,EAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type { BaseResponseObject, BaseRouteResponse, MiddlewareArgumentsInputFunction, MiddlewareChain, MiddlewareSchemaInputFunction, ResponseData, ResponseError, ResponseObject, RouteArguments, RouteModule, RouteResponse, RouteSchema, ConfigRouteEntry, RouteConfig, Permission, } from './lib/types-and-interfaces';
2
+ export { CustomError } from './lib/custom-error';
3
+ export { lambdaRouteProxyEntryHandler } from './lib/lambda-route-proxy-entry-handler';
4
+ export { lambdaRouteProxyPathNotFound } from './lib/lambda-route-proxy-path-not-found';
5
+ export { schemaValidationMiddleware } from './lib/middlewares/route-module-schema-validation-middleware';
6
+ export { jwtValidationMiddleware } from './lib/middlewares/route-module-jwt-validation-middleware';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,iBAAiB,EACjB,gCAAgC,EAChC,eAAe,EACf,6BAA6B,EAC7B,YAAY,EACZ,aAAa,EACb,cAAc,EACd,cAAc,EACd,WAAW,EACX,aAAa,EACb,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,UAAU,GACX,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,4BAA4B,EAAE,MAAM,wCAAwC,CAAC;AAEtF,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAEvF,OAAO,EAAE,0BAA0B,EAAE,MAAM,6DAA6D,CAAC;AAEzG,OAAO,EAAE,uBAAuB,EAAE,MAAM,0DAA0D,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jwtValidationMiddleware = exports.schemaValidationMiddleware = exports.lambdaRouteProxyPathNotFound = exports.lambdaRouteProxyEntryHandler = exports.CustomError = void 0;
4
+ var custom_error_1 = require("./lib/custom-error");
5
+ Object.defineProperty(exports, "CustomError", { enumerable: true, get: function () { return custom_error_1.CustomError; } });
6
+ var lambda_route_proxy_entry_handler_1 = require("./lib/lambda-route-proxy-entry-handler");
7
+ Object.defineProperty(exports, "lambdaRouteProxyEntryHandler", { enumerable: true, get: function () { return lambda_route_proxy_entry_handler_1.lambdaRouteProxyEntryHandler; } });
8
+ var lambda_route_proxy_path_not_found_1 = require("./lib/lambda-route-proxy-path-not-found");
9
+ Object.defineProperty(exports, "lambdaRouteProxyPathNotFound", { enumerable: true, get: function () { return lambda_route_proxy_path_not_found_1.lambdaRouteProxyPathNotFound; } });
10
+ var route_module_schema_validation_middleware_1 = require("./lib/middlewares/route-module-schema-validation-middleware");
11
+ Object.defineProperty(exports, "schemaValidationMiddleware", { enumerable: true, get: function () { return route_module_schema_validation_middleware_1.schemaValidationMiddleware; } });
12
+ var route_module_jwt_validation_middleware_1 = require("./lib/middlewares/route-module-jwt-validation-middleware");
13
+ Object.defineProperty(exports, "jwtValidationMiddleware", { enumerable: true, get: function () { return route_module_jwt_validation_middleware_1.jwtValidationMiddleware; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAkBA,mDAAiD;AAAxC,2GAAA,WAAW,OAAA;AAEpB,2FAAsF;AAA7E,gJAAA,4BAA4B,OAAA;AAErC,6FAAuF;AAA9E,iJAAA,4BAA4B,OAAA;AAErC,yHAAyG;AAAhG,uJAAA,0BAA0B,OAAA;AAEnC,mHAAmG;AAA1F,iJAAA,uBAAuB,OAAA"}
@@ -0,0 +1,3 @@
1
+ import { APIGatewayProxyEventV2 } from "aws-lambda";
2
+ export declare const authorizeRoute: (event: APIGatewayProxyEventV2) => void;
3
+ //# sourceMappingURL=authorization-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-helper.d.ts","sourceRoot":"","sources":["../../src/lib/authorization-helper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAGpD,eAAO,MAAM,cAAc,yCAO1B,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.authorizeRoute = void 0;
4
+ // import { CustomError } from './custom-error';
5
+ const authorizeRoute = (event) => {
6
+ // extract token
7
+ const token = event.headers.authorization;
8
+ if (!token) {
9
+ // throw new CustomError('Request is unauthenticated. No bearer token exists.', 401);
10
+ }
11
+ // implement authorize check with jwt from issuer
12
+ };
13
+ exports.authorizeRoute = authorizeRoute;
14
+ //# sourceMappingURL=authorization-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization-helper.js","sourceRoot":"","sources":["../../src/lib/authorization-helper.ts"],"names":[],"mappings":";;;AACA,gDAAgD;AAEzC,MAAM,cAAc,GAAG,CAAC,KAA6B,EAAE,EAAE;IAC9D,gBAAgB;IAChB,MAAM,KAAK,GAAW,KAAK,CAAC,OAAQ,CAAC,aAAuB,CAAC;IAC7D,IAAI,CAAC,KAAK,EAAE;QACV,qFAAqF;KACtF;IACD,iDAAiD;AACnD,CAAC,CAAC;AAPW,QAAA,cAAc,kBAOzB"}
@@ -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,MAA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MAAM,CAAC;IAC9C,QAAQ,EAAE,EAAE;IACZ,QAAQ,EAAE,WAAW;CACtB,CAAC,CAAC;AAGH;;GAEG;AACI,MAAM,KAAK,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,iBAAM,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,cAAM,EAAE,CAAC,CAAC;AAA/D,QAAA,KAAK,SAA0D;AAAA,CAAC;AAE7E;;GAEG;AACI,MAAM,IAAI,GAAG,CAAC,KAAU,EAAE,EAAE,CAAC,iBAAM,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,cAAM,EAAE,CAAC,CAAC;AAA9D,QAAA,IAAI,QAA0D;AAGrE,MAAM,2BAA2B,GAAG,CAAC,UAAkB,EAAE,YAAoB,EAAE,aAAqB,EAAE,EAAE;IAC7G,IAAI;QACF,MAAM,GAAG,GAAQ,IAAA,aAAK,EAAC,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;QAC5D,yBAAyB;QACzB,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;QACxC,EAAE,CAAC,aAAa,CAAC,UAAU,EAAE,IAAA,YAAI,EAAC,GAAG,CAAC,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"}
@@ -0,0 +1,8 @@
1
+ export declare class CustomError extends Error {
2
+ _httpStatusCode: number;
3
+ _message: string;
4
+ constructor(message: string, statusCode: number);
5
+ get httpStatusCode(): number;
6
+ get message(): string;
7
+ }
8
+ //# sourceMappingURL=custom-error.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomError = void 0;
4
+ class CustomError extends Error {
5
+ constructor(message, statusCode) {
6
+ super(message);
7
+ this._httpStatusCode = statusCode || 500;
8
+ this._message = message;
9
+ }
10
+ get httpStatusCode() {
11
+ return this._httpStatusCode;
12
+ }
13
+ get message() {
14
+ return this._message;
15
+ }
16
+ }
17
+ exports.CustomError = CustomError;
18
+ ;
19
+ //# sourceMappingURL=custom-error.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,10 @@
1
+ import { APIGatewayProxyEventV2 } from 'aws-lambda';
2
+ import { RouteConfig, RouteArguments, RouteModule } from './types-and-interfaces';
3
+ export declare const getRouteModule: (config: RouteConfig, method: string, path: string, availableRouteModules: {
4
+ [key: string]: any;
5
+ }) => RouteModule;
6
+ export declare const getRouteModuleResult: ({ routeChain }: RouteModule, incoming: RouteArguments) => Promise<any>;
7
+ export declare const lambdaRouteProxyEntryHandler: (config: RouteConfig, availableRouteModules: {
8
+ [key: string]: any;
9
+ }) => (event: APIGatewayProxyEventV2) => Promise<{}>;
10
+ //# sourceMappingURL=lambda-route-proxy-entry-handler.d.ts.map
@@ -0,0 +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;;oDAgD7D,CAAC"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lambdaRouteProxyEntryHandler = exports.getRouteModuleResult = exports.getRouteModule = void 0;
4
+ const custom_error_1 = require("./custom-error");
5
+ const authorization_helper_1 = require("./authorization-helper");
6
+ const getRouteConfigEntry = (config, method, path) => config.routes.find(r => r.path.toLowerCase() === path.toLowerCase() && r.method.toLowerCase() === method.toLowerCase());
7
+ const shouldAuthorizeRoute = (routesConfig, routeConfigEntry) => (routesConfig.authorizeAllRoutes && routeConfigEntry.authorizeRoute !== false)
8
+ ||
9
+ routeConfigEntry.authorizeRoute === true;
10
+ const getRouteModule = (config, method, path, availableRouteModules) => {
11
+ const routeEntry = getRouteConfigEntry(config, method, path);
12
+ let routeModule = null;
13
+ console.log(`route entry: ${JSON.stringify(routeEntry)}`);
14
+ if (routeEntry) {
15
+ const matchingRouteModuleMapKey = Object.keys(availableRouteModules).find((k) => routeEntry.handlerPath.endsWith(k));
16
+ // routeModule = availableRouteModules[routeEntry.handlerPath.split('/').reverse()[0]];
17
+ routeModule = availableRouteModules[matchingRouteModuleMapKey];
18
+ }
19
+ return routeModule;
20
+ };
21
+ exports.getRouteModule = getRouteModule;
22
+ const getRouteModuleResult = async ({ routeChain }, incoming) => {
23
+ let returnValue = incoming;
24
+ for (const chainFn of routeChain) {
25
+ returnValue = await chainFn(returnValue);
26
+ }
27
+ return returnValue;
28
+ };
29
+ exports.getRouteModuleResult = getRouteModuleResult;
30
+ const lambdaRouteProxyEntryHandler = (config, availableRouteModules) => async (event) => {
31
+ console.log(`Event Data: ${JSON.stringify(event)}`);
32
+ const { routeKey, queryStringParameters, pathParameters, body, isBase64Encoded, } = event;
33
+ let retVal = {};
34
+ try {
35
+ const [method = '', path = ''] = routeKey.split(' ');
36
+ if (shouldAuthorizeRoute(config, getRouteConfigEntry(config, method, path))) {
37
+ await (0, authorization_helper_1.authorizeRoute)(event);
38
+ }
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}`);
45
+ retVal = await (0, exports.getRouteModuleResult)(routeModule, {
46
+ query: queryStringParameters,
47
+ params: pathParameters,
48
+ body: body ? decodedBody || JSON.parse(body) : undefined,
49
+ rawEvent: event,
50
+ });
51
+ }
52
+ catch (error) {
53
+ console.error(JSON.stringify({ error, stack: error.stack }));
54
+ if (error instanceof custom_error_1.CustomError) {
55
+ retVal = {
56
+ statusCode: error.httpStatusCode,
57
+ headers: { 'Content-Type': 'application/json' },
58
+ body: error.message,
59
+ };
60
+ }
61
+ else {
62
+ retVal = {
63
+ statusCode: 500,
64
+ headers: { 'Content-Type': 'application/json' },
65
+ body: error.message || JSON.stringify(error),
66
+ };
67
+ }
68
+ }
69
+ return retVal;
70
+ };
71
+ exports.lambdaRouteProxyEntryHandler = lambdaRouteProxyEntryHandler;
72
+ //# sourceMappingURL=lambda-route-proxy-entry-handler.js.map
@@ -0,0 +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,KAAK,KAAK,CAAC;;QAE9E,gBAAgB,CAAC,cAAc,KAAK,IAAI,CAAC;AAGpC,MAAM,cAAc,GAAG,CAAC,MAAmB,EAAE,MAAc,EAAE,IAAY,EAAE,qBAA6C,EAAe,EAAE;IAC9I,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAC7D,IAAI,WAAW,GAAG,IAAI,CAAC;IACvB,OAAO,CAAC,GAAG,CAAC,gBAAgB,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;IAC1D,IAAI,UAAU,EAAE;QACd,MAAM,yBAAyB,GAAG,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,IAAI,CAAC,CAAC,CAAS,E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}
@@ -0,0 +1,3 @@
1
+ import { RouteModule } from './types-and-interfaces';
2
+ export declare const lambdaRouteProxyPathNotFound: RouteModule;
3
+ //# sourceMappingURL=lambda-route-proxy-path-not-found.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lambdaRouteProxyPathNotFound = void 0;
4
+ const handler = async (input) => {
5
+ if (input.rawEvent.requestContext.http.method === 'OPTIONS') {
6
+ return {
7
+ statusCode: 200,
8
+ headers: {
9
+ 'Access-Control-Allow-Origin': '*',
10
+ 'Access-Control-Allow-Methods': '*',
11
+ 'Access-Control-Allow-Headers': '*',
12
+ 'Access-Control-Max-Age': 300,
13
+ }
14
+ };
15
+ }
16
+ return { statusCode: 404, body: JSON.stringify('Not found') };
17
+ };
18
+ exports.lambdaRouteProxyPathNotFound = {
19
+ routeChain: [handler],
20
+ routeSchema: {},
21
+ };
22
+ //# sourceMappingURL=lambda-route-proxy-path-not-found.js.map
@@ -0,0 +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,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"}
@@ -0,0 +1,4 @@
1
+ import { RouteArguments } from '../types-and-interfaces';
2
+ export declare const jwtValidationMiddleware: (incomingData: RouteArguments) => RouteArguments;
3
+ export default jwtValidationMiddleware;
4
+ //# sourceMappingURL=route-module-jwt-validation-middleware.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-module-jwt-validation-middleware.d.ts","sourceRoot":"","sources":["../../../src/lib/middlewares/route-module-jwt-validation-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAIzD,eAAO,MAAM,uBAAuB,iBAAkB,cAAc,KAAG,cAuBtE,CAAC;AAEF,eAAe,uBAAuB,CAAC"}