quidproquo-actionprocessor-awslambda 0.0.13 → 0.0.15

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.
@@ -0,0 +1,7 @@
1
+ export declare const randomGuid: () => string;
2
+ export declare type UrlMatchPath = RegExp | string;
3
+ export interface UrlMatch {
4
+ didMatch: boolean;
5
+ params: Record<string, string> | null;
6
+ }
7
+ export declare const matchUrl: (path: UrlMatchPath, url: string) => UrlMatch;
@@ -0,0 +1,17 @@
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
+ const matchResult = (0, node_match_path_1.match)(path, url);
12
+ return {
13
+ didMatch: matchResult.matches,
14
+ params: matchResult.params,
15
+ };
16
+ };
17
+ exports.matchUrl = matchUrl;
@@ -0,0 +1,26 @@
1
+ import { QPQConfig } from 'quidproquo-core';
2
+ import { RouteQPQWebServerConfigSetting, HTTPEventParams } from 'quidproquo-webserver';
3
+ declare const _default: (config: QPQConfig) => {
4
+ "@quidproquo-core/event/TransformEventParams": (payload: any, session: any) => Promise<HTTPEventParams<any>>;
5
+ "@quidproquo-core/event/TransformResponseResult": (payload: any, session: any) => Promise<{
6
+ statusCode: any;
7
+ body: any;
8
+ headers: {
9
+ 'Content-Type': string;
10
+ 'Access-Control-Allow-Headers': string;
11
+ 'Access-Control-Allow-Methods': string;
12
+ 'Access-Control-Allow-Origin': string;
13
+ };
14
+ }>;
15
+ "@quidproquo-core/event/AutoRespond": (payload: any, session: any) => Promise<{
16
+ statusCode: number;
17
+ headers: {
18
+ 'Content-Type': string;
19
+ 'Access-Control-Allow-Headers': string;
20
+ 'Access-Control-Allow-Methods': string;
21
+ 'Access-Control-Allow-Origin': string;
22
+ };
23
+ } | null>;
24
+ "@quidproquo-core/event/MatchStory": (payload: any, session: any) => Promise<RouteQPQWebServerConfigSetting | undefined>;
25
+ };
26
+ export default _default;
@@ -0,0 +1,84 @@
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 (payload, session) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const { params: [event], } = payload;
18
+ const path = (event.path || '').replace(new RegExp(`^(\/${appName})/`), '/');
19
+ return {
20
+ path,
21
+ query: Object.assign(Object.assign({}, (event.multiValueQueryStringParameters || {})), (event.queryStringParameters || {})),
22
+ body: event.body ? JSON.parse(event.body) : undefined,
23
+ headers: event.headers || {},
24
+ method: event.httpMethod,
25
+ correlation: (0, awsLambdaUtils_1.randomGuid)(),
26
+ };
27
+ });
28
+ };
29
+ const getProcessTransformResponseResult = (domainName) => {
30
+ return (payload, session) => __awaiter(void 0, void 0, void 0, function* () {
31
+ return ({
32
+ statusCode: payload.response.result.statusCode,
33
+ body: payload.response.result.body,
34
+ headers: {
35
+ 'Content-Type': 'application/json',
36
+ 'Access-Control-Allow-Headers': '*',
37
+ 'Access-Control-Allow-Methods': '*',
38
+ 'Access-Control-Allow-Origin': `https://${domainName}`,
39
+ },
40
+ });
41
+ });
42
+ };
43
+ const getProcessAutoRespond = (domainName) => {
44
+ return (payload, session) => __awaiter(void 0, void 0, void 0, function* () {
45
+ if (payload.http === 'OPTIONS') {
46
+ return {
47
+ statusCode: 200,
48
+ headers: {
49
+ 'Content-Type': 'application/json',
50
+ 'Access-Control-Allow-Headers': '*',
51
+ 'Access-Control-Allow-Methods': '*',
52
+ 'Access-Control-Allow-Origin': `https://${domainName}`,
53
+ },
54
+ };
55
+ }
56
+ return null;
57
+ });
58
+ };
59
+ const getProcessMatchStory = (routes) => (payload, session) => __awaiter(void 0, void 0, void 0, function* () {
60
+ // Sort the routes by string length
61
+ // Note: We may need to filter variable routes out {} as the variables are length independent
62
+ const sortedRoutes = routes
63
+ .filter((r) => r.method === payload.method)
64
+ .sort((a, b) => {
65
+ if (a.path.length < b.path.length)
66
+ return -1;
67
+ if (a.path.length > b.path.length)
68
+ return 1;
69
+ return 0;
70
+ });
71
+ // Find the most relevant match
72
+ return sortedRoutes.find((r) => (0, awsLambdaUtils_1.matchUrl)(r.path, payload.path).didMatch);
73
+ });
74
+ exports.default = (config) => {
75
+ const routes = quidproquo_webserver_1.qpqWebServerUtils.getAllRoutes(config);
76
+ const appName = quidproquo_core_1.qpqCoreUtils.getAppName(config);
77
+ const domainName = quidproquo_webserver_1.qpqWebServerUtils.getDomainName(config);
78
+ return {
79
+ [quidproquo_core_1.EventActionTypeEnum.TransformEventParams]: getProcessTransformEventParams(appName),
80
+ [quidproquo_core_1.EventActionTypeEnum.TransformResponseResult]: getProcessTransformResponseResult(domainName),
81
+ [quidproquo_core_1.EventActionTypeEnum.AutoRespond]: getProcessAutoRespond(domainName),
82
+ [quidproquo_core_1.EventActionTypeEnum.MatchStory]: getProcessMatchStory(routes),
83
+ };
84
+ };
@@ -1,2 +1 @@
1
- declare const _default: {};
2
- export default _default;
1
+ export { default as getAPIGatewayEventActionProcessor } from './event/getAPIGatewayEventActionProcessor';
@@ -1,3 +1,8 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {};
6
+ exports.getAPIGatewayEventActionProcessor = void 0;
7
+ var getAPIGatewayEventActionProcessor_1 = require("./event/getAPIGatewayEventActionProcessor");
8
+ Object.defineProperty(exports, "getAPIGatewayEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getAPIGatewayEventActionProcessor_1).default; } });
@@ -1 +1 @@
1
- export { default as coreActionProcessor } from "./core";
1
+ export * from './core';
@@ -1,8 +1,17 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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);
4
15
  };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.coreActionProcessor = void 0;
7
- var core_1 = require("./core");
8
- Object.defineProperty(exports, "coreActionProcessor", { enumerable: true, get: function () { return __importDefault(core_1).default; } });
17
+ __exportStar(require("./core"), exports);
package/lib/index.d.ts CHANGED
@@ -1 +1 @@
1
- export * from "./getActionProcessor";
1
+ export * from './getActionProcessor';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
@@ -23,9 +23,13 @@
23
23
  },
24
24
  "homepage": "https://github.com/joe-coady/quidproquo#readme",
25
25
  "dependencies": {
26
- "quidproquo-core": "*"
26
+ "aws-sdk": "^2.1264.0",
27
+ "node-match-path": "^0.6.3",
28
+ "quidproquo-core": "*",
29
+ "quidproquo-webserver": "*"
27
30
  },
28
31
  "devDependencies": {
32
+ "@types/node": "^18.11.9",
29
33
  "quidproquo-tsconfig": "*",
30
34
  "typescript": "^4.9.3"
31
35
  }
@@ -1,2 +0,0 @@
1
- declare const _default: {};
2
- export default _default;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = {};
4
- // import { EventActionTypeEnum } from "quidproquo-core";
5
- // export default (configs: ) => ({
6
- // [EventActionTypeEnum.TransformEventParams]: getProcessTransformEventParams(
7
- // routes,
8
- // service
9
- // ),
10
- // [EventActionTypeEnum.TransformResponseResult]:
11
- // getProcessTransformResponseResult(routes),
12
- // [EventActionTypeEnum.AutoRespond]: getProcessAutoRespond(routes),
13
- // [EventActionTypeEnum.Match]: getProcessMatch(routes),
14
- // [EventActionTypeEnum.ExecuteStory]: getProcessExecuteStory(routes, service),
15
- // });