@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.
- package/index.d.ts +34 -31
- package/index.js +48 -48
- package/package.json +67 -70
package/index.d.ts
CHANGED
|
@@ -1,40 +1,43 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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> =
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
s3ObjectResponse: {
|
|
32
|
+
RequestRoute: string;
|
|
33
|
+
RequestToken: string;
|
|
34
|
+
};
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
declare function s3ObjectResponse<
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
2
|
+
canPrefetch,
|
|
3
|
+
createClient,
|
|
4
|
+
createPrefetchClient,
|
|
5
|
+
// catchInvalidSignatureException
|
|
6
|
+
} from "@middy/util";
|
|
7
7
|
|
|
8
|
-
import { S3Client, WriteGetObjectResponseCommand } from
|
|
8
|
+
import { S3Client, WriteGetObjectResponseCommand } from "@aws-sdk/client-s3";
|
|
9
9
|
|
|
10
10
|
const defaults = {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
11
|
+
AwsClient: S3Client,
|
|
12
|
+
awsClientOptions: {},
|
|
13
|
+
awsClientAssumeRole: undefined,
|
|
14
|
+
awsClientCapture: undefined,
|
|
15
|
+
disablePrefetch: false,
|
|
16
|
+
};
|
|
17
17
|
|
|
18
18
|
const s3ObjectResponseMiddleware = (opts = {}) => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
}
|