quidproquo-actionprocessor-awslambda 0.0.102 → 0.0.103

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.
@@ -14,7 +14,6 @@ const awsNamingUtils_1 = require("../../../awsNamingUtils");
14
14
  const dynamo_1 = require("../../../logic/dynamo");
15
15
  const getProcessKeyValueStoreUpsert = (qpqConfig) => {
16
16
  return ({ keyValueStoreName, item, options }) => __awaiter(void 0, void 0, void 0, function* () {
17
- console.log('HERE!');
18
17
  const dynamoTableName = (0, awsNamingUtils_1.getQpqRuntimeResourceNameFromConfig)(keyValueStoreName, qpqConfig, 'kvs');
19
18
  const region = quidproquo_core_1.qpqCoreUtils.getApplicationModuleDeployRegion(qpqConfig);
20
19
  const storeConfig = quidproquo_core_1.qpqCoreUtils.getKeyValueStoreByName(qpqConfig, keyValueStoreName);
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Memoizes a function by caching its return values.
3
+ * @param func The function to memoize.
4
+ * @param ttlInSeconds Time-to-live for the cached values in seconds.
5
+ * @returns The memoized function.
6
+ */
7
+ export declare const memoFunc: <T extends (...args: any[]) => any>(func: T, ttlInSeconds?: number) => T;
@@ -0,0 +1,35 @@
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.memoFunc = void 0;
7
+ const node_cache_1 = __importDefault(require("node-cache"));
8
+ const cache = new WeakMap();
9
+ /**
10
+ * Memoizes a function by caching its return values.
11
+ * @param func The function to memoize.
12
+ * @param ttlInSeconds Time-to-live for the cached values in seconds.
13
+ * @returns The memoized function.
14
+ */
15
+ const memoFunc = (func, ttlInSeconds = 3600) => {
16
+ return ((...args) => {
17
+ // Check if the function has a corresponding cache entry
18
+ if (!cache.has(func)) {
19
+ // Create a new NodeCache instance and store it in the cache
20
+ cache.set(func, new node_cache_1.default({ stdTTL: ttlInSeconds }));
21
+ }
22
+ const cacheKey = JSON.stringify(args);
23
+ const nodeCache = cache.get(func);
24
+ const cachedValue = nodeCache.get(cacheKey);
25
+ if (cachedValue) {
26
+ return cachedValue;
27
+ }
28
+ // Call the original function if the value is not cached
29
+ const result = func(...args);
30
+ // Cache the result for future use
31
+ nodeCache.set(cacheKey, result);
32
+ return result;
33
+ });
34
+ };
35
+ exports.memoFunc = memoFunc;
@@ -11,7 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getExportedValue = void 0;
13
13
  const client_cloudformation_1 = require("@aws-sdk/client-cloudformation");
14
- const getExportedValue = (variableName, region) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const memoFunc_1 = require("../cache/memoFunc");
15
+ exports.getExportedValue = (0, memoFunc_1.memoFunc)((variableName, region) => __awaiter(void 0, void 0, void 0, function* () {
15
16
  var _a;
16
17
  const cloudformation = new client_cloudformation_1.CloudFormationClient({ region });
17
18
  const listCommandParams = {};
@@ -25,5 +26,4 @@ const getExportedValue = (variableName, region) => __awaiter(void 0, void 0, voi
25
26
  listCommandParams.NextToken = result.NextToken;
26
27
  } while (!!listCommandParams.NextToken);
27
28
  throw new Error(`CF could not find: [${variableName}]`);
28
- });
29
- exports.getExportedValue = getExportedValue;
29
+ }));
@@ -2,12 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.calculateSecretHash = void 0;
4
4
  const crypto_1 = require("crypto");
5
- const calculateSecretHash = (username, clientId, clientSecret) => {
5
+ const memoFunc_1 = require("../../cache/memoFunc");
6
+ exports.calculateSecretHash = (0, memoFunc_1.memoFunc)((username, clientId, clientSecret) => {
6
7
  // create the hmac with the sha256 algorithm and a secret key
7
8
  const hasher = (0, crypto_1.createHmac)('sha256', clientSecret);
8
9
  // add the value we want to hash
9
10
  hasher.update(`${username}${clientId}`);
10
11
  // get the hashed value as base64
11
12
  return hasher.digest('base64');
12
- };
13
- exports.calculateSecretHash = calculateSecretHash;
13
+ });
@@ -11,7 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getParameter = void 0;
13
13
  const client_ssm_1 = require("@aws-sdk/client-ssm");
14
- const getParameter = (parameterName, region) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const memoFunc_1 = require("../cache/memoFunc");
15
+ exports.getParameter = (0, memoFunc_1.memoFunc)((parameterName, region) => __awaiter(void 0, void 0, void 0, function* () {
15
16
  var _a;
16
17
  const smClient = new client_ssm_1.SSMClient({
17
18
  region,
@@ -20,5 +21,4 @@ const getParameter = (parameterName, region) => __awaiter(void 0, void 0, void 0
20
21
  Name: parameterName,
21
22
  }));
22
23
  return ((_a = response.Parameter) === null || _a === void 0 ? void 0 : _a.Value) || '';
23
- });
24
- exports.getParameter = getParameter;
24
+ }), 60);
@@ -11,12 +11,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getParameters = void 0;
13
13
  const client_ssm_1 = require("@aws-sdk/client-ssm");
14
- const getParameters = (parameterNames, region) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const memoFunc_1 = require("../cache/memoFunc");
15
+ exports.getParameters = (0, memoFunc_1.memoFunc)((parameterNames, region) => __awaiter(void 0, void 0, void 0, function* () {
15
16
  const smClient = new client_ssm_1.SSMClient({ region });
16
17
  const response = yield smClient.send(new client_ssm_1.GetParametersCommand({
17
18
  Names: parameterNames,
18
19
  }));
19
20
  const resolvedParams = response.Parameters || [];
20
21
  return parameterNames.map((pn) => { var _a; return ((_a = resolvedParams.find((rp) => rp.Name == pn)) === null || _a === void 0 ? void 0 : _a.Value) || ''; });
21
- });
22
- exports.getParameters = getParameters;
22
+ }), 60);
@@ -11,7 +11,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.getSecret = void 0;
13
13
  const client_secrets_manager_1 = require("@aws-sdk/client-secrets-manager");
14
- const getSecret = (secretName, region) => __awaiter(void 0, void 0, void 0, function* () {
14
+ const memoFunc_1 = require("../cache/memoFunc");
15
+ exports.getSecret = (0, memoFunc_1.memoFunc)((secretName, region) => __awaiter(void 0, void 0, void 0, function* () {
15
16
  const smClient = new client_secrets_manager_1.SecretsManagerClient({
16
17
  region,
17
18
  });
@@ -19,5 +20,4 @@ const getSecret = (secretName, region) => __awaiter(void 0, void 0, void 0, func
19
20
  SecretId: secretName,
20
21
  }));
21
22
  return response.SecretString || '';
22
- });
23
- exports.getSecret = getSecret;
23
+ }), 60);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quidproquo-actionprocessor-awslambda",
3
- "version": "0.0.102",
3
+ "version": "0.0.103",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.js",
@@ -41,6 +41,7 @@
41
41
  "jsonwebtoken": "^9.0.0",
42
42
  "jwks-rsa": "^3.0.1",
43
43
  "lodash": "^4.17.21",
44
+ "node-cache": "^5.1.2",
44
45
  "node-match-path": "^0.6.3",
45
46
  "quidproquo-core": "*",
46
47
  "quidproquo-webserver": "*"