@middy/util 3.6.2 → 4.0.0-alpha.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/index.cjs +9 -22
- package/index.d.ts +1 -1
- package/index.js +9 -21
- package/package.json +5 -5
package/index.cjs
CHANGED
|
@@ -9,7 +9,6 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
awsClientDefaultOptions: ()=>awsClientDefaultOptions,
|
|
13
12
|
createPrefetchClient: ()=>createPrefetchClient,
|
|
14
13
|
createClient: ()=>createClient,
|
|
15
14
|
canPrefetch: ()=>canPrefetch,
|
|
@@ -25,21 +24,8 @@ _export(exports, {
|
|
|
25
24
|
HttpError: ()=>HttpError,
|
|
26
25
|
createError: ()=>createError
|
|
27
26
|
});
|
|
28
|
-
const _https = require("https");
|
|
29
|
-
var _response;
|
|
30
|
-
const awsClientDefaultOptions = {
|
|
31
|
-
httpOptions: {
|
|
32
|
-
agent: new _https.Agent({
|
|
33
|
-
keepAlive: true,
|
|
34
|
-
secureProtocol: 'TLSv1_2_method'
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
27
|
const createPrefetchClient = (options)=>{
|
|
39
|
-
const awsClientOptions =
|
|
40
|
-
...awsClientDefaultOptions,
|
|
41
|
-
...options.awsClientOptions
|
|
42
|
-
};
|
|
28
|
+
const { awsClientOptions } = options;
|
|
43
29
|
const client = new options.AwsClient(awsClientOptions);
|
|
44
30
|
if (options.awsClientCapture && options.disablePrefetch) {
|
|
45
31
|
return options.awsClientCapture(client);
|
|
@@ -99,9 +85,9 @@ const getInternal = async (variables, request)=>{
|
|
|
99
85
|
values = await Promise.allSettled(promises);
|
|
100
86
|
const errors = values.filter((res)=>res.status === 'rejected').map((res)=>res.reason);
|
|
101
87
|
if (errors.length) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
88
|
+
throw new Error('Failed to resolve internal values', {
|
|
89
|
+
cause: errors
|
|
90
|
+
});
|
|
105
91
|
}
|
|
106
92
|
return keys.reduce((obj, key, index)=>({
|
|
107
93
|
...obj,
|
|
@@ -204,10 +190,12 @@ const normalizeHttpResponse = (request)=>{
|
|
|
204
190
|
response = {};
|
|
205
191
|
} else if (typeof response?.statusCode === 'undefined' && typeof response?.body === 'undefined' && typeof response?.headers === 'undefined') {
|
|
206
192
|
response = {
|
|
193
|
+
statusCode: 200,
|
|
207
194
|
body: response
|
|
208
195
|
};
|
|
209
196
|
}
|
|
210
|
-
|
|
197
|
+
response.statusCode ??= 500;
|
|
198
|
+
response.headers ??= {};
|
|
211
199
|
request.response = response;
|
|
212
200
|
return response;
|
|
213
201
|
};
|
|
@@ -218,9 +206,8 @@ class HttpError extends Error {
|
|
|
218
206
|
options = message;
|
|
219
207
|
message = undefined;
|
|
220
208
|
}
|
|
221
|
-
message
|
|
222
|
-
super(message);
|
|
223
|
-
this.cause = options.cause;
|
|
209
|
+
message ??= httpErrorCodes[code];
|
|
210
|
+
super(message, options);
|
|
224
211
|
const name = httpErrorCodes[code].replace(createErrorRegexp, '');
|
|
225
212
|
this.name = name.substr(-5) !== 'Error' ? name + 'Error' : name;
|
|
226
213
|
this.status = this.statusCode = code;
|
package/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import middy from '@middy/core'
|
|
2
2
|
|
|
3
3
|
interface Options<Client, ClientOptions> {
|
|
4
|
-
AwsClient?: new() => Client
|
|
4
|
+
AwsClient?: new(...args: any[]) => Client
|
|
5
5
|
awsClientOptions?: Partial<ClientOptions>
|
|
6
6
|
awsClientAssumeRole?: string
|
|
7
7
|
awsClientCapture?: (service: Client) => Client
|
package/index.js
CHANGED
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
var _response;
|
|
2
|
-
import { Agent } from 'https';
|
|
3
|
-
export const awsClientDefaultOptions = {
|
|
4
|
-
httpOptions: {
|
|
5
|
-
agent: new Agent({
|
|
6
|
-
keepAlive: true,
|
|
7
|
-
secureProtocol: 'TLSv1_2_method'
|
|
8
|
-
})
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
1
|
export const createPrefetchClient = (options)=>{
|
|
12
|
-
const awsClientOptions =
|
|
13
|
-
...awsClientDefaultOptions,
|
|
14
|
-
...options.awsClientOptions
|
|
15
|
-
};
|
|
2
|
+
const { awsClientOptions } = options;
|
|
16
3
|
const client = new options.AwsClient(awsClientOptions);
|
|
17
4
|
if (options.awsClientCapture && options.disablePrefetch) {
|
|
18
5
|
return options.awsClientCapture(client);
|
|
@@ -72,9 +59,9 @@ export const getInternal = async (variables, request)=>{
|
|
|
72
59
|
values = await Promise.allSettled(promises);
|
|
73
60
|
const errors = values.filter((res)=>res.status === 'rejected').map((res)=>res.reason);
|
|
74
61
|
if (errors.length) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
62
|
+
throw new Error('Failed to resolve internal values', {
|
|
63
|
+
cause: errors
|
|
64
|
+
});
|
|
78
65
|
}
|
|
79
66
|
return keys.reduce((obj, key, index)=>({
|
|
80
67
|
...obj,
|
|
@@ -177,10 +164,12 @@ export const normalizeHttpResponse = (request)=>{
|
|
|
177
164
|
response = {};
|
|
178
165
|
} else if (typeof response?.statusCode === 'undefined' && typeof response?.body === 'undefined' && typeof response?.headers === 'undefined') {
|
|
179
166
|
response = {
|
|
167
|
+
statusCode: 200,
|
|
180
168
|
body: response
|
|
181
169
|
};
|
|
182
170
|
}
|
|
183
|
-
|
|
171
|
+
response.statusCode ??= 500;
|
|
172
|
+
response.headers ??= {};
|
|
184
173
|
request.response = response;
|
|
185
174
|
return response;
|
|
186
175
|
};
|
|
@@ -191,9 +180,8 @@ export class HttpError extends Error {
|
|
|
191
180
|
options = message;
|
|
192
181
|
message = undefined;
|
|
193
182
|
}
|
|
194
|
-
message
|
|
195
|
-
super(message);
|
|
196
|
-
this.cause = options.cause;
|
|
183
|
+
message ??= httpErrorCodes[code];
|
|
184
|
+
super(message, options);
|
|
197
185
|
const name = httpErrorCodes[code].replace(createErrorRegexp, '');
|
|
198
186
|
this.name = name.substr(-5) !== 'Error' ? name + 'Error' : name;
|
|
199
187
|
this.status = this.statusCode = code;
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/util",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-alpha.0",
|
|
4
4
|
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (util package)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=16"
|
|
8
8
|
},
|
|
9
9
|
"engineStrict": true,
|
|
10
10
|
"publishConfig": {
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"url": "https://github.com/middyjs/middy/issues"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@
|
|
63
|
+
"@aws-sdk/client-ssm": "^3.0.0",
|
|
64
|
+
"@middy/core": "4.0.0-alpha.0",
|
|
64
65
|
"@types/aws-lambda": "^8.10.76",
|
|
65
66
|
"@types/node": "^18.0.0",
|
|
66
|
-
"aws-sdk": "^2.939.0",
|
|
67
67
|
"aws-xray-sdk": "^3.3.3"
|
|
68
68
|
},
|
|
69
69
|
"homepage": "https://middy.js.org",
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "306fb9aa633d5757d11ced3dc192f046ef3c2685"
|
|
71
71
|
}
|