@middy/sts 2.5.3 → 3.0.0-alpha.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2021 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
3
+ Copyright (c) 2017-2022 Luciano Mammino, will Farrell 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
@@ -91,7 +91,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
91
91
 
92
92
  ## License
93
93
 
94
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2021 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
94
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
95
95
 
96
96
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
97
97
  <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.d.ts CHANGED
@@ -1,18 +1,11 @@
1
1
  import { STS } from 'aws-sdk'
2
- import { captureAWSClient } from 'aws-xray-sdk'
3
2
  import middy from '@middy/core'
3
+ import { Options as MiddyOptions } from '@middy/util'
4
4
 
5
- interface Options<S = STS> {
6
- AwsClient?: new() => S
7
- awsClientOptions?: Partial<STS.Types.ClientConfiguration>
8
- // awsClientAssumeRole?: string,
9
- awsClientCapture?: typeof captureAWSClient
10
- fetchData?: { [key: string]: string }
11
- disablePrefetch?: boolean
12
- cacheKey?: string
13
- cacheExpiry?: number
14
- // setToEnv?: boolean,
15
- setToContext?: boolean
5
+ interface Options<S = STS>
6
+ extends Pick<MiddyOptions<S, STS.Types.ClientConfiguration>,
7
+ 'AwsClient' | 'awsClientOptions' | 'awsClientCapture' |
8
+ 'fetchData' | 'disablePrefetch' | 'cacheKey' | 'cacheExpiry' | 'setToContext'> {
16
9
  }
17
10
 
18
11
  declare function sts (options?: Options): middy.MiddlewareObj
package/index.js CHANGED
@@ -1,30 +1,13 @@
1
- "use strict";
2
-
3
- const {
4
- canPrefetch,
5
- createPrefetchClient,
6
- createClient,
7
- getInternal,
8
- processCache,
9
- getCache,
10
- modifyCache
11
- } = require('@middy/util');
12
-
13
- const STS = require('aws-sdk/clients/sts'); // v2
14
- // const { STS } = require('@aws-sdk/client-sts') // v3
15
-
16
-
1
+ import { canPrefetch, createPrefetchClient, createClient, getInternal, processCache, getCache, modifyCache } from '@middy/util';
2
+ import STS from 'aws-sdk/clients/sts.js';
17
3
  const defaults = {
18
4
  AwsClient: STS,
19
5
  awsClientOptions: {},
20
- // awsClientAssumeRole: undefined, // Not Applicable, as this is the middleware that defines the roles
21
6
  awsClientCapture: undefined,
22
7
  fetchData: {},
23
- // { contextKey: {RoleArn, RoleSessionName} }
24
8
  disablePrefetch: false,
25
9
  cacheKey: 'sts',
26
10
  cacheExpiry: -1,
27
- // setToEnv: false, // returns object, cannot set to process.env
28
11
  setToContext: false
29
12
  };
30
13
 
@@ -37,21 +20,15 @@ const stsMiddleware = (opts = {}) => {
37
20
  const values = {};
38
21
 
39
22
  for (const internalKey of Object.keys(options.fetchData)) {
40
- var _assumeRoleOptions$Ro;
41
-
42
23
  if (cachedValues[internalKey]) continue;
43
- const assumeRoleOptions = options.fetchData[internalKey]; // Date cannot be used here to assign default session name, possibility of collision when > 1 role defined
44
-
45
- assumeRoleOptions.RoleSessionName = (_assumeRoleOptions$Ro = assumeRoleOptions === null || assumeRoleOptions === void 0 ? void 0 : assumeRoleOptions.RoleSessionName) !== null && _assumeRoleOptions$Ro !== void 0 ? _assumeRoleOptions$Ro : 'middy-sts-session-' + Math.ceil(Math.random() * 99999);
46
- values[internalKey] = client.assumeRole(assumeRoleOptions).promise() // Required for aws-sdk v2
47
- .then(resp => ({
24
+ const assumeRoleOptions = options.fetchData[internalKey];
25
+ assumeRoleOptions.RoleSessionName ?? (assumeRoleOptions.RoleSessionName = 'middy-sts-session-' + Math.ceil(Math.random() * 99999));
26
+ values[internalKey] = client.assumeRole(assumeRoleOptions).promise().then(resp => ({
48
27
  accessKeyId: resp.Credentials.AccessKeyId,
49
28
  secretAccessKey: resp.Credentials.SecretAccessKey,
50
29
  sessionToken: resp.Credentials.SessionToken
51
30
  })).catch(e => {
52
- var _getCache$value, _getCache;
53
-
54
- const value = (_getCache$value = (_getCache = getCache(options.cacheKey)) === null || _getCache === void 0 ? void 0 : _getCache.value) !== null && _getCache$value !== void 0 ? _getCache$value : {};
31
+ const value = getCache(options.cacheKey).value ?? {};
55
32
  value[internalKey] = undefined;
56
33
  modifyCache(options.cacheKey, value);
57
34
  throw e;
@@ -69,15 +46,13 @@ const stsMiddleware = (opts = {}) => {
69
46
  }
70
47
 
71
48
  const stsMiddlewareBefore = async request => {
72
- var _prefetch;
73
-
74
49
  if (!client) {
75
50
  client = await createClient(options, request);
76
51
  }
77
52
 
78
53
  const {
79
54
  value
80
- } = (_prefetch = prefetch) !== null && _prefetch !== void 0 ? _prefetch : processCache(options, fetch, request);
55
+ } = prefetch ?? processCache(options, fetch, request);
81
56
  Object.assign(request.internal, value);
82
57
 
83
58
  if (options.setToContext) {
@@ -93,4 +68,4 @@ const stsMiddleware = (opts = {}) => {
93
68
  };
94
69
  };
95
70
 
96
- module.exports = stsMiddleware;
71
+ export default stsMiddleware;
package/package.json CHANGED
@@ -1,18 +1,19 @@
1
1
  {
2
2
  "name": "@middy/sts",
3
- "version": "2.5.3",
3
+ "version": "3.0.0-alpha.2",
4
4
  "description": "STS (Security Token Service) credentials middleware for the middy framework",
5
- "type": "commonjs",
5
+ "type": "module",
6
6
  "engines": {
7
- "node": ">=12"
7
+ "node": ">=14"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
- "main": "index.js",
13
+ "exports": "./index.js",
14
14
  "types": "index.d.ts",
15
15
  "files": [
16
+ "index.js",
16
17
  "index.d.ts"
17
18
  ],
18
19
  "scripts": {
@@ -46,12 +47,12 @@
46
47
  },
47
48
  "homepage": "https://github.com/middyjs/middy#readme",
48
49
  "dependencies": {
49
- "@middy/util": "^2.5.3"
50
+ "@middy/util": "^3.0.0-alpha.2"
50
51
  },
51
52
  "devDependencies": {
52
- "@middy/core": "^2.5.3",
53
+ "@middy/core": "^3.0.0-alpha.2",
53
54
  "aws-sdk": "^2.939.0",
54
55
  "aws-xray-sdk": "^3.3.3"
55
56
  },
56
- "gitHead": "690884d43b9cd632aeca9a5eba1612160b987cd4"
57
+ "gitHead": "de30419273ecbff08f367f47c7e320ec981cf145"
57
58
  }