@middy/sts 3.6.1 → 4.0.0-alpha.0

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
@@ -46,11 +46,10 @@ To install this middleware you can use NPM:
46
46
  npm install --save @middy/sts
47
47
  ```
48
48
 
49
-
50
49
  ## Options
51
50
 
52
- - `AwsClient` (object) (default `AWS.STS`): AWS.STS class constructor (e.g. that has been instrumented with AWS XRay). Must be from `aws-sdk` v2.
53
- - `awsClientOptions` (object) (default `undefined`): Options to pass to AWS.STS class constructor.
51
+ - `AwsClient` (object) (default `STSClient`): STSClient class constructor (e.g. that has been instrumented with AWS XRay). Must be from `@aws-sdk/client-sts`.
52
+ - `awsClientOptions` (object) (default `undefined`): Options to pass to STSClient class constructor.
54
53
  - `awsClientCapture` (function) (default `undefined`): Enable XRay by passing `captureAWSClient` from `aws-xray-sdk` in.
55
54
  - `fetchData` (object) (required): Mapping of internal key name to API request parameters.
56
55
  - `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
@@ -59,6 +58,7 @@ npm install --save @middy/sts
59
58
  - `setToContext` (boolean) (default `false`): Store credentials to `request.context`.
60
59
 
61
60
  NOTES:
61
+
62
62
  - Lambda is required to have IAM permission for `sts:AssumeRole`
63
63
  - `setToContext` are included for legacy support and should be avoided for performance and security reasons. See main documentation for best practices.
64
64
 
@@ -73,33 +73,31 @@ const handler = middy((event, context) => {
73
73
  statusCode: 200,
74
74
  headers: {},
75
75
  body: JSON.stringify({ message: 'hello world' })
76
- };
76
+ }
77
77
 
78
78
  return response
79
79
  })
80
80
 
81
- handler
82
- .use(sts({
81
+ handler.use(
82
+ sts({
83
83
  fetchData: {
84
84
  assumeRole: {
85
85
  RoleArn: '...',
86
- RoleSessionName:'' // optional
86
+ RoleSessionName: '' // optional
87
87
  }
88
88
  }
89
- }))
89
+ })
90
+ )
90
91
  ```
91
92
 
92
-
93
93
  ## Middy documentation and examples
94
94
 
95
95
  For more documentation and examples, refers to the main [Middy monorepo on GitHub](https://github.com/middyjs/middy) or [Middy official website](https://middy.js.org).
96
96
 
97
-
98
97
  ## Contributing
99
98
 
100
99
  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).
101
100
 
102
-
103
101
  ## License
104
102
 
105
103
  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).
package/index.cjs CHANGED
@@ -7,15 +7,9 @@ Object.defineProperty(module, "exports", {
7
7
  get: ()=>_default
8
8
  });
9
9
  const _util = require("@middy/util");
10
- const _stsJs = _interopRequireDefault(require("aws-sdk/clients/sts.js"));
11
- function _interopRequireDefault(obj) {
12
- return obj && obj.__esModule ? obj : {
13
- default: obj
14
- };
15
- }
16
- var _assumeRoleOptions;
10
+ const _clientSts = require("@aws-sdk/client-sts");
17
11
  const defaults = {
18
- AwsClient: _stsJs.default,
12
+ AwsClient: _clientSts.STSClient,
19
13
  awsClientOptions: {},
20
14
  awsClientCapture: undefined,
21
15
  fetchData: {},
@@ -34,8 +28,8 @@ const stsMiddleware = (opts = {})=>{
34
28
  for (const internalKey of Object.keys(options.fetchData)){
35
29
  if (cachedValues[internalKey]) continue;
36
30
  const assumeRoleOptions = options.fetchData[internalKey];
37
- (_assumeRoleOptions = assumeRoleOptions).RoleSessionName ?? (_assumeRoleOptions.RoleSessionName = 'middy-sts-session-' + Math.ceil(Math.random() * 99999));
38
- values[internalKey] = client.assumeRole(assumeRoleOptions).promise().then((resp)=>({
31
+ assumeRoleOptions.RoleSessionName ??= 'middy-sts-session-' + Math.ceil(Math.random() * 99999);
32
+ values[internalKey] = client.send(new _clientSts.AssumeRoleCommand(assumeRoleOptions)).then((resp)=>({
39
33
  accessKeyId: resp.Credentials.AccessKeyId,
40
34
  secretAccessKey: resp.Credentials.SecretAccessKey,
41
35
  sessionToken: resp.Credentials.SessionToken
package/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  import middy from '@middy/core'
2
2
  import { Options as MiddyOptions } from '@middy/util'
3
3
  import { Context as LambdaContext } from 'aws-lambda'
4
- import STS from 'aws-sdk/clients/sts'
4
+ import { STSClient, STSClientConfig } from '@aws-sdk/client-sts'
5
5
 
6
- interface Options<S = STS>
6
+ interface Options<AwsSTSClient = STSClient>
7
7
  extends Pick<
8
- MiddyOptions<S, STS.Types.ClientConfiguration>,
8
+ MiddyOptions<AwsSTSClient, STSClientConfig>,
9
9
  | 'AwsClient'
10
10
  | 'awsClientOptions'
11
11
  | 'awsClientCapture'
@@ -23,9 +23,7 @@ export type Context<TOptions extends Options | undefined> = TOptions extends {
23
23
  Record<
24
24
  keyof TOptions['fetchData'],
25
25
  {
26
- accessKeyId: STS.accessKeyIdType
27
- secretAccessKey: STS.accessKeySecretType
28
- sessionToken: STS.tokenType
26
+ credentials: STSClientConfig['credentials']
29
27
  }
30
28
  >
31
29
  : LambdaContext
package/index.js CHANGED
@@ -1,8 +1,7 @@
1
- var _assumeRoleOptions;
2
1
  import { canPrefetch, createPrefetchClient, createClient, getCache, getInternal, processCache, modifyCache } from '@middy/util';
3
- import STS from 'aws-sdk/clients/sts.js';
2
+ import { STSClient, AssumeRoleCommand } from '@aws-sdk/client-sts';
4
3
  const defaults = {
5
- AwsClient: STS,
4
+ AwsClient: STSClient,
6
5
  awsClientOptions: {},
7
6
  awsClientCapture: undefined,
8
7
  fetchData: {},
@@ -21,8 +20,8 @@ const stsMiddleware = (opts = {})=>{
21
20
  for (const internalKey of Object.keys(options.fetchData)){
22
21
  if (cachedValues[internalKey]) continue;
23
22
  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)=>({
23
+ assumeRoleOptions.RoleSessionName ??= 'middy-sts-session-' + Math.ceil(Math.random() * 99999);
24
+ values[internalKey] = client.send(new AssumeRoleCommand(assumeRoleOptions)).then((resp)=>({
26
25
  accessKeyId: resp.Credentials.AccessKeyId,
27
26
  secretAccessKey: resp.Credentials.SecretAccessKey,
28
27
  sessionToken: resp.Credentials.SessionToken
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@middy/sts",
3
- "version": "3.6.1",
3
+ "version": "4.0.0-alpha.0",
4
4
  "description": "STS (Security Token Service) credentials middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
7
- "node": ">=14"
7
+ "node": ">=16"
8
8
  },
9
9
  "engineStrict": true,
10
10
  "publishConfig": {
@@ -62,13 +62,13 @@
62
62
  },
63
63
  "homepage": "https://middy.js.org",
64
64
  "dependencies": {
65
- "@middy/util": "3.6.1"
65
+ "@middy/util": "4.0.0-alpha.0"
66
66
  },
67
67
  "devDependencies": {
68
- "@middy/core": "3.6.1",
68
+ "@aws-sdk/client-sts": "^3.186.0",
69
+ "@middy/core": "4.0.0-alpha.0",
69
70
  "@types/aws-lambda": "^8.10.101",
70
- "aws-sdk": "^2.939.0",
71
71
  "aws-xray-sdk": "^3.3.3"
72
72
  },
73
- "gitHead": "31a7f9f8e93a73a8be382b3022b9cfcbc13b2961"
73
+ "gitHead": "306fb9aa633d5757d11ced3dc192f046ef3c2685"
74
74
  }