@adobe/helix-admin-support 1.3.11 → 1.3.13
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/CHANGELOG.md +14 -0
- package/package.json +3 -2
- package/src/fetch-s3.js +23 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [1.3.13](https://github.com/adobe/helix-admin-support/compare/v1.3.12...v1.3.13) (2022-09-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* fetch S3 regression ([fa2b571](https://github.com/adobe/helix-admin-support/commit/fa2b5715112314224feb520af16f93a51fc0e4bb))
|
|
7
|
+
|
|
8
|
+
## [1.3.12](https://github.com/adobe/helix-admin-support/compare/v1.3.11...v1.3.12) (2022-09-27)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* destroy S3Client after use; use timeout for S3 fetch ([378bb37](https://github.com/adobe/helix-admin-support/commit/378bb37fd2603f59fc6886db4c928f2b4e1cbb7b))
|
|
14
|
+
|
|
1
15
|
## [1.3.11](https://github.com/adobe/helix-admin-support/compare/v1.3.10...v1.3.11) (2022-09-24)
|
|
2
16
|
|
|
3
17
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-admin-support",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.13",
|
|
4
4
|
"description": "Helix Admin Support Library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|
"@adobe/fetch": "3.1.4",
|
|
35
35
|
"@adobe/helix-shared-config": "9.1.1",
|
|
36
36
|
"@adobe/helix-shared-utils": "2.1.0",
|
|
37
|
-
"@aws-sdk/client-s3": "3.178.0"
|
|
37
|
+
"@aws-sdk/client-s3": "3.178.0",
|
|
38
|
+
"@aws-sdk/node-http-handler": "3.178.0"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
41
|
"@adobe/eslint-config-helix": "1.3.2",
|
package/src/fetch-s3.js
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
HeadObjectCommand,
|
|
19
19
|
NoSuchKey,
|
|
20
20
|
} from '@aws-sdk/client-s3';
|
|
21
|
+
import { NodeHttpHandler } from '@aws-sdk/node-http-handler';
|
|
21
22
|
|
|
22
23
|
const gunzip = promisify(zlib.gunzip);
|
|
23
24
|
|
|
@@ -38,6 +39,11 @@ export async function fetchS3(context, bucketId, key, head = false) {
|
|
|
38
39
|
}
|
|
39
40
|
const { log, env = {} } = context;
|
|
40
41
|
|
|
42
|
+
const {
|
|
43
|
+
HELIX_HTTP_CONNECTION_TIMEOUT = 5000,
|
|
44
|
+
HELIX_HTTP_SOCKET_TIMEOUT = 15000,
|
|
45
|
+
} = env;
|
|
46
|
+
|
|
41
47
|
try {
|
|
42
48
|
// the client initialization is a bit picky with undefined properties.
|
|
43
49
|
// so we omit the credentials when we provide them via context.env
|
|
@@ -48,21 +54,28 @@ export async function fetchS3(context, bucketId, key, head = false) {
|
|
|
48
54
|
accessKeyId: env.AWS_S3_ACCESS_KEY_ID,
|
|
49
55
|
secretAccessKey: env.AWS_S3_SECRET_ACCESS_KEY,
|
|
50
56
|
},
|
|
57
|
+
requestHandler: new NodeHttpHandler({
|
|
58
|
+
connectionTimeout: HELIX_HTTP_CONNECTION_TIMEOUT,
|
|
59
|
+
socketTimeout: HELIX_HTTP_SOCKET_TIMEOUT,
|
|
60
|
+
}),
|
|
51
61
|
};
|
|
52
62
|
const s3 = new S3Client(opts);
|
|
53
63
|
const Command = head ? HeadObjectCommand : GetObjectCommand;
|
|
54
|
-
|
|
55
|
-
Bucket: bucketId,
|
|
56
|
-
Key: key,
|
|
57
|
-
// todo: add timeout
|
|
58
|
-
}));
|
|
59
|
-
|
|
64
|
+
let res;
|
|
60
65
|
let buffer = '';
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
try {
|
|
67
|
+
res = await s3.send(new Command({
|
|
68
|
+
Bucket: bucketId,
|
|
69
|
+
Key: key,
|
|
70
|
+
}));
|
|
71
|
+
if (!head) {
|
|
72
|
+
buffer = await new Response(res.Body, {}).buffer();
|
|
73
|
+
if (res.ContentEncoding === 'gzip') {
|
|
74
|
+
buffer = await gunzip(buffer);
|
|
75
|
+
}
|
|
65
76
|
}
|
|
77
|
+
} finally {
|
|
78
|
+
s3.destroy();
|
|
66
79
|
}
|
|
67
80
|
const headers = {};
|
|
68
81
|
if (res.LastModified) {
|