@aws-sdk/middleware-sdk-s3 3.609.0 → 3.616.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/dist-cjs/index.js
CHANGED
|
@@ -441,25 +441,43 @@ var resolveS3Config = /* @__PURE__ */ __name((input, {
|
|
|
441
441
|
|
|
442
442
|
// src/throw-200-exceptions.ts
|
|
443
443
|
|
|
444
|
-
var
|
|
444
|
+
var import_util_stream = require("@smithy/util-stream");
|
|
445
|
+
var THROW_IF_EMPTY_BODY = {
|
|
446
|
+
CopyObjectCommand: true,
|
|
447
|
+
UploadPartCopyCommand: true,
|
|
448
|
+
CompleteMultipartUploadCommand: true
|
|
449
|
+
};
|
|
450
|
+
var MAX_BYTES_TO_INSPECT = 3e3;
|
|
451
|
+
var throw200ExceptionsMiddleware = /* @__PURE__ */ __name((config) => (next, context) => async (args) => {
|
|
445
452
|
const result = await next(args);
|
|
446
453
|
const { response } = result;
|
|
447
|
-
if (!import_protocol_http.HttpResponse.isInstance(response))
|
|
454
|
+
if (!import_protocol_http.HttpResponse.isInstance(response)) {
|
|
448
455
|
return result;
|
|
449
|
-
|
|
450
|
-
|
|
456
|
+
}
|
|
457
|
+
const { statusCode, body: sourceBody } = response;
|
|
458
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
451
459
|
return result;
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
460
|
+
}
|
|
461
|
+
let bodyCopy = sourceBody;
|
|
462
|
+
let body = sourceBody;
|
|
463
|
+
if (sourceBody && typeof sourceBody === "object" && !(sourceBody instanceof Uint8Array)) {
|
|
464
|
+
[bodyCopy, body] = await (0, import_util_stream.splitStream)(sourceBody);
|
|
465
|
+
}
|
|
466
|
+
response.body = body;
|
|
467
|
+
const bodyBytes = await collectBody(bodyCopy, {
|
|
468
|
+
streamCollector: async (stream) => {
|
|
469
|
+
return (0, import_util_stream.headStream)(stream, MAX_BYTES_TO_INSPECT);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
|
|
473
|
+
if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName]) {
|
|
455
474
|
const err = new Error("S3 aborted request");
|
|
456
475
|
err.name = "InternalError";
|
|
457
476
|
throw err;
|
|
458
477
|
}
|
|
459
|
-
if (
|
|
478
|
+
if (bodyStringTail && bodyStringTail.endsWith("</Error>")) {
|
|
460
479
|
response.statusCode = 400;
|
|
461
480
|
}
|
|
462
|
-
response.body = bodyBytes;
|
|
463
481
|
return result;
|
|
464
482
|
}, "throw200ExceptionsMiddleware");
|
|
465
483
|
var collectBody = /* @__PURE__ */ __name((streamBody = new Uint8Array(), context) => {
|
|
@@ -468,7 +486,6 @@ var collectBody = /* @__PURE__ */ __name((streamBody = new Uint8Array(), context
|
|
|
468
486
|
}
|
|
469
487
|
return context.streamCollector(streamBody) || Promise.resolve(new Uint8Array());
|
|
470
488
|
}, "collectBody");
|
|
471
|
-
var collectBodyString = /* @__PURE__ */ __name((streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body)), "collectBodyString");
|
|
472
489
|
var throw200ExceptionsMiddlewareOptions = {
|
|
473
490
|
relation: "after",
|
|
474
491
|
toMiddleware: "deserializerMiddleware",
|
|
@@ -1,23 +1,41 @@
|
|
|
1
1
|
import { HttpResponse } from "@smithy/protocol-http";
|
|
2
|
-
|
|
2
|
+
import { headStream, splitStream } from "@smithy/util-stream";
|
|
3
|
+
const THROW_IF_EMPTY_BODY = {
|
|
4
|
+
CopyObjectCommand: true,
|
|
5
|
+
UploadPartCopyCommand: true,
|
|
6
|
+
CompleteMultipartUploadCommand: true,
|
|
7
|
+
};
|
|
8
|
+
const MAX_BYTES_TO_INSPECT = 3000;
|
|
9
|
+
export const throw200ExceptionsMiddleware = (config) => (next, context) => async (args) => {
|
|
3
10
|
const result = await next(args);
|
|
4
11
|
const { response } = result;
|
|
5
|
-
if (!HttpResponse.isInstance(response))
|
|
12
|
+
if (!HttpResponse.isInstance(response)) {
|
|
6
13
|
return result;
|
|
7
|
-
|
|
8
|
-
|
|
14
|
+
}
|
|
15
|
+
const { statusCode, body: sourceBody } = response;
|
|
16
|
+
if (statusCode < 200 || statusCode >= 300) {
|
|
9
17
|
return result;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
18
|
+
}
|
|
19
|
+
let bodyCopy = sourceBody;
|
|
20
|
+
let body = sourceBody;
|
|
21
|
+
if (sourceBody && typeof sourceBody === "object" && !(sourceBody instanceof Uint8Array)) {
|
|
22
|
+
[bodyCopy, body] = await splitStream(sourceBody);
|
|
23
|
+
}
|
|
24
|
+
response.body = body;
|
|
25
|
+
const bodyBytes = await collectBody(bodyCopy, {
|
|
26
|
+
streamCollector: async (stream) => {
|
|
27
|
+
return headStream(stream, MAX_BYTES_TO_INSPECT);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
|
|
31
|
+
if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName]) {
|
|
13
32
|
const err = new Error("S3 aborted request");
|
|
14
33
|
err.name = "InternalError";
|
|
15
34
|
throw err;
|
|
16
35
|
}
|
|
17
|
-
if (
|
|
36
|
+
if (bodyStringTail && bodyStringTail.endsWith("</Error>")) {
|
|
18
37
|
response.statusCode = 400;
|
|
19
38
|
}
|
|
20
|
-
response.body = bodyBytes;
|
|
21
39
|
return result;
|
|
22
40
|
};
|
|
23
41
|
const collectBody = (streamBody = new Uint8Array(), context) => {
|
|
@@ -26,7 +44,6 @@ const collectBody = (streamBody = new Uint8Array(), context) => {
|
|
|
26
44
|
}
|
|
27
45
|
return context.streamCollector(streamBody) || Promise.resolve(new Uint8Array());
|
|
28
46
|
};
|
|
29
|
-
const collectBodyString = (streamBody, context) => collectBody(streamBody, context).then((body) => context.utf8Encoder(body));
|
|
30
47
|
export const throw200ExceptionsMiddlewareOptions = {
|
|
31
48
|
relation: "after",
|
|
32
49
|
toMiddleware: "deserializerMiddleware",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { DeserializeMiddleware, Encoder, Pluggable, RelativeMiddlewareOptions
|
|
1
|
+
import { DeserializeMiddleware, Encoder, Pluggable, RelativeMiddlewareOptions } from "@smithy/types";
|
|
2
2
|
type PreviouslyResolved = {
|
|
3
|
-
streamCollector: StreamCollector;
|
|
4
3
|
utf8Encoder: Encoder;
|
|
5
4
|
};
|
|
6
5
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/middleware-sdk-s3",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.616.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
|
|
6
6
|
"build:cjs": "node ../../scripts/compilation/inline middleware-sdk-s3",
|
|
@@ -25,12 +25,14 @@
|
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@aws-sdk/types": "3.609.0",
|
|
27
27
|
"@aws-sdk/util-arn-parser": "3.568.0",
|
|
28
|
-
"@smithy/node-config-provider": "^3.1.
|
|
29
|
-
"@smithy/protocol-http": "^4.0.
|
|
30
|
-
"@smithy/signature-v4": "^
|
|
31
|
-
"@smithy/smithy-client": "^3.1.
|
|
28
|
+
"@smithy/node-config-provider": "^3.1.4",
|
|
29
|
+
"@smithy/protocol-http": "^4.0.4",
|
|
30
|
+
"@smithy/signature-v4": "^4.0.0",
|
|
31
|
+
"@smithy/smithy-client": "^3.1.8",
|
|
32
32
|
"@smithy/types": "^3.3.0",
|
|
33
33
|
"@smithy/util-config-provider": "^3.0.0",
|
|
34
|
+
"@smithy/util-stream": "^3.1.0",
|
|
35
|
+
"@smithy/util-utf8": "^3.0.0",
|
|
34
36
|
"tslib": "^2.6.2"
|
|
35
37
|
},
|
|
36
38
|
"devDependencies": {
|