@middy/util 7.0.2 → 7.1.0
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.
- package/README.md +2 -2
- package/index.d.ts +2 -0
- package/index.js +11 -8
- package/package.json +3 -2
- package/type-utils.d.ts +2 -0
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
<p>
|
|
6
6
|
<a href="https://github.com/middyjs/middy/actions/workflows/test-unit.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-unit.yml/badge.svg" alt="GitHub Actions unit test status"></a>
|
|
7
7
|
<a href="https://github.com/middyjs/middy/actions/workflows/test-dast.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-dast.yml/badge.svg" alt="GitHub Actions dast test status"></a>
|
|
8
|
-
<a href="https://github.com/middyjs/middy/actions/workflows/test-perf.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-
|
|
8
|
+
<a href="https://github.com/middyjs/middy/actions/workflows/test-perf.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-perf.yml/badge.svg" alt="GitHub Actions perf test status"></a>
|
|
9
9
|
<a href="https://github.com/middyjs/middy/actions/workflows/test-sast.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-sast.yml/badge.svg" alt="GitHub Actions SAST test status"></a>
|
|
10
10
|
<a href="https://github.com/middyjs/middy/actions/workflows/test-lint.yml"><img src="https://github.com/middyjs/middy/actions/workflows/test-lint.yml/badge.svg" alt="GitHub Actions lint test status"></a>
|
|
11
11
|
<br/>
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
## License
|
|
34
34
|
|
|
35
|
-
Licensed under [MIT License](LICENSE). Copyright (c) 2017-
|
|
35
|
+
Licensed under [MIT License](LICENSE). Copyright (c) 2017-2026 [will Farrell](https://github.com/willfarrell), [Luciano Mammino](https://github.com/lmammino), and [Middy contributors](https://github.com/middyjs/middy/graphs/contributors).
|
|
36
36
|
|
|
37
37
|
<a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
|
|
38
38
|
<img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Copyright 2017 - 2026 will Farrell, Luciano Mammino, and Middy contributors.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
1
3
|
export const createPrefetchClient = (options) => {
|
|
2
4
|
const { awsClientOptions } = options;
|
|
3
5
|
const client = new options.AwsClient(awsClientOptions);
|
|
@@ -103,11 +105,11 @@ export const sanitizeKey = (key) => {
|
|
|
103
105
|
};
|
|
104
106
|
|
|
105
107
|
// fetch Cache
|
|
106
|
-
const cache =
|
|
108
|
+
const cache = Object.create(null); // key: { value:{fetchKey:Promise}, expiry }
|
|
107
109
|
export const processCache = (
|
|
108
110
|
options,
|
|
109
111
|
middlewareFetch = () => undefined,
|
|
110
|
-
|
|
112
|
+
middlewareFetchRequest = {},
|
|
111
113
|
) => {
|
|
112
114
|
let { cacheKey, cacheKeyExpiry, cacheExpiry } = options;
|
|
113
115
|
cacheExpiry = cacheKeyExpiry?.[cacheKey] ?? cacheExpiry;
|
|
@@ -118,7 +120,7 @@ export const processCache = (
|
|
|
118
120
|
|
|
119
121
|
if (unexpired) {
|
|
120
122
|
if (cached.modified) {
|
|
121
|
-
const value = middlewareFetch(
|
|
123
|
+
const value = middlewareFetch(middlewareFetchRequest, cached.value);
|
|
122
124
|
Object.assign(cached.value, value);
|
|
123
125
|
cache[cacheKey] = { value: cached.value, expiry: cached.expiry };
|
|
124
126
|
return cache[cacheKey];
|
|
@@ -126,7 +128,7 @@ export const processCache = (
|
|
|
126
128
|
return { ...cached, cache: true };
|
|
127
129
|
}
|
|
128
130
|
}
|
|
129
|
-
const value = middlewareFetch(
|
|
131
|
+
const value = middlewareFetch(middlewareFetchRequest);
|
|
130
132
|
// secrets-manager can override to unix timestamp
|
|
131
133
|
const expiry = cacheExpiry > 86400000 ? cacheExpiry : now + cacheExpiry;
|
|
132
134
|
const duration = cacheExpiry > 86400000 ? cacheExpiry - now : cacheExpiry;
|
|
@@ -134,7 +136,8 @@ export const processCache = (
|
|
|
134
136
|
const refresh =
|
|
135
137
|
duration > 0
|
|
136
138
|
? setTimeout(
|
|
137
|
-
() =>
|
|
139
|
+
() =>
|
|
140
|
+
processCache(options, middlewareFetch, middlewareFetchRequest),
|
|
138
141
|
duration,
|
|
139
142
|
)
|
|
140
143
|
: undefined;
|
|
@@ -203,14 +206,14 @@ export const isExecutionModeDurable = (context) => {
|
|
|
203
206
|
return false;
|
|
204
207
|
};
|
|
205
208
|
|
|
206
|
-
export const executionContext = (key, context) => {
|
|
209
|
+
export const executionContext = (request, key, context) => {
|
|
207
210
|
if (isExecutionModeDurable(context)) {
|
|
208
211
|
return request.context.executionContext[key];
|
|
209
212
|
}
|
|
210
213
|
return request.context[key];
|
|
211
214
|
};
|
|
212
215
|
|
|
213
|
-
export const lambdaContext = (key, context) => {
|
|
216
|
+
export const lambdaContext = (request, key, context) => {
|
|
214
217
|
if (isExecutionModeDurable(context)) {
|
|
215
218
|
return request.context.lambdaContext[key];
|
|
216
219
|
}
|
|
@@ -266,7 +269,7 @@ export class HttpError extends Error {
|
|
|
266
269
|
super(message, options);
|
|
267
270
|
|
|
268
271
|
const name = httpErrorCodes[code].replace(createErrorRegexp, "");
|
|
269
|
-
this.name = name.
|
|
272
|
+
this.name = !name.endsWith("Error") ? `${name}Error` : name;
|
|
270
273
|
|
|
271
274
|
this.status = this.statusCode = code; // setting `status` for backwards compatibility w/ `http-errors`
|
|
272
275
|
this.expose = options.expose ?? code < 500;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/util",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (util package)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"access": "public"
|
|
12
12
|
},
|
|
13
13
|
"module": "./index.js",
|
|
14
|
+
"sideEffects": false,
|
|
14
15
|
"exports": {
|
|
15
16
|
".": {
|
|
16
17
|
"import": {
|
|
@@ -59,7 +60,7 @@
|
|
|
59
60
|
},
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@aws-sdk/client-ssm": "^3.0.0",
|
|
62
|
-
"@middy/core": "7.0
|
|
63
|
+
"@middy/core": "7.1.0",
|
|
63
64
|
"@types/aws-lambda": "^8.10.76",
|
|
64
65
|
"@types/node": "^22.0.0",
|
|
65
66
|
"aws-xray-sdk": "^3.3.3"
|