@middy/ssm 7.1.2 → 7.1.4

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 CHANGED
@@ -30,10 +30,23 @@
30
30
  <p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/ssm">https://middy.js.org/docs/middlewares/ssm</a></p>
31
31
  </div>
32
32
 
33
- ## License
33
+ ## Install
34
+
35
+ ```bash
36
+ npm install --save @middy/ssm @aws-sdk/client-ssm
37
+ ```
38
+
39
+
40
+ ## Documentation and examples
41
+
42
+ For documentation and examples, refer to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org/docs/middlewares/ssm).
34
43
 
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
44
 
37
- <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
38
- <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
39
- </a>
45
+ ## Contributing
46
+
47
+ Everyone is very welcome to contribute to this repository. Feel free to [raise issues](https://github.com/middyjs/middy/issues) or to [submit Pull Requests](https://github.com/middyjs/middy/pulls).
48
+
49
+
50
+ ## License
51
+
52
+ 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).
package/index.d.ts CHANGED
@@ -39,7 +39,7 @@ declare function ssm<TOptions extends SSMOptions>(
39
39
  options?: TOptions,
40
40
  ): middy.MiddlewareObj<
41
41
  unknown,
42
- any,
42
+ unknown,
43
43
  Error,
44
44
  Context<TOptions>,
45
45
  Internal<TOptions>
package/index.js CHANGED
@@ -35,11 +35,12 @@ const defaults = {
35
35
  const ssmMiddleware = (opts = {}) => {
36
36
  const options = { ...defaults, ...opts };
37
37
 
38
+ const fetchDataKeys = Object.keys(options.fetchData);
39
+ const fetchDataValues = Object.values(options.fetchData);
38
40
  const fetchRequest = (request, cachedValues) => {
39
- return {
40
- ...fetchSingleRequest(request, cachedValues),
41
- ...fetchByPathRequest(request, cachedValues),
42
- };
41
+ const single = fetchSingleRequest(request, cachedValues);
42
+ const path = fetchByPathRequest(request, cachedValues);
43
+ return Object.assign(single, path);
43
44
  };
44
45
 
45
46
  const fetchSingleRequest = (request, cachedValues = {}) => {
@@ -48,8 +49,8 @@ const ssmMiddleware = (opts = {}) => {
48
49
  const batchKeys = new Map();
49
50
  const namedKeys = [];
50
51
 
51
- const internalKeys = Object.keys(options.fetchData);
52
- const fetchKeys = Object.values(options.fetchData);
52
+ const internalKeys = fetchDataKeys;
53
+ const fetchKeys = fetchDataValues;
53
54
  for (const internalKey of internalKeys) {
54
55
  if (cachedValues[internalKey]) continue;
55
56
  if (options.fetchData[internalKey].endsWith("/")) continue; // Skip path passed in
@@ -77,25 +78,22 @@ const ssmMiddleware = (opts = {}) => {
77
78
  .catch((e) => catchInvalidSignatureException(e, client, command))
78
79
  .then((resp) => {
79
80
  // Don't sanitize key, mapped to set value in options
80
- return Object.assign(
81
- {},
82
- ...(resp.InvalidParameters ?? []).map((fetchKey) => {
83
- return {
84
- [fetchKey]: new Promise(() => {
85
- const internalKey = internalKeys[fetchKeys.indexOf(fetchKey)];
86
- const value = getCache(options.cacheKey).value ?? {};
87
- value[internalKey] = undefined;
88
- modifyCache(options.cacheKey, value);
89
- throw new Error(`InvalidParameter ${fetchKey}`, {
90
- cause: { package: "@middy/ssm" },
91
- });
92
- }),
93
- };
94
- }),
95
- ...(resp.Parameters ?? []).map((param) => {
96
- return { [param.Name]: parseValue(param) };
97
- }),
98
- );
81
+ const result = {};
82
+ for (const fetchKey of resp.InvalidParameters ?? []) {
83
+ result[fetchKey] = new Promise(() => {
84
+ const internalKey = internalKeys[fetchKeys.indexOf(fetchKey)];
85
+ const value = getCache(options.cacheKey).value ?? {};
86
+ value[internalKey] = undefined;
87
+ modifyCache(options.cacheKey, value);
88
+ throw new Error(`InvalidParameter ${fetchKey}`, {
89
+ cause: { package: "@middy/ssm" },
90
+ });
91
+ });
92
+ }
93
+ for (const param of resp.Parameters ?? []) {
94
+ result[param.Name] = parseValue(param);
95
+ }
96
+ return result;
99
97
  })
100
98
  .catch((e) => {
101
99
  const value = getCache(options.cacheKey).value ?? {};
@@ -127,7 +125,7 @@ const ssmMiddleware = (opts = {}) => {
127
125
 
128
126
  const fetchByPathRequest = (request, cachedValues = {}) => {
129
127
  const values = {};
130
- for (const internalKey of Object.keys(options.fetchData)) {
128
+ for (const internalKey of fetchDataKeys) {
131
129
  if (cachedValues[internalKey]) continue;
132
130
  const fetchKey = options.fetchData[internalKey];
133
131
  if (!fetchKey.endsWith("/")) continue; // Skip not path passed in
@@ -152,14 +150,9 @@ const ssmMiddleware = (opts = {}) => {
152
150
  .send(command)
153
151
  .catch((e) => catchInvalidSignatureException(e, client, command))
154
152
  .then((resp) => {
155
- Object.assign(
156
- values,
157
- ...resp.Parameters.map((param) => {
158
- return {
159
- [sanitizeKey(param.Name.replace(path, ""))]: parseValue(param),
160
- };
161
- }),
162
- );
153
+ for (const param of resp.Parameters) {
154
+ values[sanitizeKey(param.Name.replace(path, ""))] = parseValue(param);
155
+ }
163
156
  if (resp.NextToken) {
164
157
  return fetchPathRequest(path, resp.NextToken, values);
165
158
  }
@@ -190,7 +183,7 @@ const ssmMiddleware = (opts = {}) => {
190
183
  Object.assign(request.internal, value);
191
184
 
192
185
  if (options.setToContext) {
193
- const data = await getInternal(Object.keys(options.fetchData), request);
186
+ const data = await getInternal(fetchDataKeys, request);
194
187
  Object.assign(request.context, data);
195
188
  }
196
189
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/ssm",
3
- "version": "7.1.2",
3
+ "version": "7.1.4",
4
4
  "description": "SSM (EC2 Systems Manager) parameters middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -65,7 +65,7 @@
65
65
  "url": "https://github.com/sponsors/willfarrell"
66
66
  },
67
67
  "dependencies": {
68
- "@middy/util": "7.1.2"
68
+ "@middy/util": "7.1.4"
69
69
  },
70
70
  "peerDependencies": {
71
71
  "@aws-sdk/client-ssm": "^3.0.0"
@@ -77,9 +77,9 @@
77
77
  },
78
78
  "devDependencies": {
79
79
  "@aws-sdk/client-ssm": "^3.0.0",
80
- "@middy/core": "7.1.2",
80
+ "@middy/core": "7.1.4",
81
81
  "@types/aws-lambda": "^8.0.0",
82
+ "@types/node": "^22.0.0",
82
83
  "aws-xray-sdk": "^3.3.3"
83
- },
84
- "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
84
+ }
85
85
  }