quidproquo-actionprocessor-awslambda 0.0.30 → 0.0.31

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 (54) hide show
  1. package/lib/awsLambdaUtils.d.ts +0 -1
  2. package/lib/awsLambdaUtils.js +1 -18
  3. package/lib/getActionProcessor/core/system/getExecuteStoryActionProcessor.d.ts +2 -2
  4. package/lib/getActionProcessor/core/system/getExecuteStoryActionProcessor.js +4 -5
  5. package/lib/getActionProcessor/core/system/index.d.ts +2 -2
  6. package/lib/getActionProcessor/core/system/index.js +1 -1
  7. package/lib/index.d.ts +1 -0
  8. package/lib/index.js +1 -0
  9. package/lib/lambdas/index.d.ts +3 -0
  10. package/lib/lambdas/index.js +19 -0
  11. package/lib/lambdas/lambdaAPIGatewayEvent.d.ts +13 -0
  12. package/lib/lambdas/lambdaAPIGatewayEvent.js +101 -0
  13. package/lib/lambdas/lambdaConfig.d.ts +4 -0
  14. package/lib/lambdas/lambdaConfig.js +4 -0
  15. package/lib/lambdas/lambdaEventBridgeEvent.d.ts +5 -0
  16. package/lib/lambdas/lambdaEventBridgeEvent.js +60 -0
  17. package/lib/types/DynamicLoader.d.ts +1 -0
  18. package/lib/types/DynamicLoader.js +2 -0
  19. package/package.json +3 -2
  20. package/src/awsLambdaUtils.ts +22 -0
  21. package/src/getActionProcessor/core/config/getConfigGetParameterActionProcessor.ts +23 -0
  22. package/src/getActionProcessor/core/config/getConfigGetParametersActionProcessor.ts +27 -0
  23. package/src/getActionProcessor/core/config/getConfigGetSecretActionProcessor.ts +23 -0
  24. package/src/getActionProcessor/core/config/index.ts +11 -0
  25. package/src/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.ts +134 -0
  26. package/src/getActionProcessor/core/event/getEventBridgeEventActionProcessor.ts +66 -0
  27. package/src/getActionProcessor/core/file/getFileDeleteActionProcessor.ts +31 -0
  28. package/src/getActionProcessor/core/file/getFileExistsActionProcessor.ts +16 -0
  29. package/src/getActionProcessor/core/file/getFileListDirectoryActionProcessor.ts +28 -0
  30. package/src/getActionProcessor/core/file/getFileReadTextContentsActionProcessor.ts +18 -0
  31. package/src/getActionProcessor/core/file/getFileWriteTextContentsActionProcessor.ts +23 -0
  32. package/src/getActionProcessor/core/file/index.ts +15 -0
  33. package/src/getActionProcessor/core/index.ts +7 -0
  34. package/src/getActionProcessor/core/system/getExecuteStoryActionProcessor.ts +67 -0
  35. package/src/getActionProcessor/core/system/index.ts +6 -0
  36. package/src/getActionProcessor/index.ts +1 -0
  37. package/src/index.ts +6 -0
  38. package/src/lambdas/index.ts +4 -0
  39. package/src/lambdas/lambdaAPIGatewayEvent.ts +105 -0
  40. package/src/lambdas/lambdaConfig.ts +11 -0
  41. package/src/lambdas/lambdaEventBridgeEvent.ts +60 -0
  42. package/src/logic/parametersManager/getParameter.ts +13 -0
  43. package/src/logic/parametersManager/getParameters.ts +15 -0
  44. package/src/logic/s3/deleteFiles.ts +17 -0
  45. package/src/logic/s3/listFiles.ts +66 -0
  46. package/src/logic/s3/objectExists.ts +18 -0
  47. package/src/logic/s3/readTextFile.ts +14 -0
  48. package/src/logic/s3/s3Client.ts +5 -0
  49. package/src/logic/s3/s3Utils.ts +5 -0
  50. package/src/logic/s3/writeTextFile.ts +17 -0
  51. package/src/logic/secretsManager/getSecret.ts +13 -0
  52. package/src/runtimeConfig/QPQAWSLambdaConfig.ts +15 -0
  53. package/src/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.ts +19 -0
  54. package/src/types/DynamicLoader.ts +1 -0
@@ -4,4 +4,3 @@ export interface UrlMatch {
4
4
  params: Record<string, string> | null;
5
5
  }
6
6
  export declare const matchUrl: (path: string, url: string) => UrlMatch;
7
- export declare const loadModule: (src: string) => Promise<any>;
@@ -1,15 +1,6 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.loadModule = exports.matchUrl = exports.randomGuid = void 0;
3
+ exports.matchUrl = exports.randomGuid = void 0;
13
4
  const crypto_1 = require("crypto");
14
5
  const node_match_path_1 = require("node-match-path");
15
6
  const randomGuid = () => {
@@ -26,11 +17,3 @@ const matchUrl = (path, url) => {
26
17
  };
27
18
  };
28
19
  exports.matchUrl = matchUrl;
29
- const loadModule = (src) => __awaiter(void 0, void 0, void 0, function* () {
30
- try {
31
- return require(src);
32
- }
33
- catch (_a) { }
34
- return null;
35
- });
36
- exports.loadModule = loadModule;
@@ -1,7 +1,7 @@
1
1
  import { SystemExecuteStoryActionProcessor } from 'quidproquo-core';
2
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
+ import { DynamicModuleLoader } from '../../../types/DynamicLoader';
3
3
  export declare const getDateNow: () => string;
4
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
4
+ declare const _default: (dynamicModuleLoader: DynamicModuleLoader) => {
5
5
  "@quidproquo-core/System/ExecuteStory": SystemExecuteStoryActionProcessor<any[]>;
6
6
  };
7
7
  export default _default;
@@ -14,9 +14,9 @@ const quidproquo_core_1 = require("quidproquo-core");
14
14
  const awsLambdaUtils_1 = require("./../../../awsLambdaUtils");
15
15
  const getDateNow = () => new Date().toISOString();
16
16
  exports.getDateNow = getDateNow;
17
- const getProcessExecuteStory = (runtimeConfig) => {
17
+ const getProcessExecuteStory = (dynamicModuleLoader) => {
18
18
  return (payload, session, actionProcessors) => __awaiter(void 0, void 0, void 0, function* () {
19
- let module = yield (0, awsLambdaUtils_1.loadModule)(payload.src);
19
+ let module = yield dynamicModuleLoader(payload.src);
20
20
  if (module === null) {
21
21
  return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, `Module not found [${payload.src}]`);
22
22
  }
@@ -38,9 +38,8 @@ const getProcessExecuteStory = (runtimeConfig) => {
38
38
  });
39
39
  });
40
40
  };
41
- exports.default = (runtimeConfig) => {
42
- // const appName = qpqCoreUtils.getAppName(config);
41
+ exports.default = (dynamicModuleLoader) => {
43
42
  return {
44
- [quidproquo_core_1.SystemActionType.ExecuteStory]: getProcessExecuteStory(runtimeConfig),
43
+ [quidproquo_core_1.SystemActionType.ExecuteStory]: getProcessExecuteStory(dynamicModuleLoader),
45
44
  };
46
45
  };
@@ -1,5 +1,5 @@
1
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
1
+ import { DynamicModuleLoader } from '../../../types/DynamicLoader';
2
+ declare const _default: (dynamicModuleLoader: DynamicModuleLoader) => {
3
3
  "@quidproquo-core/System/ExecuteStory": import("quidproquo-core/lib").SystemExecuteStoryActionProcessor<any[]>;
4
4
  };
5
5
  export default _default;
@@ -4,4 +4,4 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const getExecuteStoryActionProcessor_1 = __importDefault(require("./getExecuteStoryActionProcessor"));
7
- exports.default = (runtimeConfig) => (Object.assign({}, (0, getExecuteStoryActionProcessor_1.default)(runtimeConfig)));
7
+ exports.default = (dynamicModuleLoader) => (Object.assign({}, (0, getExecuteStoryActionProcessor_1.default)(dynamicModuleLoader)));
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './getActionProcessor';
2
2
  export * as awsLambdaUtils from './awsLambdaUtils';
3
3
  export * from './runtimeConfig/QPQAWSLambdaConfig';
4
+ export * from './types/DynamicLoader';
package/lib/index.js CHANGED
@@ -30,3 +30,4 @@ exports.awsLambdaUtils = void 0;
30
30
  __exportStar(require("./getActionProcessor"), exports);
31
31
  exports.awsLambdaUtils = __importStar(require("./awsLambdaUtils"));
32
32
  __exportStar(require("./runtimeConfig/QPQAWSLambdaConfig"), exports);
33
+ __exportStar(require("./types/DynamicLoader"), exports);
@@ -0,0 +1,3 @@
1
+ export * from './lambdaConfig';
2
+ export * from './lambdaAPIGatewayEvent';
3
+ export * from './lambdaEventBridgeEvent';
@@ -0,0 +1,19 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lambdaConfig"), exports);
18
+ __exportStar(require("./lambdaAPIGatewayEvent"), exports);
19
+ __exportStar(require("./lambdaEventBridgeEvent"), exports);
@@ -0,0 +1,13 @@
1
+ import { Context } from 'aws-lambda';
2
+ import { DynamicModuleLoader } from '../types/DynamicLoader';
3
+ import { ActionProcessorListResolver } from './lambdaConfig';
4
+ export declare const getAPIGatewayEventExecutor: (dynamicModuleLoader: DynamicModuleLoader, getCustomActionProcessors?: ActionProcessorListResolver) => (event: import("aws-lambda").APIGatewayProxyEvent, context: Context) => Promise<{
5
+ statusCode: any;
6
+ body: string;
7
+ headers: any;
8
+ }>;
9
+ export declare const executeAPIGatewayEvent: (event: import("aws-lambda").APIGatewayProxyEvent, context: Context) => Promise<{
10
+ statusCode: any;
11
+ body: string;
12
+ headers: any;
13
+ }>;
@@ -0,0 +1,101 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.executeAPIGatewayEvent = exports.getAPIGatewayEventExecutor = void 0;
39
+ const quidproquo_webserver_1 = require("quidproquo-webserver");
40
+ const quidproquo_core_1 = require("quidproquo-core");
41
+ const quidproquo_actionprocessor_node_1 = require("quidproquo-actionprocessor-node");
42
+ const awsLambdaUtils = __importStar(require("../awsLambdaUtils"));
43
+ const getActionProcessor_1 = require("../getActionProcessor");
44
+ const lambdaConfig_1 = require("./lambdaConfig");
45
+ // @ts-ignore - Special webpack loader
46
+ const qpq_dynamic_loader_1 = __importDefault(require("qpq-dynamic-loader!"));
47
+ // TODO: Make this a util or something based on server time or something..
48
+ const getDateNow = () => new Date().toISOString();
49
+ const ErrorTypeHttpResponseMap = {
50
+ [quidproquo_core_1.ErrorTypeEnum.BadRequest]: 400,
51
+ [quidproquo_core_1.ErrorTypeEnum.Unauthorized]: 401,
52
+ [quidproquo_core_1.ErrorTypeEnum.PaymentRequired]: 402,
53
+ [quidproquo_core_1.ErrorTypeEnum.Forbidden]: 403,
54
+ [quidproquo_core_1.ErrorTypeEnum.NotFound]: 404,
55
+ [quidproquo_core_1.ErrorTypeEnum.TimeOut]: 408,
56
+ [quidproquo_core_1.ErrorTypeEnum.UnsupportedMediaType]: 415,
57
+ [quidproquo_core_1.ErrorTypeEnum.OutOfResources]: 500,
58
+ [quidproquo_core_1.ErrorTypeEnum.GenericError]: 500,
59
+ [quidproquo_core_1.ErrorTypeEnum.NotImplemented]: 501,
60
+ [quidproquo_core_1.ErrorTypeEnum.NoContent]: 204,
61
+ [quidproquo_core_1.ErrorTypeEnum.Invalid]: 422,
62
+ };
63
+ const getAPIGatewayEventExecutor = (dynamicModuleLoader, getCustomActionProcessors = () => ({})) => {
64
+ return (event, context) => __awaiter(void 0, void 0, void 0, function* () {
65
+ // Build a processor for the session and stuff
66
+ // Remove the non route ones ~ let the story execute action add them
67
+ const storyActionProcessor = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, getActionProcessor_1.getAPIGatewayEventActionProcessor)(lambdaConfig_1.lambdaRuntimeConfig.qpqConfig)), (0, getActionProcessor_1.getConfigGetSecretActionProcessor)(lambdaConfig_1.lambdaRuntimeConfig)), (0, getActionProcessor_1.getConfigGetParameterActionProcessor)(lambdaConfig_1.lambdaRuntimeConfig)), (0, getActionProcessor_1.getConfigGetParametersActionProcessor)(lambdaConfig_1.lambdaRuntimeConfig)), (0, getActionProcessor_1.getSystemActionProcessor)(dynamicModuleLoader)), (0, getActionProcessor_1.getFileActionProcessor)(lambdaConfig_1.lambdaRuntimeConfig)), getCustomActionProcessors(lambdaConfig_1.lambdaRuntimeConfig));
68
+ const logger = (result) => __awaiter(void 0, void 0, void 0, function* () {
69
+ // addResult(
70
+ // envConfig.appName,
71
+ // getDateNow(),
72
+ // doWeCarePath,
73
+ // "route-infrastructure",
74
+ // "infrastructure",
75
+ // "askRoute",
76
+ // result
77
+ // );
78
+ });
79
+ // // Run the callback
80
+ const resolveStory = (0, quidproquo_core_1.createRuntime)({}, storyActionProcessor, getDateNow, logger, awsLambdaUtils.randomGuid);
81
+ const result = yield resolveStory(quidproquo_core_1.askProcessEvent, [event, context]);
82
+ // Run the callback
83
+ if (!result.error) {
84
+ return {
85
+ statusCode: result.result.statusCode,
86
+ body: JSON.stringify(result.result.body),
87
+ headers: result.result.headers,
88
+ };
89
+ }
90
+ console.log(JSON.stringify(result));
91
+ const code = ErrorTypeHttpResponseMap[result.error.errorType];
92
+ return {
93
+ statusCode: code || 500,
94
+ body: JSON.stringify(result.error),
95
+ headers: quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(lambdaConfig_1.lambdaRuntimeConfig.qpqConfig, {}, event.headers),
96
+ };
97
+ });
98
+ };
99
+ exports.getAPIGatewayEventExecutor = getAPIGatewayEventExecutor;
100
+ // Default executor
101
+ exports.executeAPIGatewayEvent = (0, exports.getAPIGatewayEventExecutor)(qpq_dynamic_loader_1.default);
@@ -0,0 +1,4 @@
1
+ import { ActionProcessorList } from 'quidproquo-core';
2
+ import { QPQAWSLambdaConfig } from '../runtimeConfig/QPQAWSLambdaConfig';
3
+ export declare const lambdaRuntimeConfig: QPQAWSLambdaConfig;
4
+ export type ActionProcessorListResolver = (lambdaRuntimeConfig: QPQAWSLambdaConfig) => ActionProcessorList;
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lambdaRuntimeConfig = void 0;
4
+ exports.lambdaRuntimeConfig = JSON.parse(process.env.lambdaRuntimeConfig || '{}');
@@ -0,0 +1,5 @@
1
+ import { EventBridgeEvent, Context } from 'aws-lambda';
2
+ import { DynamicModuleLoader } from '../types/DynamicLoader';
3
+ import { ActionProcessorListResolver } from './lambdaConfig';
4
+ export declare const getEventBridgeEventExecutor: (dynamicModuleLoader: DynamicModuleLoader, getCustomActionProcessors?: ActionProcessorListResolver) => (event: EventBridgeEvent<string, void>, context: Context) => Promise<void>;
5
+ export declare const executeEventBridgeEvent: (event: EventBridgeEvent<string, void>, context: Context) => Promise<void>;
@@ -0,0 +1,60 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.executeEventBridgeEvent = exports.getEventBridgeEventExecutor = void 0;
39
+ const quidproquo_core_1 = require("quidproquo-core");
40
+ const quidproquo_actionprocessor_node_1 = require("quidproquo-actionprocessor-node");
41
+ const awsLambdaUtils = __importStar(require("../awsLambdaUtils"));
42
+ const getActionProcessor_1 = require("../getActionProcessor");
43
+ const lambdaConfig_1 = require("./lambdaConfig");
44
+ // @ts-ignore - Special webpack loader
45
+ const qpq_dynamic_loader_1 = __importDefault(require("qpq-dynamic-loader!"));
46
+ // TODO: Make this a util or something based on server time or something..
47
+ const getDateNow = () => new Date().toISOString();
48
+ const getEventBridgeEventExecutor = (dynamicModuleLoader, getCustomActionProcessors = () => ({})) => {
49
+ return (event, context) => __awaiter(void 0, void 0, void 0, function* () {
50
+ // Build a processor for the session and stuff
51
+ // Remove the non event ones
52
+ const storyActionProcessor = Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, getActionProcessor_1.getEventBridgeEventActionProcessor)(lambdaConfig_1.lambdaRuntimeConfig)), (0, getActionProcessor_1.getSystemActionProcessor)(dynamicModuleLoader)), (0, getActionProcessor_1.getFileActionProcessor)(lambdaConfig_1.lambdaRuntimeConfig)), (0, getActionProcessor_1.getConfigGetSecretActionProcessor)(lambdaConfig_1.lambdaRuntimeConfig)), (0, getActionProcessor_1.getConfigGetParameterActionProcessor)(lambdaConfig_1.lambdaRuntimeConfig)), (0, getActionProcessor_1.getConfigGetParametersActionProcessor)(lambdaConfig_1.lambdaRuntimeConfig)), getCustomActionProcessors(lambdaConfig_1.lambdaRuntimeConfig));
53
+ const logger = (result) => __awaiter(void 0, void 0, void 0, function* () { });
54
+ // Run the callback
55
+ const resolveStory = (0, quidproquo_core_1.createRuntime)({}, storyActionProcessor, getDateNow, logger, awsLambdaUtils.randomGuid);
56
+ yield resolveStory(quidproquo_core_1.askProcessEvent, [event, context]);
57
+ });
58
+ };
59
+ exports.getEventBridgeEventExecutor = getEventBridgeEventExecutor;
60
+ exports.executeEventBridgeEvent = (0, exports.getEventBridgeEventExecutor)(qpq_dynamic_loader_1.default);
@@ -0,0 +1 @@
1
+ export type DynamicModuleLoader = (src: string) => Promise<any>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.30",
3
+ "version": "0.0.31",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
7
7
  "files": [
8
- "lib/**/*"
8
+ "lib/**/*",
9
+ "src/**/*"
9
10
  ],
10
11
  "scripts": {
11
12
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -0,0 +1,22 @@
1
+ import { randomUUID } from 'crypto';
2
+ import { match } from 'node-match-path';
3
+
4
+ export const randomGuid = () => {
5
+ return randomUUID();
6
+ };
7
+
8
+ export interface UrlMatch {
9
+ didMatch: boolean;
10
+ params: Record<string, string> | null;
11
+ }
12
+
13
+ export const matchUrl = (path: string, url: string): UrlMatch => {
14
+ // /attempt/{attemptUuid}/result/{test} => /attempt/:attemptUuid/result/:test
15
+ const modifiedPath = path.replaceAll(/{(.+?)}/g, (m, g) => `:${g}`);
16
+
17
+ const matchResult = match(modifiedPath, url);
18
+ return {
19
+ didMatch: matchResult.matches,
20
+ params: matchResult.params,
21
+ };
22
+ };
@@ -0,0 +1,23 @@
1
+ import { ConfigActionType, ConfigGetParameterActionProcessor, actionResult } from 'quidproquo-core';
2
+
3
+ import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
4
+ import { resolveParameterKey } from '../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils';
5
+
6
+ import { getParameter } from '../../../logic/parametersManager/getParameter';
7
+
8
+ const getProcessConfigGetParameter = (
9
+ runtimeConfig: QPQAWSLambdaConfig,
10
+ ): ConfigGetParameterActionProcessor => {
11
+ return async ({ parameterName }) => {
12
+ const awsParameterKey = resolveParameterKey(parameterName, runtimeConfig);
13
+ const parameterValue = await getParameter(awsParameterKey);
14
+
15
+ return actionResult(parameterValue);
16
+ };
17
+ };
18
+
19
+ export default (runtimeConfig: QPQAWSLambdaConfig) => {
20
+ return {
21
+ [ConfigActionType.GetParameter]: getProcessConfigGetParameter(runtimeConfig),
22
+ };
23
+ };
@@ -0,0 +1,27 @@
1
+ import {
2
+ ConfigActionType,
3
+ ConfigGetParametersActionProcessor,
4
+ actionResult,
5
+ } from 'quidproquo-core';
6
+
7
+ import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
8
+ import { resolveParameterKey } from '../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils';
9
+
10
+ import { getParameters } from '../../../logic/parametersManager/getParameters';
11
+
12
+ const getProcessConfigGetParameters = (
13
+ runtimeConfig: QPQAWSLambdaConfig,
14
+ ): ConfigGetParametersActionProcessor => {
15
+ return async ({ parameterNames }) => {
16
+ const awsParameterKeys = parameterNames.map((pn) => resolveParameterKey(pn, runtimeConfig));
17
+ const parameterValues = await getParameters(awsParameterKeys);
18
+
19
+ return actionResult(parameterValues);
20
+ };
21
+ };
22
+
23
+ export default (runtimeConfig: QPQAWSLambdaConfig) => {
24
+ return {
25
+ [ConfigActionType.GetParameters]: getProcessConfigGetParameters(runtimeConfig),
26
+ };
27
+ };
@@ -0,0 +1,23 @@
1
+ import { ConfigActionType, ConfigGetSecretActionProcessor, actionResult } from 'quidproquo-core';
2
+
3
+ import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
4
+ import { resolveSecretKey } from '../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils';
5
+
6
+ import { getSecret } from '../../../logic/secretsManager/getSecret';
7
+
8
+ const getProcessConfigActionType = (
9
+ runtimeConfig: QPQAWSLambdaConfig,
10
+ ): ConfigGetSecretActionProcessor => {
11
+ return async ({ secretName }) => {
12
+ const awsSecretKey = resolveSecretKey(secretName, runtimeConfig);
13
+ const secretValue = await getSecret(awsSecretKey);
14
+
15
+ return actionResult(secretValue);
16
+ };
17
+ };
18
+
19
+ export default (runtimeConfig: QPQAWSLambdaConfig) => {
20
+ return {
21
+ [ConfigActionType.GetSecret]: getProcessConfigActionType(runtimeConfig),
22
+ };
23
+ };
@@ -0,0 +1,11 @@
1
+ import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
+
3
+ import getConfigGetParameterActionProcessor from './getConfigGetParameterActionProcessor';
4
+ import getConfigGetParametersActionProcessor from './getConfigGetParametersActionProcessor';
5
+ import getConfigGetSecretActionProcessor from './getConfigGetSecretActionProcessor';
6
+
7
+ export default (runtimeConfig: QPQAWSLambdaConfig) => ({
8
+ ...getConfigGetParameterActionProcessor(runtimeConfig),
9
+ ...getConfigGetParametersActionProcessor(runtimeConfig),
10
+ ...getConfigGetSecretActionProcessor(runtimeConfig),
11
+ });
@@ -0,0 +1,134 @@
1
+ import {
2
+ EventActionType,
3
+ QPQConfig,
4
+ qpqCoreUtils,
5
+ MatchStoryResult,
6
+ EventMatchStoryActionProcessor,
7
+ EventTransformEventParamsActionProcessor,
8
+ EventTransformResponseResultActionProcessor,
9
+ EventAutoRespondActionProcessor,
10
+ actionResult,
11
+ actionResultError,
12
+ ErrorTypeEnum,
13
+ } from 'quidproquo-core';
14
+
15
+ import {
16
+ RouteQPQWebServerConfigSetting,
17
+ HTTPEventParams,
18
+ qpqWebServerUtils,
19
+ } from 'quidproquo-webserver';
20
+
21
+ import { APIGatewayEvent, Context, APIGatewayProxyResult } from 'aws-lambda';
22
+
23
+ import { matchUrl } from '../../../awsLambdaUtils';
24
+
25
+ const getProcessTransformEventParams = (
26
+ appName: string,
27
+ ): EventTransformEventParamsActionProcessor<[APIGatewayEvent, Context], HTTPEventParams<any>> => {
28
+ return async ({ eventParams: [apiGatewayEvent, context] }) => {
29
+ const path = (apiGatewayEvent.path || '').replace(new RegExp(`^(\/${appName})/`), '/');
30
+ console.log('getProcessTransformEventParams', JSON.stringify(apiGatewayEvent));
31
+
32
+ return actionResult({
33
+ path,
34
+ query: {
35
+ ...(apiGatewayEvent.multiValueQueryStringParameters || {}),
36
+ ...(apiGatewayEvent.queryStringParameters || {}),
37
+ } as { [key: string]: undefined | string | string[] },
38
+ body: apiGatewayEvent.body ? JSON.parse(apiGatewayEvent.body) : undefined,
39
+ headers: apiGatewayEvent.headers,
40
+ method: apiGatewayEvent.httpMethod as 'GET' | 'POST',
41
+ correlation: context.awsRequestId,
42
+ sourceIp: apiGatewayEvent.requestContext.identity.sourceIp,
43
+ });
44
+ };
45
+ };
46
+
47
+ const getProcessTransformResponseResult = (
48
+ configs: QPQConfig,
49
+ ): EventTransformResponseResultActionProcessor<APIGatewayProxyResult> => {
50
+ // We might need to JSON.stringify the body.
51
+ return async (payload) => {
52
+ // Validate response
53
+ // if !valid actionResultError
54
+
55
+ console.log('getProcessTransformResponseResult', JSON.stringify(payload));
56
+
57
+ return actionResult<APIGatewayProxyResult>({
58
+ statusCode: payload.response.result.statusCode,
59
+ body: payload.response.result.body,
60
+ headers: {
61
+ 'Content-Type': 'application/json',
62
+ ...qpqWebServerUtils.getCorsHeaders(configs, {}, payload.transformedEventParams.headers),
63
+ ...(payload.response.headers || {}),
64
+ },
65
+ });
66
+ };
67
+ };
68
+
69
+ const getProcessAutoRespond = (
70
+ configs: QPQConfig,
71
+ ): EventAutoRespondActionProcessor<HTTPEventParams<any>> => {
72
+ return async (payload) => {
73
+ if (payload.transformedEventParams.method === 'OPTIONS') {
74
+ return actionResult({
75
+ result: {
76
+ statusCode: 200,
77
+ headers: qpqWebServerUtils.getCorsHeaders(
78
+ configs,
79
+ {},
80
+ payload.transformedEventParams.headers,
81
+ ),
82
+ },
83
+ });
84
+ }
85
+
86
+ return actionResult(null);
87
+ };
88
+ };
89
+
90
+ const getProcessMatchStory = (
91
+ routes: RouteQPQWebServerConfigSetting[],
92
+ ): EventMatchStoryActionProcessor<HTTPEventParams<any>> => {
93
+ return async (payload) => {
94
+ // Sort the routes by string length
95
+ // Note: We may need to filter variable routes out {} as the variables are length independent
96
+ const sortedRoutes = routes
97
+ .filter((r: any) => r.method === payload.transformedEventParams.method)
98
+ .sort((a: any, b: any) => {
99
+ if (a.path.length < b.path.length) return -1;
100
+ if (a.path.length > b.path.length) return 1;
101
+ return 0;
102
+ });
103
+
104
+ // Find the most relevant match
105
+ const matchedRoute = sortedRoutes
106
+ .map((r) => ({
107
+ match: matchUrl(r.path, payload.transformedEventParams.path),
108
+ route: r,
109
+ }))
110
+ .find((m) => m.match.didMatch);
111
+
112
+ if (!matchedRoute) {
113
+ return actionResultError(ErrorTypeEnum.NotFound, 'route not found');
114
+ }
115
+
116
+ return actionResult<MatchStoryResult>({
117
+ src: matchedRoute.route.src,
118
+ runtime: matchedRoute.route.runtime,
119
+ options: matchedRoute.match.params || {},
120
+ });
121
+ };
122
+ };
123
+
124
+ export default (config: QPQConfig) => {
125
+ const routes = qpqWebServerUtils.getAllRoutes(config);
126
+ const appName = qpqCoreUtils.getAppName(config);
127
+
128
+ return {
129
+ [EventActionType.TransformEventParams]: getProcessTransformEventParams(appName),
130
+ [EventActionType.TransformResponseResult]: getProcessTransformResponseResult(config),
131
+ [EventActionType.AutoRespond]: getProcessAutoRespond(config),
132
+ [EventActionType.MatchStory]: getProcessMatchStory(routes),
133
+ };
134
+ };