@middy/ssm 7.2.2 → 7.3.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.d.ts +5 -0
- package/index.js +24 -12
- package/package.json +3 -6
package/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare function ssmParam<T>(path: string): ParamType<T>;
|
|
|
11
11
|
export interface SSMOptions<AwsSSMClient = SSMClient>
|
|
12
12
|
extends Omit<MiddyOptions<AwsSSMClient, SSMClientConfig>, "fetchData"> {
|
|
13
13
|
fetchData?: { [key: string]: string | ParamType<unknown> };
|
|
14
|
+
awsRequestLimit?: number;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
export type Context<TOptions extends SSMOptions | undefined> =
|
|
@@ -45,4 +46,8 @@ declare function ssm<TOptions extends SSMOptions>(
|
|
|
45
46
|
Internal<TOptions>
|
|
46
47
|
>;
|
|
47
48
|
|
|
49
|
+
export declare function ssmValidateOptions(
|
|
50
|
+
options?: Record<string, unknown>,
|
|
51
|
+
): void;
|
|
52
|
+
|
|
48
53
|
export default ssm;
|
package/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
SSMClient,
|
|
7
7
|
} from "@aws-sdk/client-ssm";
|
|
8
8
|
import {
|
|
9
|
+
awsClientOptionSchema,
|
|
9
10
|
canPrefetch,
|
|
10
11
|
catchInvalidSignatureException,
|
|
11
12
|
createClient,
|
|
@@ -16,9 +17,9 @@ import {
|
|
|
16
17
|
modifyCache,
|
|
17
18
|
processCache,
|
|
18
19
|
sanitizeKey,
|
|
20
|
+
validateOptions,
|
|
19
21
|
} from "@middy/util";
|
|
20
22
|
|
|
21
|
-
const awsRequestLimit = 10;
|
|
22
23
|
const defaults = {
|
|
23
24
|
AwsClient: SSMClient, // Allow for XRay
|
|
24
25
|
awsClientOptions: {},
|
|
@@ -30,8 +31,17 @@ const defaults = {
|
|
|
30
31
|
cacheKeyExpiry: {},
|
|
31
32
|
cacheExpiry: -1,
|
|
32
33
|
setToContext: false,
|
|
34
|
+
awsRequestLimit: 10,
|
|
33
35
|
};
|
|
34
36
|
|
|
37
|
+
const optionSchema = {
|
|
38
|
+
...awsClientOptionSchema,
|
|
39
|
+
awsRequestLimit: (v) => Number.isInteger(v) && v >= 1,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export const ssmValidateOptions = (options) =>
|
|
43
|
+
validateOptions("@middy/ssm", optionSchema, options);
|
|
44
|
+
|
|
35
45
|
const ssmMiddleware = (opts = {}) => {
|
|
36
46
|
const options = { ...defaults, ...opts };
|
|
37
47
|
|
|
@@ -62,7 +72,7 @@ const ssmMiddleware = (opts = {}) => {
|
|
|
62
72
|
batchKeys.set(internalKey, fetchKey);
|
|
63
73
|
// from the first to the batch size skip, unless it's the last entry
|
|
64
74
|
if (
|
|
65
|
-
(!idx || (idx + 1) % awsRequestLimit !== 0) &&
|
|
75
|
+
(!idx || (idx + 1) % options.awsRequestLimit !== 0) &&
|
|
66
76
|
!(idx + 1 === namedKeys.length)
|
|
67
77
|
) {
|
|
68
78
|
continue;
|
|
@@ -80,15 +90,15 @@ const ssmMiddleware = (opts = {}) => {
|
|
|
80
90
|
// Don't sanitize key, mapped to set value in options
|
|
81
91
|
const result = {};
|
|
82
92
|
for (const fetchKey of resp.InvalidParameters ?? []) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
93
|
+
const internalKey = internalKeys[fetchKeys.indexOf(fetchKey)];
|
|
94
|
+
const value = getCache(options.cacheKey).value ?? {};
|
|
95
|
+
value[internalKey] = undefined;
|
|
96
|
+
modifyCache(options.cacheKey, value);
|
|
97
|
+
result[fetchKey] = Promise.reject(
|
|
98
|
+
new Error(`InvalidParameter ${fetchKey}`, {
|
|
89
99
|
cause: { package: "@middy/ssm" },
|
|
90
|
-
})
|
|
91
|
-
|
|
100
|
+
}),
|
|
101
|
+
);
|
|
92
102
|
}
|
|
93
103
|
for (const param of resp.Parameters ?? []) {
|
|
94
104
|
result[param.Name] = parseValue(param);
|
|
@@ -150,7 +160,7 @@ const ssmMiddleware = (opts = {}) => {
|
|
|
150
160
|
.send(command)
|
|
151
161
|
.catch((e) => catchInvalidSignatureException(e, client, command))
|
|
152
162
|
.then((resp) => {
|
|
153
|
-
for (const param of resp.Parameters) {
|
|
163
|
+
for (const param of resp.Parameters ?? []) {
|
|
154
164
|
values[sanitizeKey(param.Name.replace(path, ""))] = parseValue(param);
|
|
155
165
|
}
|
|
156
166
|
if (resp.NextToken) {
|
|
@@ -168,6 +178,7 @@ const ssmMiddleware = (opts = {}) => {
|
|
|
168
178
|
};
|
|
169
179
|
|
|
170
180
|
let client;
|
|
181
|
+
let clientInit;
|
|
171
182
|
if (canPrefetch(options)) {
|
|
172
183
|
client = createPrefetchClient(options);
|
|
173
184
|
processCache(options, fetchRequest);
|
|
@@ -175,7 +186,8 @@ const ssmMiddleware = (opts = {}) => {
|
|
|
175
186
|
|
|
176
187
|
const ssmMiddlewareBefore = async (request) => {
|
|
177
188
|
if (!client) {
|
|
178
|
-
|
|
189
|
+
clientInit ??= createClient(options, request);
|
|
190
|
+
client = await clientInit;
|
|
179
191
|
}
|
|
180
192
|
|
|
181
193
|
const { value } = processCache(options, fetchRequest, request);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/ssm",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "SSM (EC2 Systems Manager) parameters middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,9 +17,6 @@
|
|
|
17
17
|
"import": {
|
|
18
18
|
"types": "./index.d.ts",
|
|
19
19
|
"default": "./index.js"
|
|
20
|
-
},
|
|
21
|
-
"require": {
|
|
22
|
-
"default": "./index.js"
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
22
|
},
|
|
@@ -65,7 +62,7 @@
|
|
|
65
62
|
"url": "https://github.com/sponsors/willfarrell"
|
|
66
63
|
},
|
|
67
64
|
"dependencies": {
|
|
68
|
-
"@middy/util": "7.
|
|
65
|
+
"@middy/util": "7.3.0"
|
|
69
66
|
},
|
|
70
67
|
"peerDependencies": {
|
|
71
68
|
"@aws-sdk/client-ssm": "^3.0.0"
|
|
@@ -77,7 +74,7 @@
|
|
|
77
74
|
},
|
|
78
75
|
"devDependencies": {
|
|
79
76
|
"@aws-sdk/client-ssm": "^3.0.0",
|
|
80
|
-
"@middy/core": "7.
|
|
77
|
+
"@middy/core": "7.3.0",
|
|
81
78
|
"@types/aws-lambda": "^8.0.0",
|
|
82
79
|
"@types/node": "^22.0.0",
|
|
83
80
|
"aws-xray-sdk": "^3.3.3"
|