@middy/secrets-manager 7.2.2 → 7.3.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 (3) hide show
  1. package/index.d.ts +4 -0
  2. package/index.js +24 -7
  3. package/package.json +3 -6
package/index.d.ts CHANGED
@@ -55,4 +55,8 @@ declare function secretsManager<
55
55
  Internal<TOptions>
56
56
  >;
57
57
 
58
+ export declare function secretsManagerValidateOptions(
59
+ options?: Record<string, unknown>,
60
+ ): void;
61
+
58
62
  export default secretsManager;
package/index.js CHANGED
@@ -6,6 +6,7 @@ import {
6
6
  SecretsManagerClient,
7
7
  } from "@aws-sdk/client-secrets-manager";
8
8
  import {
9
+ awsClientOptionSchema,
9
10
  canPrefetch,
10
11
  catchInvalidSignatureException,
11
12
  createClient,
@@ -15,6 +16,7 @@ import {
15
16
  jsonSafeParse,
16
17
  modifyCache,
17
18
  processCache,
19
+ validateOptions,
18
20
  } from "@middy/util";
19
21
 
20
22
  const defaults = {
@@ -31,6 +33,16 @@ const defaults = {
31
33
  setToContext: false,
32
34
  };
33
35
 
36
+ const optionSchema = {
37
+ ...awsClientOptionSchema,
38
+ fetchRotationDate: (v) =>
39
+ typeof v === "boolean" ||
40
+ (v !== null && typeof v === "object" && !Array.isArray(v)),
41
+ };
42
+
43
+ export const secretsManagerValidateOptions = (options) =>
44
+ validateOptions("@middy/secrets-manager", optionSchema, options);
45
+
34
46
  const secretsManagerMiddleware = (opts = {}) => {
35
47
  const options = {
36
48
  ...defaults,
@@ -66,18 +78,21 @@ const secretsManagerMiddleware = (opts = {}) => {
66
78
  )
67
79
  .then((resp) => {
68
80
  if (options.cacheExpiry < 0) {
69
- options.cacheKeyExpiry[internalKey] =
70
- resp.NextRotationDate * 1000;
81
+ if (resp.NextRotationDate) {
82
+ options.cacheKeyExpiry[internalKey] =
83
+ resp.NextRotationDate * 1000;
84
+ }
71
85
  } else {
72
- options.cacheKeyExpiry[internalKey] = Math.min(
86
+ const lastChanged =
73
87
  Math.max(
74
88
  resp.LastRotationDate ?? 0,
75
89
  resp.LastChangedDate ?? 0,
76
90
  ) *
77
91
  1000 +
78
- options.cacheExpiry,
79
- resp.NextRotationDate * 1000,
80
- );
92
+ options.cacheExpiry;
93
+ options.cacheKeyExpiry[internalKey] = resp.NextRotationDate
94
+ ? Math.min(lastChanged, resp.NextRotationDate * 1000)
95
+ : lastChanged;
81
96
  }
82
97
  })
83
98
  : undefined;
@@ -105,6 +120,7 @@ const secretsManagerMiddleware = (opts = {}) => {
105
120
  };
106
121
 
107
122
  let client;
123
+ let clientInit;
108
124
  if (canPrefetch(options)) {
109
125
  client = createPrefetchClient(options);
110
126
  processCache(options, fetchRequest);
@@ -112,7 +128,8 @@ const secretsManagerMiddleware = (opts = {}) => {
112
128
 
113
129
  const secretsManagerMiddlewareBefore = async (request) => {
114
130
  if (!client) {
115
- client = await createClient(options, request);
131
+ clientInit ??= createClient(options, request);
132
+ client = await clientInit;
116
133
  }
117
134
 
118
135
  const { value } = processCache(options, fetchRequest, request);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/secrets-manager",
3
- "version": "7.2.2",
3
+ "version": "7.3.0",
4
4
  "description": "Secrets Manager middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -17,9 +17,6 @@
17
17
  "import": {
18
18
  "types": "./index.d.ts",
19
19
  "default": "./index.js"
20
- },
21
- "require": {
22
- "default": "./index.js"
23
20
  }
24
21
  }
25
22
  },
@@ -63,7 +60,7 @@
63
60
  "url": "https://github.com/sponsors/willfarrell"
64
61
  },
65
62
  "dependencies": {
66
- "@middy/util": "7.2.2"
63
+ "@middy/util": "7.3.0"
67
64
  },
68
65
  "peerDependencies": {
69
66
  "@aws-sdk/client-secrets-manager": "^3.0.0"
@@ -75,7 +72,7 @@
75
72
  },
76
73
  "devDependencies": {
77
74
  "@aws-sdk/client-secrets-manager": "^3.0.0",
78
- "@middy/core": "7.2.2",
75
+ "@middy/core": "7.3.0",
79
76
  "@types/aws-lambda": "^8.0.0",
80
77
  "@types/node": "^22.0.0",
81
78
  "aws-xray-sdk": "^3.3.3"