quidproquo-actionprocessor-awslambda 0.0.104 → 0.0.106

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.
@@ -3,6 +3,7 @@ export declare const getGlobalConfigRuntimeResourceName: (resourceName: string,
3
3
  export declare const getGlobalQpqRuntimeResourceName: (resourceName: string, application: string, environment: string, feature?: string, resourceType?: string) => string;
4
4
  export declare const getConfigRuntimeResourceName: (resourceName: string, application: string, service: string, environment: string, feature?: string) => string;
5
5
  export declare const getConfigRuntimeResourceNameFromConfig: (resourceName: string, qpqConfig: QPQConfig) => string;
6
+ export declare const getConfigRuntimeResourceNameFromConfigWithServiceOverride: (resourceName: string, qpqConfig: QPQConfig, serviceOverride?: string) => string;
6
7
  export declare const getQpqRuntimeResourceName: (resourceName: string, application: string, service: string, environment: string, feature?: string, resourceType?: string) => string;
7
8
  export declare const getQpqRuntimeResourceNameFromConfig: (resourceName: string, qpqConfig: QPQConfig, resourceType?: string) => string;
8
9
  export declare const getCFExportNameUserPoolIdFromConfig: (userDirectoryName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCFExportNameDistributionIdArnFromConfig = exports.getCFExportNameSnsTopicArnFromConfig = exports.getCFExportNameApiKeyIdFromConfig = exports.getCFExportNameUserPoolClientIdFromConfig = exports.getCFExportNameUserPoolIdFromConfig = exports.getQpqRuntimeResourceNameFromConfig = exports.getQpqRuntimeResourceName = exports.getConfigRuntimeResourceNameFromConfig = exports.getConfigRuntimeResourceName = exports.getGlobalQpqRuntimeResourceName = exports.getGlobalConfigRuntimeResourceName = void 0;
3
+ exports.getCFExportNameDistributionIdArnFromConfig = exports.getCFExportNameSnsTopicArnFromConfig = exports.getCFExportNameApiKeyIdFromConfig = exports.getCFExportNameUserPoolClientIdFromConfig = exports.getCFExportNameUserPoolIdFromConfig = exports.getQpqRuntimeResourceNameFromConfig = exports.getQpqRuntimeResourceName = exports.getConfigRuntimeResourceNameFromConfigWithServiceOverride = exports.getConfigRuntimeResourceNameFromConfig = exports.getConfigRuntimeResourceName = exports.getGlobalQpqRuntimeResourceName = exports.getGlobalConfigRuntimeResourceName = void 0;
4
4
  const quidproquo_core_1 = require("quidproquo-core");
5
5
  const getGlobalConfigRuntimeResourceName = (resourceName, application, environment, feature) => {
6
6
  const baseName = `${resourceName}-${application}-${environment}`;
@@ -31,6 +31,14 @@ const getConfigRuntimeResourceNameFromConfig = (resourceName, qpqConfig) => {
31
31
  return (0, exports.getConfigRuntimeResourceName)(resourceName, application, service, environment, feature);
32
32
  };
33
33
  exports.getConfigRuntimeResourceNameFromConfig = getConfigRuntimeResourceNameFromConfig;
34
+ const getConfigRuntimeResourceNameFromConfigWithServiceOverride = (resourceName, qpqConfig, serviceOverride) => {
35
+ const application = quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
36
+ const service = serviceOverride || quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
37
+ const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
38
+ const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
39
+ return (0, exports.getConfigRuntimeResourceName)(resourceName, application, service, environment, feature);
40
+ };
41
+ exports.getConfigRuntimeResourceNameFromConfigWithServiceOverride = getConfigRuntimeResourceNameFromConfigWithServiceOverride;
34
42
  const getQpqRuntimeResourceName = (resourceName, application, service, environment, feature, resourceType = '') => {
35
43
  const name = (0, exports.getConfigRuntimeResourceName)(resourceName, application, service, environment, feature);
36
44
  return `${name}-qpq${resourceType}`;
@@ -13,6 +13,7 @@ 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 isAuthValid_1 = require("./utils/isAuthValid");
16
+ const parseMultipartFormData_1 = require("./utils/parseMultipartFormData");
16
17
  const transformHttpEventHeadersToAPIGatewayProxyResultHeaders = (headers) => {
17
18
  return Object.keys(headers)
18
19
  .filter((header) => !!headers[header])
@@ -31,6 +32,11 @@ const getProcessTransformEventParams = (serviceName) => {
31
32
  sourceIp: apiGatewayEvent.requestContext.identity.sourceIp,
32
33
  isBase64Encoded: apiGatewayEvent.isBase64Encoded,
33
34
  };
35
+ // Transform the body if its a multipart/form-data
36
+ if ((quidproquo_webserver_1.qpqWebServerUtils.getHeaderValue('Content-Type', apiGatewayEvent.headers) || '').startsWith('multipart/form-data') &&
37
+ apiGatewayEvent.body) {
38
+ transformedEventParams.files = yield (0, parseMultipartFormData_1.parseMultipartFormData)(apiGatewayEvent);
39
+ }
34
40
  console.log(JSON.stringify(transformedEventParams, null, 2));
35
41
  return (0, quidproquo_core_1.actionResult)(transformedEventParams);
36
42
  });
@@ -0,0 +1,2 @@
1
+ import { QPQBinaryData } from 'quidproquo-core';
2
+ export declare const parseMultipartFormData: (event: import("aws-lambda").APIGatewayProxyEvent) => Promise<QPQBinaryData[]>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseMultipartFormData = void 0;
4
+ // can i import this normally?
5
+ const Busboy = require("busboy");
6
+ const parseMultipartFormData = (event) => new Promise((resolve, reject) => {
7
+ const busboy = Busboy({
8
+ headers: {
9
+ 'content-type': event.headers['content-type'] || event.headers['Content-Type'],
10
+ },
11
+ });
12
+ const result = {
13
+ files: [],
14
+ fields: {},
15
+ };
16
+ busboy.on('file', (name, file, info) => {
17
+ let fileBuffer = Buffer.alloc(0);
18
+ file.on('data', (data) => {
19
+ fileBuffer = Buffer.concat([fileBuffer, data]); // Concatenate the new data to the existing buffer
20
+ });
21
+ file.on('end', () => {
22
+ if (fileBuffer.length > 0) {
23
+ result.files.push({
24
+ filename: info.filename,
25
+ contentType: info.mimeType,
26
+ encoding: info.encoding,
27
+ name: name,
28
+ content: fileBuffer,
29
+ });
30
+ }
31
+ });
32
+ });
33
+ busboy.on('field', (name, value) => {
34
+ result.fields[name] = value;
35
+ });
36
+ busboy.on('error', (error) => {
37
+ reject(error);
38
+ });
39
+ busboy.on('finish', () => {
40
+ const qpqBinaryFiles = result.files.map((f) => ({
41
+ filename: f.filename,
42
+ mimetype: f.contentType,
43
+ base64Data: f.content.toString('base64'),
44
+ }));
45
+ resolve(qpqBinaryFiles);
46
+ });
47
+ busboy.write(event.body, event.isBase64Encoded ? 'base64' : 'binary');
48
+ busboy.end();
49
+ });
50
+ exports.parseMultipartFormData = parseMultipartFormData;
@@ -10,12 +10,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
14
13
  const quidproquo_core_2 = require("quidproquo-core");
15
14
  const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
+ const utils_1 = require("./utils");
16
16
  const getProcessFileDelete = (qpqConfig) => {
17
17
  return ({ drive, filepaths }) => __awaiter(void 0, void 0, void 0, function* () {
18
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, qpqConfig);
18
+ const s3BucketName = (0, utils_1.resolveStorageDriveBucketName)(drive, qpqConfig);
19
19
  const errored = yield (0, s3Utils_1.deleteFiles)(s3BucketName, filepaths, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig));
20
20
  // errored deletes are a graceful success ~ Retry
21
21
  // if (errored.length > 0) {
@@ -10,11 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
+ const utils_1 = require("./utils");
14
14
  const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
15
  const getProcessFileExists = (qpqConfig) => {
16
16
  return ({ drive, filepath }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, qpqConfig);
17
+ const s3BucketName = (0, utils_1.resolveStorageDriveBucketName)(drive, qpqConfig);
18
18
  return (0, quidproquo_core_1.actionResult)(yield (0, s3Utils_1.objectExists)(s3BucketName, filepath, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig)));
19
19
  });
20
20
  };
@@ -10,14 +10,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
+ const utils_1 = require("./utils");
14
14
  const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
15
  const getProcessFileListDirectory = (qpqConfig) => {
16
16
  return ({ drive, folderPath, maxFiles, pageToken }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, qpqConfig);
17
+ const xServiceDriveName = (0, utils_1.resolveCrossServiceDriveName)(drive);
18
+ const s3BucketName = (0, utils_1.resolveStorageDriveBucketName)(drive, qpqConfig);
18
19
  const s3FileList = yield (0, s3Utils_1.listFiles)(s3BucketName, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig), folderPath, maxFiles, pageToken);
19
20
  // Add the drive onto the list
20
- const fileInfos = s3FileList.fileInfos.map((s3fi) => (Object.assign(Object.assign({}, s3fi), { drive: drive })));
21
+ const fileInfos = s3FileList.fileInfos.map((s3fi) => (Object.assign(Object.assign({}, s3fi), { drive: xServiceDriveName })));
21
22
  return (0, quidproquo_core_1.actionResult)({
22
23
  fileInfos,
23
24
  pageToken: s3FileList.pageToken,
@@ -10,11 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
+ const utils_1 = require("./utils");
14
14
  const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
15
  const getProcessFileReadBinaryContents = (qpqConfig) => {
16
16
  return ({ drive, filepath }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, qpqConfig);
17
+ const s3BucketName = (0, utils_1.resolveStorageDriveBucketName)(drive, qpqConfig);
18
18
  return (0, quidproquo_core_1.actionResult)(yield (0, s3Utils_1.readBinaryFile)(s3BucketName, filepath, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig)));
19
19
  });
20
20
  };
@@ -10,11 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
+ const utils_1 = require("./utils");
14
14
  const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
15
  const getProcessFileReadTextContents = (qpqConfig) => {
16
16
  return ({ drive, filepath }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, qpqConfig);
17
+ const s3BucketName = (0, utils_1.resolveStorageDriveBucketName)(drive, qpqConfig);
18
18
  return (0, quidproquo_core_1.actionResult)(yield (0, s3Utils_1.readTextFile)(s3BucketName, filepath, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig)));
19
19
  });
20
20
  };
@@ -10,11 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
+ const utils_1 = require("./utils");
14
14
  const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
15
  const getProcessFileWriteBinaryContents = (qpqConfig) => {
16
16
  return ({ drive, filepath, data }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, qpqConfig);
17
+ const s3BucketName = (0, utils_1.resolveStorageDriveBucketName)(drive, qpqConfig);
18
18
  yield (0, s3Utils_1.writeBinaryFile)(s3BucketName, filepath, data, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig));
19
19
  return (0, quidproquo_core_1.actionResult)(void 0);
20
20
  });
@@ -10,11 +10,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const quidproquo_core_1 = require("quidproquo-core");
13
- const qpqAwsLambdaRuntimeConfigUtils_1 = require("../../../runtimeConfig/qpqAwsLambdaRuntimeConfigUtils");
13
+ const utils_1 = require("./utils");
14
14
  const s3Utils_1 = require("../../../logic/s3/s3Utils");
15
15
  const getProcessFileWriteTextContents = (qpqConfig) => {
16
16
  return ({ drive, filepath, data }) => __awaiter(void 0, void 0, void 0, function* () {
17
- const s3BucketName = (0, qpqAwsLambdaRuntimeConfigUtils_1.resolveResourceName)(drive, qpqConfig);
17
+ const s3BucketName = (0, utils_1.resolveStorageDriveBucketName)(drive, qpqConfig);
18
18
  yield (0, s3Utils_1.writeTextFile)(s3BucketName, filepath, data, quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig));
19
19
  return (0, quidproquo_core_1.actionResult)(void 0);
20
20
  });
@@ -0,0 +1 @@
1
+ export * from './resolveStorageDriveBucketName';
@@ -0,0 +1,17 @@
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("./resolveStorageDriveBucketName"), exports);
@@ -0,0 +1,3 @@
1
+ import { QPQConfig, DriveName, CrossServiceDriveName } from 'quidproquo-core';
2
+ export declare const resolveCrossServiceDriveName: (drive: DriveName) => CrossServiceDriveName;
3
+ export declare const resolveStorageDriveBucketName: (drive: DriveName, qpqConfig: QPQConfig) => string;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolveStorageDriveBucketName = exports.resolveCrossServiceDriveName = void 0;
4
+ const awsNamingUtils_1 = require("../../../../awsNamingUtils");
5
+ const resolveCrossServiceDriveName = (drive) => {
6
+ if (typeof drive === 'string') {
7
+ return {
8
+ name: drive,
9
+ };
10
+ }
11
+ return drive;
12
+ };
13
+ exports.resolveCrossServiceDriveName = resolveCrossServiceDriveName;
14
+ const resolveStorageDriveBucketName = (drive, qpqConfig) => {
15
+ const xServiceDriveName = (0, exports.resolveCrossServiceDriveName)(drive);
16
+ return (0, awsNamingUtils_1.getConfigRuntimeResourceNameFromConfigWithServiceOverride)(xServiceDriveName.name, qpqConfig, xServiceDriveName.service);
17
+ };
18
+ exports.resolveStorageDriveBucketName = resolveStorageDriveBucketName;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.104",
3
+ "version": "0.0.106",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
@@ -38,6 +38,7 @@
38
38
  "@aws-sdk/client-ssm": "^3.278.0",
39
39
  "aws-jwt-verify": "^3.4.0",
40
40
  "aws-sdk": "^2.1322.0",
41
+ "busboy": "^1.6.0",
41
42
  "jsonwebtoken": "^9.0.0",
42
43
  "jwks-rsa": "^3.0.1",
43
44
  "lodash": "^4.17.21",
@@ -48,6 +49,7 @@
48
49
  },
49
50
  "devDependencies": {
50
51
  "@types/aws-lambda": "^8.10.109",
52
+ "@types/busboy": "^1.5.0",
51
53
  "@types/jsonwebtoken": "^9.0.2",
52
54
  "@types/lodash": "^4.14.194",
53
55
  "@types/node": "^18.11.9",