@middy/ssm 3.0.0 → 3.0.3

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
3
+ Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell) and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -9,8 +9,8 @@
9
9
  <a href="https://packagephobia.com/result?p=@middy/ssm">
10
10
  <img src="https://packagephobia.com/badge?p=@middy/ssm" alt="npm install size" style="max-width:100%;">
11
11
  </a>
12
- <a href="https://github.com/middyjs/middy/actions">
13
- <img src="https://github.com/middyjs/middy/workflows/Tests/badge.svg" alt="GitHub Actions test status badge" style="max-width:100%;">
12
+ <a href="https://github.com/middyjs/middy/actions/workflows/tests.yml">
13
+ <img src="https://github.com/middyjs/middy/actions/workflows/tests.yml/badge.svg?branch=main&event=push" alt="GitHub Actions CI status badge" style="max-width:100%;">
14
14
  </a>
15
15
  <br/>
16
16
  <a href="https://standardjs.com/">
@@ -33,6 +33,7 @@
33
33
  <img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;">
34
34
  </a>
35
35
  </p>
36
+ <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>
36
37
  </div>
37
38
 
38
39
  This middleware fetches parameters from [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-paramstore.html).
@@ -141,7 +142,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
141
142
 
142
143
  ## License
143
144
 
144
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
145
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
145
146
 
146
147
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
147
148
  <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.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _util=require("@middy/util");var _ssmJs=_interopRequireDefault(require("aws-sdk/clients/ssm.js"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}const awsRequestLimit=10;const defaults={AwsClient:_ssmJs.default,awsClientOptions:{},awsClientAssumeRole:undefined,awsClientCapture:undefined,fetchData:{},disablePrefetch:false,cacheKey:"ssm",cacheExpiry:-1,setToContext:false};const ssmMiddleware=(opts={})=>{const options={...defaults,...opts};const fetch=(request,cachedValues)=>{return{...fetchSingle(request,cachedValues),...fetchByPath(request,cachedValues)}};const fetchSingle=(request,cachedValues={})=>{const values={};let batchReq=null;let batchInternalKeys=[];let batchFetchKeys=[];const internalKeys=Object.keys(options.fetchData);const fetchKeys=Object.values(options.fetchData);for(const[idx,internalKey2]of internalKeys.entries()){if(cachedValues[internalKey2])continue;const fetchKey1=options.fetchData[internalKey2];if(fetchKey1.substr(-1)==="/")continue;batchInternalKeys.push(internalKey2);batchFetchKeys.push(fetchKey1);if((!idx||(idx+1)%awsRequestLimit!==0)&&!(idx+1===internalKeys.length)){continue}batchReq=client.getParameters({Names:batchFetchKeys,WithDecryption:true}).promise().then(resp=>{return Object.assign(...(resp.InvalidParameters??[]).map(fetchKey=>{return{[fetchKey]:new Promise(()=>{const internalKey=internalKeys[fetchKeys.indexOf(fetchKey)];const value=(0,_util).getCache(options.cacheKey).value??{};value[internalKey]=undefined;(0,_util).modifyCache(options.cacheKey,value);throw new Error("[ssm] InvalidParameter "+fetchKey)})}}),...(resp.Parameters??[]).map(param=>{return{[param.Name]:parseValue(param)}}))}).catch(e=>{const value=(0,_util).getCache(options.cacheKey).value??{};value[internalKey2]=undefined;(0,_util).modifyCache(options.cacheKey,value);throw e});for(const internalKey1 of batchInternalKeys){values[internalKey1]=batchReq.then(params=>{return params[options.fetchData[internalKey1]]})}batchInternalKeys=[];batchFetchKeys=[];batchReq=null}return values};const fetchByPath=(request,cachedValues={})=>{const values={};for(const internalKey in options.fetchData){if(cachedValues[internalKey])continue;const fetchKey=options.fetchData[internalKey];if(fetchKey.substr(-1)!=="/")continue;values[internalKey]=fetchPath(fetchKey).catch(e=>{const value=(0,_util).getCache(options.cacheKey).value??{};value[internalKey]=undefined;(0,_util).modifyCache(options.cacheKey,value);throw e})}return values};const fetchPath=(path,nextToken,values={})=>{return client.getParametersByPath({Path:path,NextToken:nextToken,Recursive:true,WithDecryption:true}).promise().then(resp=>{Object.assign(values,...resp.Parameters.map(param=>{return{[(0,_util).sanitizeKey(param.Name.replace(path,""))]:parseValue(param)}}));if(resp.NextToken)return fetchPath(path,resp.NextToken,values);return values})};const parseValue=param=>{if(param.Type==="StringList"){return param.Value.split(",")}return(0,_util).jsonSafeParse(param.Value)};let prefetch,client;if((0,_util).canPrefetch(options)){client=(0,_util).createPrefetchClient(options);prefetch=(0,_util).processCache(options,fetch)}const ssmMiddlewareBefore=async request=>{if(!client){client=await (0,_util).createClient(options,request)}const{value}=prefetch??(0,_util).processCache(options,fetch,request);Object.assign(request.internal,value);if(options.setToContext){const data=await (0,_util).getInternal(Object.keys(options.fetchData),request);Object.assign(request.context,data)}prefetch=null};return{before:ssmMiddlewareBefore}};var _default=ssmMiddleware;exports.default=_default
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});module.exports=void 0;var _util=require("@middy/util");var _ssmJs=_interopRequireDefault(require("aws-sdk/clients/ssm.js"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}const awsRequestLimit=10;const defaults={AwsClient:_ssmJs.default,awsClientOptions:{},awsClientAssumeRole:undefined,awsClientCapture:undefined,fetchData:{},disablePrefetch:false,cacheKey:"ssm",cacheExpiry:-1,setToContext:false};const ssmMiddleware=(opts={})=>{const options={...defaults,...opts};const fetch=(request,cachedValues)=>{return{...fetchSingle(request,cachedValues),...fetchByPath(request,cachedValues)}};const fetchSingle=(request,cachedValues={})=>{const values={};let batchReq=null;let batchInternalKeys=[];let batchFetchKeys=[];const internalKeys=Object.keys(options.fetchData);const fetchKeys=Object.values(options.fetchData);for(const[idx,internalKey2]of internalKeys.entries()){if(cachedValues[internalKey2])continue;const fetchKey1=options.fetchData[internalKey2];if(fetchKey1.substr(-1)==="/")continue;batchInternalKeys.push(internalKey2);batchFetchKeys.push(fetchKey1);if((!idx||(idx+1)%awsRequestLimit!==0)&&!(idx+1===internalKeys.length)){continue}batchReq=client.getParameters({Names:batchFetchKeys,WithDecryption:true}).promise().then(resp=>{return Object.assign(...(resp.InvalidParameters??[]).map(fetchKey=>{return{[fetchKey]:new Promise(()=>{const internalKey=internalKeys[fetchKeys.indexOf(fetchKey)];const value=(0,_util).getCache(options.cacheKey).value??{};value[internalKey]=undefined;(0,_util).modifyCache(options.cacheKey,value);throw new Error("[ssm] InvalidParameter "+fetchKey)})}}),...(resp.Parameters??[]).map(param=>{return{[param.Name]:parseValue(param)}}))}).catch(e=>{const value=(0,_util).getCache(options.cacheKey).value??{};value[internalKey2]=undefined;(0,_util).modifyCache(options.cacheKey,value);throw e});for(const internalKey1 of batchInternalKeys){values[internalKey1]=batchReq.then(params=>{return params[options.fetchData[internalKey1]]})}batchInternalKeys=[];batchFetchKeys=[];batchReq=null}return values};const fetchByPath=(request,cachedValues={})=>{const values={};for(const internalKey in options.fetchData){if(cachedValues[internalKey])continue;const fetchKey=options.fetchData[internalKey];if(fetchKey.substr(-1)!=="/")continue;values[internalKey]=fetchPath(fetchKey).catch(e=>{const value=(0,_util).getCache(options.cacheKey).value??{};value[internalKey]=undefined;(0,_util).modifyCache(options.cacheKey,value);throw e})}return values};const fetchPath=(path,nextToken,values={})=>{return client.getParametersByPath({Path:path,NextToken:nextToken,Recursive:true,WithDecryption:true}).promise().then(resp=>{Object.assign(values,...resp.Parameters.map(param=>{return{[(0,_util).sanitizeKey(param.Name.replace(path,""))]:parseValue(param)}}));if(resp.NextToken)return fetchPath(path,resp.NextToken,values);return values})};const parseValue=param=>{if(param.Type==="StringList"){return param.Value.split(",")}return(0,_util).jsonSafeParse(param.Value)};let prefetch,client;if((0,_util).canPrefetch(options)){client=(0,_util).createPrefetchClient(options);prefetch=(0,_util).processCache(options,fetch)}const ssmMiddlewareBefore=async request=>{if(!client){client=await (0,_util).createClient(options,request)}const{value}=prefetch??(0,_util).processCache(options,fetch,request);Object.assign(request.internal,value);if(options.setToContext){const data=await (0,_util).getInternal(Object.keys(options.fetchData),request);Object.assign(request.context,data)}prefetch=null};return{before:ssmMiddlewareBefore}};var _default=ssmMiddleware;module.exports=_default
2
2
 
3
3
  //# sourceMappingURL=index.cjs.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/ssm",
3
- "version": "3.0.0",
3
+ "version": "3.0.3",
4
4
  "description": "SSM (EC2 Systems Manager) parameters middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -55,12 +55,12 @@
55
55
  },
56
56
  "homepage": "https://middy.js.org",
57
57
  "dependencies": {
58
- "@middy/util": "^3.0.0"
58
+ "@middy/util": "3.0.3"
59
59
  },
60
60
  "devDependencies": {
61
- "@middy/core": "^3.0.0",
61
+ "@middy/core": "3.0.3",
62
62
  "aws-sdk": "^2.939.0",
63
63
  "aws-xray-sdk": "^3.3.3"
64
64
  },
65
- "gitHead": "01520fa8628a36c2f89e126cad656a16547ea0d6"
65
+ "gitHead": "ea9e5e8cce754d0c467c7dd3ac9a7601149efea2"
66
66
  }