@torthu/jacketui-bring 0.2.4 → 1.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.
Files changed (73) hide show
  1. package/README.md +0 -2
  2. package/dist/bring.js +5 -4
  3. package/dist/errors/AbortError.js +1 -1
  4. package/dist/errors/ClientError.js +1 -1
  5. package/dist/errors/NetworkError.js +1 -1
  6. package/dist/errors/ServerError.js +1 -1
  7. package/dist/errors/TimeoutError.js +1 -1
  8. package/dist/errors/index.js +6 -6
  9. package/dist/fetch.js +1 -1
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.js +6 -5
  12. package/dist/request-builder-pipe/headers.js +11 -2
  13. package/dist/request-builder-pipe/index.d.ts +1 -0
  14. package/dist/request-builder-pipe/index.js +20 -19
  15. package/dist/request-builder-pipe/jitter.js +1 -1
  16. package/dist/response-pipe/index.js +6 -6
  17. package/dist/tryFetch.js +17 -1
  18. package/dist/types/BringInit.d.ts +1 -3
  19. package/package.json +27 -9
  20. package/src/bring.ts +0 -207
  21. package/src/errors/AbortError.ts +0 -18
  22. package/src/errors/BringError.ts +0 -24
  23. package/src/errors/ClientError.ts +0 -24
  24. package/src/errors/NetworkError.ts +0 -23
  25. package/src/errors/ServerError.ts +0 -24
  26. package/src/errors/TimeoutError.ts +0 -18
  27. package/src/errors/index.ts +0 -6
  28. package/src/fetch.ts +0 -34
  29. package/src/helpers/exponentialBackoff.ts +0 -28
  30. package/src/helpers/extractCallbacks.ts +0 -23
  31. package/src/helpers/extractRequestInit.ts +0 -30
  32. package/src/helpers/randomJitter.ts +0 -22
  33. package/src/helpers/shouldRetry.ts +0 -40
  34. package/src/index.ts +0 -7
  35. package/src/request-builder-pipe/backoff.ts +0 -22
  36. package/src/request-builder-pipe/body.ts +0 -17
  37. package/src/request-builder-pipe/cache.ts +0 -23
  38. package/src/request-builder-pipe/cors.ts +0 -39
  39. package/src/request-builder-pipe/credentials.ts +0 -33
  40. package/src/request-builder-pipe/header.ts +0 -28
  41. package/src/request-builder-pipe/headers.ts +0 -34
  42. package/src/request-builder-pipe/index.ts +0 -20
  43. package/src/request-builder-pipe/integrity.ts +0 -23
  44. package/src/request-builder-pipe/jitter.ts +0 -17
  45. package/src/request-builder-pipe/jsonBody.ts +0 -12
  46. package/src/request-builder-pipe/keepalive.ts +0 -21
  47. package/src/request-builder-pipe/method.ts +0 -18
  48. package/src/request-builder-pipe/priority.ts +0 -20
  49. package/src/request-builder-pipe/redirect.ts +0 -23
  50. package/src/request-builder-pipe/referrer.ts +0 -21
  51. package/src/request-builder-pipe/referrerPolicy.ts +0 -33
  52. package/src/request-builder-pipe/retry.ts +0 -13
  53. package/src/request-builder-pipe/shouldRetry.ts +0 -11
  54. package/src/request-builder-pipe/timeout.ts +0 -19
  55. package/src/request-builder-pipe/url.ts +0 -18
  56. package/src/response-pipe/arrayBuffer.ts +0 -18
  57. package/src/response-pipe/blob.ts +0 -18
  58. package/src/response-pipe/bytes.ts +0 -18
  59. package/src/response-pipe/formData.ts +0 -18
  60. package/src/response-pipe/index.ts +0 -6
  61. package/src/response-pipe/json.ts +0 -20
  62. package/src/response-pipe/text.ts +0 -18
  63. package/src/tryFetch.ts +0 -32
  64. package/src/types/BringDecorator.ts +0 -5
  65. package/src/types/BringInit.ts +0 -86
  66. package/src/types/ClientErrorResponse.ts +0 -72
  67. package/src/types/InformationalResponse.ts +0 -20
  68. package/src/types/RedirectResponse.ts +0 -20
  69. package/src/types/ServerErrorResponse.ts +0 -56
  70. package/src/types/SuccessResponse.ts +0 -57
  71. package/src/types/statusCodes.ts +0 -69
  72. package/test/bring.spec.ts +0 -149
  73. package/tsconfig.json +0 -21
package/src/fetch.ts DELETED
@@ -1,34 +0,0 @@
1
- import { bring } from "./bring";
2
- import { BringInit } from "./types/BringInit";
3
-
4
- /** fetch(url: string, init?: Omit<BringInit, "url">): AbortablePromise<Result<Response, BringError>>
5
- *
6
- * Wraps bring in a fetch-like API.
7
- * This is a convenience function for bring.
8
- *
9
- * Some caveats:
10
- * - BringInit expects and AbortController instead of a signal.
11
- * - The first argument cannot be a Request object.
12
- *
13
- * @note This is not a drop-in replacement for the Fetch API.
14
- *
15
- * @note bring does not throw errors, but will return a Result.
16
- *
17
- * @example
18
- * const result = await fetch("https://example.com", { method: "GET" });
19
- * if (result.ok) {
20
- * const data = await result.value.json();
21
- * console.log(data);
22
- * } else {
23
- * console.error(result.error);
24
- * }
25
- *
26
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API
27
- *
28
- * @param url string | URL - The URL to fetch.
29
- * @param init BringInit - extends RequestInit from the Fetch API.
30
- * @returns AbortablePromise<Result<Response, BringError>> - A promise that resolves to a Result object containing either a Response or a BringError.
31
- */
32
- export const fetch = (url: string | URL, init?: Omit<BringInit, "url">) => {
33
- return bring({ url, ...init });
34
- };
@@ -1,28 +0,0 @@
1
- export interface BackoffOptions {
2
- base?: number;
3
- factor?: number;
4
- max?: number;
5
- min?: number;
6
- }
7
-
8
- /** backoff(retryNum: number): number
9
- *
10
- * Backoff is the time to wait before retrying a request. It is calculated using an exponential backoff algorithm.
11
- *
12
- * The formula is: base * factor^(retryNum - 1)
13
- *
14
- * @param retryNum The number of times the request has been retried
15
- * @param options
16
- * @param options.base Base backoff time in milliseconds
17
- * @param options.factor Multiplier for the backoff time
18
- * @param options.max Maximum backoff time in milliseconds
19
- * @param options.min Minimum backoff time in milliseconds
20
- * @returns number
21
- */
22
- export const exponentialBackoff = (
23
- retryNum: number,
24
- { base = 500, factor = 1.5, max = 10000, min = 500 }: BackoffOptions = {}
25
- ): number => {
26
- const calculatedBackoff = base * Math.pow(factor, retryNum - 1);
27
- return Math.min(Math.max(calculatedBackoff, min), max);
28
- };
@@ -1,23 +0,0 @@
1
- import { BringCallbacks, BringInit } from "../types/BringInit";
2
-
3
- export const extractCallbacks = (init: BringInit): BringCallbacks => {
4
- const {
5
- onSuccess,
6
- onError,
7
- onAbort,
8
- onRetry,
9
- onTimeout,
10
- onClientError,
11
- onServerError,
12
- } = init;
13
-
14
- return {
15
- onSuccess,
16
- onError,
17
- onAbort,
18
- onRetry,
19
- onTimeout,
20
- onClientError,
21
- onServerError,
22
- };
23
- };
@@ -1,30 +0,0 @@
1
- import { BringInit, RequestInit } from "../types/BringInit";
2
-
3
- export const extractRequestInit = (init: BringInit): RequestInit => {
4
- const {
5
- method,
6
- headers,
7
- body,
8
- mode,
9
- credentials,
10
- cache,
11
- redirect,
12
- referrer,
13
- referrerPolicy,
14
- integrity,
15
- keepalive,
16
- } = init;
17
- return {
18
- method,
19
- headers,
20
- body,
21
- mode,
22
- credentials,
23
- cache,
24
- redirect,
25
- referrer,
26
- referrerPolicy,
27
- integrity,
28
- keepalive,
29
- };
30
- };
@@ -1,22 +0,0 @@
1
- export interface JitterOptions {
2
- min?: number;
3
- max?: number;
4
- }
5
-
6
- /** jitter(backoff: number): number
7
- *
8
- * Jitter is a random value added to the backoff time to prevent a thundering herd problem (when multiple clients retry at the same time).
9
- *
10
- * @param backoff The backoff time in milliseconds
11
- * @param options
12
- * @param options.min (default 0) Minimum jitter time in milliseconds
13
- * @param options.max (default 100) Maximum jitter time in milliseconds
14
- * @returns number
15
- */
16
- export const randomJitter = ({
17
- min = 0,
18
- max = 100,
19
- }: JitterOptions = {}): number => {
20
- const jitter = Math.random() * max;
21
- return jitter < min ? min : jitter;
22
- };
@@ -1,40 +0,0 @@
1
- import { Failure } from "@torthu/jacketui-core";
2
- import { BringError } from "../errors";
3
-
4
- const defaultRetryStatuses = [0, 408, 425, 429, 500, 502, 503, 504];
5
-
6
- interface RetryOptions {
7
- retryStatuses?: number[];
8
- }
9
-
10
- /** shouldRetry(failure: Failure<BringError>, options?: RetryOptions): boolean
11
- *
12
- * Determines if a request should be retried based on the failure and options.
13
- * By default, it retries on 0, 408, 425, 429, 500, 502, 503, and 504 status codes.
14
- *
15
- * Additionally if there is no response (i.e the request failed before a response was received),
16
- * it will retry.
17
- *
18
- * You can override this behavior by passing a custom `retryStatuses` array.
19
- *
20
- * @param failure Failure<BringError>
21
- * @param options RetryOptions
22
- * @param options.retryStatuses Array of status codes to retry on
23
- * @returns boolean
24
- */
25
- export const shouldRetry = (
26
- failure: Failure<BringError>,
27
- { retryStatuses = defaultRetryStatuses }: RetryOptions = {}
28
- ): boolean => {
29
- const error = failure.error;
30
-
31
- if (error.response) {
32
- if (retryStatuses.includes(error.response.status)) {
33
- return true;
34
- } else {
35
- return false;
36
- }
37
- }
38
-
39
- return true;
40
- };
package/src/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from "./bring";
2
- export * from "./tryFetch";
3
- export * from "./errors";
4
- export * from "./request-builder-pipe";
5
- export * from "./response-pipe";
6
-
7
- export type { BringInit } from "./types/BringInit";
@@ -1,22 +0,0 @@
1
- import {
2
- BackoffOptions,
3
- exponentialBackoff,
4
- } from "../helpers/exponentialBackoff";
5
- import { BringInitDecorator } from "../types/BringDecorator";
6
-
7
- /** backoff(options?: BackoffOptions): BringInitDecorator
8
- *
9
- * Sets a exponential backoff function for retrying requests.
10
- *
11
- * @param options (optional) Backoff options
12
- * @param options.base Base backoff time in milliseconds
13
- * @param options.factor Multiplier for the backoff time
14
- * @param options.max Maximum backoff time in milliseconds
15
- * @param options.min Minimum backoff time in milliseconds
16
- * @returns BringInitDecorator
17
- */
18
- export const backoff = (options?: BackoffOptions): BringInitDecorator => {
19
- const backoffFun = (retryNum: number) =>
20
- exponentialBackoff(retryNum, options);
21
- return (init) => ({ ...init, backoff: backoffFun });
22
- };
@@ -1,17 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** body(body): BringInitDecorator
5
- *
6
- * Sets the body of the request.
7
- *
8
- * @note This is a low-level helper. For JSON bodies, use `jsonBody` instead or manually JSON.stringify first.
9
- *
10
- * @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#body
11
- *
12
- * @param body
13
- * @returns BringInitDecorator
14
- */
15
- export const body =
16
- (body: BringInit["body"]): BringInitDecorator =>
17
- (init) => ({ ...init, body });
@@ -1,23 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** cache(cacheMode): BringInitDecorator
5
- *
6
- * Sets the cache mode for the request.
7
- * Possible values are "default", "no-store", "reload", "no-cache", "force-cache", and "only-if-cached".
8
- * The default value is "default".
9
- *
10
- * @example
11
- * const customGet = (url: string) => pipe(cache("no-cache"), method("GET"), bring)({ url })
12
- *
13
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
14
- *
15
- * @param cacheMode - The cache mode to use for the request. "default", "no-store", "reload", "no-cache", "force-cache", and "only-if-cached"
16
- * @returns BringInitDecorator
17
- */
18
- export const cache =
19
- (cacheMode: BringInit["cache"] = "default"): BringInitDecorator =>
20
- (init) => {
21
- init.cache = cacheMode;
22
- return init;
23
- };
@@ -1,39 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** cors(corsMode): BringInitDecorator
5
- *
6
- * Sets the CORS mode for the request.
7
- *
8
- * The default value is "cors".
9
- *
10
- * Possible values are: "cors", "no-cors", "same-origin".
11
- * - "cors": CORS mode is enabled. This is the default value.
12
- * - "no-cors": CORS mode is disabled.
13
- * - "same-origin": CORS mode is enabled only for same-origin requests.
14
- *
15
- * An origin is the combination of protocol, host, and port.
16
- * The path is not included in the origin.
17
- *
18
- * For example,
19
- * - https://example.com is an origin.
20
- * - https://example.com/path is the same origin.
21
- * - https://example.com:8080 is a different origin.
22
- * - https://sub.example.com/path is a different origin.
23
- * - http://example.com is a different origin.
24
- *
25
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/mode
26
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
27
- *
28
- * @example
29
- * const customGet = (url: string) => pipe(cors("no-cors"), method("GET"), bring)({ url }
30
- *
31
- * @param corsMode - The mode to use for the request. "cors", "no-cors", "same-origin" (default: "cors").
32
- * @returns BringInitDecorator
33
- */
34
- export const cors =
35
- (corsMode: BringInit["mode"] = "cors"): BringInitDecorator =>
36
- (init) => {
37
- init.mode = corsMode;
38
- return init;
39
- };
@@ -1,33 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** credentials(credentialsMode): BringInitDecorator
5
- *
6
- * Sets the credentials mode for the request.
7
- *
8
- * Credentials are cookies, TLS client certificates, or authentication headers containing a username and password.
9
- *
10
- * Possible values are:
11
- * - "omit": Never send cookies.
12
- * - "same-origin": Send cookies only if the URL is on the same origin as the calling script. This is the default value.
13
- * - "include": Always send cookies, even for cross-origin calls.
14
- *
15
- * The default value is "same-origin".
16
- *
17
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
18
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#including_credentials
19
- *
20
- * @example
21
- * const customGet = (url: string) => pipe(credentials("include"), method("GET"), bring)({ url })
22
- *
23
- * @param credentialsMode
24
- * @returns
25
- */
26
- export const credentials =
27
- (
28
- credentialsMode: BringInit["credentials"] = "same-origin"
29
- ): BringInitDecorator =>
30
- (init) => {
31
- init.credentials = credentialsMode;
32
- return init;
33
- };
@@ -1,28 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
-
3
- /** header(key: string, val: string): BringInitDecorator
4
- *
5
- * Sets a header on the request.
6
- * If the header already exists, it will be overwritten.
7
- *
8
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
9
- *
10
- * @param key The name of the header to set.
11
- * @param val The value of the header to set.
12
- * @returns BringDecorator
13
- */
14
- export const header = (key: string, val: string): BringInitDecorator => {
15
- return (init) => {
16
- init.headers ??= new Headers();
17
-
18
- if (init.headers instanceof Headers) {
19
- !init.headers.has(key)
20
- ? init.headers.append(key, val)
21
- : init.headers.set(key, val);
22
- } else {
23
- init.headers[key] = val;
24
- }
25
-
26
- return init;
27
- };
28
- };
@@ -1,34 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
-
3
- /** headers(Record<string, string> | Headers): BringInitDecorator
4
- *
5
- * Sets multiple headers on the request
6
- * If a header already exists, it will be overwritten.
7
- * If a header does not exist, it will be appended.
8
- *
9
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
10
- *
11
- * @param headers A record of headers to set or a Headers object.
12
- * @returns BringDecorator
13
- */
14
- export const headers = (
15
- headers: Record<string, string | number> | Headers
16
- ): BringInitDecorator => {
17
- return (init) => {
18
- init.headers ??= new Headers();
19
-
20
- if (init.headers instanceof Headers) {
21
- for (const [key, val] of Object.entries(headers)) {
22
- !init.headers.has(key)
23
- ? init.headers.append(key, val)
24
- : init.headers.set(key, val);
25
- }
26
- } else {
27
- for (const [key, val] of Object.entries(headers)) {
28
- init.headers[key] = val;
29
- }
30
- }
31
-
32
- return init;
33
- };
34
- };
@@ -1,20 +0,0 @@
1
- export * from "./cache";
2
- export * from "./cors";
3
- export * from "./credentials";
4
- export * from "./header";
5
- export * from "./headers";
6
- export * from "./integrity";
7
- export * from "./keepalive";
8
- export * from "./method";
9
- export * from "./redirect";
10
- export * from "./referrer";
11
- export * from "./referrerPolicy";
12
- export * from "./retry";
13
- export * from "./body";
14
- export * from "./jsonBody";
15
- export * from "./priority";
16
- export * from "./url";
17
-
18
- export * from "./backoff";
19
- export * from "./jitter";
20
- export * from "./timeout";
@@ -1,23 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** integrity(integrityMode): BringInitDecorator
5
- *
6
- * Sets the integrity mode of the request.
7
- *
8
- * The format of this option is <hash-algo>-<hash-source> where:
9
- * - <hash-algo> is one of the following values: sha256, sha384, or sha512
10
- * - <hash-source> is the Base64-encoding of the result of hashing the resource with the specified hash algorithm.
11
- *
12
- * @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#integrity
13
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/integrity
14
- *
15
- * @param integrityMode
16
- * @returns BringDecorator
17
- */
18
- export const integrity =
19
- (integrityMode: BringInit["integrity"] = ""): BringInitDecorator =>
20
- (init) => {
21
- init.integrity = integrityMode;
22
- return init;
23
- };
@@ -1,17 +0,0 @@
1
- import { JitterOptions, randomJitter } from "../helpers/randomJitter";
2
- import { BringInitDecorator } from "../types/BringDecorator";
3
-
4
- /** jitter(options?: JitterOptions): BringInitDecorator
5
- *
6
- * Sets a jitter function for retrying requests.
7
- * Jitter is a random value added to the backoff time to prevent a thundering herd problem (when multiple clients retry at the same time).
8
- *
9
- * @param options (optional) Jitter options
10
- * @param options.max (default 100) Maximum jitter time in milliseconds
11
- * @param options.min (default 0) Minimum jitter time in milliseconds
12
- * @returns BringInitDecorator
13
- */
14
- export const jitter = (options?: JitterOptions): BringInitDecorator => {
15
- const jitterFun = () => randomJitter(options);
16
- return (init) => ({ ...init, backoff: jitterFun });
17
- };
@@ -1,12 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
-
3
- /** jsonBody(body: any): BringInitDecorator
4
- *
5
- * Sets the body of the request to a JSON string.
6
- *
7
- * @param body Any JSON serializable value
8
- * @returns BringInitDecorator
9
- */
10
- export const jsonBody =
11
- <BodyType = any>(body: BodyType): BringInitDecorator =>
12
- (init) => ({ ...init, body: JSON.stringify(body) });
@@ -1,21 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** keepalive(boolean): BringInitDecorator
5
- *
6
- * Sets the keepalive mode of the request.
7
- *
8
- * If set to true, the request will be kept alive until the browser is closed.
9
- *
10
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/keepalive
11
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#keepalive
12
- *
13
- * @param keepaliveMode
14
- * @returns
15
- */
16
- export const keepalive =
17
- (keepaliveMode: BringInit["keepalive"] = false): BringInitDecorator =>
18
- (init) => {
19
- init.keepalive = keepaliveMode;
20
- return init;
21
- };
@@ -1,18 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** method(string): BringInitDecorator
5
- *
6
- * Sets the HTTP method of the request.
7
- *
8
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/method
9
- *
10
- * @param method - The HTTP method to use for the request.
11
- * @returns BringDecorator
12
- */
13
- export const method =
14
- (method: BringInit["method"] = "GET"): BringInitDecorator =>
15
- (init) => ({
16
- ...init,
17
- method,
18
- });
@@ -1,20 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** priority("auto" | "high" | "low"): BringInitDecorator
5
- *
6
- * The priority of the request relative to other requests of the same type.
7
- *
8
- * Possible values are:
9
- * - "auto" (default) No user preference for the fetch priority
10
- * - "high" A high priority fetch request relative to other requests of the same type.
11
- * - "low" A low priority fetch request relative to other requests of the same type.
12
- *
13
- * @param priorityMode "auto" | "high" | "low
14
- * @returns BringInitDecorator
15
- */
16
- export const priority = (
17
- priorityMode: BringInit["priority"] = "auto"
18
- ): BringInitDecorator => {
19
- return (init) => ({ ...init, priority: priorityMode });
20
- };
@@ -1,23 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** redirect(string): BringInitDecorator
5
- *
6
- * Sets the redirect mode of the request.
7
- *
8
- * Possible values are:
9
- * - "follow": Automatically follow redirects. This is the default value.
10
- * - "error": Abort with an error if a redirect occurs.
11
- * - "manual": Handle redirects manually.
12
- *
13
- * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect
14
- *
15
- * @param redirectMode - The redirect mode to use. "follow" | "error" | "manual". Defaults to "follow".
16
- * @returns BringIntDecorator
17
- */
18
- export const redirect =
19
- (redirectMode: BringInit["redirect"] = "follow"): BringInitDecorator =>
20
- (init) => {
21
- init.redirect = redirectMode;
22
- return init;
23
- };
@@ -1,21 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** referrer(string): BringInitDecorator
5
- *
6
- * A string specifying the value to use for the request's Referer header. One of the following:
7
- * - A same-origin relative or absolute URL
8
- * - An empty string, which indicates that no Referer header should be sent
9
- * - "about:client" (default) set the Referer header to the default value for the context of the request (for example, the URL of the page that made the request).
10
- *
11
- * @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#referrer
12
- *
13
- * @param referrerMode
14
- * @returns
15
- */
16
- export const referrer =
17
- (referrerMode: BringInit["referrer"] = "about:client"): BringInitDecorator =>
18
- (init) => {
19
- init.referrer = referrerMode;
20
- return init;
21
- };
@@ -1,33 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** referrerPolicy(string): BringInitDecorator
5
- *
6
- * A string specifying the value of the referrer-policy header to use for the request.
7
- *
8
- * Possible values are:
9
- * - "no-referrer" The Referer header will not be sent.
10
- * - "no-referrer-when-downgrade" Send the origin, path, and query string in Referer when the protocol security level stays the same or improves
11
- * - "origin" Send only the origin in the Referer header. For example, a document at https://example.com/page.html will send the referrer https://example.com/.
12
- * - "origin-when-cross-origin" When performing a same-origin request to the same protocol level (HTTP→HTTP, HTTPS→HTTPS), send the origin, path, and query string. Send only the origin for cross origin requests and requests to less secure destinations (HTTPS→HTTP).
13
- * - "same-origin" Send the origin, path, and query string for same-origin requests. Don't send the Referer header for cross-origin requests.
14
- * - "strict-origin" Send only the origin when the protocol security level stays the same (HTTPS→HTTPS). Don't send the Referer header to less secure destinations (HTTPS→HTTP).
15
- * - "strict-origin-when-cross-origin" (default) Send the origin, path, and query string when performing a same-origin request. For cross-origin requests send the origin (only) when the protocol security level stays same (HTTPS→HTTPS). Don't send the Referer header to less secure destinations (HTTPS→HTTP).
16
- * - "unsafe-url" Send the origin, path, and query string when performing any request, regardless of security.
17
- *
18
- * Default is "strict-origin-when-cross-origin"
19
- *
20
- * @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#referrerpolicy
21
- * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Referrer-Policy
22
- *
23
- * @param referrerPolicyMode
24
- * @returns BringInitDecorator
25
- */
26
- export const referrerPolicy =
27
- (
28
- referrerPolicyMode: BringInit["referrerPolicy"] = "strict-origin-when-cross-origin"
29
- ): BringInitDecorator =>
30
- (init) => {
31
- init.referrerPolicy = referrerPolicyMode;
32
- return init;
33
- };
@@ -1,13 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** retry(number): BringInitDecorator
5
- *
6
- * Sets the number of times to retry the request.
7
- *
8
- * @param retry The number of times to retry the request.
9
- * @returns BringInitDecorator
10
- */
11
- export const retry =
12
- (retry: BringInit["retry"]): BringInitDecorator =>
13
- (init) => ({ ...init, retry });
@@ -1,11 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** shouldRetry((response: Response, retryNum: number) => boolean)): BringInitDecorator
5
- *
6
- * @param shouldRetry ((response: Response, retryNum: number) => boolean)
7
- * @returns BringInitDecorator
8
- */
9
- export const shouldRetry =
10
- (shouldRetry: BringInit["shouldRetry"]): BringInitDecorator =>
11
- (init) => ({ ...init, shouldRetry });
@@ -1,19 +0,0 @@
1
- import { BringInitDecorator } from "../types/BringDecorator";
2
- import { BringInit } from "../types/BringInit";
3
-
4
- /** timeout(number): BringInitDecorator
5
- *
6
- * Sets in-flight timeout for request.
7
- * Used to configure AbortSignal.timeout().
8
- *
9
- * If retry is set, timeout will be applied to each retry.
10
- * Total time for request will be (timeout + jitter + backoff) * retry.
11
- *
12
- * @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/timeout_static
13
- *
14
- * @param timeout The time to wait before aborting the request.
15
- * @returns BringInitDecorator
16
- */
17
- export const timeout =
18
- (timeout: BringInit["timeout"]): BringInitDecorator =>
19
- (init) => ({ ...init, timeout });