quidproquo-actionprocessor-awslambda 0.0.43 → 0.0.44

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.
@@ -10,12 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
+ const quidproquo_webserver_1 = require("quidproquo-webserver");
13
14
  const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
14
15
  const getParameter_1 = require("../../../logic/parametersManager/getParameter");
15
16
  const getProcessConfigGetParameter = (runtimeConfig) => {
16
17
  return ({ parameterName }) => __awaiter(void 0, void 0, void 0, function* () {
17
18
  const awsParameterKey = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveParameterKey)(parameterName, runtimeConfig);
18
- const parameterValue = yield (0, getParameter_1.getParameter)(awsParameterKey);
19
+ const parameterValue = yield (0, getParameter_1.getParameter)(awsParameterKey, quidproquo_webserver_1.qpqWebServerUtils.getDeployRegion(runtimeConfig.qpqConfig));
19
20
  return (0, quidproquo_core_1.actionResult)(parameterValue);
20
21
  });
21
22
  };
@@ -10,12 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
+ const quidproquo_webserver_1 = require("quidproquo-webserver");
13
14
  const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
14
15
  const getParameters_1 = require("../../../logic/parametersManager/getParameters");
15
16
  const getProcessConfigGetParameters = (runtimeConfig) => {
16
17
  return ({ parameterNames }) => __awaiter(void 0, void 0, void 0, function* () {
17
18
  const awsParameterKeys = parameterNames.map((pn) => (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveParameterKey)(pn, runtimeConfig));
18
- const parameterValues = yield (0, getParameters_1.getParameters)(awsParameterKeys);
19
+ const parameterValues = yield (0, getParameters_1.getParameters)(awsParameterKeys, quidproquo_webserver_1.qpqWebServerUtils.getDeployRegion(runtimeConfig.qpqConfig));
19
20
  return (0, quidproquo_core_1.actionResult)(parameterValues);
20
21
  });
21
22
  };
@@ -3,7 +3,7 @@ import { HTTPEventParams } from 'quidproquo-webserver';
3
3
  import { Context, APIGatewayProxyResult } from 'aws-lambda';
4
4
  declare const _default: (config: QPQConfig) => {
5
5
  "@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[import("aws-lambda").APIGatewayProxyEvent, Context], HTTPEventParams<any>>;
6
- "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<APIGatewayProxyResult>;
6
+ "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<any, any, APIGatewayProxyResult>;
7
7
  "@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<HTTPEventParams<any>>;
8
8
  "@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<HTTPEventParams<any>>;
9
9
  };
@@ -15,7 +15,6 @@ const awsLambdaUtils_1 = require("../../../awsLambdaUtils");
15
15
  const getProcessTransformEventParams = (appName) => {
16
16
  return ({ eventParams: [apiGatewayEvent, context] }) => __awaiter(void 0, void 0, void 0, function* () {
17
17
  const path = (apiGatewayEvent.path || '').replace(new RegExp(`^(\/${appName})/`), '/');
18
- console.log('getProcessTransformEventParams', JSON.stringify(apiGatewayEvent));
19
18
  return (0, quidproquo_core_1.actionResult)({
20
19
  path,
21
20
  query: Object.assign(Object.assign({}, (apiGatewayEvent.multiValueQueryStringParameters || {})), (apiGatewayEvent.queryStringParameters || {})),
@@ -30,13 +29,11 @@ const getProcessTransformEventParams = (appName) => {
30
29
  const getProcessTransformResponseResult = (configs) => {
31
30
  // We might need to JSON.stringify the body.
32
31
  return (payload) => __awaiter(void 0, void 0, void 0, function* () {
33
- // Validate response
34
- // if !valid actionResultError
35
- console.log('getProcessTransformResponseResult', JSON.stringify(payload));
32
+ var _a;
36
33
  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 || {})),
34
+ statusCode: payload.response.statusCode,
35
+ body: payload.response.body,
36
+ headers: Object.assign(Object.assign({ 'Content-Type': 'application/json' }, quidproquo_webserver_1.qpqWebServerUtils.getCorsHeaders(configs, {}, payload.transformedEventParams.headers)), (((_a = payload === null || payload === void 0 ? void 0 : payload.response) === null || _a === void 0 ? void 0 : _a.headers) || {})),
40
37
  });
41
38
  });
42
39
  };
@@ -0,0 +1,10 @@
1
+ import { QPQConfig, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor } from 'quidproquo-core';
2
+ import { SeoEventParams, SeoEventResponse } from 'quidproquo-webserver';
3
+ import { CloudFrontRequestEvent, Context } from 'aws-lambda';
4
+ declare const _default: (config: QPQConfig) => {
5
+ "@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[CloudFrontRequestEvent, Context], SeoEventParams<any>>;
6
+ "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<SeoEventResponse, SeoEventParams<any>, SeoEventResponse>;
7
+ "@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<SeoEventParams<any>>;
8
+ "@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<SeoEventParams<any>>;
9
+ };
10
+ export default _default;
@@ -0,0 +1,77 @@
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 = () => {
16
+ return ({ eventParams: [cloudFrontRequestEvent, context] }) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const cfRecordRequest = cloudFrontRequestEvent.Records[0].cf.request;
18
+ const headers = Object.keys(cfRecordRequest.headers).reduce((acc, header) => (Object.assign(Object.assign({}, acc), { [header]: cfRecordRequest.headers[header][0].value })), {});
19
+ return (0, quidproquo_core_1.actionResult)({
20
+ body: cfRecordRequest.body,
21
+ correlation: context.awsRequestId,
22
+ method: cfRecordRequest.method,
23
+ path: cfRecordRequest.uri,
24
+ sourceIp: cfRecordRequest.clientIp,
25
+ headers: headers,
26
+ // TODO: query string support
27
+ query: {},
28
+ });
29
+ });
30
+ };
31
+ const getProcessTransformResponseResult = (configs) => {
32
+ return ({ response }) => __awaiter(void 0, void 0, void 0, function* () {
33
+ return (0, quidproquo_core_1.actionResult)(response);
34
+ });
35
+ };
36
+ const getProcessAutoRespond = () => {
37
+ return (payload) => __awaiter(void 0, void 0, void 0, function* () {
38
+ return (0, quidproquo_core_1.actionResult)(null);
39
+ });
40
+ };
41
+ const getProcessMatchStory = (seoConfigs) => {
42
+ return (payload) => __awaiter(void 0, void 0, void 0, function* () {
43
+ /// Sort the routes by string length
44
+ // Note: We may need to filter variable routes out {} as the variables are length independent
45
+ const sortedSeoConfigs = seoConfigs.sort((a, b) => {
46
+ if (a.path.length < b.path.length)
47
+ return -1;
48
+ if (a.path.length > b.path.length)
49
+ return 1;
50
+ return 0;
51
+ });
52
+ // Find the most relevant match
53
+ const matchedSeoConfig = sortedSeoConfigs
54
+ .map((r) => ({
55
+ match: (0, awsLambdaUtils_1.matchUrl)(r.path, payload.transformedEventParams.path),
56
+ route: r,
57
+ }))
58
+ .find((m) => m.match.didMatch);
59
+ if (!matchedSeoConfig) {
60
+ return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, 'seo not found');
61
+ }
62
+ return (0, quidproquo_core_1.actionResult)({
63
+ src: matchedSeoConfig.route.src,
64
+ runtime: matchedSeoConfig.route.runtime,
65
+ options: matchedSeoConfig.match.params || {},
66
+ });
67
+ });
68
+ };
69
+ exports.default = (config) => {
70
+ const seoConfigs = quidproquo_webserver_1.qpqWebServerUtils.getAllSeo(config);
71
+ return {
72
+ [quidproquo_core_1.EventActionType.TransformEventParams]: getProcessTransformEventParams(),
73
+ [quidproquo_core_1.EventActionType.TransformResponseResult]: getProcessTransformResponseResult(config),
74
+ [quidproquo_core_1.EventActionType.AutoRespond]: getProcessAutoRespond(),
75
+ [quidproquo_core_1.EventActionType.MatchStory]: getProcessMatchStory(seoConfigs),
76
+ };
77
+ };
@@ -3,7 +3,7 @@ import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
3
3
  import { EventBridgeEvent, Context } from 'aws-lambda';
4
4
  declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
5
5
  "@quidproquo-core/event/TransformEventParams": EventTransformEventParamsActionProcessor<[EventBridgeEvent<any, any>, Context], ScheduledEventParams<any>>;
6
- "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<any>;
6
+ "@quidproquo-core/event/TransformResponseResult": EventTransformResponseResultActionProcessor<any, any, any>;
7
7
  "@quidproquo-core/event/AutoRespond": EventAutoRespondActionProcessor<ScheduledEventParams<any>>;
8
8
  "@quidproquo-core/event/MatchStory": EventMatchStoryActionProcessor<ScheduledEventParams<any>>;
9
9
  };
@@ -29,8 +29,6 @@ const getProcessAutoRespond = () => {
29
29
  };
30
30
  const getProcessMatchStory = (lambdaRuntimeConfig) => {
31
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
32
  if (!lambdaRuntimeConfig) {
35
33
  return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, 'event runtime not found');
36
34
  }
@@ -2,6 +2,7 @@ export { default as getConfigGetSecretActionProcessor } from './config/getConfig
2
2
  export { default as getConfigGetParameterActionProcessor } from './config/getConfigGetParameterActionProcessor';
3
3
  export { default as getConfigGetParametersActionProcessor } from './config/getConfigGetParametersActionProcessor';
4
4
  export { default as getAPIGatewayEventActionProcessor } from './event/getAPIGatewayEventActionProcessor';
5
+ export { default as getCloudFrontOriginRequestEventActionProcessor } from './event/getCloudFrontOriginRequestEventActionProcessor';
5
6
  export { default as getEventBridgeEventActionProcessor } from './event/getEventBridgeEventActionProcessor';
6
7
  export { default as getSystemActionProcessor } from './system';
7
8
  export { default as getFileActionProcessor } from './file';
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getFileActionProcessor = exports.getSystemActionProcessor = exports.getEventBridgeEventActionProcessor = exports.getAPIGatewayEventActionProcessor = exports.getConfigGetParametersActionProcessor = exports.getConfigGetParameterActionProcessor = exports.getConfigGetSecretActionProcessor = void 0;
6
+ exports.getFileActionProcessor = exports.getSystemActionProcessor = exports.getEventBridgeEventActionProcessor = exports.getCloudFrontOriginRequestEventActionProcessor = exports.getAPIGatewayEventActionProcessor = exports.getConfigGetParametersActionProcessor = exports.getConfigGetParameterActionProcessor = exports.getConfigGetSecretActionProcessor = void 0;
7
7
  var getConfigGetSecretActionProcessor_1 = require("./config/getConfigGetSecretActionProcessor");
8
8
  Object.defineProperty(exports, "getConfigGetSecretActionProcessor", { enumerable: true, get: function () { return __importDefault(getConfigGetSecretActionProcessor_1).default; } });
9
9
  var getConfigGetParameterActionProcessor_1 = require("./config/getConfigGetParameterActionProcessor");
@@ -12,6 +12,8 @@ var getConfigGetParametersActionProcessor_1 = require("./config/getConfigGetPara
12
12
  Object.defineProperty(exports, "getConfigGetParametersActionProcessor", { enumerable: true, get: function () { return __importDefault(getConfigGetParametersActionProcessor_1).default; } });
13
13
  var getAPIGatewayEventActionProcessor_1 = require("./event/getAPIGatewayEventActionProcessor");
14
14
  Object.defineProperty(exports, "getAPIGatewayEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getAPIGatewayEventActionProcessor_1).default; } });
15
+ var getCloudFrontOriginRequestEventActionProcessor_1 = require("./event/getCloudFrontOriginRequestEventActionProcessor");
16
+ Object.defineProperty(exports, "getCloudFrontOriginRequestEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getCloudFrontOriginRequestEventActionProcessor_1).default; } });
15
17
  var getEventBridgeEventActionProcessor_1 = require("./event/getEventBridgeEventActionProcessor");
16
18
  Object.defineProperty(exports, "getEventBridgeEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getEventBridgeEventActionProcessor_1).default; } });
17
19
  var system_1 = require("./system");
@@ -32,10 +32,7 @@ const getProcessExecuteStory = (dynamicModuleLoader) => {
32
32
  if (storyResult.error) {
33
33
  return (0, quidproquo_core_1.actionResultError)(storyResult.error.errorType, `story error! in ${payload.src}::${payload.runtime} -> [${storyResult.error.errorText}]`, storyResult.error.errorStack);
34
34
  }
35
- return (0, quidproquo_core_1.actionResult)({
36
- result: storyResult.result,
37
- session: storyResult.session,
38
- });
35
+ return (0, quidproquo_core_1.actionResult)(storyResult.result);
39
36
  });
40
37
  };
41
38
  exports.default = (dynamicModuleLoader) => {
package/lib/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from './getActionProcessor';
2
2
  export * as awsLambdaUtils from './awsLambdaUtils';
3
3
  export * from './runtimeConfig/QPQAWSLambdaConfig';
4
4
  export * from './types/DynamicLoader';
5
+ export * from './logic/parametersManager/getParameter';
package/lib/index.js CHANGED
@@ -31,3 +31,4 @@ __exportStar(require("./getActionProcessor"), exports);
31
31
  exports.awsLambdaUtils = __importStar(require("./awsLambdaUtils"));
32
32
  __exportStar(require("./runtimeConfig/QPQAWSLambdaConfig"), exports);
33
33
  __exportStar(require("./types/DynamicLoader"), exports);
34
+ __exportStar(require("./logic/parametersManager/getParameter"), exports);
@@ -1 +1 @@
1
- export declare const getParameter: (parameterName: string) => Promise<string>;
1
+ export declare const getParameter: (parameterName: string, region: string) => Promise<string>;
@@ -11,9 +11,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getParameter = void 0;
13
13
  const client_ssm_1 = require("@aws-sdk/client-ssm");
14
- const smClient = new client_ssm_1.SSMClient({});
15
- const getParameter = (parameterName) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const getParameter = (parameterName, region) => __awaiter(void 0, void 0, void 0, function* () {
16
15
  var _a;
16
+ const smClient = new client_ssm_1.SSMClient({
17
+ region,
18
+ });
17
19
  const response = yield smClient.send(new client_ssm_1.GetParameterCommand({
18
20
  Name: parameterName,
19
21
  }));
@@ -1 +1 @@
1
- export declare const getParameters: (parameterNames: string[]) => Promise<string[]>;
1
+ export declare const getParameters: (parameterNames: string[], region: string) => Promise<string[]>;
@@ -11,8 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getParameters = void 0;
13
13
  const client_ssm_1 = require("@aws-sdk/client-ssm");
14
- const smClient = new client_ssm_1.SSMClient({});
15
- const getParameters = (parameterNames) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const getParameters = (parameterNames, region) => __awaiter(void 0, void 0, void 0, function* () {
15
+ const smClient = new client_ssm_1.SSMClient({ region });
16
16
  const response = yield smClient.send(new client_ssm_1.GetParametersCommand({
17
17
  Names: parameterNames,
18
18
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.43",
3
+ "version": "0.0.44",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
@@ -11,7 +11,7 @@
11
11
  "test": "echo \"Error: no test specified\" && exit 1",
12
12
  "clean": "npx rimraf lib",
13
13
  "build": "npm run clean && tsc",
14
- "watch": "npm run clean && tsc -w"
14
+ "watch": "tsc -w"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",