quidproquo-deploy-awscdk 0.0.32 → 0.0.34

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/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "quidproquo-deploy-awscdk",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
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/lambdas/*"
9
10
  ],
10
11
  "scripts": {
11
12
  "test": "echo \"Error: no test specified\" && exit 1",
@@ -0,0 +1,4 @@
1
+ export * from './lambdaConfig';
2
+
3
+ export * from './lambdaAPIGatewayEvent';
4
+ export * from './lambdaEventBridgeEvent';
@@ -0,0 +1,108 @@
1
+ import { coreActionProcessor, webserverActionProcessor } from 'quidproquo-actionprocessor-node';
2
+
3
+ import {
4
+ getAPIGatewayEventActionProcessor,
5
+ getSystemActionProcessor,
6
+ getFileActionProcessor,
7
+ getConfigGetSecretActionProcessor,
8
+ getConfigGetParameterActionProcessor,
9
+ getConfigGetParametersActionProcessor,
10
+ awsLambdaUtils,
11
+ DynamicModuleLoader,
12
+ } from 'quidproquo-actionprocessor-awslambda';
13
+
14
+ import { qpqWebServerUtils } from 'quidproquo-webserver';
15
+
16
+ import { createRuntime, askProcessEvent, ErrorTypeEnum } from 'quidproquo-core';
17
+
18
+ import { APIGatewayEvent, Context } from 'aws-lambda';
19
+
20
+ import { lambdaRuntimeConfig, ActionProcessorListResolver } from './lambdaConfig';
21
+
22
+ // @ts-ignore - Special webpack loader
23
+ import qpqDynamicModuleLoader from 'qpq-dynamic-loader!';
24
+
25
+ // TODO: Make this a util or something based on server time or something..
26
+ const getDateNow = () => new Date().toISOString();
27
+
28
+ const ErrorTypeHttpResponseMap = {
29
+ [ErrorTypeEnum.BadRequest]: 400,
30
+ [ErrorTypeEnum.Unauthorized]: 401,
31
+ [ErrorTypeEnum.PaymentRequired]: 402,
32
+ [ErrorTypeEnum.Forbidden]: 403,
33
+ [ErrorTypeEnum.NotFound]: 404,
34
+ [ErrorTypeEnum.TimeOut]: 408,
35
+ [ErrorTypeEnum.UnsupportedMediaType]: 415,
36
+ [ErrorTypeEnum.OutOfResources]: 500,
37
+ [ErrorTypeEnum.GenericError]: 500,
38
+ [ErrorTypeEnum.NotImplemented]: 501,
39
+ [ErrorTypeEnum.NoContent]: 204,
40
+ [ErrorTypeEnum.Invalid]: 422,
41
+ };
42
+
43
+ export const getAPIGatewayEventExecutor = (
44
+ dynamicModuleLoader: DynamicModuleLoader,
45
+ getCustomActionProcessors: ActionProcessorListResolver = () => ({}),
46
+ ) => {
47
+ return async (event: APIGatewayEvent, context: Context) => {
48
+ // Build a processor for the session and stuff
49
+ // Remove the non route ones ~ let the story execute action add them
50
+ const storyActionProcessor = {
51
+ ...coreActionProcessor,
52
+ ...webserverActionProcessor,
53
+
54
+ ...getAPIGatewayEventActionProcessor(lambdaRuntimeConfig.qpqConfig),
55
+ ...getConfigGetSecretActionProcessor(lambdaRuntimeConfig),
56
+ ...getConfigGetParameterActionProcessor(lambdaRuntimeConfig),
57
+ ...getConfigGetParametersActionProcessor(lambdaRuntimeConfig),
58
+ ...getSystemActionProcessor(dynamicModuleLoader),
59
+ ...getFileActionProcessor(lambdaRuntimeConfig),
60
+
61
+ ...getCustomActionProcessors(lambdaRuntimeConfig),
62
+ };
63
+
64
+ const logger = async (result: any) => {
65
+ // addResult(
66
+ // envConfig.appName,
67
+ // getDateNow(),
68
+ // doWeCarePath,
69
+ // "route-infrastructure",
70
+ // "infrastructure",
71
+ // "askRoute",
72
+ // result
73
+ // );
74
+ };
75
+
76
+ // // Run the callback
77
+
78
+ const resolveStory = createRuntime(
79
+ {},
80
+ storyActionProcessor,
81
+ getDateNow,
82
+ logger,
83
+ awsLambdaUtils.randomGuid,
84
+ );
85
+
86
+ const result = await resolveStory(askProcessEvent, [event, context]);
87
+
88
+ // Run the callback
89
+ if (!result.error) {
90
+ return {
91
+ statusCode: result.result.statusCode,
92
+ body: JSON.stringify(result.result.body),
93
+ headers: result.result.headers,
94
+ };
95
+ }
96
+
97
+ console.log(JSON.stringify(result));
98
+ const code = ErrorTypeHttpResponseMap[result.error.errorType];
99
+ return {
100
+ statusCode: code || 500,
101
+ body: JSON.stringify(result.error),
102
+ headers: qpqWebServerUtils.getCorsHeaders(lambdaRuntimeConfig.qpqConfig, {}, event.headers),
103
+ };
104
+ };
105
+ };
106
+
107
+ // Default executor
108
+ export const executeAPIGatewayEvent = getAPIGatewayEventExecutor(qpqDynamicModuleLoader);
@@ -0,0 +1,10 @@
1
+ import { ActionProcessorList } from 'quidproquo-core';
2
+ import { QPQAWSLambdaConfig } from 'quidproquo-actionprocessor-awslambda';
3
+
4
+ export const lambdaRuntimeConfig = JSON.parse(
5
+ process.env.lambdaRuntimeConfig || '{}',
6
+ ) as QPQAWSLambdaConfig;
7
+
8
+ export type ActionProcessorListResolver = (
9
+ lambdaRuntimeConfig: QPQAWSLambdaConfig,
10
+ ) => ActionProcessorList;
@@ -0,0 +1,61 @@
1
+ import { coreActionProcessor, webserverActionProcessor } from 'quidproquo-actionprocessor-node';
2
+
3
+ import {
4
+ getEventBridgeEventActionProcessor,
5
+ getSystemActionProcessor,
6
+ getFileActionProcessor,
7
+ getConfigGetSecretActionProcessor,
8
+ getConfigGetParameterActionProcessor,
9
+ getConfigGetParametersActionProcessor,
10
+ awsLambdaUtils,
11
+ DynamicModuleLoader,
12
+ } from 'quidproquo-actionprocessor-awslambda';
13
+ import { createRuntime, askProcessEvent } from 'quidproquo-core';
14
+
15
+ import { EventBridgeEvent, Context } from 'aws-lambda';
16
+
17
+ import { lambdaRuntimeConfig, ActionProcessorListResolver } from './lambdaConfig';
18
+
19
+ // @ts-ignore - Special webpack loader
20
+ import qpqDynamicModuleLoader from 'qpq-dynamic-loader!';
21
+
22
+ // TODO: Make this a util or something based on server time or something..
23
+ const getDateNow = () => new Date().toISOString();
24
+
25
+ export const getEventBridgeEventExecutor = (
26
+ dynamicModuleLoader: DynamicModuleLoader,
27
+ getCustomActionProcessors: ActionProcessorListResolver = () => ({}),
28
+ ) => {
29
+ return async (event: EventBridgeEvent<string, void>, context: Context) => {
30
+ // Build a processor for the session and stuff
31
+ // Remove the non event ones
32
+ const storyActionProcessor = {
33
+ ...coreActionProcessor,
34
+ ...webserverActionProcessor,
35
+
36
+ ...getEventBridgeEventActionProcessor(lambdaRuntimeConfig),
37
+ ...getSystemActionProcessor(dynamicModuleLoader),
38
+ ...getFileActionProcessor(lambdaRuntimeConfig),
39
+ ...getConfigGetSecretActionProcessor(lambdaRuntimeConfig),
40
+ ...getConfigGetParameterActionProcessor(lambdaRuntimeConfig),
41
+ ...getConfigGetParametersActionProcessor(lambdaRuntimeConfig),
42
+
43
+ ...getCustomActionProcessors(lambdaRuntimeConfig),
44
+ };
45
+
46
+ const logger = async (result: any) => {};
47
+
48
+ // Run the callback
49
+ const resolveStory = createRuntime(
50
+ {},
51
+ storyActionProcessor,
52
+ getDateNow,
53
+ logger,
54
+ awsLambdaUtils.randomGuid,
55
+ );
56
+
57
+ await resolveStory(askProcessEvent, [event, context]);
58
+ };
59
+ };
60
+
61
+ export const executeEventBridgeEvent = getEventBridgeEventExecutor(qpqDynamicModuleLoader);