quidproquo-actionprocessor-awslambda 0.0.79 → 0.0.81

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.
@@ -9,3 +9,4 @@ export declare const getCFExportNameUserPoolIdFromConfig: (userDirectoryName: st
9
9
  export declare const getCFExportNameUserPoolClientIdFromConfig: (userDirectoryName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
10
10
  export declare const getCFExportNameApiKeyIdFromConfig: (apiKeyName: string, qpqConfig: QPQConfig, serviceOverride?: string, applicationOverride?: string) => string;
11
11
  export declare const getCFExportNameSnsTopicArnFromConfig: (eventBusName: string, qpqConfig: QPQConfig, applicationOverride?: string) => string;
12
+ export declare const getCFExportNameDistributionIdArnFromConfig: (webEntryName: 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.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.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}`;
@@ -75,3 +75,11 @@ const getCFExportNameSnsTopicArnFromConfig = (eventBusName, qpqConfig, applicati
75
75
  return (0, exports.getGlobalQpqRuntimeResourceName)(eventBusName, application, environment, feature, 'sns-topic-arn-export');
76
76
  };
77
77
  exports.getCFExportNameSnsTopicArnFromConfig = getCFExportNameSnsTopicArnFromConfig;
78
+ const getCFExportNameDistributionIdArnFromConfig = (webEntryName, qpqConfig, serviceOverride, applicationOverride) => {
79
+ const application = applicationOverride || quidproquo_core_1.qpqCoreUtils.getApplicationName(qpqConfig);
80
+ const service = serviceOverride || quidproquo_core_1.qpqCoreUtils.getApplicationModuleName(qpqConfig);
81
+ const environment = quidproquo_core_1.qpqCoreUtils.getApplicationModuleEnvironment(qpqConfig);
82
+ const feature = quidproquo_core_1.qpqCoreUtils.getApplicationModuleFeature(qpqConfig);
83
+ return (0, exports.getQpqRuntimeResourceName)(webEntryName, application, service, environment, feature, 'distribution-id-export');
84
+ };
85
+ exports.getCFExportNameDistributionIdArnFromConfig = getCFExportNameDistributionIdArnFromConfig;
@@ -1 +1,2 @@
1
1
  export * from './core';
2
+ export * from './webserver';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./core"), exports);
18
+ __exportStar(require("./webserver"), exports);
@@ -0,0 +1 @@
1
+ export { default as getWebEntryActionProcessor } from './webEntry';
@@ -0,0 +1,8 @@
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
+ exports.getWebEntryActionProcessor = void 0;
7
+ var webEntry_1 = require("./webEntry");
8
+ Object.defineProperty(exports, "getWebEntryActionProcessor", { enumerable: true, get: function () { return __importDefault(webEntry_1).default; } });
@@ -0,0 +1,6 @@
1
+ import { QPQConfig } from 'quidproquo-core';
2
+ import { WebEntryInvalidateCacheActionProcessor } from 'quidproquo-webserver';
3
+ declare const _default: (qpqConfig: QPQConfig) => {
4
+ "@quidproquo-webserver/WebEntry/InvalidateCache": WebEntryInvalidateCacheActionProcessor;
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 quidproquo_core_1 = require("quidproquo-core");
13
+ const quidproquo_webserver_1 = require("quidproquo-webserver");
14
+ const awsNamingUtils_1 = require("../../../awsNamingUtils");
15
+ const invalidateCache_1 = require("../../../logic/cloudFront/invalidateCache");
16
+ const getExportedValue_1 = require("../../../logic/cloudformation/getExportedValue");
17
+ const getWebEntryInvalidteCacheActionProcessor = (qpqConfig) => {
18
+ return ({ paths, webEntryName }) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
20
+ const distributionId = yield (0, getExportedValue_1.getExportedValue)((0, awsNamingUtils_1.getCFExportNameDistributionIdArnFromConfig)(webEntryName, qpqConfig), region);
21
+ yield (0, invalidateCache_1.invalidateCache)(distributionId, region, paths);
22
+ return (0, quidproquo_core_1.actionResult)(void 0);
23
+ });
24
+ };
25
+ exports.default = (qpqConfig) => {
26
+ return {
27
+ [quidproquo_webserver_1.WebEntryActionType.InvalidateCache]: getWebEntryInvalidteCacheActionProcessor(qpqConfig),
28
+ };
29
+ };
@@ -0,0 +1,5 @@
1
+ import { QPQConfig } from 'quidproquo-core';
2
+ declare const _default: (qpqConfig: QPQConfig) => {
3
+ "@quidproquo-webserver/WebEntry/InvalidateCache": import("quidproquo-webserver/lib").WebEntryInvalidateCacheActionProcessor;
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 getWebEntryInvalidateCacheActionProcessor_1 = __importDefault(require("./getWebEntryInvalidateCacheActionProcessor"));
7
+ exports.default = (qpqConfig) => (Object.assign({}, (0, getWebEntryInvalidateCacheActionProcessor_1.default)(qpqConfig)));
@@ -0,0 +1,2 @@
1
+ export declare const getInvalidationCallerReference: (paths: string[]) => string;
2
+ export declare const invalidateCache: (distributionId: string, region: string, paths: string[]) => Promise<void>;
@@ -0,0 +1,40 @@
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.invalidateCache = exports.getInvalidationCallerReference = void 0;
16
+ const client_cloudfront_1 = require("@aws-sdk/client-cloudfront");
17
+ const crypto_1 = __importDefault(require("crypto"));
18
+ const getInvalidationCallerReference = (paths) => {
19
+ const allPaths = paths.join('');
20
+ // All paths as a hash
21
+ const allPathHash = crypto_1.default.createHash('md5').update(allPaths).digest('hex');
22
+ // Unique key is the now time with all paths hash
23
+ return allPathHash + new Date().toISOString();
24
+ };
25
+ exports.getInvalidationCallerReference = getInvalidationCallerReference;
26
+ const invalidateCache = (distributionId, region, paths) => __awaiter(void 0, void 0, void 0, function* () {
27
+ const cloudformation = new client_cloudfront_1.CloudFrontClient({ region });
28
+ const input = {
29
+ DistributionId: distributionId,
30
+ InvalidationBatch: {
31
+ Paths: {
32
+ Quantity: paths.length,
33
+ Items: paths,
34
+ },
35
+ CallerReference: (0, exports.getInvalidationCallerReference)(paths),
36
+ },
37
+ };
38
+ yield cloudformation.send(new client_cloudfront_1.CreateInvalidationCommand(input));
39
+ });
40
+ exports.invalidateCache = invalidateCache;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.79",
3
+ "version": "0.0.81",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
@@ -27,6 +27,7 @@
27
27
  "dependencies": {
28
28
  "@aws-sdk/client-api-gateway": "^3.278.0",
29
29
  "@aws-sdk/client-cloudformation": "^3.278.0",
30
+ "@aws-sdk/client-cloudfront": "^3.289.0",
30
31
  "@aws-sdk/client-cognito-identity-provider": "^3.278.0",
31
32
  "@aws-sdk/client-s3": "^3.278.0",
32
33
  "@aws-sdk/client-secrets-manager": "^3.278.0",