@middy/util 5.0.2 → 5.0.3

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 +2 -13
  2. package/package.json +3 -3
package/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  export const createPrefetchClient = (options)=>{
2
2
  const { awsClientOptions } = options;
3
3
  const client = new options.AwsClient(awsClientOptions);
4
- // AWS XRay
5
4
  if (options.awsClientCapture && options.disablePrefetch) {
6
5
  return options.awsClientCapture(client);
7
6
  } else if (options.awsClientCapture) {
@@ -11,7 +10,6 @@ export const createPrefetchClient = (options)=>{
11
10
  };
12
11
  export const createClient = async (options, request)=>{
13
12
  let awsClientCredentials = {};
14
- // Role Credentials
15
13
  if (options.awsClientAssumeRole) {
16
14
  if (!request) {
17
15
  throw new Error('Request required when assuming role', {
@@ -36,7 +34,6 @@ export const createClient = async (options, request)=>{
36
34
  export const canPrefetch = (options = {})=>{
37
35
  return !options.awsClientAssumeRole && !options.disablePrefetch;
38
36
  };
39
- // Internal Context
40
37
  export const getInternal = async (variables, request)=>{
41
38
  if (!variables || !request) return {};
42
39
  let keys = [];
@@ -55,7 +52,6 @@ export const getInternal = async (variables, request)=>{
55
52
  }
56
53
  const promises = [];
57
54
  for (const internalKey of values){
58
- // 'internal.key.sub_value' -> { [key]: internal.key.sub_value }
59
55
  const pathOptionKey = internalKey.split('.');
60
56
  const rootOptionKey = pathOptionKey.shift();
61
57
  let valuePromise = request.internal[rootOptionKey];
@@ -64,8 +60,6 @@ export const getInternal = async (variables, request)=>{
64
60
  }
65
61
  promises.push(valuePromise.then((value)=>pathOptionKey.reduce((p, c)=>p?.[c], value)));
66
62
  }
67
- // ensure promise has resolved by the time it's needed
68
- // If one of the promises throws it will bubble up to @middy/core
69
63
  values = await Promise.allSettled(promises);
70
64
  const errors = values.filter((res)=>res.status === 'rejected').map((res)=>res.reason);
71
65
  if (errors.length) {
@@ -87,9 +81,7 @@ const sanitizeKeyRemoveDisallowedChar = /[^a-zA-Z0-9]+/g;
87
81
  export const sanitizeKey = (key)=>{
88
82
  return key.replace(sanitizeKeyPrefixLeadingNumber, '_$1').replace(sanitizeKeyRemoveDisallowedChar, '_');
89
83
  };
90
- // fetch Cache
91
- const cache = {} // key: { value:{fetchKey:Promise}, expiry }
92
- ;
84
+ const cache = {};
93
85
  export const processCache = (options, fetch = ()=>undefined, request)=>{
94
86
  let { cacheKey, cacheKeyExpiry, cacheExpiry } = options;
95
87
  cacheExpiry = cacheKeyExpiry?.[cacheKey] ?? cacheExpiry;
@@ -116,7 +108,6 @@ export const processCache = (options, fetch = ()=>undefined, request)=>{
116
108
  }
117
109
  const value = fetch(request);
118
110
  const now = Date.now();
119
- // secrets-manager overrides to unix timestamp
120
111
  const expiry = cacheExpiry > 86400000 ? cacheExpiry : now + cacheExpiry;
121
112
  const duration = cacheExpiry > 86400000 ? cacheExpiry - now : cacheExpiry;
122
113
  if (cacheExpiry) {
@@ -136,7 +127,6 @@ export const getCache = (key)=>{
136
127
  if (!cache[key]) return {};
137
128
  return cache[key];
138
129
  };
139
- // Used to remove parts of a cache
140
130
  export const modifyCache = (cacheKey, value)=>{
141
131
  if (!cache[cacheKey]) return;
142
132
  clearInterval(cache[cacheKey]?.refresh);
@@ -197,8 +187,7 @@ export class HttpError extends Error {
197
187
  super(message, options);
198
188
  const name = httpErrorCodes[code].replace(createErrorRegexp, '');
199
189
  this.name = name.substr(-5) !== 'Error' ? name + 'Error' : name;
200
- this.status = this.statusCode = code // setting `status` for backwards compatibility w/ `http-errors`
201
- ;
190
+ this.status = this.statusCode = code;
202
191
  this.expose = options.expose ?? code < 500;
203
192
  }
204
193
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/util",
3
- "version": "5.0.2",
3
+ "version": "5.0.3",
4
4
  "description": "🛵 The stylish Node.js middleware engine for AWS Lambda (util package)",
5
5
  "type": "module",
6
6
  "engines": {
@@ -55,7 +55,7 @@
55
55
  },
56
56
  "devDependencies": {
57
57
  "@aws-sdk/client-ssm": "^3.0.0",
58
- "@middy/core": "5.0.2",
58
+ "@middy/core": "5.0.3",
59
59
  "@types/aws-lambda": "^8.10.76",
60
60
  "@types/node": "^20.0.0",
61
61
  "aws-xray-sdk": "^3.3.3"
@@ -65,5 +65,5 @@
65
65
  "type": "github",
66
66
  "url": "https://github.com/sponsors/willfarrell"
67
67
  },
68
- "gitHead": "6d17e155237022f2a0abd095ac7cd99ebfc7fc71"
68
+ "gitHead": "87660575a7ac2b52e4153c407a4c63c9449dcd0d"
69
69
  }