quidproquo-actionprocessor-awslambda 0.0.35 → 0.0.36

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 (89) hide show
  1. package/package.json +1 -4
  2. package/src/awsLambdaUtils.ts +22 -0
  3. package/src/getActionProcessor/core/config/getConfigGetParameterActionProcessor.ts +23 -0
  4. package/src/getActionProcessor/core/config/getConfigGetParametersActionProcessor.ts +27 -0
  5. package/src/getActionProcessor/core/config/getConfigGetSecretActionProcessor.ts +23 -0
  6. package/src/getActionProcessor/core/config/index.ts +11 -0
  7. package/src/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.ts +134 -0
  8. package/src/getActionProcessor/core/event/getEventBridgeEventActionProcessor.ts +66 -0
  9. package/src/getActionProcessor/core/file/getFileDeleteActionProcessor.ts +31 -0
  10. package/src/getActionProcessor/core/file/getFileExistsActionProcessor.ts +16 -0
  11. package/src/getActionProcessor/core/file/getFileListDirectoryActionProcessor.ts +28 -0
  12. package/src/getActionProcessor/core/file/getFileReadTextContentsActionProcessor.ts +18 -0
  13. package/src/getActionProcessor/core/file/getFileWriteTextContentsActionProcessor.ts +23 -0
  14. package/src/getActionProcessor/core/file/index.ts +15 -0
  15. package/{lib/getActionProcessor/core/index.d.ts → src/getActionProcessor/core/index.ts} +0 -0
  16. package/src/getActionProcessor/core/system/getExecuteStoryActionProcessor.ts +67 -0
  17. package/src/getActionProcessor/core/system/index.ts +6 -0
  18. package/{lib/getActionProcessor/index.d.ts → src/getActionProcessor/index.ts} +0 -0
  19. package/{lib/index.d.ts → src/index.ts} +2 -0
  20. package/src/logic/parametersManager/getParameter.ts +13 -0
  21. package/src/logic/parametersManager/getParameters.ts +15 -0
  22. package/src/logic/s3/deleteFiles.ts +17 -0
  23. package/src/logic/s3/listFiles.ts +66 -0
  24. package/src/logic/s3/objectExists.ts +18 -0
  25. package/src/logic/s3/readTextFile.ts +14 -0
  26. package/{lib/logic/s3/s3Client.d.ts → src/logic/s3/s3Client.ts} +3 -1
  27. package/{lib/logic/s3/s3Utils.d.ts → src/logic/s3/s3Utils.ts} +0 -0
  28. package/src/logic/s3/writeTextFile.ts +17 -0
  29. package/src/logic/secretsManager/getSecret.ts +13 -0
  30. package/src/runtimeConfig/QPQAWSLambdaConfig.ts +15 -0
  31. package/src/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.ts +19 -0
  32. package/{lib/types/DynamicLoader.d.ts → src/types/DynamicLoader.ts} +0 -0
  33. package/tsconfig.json +8 -0
  34. package/lib/awsLambdaUtils.d.ts +0 -6
  35. package/lib/awsLambdaUtils.js +0 -19
  36. package/lib/getActionProcessor/core/config/getConfigGetParameterActionProcessor.d.ts +0 -6
  37. package/lib/getActionProcessor/core/config/getConfigGetParameterActionProcessor.js +0 -26
  38. package/lib/getActionProcessor/core/config/getConfigGetParametersActionProcessor.d.ts +0 -6
  39. package/lib/getActionProcessor/core/config/getConfigGetParametersActionProcessor.js +0 -26
  40. package/lib/getActionProcessor/core/config/getConfigGetSecretActionProcessor.d.ts +0 -6
  41. package/lib/getActionProcessor/core/config/getConfigGetSecretActionProcessor.js +0 -26
  42. package/lib/getActionProcessor/core/config/index.d.ts +0 -7
  43. package/lib/getActionProcessor/core/config/index.js +0 -9
  44. package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.d.ts +0 -10
  45. package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.js +0 -95
  46. package/lib/getActionProcessor/core/event/getEventBridgeEventActionProcessor.d.ts +0 -10
  47. package/lib/getActionProcessor/core/event/getEventBridgeEventActionProcessor.js +0 -51
  48. package/lib/getActionProcessor/core/file/getFileDeleteActionProcessor.d.ts +0 -6
  49. package/lib/getActionProcessor/core/file/getFileDeleteActionProcessor.js +0 -31
  50. package/lib/getActionProcessor/core/file/getFileExistsActionProcessor.d.ts +0 -6
  51. package/lib/getActionProcessor/core/file/getFileExistsActionProcessor.js +0 -23
  52. package/lib/getActionProcessor/core/file/getFileListDirectoryActionProcessor.d.ts +0 -6
  53. package/lib/getActionProcessor/core/file/getFileListDirectoryActionProcessor.js +0 -29
  54. package/lib/getActionProcessor/core/file/getFileReadTextContentsActionProcessor.d.ts +0 -6
  55. package/lib/getActionProcessor/core/file/getFileReadTextContentsActionProcessor.js +0 -23
  56. package/lib/getActionProcessor/core/file/getFileWriteTextContentsActionProcessor.d.ts +0 -6
  57. package/lib/getActionProcessor/core/file/getFileWriteTextContentsActionProcessor.js +0 -24
  58. package/lib/getActionProcessor/core/file/index.d.ts +0 -9
  59. package/lib/getActionProcessor/core/file/index.js +0 -11
  60. package/lib/getActionProcessor/core/index.js +0 -20
  61. package/lib/getActionProcessor/core/system/getExecuteStoryActionProcessor.d.ts +0 -7
  62. package/lib/getActionProcessor/core/system/getExecuteStoryActionProcessor.js +0 -45
  63. package/lib/getActionProcessor/core/system/index.d.ts +0 -5
  64. package/lib/getActionProcessor/core/system/index.js +0 -7
  65. package/lib/getActionProcessor/index.js +0 -17
  66. package/lib/index.js +0 -33
  67. package/lib/logic/parametersManager/getParameter.d.ts +0 -1
  68. package/lib/logic/parametersManager/getParameter.js +0 -22
  69. package/lib/logic/parametersManager/getParameters.d.ts +0 -1
  70. package/lib/logic/parametersManager/getParameters.js +0 -22
  71. package/lib/logic/s3/deleteFiles.d.ts +0 -1
  72. package/lib/logic/s3/deleteFiles.js +0 -29
  73. package/lib/logic/s3/listFiles.d.ts +0 -10
  74. package/lib/logic/s3/listFiles.js +0 -56
  75. package/lib/logic/s3/objectExists.d.ts +0 -1
  76. package/lib/logic/s3/objectExists.js +0 -30
  77. package/lib/logic/s3/readTextFile.d.ts +0 -1
  78. package/lib/logic/s3/readTextFile.js +0 -26
  79. package/lib/logic/s3/s3Client.js +0 -5
  80. package/lib/logic/s3/s3Utils.js +0 -21
  81. package/lib/logic/s3/writeTextFile.d.ts +0 -1
  82. package/lib/logic/s3/writeTextFile.js +0 -25
  83. package/lib/logic/secretsManager/getSecret.d.ts +0 -1
  84. package/lib/logic/secretsManager/getSecret.js +0 -21
  85. package/lib/runtimeConfig/QPQAWSLambdaConfig.d.ts +0 -12
  86. package/lib/runtimeConfig/QPQAWSLambdaConfig.js +0 -2
  87. package/lib/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.d.ts +0 -4
  88. package/lib/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.js +0 -15
  89. package/lib/types/DynamicLoader.js +0 -2
@@ -0,0 +1,18 @@
1
+ import { HeadObjectCommand } from '@aws-sdk/client-s3';
2
+
3
+ import s3Client from './s3Client';
4
+
5
+ export const objectExists = async (bucketName: string, key: string): Promise<boolean> => {
6
+ try {
7
+ const response = await s3Client.send(
8
+ new HeadObjectCommand({
9
+ Key: key,
10
+ Bucket: bucketName,
11
+ }),
12
+ );
13
+
14
+ return true;
15
+ } catch {
16
+ return false;
17
+ }
18
+ };
@@ -0,0 +1,14 @@
1
+ import { GetObjectCommand } from '@aws-sdk/client-s3';
2
+
3
+ import s3Client from './s3Client';
4
+
5
+ export const readTextFile = async (bucketName: string, key: string): Promise<string> => {
6
+ const response = await s3Client.send(
7
+ new GetObjectCommand({
8
+ Key: key,
9
+ Bucket: bucketName,
10
+ }),
11
+ );
12
+
13
+ return (await response.Body?.transformToString()) || '';
14
+ };
@@ -1,3 +1,5 @@
1
1
  import { S3Client } from '@aws-sdk/client-s3';
2
- declare const s3Client: S3Client;
2
+
3
+ const s3Client = new S3Client({ region: 'ap-southeast-2' });
4
+
3
5
  export default s3Client;
@@ -0,0 +1,17 @@
1
+ import { PutObjectCommand } from '@aws-sdk/client-s3';
2
+
3
+ import s3Client from './s3Client';
4
+
5
+ export const writeTextFile = async (
6
+ bucketName: string,
7
+ key: string,
8
+ data: string,
9
+ ): Promise<void> => {
10
+ await s3Client.send(
11
+ new PutObjectCommand({
12
+ Key: key,
13
+ Bucket: bucketName,
14
+ Body: Buffer.from(data),
15
+ }),
16
+ );
17
+ };
@@ -0,0 +1,13 @@
1
+ import { SecretsManagerClient, GetSecretValueCommand } from '@aws-sdk/client-secrets-manager';
2
+
3
+ const smClient = new SecretsManagerClient({});
4
+
5
+ export const getSecret = async (secretName: string): Promise<string> => {
6
+ const response = await smClient.send(
7
+ new GetSecretValueCommand({
8
+ SecretId: secretName,
9
+ }),
10
+ );
11
+
12
+ return response.SecretString || '';
13
+ };
@@ -0,0 +1,15 @@
1
+ import { QPQConfig } from 'quidproquo-core';
2
+ export interface LambdaRuntimeConfig {
3
+ src: string;
4
+ runtime: string;
5
+ }
6
+
7
+ export interface QPQAWSLambdaConfig {
8
+ qpqConfig: QPQConfig;
9
+
10
+ resourceNameMap: Record<string, string>;
11
+ secretNameMap: Record<string, string>;
12
+ parameterNameMap: Record<string, string>;
13
+
14
+ lambdaRuntimeConfig?: LambdaRuntimeConfig;
15
+ }
@@ -0,0 +1,19 @@
1
+ import { QPQAWSLambdaConfig } from './QPQAWSLambdaConfig';
2
+
3
+ export const resolveResourceName = (
4
+ resourceName: string,
5
+ qpqAwsLambdaConfig: QPQAWSLambdaConfig,
6
+ ) => {
7
+ return qpqAwsLambdaConfig.resourceNameMap[resourceName] || resourceName;
8
+ };
9
+
10
+ export const resolveSecretKey = (secretName: string, qpqAwsLambdaConfig: QPQAWSLambdaConfig) => {
11
+ return qpqAwsLambdaConfig.secretNameMap[secretName] || secretName;
12
+ };
13
+
14
+ export const resolveParameterKey = (
15
+ parameterName: string,
16
+ qpqAwsLambdaConfig: QPQAWSLambdaConfig,
17
+ ) => {
18
+ return qpqAwsLambdaConfig.parameterNameMap[parameterName] || parameterName;
19
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "quidproquo-tsconfig",
3
+ "compilerOptions": {
4
+ "outDir": "./lib"
5
+ },
6
+ "include": ["src"],
7
+ "exclude": ["node_modules"]
8
+ }
@@ -1,6 +0,0 @@
1
- export declare const randomGuid: () => string;
2
- export interface UrlMatch {
3
- didMatch: boolean;
4
- params: Record<string, string> | null;
5
- }
6
- export declare const matchUrl: (path: string, url: string) => UrlMatch;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.matchUrl = exports.randomGuid = void 0;
4
- const crypto_1 = require("crypto");
5
- const node_match_path_1 = require("node-match-path");
6
- const randomGuid = () => {
7
- return (0, crypto_1.randomUUID)();
8
- };
9
- exports.randomGuid = randomGuid;
10
- const matchUrl = (path, url) => {
11
- // /attempt/{attemptUuid}/result/{test} => /attempt/:attemptUuid/result/:test
12
- const modifiedPath = path.replaceAll(/{(.+?)}/g, (m, g) => `:${g}`);
13
- const matchResult = (0, node_match_path_1.match)(modifiedPath, url);
14
- return {
15
- didMatch: matchResult.matches,
16
- params: matchResult.params,
17
- };
18
- };
19
- exports.matchUrl = matchUrl;
@@ -1,6 +0,0 @@
1
- import { ConfigGetParameterActionProcessor } from 'quidproquo-core';
2
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
3
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
4
- "@quidproquo-core/Config/GetParameter": ConfigGetParameterActionProcessor;
5
- };
6
- export default _default;
@@ -1,26 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
14
- const getParameter_1 = require("../../../logic/parametersManager/getParameter");
15
- const getProcessConfigGetParameter = (runtimeConfig) => {
16
- return ({ parameterName }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const awsParameterKey = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveParameterKey)(parameterName, runtimeConfig);
18
- const parameterValue = yield (0, getParameter_1.getParameter)(awsParameterKey);
19
- return (0, quidproquo_core_1.actionResult)(parameterValue);
20
- });
21
- };
22
- exports.default = (runtimeConfig) => {
23
- return {
24
- [quidproquo_core_1.ConfigActionType.GetParameter]: getProcessConfigGetParameter(runtimeConfig),
25
- };
26
- };
@@ -1,6 +0,0 @@
1
- import { ConfigGetParametersActionProcessor } from 'quidproquo-core';
2
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
3
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
4
- "@quidproquo-core/Config/GetParameters": ConfigGetParametersActionProcessor;
5
- };
6
- export default _default;
@@ -1,26 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
14
- const getParameters_1 = require("../../../logic/parametersManager/getParameters");
15
- const getProcessConfigGetParameters = (runtimeConfig) => {
16
- return ({ parameterNames }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const awsParameterKeys = parameterNames.map((pn) => (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveParameterKey)(pn, runtimeConfig));
18
- const parameterValues = yield (0, getParameters_1.getParameters)(awsParameterKeys);
19
- return (0, quidproquo_core_1.actionResult)(parameterValues);
20
- });
21
- };
22
- exports.default = (runtimeConfig) => {
23
- return {
24
- [quidproquo_core_1.ConfigActionType.GetParameters]: getProcessConfigGetParameters(runtimeConfig),
25
- };
26
- };
@@ -1,6 +0,0 @@
1
- import { ConfigGetSecretActionProcessor } from 'quidproquo-core';
2
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
3
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
4
- "@quidproquo-core/Config/GetSecret": ConfigGetSecretActionProcessor;
5
- };
6
- export default _default;
@@ -1,26 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
14
- const getSecret_1 = require("../../../logic/secretsManager/getSecret");
15
- const getProcessConfigActionType = (runtimeConfig) => {
16
- return ({ secretName }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const awsSecretKey = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveSecretKey)(secretName, runtimeConfig);
18
- const secretValue = yield (0, getSecret_1.getSecret)(awsSecretKey);
19
- return (0, quidproquo_core_1.actionResult)(secretValue);
20
- });
21
- };
22
- exports.default = (runtimeConfig) => {
23
- return {
24
- [quidproquo_core_1.ConfigActionType.GetSecret]: getProcessConfigActionType(runtimeConfig),
25
- };
26
- };
@@ -1,7 +0,0 @@
1
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
3
- "@quidproquo-core/Config/GetSecret": import("quidproquo-core/lib").ConfigGetSecretActionProcessor;
4
- "@quidproquo-core/Config/GetParameters": import("quidproquo-core/lib").ConfigGetParametersActionProcessor;
5
- "@quidproquo-core/Config/GetParameter": import("quidproquo-core/lib").ConfigGetParameterActionProcessor;
6
- };
7
- export default _default;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const getConfigGetParameterActionProcessor_1 = __importDefault(require("./getConfigGetParameterActionProcessor"));
7
- const getConfigGetParametersActionProcessor_1 = __importDefault(require("./getConfigGetParametersActionProcessor"));
8
- const getConfigGetSecretActionProcessor_1 = __importDefault(require("./getConfigGetSecretActionProcessor"));
9
- exports.default = (runtimeConfig) => (Object.assign(Object.assign(Object.assign({}, (0, getConfigGetParameterActionProcessor_1.default)(runtimeConfig)), (0, getConfigGetParametersActionProcessor_1.default)(runtimeConfig)), (0, getConfigGetSecretActionProcessor_1.default)(runtimeConfig)));
@@ -1,10 +0,0 @@
1
- import { QPQConfig, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor } from 'quidproquo-core';
2
- import { HTTPEventParams } from 'quidproquo-webserver';
3
- import { Context, APIGatewayProxyResult } from 'aws-lambda';
4
- declare const _default: (config: QPQConfig) => {
5
- "@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[import("aws-lambda").APIGatewayProxyEvent, Context], HTTPEventParams<any>>;
6
- "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<APIGatewayProxyResult>;
7
- "@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<HTTPEventParams<any>>;
8
- "@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<HTTPEventParams<any>>;
9
- };
10
- export default _default;
@@ -1,95 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const quidproquo_core_1 = require("quidproquo-core");
13
- const quidproquo_webserver_1 = require("quidproquo-webserver");
14
- const awsLambdaUtils_1 = require("../../../awsLambdaUtils");
15
- const getProcessTransformEventParams = (appName) => {
16
- return ({ eventParams: [apiGatewayEvent, context] }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const path = (apiGatewayEvent.path || '').replace(new RegExp(`^(\/${appName})/`), '/');
18
- console.log('getProcessTransformEventParams', JSON.stringify(apiGatewayEvent));
19
- return (0, quidproquo_core_1.actionResult)({
20
- path,
21
- query: Object.assign(Object.assign({}, (apiGatewayEvent.multiValueQueryStringParameters || {})), (apiGatewayEvent.queryStringParameters || {})),
22
- body: apiGatewayEvent.body ? JSON.parse(apiGatewayEvent.body) : undefined,
23
- headers: apiGatewayEvent.headers,
24
- method: apiGatewayEvent.httpMethod,
25
- correlation: context.awsRequestId,
26
- sourceIp: apiGatewayEvent.requestContext.identity.sourceIp,
27
- });
28
- });
29
- };
30
- const getProcessTransformResponseResult = (configs) => {
31
- // We might need to JSON.stringify the body.
32
- return (payload) => __awaiter(void 0, void 0, void 0, function* () {
33
- // Validate response
34
- // if !valid actionResultError
35
- console.log('getProcessTransformResponseResult', JSON.stringify(payload));
36
- return (0, quidproquo_core_1.actionResult)({
37
- statusCode: payload.response.result.statusCode,
38
- body: payload.response.result.body,
39
- headers: Object.assign(Object.assign({ 'Content-Type': 'application/json' }, quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(configs, {}, payload.transformedEventParams.headers)), (payload.response.headers || {})),
40
- });
41
- });
42
- };
43
- const getProcessAutoRespond = (configs) => {
44
- return (payload) => __awaiter(void 0, void 0, void 0, function* () {
45
- if (payload.transformedEventParams.method === 'OPTIONS') {
46
- return (0, quidproquo_core_1.actionResult)({
47
- result: {
48
- statusCode: 200,
49
- headers: quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(configs, {}, payload.transformedEventParams.headers),
50
- },
51
- });
52
- }
53
- return (0, quidproquo_core_1.actionResult)(null);
54
- });
55
- };
56
- const getProcessMatchStory = (routes) => {
57
- return (payload) => __awaiter(void 0, void 0, void 0, function* () {
58
- // Sort the routes by string length
59
- // Note: We may need to filter variable routes out {} as the variables are length independent
60
- const sortedRoutes = routes
61
- .filter((r) => r.method === payload.transformedEventParams.method)
62
- .sort((a, b) => {
63
- if (a.path.length < b.path.length)
64
- return -1;
65
- if (a.path.length > b.path.length)
66
- return 1;
67
- return 0;
68
- });
69
- // Find the most relevant match
70
- const matchedRoute = sortedRoutes
71
- .map((r) => ({
72
- match: (0, awsLambdaUtils_1.matchUrl)(r.path, payload.transformedEventParams.path),
73
- route: r,
74
- }))
75
- .find((m) => m.match.didMatch);
76
- if (!matchedRoute) {
77
- return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, 'route not found');
78
- }
79
- return (0, quidproquo_core_1.actionResult)({
80
- src: matchedRoute.route.src,
81
- runtime: matchedRoute.route.runtime,
82
- options: matchedRoute.match.params || {},
83
- });
84
- });
85
- };
86
- exports.default = (config) => {
87
- const routes = quidproquo_webserver_1.qpqWebServerUtils.getAllRoutes(config);
88
- const appName = quidproquo_core_1.qpqCoreUtils.getAppName(config);
89
- return {
90
- [quidproquo_core_1.EventActionType.TransformEventParams]: getProcessTransformEventParams(appName),
91
- [quidproquo_core_1.EventActionType.TransformResponseResult]: getProcessTransformResponseResult(config),
92
- [quidproquo_core_1.EventActionType.AutoRespond]: getProcessAutoRespond(config),
93
- [quidproquo_core_1.EventActionType.MatchStory]: getProcessMatchStory(routes),
94
- };
95
- };
@@ -1,10 +0,0 @@
1
- import { EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor, ScheduledEventParams } from 'quidproquo-core';
2
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
3
- import { EventBridgeEvent, Context } from 'aws-lambda';
4
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
5
- "@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[EventBridgeEvent<any, any>, Context], ScheduledEventParams<any>>;
6
- "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<any>;
7
- "@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<ScheduledEventParams<any>>;
8
- "@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<ScheduledEventParams<any>>;
9
- };
10
- export default _default;
@@ -1,51 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const quidproquo_core_1 = require("quidproquo-core");
13
- const getProcessTransformEventParams = () => {
14
- return ({ eventParams: [eventBridgeEvent, context] }) => __awaiter(void 0, void 0, void 0, function* () {
15
- return (0, quidproquo_core_1.actionResult)({
16
- time: eventBridgeEvent.time,
17
- correlation: context.awsRequestId,
18
- detail: eventBridgeEvent.detail,
19
- });
20
- });
21
- };
22
- // No transform
23
- const getProcessTransformResponseResult = () => {
24
- return ({ response }) => __awaiter(void 0, void 0, void 0, function* () { return (0, quidproquo_core_1.actionResult)(response); });
25
- };
26
- // never early exit (maybe add validation?)
27
- const getProcessAutoRespond = () => {
28
- return () => __awaiter(void 0, void 0, void 0, function* () { return (0, quidproquo_core_1.actionResult)(null); });
29
- };
30
- const getProcessMatchStory = (lambdaRuntimeConfig) => {
31
- return (payload) => __awaiter(void 0, void 0, void 0, function* () {
32
- console.log('Trying to match story');
33
- console.log(JSON.stringify(lambdaRuntimeConfig));
34
- if (!lambdaRuntimeConfig) {
35
- return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, 'event runtime not found');
36
- }
37
- return (0, quidproquo_core_1.actionResult)({
38
- src: lambdaRuntimeConfig.src,
39
- runtime: lambdaRuntimeConfig.runtime,
40
- options: {},
41
- });
42
- });
43
- };
44
- exports.default = (runtimeConfig) => {
45
- return {
46
- [quidproquo_core_1.EventActionType.TransformEventParams]: getProcessTransformEventParams(),
47
- [quidproquo_core_1.EventActionType.TransformResponseResult]: getProcessTransformResponseResult(),
48
- [quidproquo_core_1.EventActionType.AutoRespond]: getProcessAutoRespond(),
49
- [quidproquo_core_1.EventActionType.MatchStory]: getProcessMatchStory(runtimeConfig.lambdaRuntimeConfig),
50
- };
51
- };
@@ -1,6 +0,0 @@
1
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
- import { FileDeleteActionProcessor } from 'quidproquo-core';
3
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
4
- "@quidproquo-core/File/Delete": FileDeleteActionProcessor;
5
- };
6
- export default _default;
@@ -1,31 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
- const quidproquo_core_1 = require("quidproquo-core");
14
- const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
- const getProcessFileDelete = (runtimeConfig) => {
16
- return ({ drive, filepaths }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, runtimeConfig);
18
- const errored = yield (0, s3Utils_1.deleteFiles)(s3BucketName, filepaths);
19
- // errored deletes are a graceful success ~ Retry
20
- // if (errored.length > 0) {
21
- // return actionResultError(
22
- // ErrorTypeEnum.GenericError,
23
- // `Could not delete files ${errored.length}`,
24
- // );
25
- // }
26
- return (0, quidproquo_core_1.actionResult)(errored);
27
- });
28
- };
29
- exports.default = (runtimeConfig) => ({
30
- [quidproquo_core_1.FileActionType.Delete]: getProcessFileDelete(runtimeConfig),
31
- });
@@ -1,6 +0,0 @@
1
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
- import { FileExistsActionProcessor } from 'quidproquo-core';
3
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
4
- "@quidproquo-core/File/Exists": FileExistsActionProcessor;
5
- };
6
- export default _default;
@@ -1,23 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
- const quidproquo_core_1 = require("quidproquo-core");
14
- const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
- const getProcessFileExists = (runtimeConfig) => {
16
- return ({ drive, filepath }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, runtimeConfig);
18
- return (0, quidproquo_core_1.actionResult)(yield (0, s3Utils_1.objectExists)(s3BucketName, filepath));
19
- });
20
- };
21
- exports.default = (runtimeConfig) => ({
22
- [quidproquo_core_1.FileActionType.Exists]: getProcessFileExists(runtimeConfig),
23
- });
@@ -1,6 +0,0 @@
1
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
- import { FileListDirectoryActionProcessor } from 'quidproquo-core';
3
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
4
- "@quidproquo-core/File/ListDirectory": FileListDirectoryActionProcessor;
5
- };
6
- export default _default;
@@ -1,29 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
- const quidproquo_core_1 = require("quidproquo-core");
14
- const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
- const getProcessFileListDirectory = (runtimeConfig) => {
16
- return ({ drive, folderPath, maxFiles, pageToken }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, runtimeConfig);
18
- const s3FileList = yield (0, s3Utils_1.listFiles)(s3BucketName, folderPath, maxFiles, pageToken);
19
- // Add the drive onto the list
20
- const fileInfos = s3FileList.fileInfos.map((s3fi) => (Object.assign(Object.assign({}, s3fi), { drive: drive })));
21
- return (0, quidproquo_core_1.actionResult)({
22
- fileInfos,
23
- pageToken: s3FileList.pageToken,
24
- });
25
- });
26
- };
27
- exports.default = (runtimeConfig) => ({
28
- [quidproquo_core_1.FileActionType.ListDirectory]: getProcessFileListDirectory(runtimeConfig),
29
- });
@@ -1,6 +0,0 @@
1
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
- import { FileReadTextContentsActionProcessor } from 'quidproquo-core';
3
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
4
- "@quidproquo-core/File/ReadTextContents": FileReadTextContentsActionProcessor;
5
- };
6
- export default _default;
@@ -1,23 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
- const quidproquo_core_1 = require("quidproquo-core");
14
- const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
- const getProcessFileReadTextContents = (runtimeConfig) => {
16
- return ({ drive, filepath }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, runtimeConfig);
18
- return (0, quidproquo_core_1.actionResult)(yield (0, s3Utils_1.readTextFile)(s3BucketName, filepath));
19
- });
20
- };
21
- exports.default = (runtimeConfig) => ({
22
- [quidproquo_core_1.FileActionType.ReadTextContents]: getProcessFileReadTextContents(runtimeConfig),
23
- });
@@ -1,6 +0,0 @@
1
- import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
- import { FileWriteTextContentsActionProcessor } from 'quidproquo-core';
3
- declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
4
- "@quidproquo-core/File/WriteTextContents": FileWriteTextContentsActionProcessor;
5
- };
6
- export default _default;
@@ -1,24 +0,0 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
- const quidproquo_core_1 = require("quidproquo-core");
14
- const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
- const getProcessFileWriteTextContents = (runtimeConfig) => {
16
- return ({ drive, filepath, data }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, runtimeConfig);
18
- yield (0, s3Utils_1.writeTextFile)(s3BucketName, filepath, data);
19
- return (0, quidproquo_core_1.actionResult)(void 0);
20
- });
21
- };
22
- exports.default = (runtimeConfig) => ({
23
- [quidproquo_core_1.FileActionType.WriteTextContents]: getProcessFileWriteTextContents(runtimeConfig),
24
- });