@middy/s3 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 +11 -2
  3. package/package.json +3 -6
package/index.d.ts CHANGED
@@ -64,4 +64,8 @@ declare function s3Middleware<TOptions extends S3Options | undefined>(
64
64
  Internal<TOptions>
65
65
  >;
66
66
 
67
+ export declare function s3ValidateOptions(
68
+ options?: Record<string, unknown>,
69
+ ): void;
70
+
67
71
  export default s3Middleware;
package/index.js CHANGED
@@ -2,15 +2,18 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
  import { GetObjectCommand, S3Client } from "@aws-sdk/client-s3";
4
4
  import {
5
+ awsClientOptionSchema,
5
6
  canPrefetch,
6
7
  catchInvalidSignatureException,
7
8
  createClient,
8
9
  createPrefetchClient,
9
10
  getCache,
10
11
  getInternal,
12
+ jsonContentTypePattern,
11
13
  jsonSafeParse,
12
14
  modifyCache,
13
15
  processCache,
16
+ validateOptions,
14
17
  } from "@middy/util";
15
18
 
16
19
  const defaults = {
@@ -25,7 +28,11 @@ const defaults = {
25
28
  cacheExpiry: -1,
26
29
  setToContext: false,
27
30
  };
28
- const jsonContentTypePattern = /^application\/([a-z0-9.+-]+\+)?json(;|$)/i;
31
+
32
+ const optionSchema = { ...awsClientOptionSchema };
33
+
34
+ export const s3ValidateOptions = (options) =>
35
+ validateOptions("@middy/s3", optionSchema, options);
29
36
  const s3Middleware = (opts = {}) => {
30
37
  const options = {
31
38
  ...defaults,
@@ -57,13 +64,15 @@ const s3Middleware = (opts = {}) => {
57
64
  return values;
58
65
  };
59
66
  let client;
67
+ let clientInit;
60
68
  if (canPrefetch(options)) {
61
69
  client = createPrefetchClient(options);
62
70
  processCache(options, fetchRequest);
63
71
  }
64
72
  const s3MiddlewareBefore = async (request) => {
65
73
  if (!client) {
66
- client = await createClient(options, request);
74
+ clientInit ??= createClient(options, request);
75
+ client = await clientInit;
67
76
  }
68
77
  const { value } = processCache(options, fetchRequest, request);
69
78
  Object.assign(request.internal, value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/s3",
3
- "version": "7.2.2",
3
+ "version": "7.3.0",
4
4
  "description": "S3 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-s3": "^3.0.0"
@@ -75,7 +72,7 @@
75
72
  },
76
73
  "devDependencies": {
77
74
  "@aws-sdk/client-s3": "^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"