@smithy/fetch-http-handler 2.2.7 → 2.3.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.
@@ -8,6 +8,12 @@ exports.keepAliveSupport = {
8
8
  supported: Boolean(typeof Request !== "undefined" && "keepalive" in new Request("https://[::1]")),
9
9
  };
10
10
  class FetchHttpHandler {
11
+ static create(instanceOrOptions) {
12
+ if (typeof (instanceOrOptions === null || instanceOrOptions === void 0 ? void 0 : instanceOrOptions.handle) === "function") {
13
+ return instanceOrOptions;
14
+ }
15
+ return new FetchHttpHandler(instanceOrOptions);
16
+ }
11
17
  constructor(options) {
12
18
  if (typeof options === "function") {
13
19
  this.configProvider = options().then((opts) => opts || {});
@@ -5,6 +5,12 @@ export const keepAliveSupport = {
5
5
  supported: Boolean(typeof Request !== "undefined" && "keepalive" in new Request("https://[::1]")),
6
6
  };
7
7
  export class FetchHttpHandler {
8
+ static create(instanceOrOptions) {
9
+ if (typeof instanceOrOptions?.handle === "function") {
10
+ return instanceOrOptions;
11
+ }
12
+ return new FetchHttpHandler(instanceOrOptions);
13
+ }
8
14
  constructor(options) {
9
15
  if (typeof options === "function") {
10
16
  this.configProvider = options().then((opts) => opts || {});
@@ -1,25 +1,7 @@
1
1
  import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
2
+ import type { FetchHttpHandlerOptions } from "@smithy/types";
2
3
  import { HttpHandlerOptions, Provider } from "@smithy/types";
3
- /**
4
- * Represents the http options that can be passed to a browser http client.
5
- */
6
- export interface FetchHttpHandlerOptions {
7
- /**
8
- * The number of milliseconds a request can take before being automatically
9
- * terminated.
10
- */
11
- requestTimeout?: number;
12
- /**
13
- * Whether to allow the request to outlive the page. Default value is false.
14
- *
15
- * There may be limitations to the payload size, number of concurrent requests,
16
- * request duration etc. when using keepalive in browsers.
17
- *
18
- * These may change over time, so look for up to date information about
19
- * these limitations before enabling keepalive.
20
- */
21
- keepAlive?: boolean;
22
- }
4
+ export { FetchHttpHandlerOptions };
23
5
  type FetchHttpHandlerConfig = FetchHttpHandlerOptions;
24
6
  /**
25
7
  * @internal
@@ -36,6 +18,11 @@ export declare const keepAliveSupport: {
36
18
  export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
37
19
  private config?;
38
20
  private configProvider;
21
+ /**
22
+ * @returns the input if it is an HttpHandler of any class,
23
+ * or instantiates a new instance of this handler.
24
+ */
25
+ static create(instanceOrOptions?: HttpHandler<any> | FetchHttpHandlerConfig): FetchHttpHandler | HttpHandler<any>;
39
26
  constructor(options?: FetchHttpHandlerOptions | Provider<FetchHttpHandlerOptions | undefined>);
40
27
  destroy(): void;
41
28
  handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{
@@ -44,4 +31,3 @@ export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerCon
44
31
  updateHttpClientConfig(key: keyof FetchHttpHandlerConfig, value: FetchHttpHandlerConfig[typeof key]): void;
45
32
  httpHandlerConfigs(): FetchHttpHandlerConfig;
46
33
  }
47
- export {};
@@ -1,25 +1,7 @@
1
1
  import { HttpHandler, HttpRequest, HttpResponse } from "@smithy/protocol-http";
2
+ import { FetchHttpHandlerOptions } from "@smithy/types";
2
3
  import { HttpHandlerOptions, Provider } from "@smithy/types";
3
- /**
4
- * Represents the http options that can be passed to a browser http client.
5
- */
6
- export interface FetchHttpHandlerOptions {
7
- /**
8
- * The number of milliseconds a request can take before being automatically
9
- * terminated.
10
- */
11
- requestTimeout?: number;
12
- /**
13
- * Whether to allow the request to outlive the page. Default value is false.
14
- *
15
- * There may be limitations to the payload size, number of concurrent requests,
16
- * request duration etc. when using keepalive in browsers.
17
- *
18
- * These may change over time, so look for up to date information about
19
- * these limitations before enabling keepalive.
20
- */
21
- keepAlive?: boolean;
22
- }
4
+ export { FetchHttpHandlerOptions };
23
5
  type FetchHttpHandlerConfig = FetchHttpHandlerOptions;
24
6
  /**
25
7
  * @internal
@@ -36,6 +18,11 @@ export declare const keepAliveSupport: {
36
18
  export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
37
19
  private config?;
38
20
  private configProvider;
21
+ /**
22
+ * @returns the input if it is an HttpHandler of any class,
23
+ * or instantiates a new instance of this handler.
24
+ */
25
+ static create(instanceOrOptions?: HttpHandler<any> | FetchHttpHandlerConfig): FetchHttpHandler | HttpHandler<any>;
39
26
  constructor(options?: FetchHttpHandlerOptions | Provider<FetchHttpHandlerOptions | undefined>);
40
27
  destroy(): void;
41
28
  handle(request: HttpRequest, { abortSignal }?: HttpHandlerOptions): Promise<{
@@ -44,4 +31,3 @@ export declare class FetchHttpHandler implements HttpHandler<FetchHttpHandlerCon
44
31
  updateHttpClientConfig(key: keyof FetchHttpHandlerConfig, value: FetchHttpHandlerConfig[typeof key]): void;
45
32
  httpHandlerConfigs(): FetchHttpHandlerConfig;
46
33
  }
47
- export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/fetch-http-handler",
3
- "version": "2.2.7",
3
+ "version": "2.3.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'",
@@ -9,7 +9,7 @@
9
9
  "build:types": "yarn g:tsc -p tsconfig.types.json",
10
10
  "build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
11
11
  "stage-release": "rimraf ./.release && yarn pack && mkdir ./.release && tar zxvf ./package.tgz --directory ./.release && rm ./package.tgz",
12
- "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
12
+ "clean": "rimraf ./dist-* && rimraf *.tsbuildinfo || exit 0",
13
13
  "lint": "eslint -c ../../.eslintrc.js \"src/**/*.ts\"",
14
14
  "format": "prettier --config ../../prettier.config.js --ignore-path ../.prettierignore --write \"**/*.{ts,md,json}\"",
15
15
  "extract:docs": "api-extractor run --local",
@@ -24,14 +24,14 @@
24
24
  "module": "./dist-es/index.js",
25
25
  "types": "./dist-types/index.d.ts",
26
26
  "dependencies": {
27
- "@smithy/protocol-http": "^3.0.10",
28
- "@smithy/querystring-builder": "^2.0.14",
29
- "@smithy/types": "^2.6.0",
27
+ "@smithy/protocol-http": "^3.0.11",
28
+ "@smithy/querystring-builder": "^2.0.15",
29
+ "@smithy/types": "^2.7.0",
30
30
  "@smithy/util-base64": "^2.0.1",
31
31
  "tslib": "^2.5.0"
32
32
  },
33
33
  "devDependencies": {
34
- "@smithy/abort-controller": "^2.0.14",
34
+ "@smithy/abort-controller": "^2.0.15",
35
35
  "@tsconfig/recommended": "1.0.1",
36
36
  "@types/chai-as-promised": "^7.1.2",
37
37
  "chai": "^4.2.0",