@middy/secrets-manager 2.5.6 → 2.5.7

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 (2) hide show
  1. package/index.js +52 -38
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -1,3 +1,5 @@
1
+ "use strict";
2
+
1
3
  const {
2
4
  canPrefetch,
3
5
  createPrefetchClient,
@@ -7,75 +9,87 @@ const {
7
9
  modifyCache,
8
10
  jsonSafeParse,
9
11
  getInternal
10
- } = require('@middy/util')
11
- const SecretsManager = require('aws-sdk/clients/secretsmanager') // v2
12
+ } = require('@middy/util');
13
+
14
+ const SecretsManager = require('aws-sdk/clients/secretsmanager'); // v2
12
15
  // const { SecretsManager } = require('@aws-sdk/client-secrets-manager') // v3
13
16
 
17
+
14
18
  const defaults = {
15
19
  AwsClient: SecretsManager,
16
20
  awsClientOptions: {},
17
21
  awsClientAssumeRole: undefined,
18
22
  awsClientCapture: undefined,
19
- fetchData: {}, // If more than 2, consider writing own using ListSecrets
23
+ fetchData: {},
24
+ // If more than 2, consider writing own using ListSecrets
20
25
  disablePrefetch: false,
21
26
  cacheKey: 'secrets-manager',
22
27
  cacheExpiry: -1,
23
- setToEnv: false, // can return object when requesting db credentials, cannot set to process.env
28
+ setToEnv: false,
29
+ // can return object when requesting db credentials, cannot set to process.env
24
30
  setToContext: false
25
- }
31
+ };
26
32
 
27
33
  const secretsManagerMiddleware = (opts = {}) => {
28
- const options = { ...defaults, ...opts }
34
+ const options = { ...defaults,
35
+ ...opts
36
+ };
29
37
 
30
38
  const fetch = (request, cachedValues = {}) => {
31
- const values = {}
32
-
33
- // Multiple secrets can be requested in a single requests,
39
+ const values = {}; // Multiple secrets can be requested in a single requests,
34
40
  // however this is likely uncommon IRL, increases complexity to handle,
35
41
  // and will require recursive promise resolution impacting performance.
36
42
  // See https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/SecretsManager.html#listSecrets-property
43
+
37
44
  for (const internalKey of Object.keys(options.fetchData)) {
38
- if (cachedValues[internalKey]) continue
39
- values[internalKey] = client
40
- .getSecretValue({ SecretId: options.fetchData[internalKey] })
41
- .promise() // Required for aws-sdk v2
42
- .then((resp) => jsonSafeParse(resp.SecretString))
43
- .catch((e) => {
44
- const value = getCache(options.cacheKey)?.value ?? {}
45
- value[internalKey] = undefined
46
- modifyCache(options.cacheKey, value)
47
- throw e
48
- })
45
+ if (cachedValues[internalKey]) continue;
46
+ values[internalKey] = client.getSecretValue({
47
+ SecretId: options.fetchData[internalKey]
48
+ }).promise() // Required for aws-sdk v2
49
+ .then(resp => jsonSafeParse(resp.SecretString)).catch(e => {
50
+ var _getCache$value, _getCache;
51
+
52
+ const value = (_getCache$value = (_getCache = getCache(options.cacheKey)) === null || _getCache === void 0 ? void 0 : _getCache.value) !== null && _getCache$value !== void 0 ? _getCache$value : {};
53
+ value[internalKey] = undefined;
54
+ modifyCache(options.cacheKey, value);
55
+ throw e;
56
+ });
49
57
  }
50
- return values
51
- }
52
58
 
53
- let prefetch, client
59
+ return values;
60
+ };
61
+
62
+ let prefetch, client;
63
+
54
64
  if (canPrefetch(options)) {
55
- client = createPrefetchClient(options)
56
- prefetch = processCache(options, fetch)
65
+ client = createPrefetchClient(options);
66
+ prefetch = processCache(options, fetch);
57
67
  }
58
68
 
59
- const secretsManagerMiddlewareBefore = async (request) => {
69
+ const secretsManagerMiddlewareBefore = async request => {
70
+ var _prefetch;
71
+
60
72
  if (!client) {
61
- client = await createClient(options, request)
73
+ client = await createClient(options, request);
62
74
  }
63
75
 
64
- const { value } = prefetch ?? processCache(options, fetch, request)
65
-
66
- Object.assign(request.internal, value)
76
+ const {
77
+ value
78
+ } = (_prefetch = prefetch) !== null && _prefetch !== void 0 ? _prefetch : processCache(options, fetch, request);
79
+ Object.assign(request.internal, value);
67
80
 
68
81
  if (options.setToContext || options.setToEnv) {
69
- const data = await getInternal(Object.keys(options.fetchData), request)
70
- if (options.setToEnv) Object.assign(process.env, data)
71
- if (options.setToContext) Object.assign(request.context, data)
82
+ const data = await getInternal(Object.keys(options.fetchData), request);
83
+ if (options.setToEnv) Object.assign(process.env, data);
84
+ if (options.setToContext) Object.assign(request.context, data);
72
85
  }
73
86
 
74
- prefetch = null
75
- }
87
+ prefetch = null;
88
+ };
76
89
 
77
90
  return {
78
91
  before: secretsManagerMiddlewareBefore
79
- }
80
- }
81
- module.exports = secretsManagerMiddleware
92
+ };
93
+ };
94
+
95
+ module.exports = secretsManagerMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/secrets-manager",
3
- "version": "2.5.6",
3
+ "version": "2.5.7",
4
4
  "description": "Secrets Manager middleware for the middy framework",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -44,12 +44,12 @@
44
44
  },
45
45
  "homepage": "https://github.com/middyjs/middy#readme",
46
46
  "dependencies": {
47
- "@middy/util": "^2.5.6"
47
+ "@middy/util": "^2.5.7"
48
48
  },
49
49
  "devDependencies": {
50
- "@middy/core": "^2.5.6",
50
+ "@middy/core": "^2.5.7",
51
51
  "aws-sdk": "^2.939.0",
52
52
  "aws-xray-sdk": "^3.3.3"
53
53
  },
54
- "gitHead": "0c789f55b4adf691f977b0d9904d1a805bb3bb2b"
54
+ "gitHead": "3983c4b138e1a4d7fcb3ed805d3b8832fff06fc1"
55
55
  }