@middy/s3-object-response 6.1.5 → 6.2.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 +34 -31
  2. package/index.js +48 -48
  3. package/package.json +67 -70
package/index.d.ts CHANGED
@@ -1,40 +1,43 @@
1
- import middy from '@middy/core'
2
- import { Options as MiddyOptions } from '@middy/util'
3
- import { Context as LambdaContext } from 'aws-lambda'
4
- import { S3Client, S3ClientConfig } from '@aws-sdk/client-s3'
5
- import { ClientRequest } from 'http'
1
+ import type { ClientRequest } from "node:http";
2
+ import type { S3Client, S3ClientConfig } from "@aws-sdk/client-s3";
3
+ import type middy from "@middy/core";
4
+ import type { Options as MiddyOptions } from "@middy/util";
5
+ import type { Context as LambdaContext } from "aws-lambda";
6
6
 
7
7
  export interface S3ObjectResponseOptions<AwsS3Client = S3Client>
8
- extends Pick<
9
- MiddyOptions<AwsS3Client, S3ClientConfig>,
10
- | 'AwsClient'
11
- | 'awsClientOptions'
12
- | 'awsClientAssumeRole'
13
- | 'awsClientCapture'
14
- | 'disablePrefetch'
15
- > {
16
- bodyType?: 'stream' | 'promise'
8
+ extends Pick<
9
+ MiddyOptions<AwsS3Client, S3ClientConfig>,
10
+ | "AwsClient"
11
+ | "awsClientOptions"
12
+ | "awsClientAssumeRole"
13
+ | "awsClientCapture"
14
+ | "disablePrefetch"
15
+ > {
16
+ bodyType?: "stream" | "promise";
17
17
  }
18
18
 
19
- export type Context<TOptions extends S3ObjectResponseOptions | undefined> = LambdaContext & {
20
- s3Object: TOptions extends { bodyType: 'stream' }
21
- ? ClientRequest
22
- : TOptions extends { bodyType: 'promise' }
23
- ? Promise<any>
24
- : never
25
- } & {
26
- s3ObjectFetch: Promise<Response>
27
- }
19
+ export type Context<TOptions extends S3ObjectResponseOptions | undefined> =
20
+ LambdaContext & {
21
+ s3Object: TOptions extends { bodyType: "stream" }
22
+ ? ClientRequest
23
+ : TOptions extends { bodyType: "promise" }
24
+ ? Promise<any>
25
+ : never;
26
+ } & {
27
+ s3ObjectFetch: Promise<Response>;
28
+ };
28
29
 
29
30
  export interface Internal extends Record<string, any> {
30
- s3ObjectResponse: {
31
- RequestRoute: string
32
- RequestToken: string
33
- }
31
+ s3ObjectResponse: {
32
+ RequestRoute: string;
33
+ RequestToken: string;
34
+ };
34
35
  }
35
36
 
36
- declare function s3ObjectResponse<TOptions extends S3ObjectResponseOptions | undefined> (
37
- options?: TOptions
38
- ): middy.MiddlewareObj<unknown, any, Error, Context<TOptions>, Internal>
37
+ declare function s3ObjectResponse<
38
+ TOptions extends S3ObjectResponseOptions | undefined,
39
+ >(
40
+ options?: TOptions,
41
+ ): middy.MiddlewareObj<unknown, any, Error, Context<TOptions>, Internal>;
39
42
 
40
- export default s3ObjectResponse
43
+ export default s3ObjectResponse;
package/index.js CHANGED
@@ -1,54 +1,54 @@
1
1
  import {
2
- canPrefetch,
3
- createPrefetchClient,
4
- createClient
5
- // catchInvalidSignatureException
6
- } from '@middy/util'
2
+ canPrefetch,
3
+ createClient,
4
+ createPrefetchClient,
5
+ // catchInvalidSignatureException
6
+ } from "@middy/util";
7
7
 
8
- import { S3Client, WriteGetObjectResponseCommand } from '@aws-sdk/client-s3'
8
+ import { S3Client, WriteGetObjectResponseCommand } from "@aws-sdk/client-s3";
9
9
 
10
10
  const defaults = {
11
- AwsClient: S3Client,
12
- awsClientOptions: {},
13
- awsClientAssumeRole: undefined,
14
- awsClientCapture: undefined,
15
- disablePrefetch: false
16
- }
11
+ AwsClient: S3Client,
12
+ awsClientOptions: {},
13
+ awsClientAssumeRole: undefined,
14
+ awsClientCapture: undefined,
15
+ disablePrefetch: false,
16
+ };
17
17
 
18
18
  const s3ObjectResponseMiddleware = (opts = {}) => {
19
- const options = { ...defaults, ...opts }
20
-
21
- let client
22
- if (canPrefetch(options)) {
23
- client = createPrefetchClient(options)
24
- }
25
-
26
- const s3ObjectResponseMiddlewareBefore = async (request) => {
27
- const { inputS3Url } = request.event.getObjectContext ?? {}
28
-
29
- request.context.s3ObjectFetch = inputS3Url ? fetch(inputS3Url) : undefined
30
- }
31
-
32
- const s3ObjectResponseMiddlewareAfter = async (request) => {
33
- if (!client) {
34
- client = await createClient(options, request)
35
- }
36
-
37
- const command = new WriteGetObjectResponseCommand({
38
- RequestRoute: request.event.getObjectContext?.outputRoute,
39
- RequestToken: request.event.getObjectContext?.outputToken,
40
- Body: request.response.Body ?? request.response.body
41
- })
42
- await client.send(command) // Doesn't return a promise?
43
- // .catch((e) => catchInvalidSignatureException(e, client, command))
44
-
45
- return { statusCode: 200 }
46
- }
47
-
48
- return {
49
- before: s3ObjectResponseMiddlewareBefore,
50
- after: s3ObjectResponseMiddlewareAfter
51
- }
52
- }
53
-
54
- export default s3ObjectResponseMiddleware
19
+ const options = { ...defaults, ...opts };
20
+
21
+ let client;
22
+ if (canPrefetch(options)) {
23
+ client = createPrefetchClient(options);
24
+ }
25
+
26
+ const s3ObjectResponseMiddlewareBefore = async (request) => {
27
+ const { inputS3Url } = request.event.getObjectContext ?? {};
28
+
29
+ request.context.s3ObjectFetch = inputS3Url ? fetch(inputS3Url) : undefined;
30
+ };
31
+
32
+ const s3ObjectResponseMiddlewareAfter = async (request) => {
33
+ if (!client) {
34
+ client = await createClient(options, request);
35
+ }
36
+
37
+ const command = new WriteGetObjectResponseCommand({
38
+ RequestRoute: request.event.getObjectContext?.outputRoute,
39
+ RequestToken: request.event.getObjectContext?.outputToken,
40
+ Body: request.response.Body ?? request.response.body,
41
+ });
42
+ await client.send(command); // Doesn't return a promise?
43
+ // .catch((e) => catchInvalidSignatureException(e, client, command))
44
+
45
+ return { statusCode: 200 };
46
+ };
47
+
48
+ return {
49
+ before: s3ObjectResponseMiddlewareBefore,
50
+ after: s3ObjectResponseMiddlewareAfter,
51
+ };
52
+ };
53
+
54
+ export default s3ObjectResponseMiddleware;
package/package.json CHANGED
@@ -1,72 +1,69 @@
1
1
  {
2
- "name": "@middy/s3-object-response",
3
- "version": "6.1.5",
4
- "description": "S3 object response handling middleware for the middy framework",
5
- "type": "module",
6
- "engines": {
7
- "node": ">=20"
8
- },
9
- "engineStrict": true,
10
- "publishConfig": {
11
- "access": "public"
12
- },
13
- "module": "./index.js",
14
- "exports": {
15
- ".": {
16
- "import": {
17
- "types": "./index.d.ts",
18
- "default": "./index.js"
19
- },
20
- "require": {
21
- "default": "./index.js"
22
- }
23
- }
24
- },
25
- "types": "index.d.ts",
26
- "files": [
27
- "index.js",
28
- "index.d.ts"
29
- ],
30
- "scripts": {
31
- "test": "npm run test:unit && npm run test:fuzz",
32
- "test:unit": "node --test __tests__/index.js",
33
- "test:fuzz": "node --test __tests__/fuzz.js",
34
- "test:benchmark": "node __benchmarks__/index.js"
35
- },
36
- "license": "MIT",
37
- "keywords": [
38
- "Lambda",
39
- "Middleware",
40
- "Serverless",
41
- "Framework",
42
- "AWS",
43
- "AWS Lambda",
44
- "Middy",
45
- "S3",
46
- "GetObjectResponse",
47
- "WriteObjectREsponse"
48
- ],
49
- "author": {
50
- "name": "Middy contributors",
51
- "url": "https://github.com/middyjs/middy/graphs/contributors"
52
- },
53
- "repository": {
54
- "type": "git",
55
- "url": "git+https://github.com/middyjs/middy.git",
56
- "directory": "packages/sts"
57
- },
58
- "bugs": {
59
- "url": "https://github.com/middyjs/middy/issues"
60
- },
61
- "homepage": "https://middy.js.org",
62
- "funding": {
63
- "type": "github",
64
- "url": "https://github.com/sponsors/willfarrell"
65
- },
66
- "devDependencies": {
67
- "@aws-sdk/client-s3": "^3.0.0",
68
- "@types/aws-lambda": "^8.10.101",
69
- "aws-xray-sdk": "^3.3.3"
70
- },
71
- "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
2
+ "name": "@middy/s3-object-response",
3
+ "version": "6.2.0",
4
+ "description": "S3 object response handling middleware for the middy framework",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": ">=20"
8
+ },
9
+ "engineStrict": true,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "module": "./index.js",
14
+ "exports": {
15
+ ".": {
16
+ "import": {
17
+ "types": "./index.d.ts",
18
+ "default": "./index.js"
19
+ },
20
+ "require": {
21
+ "default": "./index.js"
22
+ }
23
+ }
24
+ },
25
+ "types": "index.d.ts",
26
+ "files": ["index.js", "index.d.ts"],
27
+ "scripts": {
28
+ "test": "npm run test:unit && npm run test:fuzz",
29
+ "test:unit": "node --test",
30
+ "test:fuzz": "node --test index.fuzz.js",
31
+ "test:perf": "node --test index.perf.js"
32
+ },
33
+ "license": "MIT",
34
+ "keywords": [
35
+ "Lambda",
36
+ "Middleware",
37
+ "Serverless",
38
+ "Framework",
39
+ "AWS",
40
+ "AWS Lambda",
41
+ "Middy",
42
+ "S3",
43
+ "GetObjectResponse",
44
+ "WriteObjectREsponse"
45
+ ],
46
+ "author": {
47
+ "name": "Middy contributors",
48
+ "url": "https://github.com/middyjs/middy/graphs/contributors"
49
+ },
50
+ "repository": {
51
+ "type": "git",
52
+ "url": "git+https://github.com/middyjs/middy.git",
53
+ "directory": "packages/sts"
54
+ },
55
+ "bugs": {
56
+ "url": "https://github.com/middyjs/middy/issues"
57
+ },
58
+ "homepage": "https://middy.js.org",
59
+ "funding": {
60
+ "type": "github",
61
+ "url": "https://github.com/sponsors/willfarrell"
62
+ },
63
+ "devDependencies": {
64
+ "@aws-sdk/client-s3": "^3.0.0",
65
+ "@types/aws-lambda": "^8.10.101",
66
+ "aws-xray-sdk": "^3.3.3"
67
+ },
68
+ "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"
72
69
  }