quidproquo-actionprocessor-awslambda 0.0.38 → 0.0.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/awsLambdaUtils.d.ts +6 -0
- package/lib/awsLambdaUtils.js +19 -0
- package/lib/getActionProcessor/core/config/getConfigGetParameterActionProcessor.d.ts +6 -0
- package/lib/getActionProcessor/core/config/getConfigGetParameterActionProcessor.js +26 -0
- package/lib/getActionProcessor/core/config/getConfigGetParametersActionProcessor.d.ts +6 -0
- package/lib/getActionProcessor/core/config/getConfigGetParametersActionProcessor.js +26 -0
- package/lib/getActionProcessor/core/config/getConfigGetSecretActionProcessor.d.ts +6 -0
- package/lib/getActionProcessor/core/config/getConfigGetSecretActionProcessor.js +26 -0
- package/lib/getActionProcessor/core/config/index.d.ts +7 -0
- package/lib/getActionProcessor/core/config/index.js +9 -0
- package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.d.ts +10 -0
- package/lib/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.js +95 -0
- package/lib/getActionProcessor/core/event/getEventBridgeEventActionProcessor.d.ts +10 -0
- package/lib/getActionProcessor/core/event/getEventBridgeEventActionProcessor.js +51 -0
- package/lib/getActionProcessor/core/file/getFileDeleteActionProcessor.d.ts +6 -0
- package/lib/getActionProcessor/core/file/getFileDeleteActionProcessor.js +31 -0
- package/lib/getActionProcessor/core/file/getFileExistsActionProcessor.d.ts +6 -0
- package/lib/getActionProcessor/core/file/getFileExistsActionProcessor.js +23 -0
- package/lib/getActionProcessor/core/file/getFileListDirectoryActionProcessor.d.ts +6 -0
- package/lib/getActionProcessor/core/file/getFileListDirectoryActionProcessor.js +29 -0
- package/lib/getActionProcessor/core/file/getFileReadTextContentsActionProcessor.d.ts +6 -0
- package/lib/getActionProcessor/core/file/getFileReadTextContentsActionProcessor.js +23 -0
- package/lib/getActionProcessor/core/file/getFileWriteTextContentsActionProcessor.d.ts +6 -0
- package/lib/getActionProcessor/core/file/getFileWriteTextContentsActionProcessor.js +24 -0
- package/lib/getActionProcessor/core/file/index.d.ts +9 -0
- package/lib/getActionProcessor/core/file/index.js +11 -0
- package/{src/getActionProcessor/core/index.ts → lib/getActionProcessor/core/index.d.ts} +0 -0
- package/lib/getActionProcessor/core/index.js +20 -0
- package/lib/getActionProcessor/core/system/getExecuteStoryActionProcessor.d.ts +7 -0
- package/lib/getActionProcessor/core/system/getExecuteStoryActionProcessor.js +45 -0
- package/lib/getActionProcessor/core/system/index.d.ts +5 -0
- package/lib/getActionProcessor/core/system/index.js +7 -0
- package/{src/getActionProcessor/index.ts → lib/getActionProcessor/index.d.ts} +0 -0
- package/lib/getActionProcessor/index.js +17 -0
- package/{src/index.ts → lib/index.d.ts} +0 -2
- package/lib/index.js +33 -0
- package/lib/logic/parametersManager/getParameter.d.ts +1 -0
- package/lib/logic/parametersManager/getParameter.js +22 -0
- package/lib/logic/parametersManager/getParameters.d.ts +1 -0
- package/lib/logic/parametersManager/getParameters.js +22 -0
- package/lib/logic/s3/deleteFiles.d.ts +1 -0
- package/lib/logic/s3/deleteFiles.js +29 -0
- package/lib/logic/s3/listFiles.d.ts +10 -0
- package/lib/logic/s3/listFiles.js +56 -0
- package/lib/logic/s3/objectExists.d.ts +1 -0
- package/lib/logic/s3/objectExists.js +30 -0
- package/lib/logic/s3/readTextFile.d.ts +1 -0
- package/lib/logic/s3/readTextFile.js +26 -0
- package/{src/logic/s3/s3Client.ts → lib/logic/s3/s3Client.d.ts} +1 -3
- package/lib/logic/s3/s3Client.js +5 -0
- package/{src/logic/s3/s3Utils.ts → lib/logic/s3/s3Utils.d.ts} +0 -0
- package/lib/logic/s3/s3Utils.js +21 -0
- package/lib/logic/s3/writeTextFile.d.ts +1 -0
- package/lib/logic/s3/writeTextFile.js +25 -0
- package/lib/logic/secretsManager/getSecret.d.ts +1 -0
- package/lib/logic/secretsManager/getSecret.js +21 -0
- package/lib/runtimeConfig/QPQAWSLambdaConfig.d.ts +12 -0
- package/lib/runtimeConfig/QPQAWSLambdaConfig.js +2 -0
- package/lib/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.d.ts +4 -0
- package/lib/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.js +15 -0
- package/{src/types/DynamicLoader.ts → lib/types/DynamicLoader.d.ts} +0 -0
- package/lib/types/DynamicLoader.js +2 -0
- package/package.json +4 -1
- package/src/awsLambdaUtils.ts +0 -22
- package/src/getActionProcessor/core/config/getConfigGetParameterActionProcessor.ts +0 -23
- package/src/getActionProcessor/core/config/getConfigGetParametersActionProcessor.ts +0 -27
- package/src/getActionProcessor/core/config/getConfigGetSecretActionProcessor.ts +0 -23
- package/src/getActionProcessor/core/config/index.ts +0 -11
- package/src/getActionProcessor/core/event/getAPIGatewayEventActionProcessor.ts +0 -134
- package/src/getActionProcessor/core/event/getEventBridgeEventActionProcessor.ts +0 -66
- package/src/getActionProcessor/core/file/getFileDeleteActionProcessor.ts +0 -31
- package/src/getActionProcessor/core/file/getFileExistsActionProcessor.ts +0 -16
- package/src/getActionProcessor/core/file/getFileListDirectoryActionProcessor.ts +0 -28
- package/src/getActionProcessor/core/file/getFileReadTextContentsActionProcessor.ts +0 -18
- package/src/getActionProcessor/core/file/getFileWriteTextContentsActionProcessor.ts +0 -23
- package/src/getActionProcessor/core/file/index.ts +0 -15
- package/src/getActionProcessor/core/system/getExecuteStoryActionProcessor.ts +0 -67
- package/src/getActionProcessor/core/system/index.ts +0 -6
- package/src/logic/parametersManager/getParameter.ts +0 -13
- package/src/logic/parametersManager/getParameters.ts +0 -15
- package/src/logic/s3/deleteFiles.ts +0 -17
- package/src/logic/s3/listFiles.ts +0 -66
- package/src/logic/s3/objectExists.ts +0 -18
- package/src/logic/s3/readTextFile.ts +0 -14
- package/src/logic/s3/writeTextFile.ts +0 -17
- package/src/logic/secretsManager/getSecret.ts +0 -13
- package/src/runtimeConfig/QPQAWSLambdaConfig.ts +0 -15
- package/src/runtimeConfig/qpqAwsLambdaRuntimeConfigUtils.ts +0 -19
- package/tsconfig.json +0 -8
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EventActionType,
|
|
3
|
-
QPQConfig,
|
|
4
|
-
qpqCoreUtils,
|
|
5
|
-
MatchStoryResult,
|
|
6
|
-
EventMatchStoryActionProcessor,
|
|
7
|
-
EventTransformEventParamsActionProcessor,
|
|
8
|
-
EventTransformResponseResultActionProcessor,
|
|
9
|
-
EventAutoRespondActionProcessor,
|
|
10
|
-
actionResult,
|
|
11
|
-
actionResultError,
|
|
12
|
-
ErrorTypeEnum,
|
|
13
|
-
} from 'quidproquo-core';
|
|
14
|
-
|
|
15
|
-
import {
|
|
16
|
-
RouteQPQWebServerConfigSetting,
|
|
17
|
-
HTTPEventParams,
|
|
18
|
-
qpqWebServerUtils,
|
|
19
|
-
} from 'quidproquo-webserver';
|
|
20
|
-
|
|
21
|
-
import { APIGatewayEvent, Context, APIGatewayProxyResult } from 'aws-lambda';
|
|
22
|
-
|
|
23
|
-
import { matchUrl } from '../../../awsLambdaUtils';
|
|
24
|
-
|
|
25
|
-
const getProcessTransformEventParams = (
|
|
26
|
-
appName: string,
|
|
27
|
-
): EventTransformEventParamsActionProcessor<[APIGatewayEvent, Context], HTTPEventParams<any>> => {
|
|
28
|
-
return async ({ eventParams: [apiGatewayEvent, context] }) => {
|
|
29
|
-
const path = (apiGatewayEvent.path || '').replace(new RegExp(`^(\/${appName})/`), '/');
|
|
30
|
-
console.log('getProcessTransformEventParams', JSON.stringify(apiGatewayEvent));
|
|
31
|
-
|
|
32
|
-
return actionResult({
|
|
33
|
-
path,
|
|
34
|
-
query: {
|
|
35
|
-
...(apiGatewayEvent.multiValueQueryStringParameters || {}),
|
|
36
|
-
...(apiGatewayEvent.queryStringParameters || {}),
|
|
37
|
-
} as { [key: string]: undefined | string | string[] },
|
|
38
|
-
body: apiGatewayEvent.body ? JSON.parse(apiGatewayEvent.body) : undefined,
|
|
39
|
-
headers: apiGatewayEvent.headers,
|
|
40
|
-
method: apiGatewayEvent.httpMethod as 'GET' | 'POST',
|
|
41
|
-
correlation: context.awsRequestId,
|
|
42
|
-
sourceIp: apiGatewayEvent.requestContext.identity.sourceIp,
|
|
43
|
-
});
|
|
44
|
-
};
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const getProcessTransformResponseResult = (
|
|
48
|
-
configs: QPQConfig,
|
|
49
|
-
): EventTransformResponseResultActionProcessor<APIGatewayProxyResult> => {
|
|
50
|
-
// We might need to JSON.stringify the body.
|
|
51
|
-
return async (payload) => {
|
|
52
|
-
// Validate response
|
|
53
|
-
// if !valid actionResultError
|
|
54
|
-
|
|
55
|
-
console.log('getProcessTransformResponseResult', JSON.stringify(payload));
|
|
56
|
-
|
|
57
|
-
return actionResult<APIGatewayProxyResult>({
|
|
58
|
-
statusCode: payload.response.result.statusCode,
|
|
59
|
-
body: payload.response.result.body,
|
|
60
|
-
headers: {
|
|
61
|
-
'Content-Type': 'application/json',
|
|
62
|
-
...qpqWebServerUtils.getCorsHeaders(configs, {}, payload.transformedEventParams.headers),
|
|
63
|
-
...(payload.response.headers || {}),
|
|
64
|
-
},
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
const getProcessAutoRespond = (
|
|
70
|
-
configs: QPQConfig,
|
|
71
|
-
): EventAutoRespondActionProcessor<HTTPEventParams<any>> => {
|
|
72
|
-
return async (payload) => {
|
|
73
|
-
if (payload.transformedEventParams.method === 'OPTIONS') {
|
|
74
|
-
return actionResult({
|
|
75
|
-
result: {
|
|
76
|
-
statusCode: 200,
|
|
77
|
-
headers: qpqWebServerUtils.getCorsHeaders(
|
|
78
|
-
configs,
|
|
79
|
-
{},
|
|
80
|
-
payload.transformedEventParams.headers,
|
|
81
|
-
),
|
|
82
|
-
},
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
return actionResult(null);
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const getProcessMatchStory = (
|
|
91
|
-
routes: RouteQPQWebServerConfigSetting[],
|
|
92
|
-
): EventMatchStoryActionProcessor<HTTPEventParams<any>> => {
|
|
93
|
-
return async (payload) => {
|
|
94
|
-
// Sort the routes by string length
|
|
95
|
-
// Note: We may need to filter variable routes out {} as the variables are length independent
|
|
96
|
-
const sortedRoutes = routes
|
|
97
|
-
.filter((r: any) => r.method === payload.transformedEventParams.method)
|
|
98
|
-
.sort((a: any, b: any) => {
|
|
99
|
-
if (a.path.length < b.path.length) return -1;
|
|
100
|
-
if (a.path.length > b.path.length) return 1;
|
|
101
|
-
return 0;
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
// Find the most relevant match
|
|
105
|
-
const matchedRoute = sortedRoutes
|
|
106
|
-
.map((r) => ({
|
|
107
|
-
match: matchUrl(r.path, payload.transformedEventParams.path),
|
|
108
|
-
route: r,
|
|
109
|
-
}))
|
|
110
|
-
.find((m) => m.match.didMatch);
|
|
111
|
-
|
|
112
|
-
if (!matchedRoute) {
|
|
113
|
-
return actionResultError(ErrorTypeEnum.NotFound, 'route not found');
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return actionResult<MatchStoryResult>({
|
|
117
|
-
src: matchedRoute.route.src,
|
|
118
|
-
runtime: matchedRoute.route.runtime,
|
|
119
|
-
options: matchedRoute.match.params || {},
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
export default (config: QPQConfig) => {
|
|
125
|
-
const routes = qpqWebServerUtils.getAllRoutes(config);
|
|
126
|
-
const appName = qpqCoreUtils.getAppName(config);
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
[EventActionType.TransformEventParams]: getProcessTransformEventParams(appName),
|
|
130
|
-
[EventActionType.TransformResponseResult]: getProcessTransformResponseResult(config),
|
|
131
|
-
[EventActionType.AutoRespond]: getProcessAutoRespond(config),
|
|
132
|
-
[EventActionType.MatchStory]: getProcessMatchStory(routes),
|
|
133
|
-
};
|
|
134
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EventActionType,
|
|
3
|
-
MatchStoryResult,
|
|
4
|
-
EventMatchStoryActionProcessor,
|
|
5
|
-
EventTransformEventParamsActionProcessor,
|
|
6
|
-
EventTransformResponseResultActionProcessor,
|
|
7
|
-
EventAutoRespondActionProcessor,
|
|
8
|
-
actionResult,
|
|
9
|
-
actionResultError,
|
|
10
|
-
ErrorTypeEnum,
|
|
11
|
-
ScheduledEventParams,
|
|
12
|
-
} from 'quidproquo-core';
|
|
13
|
-
|
|
14
|
-
import { QPQAWSLambdaConfig, LambdaRuntimeConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
|
|
15
|
-
|
|
16
|
-
import { EventBridgeEvent, Context, APIGatewayProxyResult } from 'aws-lambda';
|
|
17
|
-
|
|
18
|
-
const getProcessTransformEventParams = (): EventTransformEventParamsActionProcessor<
|
|
19
|
-
[EventBridgeEvent<any, any>, Context],
|
|
20
|
-
ScheduledEventParams<any>
|
|
21
|
-
> => {
|
|
22
|
-
return async ({ eventParams: [eventBridgeEvent, context] }) => {
|
|
23
|
-
return actionResult({
|
|
24
|
-
time: eventBridgeEvent.time,
|
|
25
|
-
correlation: context.awsRequestId,
|
|
26
|
-
detail: eventBridgeEvent.detail,
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
// No transform
|
|
32
|
-
const getProcessTransformResponseResult = (): EventTransformResponseResultActionProcessor<any> => {
|
|
33
|
-
return async ({ response }) => actionResult<any>(response);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
// never early exit (maybe add validation?)
|
|
37
|
-
const getProcessAutoRespond = (): EventAutoRespondActionProcessor<ScheduledEventParams<any>> => {
|
|
38
|
-
return async () => actionResult(null);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const getProcessMatchStory = (
|
|
42
|
-
lambdaRuntimeConfig?: LambdaRuntimeConfig,
|
|
43
|
-
): EventMatchStoryActionProcessor<ScheduledEventParams<any>> => {
|
|
44
|
-
return async (payload) => {
|
|
45
|
-
console.log('Trying to match story');
|
|
46
|
-
console.log(JSON.stringify(lambdaRuntimeConfig));
|
|
47
|
-
if (!lambdaRuntimeConfig) {
|
|
48
|
-
return actionResultError(ErrorTypeEnum.NotFound, 'event runtime not found');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return actionResult<MatchStoryResult>({
|
|
52
|
-
src: lambdaRuntimeConfig.src,
|
|
53
|
-
runtime: lambdaRuntimeConfig.runtime,
|
|
54
|
-
options: {},
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export default (runtimeConfig: QPQAWSLambdaConfig) => {
|
|
60
|
-
return {
|
|
61
|
-
[EventActionType.TransformEventParams]: getProcessTransformEventParams(),
|
|
62
|
-
[EventActionType.TransformResponseResult]: getProcessTransformResponseResult(),
|
|
63
|
-
[EventActionType.AutoRespond]: getProcessAutoRespond(),
|
|
64
|
-
[EventActionType.MatchStory]: getProcessMatchStory(runtimeConfig.lambdaRuntimeConfig),
|
|
65
|
-
};
|
|
66
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
|
|
2
|
-
import { resolveResourceName } from '../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils';
|
|
3
|
-
import {
|
|
4
|
-
FileDeleteActionProcessor,
|
|
5
|
-
actionResult,
|
|
6
|
-
actionResultError,
|
|
7
|
-
FileActionType,
|
|
8
|
-
ErrorTypeEnum,
|
|
9
|
-
} from 'quidproquo-core';
|
|
10
|
-
import { deleteFiles } from '../../../logic/s3/s3Utils';
|
|
11
|
-
|
|
12
|
-
const getProcessFileDelete = (runtimeConfig: QPQAWSLambdaConfig): FileDeleteActionProcessor => {
|
|
13
|
-
return async ({ drive, filepaths }) => {
|
|
14
|
-
const s3BucketName = resolveResourceName(drive, runtimeConfig);
|
|
15
|
-
const errored = await deleteFiles(s3BucketName, filepaths);
|
|
16
|
-
|
|
17
|
-
// errored deletes are a graceful success ~ Retry
|
|
18
|
-
// if (errored.length > 0) {
|
|
19
|
-
// return actionResultError(
|
|
20
|
-
// ErrorTypeEnum.GenericError,
|
|
21
|
-
// `Could not delete files ${errored.length}`,
|
|
22
|
-
// );
|
|
23
|
-
// }
|
|
24
|
-
|
|
25
|
-
return actionResult(errored);
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default (runtimeConfig: QPQAWSLambdaConfig) => ({
|
|
30
|
-
[FileActionType.Delete]: getProcessFileDelete(runtimeConfig),
|
|
31
|
-
});
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
|
|
2
|
-
import { resolveResourceName } from '../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils';
|
|
3
|
-
import { FileExistsActionProcessor, actionResult, FileActionType } from 'quidproquo-core';
|
|
4
|
-
import { objectExists } from '../../../logic/s3/s3Utils';
|
|
5
|
-
|
|
6
|
-
const getProcessFileExists = (runtimeConfig: QPQAWSLambdaConfig): FileExistsActionProcessor => {
|
|
7
|
-
return async ({ drive, filepath }) => {
|
|
8
|
-
const s3BucketName = resolveResourceName(drive, runtimeConfig);
|
|
9
|
-
|
|
10
|
-
return actionResult(await objectExists(s3BucketName, filepath));
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export default (runtimeConfig: QPQAWSLambdaConfig) => ({
|
|
15
|
-
[FileActionType.Exists]: getProcessFileExists(runtimeConfig),
|
|
16
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
|
|
2
|
-
import { resolveResourceName } from '../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils';
|
|
3
|
-
import { FileListDirectoryActionProcessor, actionResult, FileActionType } from 'quidproquo-core';
|
|
4
|
-
import { listFiles } from '../../../logic/s3/s3Utils';
|
|
5
|
-
|
|
6
|
-
const getProcessFileListDirectory = (
|
|
7
|
-
runtimeConfig: QPQAWSLambdaConfig,
|
|
8
|
-
): FileListDirectoryActionProcessor => {
|
|
9
|
-
return async ({ drive, folderPath, maxFiles, pageToken }) => {
|
|
10
|
-
const s3BucketName = resolveResourceName(drive, runtimeConfig);
|
|
11
|
-
const s3FileList = await listFiles(s3BucketName, folderPath, maxFiles, pageToken);
|
|
12
|
-
|
|
13
|
-
// Add the drive onto the list
|
|
14
|
-
const fileInfos = s3FileList.fileInfos.map((s3fi) => ({
|
|
15
|
-
...s3fi,
|
|
16
|
-
drive: drive,
|
|
17
|
-
}));
|
|
18
|
-
|
|
19
|
-
return actionResult({
|
|
20
|
-
fileInfos,
|
|
21
|
-
pageToken: s3FileList.pageToken,
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export default (runtimeConfig: QPQAWSLambdaConfig) => ({
|
|
27
|
-
[FileActionType.ListDirectory]: getProcessFileListDirectory(runtimeConfig),
|
|
28
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
|
|
2
|
-
import { resolveResourceName } from '../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils';
|
|
3
|
-
import { FileReadTextContentsActionProcessor, actionResult, FileActionType } from 'quidproquo-core';
|
|
4
|
-
import { readTextFile } from '../../../logic/s3/s3Utils';
|
|
5
|
-
|
|
6
|
-
const getProcessFileReadTextContents = (
|
|
7
|
-
runtimeConfig: QPQAWSLambdaConfig,
|
|
8
|
-
): FileReadTextContentsActionProcessor => {
|
|
9
|
-
return async ({ drive, filepath }) => {
|
|
10
|
-
const s3BucketName = resolveResourceName(drive, runtimeConfig);
|
|
11
|
-
|
|
12
|
-
return actionResult(await readTextFile(s3BucketName, filepath));
|
|
13
|
-
};
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export default (runtimeConfig: QPQAWSLambdaConfig) => ({
|
|
17
|
-
[FileActionType.ReadTextContents]: getProcessFileReadTextContents(runtimeConfig),
|
|
18
|
-
});
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
|
|
2
|
-
import { resolveResourceName } from '../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils';
|
|
3
|
-
import {
|
|
4
|
-
FileWriteTextContentsActionProcessor,
|
|
5
|
-
actionResult,
|
|
6
|
-
FileActionType,
|
|
7
|
-
} from 'quidproquo-core';
|
|
8
|
-
import { writeTextFile } from '../../../logic/s3/s3Utils';
|
|
9
|
-
|
|
10
|
-
const getProcessFileWriteTextContents = (
|
|
11
|
-
runtimeConfig: QPQAWSLambdaConfig,
|
|
12
|
-
): FileWriteTextContentsActionProcessor => {
|
|
13
|
-
return async ({ drive, filepath, data }) => {
|
|
14
|
-
const s3BucketName = resolveResourceName(drive, runtimeConfig);
|
|
15
|
-
await writeTextFile(s3BucketName, filepath, data);
|
|
16
|
-
|
|
17
|
-
return actionResult(void 0);
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export default (runtimeConfig: QPQAWSLambdaConfig) => ({
|
|
22
|
-
[FileActionType.WriteTextContents]: getProcessFileWriteTextContents(runtimeConfig),
|
|
23
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { QPQAWSLambdaConfig } from '../../../runtimeConfig/QPQAWSLambdaConfig';
|
|
2
|
-
|
|
3
|
-
import getFileDeleteActionProcessor from './getFileDeleteActionProcessor';
|
|
4
|
-
import getFileExistsActionProcessor from './getFileExistsActionProcessor';
|
|
5
|
-
import getFileListDirectoryActionProcessor from './getFileListDirectoryActionProcessor';
|
|
6
|
-
import getFileReadTextContentsActionProcessor from './getFileReadTextContentsActionProcessor';
|
|
7
|
-
import getFileWriteTextContentsActionProcessor from './getFileWriteTextContentsActionProcessor';
|
|
8
|
-
|
|
9
|
-
export default (runtimeConfig: QPQAWSLambdaConfig) => ({
|
|
10
|
-
...getFileDeleteActionProcessor(runtimeConfig),
|
|
11
|
-
...getFileExistsActionProcessor(runtimeConfig),
|
|
12
|
-
...getFileListDirectoryActionProcessor(runtimeConfig),
|
|
13
|
-
...getFileReadTextContentsActionProcessor(runtimeConfig),
|
|
14
|
-
...getFileWriteTextContentsActionProcessor(runtimeConfig),
|
|
15
|
-
});
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
SystemActionType,
|
|
3
|
-
QPQConfig,
|
|
4
|
-
qpqCoreUtils,
|
|
5
|
-
SystemExecuteStoryActionPayload,
|
|
6
|
-
StorySession,
|
|
7
|
-
createRuntime,
|
|
8
|
-
SystemExecuteStoryActionProcessor,
|
|
9
|
-
actionResultError,
|
|
10
|
-
ErrorTypeEnum,
|
|
11
|
-
actionResult,
|
|
12
|
-
ActionProcessorList,
|
|
13
|
-
} from 'quidproquo-core';
|
|
14
|
-
|
|
15
|
-
import { randomGuid } from './../../../awsLambdaUtils';
|
|
16
|
-
import { DynamicModuleLoader } from '../../../types/DynamicLoader';
|
|
17
|
-
|
|
18
|
-
export const getDateNow = () => new Date().toISOString();
|
|
19
|
-
|
|
20
|
-
const getProcessExecuteStory = <T extends Array<any>>(
|
|
21
|
-
dynamicModuleLoader: DynamicModuleLoader,
|
|
22
|
-
): SystemExecuteStoryActionProcessor<T> => {
|
|
23
|
-
return async (
|
|
24
|
-
payload: SystemExecuteStoryActionPayload<T>,
|
|
25
|
-
session: StorySession,
|
|
26
|
-
actionProcessors: ActionProcessorList,
|
|
27
|
-
): Promise<any> => {
|
|
28
|
-
let module = await dynamicModuleLoader(payload.src);
|
|
29
|
-
if (module === null) {
|
|
30
|
-
return actionResultError(ErrorTypeEnum.NotFound, `Module not found [${payload.src}]`);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const story = module[payload.runtime];
|
|
34
|
-
if (!story) {
|
|
35
|
-
return actionResultError(
|
|
36
|
-
ErrorTypeEnum.NotFound,
|
|
37
|
-
`[${payload.runtime}] not found in module [${payload.src}]`,
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const logger = async (result: any) => {
|
|
42
|
-
// return await addResult(service, getDateNow(), payload.params[0][0].path, 'user-route', payload.src, payload.runtime, result);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const resolveStory = createRuntime(session, actionProcessors, getDateNow, logger, randomGuid);
|
|
46
|
-
const storyResult = await resolveStory(story, payload.params);
|
|
47
|
-
|
|
48
|
-
if (storyResult.error) {
|
|
49
|
-
return actionResultError(
|
|
50
|
-
storyResult.error.errorType,
|
|
51
|
-
`story error! in ${payload.src}::${payload.runtime} -> [${storyResult.error.errorText}]`,
|
|
52
|
-
storyResult.error.errorStack,
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return actionResult({
|
|
57
|
-
result: storyResult.result,
|
|
58
|
-
session: storyResult.session,
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export default (dynamicModuleLoader: DynamicModuleLoader) => {
|
|
64
|
-
return {
|
|
65
|
-
[SystemActionType.ExecuteStory]: getProcessExecuteStory(dynamicModuleLoader),
|
|
66
|
-
};
|
|
67
|
-
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import getExecuteStoryActionProcessor from './getExecuteStoryActionProcessor';
|
|
2
|
-
import { DynamicModuleLoader } from '../../../types/DynamicLoader';
|
|
3
|
-
|
|
4
|
-
export default (dynamicModuleLoader: DynamicModuleLoader) => ({
|
|
5
|
-
...getExecuteStoryActionProcessor(dynamicModuleLoader),
|
|
6
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { SSMClient, GetParameterCommand } from '@aws-sdk/client-ssm';
|
|
2
|
-
|
|
3
|
-
const smClient = new SSMClient({});
|
|
4
|
-
|
|
5
|
-
export const getParameter = async (parameterName: string): Promise<string> => {
|
|
6
|
-
const response = await smClient.send(
|
|
7
|
-
new GetParameterCommand({
|
|
8
|
-
Name: parameterName,
|
|
9
|
-
}),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
return response.Parameter?.Value || '';
|
|
13
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { SSMClient, GetParametersCommand } from '@aws-sdk/client-ssm';
|
|
2
|
-
|
|
3
|
-
const smClient = new SSMClient({});
|
|
4
|
-
|
|
5
|
-
export const getParameters = async (parameterNames: string[]): Promise<string[]> => {
|
|
6
|
-
const response = await smClient.send(
|
|
7
|
-
new GetParametersCommand({
|
|
8
|
-
Names: parameterNames,
|
|
9
|
-
}),
|
|
10
|
-
);
|
|
11
|
-
|
|
12
|
-
const resolvedParams = response.Parameters || [];
|
|
13
|
-
|
|
14
|
-
return parameterNames.map((pn) => resolvedParams.find((rp) => rp.Name == pn)?.Value || '');
|
|
15
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { DeleteObjectsCommand, DeleteObjectsCommandInput } from '@aws-sdk/client-s3';
|
|
2
|
-
|
|
3
|
-
import s3Client from './s3Client';
|
|
4
|
-
|
|
5
|
-
export const deleteFiles = async (drive: string, filepaths: string[]): Promise<string[]> => {
|
|
6
|
-
const bucketParams: DeleteObjectsCommandInput = {
|
|
7
|
-
Bucket: drive,
|
|
8
|
-
Delete: {
|
|
9
|
-
Quiet: true,
|
|
10
|
-
Objects: filepaths.map((fp) => ({ Key: fp })),
|
|
11
|
-
},
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const response = await s3Client.send(new DeleteObjectsCommand(bucketParams));
|
|
15
|
-
|
|
16
|
-
return (response.Errors || []).map((e) => e.Key || '');
|
|
17
|
-
};
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { ListObjectsV2Command, ListObjectsV2CommandInput } from '@aws-sdk/client-s3';
|
|
2
|
-
import { filePathDelimiter } from 'quidproquo-core';
|
|
3
|
-
import s3Client from './s3Client';
|
|
4
|
-
|
|
5
|
-
export interface S3FileInfo {
|
|
6
|
-
filepath: string;
|
|
7
|
-
isDir: boolean;
|
|
8
|
-
hashMd5?: string;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export interface S3FileList {
|
|
12
|
-
fileInfos: S3FileInfo[];
|
|
13
|
-
pageToken?: string;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const listFiles = async (
|
|
17
|
-
drive: string,
|
|
18
|
-
folder: string = '',
|
|
19
|
-
maxKeys: number = 1000,
|
|
20
|
-
pageToken?: string,
|
|
21
|
-
): Promise<S3FileList> => {
|
|
22
|
-
const validatedPrefix = `${folder}${
|
|
23
|
-
folder.endsWith(filePathDelimiter) || !folder ? '' : filePathDelimiter
|
|
24
|
-
}`;
|
|
25
|
-
const bucketParams: ListObjectsV2CommandInput = {
|
|
26
|
-
Bucket: drive,
|
|
27
|
-
Delimiter: filePathDelimiter,
|
|
28
|
-
Prefix: validatedPrefix,
|
|
29
|
-
ContinuationToken: pageToken,
|
|
30
|
-
MaxKeys: maxKeys,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
// Declare truncated as a flag that the while loop is based on.
|
|
34
|
-
let files: S3FileInfo[] = [];
|
|
35
|
-
|
|
36
|
-
const response = await s3Client.send(new ListObjectsV2Command(bucketParams));
|
|
37
|
-
|
|
38
|
-
if (response.CommonPrefixes && !bucketParams.ContinuationToken) {
|
|
39
|
-
files = [
|
|
40
|
-
...files,
|
|
41
|
-
...response.CommonPrefixes.filter((cp) => !!cp.Prefix).map((cp) => ({
|
|
42
|
-
filepath: cp.Prefix!,
|
|
43
|
-
drive: drive,
|
|
44
|
-
isDir: true,
|
|
45
|
-
})),
|
|
46
|
-
];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
files = [
|
|
50
|
-
...files,
|
|
51
|
-
...(response.Contents || [])
|
|
52
|
-
.filter((c) => !!c.Key && c.Key != folder)
|
|
53
|
-
.map(
|
|
54
|
-
(item): S3FileInfo => ({
|
|
55
|
-
filepath: item.Key!,
|
|
56
|
-
isDir: item.Key!.endsWith(filePathDelimiter),
|
|
57
|
-
hashMd5: item.ETag,
|
|
58
|
-
}),
|
|
59
|
-
),
|
|
60
|
-
];
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
fileInfos: files,
|
|
64
|
-
pageToken: response.NextContinuationToken,
|
|
65
|
-
};
|
|
66
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
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,17 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,15 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
};
|