@middy/ssm 3.1.1 → 3.2.2
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 +28 -26
- package/index.d.ts +23 -4
- package/index.js +7 -7
- package/package.json +7 -5
package/index.cjs
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
module
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Object.defineProperty(module, "exports", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: ()=>_default
|
|
8
|
+
});
|
|
9
|
+
const _util = require("@middy/util");
|
|
10
|
+
const _ssmJs = _interopRequireDefault(require("aws-sdk/clients/ssm.js"));
|
|
8
11
|
function _interopRequireDefault(obj) {
|
|
9
12
|
return obj && obj.__esModule ? obj : {
|
|
10
13
|
default: obj
|
|
@@ -40,12 +43,12 @@ const ssmMiddleware = (opts = {})=>{
|
|
|
40
43
|
let batchFetchKeys = [];
|
|
41
44
|
const internalKeys = Object.keys(options.fetchData);
|
|
42
45
|
const fetchKeys = Object.values(options.fetchData);
|
|
43
|
-
for (const [idx,
|
|
44
|
-
if (cachedValues[
|
|
45
|
-
const
|
|
46
|
-
if (
|
|
47
|
-
batchInternalKeys.push(
|
|
48
|
-
batchFetchKeys.push(
|
|
46
|
+
for (const [idx, internalKey] of internalKeys.entries()){
|
|
47
|
+
if (cachedValues[internalKey]) continue;
|
|
48
|
+
const fetchKey = options.fetchData[internalKey];
|
|
49
|
+
if (fetchKey.substr(-1) === '/') continue;
|
|
50
|
+
batchInternalKeys.push(internalKey);
|
|
51
|
+
batchFetchKeys.push(fetchKey);
|
|
49
52
|
if ((!idx || (idx + 1) % awsRequestLimit !== 0) && !(idx + 1 === internalKeys.length)) {
|
|
50
53
|
continue;
|
|
51
54
|
}
|
|
@@ -57,9 +60,9 @@ const ssmMiddleware = (opts = {})=>{
|
|
|
57
60
|
return {
|
|
58
61
|
[fetchKey]: new Promise(()=>{
|
|
59
62
|
const internalKey = internalKeys[fetchKeys.indexOf(fetchKey)];
|
|
60
|
-
const value = (0, _util
|
|
63
|
+
const value = (0, _util.getCache)(options.cacheKey).value ?? {};
|
|
61
64
|
value[internalKey] = undefined;
|
|
62
|
-
(0, _util
|
|
65
|
+
(0, _util.modifyCache)(options.cacheKey, value);
|
|
63
66
|
throw new Error('[ssm] InvalidParameter ' + fetchKey);
|
|
64
67
|
})
|
|
65
68
|
};
|
|
@@ -69,9 +72,9 @@ const ssmMiddleware = (opts = {})=>{
|
|
|
69
72
|
};
|
|
70
73
|
}));
|
|
71
74
|
}).catch((e)=>{
|
|
72
|
-
const value = (0, _util
|
|
73
|
-
value[
|
|
74
|
-
(0, _util
|
|
75
|
+
const value = (0, _util.getCache)(options.cacheKey).value ?? {};
|
|
76
|
+
value[internalKey] = undefined;
|
|
77
|
+
(0, _util.modifyCache)(options.cacheKey, value);
|
|
75
78
|
throw e;
|
|
76
79
|
});
|
|
77
80
|
for (const internalKey1 of batchInternalKeys){
|
|
@@ -92,9 +95,9 @@ const ssmMiddleware = (opts = {})=>{
|
|
|
92
95
|
const fetchKey = options.fetchData[internalKey];
|
|
93
96
|
if (fetchKey.substr(-1) !== '/') continue;
|
|
94
97
|
values[internalKey] = fetchPath(fetchKey).catch((e)=>{
|
|
95
|
-
const value = (0, _util
|
|
98
|
+
const value = (0, _util.getCache)(options.cacheKey).value ?? {};
|
|
96
99
|
value[internalKey] = undefined;
|
|
97
|
-
(0, _util
|
|
100
|
+
(0, _util.modifyCache)(options.cacheKey, value);
|
|
98
101
|
throw e;
|
|
99
102
|
});
|
|
100
103
|
}
|
|
@@ -109,7 +112,7 @@ const ssmMiddleware = (opts = {})=>{
|
|
|
109
112
|
}).promise().then((resp)=>{
|
|
110
113
|
Object.assign(values, ...resp.Parameters.map((param)=>{
|
|
111
114
|
return {
|
|
112
|
-
[(0, _util
|
|
115
|
+
[(0, _util.sanitizeKey)(param.Name.replace(path, ''))]: parseValue(param)
|
|
113
116
|
};
|
|
114
117
|
}));
|
|
115
118
|
if (resp.NextToken) return fetchPath(path, resp.NextToken, values);
|
|
@@ -120,21 +123,21 @@ const ssmMiddleware = (opts = {})=>{
|
|
|
120
123
|
if (param.Type === 'StringList') {
|
|
121
124
|
return param.Value.split(',');
|
|
122
125
|
}
|
|
123
|
-
return (0, _util
|
|
126
|
+
return (0, _util.jsonSafeParse)(param.Value);
|
|
124
127
|
};
|
|
125
128
|
let prefetch, client;
|
|
126
|
-
if ((0, _util
|
|
127
|
-
client = (0, _util
|
|
128
|
-
prefetch = (0, _util
|
|
129
|
+
if ((0, _util.canPrefetch)(options)) {
|
|
130
|
+
client = (0, _util.createPrefetchClient)(options);
|
|
131
|
+
prefetch = (0, _util.processCache)(options, fetch);
|
|
129
132
|
}
|
|
130
133
|
const ssmMiddlewareBefore = async (request)=>{
|
|
131
134
|
if (!client) {
|
|
132
|
-
client = await (0, _util
|
|
135
|
+
client = await (0, _util.createClient)(options, request);
|
|
133
136
|
}
|
|
134
|
-
const { value } = prefetch ?? (0, _util
|
|
137
|
+
const { value } = prefetch ?? (0, _util.processCache)(options, fetch, request);
|
|
135
138
|
Object.assign(request.internal, value);
|
|
136
139
|
if (options.setToContext) {
|
|
137
|
-
const data = await (0, _util
|
|
140
|
+
const data = await (0, _util.getInternal)(Object.keys(options.fetchData), request);
|
|
138
141
|
Object.assign(request.context, data);
|
|
139
142
|
}
|
|
140
143
|
prefetch = null;
|
|
@@ -143,8 +146,7 @@ const ssmMiddleware = (opts = {})=>{
|
|
|
143
146
|
before: ssmMiddlewareBefore
|
|
144
147
|
};
|
|
145
148
|
};
|
|
146
|
-
|
|
147
|
-
module.exports = _default;
|
|
149
|
+
const _default = ssmMiddleware;
|
|
148
150
|
|
|
149
151
|
|
|
150
152
|
//# sourceMappingURL=index.cjs.map
|
package/index.d.ts
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
|
-
import SSM from 'aws-sdk/clients/ssm'
|
|
2
|
-
import { Options as MiddyOptions } from '@middy/util'
|
|
3
1
|
import middy from '@middy/core'
|
|
2
|
+
import { Options as MiddyOptions } from '@middy/util'
|
|
3
|
+
import { Context as LambdaContext } from 'aws-lambda'
|
|
4
|
+
import SSM from 'aws-sdk/clients/ssm'
|
|
5
|
+
import { JsonValue } from 'type-fest'
|
|
6
|
+
|
|
7
|
+
interface Options<S = SSM>
|
|
8
|
+
extends MiddyOptions<S, SSM.Types.ClientConfiguration> {}
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
11
|
+
type ExtractSingles<T> = T extends `/${infer _}` ? never : T
|
|
4
12
|
|
|
5
|
-
|
|
13
|
+
export type Context<TOptions extends Options | undefined> = TOptions extends {
|
|
14
|
+
setToContext: true
|
|
15
|
+
}
|
|
16
|
+
? LambdaContext &
|
|
17
|
+
Record<ExtractSingles<keyof TOptions['fetchData']>, JsonValue> &
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
19
|
+
(keyof TOptions['fetchData'] extends `${infer _P}/${infer _S}`
|
|
20
|
+
? Record<string, JsonValue>
|
|
21
|
+
: unknown)
|
|
22
|
+
: LambdaContext
|
|
6
23
|
|
|
7
|
-
declare function ssm
|
|
24
|
+
declare function ssm<TOptions extends Options> (
|
|
25
|
+
options?: TOptions
|
|
26
|
+
): middy.MiddlewareObj<unknown, any, Error, Context<TOptions>>
|
|
8
27
|
|
|
9
28
|
export default ssm
|
package/index.js
CHANGED
|
@@ -30,12 +30,12 @@ const ssmMiddleware = (opts = {})=>{
|
|
|
30
30
|
let batchFetchKeys = [];
|
|
31
31
|
const internalKeys = Object.keys(options.fetchData);
|
|
32
32
|
const fetchKeys = Object.values(options.fetchData);
|
|
33
|
-
for (const [idx,
|
|
34
|
-
if (cachedValues[
|
|
35
|
-
const
|
|
36
|
-
if (
|
|
37
|
-
batchInternalKeys.push(
|
|
38
|
-
batchFetchKeys.push(
|
|
33
|
+
for (const [idx, internalKey] of internalKeys.entries()){
|
|
34
|
+
if (cachedValues[internalKey]) continue;
|
|
35
|
+
const fetchKey = options.fetchData[internalKey];
|
|
36
|
+
if (fetchKey.substr(-1) === '/') continue;
|
|
37
|
+
batchInternalKeys.push(internalKey);
|
|
38
|
+
batchFetchKeys.push(fetchKey);
|
|
39
39
|
if ((!idx || (idx + 1) % awsRequestLimit !== 0) && !(idx + 1 === internalKeys.length)) {
|
|
40
40
|
continue;
|
|
41
41
|
}
|
|
@@ -60,7 +60,7 @@ const ssmMiddleware = (opts = {})=>{
|
|
|
60
60
|
}));
|
|
61
61
|
}).catch((e)=>{
|
|
62
62
|
const value = getCache(options.cacheKey).value ?? {};
|
|
63
|
-
value[
|
|
63
|
+
value[internalKey] = undefined;
|
|
64
64
|
modifyCache(options.cacheKey, value);
|
|
65
65
|
throw e;
|
|
66
66
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/ssm",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.2",
|
|
4
4
|
"description": "SSM (EC2 Systems Manager) parameters middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -62,12 +62,14 @@
|
|
|
62
62
|
},
|
|
63
63
|
"homepage": "https://middy.js.org",
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@middy/util": "3.
|
|
65
|
+
"@middy/util": "3.2.2"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@middy/core": "3.
|
|
68
|
+
"@middy/core": "3.2.2",
|
|
69
|
+
"@types/aws-lambda": "^8.10.101",
|
|
69
70
|
"aws-sdk": "^2.939.0",
|
|
70
|
-
"aws-xray-sdk": "^3.3.3"
|
|
71
|
+
"aws-xray-sdk": "^3.3.3",
|
|
72
|
+
"type-fest": "^2.18.0"
|
|
71
73
|
},
|
|
72
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "4c960a361cc8844f7b2e6202d9544c852366fb01"
|
|
73
75
|
}
|