quidproquo-actionprocessor-awslambda 0.0.18 → 0.0.19

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 (51) hide show
  1. package/lib/awsLambdaUtils.d.ts +2 -2
  2. package/lib/awsLambdaUtils.js +21 -2
  3. package/lib/getActionProcessor/core/config/getConfigGetSecretActionProcessor.d.ts +6 -0
  4. package/lib/getActionProcessor/core/config/getConfigGetSecretActionProcessor.js +24 -0
  5. package/lib/getActionProcessor/core/config/index.d.ts +5 -0
  6. package/lib/getActionProcessor/core/config/index.js +7 -0
  7. package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.d.ts +7 -24
  8. package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.js +48 -30
  9. package/lib/getActionProcessor/core/event/getEventBridgeEventActionProcessor.d.ts +10 -0
  10. package/lib/getActionProcessor/core/event/getEventBridgeEventActionProcessor.js +49 -0
  11. package/lib/getActionProcessor/core/file/getFileDeleteActionProcessor.d.ts +6 -0
  12. package/lib/getActionProcessor/core/file/getFileDeleteActionProcessor.js +31 -0
  13. package/lib/getActionProcessor/core/file/getFileExistsActionProcessor.d.ts +6 -0
  14. package/lib/getActionProcessor/core/file/getFileExistsActionProcessor.js +23 -0
  15. package/lib/getActionProcessor/core/file/getFileListDirectoryActionProcessor.d.ts +6 -0
  16. package/lib/getActionProcessor/core/file/getFileListDirectoryActionProcessor.js +29 -0
  17. package/lib/getActionProcessor/core/file/getFileReadTextContentsActionProcessor.d.ts +6 -0
  18. package/lib/getActionProcessor/core/file/getFileReadTextContentsActionProcessor.js +23 -0
  19. package/lib/getActionProcessor/core/file/getFileWriteTextContentsActionProcessor.d.ts +6 -0
  20. package/lib/getActionProcessor/core/file/getFileWriteTextContentsActionProcessor.js +24 -0
  21. package/lib/getActionProcessor/core/file/index.d.ts +9 -0
  22. package/lib/getActionProcessor/core/file/index.js +11 -0
  23. package/lib/getActionProcessor/core/index.d.ts +4 -1
  24. package/lib/getActionProcessor/core/index.js +9 -3
  25. package/lib/getActionProcessor/core/system/getExecuteStoryActionProcessor.d.ts +4 -3
  26. package/lib/getActionProcessor/core/system/getExecuteStoryActionProcessor.js +32 -32
  27. package/lib/getActionProcessor/core/system/index.d.ts +5 -0
  28. package/lib/getActionProcessor/core/system/index.js +7 -0
  29. package/lib/index.d.ts +1 -0
  30. package/lib/index.js +1 -0
  31. package/lib/logic/s3/deleteFiles.d.ts +1 -0
  32. package/lib/logic/s3/deleteFiles.js +29 -0
  33. package/lib/logic/s3/listFiles.d.ts +10 -0
  34. package/lib/logic/s3/listFiles.js +56 -0
  35. package/lib/logic/s3/objectExists.d.ts +1 -0
  36. package/lib/logic/s3/objectExists.js +30 -0
  37. package/lib/logic/s3/readTextFile.d.ts +1 -0
  38. package/lib/logic/s3/readTextFile.js +26 -0
  39. package/lib/logic/s3/s3Client.d.ts +3 -0
  40. package/lib/logic/s3/s3Client.js +5 -0
  41. package/lib/logic/s3/s3Utils.d.ts +5 -0
  42. package/lib/logic/s3/s3Utils.js +21 -0
  43. package/lib/logic/s3/writeTextFile.d.ts +1 -0
  44. package/lib/logic/s3/writeTextFile.js +25 -0
  45. package/lib/logic/secretsManager/getSecret.d.ts +1 -0
  46. package/lib/logic/secretsManager/getSecret.js +21 -0
  47. package/lib/runtimeConfig/QPQAWSLambdaConfig.d.ts +8 -0
  48. package/lib/runtimeConfig/QPQAWSLambdaConfig.js +2 -0
  49. package/lib/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.d.ts +2 -0
  50. package/lib/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.js +7 -0
  51. package/package.json +5 -2
@@ -1,7 +1,7 @@
1
1
  export declare const randomGuid: () => string;
2
- export declare type UrlMatchPath = RegExp | string;
3
2
  export interface UrlMatch {
4
3
  didMatch: boolean;
5
4
  params: Record<string, string> | null;
6
5
  }
7
- export declare const matchUrl: (path: UrlMatchPath, url: string) => UrlMatch;
6
+ export declare const matchUrl: (path: string, url: string) => UrlMatch;
7
+ export declare const loadModule: (src: string) => Promise<any>;
@@ -1,6 +1,15 @@
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
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.matchUrl = exports.randomGuid = void 0;
12
+ exports.loadModule = exports.matchUrl = exports.randomGuid = void 0;
4
13
  const crypto_1 = require("crypto");
5
14
  const node_match_path_1 = require("node-match-path");
6
15
  const randomGuid = () => {
@@ -8,10 +17,20 @@ const randomGuid = () => {
8
17
  };
9
18
  exports.randomGuid = randomGuid;
10
19
  const matchUrl = (path, url) => {
11
- const matchResult = (0, node_match_path_1.match)(path, url);
20
+ // /attempt/{attemptUuid}/result/{test} => /attempt/:attemptUuid/result/:test
21
+ const modifiedPath = path.replaceAll(/{(.+?)}/g, (m, g) => `:${g}`);
22
+ const matchResult = (0, node_match_path_1.match)(modifiedPath, url);
12
23
  return {
13
24
  didMatch: matchResult.matches,
14
25
  params: matchResult.params,
15
26
  };
16
27
  };
17
28
  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;
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,24 @@
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 getSecret_1 = require("../../../logic/secretsManager/getSecret");
14
+ const getProcessConfigActionType = () => {
15
+ return ({ secretName }) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const secretValue = yield (0, getSecret_1.getSecret)(secretName);
17
+ return (0, quidproquo_core_1.actionResult)(secretValue);
18
+ });
19
+ };
20
+ exports.default = (runtimeConfig) => {
21
+ return {
22
+ [quidproquo_core_1.ConfigActionType.GetSecret]: getProcessConfigActionType(),
23
+ };
24
+ };
@@ -0,0 +1,5 @@
1
+ import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
+ declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
3
+ "@quidproquo-core/Config/GetSecret": import("quidproquo-core/lib").ConfigGetSecretActionProcessor;
4
+ };
5
+ export default _default;
@@ -0,0 +1,7 @@
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 getConfigGetSecretActionProcessor_1 = __importDefault(require("./getConfigGetSecretActionProcessor"));
7
+ exports.default = (runtimeConfig) => (Object.assign({}, (0, getConfigGetSecretActionProcessor_1.default)(runtimeConfig)));
@@ -1,27 +1,10 @@
1
- import { QPQConfig, EventTransformEventParamsActionPayload, EventTransformResponseResultActionPayload, EventMatchStoryActionPayload, EventAutoRespondActionPayload, StorySession } from 'quidproquo-core';
2
- import { RouteQPQWebServerConfigSetting, HTTPEventParams } from 'quidproquo-webserver';
3
- import { Context } from 'aws-lambda';
1
+ import { QPQConfig, EventMatchStoryActionProcessor, EventTransformEventParamsActionProcessor, EventTransformResponseResultActionProcessor, EventAutoRespondActionProcessor } from 'quidproquo-core';
2
+ import { HTTPEventParams } from 'quidproquo-webserver';
3
+ import { Context, APIGatewayProxyResult } from 'aws-lambda';
4
4
  declare const _default: (config: QPQConfig) => {
5
- "@quidproquo-core/event/TransformEventParams": (payload: EventTransformEventParamsActionPayload<[import("aws-lambda").APIGatewayProxyEvent, Context]>, session: StorySession) => Promise<HTTPEventParams<any>>;
6
- "@quidproquo-core/event/TransformResponseResult": (payload: EventTransformResponseResultActionPayload, session: StorySession) => Promise<{
7
- statusCode: any;
8
- body: any;
9
- headers: {
10
- 'Content-Type': string;
11
- 'Access-Control-Allow-Headers': string;
12
- 'Access-Control-Allow-Methods': string;
13
- 'Access-Control-Allow-Origin': string;
14
- };
15
- }>;
16
- "@quidproquo-core/event/AutoRespond": (payload: EventAutoRespondActionPayload<HTTPEventParams<any>>, session: StorySession) => Promise<{
17
- statusCode: number;
18
- headers: {
19
- 'Content-Type': string;
20
- 'Access-Control-Allow-Headers': string;
21
- 'Access-Control-Allow-Methods': string;
22
- 'Access-Control-Allow-Origin': string;
23
- };
24
- } | null>;
25
- "@quidproquo-core/event/MatchStory": (payload: EventMatchStoryActionPayload<HTTPEventParams<any>>, session: StorySession) => Promise<RouteQPQWebServerConfigSetting | undefined>;
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>>;
26
9
  };
27
10
  export default _default;
@@ -13,24 +13,27 @@ const quidproquo_core_1 = require("quidproquo-core");
13
13
  const quidproquo_webserver_1 = require("quidproquo-webserver");
14
14
  const awsLambdaUtils_1 = require("../../../awsLambdaUtils");
15
15
  const getProcessTransformEventParams = (appName) => {
16
- return (payload, session) => __awaiter(void 0, void 0, void 0, function* () {
17
- const [apiGatewayEvent, context] = payload.eventParams;
16
+ return ({ eventParams: [apiGatewayEvent, context] }) => __awaiter(void 0, void 0, void 0, function* () {
18
17
  const path = (apiGatewayEvent.path || '').replace(new RegExp(`^(\/${appName})/`), '/');
19
- return {
18
+ return (0, quidproquo_core_1.actionResult)({
20
19
  path,
21
20
  query: Object.assign(Object.assign({}, (apiGatewayEvent.multiValueQueryStringParameters || {})), (apiGatewayEvent.queryStringParameters || {})),
22
21
  body: apiGatewayEvent.body ? JSON.parse(apiGatewayEvent.body) : undefined,
23
22
  headers: apiGatewayEvent.headers,
24
23
  method: apiGatewayEvent.httpMethod,
25
24
  correlation: context.awsRequestId,
26
- };
25
+ sourceIp: apiGatewayEvent.requestContext.identity.sourceIp,
26
+ });
27
27
  });
28
28
  };
29
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,
30
+ // We might need to JSON.stringify the body.
31
+ return ({ response }) => __awaiter(void 0, void 0, void 0, function* () {
32
+ // Validate response
33
+ // if !valid actionResultError
34
+ return (0, quidproquo_core_1.actionResult)({
35
+ statusCode: response.result.statusCode,
36
+ body: response.result.body,
34
37
  headers: {
35
38
  'Content-Type': 'application/json',
36
39
  'Access-Control-Allow-Headers': '*',
@@ -41,9 +44,9 @@ const getProcessTransformResponseResult = (domainName) => {
41
44
  });
42
45
  };
43
46
  const getProcessAutoRespond = (domainName) => {
44
- return (payload, session) => __awaiter(void 0, void 0, void 0, function* () {
47
+ return (payload) => __awaiter(void 0, void 0, void 0, function* () {
45
48
  if (payload.transformedEventParams.method === 'OPTIONS') {
46
- return {
49
+ return (0, quidproquo_core_1.actionResult)({
47
50
  statusCode: 200,
48
51
  headers: {
49
52
  'Content-Type': 'application/json',
@@ -51,34 +54,49 @@ const getProcessAutoRespond = (domainName) => {
51
54
  'Access-Control-Allow-Methods': '*',
52
55
  'Access-Control-Allow-Origin': `https://${domainName}`,
53
56
  },
54
- };
57
+ });
55
58
  }
56
- return null;
59
+ return (0, quidproquo_core_1.actionResult)(null);
57
60
  });
58
61
  };
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.transformedEventParams.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;
62
+ const getProcessMatchStory = (routes) => {
63
+ return (payload) => __awaiter(void 0, void 0, void 0, function* () {
64
+ // Sort the routes by string length
65
+ // Note: We may need to filter variable routes out {} as the variables are length independent
66
+ const sortedRoutes = routes
67
+ .filter((r) => r.method === payload.transformedEventParams.method)
68
+ .sort((a, b) => {
69
+ if (a.path.length < b.path.length)
70
+ return -1;
71
+ if (a.path.length > b.path.length)
72
+ return 1;
73
+ return 0;
74
+ });
75
+ // Find the most relevant match
76
+ const matchedRoute = sortedRoutes
77
+ .map((r) => ({
78
+ match: (0, awsLambdaUtils_1.matchUrl)(r.path, payload.transformedEventParams.path),
79
+ route: r,
80
+ }))
81
+ .find((m) => m.match.didMatch);
82
+ if (!matchedRoute) {
83
+ return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, 'route not found');
84
+ }
85
+ return (0, quidproquo_core_1.actionResult)({
86
+ src: matchedRoute.route.src,
87
+ runtime: matchedRoute.route.runtime,
88
+ options: matchedRoute.match.params || {},
89
+ });
70
90
  });
71
- // Find the most relevant match
72
- return sortedRoutes.find((r) => (0, awsLambdaUtils_1.matchUrl)(r.path, payload.transformedEventParams.path).didMatch);
73
- });
91
+ };
74
92
  exports.default = (config) => {
75
93
  const routes = quidproquo_webserver_1.qpqWebServerUtils.getAllRoutes(config);
76
94
  const appName = quidproquo_core_1.qpqCoreUtils.getAppName(config);
77
95
  const domainName = quidproquo_webserver_1.qpqWebServerUtils.getDomainName(config);
78
96
  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),
97
+ [quidproquo_core_1.EventActionType.TransformEventParams]: getProcessTransformEventParams(appName),
98
+ [quidproquo_core_1.EventActionType.TransformResponseResult]: getProcessTransformResponseResult(domainName),
99
+ [quidproquo_core_1.EventActionType.AutoRespond]: getProcessAutoRespond(domainName),
100
+ [quidproquo_core_1.EventActionType.MatchStory]: getProcessMatchStory(routes),
83
101
  };
84
102
  };
@@ -0,0 +1,10 @@
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;
@@ -0,0 +1,49 @@
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
+ if (!lambdaRuntimeConfig) {
33
+ return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, 'event runtime not found');
34
+ }
35
+ return (0, quidproquo_core_1.actionResult)({
36
+ src: lambdaRuntimeConfig.src,
37
+ runtime: lambdaRuntimeConfig.runtime,
38
+ options: {},
39
+ });
40
+ });
41
+ };
42
+ exports.default = (runtimeConfig) => {
43
+ return {
44
+ [quidproquo_core_1.EventActionType.TransformEventParams]: getProcessTransformEventParams(),
45
+ [quidproquo_core_1.EventActionType.TransformResponseResult]: getProcessTransformResponseResult(),
46
+ [quidproquo_core_1.EventActionType.AutoRespond]: getProcessAutoRespond(),
47
+ [quidproquo_core_1.EventActionType.MatchStory]: getProcessMatchStory(runtimeConfig.lambdaRuntimeConfig),
48
+ };
49
+ };
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,31 @@
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
+ });
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,23 @@
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
+ });
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,29 @@
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
+ });
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,23 @@
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
+ });
@@ -0,0 +1,6 @@
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;
@@ -0,0 +1,24 @@
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
+ });
@@ -0,0 +1,9 @@
1
+ import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
+ declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
3
+ "@quidproquo-core/File/WriteTextContents": import("quidproquo-core/lib").FileWriteTextContentsActionProcessor;
4
+ "@quidproquo-core/File/ReadTextContents": import("quidproquo-core/lib").FileReadTextContentsActionProcessor;
5
+ "@quidproquo-core/File/ListDirectory": import("quidproquo-core/lib").FileListDirectoryActionProcessor;
6
+ "@quidproquo-core/File/Exists": import("quidproquo-core/lib").FileExistsActionProcessor;
7
+ "@quidproquo-core/File/Delete": import("quidproquo-core/lib").FileDeleteActionProcessor;
8
+ };
9
+ export default _default;
@@ -0,0 +1,11 @@
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 getFileDeleteActionProcessor_1 = __importDefault(require("./getFileDeleteActionProcessor"));
7
+ const getFileExistsActionProcessor_1 = __importDefault(require("./getFileExistsActionProcessor"));
8
+ const getFileListDirectoryActionProcessor_1 = __importDefault(require("./getFileListDirectoryActionProcessor"));
9
+ const getFileReadTextContentsActionProcessor_1 = __importDefault(require("./getFileReadTextContentsActionProcessor"));
10
+ const getFileWriteTextContentsActionProcessor_1 = __importDefault(require("./getFileWriteTextContentsActionProcessor"));
11
+ exports.default = (runtimeConfig) => (Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, (0, getFileDeleteActionProcessor_1.default)(runtimeConfig)), (0, getFileExistsActionProcessor_1.default)(runtimeConfig)), (0, getFileListDirectoryActionProcessor_1.default)(runtimeConfig)), (0, getFileReadTextContentsActionProcessor_1.default)(runtimeConfig)), (0, getFileWriteTextContentsActionProcessor_1.default)(runtimeConfig)));
@@ -1,2 +1,5 @@
1
+ export { default as getConfigGetSecretActionProcessor } from './config/getConfigGetSecretActionProcessor';
1
2
  export { default as getAPIGatewayEventActionProcessor } from './event/getAPIGatewayEventActionProcessor';
2
- export { default as getExecuteStoryActionProcessor } from './system/getExecuteStoryActionProcessor';
3
+ export { default as getEventBridgeEventActionProcessor } from './event/getEventBridgeEventActionProcessor';
4
+ export { default as getSystemActionProcessor } from './system';
5
+ export { default as getFileActionProcessor } from './file';
@@ -3,8 +3,14 @@ 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.getExecuteStoryActionProcessor = exports.getAPIGatewayEventActionProcessor = void 0;
6
+ exports.getFileActionProcessor = exports.getSystemActionProcessor = exports.getEventBridgeEventActionProcessor = exports.getAPIGatewayEventActionProcessor = exports.getConfigGetSecretActionProcessor = void 0;
7
+ var getConfigGetSecretActionProcessor_1 = require("./config/getConfigGetSecretActionProcessor");
8
+ Object.defineProperty(exports, "getConfigGetSecretActionProcessor", { enumerable: true, get: function () { return __importDefault(getConfigGetSecretActionProcessor_1).default; } });
7
9
  var getAPIGatewayEventActionProcessor_1 = require("./event/getAPIGatewayEventActionProcessor");
8
10
  Object.defineProperty(exports, "getAPIGatewayEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getAPIGatewayEventActionProcessor_1).default; } });
9
- var getExecuteStoryActionProcessor_1 = require("./system/getExecuteStoryActionProcessor");
10
- Object.defineProperty(exports, "getExecuteStoryActionProcessor", { enumerable: true, get: function () { return __importDefault(getExecuteStoryActionProcessor_1).default; } });
11
+ var getEventBridgeEventActionProcessor_1 = require("./event/getEventBridgeEventActionProcessor");
12
+ Object.defineProperty(exports, "getEventBridgeEventActionProcessor", { enumerable: true, get: function () { return __importDefault(getEventBridgeEventActionProcessor_1).default; } });
13
+ var system_1 = require("./system");
14
+ Object.defineProperty(exports, "getSystemActionProcessor", { enumerable: true, get: function () { return __importDefault(system_1).default; } });
15
+ var file_1 = require("./file");
16
+ Object.defineProperty(exports, "getFileActionProcessor", { enumerable: true, get: function () { return __importDefault(file_1).default; } });
@@ -1,6 +1,7 @@
1
- import { QPQConfig, SystemExecuteStoryActionPayload, StorySession } from 'quidproquo-core';
1
+ import { SystemExecuteStoryActionProcessor } from 'quidproquo-core';
2
+ import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
3
  export declare const getDateNow: () => string;
3
- declare const _default: (config: QPQConfig) => {
4
- "@quidproquo-core/System/ExecuteStory": (payload: SystemExecuteStoryActionPayload<any[]>, session: StorySession) => Promise<any>;
4
+ declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
5
+ "@quidproquo-core/System/ExecuteStory": SystemExecuteStoryActionProcessor<any[]>;
5
6
  };
6
7
  export default _default;
@@ -8,46 +8,46 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
11
14
  Object.defineProperty(exports, "__esModule", { value: true });
12
15
  exports.getDateNow = void 0;
13
16
  const quidproquo_core_1 = require("quidproquo-core");
17
+ const file_1 = __importDefault(require("../file"));
18
+ const config_1 = __importDefault(require("../config"));
19
+ const quidproquo_actionprocessor_node_1 = require("quidproquo-actionprocessor-node");
20
+ const awsLambdaUtils_1 = require("./../../../awsLambdaUtils");
14
21
  const getDateNow = () => new Date().toISOString();
15
22
  exports.getDateNow = getDateNow;
16
- const getProcessExecuteStory = (appName) => {
23
+ const getProcessExecuteStory = (runtimeConfig) => {
17
24
  return (payload, session) => __awaiter(void 0, void 0, void 0, function* () {
18
- // const module = require(payload.src);
19
- // const story = module[payload.runtime];
20
- // const logger = async (result: any) => {
21
- // // return await addResult(service, getDateNow(), payload.params[0][0].path, 'user-route', payload.src, payload.runtime, result);
22
- // };
23
- // const actionProcessors = {
24
- // ...coreActionProcessor,
25
- // ...webserverActionProcessor,
26
- // };
27
- // const result = await resolveStory(
28
- // story,
29
- // payload.params,
30
- // session,
31
- // actionProcessors,
32
- // getDateNow,
33
- // logger,
34
- // randomGuid,
35
- // );
36
- // return {
37
- // result: result.result,
38
- // session: result.session,
39
- // };
40
- // statusCode: payload.response.result.statusCode,
41
- // body: payload.response.result.body,
42
- return {
43
- result: { statusCode: 200, body: { omg: 'wtf bbq' } },
44
- session: {},
45
- };
25
+ let module = yield (0, awsLambdaUtils_1.loadModule)(payload.src);
26
+ if (module === null) {
27
+ return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, `Module not found [${payload.src}]`);
28
+ }
29
+ const story = module[payload.runtime];
30
+ if (!story) {
31
+ return (0, quidproquo_core_1.actionResultError)(quidproquo_core_1.ErrorTypeEnum.NotFound, `[${payload.runtime}] not found in module [${payload.src}]`);
32
+ }
33
+ const logger = (result) => __awaiter(void 0, void 0, void 0, function* () {
34
+ // return await addResult(service, getDateNow(), payload.params[0][0].path, 'user-route', payload.src, payload.runtime, result);
35
+ });
36
+ const allActionProcessors = Object.assign(Object.assign(Object.assign(Object.assign({}, quidproquo_actionprocessor_node_1.coreActionProcessor), quidproquo_actionprocessor_node_1.webserverActionProcessor), (0, file_1.default)(runtimeConfig)), (0, config_1.default)(runtimeConfig));
37
+ const resolveStory = (0, quidproquo_core_1.createRuntime)(session, allActionProcessors, exports.getDateNow, logger, awsLambdaUtils_1.randomGuid);
38
+ const storyResult = yield resolveStory(story, payload.params);
39
+ if (storyResult.error) {
40
+ return (0, quidproquo_core_1.actionResultError)(storyResult.error.errorType, `story error! in ${payload.src}::${payload.runtime} -> [${storyResult.error.errorText}]`, storyResult.error.errorStack);
41
+ }
42
+ return (0, quidproquo_core_1.actionResult)({
43
+ result: storyResult.result,
44
+ session: storyResult.session,
45
+ });
46
46
  });
47
47
  };
48
- exports.default = (config) => {
49
- const appName = quidproquo_core_1.qpqCoreUtils.getAppName(config);
48
+ exports.default = (runtimeConfig) => {
49
+ // const appName = qpqCoreUtils.getAppName(config);
50
50
  return {
51
- [quidproquo_core_1.SystemActionTypeEnum.ExecuteStory]: getProcessExecuteStory(appName),
51
+ [quidproquo_core_1.SystemActionType.ExecuteStory]: getProcessExecuteStory(runtimeConfig),
52
52
  };
53
53
  };
@@ -0,0 +1,5 @@
1
+ import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
2
+ declare const _default: (runtimeConfig: QPQAWSLambdaConfig) => {
3
+ "@quidproquo-core/System/ExecuteStory": import("quidproquo-core/lib").SystemExecuteStoryActionProcessor<any[]>;
4
+ };
5
+ export default _default;
@@ -0,0 +1,7 @@
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 getExecuteStoryActionProcessor_1 = __importDefault(require("./getExecuteStoryActionProcessor"));
7
+ exports.default = (runtimeConfig) => (Object.assign({}, (0, getExecuteStoryActionProcessor_1.default)(runtimeConfig)));
package/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './getActionProcessor';
2
2
  export * as awsLambdaUtils from './awsLambdaUtils';
3
+ export * from './runtimeConfig/QPQAWSLambdaConfig';
package/lib/index.js CHANGED
@@ -29,3 +29,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.awsLambdaUtils = void 0;
30
30
  __exportStar(require("./getActionProcessor"), exports);
31
31
  exports.awsLambdaUtils = __importStar(require("./awsLambdaUtils"));
32
+ __exportStar(require("./runtimeConfig/QPQAWSLambdaConfig"), exports);
@@ -0,0 +1 @@
1
+ export declare const deleteFiles: (drive: string, filepaths: string[]) => Promise<string[]>;
@@ -0,0 +1,29 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.deleteFiles = void 0;
16
+ const client_s3_1 = require("@aws-sdk/client-s3");
17
+ const s3Client_1 = __importDefault(require("./s3Client"));
18
+ const deleteFiles = (drive, filepaths) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const bucketParams = {
20
+ Bucket: drive,
21
+ Delete: {
22
+ Quiet: true,
23
+ Objects: filepaths.map((fp) => ({ Key: fp })),
24
+ },
25
+ };
26
+ const response = yield s3Client_1.default.send(new client_s3_1.DeleteObjectsCommand(bucketParams));
27
+ return (response.Errors || []).map((e) => e.Key || '');
28
+ });
29
+ exports.deleteFiles = deleteFiles;
@@ -0,0 +1,10 @@
1
+ export interface S3FileInfo {
2
+ filepath: string;
3
+ isDir: boolean;
4
+ hashMd5?: string;
5
+ }
6
+ export interface S3FileList {
7
+ fileInfos: S3FileInfo[];
8
+ pageToken?: string;
9
+ }
10
+ export declare const listFiles: (drive: string, folder?: string, maxKeys?: number, pageToken?: string) => Promise<S3FileList>;
@@ -0,0 +1,56 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.listFiles = void 0;
16
+ const client_s3_1 = require("@aws-sdk/client-s3");
17
+ const quidproquo_core_1 = require("quidproquo-core");
18
+ const s3Client_1 = __importDefault(require("./s3Client"));
19
+ const listFiles = (drive, folder = '', maxKeys = 1000, pageToken) => __awaiter(void 0, void 0, void 0, function* () {
20
+ const validatedPrefix = `${folder}${folder.endsWith(quidproquo_core_1.filePathDelimiter) || !folder ? '' : quidproquo_core_1.filePathDelimiter}`;
21
+ const bucketParams = {
22
+ Bucket: drive,
23
+ Delimiter: quidproquo_core_1.filePathDelimiter,
24
+ Prefix: validatedPrefix,
25
+ ContinuationToken: pageToken,
26
+ MaxKeys: maxKeys,
27
+ };
28
+ // Declare truncated as a flag that the while loop is based on.
29
+ let files = [];
30
+ const response = yield s3Client_1.default.send(new client_s3_1.ListObjectsV2Command(bucketParams));
31
+ if (response.CommonPrefixes && !bucketParams.ContinuationToken) {
32
+ files = [
33
+ ...files,
34
+ ...response.CommonPrefixes.filter((cp) => !!cp.Prefix).map((cp) => ({
35
+ filepath: cp.Prefix,
36
+ drive: drive,
37
+ isDir: true,
38
+ })),
39
+ ];
40
+ }
41
+ files = [
42
+ ...files,
43
+ ...(response.Contents || [])
44
+ .filter((c) => !!c.Key && c.Key != folder)
45
+ .map((item) => ({
46
+ filepath: item.Key,
47
+ isDir: item.Key.endsWith(quidproquo_core_1.filePathDelimiter),
48
+ hashMd5: item.ETag,
49
+ })),
50
+ ];
51
+ return {
52
+ fileInfos: files,
53
+ pageToken: response.NextContinuationToken,
54
+ };
55
+ });
56
+ exports.listFiles = listFiles;
@@ -0,0 +1 @@
1
+ export declare const objectExists: (bucketName: string, key: string) => Promise<boolean>;
@@ -0,0 +1,30 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.objectExists = void 0;
16
+ const client_s3_1 = require("@aws-sdk/client-s3");
17
+ const s3Client_1 = __importDefault(require("./s3Client"));
18
+ const objectExists = (bucketName, key) => __awaiter(void 0, void 0, void 0, function* () {
19
+ try {
20
+ const response = yield s3Client_1.default.send(new client_s3_1.HeadObjectCommand({
21
+ Key: key,
22
+ Bucket: bucketName,
23
+ }));
24
+ return true;
25
+ }
26
+ catch (_a) {
27
+ return false;
28
+ }
29
+ });
30
+ exports.objectExists = objectExists;
@@ -0,0 +1 @@
1
+ export declare const readTextFile: (bucketName: string, key: string) => Promise<string>;
@@ -0,0 +1,26 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.readTextFile = void 0;
16
+ const client_s3_1 = require("@aws-sdk/client-s3");
17
+ const s3Client_1 = __importDefault(require("./s3Client"));
18
+ const readTextFile = (bucketName, key) => __awaiter(void 0, void 0, void 0, function* () {
19
+ var _a;
20
+ const response = yield s3Client_1.default.send(new client_s3_1.GetObjectCommand({
21
+ Key: key,
22
+ Bucket: bucketName,
23
+ }));
24
+ return (yield ((_a = response.Body) === null || _a === void 0 ? void 0 : _a.transformToString())) || '';
25
+ });
26
+ exports.readTextFile = readTextFile;
@@ -0,0 +1,3 @@
1
+ import { S3Client } from '@aws-sdk/client-s3';
2
+ declare const s3Client: S3Client;
3
+ export default s3Client;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const client_s3_1 = require("@aws-sdk/client-s3");
4
+ const s3Client = new client_s3_1.S3Client({ region: 'ap-southeast-2' });
5
+ exports.default = s3Client;
@@ -0,0 +1,5 @@
1
+ export * from './deleteFiles';
2
+ export * from './listFiles';
3
+ export * from './objectExists';
4
+ export * from './readTextFile';
5
+ export * from './writeTextFile';
@@ -0,0 +1,21 @@
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("./deleteFiles"), exports);
18
+ __exportStar(require("./listFiles"), exports);
19
+ __exportStar(require("./objectExists"), exports);
20
+ __exportStar(require("./readTextFile"), exports);
21
+ __exportStar(require("./writeTextFile"), exports);
@@ -0,0 +1 @@
1
+ export declare const writeTextFile: (bucketName: string, key: string, data: string) => Promise<void>;
@@ -0,0 +1,25 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.writeTextFile = void 0;
16
+ const client_s3_1 = require("@aws-sdk/client-s3");
17
+ const s3Client_1 = __importDefault(require("./s3Client"));
18
+ const writeTextFile = (bucketName, key, data) => __awaiter(void 0, void 0, void 0, function* () {
19
+ yield s3Client_1.default.send(new client_s3_1.PutObjectCommand({
20
+ Key: key,
21
+ Bucket: bucketName,
22
+ Body: Buffer.from(data),
23
+ }));
24
+ });
25
+ exports.writeTextFile = writeTextFile;
@@ -0,0 +1 @@
1
+ export declare const getSecret: (secretName: string) => Promise<string>;
@@ -0,0 +1,21 @@
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
+ exports.getSecret = void 0;
13
+ const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
14
+ const smClient = new client_secrets_manager_1.SecretsManagerClient({});
15
+ const getSecret = (secretName) => __awaiter(void 0, void 0, void 0, function* () {
16
+ const response = yield smClient.send(new client_secrets_manager_1.GetSecretValueCommand({
17
+ SecretId: secretName,
18
+ }));
19
+ return response.SecretString || '';
20
+ });
21
+ exports.getSecret = getSecret;
@@ -0,0 +1,8 @@
1
+ export interface LambdaRuntimeConfig {
2
+ src: string;
3
+ runtime: string;
4
+ }
5
+ export interface QPQAWSLambdaConfig {
6
+ resourceNameMap: Record<string, string>;
7
+ lambdaRuntimeConfig?: LambdaRuntimeConfig;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ import { QPQAWSLambdaConfig } from './QPQAWSLambdaConfig';
2
+ export declare const resolveResourceName: (resourceName: string, qpqAwsLambdaConfig: QPQAWSLambdaConfig) => string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveResourceName = void 0;
4
+ const resolveResourceName = (resourceName, qpqAwsLambdaConfig) => {
5
+ return qpqAwsLambdaConfig.resourceNameMap[resourceName] || resourceName;
6
+ };
7
+ exports.resolveResourceName = resolveResourceName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
@@ -9,7 +9,8 @@
9
9
  ],
10
10
  "scripts": {
11
11
  "test": "echo \"Error: no test specified\" && exit 1",
12
- "build": "npx rimraf lib && tsc"
12
+ "build": "npx rimraf lib && tsc",
13
+ "watch": "tsc -w"
13
14
  },
14
15
  "repository": {
15
16
  "type": "git",
@@ -23,6 +24,8 @@
23
24
  },
24
25
  "homepage": "https://github.com/joe-coady/quidproquo#readme",
25
26
  "dependencies": {
27
+ "@aws-sdk/client-s3": "^3.224.0",
28
+ "@aws-sdk/client-secrets-manager": "^3.229.0",
26
29
  "aws-sdk": "^2.1264.0",
27
30
  "node-match-path": "^0.6.3",
28
31
  "quidproquo-core": "*",