@middy/secrets-manager 3.0.0-alpha.6 → 3.0.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.
Files changed (4) hide show
  1. package/README.md +26 -16
  2. package/index.cjs +3 -0
  3. package/index.js +2 -67
  4. package/package.json +13 -6
package/README.md CHANGED
@@ -1,26 +1,36 @@
1
- # Middy secrets-manager middleware
2
-
3
- <div align="center">
4
- <img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.png"/>
5
- </div>
6
-
7
1
  <div align="center">
2
+ <h1>Middy secrets-manager middleware</h1>
3
+ <img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.svg"/>
8
4
  <p><strong>Secrets Manager middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda</strong></p>
9
- </div>
10
-
11
- <div align="center">
12
5
  <p>
13
- <a href="http://badge.fury.io/js/%40middy%2Fsecrets-manager">
6
+ <a href="https://www.npmjs.com/package/@middy/secrets-manager?activeTab=versions">
14
7
  <img src="https://badge.fury.io/js/%40middy%2Fsecrets-manager.svg" alt="npm version" style="max-width:100%;">
15
8
  </a>
9
+ <a href="https://packagephobia.com/result?p=@middy/secrets-manager">
10
+ <img src="https://packagephobia.com/badge?p=@middy/secrets-manager" alt="npm install size" style="max-width:100%;">
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%;">
14
+ </a>
15
+ <br/>
16
+ <a href="https://standardjs.com/">
17
+ <img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard Code Style" style="max-width:100%;">
18
+ </a>
16
19
  <a href="https://snyk.io/test/github/middyjs/middy">
17
20
  <img src="https://snyk.io/test/github/middyjs/middy/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/middyjs/middy" style="max-width:100%;">
18
21
  </a>
19
- <a href="https://standardjs.com/">
20
- <img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard Code Style" style="max-width:100%;">
22
+ <a href="https://lgtm.com/projects/g/middyjs/middy/context:javascript">
23
+ <img src="https://img.shields.io/lgtm/grade/javascript/g/middyjs/middy.svg?logo=lgtm&logoWidth=18" alt="Language grade: JavaScript" style="max-width:100%;">
24
+ </a>
25
+ <a href="https://bestpractices.coreinfrastructure.org/projects/5280">
26
+ <img src="https://bestpractices.coreinfrastructure.org/projects/5280/badge" alt="Core Infrastructure Initiative (CII) Best Practices" style="max-width:100%;">
21
27
  </a>
28
+ <br/>
22
29
  <a href="https://gitter.im/middyjs/Lobby">
23
- <img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;">
30
+ <img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;">
31
+ </a>
32
+ <a href="https://stackoverflow.com/questions/tagged/middy?sort=Newest&uqlId=35052">
33
+ <img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;">
24
34
  </a>
25
35
  </p>
26
36
  </div>
@@ -46,9 +56,9 @@ npm install --save @middy/secrets-manager
46
56
  ## Options
47
57
 
48
58
  - `AwsClient` (object) (default `AWS.SecretsManager`): AWS.SecretsManager class constructor (e.g. that has been instrumented with AWS XRay). Must be from `aws-sdk` v2.
49
- - `awsClientOptions` (object) (optional): Options to pass to AWS.SecretsManager class constructor.
50
- - `awsClientAssumeRole` (string) (optional): Internal key where secrets are stored. See [@middy/sts](/packages/sts/README.md) on to set this.
51
- - `awsClientCapture` (function) (optional): Enable XRay by passing `captureAWSClient` from `aws-xray-sdk` in.
59
+ - `awsClientOptions` (object) (default `undefined`): Options to pass to AWS.SecretsManager class constructor.
60
+ - `awsClientAssumeRole` (string) (default `undefined`): Internal key where secrets are stored. See [@middy/sts](/packages/sts/README.md) on to set this.
61
+ - `awsClientCapture` (function) (default `undefined`): Enable XRay by passing `captureAWSClient` from `aws-xray-sdk` in.
52
62
  - `fetchData` (object) (required): Mapping of internal key name to API request parameter `SecretId`.
53
63
  - `disablePrefetch` (boolean) (default `false`): On cold start requests will trigger early if they can. Setting `awsClientAssumeRole` disables prefetch.
54
64
  - `cacheKey` (string) (default `secrets-manager`): Cache key for the fetched data responses. Must be unique across all middleware.
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 _secretsmanagerJs=_interopRequireDefault(require("aws-sdk/clients/secretsmanager.js"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}const defaults={AwsClient:_secretsmanagerJs.default,awsClientOptions:{},awsClientAssumeRole:undefined,awsClientCapture:undefined,fetchData:{},disablePrefetch:false,cacheKey:"secrets-manager",cacheExpiry:-1,setToContext:false};const secretsManagerMiddleware=(opts={})=>{const options={...defaults,...opts};const fetch=(request,cachedValues={})=>{const values={};for(const internalKey of Object.keys(options.fetchData)){if(cachedValues[internalKey])continue;values[internalKey]=client.getSecretValue({SecretId:options.fetchData[internalKey]}).promise().then(resp=>(0,_util).jsonSafeParse(resp.SecretString)).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 secretsManagerMiddlewareBefore=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:secretsManagerMiddlewareBefore}};var _default=secretsManagerMiddleware;exports.default=_default
2
+
3
+ //# sourceMappingURL=index.cjs.map
package/index.js CHANGED
@@ -1,68 +1,3 @@
1
- import { canPrefetch, createPrefetchClient, createClient, getCache, getInternal, processCache, modifyCache, jsonSafeParse } from '@middy/util';
2
- import SecretsManager from 'aws-sdk/clients/secretsmanager.js';
3
- const defaults = {
4
- AwsClient: SecretsManager,
5
- awsClientOptions: {},
6
- awsClientAssumeRole: undefined,
7
- awsClientCapture: undefined,
8
- fetchData: {},
9
- disablePrefetch: false,
10
- cacheKey: 'secrets-manager',
11
- cacheExpiry: -1,
12
- setToContext: false
13
- };
1
+ import{canPrefetch,createPrefetchClient,createClient,getCache,getInternal,processCache,modifyCache,jsonSafeParse}from"@middy/util";import SecretsManager from"aws-sdk/clients/secretsmanager.js";const defaults={AwsClient:SecretsManager,awsClientOptions:{},awsClientAssumeRole:undefined,awsClientCapture:undefined,fetchData:{},disablePrefetch:false,cacheKey:"secrets-manager",cacheExpiry:-1,setToContext:false};const secretsManagerMiddleware=(opts={})=>{const options={...defaults,...opts};const fetch=(request,cachedValues={})=>{const values={};for(const internalKey of Object.keys(options.fetchData)){if(cachedValues[internalKey])continue;values[internalKey]=client.getSecretValue({SecretId:options.fetchData[internalKey]}).promise().then(resp=>jsonSafeParse(resp.SecretString)).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 secretsManagerMiddlewareBefore=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:secretsManagerMiddlewareBefore}};export default secretsManagerMiddleware
14
2
 
15
- const secretsManagerMiddleware = (opts = {}) => {
16
- const options = { ...defaults,
17
- ...opts
18
- };
19
-
20
- const fetch = (request, cachedValues = {}) => {
21
- const values = {};
22
-
23
- for (const internalKey of Object.keys(options.fetchData)) {
24
- if (cachedValues[internalKey]) continue;
25
- values[internalKey] = client.getSecretValue({
26
- SecretId: options.fetchData[internalKey]
27
- }).promise().then(resp => jsonSafeParse(resp.SecretString)).catch(e => {
28
- const value = getCache(options.cacheKey).value ?? {};
29
- value[internalKey] = undefined;
30
- modifyCache(options.cacheKey, value);
31
- throw e;
32
- });
33
- }
34
-
35
- return values;
36
- };
37
-
38
- let prefetch, client;
39
-
40
- if (canPrefetch(options)) {
41
- client = createPrefetchClient(options);
42
- prefetch = processCache(options, fetch);
43
- }
44
-
45
- const secretsManagerMiddlewareBefore = async request => {
46
- if (!client) {
47
- client = await createClient(options, request);
48
- }
49
-
50
- const {
51
- value
52
- } = prefetch ?? processCache(options, fetch, request);
53
- Object.assign(request.internal, value);
54
-
55
- if (options.setToContext) {
56
- const data = await getInternal(Object.keys(options.fetchData), request);
57
- Object.assign(request.context, data);
58
- }
59
-
60
- prefetch = null;
61
- };
62
-
63
- return {
64
- before: secretsManagerMiddlewareBefore
65
- };
66
- };
67
-
68
- export default secretsManagerMiddleware;
3
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/secrets-manager",
3
- "version": "3.0.0-alpha.6",
3
+ "version": "3.0.0",
4
4
  "description": "Secrets Manager 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": {
@@ -44,14 +51,14 @@
44
51
  "bugs": {
45
52
  "url": "https://github.com/middyjs/middy/issues"
46
53
  },
47
- "homepage": "https://github.com/middyjs/middy#readme",
54
+ "homepage": "https://middy.js.org",
48
55
  "dependencies": {
49
- "@middy/util": "^3.0.0-alpha.6"
56
+ "@middy/util": "^3.0.0"
50
57
  },
51
58
  "devDependencies": {
52
- "@middy/core": "^3.0.0-alpha.6",
59
+ "@middy/core": "^3.0.0",
53
60
  "aws-sdk": "^2.939.0",
54
61
  "aws-xray-sdk": "^3.3.3"
55
62
  },
56
- "gitHead": "176660ed3e0716d6bfb635c77251b301e0e24720"
63
+ "gitHead": "01520fa8628a36c2f89e126cad656a16547ea0d6"
57
64
  }