@smithy/fetch-http-handler 4.1.2 → 5.0.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
@@ -54,13 +54,16 @@ __name(requestTimeout, "requestTimeout");
54
54
  var keepAliveSupport = {
55
55
  supported: void 0
56
56
  };
57
- var _FetchHttpHandler = class _FetchHttpHandler {
57
+ var FetchHttpHandler = class _FetchHttpHandler {
58
+ static {
59
+ __name(this, "FetchHttpHandler");
60
+ }
58
61
  /**
59
62
  * @returns the input if it is an HttpHandler of any class,
60
63
  * or instantiates a new instance of this handler.
61
64
  */
62
65
  static create(instanceOrOptions) {
63
- if (typeof (instanceOrOptions == null ? void 0 : instanceOrOptions.handle) === "function") {
66
+ if (typeof instanceOrOptions?.handle === "function") {
64
67
  return instanceOrOptions;
65
68
  }
66
69
  return new _FetchHttpHandler(instanceOrOptions);
@@ -81,14 +84,13 @@ var _FetchHttpHandler = class _FetchHttpHandler {
81
84
  destroy() {
82
85
  }
83
86
  async handle(request, { abortSignal } = {}) {
84
- var _a;
85
87
  if (!this.config) {
86
88
  this.config = await this.configProvider;
87
89
  }
88
90
  const requestTimeoutInMs = this.config.requestTimeout;
89
91
  const keepAlive = this.config.keepAlive === true;
90
92
  const credentials = this.config.credentials;
91
- if (abortSignal == null ? void 0 : abortSignal.aborted) {
93
+ if (abortSignal?.aborted) {
92
94
  const abortError = new Error("Request aborted");
93
95
  abortError.name = "AbortError";
94
96
  return Promise.reject(abortError);
@@ -116,7 +118,7 @@ var _FetchHttpHandler = class _FetchHttpHandler {
116
118
  method,
117
119
  credentials
118
120
  };
119
- if ((_a = this.config) == null ? void 0 : _a.cache) {
121
+ if (this.config?.cache) {
120
122
  requestOptions.cache = this.config.cache;
121
123
  }
122
124
  if (body) {
@@ -194,17 +196,24 @@ var _FetchHttpHandler = class _FetchHttpHandler {
194
196
  return this.config ?? {};
195
197
  }
196
198
  };
197
- __name(_FetchHttpHandler, "FetchHttpHandler");
198
- var FetchHttpHandler = _FetchHttpHandler;
199
199
 
200
200
  // src/stream-collector.ts
201
+ var import_util_base64 = require("@smithy/util-base64");
201
202
  var streamCollector = /* @__PURE__ */ __name(async (stream) => {
202
- var _a;
203
- if (typeof Blob === "function" && stream instanceof Blob || ((_a = stream.constructor) == null ? void 0 : _a.name) === "Blob") {
204
- return new Uint8Array(await stream.arrayBuffer());
203
+ if (typeof Blob === "function" && stream instanceof Blob || stream.constructor?.name === "Blob") {
204
+ if (Blob.prototype.arrayBuffer !== void 0) {
205
+ return new Uint8Array(await stream.arrayBuffer());
206
+ }
207
+ return collectBlob(stream);
205
208
  }
206
209
  return collectStream(stream);
207
210
  }, "streamCollector");
211
+ async function collectBlob(blob) {
212
+ const base64 = await readToBase64(blob);
213
+ const arrayBuffer = (0, import_util_base64.fromBase64)(base64);
214
+ return new Uint8Array(arrayBuffer);
215
+ }
216
+ __name(collectBlob, "collectBlob");
208
217
  async function collectStream(stream) {
209
218
  const chunks = [];
210
219
  const reader = stream.getReader();
@@ -227,6 +236,24 @@ async function collectStream(stream) {
227
236
  return collected;
228
237
  }
229
238
  __name(collectStream, "collectStream");
239
+ function readToBase64(blob) {
240
+ return new Promise((resolve, reject) => {
241
+ const reader = new FileReader();
242
+ reader.onloadend = () => {
243
+ if (reader.readyState !== 2) {
244
+ return reject(new Error("Reader aborted too early"));
245
+ }
246
+ const result = reader.result ?? "";
247
+ const commaIndex = result.indexOf(",");
248
+ const dataOffset = commaIndex > -1 ? commaIndex + 1 : result.length;
249
+ resolve(result.substring(dataOffset));
250
+ };
251
+ reader.onabort = () => reject(new Error("Read aborted"));
252
+ reader.onerror = () => reject(reader.error);
253
+ reader.readAsDataURL(blob);
254
+ });
255
+ }
256
+ __name(readToBase64, "readToBase64");
230
257
  // Annotate the CommonJS export names for ESM import in node:
231
258
 
232
259
  0 && (module.exports = {
@@ -1,9 +1,18 @@
1
+ import { fromBase64 } from "@smithy/util-base64";
1
2
  export const streamCollector = async (stream) => {
2
3
  if ((typeof Blob === "function" && stream instanceof Blob) || stream.constructor?.name === "Blob") {
3
- return new Uint8Array(await stream.arrayBuffer());
4
+ if (Blob.prototype.arrayBuffer !== undefined) {
5
+ return new Uint8Array(await stream.arrayBuffer());
6
+ }
7
+ return collectBlob(stream);
4
8
  }
5
9
  return collectStream(stream);
6
10
  };
11
+ async function collectBlob(blob) {
12
+ const base64 = await readToBase64(blob);
13
+ const arrayBuffer = fromBase64(base64);
14
+ return new Uint8Array(arrayBuffer);
15
+ }
7
16
  async function collectStream(stream) {
8
17
  const chunks = [];
9
18
  const reader = stream.getReader();
@@ -25,3 +34,20 @@ async function collectStream(stream) {
25
34
  }
26
35
  return collected;
27
36
  }
37
+ function readToBase64(blob) {
38
+ return new Promise((resolve, reject) => {
39
+ const reader = new FileReader();
40
+ reader.onloadend = () => {
41
+ if (reader.readyState !== 2) {
42
+ return reject(new Error("Reader aborted too early"));
43
+ }
44
+ const result = (reader.result ?? "");
45
+ const commaIndex = result.indexOf(",");
46
+ const dataOffset = commaIndex > -1 ? commaIndex + 1 : result.length;
47
+ resolve(result.substring(dataOffset));
48
+ };
49
+ reader.onabort = () => reject(new Error("Read aborted"));
50
+ reader.onerror = () => reject(reader.error);
51
+ reader.readAsDataURL(blob);
52
+ });
53
+ }
@@ -1,8 +1,10 @@
1
1
  import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
2
2
  import type { FetchHttpHandlerOptions } from "@smithy/types";
3
3
  import { HttpHandlerOptions, Provider } from "@smithy/types";
4
+ /**
5
+ * @public
6
+ */
4
7
  export { FetchHttpHandlerOptions };
5
- type FetchHttpHandlerConfig = FetchHttpHandlerOptions;
6
8
  /**
7
9
  * @internal
8
10
  * Detection of keepalive support. Can be overridden for testing.
@@ -21,7 +23,7 @@ export type AdditionalRequestParameters = {
21
23
  *
22
24
  * HttpHandler implementation using browsers' `fetch` global function.
23
25
  */
24
- export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
26
+ export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerOptions> {
25
27
  private config?;
26
28
  private configProvider;
27
29
  /**
@@ -34,6 +36,6 @@ export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerCon
34
36
  handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{
35
37
  response: HttpResponse;
36
38
  }>;
37
- updateHttpClientConfig(key: keyof FetchHttpHandlerConfig, value: FetchHttpHandlerConfig[typeof key]): void;
38
- httpHandlerConfigs(): FetchHttpHandlerConfig;
39
+ updateHttpClientConfig(key: keyof FetchHttpHandlerOptions, value: FetchHttpHandlerOptions[typeof key]): void;
40
+ httpHandlerConfigs(): FetchHttpHandlerOptions;
39
41
  }
@@ -1,8 +1,10 @@
1
1
  import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
2
2
  import { FetchHttpHandlerOptions } from "@smithy/types";
3
3
  import { HttpHandlerOptions, Provider } from "@smithy/types";
4
+ /**
5
+ * @public
6
+ */
4
7
  export { FetchHttpHandlerOptions };
5
- type FetchHttpHandlerConfig = FetchHttpHandlerOptions;
6
8
  /**
7
9
  * @internal
8
10
  * Detection of keepalive support. Can be overridden for testing.
@@ -21,7 +23,7 @@ export type AdditionalRequestParameters = {
21
23
  *
22
24
  * HttpHandler implementation using browsers' `fetch` global function.
23
25
  */
24
- export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
26
+ export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerOptions> {
25
27
  private config?;
26
28
  private configProvider;
27
29
  /**
@@ -34,6 +36,6 @@ export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerCon
34
36
  handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{
35
37
  response: HttpResponse;
36
38
  }>;
37
- updateHttpClientConfig(key: keyof FetchHttpHandlerConfig, value: FetchHttpHandlerConfig[typeof key]): void;
38
- httpHandlerConfigs(): FetchHttpHandlerConfig;
39
+ updateHttpClientConfig(key: keyof FetchHttpHandlerOptions, value: FetchHttpHandlerOptions[typeof key]): void;
40
+ httpHandlerConfigs(): FetchHttpHandlerOptions;
39
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/fetch-http-handler",
3
- "version": "4.1.2",
3
+ "version": "5.0.0",
4
4
  "description": "Provides a way to make requests",
5
5
  "scripts": {
6
6
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types && yarn build:types:downlevel'",
@@ -27,14 +27,14 @@
27
27
  "module": "./dist-es/index.js",
28
28
  "types": "./dist-types/index.d.ts",
29
29
  "dependencies": {
30
- "@smithy/protocol-http": "^4.1.8",
31
- "@smithy/querystring-builder": "^3.0.11",
32
- "@smithy/types": "^3.7.2",
33
- "@smithy/util-base64": "^3.0.0",
30
+ "@smithy/protocol-http": "^5.0.0",
31
+ "@smithy/querystring-builder": "^4.0.0",
32
+ "@smithy/types": "^4.0.0",
33
+ "@smithy/util-base64": "^4.0.0",
34
34
  "tslib": "^2.6.2"
35
35
  },
36
36
  "devDependencies": {
37
- "@smithy/abort-controller": "^3.1.9",
37
+ "@smithy/abort-controller": "^4.0.0",
38
38
  "concurrently": "7.0.0",
39
39
  "downlevel-dts": "0.10.1",
40
40
  "rimraf": "3.0.2",
@@ -61,5 +61,8 @@
61
61
  },
62
62
  "publishConfig": {
63
63
  "directory": ".release/package"
64
+ },
65
+ "engines": {
66
+ "node": ">=18.0.0"
64
67
  }
65
68
  }