@middy/rds-signer 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 +56 -40
  2. package/package.json +4 -4
package/index.js CHANGED
@@ -1,82 +1,98 @@
1
+ "use strict";
2
+
1
3
  const {
2
4
  canPrefetch,
3
5
  getInternal,
4
6
  processCache,
5
7
  getCache,
6
8
  modifyCache
7
- } = require('@middy/util')
8
- const { Signer } = require('aws-sdk/clients/rds.js') // v2
9
+ } = require('@middy/util');
10
+
11
+ const {
12
+ Signer
13
+ } = require('aws-sdk/clients/rds.js'); // v2
9
14
  // const { RDS:{Signer} } = require('@aws-sdk/client-rds') // v3
10
15
 
16
+
11
17
  const defaults = {
12
18
  AwsClient: Signer,
13
19
  awsClientOptions: {},
14
- fetchData: {}, // { contextKey: {region, hostname, username, database, port} }
20
+ fetchData: {},
21
+ // { contextKey: {region, hostname, username, database, port} }
15
22
  disablePrefetch: false,
16
23
  cacheKey: 'rds-signer',
17
24
  cacheExpiry: -1,
18
25
  setToEnv: false,
19
26
  setToContext: false
20
- }
27
+ };
21
28
 
22
29
  const rdsSignerMiddleware = (opts = {}) => {
23
- const options = { ...defaults, ...opts }
30
+ const options = { ...defaults,
31
+ ...opts
32
+ };
24
33
 
25
34
  const fetch = (request, cachedValues = {}) => {
26
- const values = {}
27
- for (const internalKey of Object.keys(options.fetchData)) {
28
- if (cachedValues[internalKey]) continue
35
+ const values = {};
29
36
 
30
- const client = new options.AwsClient({
31
- ...options.awsClientOptions,
37
+ for (const internalKey of Object.keys(options.fetchData)) {
38
+ if (cachedValues[internalKey]) continue;
39
+ const client = new options.AwsClient({ ...options.awsClientOptions,
32
40
  ...options.fetchData[internalKey]
33
- })
34
- // AWS doesn't support getAuthToken.promise() in aws-sdk v2 :( See https://github.com/aws/aws-sdk-js/issues/3595
41
+ }); // AWS doesn't support getAuthToken.promise() in aws-sdk v2 :( See https://github.com/aws/aws-sdk-js/issues/3595
42
+
35
43
  values[internalKey] = new Promise((resolve, reject) => {
36
44
  client.getAuthToken({}, (err, token) => {
37
45
  if (err) {
38
- reject(err)
39
- }
40
- // Catch Missing token, this usually means their is something wrong with the credentials
46
+ reject(err);
47
+ } // Catch Missing token, this usually means their is something wrong with the credentials
48
+
49
+
41
50
  if (!token.includes('X-Amz-Security-Token=')) {
42
- reject(new Error('X-Amz-Security-Token Missing'))
51
+ reject(new Error('X-Amz-Security-Token Missing'));
43
52
  }
44
- resolve(token)
45
- })
46
- }).catch((e) => {
47
- const value = getCache(options.cacheKey)?.value ?? {}
48
- value[internalKey] = undefined
49
- modifyCache(options.cacheKey, value)
50
- throw e
51
- })
52
- // aws-sdk v3
53
+
54
+ resolve(token);
55
+ });
56
+ }).catch(e => {
57
+ var _getCache$value, _getCache;
58
+
59
+ const value = (_getCache$value = (_getCache = getCache(options.cacheKey)) === null || _getCache === void 0 ? void 0 : _getCache.value) !== null && _getCache$value !== void 0 ? _getCache$value : {};
60
+ value[internalKey] = undefined;
61
+ modifyCache(options.cacheKey, value);
62
+ throw e;
63
+ }); // aws-sdk v3
53
64
  // values[internalKey] = createClient(awsClientOptions, request).then(client => client.getAuthToken())
54
65
  }
55
66
 
56
- return values
57
- }
67
+ return values;
68
+ };
69
+
70
+ let prefetch;
58
71
 
59
- let prefetch
60
72
  if (canPrefetch(options)) {
61
- prefetch = processCache(options, fetch)
73
+ prefetch = processCache(options, fetch);
62
74
  }
63
75
 
64
- const rdsSignerMiddlewareBefore = async (request) => {
65
- const { value } = prefetch ?? processCache(options, fetch, request)
76
+ const rdsSignerMiddlewareBefore = async request => {
77
+ var _prefetch;
66
78
 
67
- Object.assign(request.internal, value)
79
+ const {
80
+ value
81
+ } = (_prefetch = prefetch) !== null && _prefetch !== void 0 ? _prefetch : processCache(options, fetch, request);
82
+ Object.assign(request.internal, value);
68
83
 
69
84
  if (options.setToContext || options.setToEnv) {
70
- const data = await getInternal(Object.keys(options.fetchData), request)
71
- if (options.setToEnv) Object.assign(process.env, data)
72
- if (options.setToContext) Object.assign(request.context, data)
85
+ const data = await getInternal(Object.keys(options.fetchData), request);
86
+ if (options.setToEnv) Object.assign(process.env, data);
87
+ if (options.setToContext) Object.assign(request.context, data);
73
88
  }
74
89
 
75
- prefetch = null
76
- }
90
+ prefetch = null;
91
+ };
77
92
 
78
93
  return {
79
94
  before: rdsSignerMiddlewareBefore
80
- }
81
- }
82
- module.exports = rdsSignerMiddleware
95
+ };
96
+ };
97
+
98
+ module.exports = rdsSignerMiddleware;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/rds-signer",
3
- "version": "2.5.6",
3
+ "version": "2.5.7",
4
4
  "description": "RDS (Relational Database Service) credentials middleware for the middy framework",
5
5
  "type": "commonjs",
6
6
  "engines": {
@@ -46,13 +46,13 @@
46
46
  },
47
47
  "homepage": "https://github.com/middyjs/middy#readme",
48
48
  "dependencies": {
49
- "@middy/util": "^2.5.6"
49
+ "@middy/util": "^2.5.7"
50
50
  },
51
51
  "devDependencies": {
52
- "@middy/core": "^2.5.6",
52
+ "@middy/core": "^2.5.7",
53
53
  "@types/node": "^16.0.0",
54
54
  "aws-sdk": "^2.939.0",
55
55
  "aws-xray-sdk": "^3.3.3"
56
56
  },
57
- "gitHead": "0c789f55b4adf691f977b0d9904d1a805bb3bb2b"
57
+ "gitHead": "3983c4b138e1a4d7fcb3ed805d3b8832fff06fc1"
58
58
  }