@middy/sts 3.0.3 → 3.0.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.
Files changed (3) hide show
  1. package/index.cjs +71 -1
  2. package/index.js +60 -1
  3. package/package.json +4 -4
package/index.cjs CHANGED
@@ -1,3 +1,73 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});module.exports=void 0;var _util=require("@middy/util");var _stsJs=_interopRequireDefault(require("aws-sdk/clients/sts.js"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}var _assumeRoleOptions;const defaults={AwsClient:_stsJs.default,awsClientOptions:{},awsClientCapture:undefined,fetchData:{},disablePrefetch:false,cacheKey:"sts",cacheExpiry:-1,setToContext:false};const stsMiddleware=(opts={})=>{const options={...defaults,...opts};const fetch=(request,cachedValues={})=>{const values={};for(const internalKey of Object.keys(options.fetchData)){if(cachedValues[internalKey])continue;const assumeRoleOptions=options.fetchData[internalKey];(_assumeRoleOptions=assumeRoleOptions).RoleSessionName??(_assumeRoleOptions.RoleSessionName="middy-sts-session-"+Math.ceil(Math.random()*99999));values[internalKey]=client.assumeRole(assumeRoleOptions).promise().then(resp=>({accessKeyId:resp.Credentials.AccessKeyId,secretAccessKey:resp.Credentials.SecretAccessKey,sessionToken:resp.Credentials.SessionToken})).catch(e=>{const value=(0,_util).getCache(options.cacheKey).value??{};value[internalKey]=undefined;(0,_util).modifyCache(options.cacheKey,value);throw e})}return values};let prefetch,client;if((0,_util).canPrefetch(options)){client=(0,_util).createPrefetchClient(options);prefetch=(0,_util).processCache(options,fetch)}const stsMiddlewareBefore=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);if(options.setToContext)Object.assign(request.context,data)}prefetch=null};return{before:stsMiddlewareBefore}};var _default=stsMiddleware;module.exports=_default
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ module.exports = void 0;
6
+ var _util = require("@middy/util");
7
+ var _stsJs = _interopRequireDefault(require("aws-sdk/clients/sts.js"));
8
+ function _interopRequireDefault(obj) {
9
+ return obj && obj.__esModule ? obj : {
10
+ default: obj
11
+ };
12
+ }
13
+ var _assumeRoleOptions;
14
+ const defaults = {
15
+ AwsClient: _stsJs.default,
16
+ awsClientOptions: {},
17
+ awsClientCapture: undefined,
18
+ fetchData: {},
19
+ disablePrefetch: false,
20
+ cacheKey: 'sts',
21
+ cacheExpiry: -1,
22
+ setToContext: false
23
+ };
24
+ const stsMiddleware = (opts = {})=>{
25
+ const options = {
26
+ ...defaults,
27
+ ...opts
28
+ };
29
+ const fetch = (request, cachedValues = {})=>{
30
+ const values = {};
31
+ for (const internalKey of Object.keys(options.fetchData)){
32
+ if (cachedValues[internalKey]) continue;
33
+ const assumeRoleOptions = options.fetchData[internalKey];
34
+ (_assumeRoleOptions = assumeRoleOptions).RoleSessionName ?? (_assumeRoleOptions.RoleSessionName = 'middy-sts-session-' + Math.ceil(Math.random() * 99999));
35
+ values[internalKey] = client.assumeRole(assumeRoleOptions).promise().then((resp)=>({
36
+ accessKeyId: resp.Credentials.AccessKeyId,
37
+ secretAccessKey: resp.Credentials.SecretAccessKey,
38
+ sessionToken: resp.Credentials.SessionToken
39
+ })).catch((e)=>{
40
+ const value = (0, _util).getCache(options.cacheKey).value ?? {};
41
+ value[internalKey] = undefined;
42
+ (0, _util).modifyCache(options.cacheKey, value);
43
+ throw e;
44
+ });
45
+ }
46
+ return values;
47
+ };
48
+ let prefetch, client;
49
+ if ((0, _util).canPrefetch(options)) {
50
+ client = (0, _util).createPrefetchClient(options);
51
+ prefetch = (0, _util).processCache(options, fetch);
52
+ }
53
+ const stsMiddlewareBefore = async (request)=>{
54
+ if (!client) {
55
+ client = await (0, _util).createClient(options, request);
56
+ }
57
+ const { value } = prefetch ?? (0, _util).processCache(options, fetch, request);
58
+ Object.assign(request.internal, value);
59
+ if (options.setToContext) {
60
+ const data = await (0, _util).getInternal(Object.keys(options.fetchData), request);
61
+ if (options.setToContext) Object.assign(request.context, data);
62
+ }
63
+ prefetch = null;
64
+ };
65
+ return {
66
+ before: stsMiddlewareBefore
67
+ };
68
+ };
69
+ var _default = stsMiddleware;
70
+ module.exports = _default;
71
+
2
72
 
3
73
  //# sourceMappingURL=index.cjs.map
package/index.js CHANGED
@@ -1,3 +1,62 @@
1
- var _assumeRoleOptions;import{canPrefetch,createPrefetchClient,createClient,getCache,getInternal,processCache,modifyCache}from"@middy/util";import STS from"aws-sdk/clients/sts.js";const defaults={AwsClient:STS,awsClientOptions:{},awsClientCapture:undefined,fetchData:{},disablePrefetch:false,cacheKey:"sts",cacheExpiry:-1,setToContext:false};const stsMiddleware=(opts={})=>{const options={...defaults,...opts};const fetch=(request,cachedValues={})=>{const values={};for(const internalKey of Object.keys(options.fetchData)){if(cachedValues[internalKey])continue;const assumeRoleOptions=options.fetchData[internalKey];(_assumeRoleOptions=assumeRoleOptions).RoleSessionName??(_assumeRoleOptions.RoleSessionName="middy-sts-session-"+Math.ceil(Math.random()*99999));values[internalKey]=client.assumeRole(assumeRoleOptions).promise().then(resp=>({accessKeyId:resp.Credentials.AccessKeyId,secretAccessKey:resp.Credentials.SecretAccessKey,sessionToken:resp.Credentials.SessionToken})).catch(e=>{const value=getCache(options.cacheKey).value??{};value[internalKey]=undefined;modifyCache(options.cacheKey,value);throw e})}return values};let prefetch,client;if(canPrefetch(options)){client=createPrefetchClient(options);prefetch=processCache(options,fetch)}const stsMiddlewareBefore=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);if(options.setToContext)Object.assign(request.context,data)}prefetch=null};return{before:stsMiddlewareBefore}};export default stsMiddleware
1
+ var _assumeRoleOptions;
2
+ import { canPrefetch, createPrefetchClient, createClient, getCache, getInternal, processCache, modifyCache } from '@middy/util';
3
+ import STS from 'aws-sdk/clients/sts.js';
4
+ const defaults = {
5
+ AwsClient: STS,
6
+ awsClientOptions: {},
7
+ awsClientCapture: undefined,
8
+ fetchData: {},
9
+ disablePrefetch: false,
10
+ cacheKey: 'sts',
11
+ cacheExpiry: -1,
12
+ setToContext: false
13
+ };
14
+ const stsMiddleware = (opts = {})=>{
15
+ const options = {
16
+ ...defaults,
17
+ ...opts
18
+ };
19
+ const fetch = (request, cachedValues = {})=>{
20
+ const values = {};
21
+ for (const internalKey of Object.keys(options.fetchData)){
22
+ if (cachedValues[internalKey]) continue;
23
+ const assumeRoleOptions = options.fetchData[internalKey];
24
+ (_assumeRoleOptions = assumeRoleOptions).RoleSessionName ?? (_assumeRoleOptions.RoleSessionName = 'middy-sts-session-' + Math.ceil(Math.random() * 99999));
25
+ values[internalKey] = client.assumeRole(assumeRoleOptions).promise().then((resp)=>({
26
+ accessKeyId: resp.Credentials.AccessKeyId,
27
+ secretAccessKey: resp.Credentials.SecretAccessKey,
28
+ sessionToken: resp.Credentials.SessionToken
29
+ })).catch((e)=>{
30
+ const value = getCache(options.cacheKey).value ?? {};
31
+ value[internalKey] = undefined;
32
+ modifyCache(options.cacheKey, value);
33
+ throw e;
34
+ });
35
+ }
36
+ return values;
37
+ };
38
+ let prefetch, client;
39
+ if (canPrefetch(options)) {
40
+ client = createPrefetchClient(options);
41
+ prefetch = processCache(options, fetch);
42
+ }
43
+ const stsMiddlewareBefore = async (request)=>{
44
+ if (!client) {
45
+ client = await createClient(options, request);
46
+ }
47
+ const { value } = prefetch ?? processCache(options, fetch, request);
48
+ Object.assign(request.internal, value);
49
+ if (options.setToContext) {
50
+ const data = await getInternal(Object.keys(options.fetchData), request);
51
+ if (options.setToContext) Object.assign(request.context, data);
52
+ }
53
+ prefetch = null;
54
+ };
55
+ return {
56
+ before: stsMiddlewareBefore
57
+ };
58
+ };
59
+ export default stsMiddleware;
60
+
2
61
 
3
62
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/sts",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "description": "STS (Security Token Service) credentials 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.3"
58
+ "@middy/util": "3.0.4"
59
59
  },
60
60
  "devDependencies": {
61
- "@middy/core": "3.0.3",
61
+ "@middy/core": "3.0.4",
62
62
  "aws-sdk": "^2.939.0",
63
63
  "aws-xray-sdk": "^3.3.3"
64
64
  },
65
- "gitHead": "ea9e5e8cce754d0c467c7dd3ac9a7601149efea2"
65
+ "gitHead": "3e9bc83e791f943c71cd7003fc27f0a3692d83a1"
66
66
  }