@aws-sdk/middleware-sdk-s3 3.972.31 → 3.972.33

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  var protocolHttp = require('@smithy/protocol-http');
4
4
  var smithyClient = require('@smithy/smithy-client');
5
- var utilStream = require('@smithy/util-stream');
5
+ var toStream = require('./toStream');
6
6
  var utilArnParser = require('@aws-sdk/util-arn-parser');
7
7
  var protocols = require('@aws-sdk/core/protocols');
8
8
  var schema = require('@smithy/core/schema');
@@ -419,45 +419,29 @@ const THROW_IF_EMPTY_BODY = {
419
419
  UploadPartCopyCommand: true,
420
420
  CompleteMultipartUploadCommand: true,
421
421
  };
422
- const MAX_BYTES_TO_INSPECT = 3000;
423
422
  const throw200ExceptionsMiddleware = (config) => (next, context) => async (args) => {
424
423
  const result = await next(args);
425
424
  const { response } = result;
426
425
  if (!protocolHttp.HttpResponse.isInstance(response)) {
427
426
  return result;
428
427
  }
429
- const { statusCode, body: sourceBody } = response;
428
+ const { statusCode, body } = response;
430
429
  if (statusCode < 200 || statusCode >= 300) {
431
430
  return result;
432
431
  }
433
- const isSplittableStream = typeof sourceBody?.stream === "function" ||
434
- typeof sourceBody?.pipe === "function" ||
435
- typeof sourceBody?.tee === "function";
436
- if (!isSplittableStream) {
437
- return result;
438
- }
439
- let bodyCopy = sourceBody;
440
- let body = sourceBody;
441
- if (sourceBody && typeof sourceBody === "object" && !(sourceBody instanceof Uint8Array)) {
442
- [bodyCopy, body] = await utilStream.splitStream(sourceBody);
443
- }
444
- response.body = body;
445
- const bodyBytes = await collectBody(bodyCopy, {
446
- streamCollector: async (stream) => {
447
- return utilStream.headStream(stream, MAX_BYTES_TO_INSPECT);
448
- },
449
- });
450
- if (typeof bodyCopy?.destroy === "function") {
451
- bodyCopy.destroy();
452
- }
453
- const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
432
+ const bodyBytes = await collectBody(body, config);
433
+ response.body = toStream.toStream(bodyBytes);
454
434
  if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName]) {
455
435
  const err = new Error("S3 aborted request");
436
+ err.$metadata = {
437
+ httpStatusCode: 503,
438
+ };
456
439
  err.name = "InternalError";
457
440
  throw err;
458
441
  }
442
+ const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
459
443
  if (bodyStringTail && bodyStringTail.endsWith("</Error>")) {
460
- response.statusCode = 400;
444
+ response.statusCode = 503;
461
445
  }
462
446
  return result;
463
447
  };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toStream = toStream;
4
+ function toStream(bytes) {
5
+ return new ReadableStream({
6
+ start(controller) {
7
+ controller.enqueue(bytes);
8
+ controller.close();
9
+ },
10
+ });
11
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toStream = toStream;
4
+ const node_stream_1 = require("node:stream");
5
+ function toStream(bytes) {
6
+ return node_stream_1.Readable.from(Buffer.from(bytes));
7
+ }
@@ -1,49 +1,33 @@
1
1
  import { HttpResponse } from "@smithy/protocol-http";
2
- import { headStream, splitStream } from "@smithy/util-stream";
2
+ import { toStream } from "./toStream";
3
3
  const THROW_IF_EMPTY_BODY = {
4
4
  CopyObjectCommand: true,
5
5
  UploadPartCopyCommand: true,
6
6
  CompleteMultipartUploadCommand: true,
7
7
  };
8
- const MAX_BYTES_TO_INSPECT = 3000;
9
8
  export const throw200ExceptionsMiddleware = (config) => (next, context) => async (args) => {
10
9
  const result = await next(args);
11
10
  const { response } = result;
12
11
  if (!HttpResponse.isInstance(response)) {
13
12
  return result;
14
13
  }
15
- const { statusCode, body: sourceBody } = response;
14
+ const { statusCode, body } = response;
16
15
  if (statusCode < 200 || statusCode >= 300) {
17
16
  return result;
18
17
  }
19
- const isSplittableStream = typeof sourceBody?.stream === "function" ||
20
- typeof sourceBody?.pipe === "function" ||
21
- typeof sourceBody?.tee === "function";
22
- if (!isSplittableStream) {
23
- return result;
24
- }
25
- let bodyCopy = sourceBody;
26
- let body = sourceBody;
27
- if (sourceBody && typeof sourceBody === "object" && !(sourceBody instanceof Uint8Array)) {
28
- [bodyCopy, body] = await splitStream(sourceBody);
29
- }
30
- response.body = body;
31
- const bodyBytes = await collectBody(bodyCopy, {
32
- streamCollector: async (stream) => {
33
- return headStream(stream, MAX_BYTES_TO_INSPECT);
34
- },
35
- });
36
- if (typeof bodyCopy?.destroy === "function") {
37
- bodyCopy.destroy();
38
- }
39
- const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
18
+ const bodyBytes = await collectBody(body, config);
19
+ response.body = toStream(bodyBytes);
40
20
  if (bodyBytes.length === 0 && THROW_IF_EMPTY_BODY[context.commandName]) {
41
21
  const err = new Error("S3 aborted request");
22
+ err.$metadata = {
23
+ httpStatusCode: 503,
24
+ };
42
25
  err.name = "InternalError";
43
26
  throw err;
44
27
  }
28
+ const bodyStringTail = config.utf8Encoder(bodyBytes.subarray(bodyBytes.length - 16));
45
29
  if (bodyStringTail && bodyStringTail.endsWith("</Error>")) {
46
- response.statusCode = 400;
30
+ response.statusCode = 503;
47
31
  }
48
32
  return result;
49
33
  };
@@ -0,0 +1,8 @@
1
+ export function toStream(bytes) {
2
+ return new ReadableStream({
3
+ start(controller) {
4
+ controller.enqueue(bytes);
5
+ controller.close();
6
+ },
7
+ });
8
+ }
@@ -0,0 +1,4 @@
1
+ import { Readable } from "node:stream";
2
+ export function toStream(bytes) {
3
+ return Readable.from(Buffer.from(bytes));
4
+ }
@@ -1,5 +1,6 @@
1
- import type { DeserializeMiddleware, Encoder, Pluggable, RelativeMiddlewareOptions } from "@smithy/types";
1
+ import type { DeserializeMiddleware, Encoder, Pluggable, RelativeMiddlewareOptions, StreamCollector } from "@smithy/types";
2
2
  type PreviouslyResolved = {
3
+ streamCollector: StreamCollector;
3
4
  utf8Encoder: Encoder;
4
5
  };
5
6
  /**
@@ -0,0 +1,4 @@
1
+ /**
2
+ * @internal
3
+ */
4
+ export declare function toStream(bytes: Uint8Array): ReadableStream;
@@ -0,0 +1,5 @@
1
+ import { Readable } from "node:stream";
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare function toStream(bytes: Uint8Array): Readable;
@@ -3,8 +3,10 @@ import {
3
3
  Encoder,
4
4
  Pluggable,
5
5
  RelativeMiddlewareOptions,
6
+ StreamCollector,
6
7
  } from "@smithy/types";
7
8
  type PreviouslyResolved = {
9
+ streamCollector: StreamCollector;
8
10
  utf8Encoder: Encoder;
9
11
  };
10
12
  export declare const throw200ExceptionsMiddleware: (
@@ -0,0 +1 @@
1
+ export declare function toStream(bytes: Uint8Array): ReadableStream;
@@ -0,0 +1,2 @@
1
+ import { Readable } from "node:stream";
2
+ export declare function toStream(bytes: Uint8Array): Readable;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/middleware-sdk-s3",
3
- "version": "3.972.31",
3
+ "version": "3.972.33",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
6
6
  "build:cjs": "node ../../scripts/compilation/inline middleware-sdk-s3",
@@ -9,13 +9,13 @@
9
9
  "build:types": "tsc -p tsconfig.types.json",
10
10
  "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
11
11
  "clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
12
- "test": "yarn g:vitest run",
13
12
  "test:types": "tsc -p tsconfig.test.json",
14
- "test:integration": "yarn g:vitest run -c vitest.config.integ.mts && yarn test:types",
15
- "test:e2e": "yarn g:vitest run -c vitest.config.e2e.mts --mode development",
16
13
  "extract:docs": "api-extractor run --local",
14
+ "test": "yarn g:vitest run",
17
15
  "test:watch": "yarn g:vitest watch",
16
+ "test:integration": "yarn g:vitest run -c vitest.config.integ.mts && yarn test:types",
18
17
  "test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts",
18
+ "test:e2e": "yarn g:vitest run -c vitest.config.e2e.mts --mode development",
19
19
  "test:e2e:watch": "yarn g:vitest watch -c vitest.config.e2e.mts"
20
20
  },
21
21
  "main": "./dist-cjs/index.js",
@@ -28,18 +28,18 @@
28
28
  },
29
29
  "license": "Apache-2.0",
30
30
  "dependencies": {
31
- "@aws-sdk/core": "^3.974.2",
31
+ "@aws-sdk/core": "^3.974.4",
32
32
  "@aws-sdk/types": "^3.973.8",
33
33
  "@aws-sdk/util-arn-parser": "^3.972.3",
34
- "@smithy/core": "^3.23.15",
34
+ "@smithy/core": "^3.23.16",
35
35
  "@smithy/node-config-provider": "^4.3.14",
36
36
  "@smithy/protocol-http": "^5.3.14",
37
37
  "@smithy/signature-v4": "^5.3.14",
38
- "@smithy/smithy-client": "^4.12.11",
38
+ "@smithy/smithy-client": "^4.12.12",
39
39
  "@smithy/types": "^4.14.1",
40
40
  "@smithy/util-config-provider": "^4.2.2",
41
41
  "@smithy/util-middleware": "^4.2.14",
42
- "@smithy/util-stream": "^4.5.23",
42
+ "@smithy/util-stream": "^4.5.24",
43
43
  "@smithy/util-utf8": "^4.2.2",
44
44
  "tslib": "^2.6.2"
45
45
  },
@@ -63,6 +63,13 @@
63
63
  "files": [
64
64
  "dist-*/**"
65
65
  ],
66
+ "browser": {
67
+ "./dist-es/toStream": "./dist-es/toStream.browser"
68
+ },
69
+ "react-native": {
70
+ "./dist-es/toStream": "./dist-es/toStream.browser",
71
+ "./dist-cjs/toStream": "./dist-cjs/toStream.browser"
72
+ },
66
73
  "homepage": "https://github.com/aws/aws-sdk-js-v3/tree/main/packages-internal/middleware-sdk-s3",
67
74
  "repository": {
68
75
  "type": "git",