@middy/ssm 3.0.0-alpha.7 → 3.0.1

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.
Files changed (3) hide show
  1. package/index.cjs +3 -0
  2. package/index.js +1 -1
  3. package/package.json +13 -6
package/index.cjs ADDED
@@ -0,0 +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
2
+
3
+ //# sourceMappingURL=index.cjs.map
package/index.js CHANGED
@@ -1,3 +1,3 @@
1
- import{canPrefetch,createPrefetchClient,createClient,processCache,getCache,modifyCache,jsonSafeParse,getInternal,sanitizeKey}from'@middy/util';import SSM from'aws-sdk/clients/ssm.js';const awsRequestLimit=10;const defaults={AwsClient:SSM,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=getCache(options.cacheKey).value??{};value[internalKey]=undefined;modifyCache(options.cacheKey,value);throw new Error('[ssm] InvalidParameter '+fetchKey)})}}),...(resp.Parameters??[]).map(param=>{return{[param.Name]:parseValue(param)}}))}).catch(e=>{const value=getCache(options.cacheKey).value??{};value[internalKey2]=undefined;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=getCache(options.cacheKey).value??{};value[internalKey]=undefined;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{[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 jsonSafeParse(param.Value)};let prefetch,client;if(canPrefetch(options)){client=createPrefetchClient(options);prefetch=processCache(options,fetch)}const ssmMiddlewareBefore=async request=>{if(!client){client=await createClient(options,request)}const{value}=prefetch??processCache(options,fetch,request);Object.assign(request.internal,value);if(options.setToContext){const data=await getInternal(Object.keys(options.fetchData),request);Object.assign(request.context,data)}prefetch=null};return{before:ssmMiddlewareBefore}};export default ssmMiddleware
1
+ import{canPrefetch,createPrefetchClient,createClient,processCache,getCache,modifyCache,jsonSafeParse,getInternal,sanitizeKey}from"@middy/util";import SSM from"aws-sdk/clients/ssm.js";const awsRequestLimit=10;const defaults={AwsClient:SSM,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=getCache(options.cacheKey).value??{};value[internalKey]=undefined;modifyCache(options.cacheKey,value);throw new Error("[ssm] InvalidParameter "+fetchKey)})}}),...(resp.Parameters??[]).map(param=>{return{[param.Name]:parseValue(param)}}))}).catch(e=>{const value=getCache(options.cacheKey).value??{};value[internalKey2]=undefined;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=getCache(options.cacheKey).value??{};value[internalKey]=undefined;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{[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 jsonSafeParse(param.Value)};let prefetch,client;if(canPrefetch(options)){client=createPrefetchClient(options);prefetch=processCache(options,fetch)}const ssmMiddlewareBefore=async request=>{if(!client){client=await createClient(options,request)}const{value}=prefetch??processCache(options,fetch,request);Object.assign(request.internal,value);if(options.setToContext){const data=await getInternal(Object.keys(options.fetchData),request);Object.assign(request.context,data)}prefetch=null};return{before:ssmMiddlewareBefore}};export default ssmMiddleware
2
2
 
3
3
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/ssm",
3
- "version": "3.0.0-alpha.7",
3
+ "version": "3.0.1",
4
4
  "description": "SSM (EC2 Systems Manager) parameters middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -10,10 +10,17 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "exports": "./index.js",
13
+ "exports": {
14
+ ".": {
15
+ "import": "./index.js",
16
+ "require": "./index.cjs",
17
+ "types": "./index.d.ts"
18
+ }
19
+ },
14
20
  "types": "index.d.ts",
15
21
  "files": [
16
22
  "index.js",
23
+ "index.cjs",
17
24
  "index.d.ts"
18
25
  ],
19
26
  "scripts": {
@@ -46,14 +53,14 @@
46
53
  "bugs": {
47
54
  "url": "https://github.com/middyjs/middy/issues"
48
55
  },
49
- "homepage": "https://github.com/middyjs/middy#readme",
56
+ "homepage": "https://middy.js.org",
50
57
  "dependencies": {
51
- "@middy/util": "^3.0.0-alpha.7"
58
+ "@middy/util": "^3.0.1"
52
59
  },
53
60
  "devDependencies": {
54
- "@middy/core": "^3.0.0-alpha.7",
61
+ "@middy/core": "^3.0.1",
55
62
  "aws-sdk": "^2.939.0",
56
63
  "aws-xray-sdk": "^3.3.3"
57
64
  },
58
- "gitHead": "5cef39ebe49c201f97d71bb0680004de4b82cb91"
65
+ "gitHead": "797455e2c2be445867bc03597e0a2d5b0560c9de"
59
66
  }