@torthu/jacketui-bring 0.0.1
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/README.md +11 -0
- package/dist/bring.d.ts +38 -0
- package/dist/bring.js +142 -0
- package/dist/errors/AbortError.d.ts +11 -0
- package/dist/errors/AbortError.js +14 -0
- package/dist/errors/BringError.d.ts +15 -0
- package/dist/errors/BringError.js +14 -0
- package/dist/errors/ClientError.d.ts +11 -0
- package/dist/errors/ClientError.js +19 -0
- package/dist/errors/NetworkError.d.ts +11 -0
- package/dist/errors/NetworkError.js +18 -0
- package/dist/errors/ServerError.d.ts +11 -0
- package/dist/errors/ServerError.js +19 -0
- package/dist/errors/TimeoutError.d.ts +11 -0
- package/dist/errors/TimeoutError.js +14 -0
- package/dist/errors/index.d.ts +6 -0
- package/dist/errors/index.js +6 -0
- package/dist/fetch.d.ts +30 -0
- package/dist/fetch.js +32 -0
- package/dist/helpers/exponentialBackoff.d.ts +21 -0
- package/dist/helpers/exponentialBackoff.js +18 -0
- package/dist/helpers/extractCallbacks.d.ts +2 -0
- package/dist/helpers/extractCallbacks.js +12 -0
- package/dist/helpers/extractRequestInit.d.ts +2 -0
- package/dist/helpers/extractRequestInit.js +16 -0
- package/dist/helpers/randomJitter.d.ts +15 -0
- package/dist/helpers/randomJitter.js +14 -0
- package/dist/helpers/shouldRetry.d.ts +22 -0
- package/dist/helpers/shouldRetry.js +28 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/pipe-helpers/backoff.d.ts +14 -0
- package/dist/pipe-helpers/backoff.js +16 -0
- package/dist/pipe-helpers/body.d.ts +14 -0
- package/dist/pipe-helpers/body.js +12 -0
- package/dist/pipe-helpers/cache.d.ts +17 -0
- package/dist/pipe-helpers/cache.js +18 -0
- package/dist/pipe-helpers/cors.d.ts +33 -0
- package/dist/pipe-helpers/cors.js +34 -0
- package/dist/pipe-helpers/credentials.d.ts +25 -0
- package/dist/pipe-helpers/credentials.js +26 -0
- package/dist/pipe-helpers/header.d.ts +13 -0
- package/dist/pipe-helpers/header.js +25 -0
- package/dist/pipe-helpers/index.d.ts +17 -0
- package/dist/pipe-helpers/index.js +17 -0
- package/dist/pipe-helpers/integrity.d.ts +17 -0
- package/dist/pipe-helpers/integrity.js +18 -0
- package/dist/pipe-helpers/jitter.d.ts +13 -0
- package/dist/pipe-helpers/jitter.js +15 -0
- package/dist/pipe-helpers/jsonBody.d.ts +10 -0
- package/dist/pipe-helpers/jsonBody.js +8 -0
- package/dist/pipe-helpers/keepalive.d.ts +15 -0
- package/dist/pipe-helpers/keepalive.js +16 -0
- package/dist/pipe-helpers/method.d.ts +12 -0
- package/dist/pipe-helpers/method.js +13 -0
- package/dist/pipe-helpers/priority.d.ts +15 -0
- package/dist/pipe-helpers/priority.js +15 -0
- package/dist/pipe-helpers/redirect.d.ts +17 -0
- package/dist/pipe-helpers/redirect.js +18 -0
- package/dist/pipe-helpers/referrer.d.ts +15 -0
- package/dist/pipe-helpers/referrer.js +16 -0
- package/dist/pipe-helpers/referrerPolicy.d.ts +25 -0
- package/dist/pipe-helpers/referrerPolicy.js +26 -0
- package/dist/pipe-helpers/retry.d.ts +10 -0
- package/dist/pipe-helpers/retry.js +8 -0
- package/dist/pipe-helpers/shouldRetry.d.ts +8 -0
- package/dist/pipe-helpers/shouldRetry.js +6 -0
- package/dist/pipe-helpers/timeout.d.ts +16 -0
- package/dist/pipe-helpers/timeout.js +14 -0
- package/dist/tryFetch.d.ts +3 -0
- package/dist/tryFetch.js +19 -0
- package/dist/types/BringDecorator.d.ts +4 -0
- package/dist/types/BringDecorator.js +1 -0
- package/dist/types/BringInit.d.ts +37 -0
- package/dist/types/BringInit.js +1 -0
- package/dist/types/ClientErrorResponse.d.ts +6 -0
- package/dist/types/ClientErrorResponse.js +32 -0
- package/dist/types/InformationalResponse.d.ts +6 -0
- package/dist/types/InformationalResponse.js +8 -0
- package/dist/types/RedirectResponse.d.ts +6 -0
- package/dist/types/RedirectResponse.js +9 -0
- package/dist/types/ServerErrorResponse.d.ts +6 -0
- package/dist/types/ServerErrorResponse.js +24 -0
- package/dist/types/SuccessResponse.d.ts +13 -0
- package/dist/types/SuccessResponse.js +20 -0
- package/dist/types/statusCodes.d.ts +69 -0
- package/dist/types/statusCodes.js +69 -0
- package/package.json +23 -0
- package/src/bring.ts +198 -0
- package/src/errors/AbortError.ts +18 -0
- package/src/errors/BringError.ts +24 -0
- package/src/errors/ClientError.ts +24 -0
- package/src/errors/NetworkError.ts +23 -0
- package/src/errors/ServerError.ts +24 -0
- package/src/errors/TimeoutError.ts +18 -0
- package/src/errors/index.ts +6 -0
- package/src/fetch.ts +34 -0
- package/src/helpers/exponentialBackoff.ts +28 -0
- package/src/helpers/extractCallbacks.ts +23 -0
- package/src/helpers/extractRequestInit.ts +30 -0
- package/src/helpers/randomJitter.ts +22 -0
- package/src/helpers/shouldRetry.ts +40 -0
- package/src/index.ts +4 -0
- package/src/pipe-helpers/backoff.ts +22 -0
- package/src/pipe-helpers/body.ts +17 -0
- package/src/pipe-helpers/cache.ts +23 -0
- package/src/pipe-helpers/cors.ts +39 -0
- package/src/pipe-helpers/credentials.ts +33 -0
- package/src/pipe-helpers/header.ts +28 -0
- package/src/pipe-helpers/index.ts +18 -0
- package/src/pipe-helpers/integrity.ts +23 -0
- package/src/pipe-helpers/jitter.ts +17 -0
- package/src/pipe-helpers/jsonBody.ts +13 -0
- package/src/pipe-helpers/keepalive.ts +21 -0
- package/src/pipe-helpers/method.ts +18 -0
- package/src/pipe-helpers/priority.ts +20 -0
- package/src/pipe-helpers/redirect.ts +23 -0
- package/src/pipe-helpers/referrer.ts +21 -0
- package/src/pipe-helpers/referrerPolicy.ts +33 -0
- package/src/pipe-helpers/retry.ts +13 -0
- package/src/pipe-helpers/shouldRetry.ts +11 -0
- package/src/pipe-helpers/timeout.ts +19 -0
- package/src/tryFetch.ts +32 -0
- package/src/types/BringDecorator.ts +5 -0
- package/src/types/BringInit.ts +78 -0
- package/src/types/ClientErrorResponse.ts +72 -0
- package/src/types/InformationalResponse.ts +20 -0
- package/src/types/RedirectResponse.ts +20 -0
- package/src/types/ServerErrorResponse.ts +56 -0
- package/src/types/SuccessResponse.ts +57 -0
- package/src/types/statusCodes.ts +69 -0
- package/tsconfig.json +11 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { exponentialBackoff, } from "../helpers/exponentialBackoff";
|
|
2
|
+
/** backoff(options?: BackoffOptions): BringInitDecorator
|
|
3
|
+
*
|
|
4
|
+
* Sets a exponential backoff function for retrying requests.
|
|
5
|
+
*
|
|
6
|
+
* @param options (optional) Backoff options
|
|
7
|
+
* @param options.base Base backoff time in milliseconds
|
|
8
|
+
* @param options.factor Multiplier for the backoff time
|
|
9
|
+
* @param options.max Maximum backoff time in milliseconds
|
|
10
|
+
* @param options.min Minimum backoff time in milliseconds
|
|
11
|
+
* @returns BringInitDecorator
|
|
12
|
+
*/
|
|
13
|
+
export const backoff = (options) => {
|
|
14
|
+
const backoffFun = (retryNum) => exponentialBackoff(retryNum, options);
|
|
15
|
+
return (init) => ({ ...init, backoff: backoffFun });
|
|
16
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** body(body): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* Sets the body of the request.
|
|
6
|
+
*
|
|
7
|
+
* @note This is a low-level helper. For JSON bodies, use `jsonBody` instead or manually JSON.stringify first.
|
|
8
|
+
*
|
|
9
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#body
|
|
10
|
+
*
|
|
11
|
+
* @param body
|
|
12
|
+
* @returns BringInitDecorator
|
|
13
|
+
*/
|
|
14
|
+
export declare const body: (body: BringInit["body"]) => BringInitDecorator;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** body(body): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* Sets the body of the request.
|
|
4
|
+
*
|
|
5
|
+
* @note This is a low-level helper. For JSON bodies, use `jsonBody` instead or manually JSON.stringify first.
|
|
6
|
+
*
|
|
7
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#body
|
|
8
|
+
*
|
|
9
|
+
* @param body
|
|
10
|
+
* @returns BringInitDecorator
|
|
11
|
+
*/
|
|
12
|
+
export const body = (body) => (init) => ({ ...init, body });
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** cache(cacheMode): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* Sets the cache mode for the request.
|
|
6
|
+
* Possible values are "default", "no-store", "reload", "no-cache", "force-cache", and "only-if-cached".
|
|
7
|
+
* The default value is "default".
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* const customGet = (url: string) => pipe(cache("no-cache"), method("GET"), bring)({ url })
|
|
11
|
+
*
|
|
12
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
|
|
13
|
+
*
|
|
14
|
+
* @param cacheMode - The cache mode to use for the request. "default", "no-store", "reload", "no-cache", "force-cache", and "only-if-cached"
|
|
15
|
+
* @returns BringInitDecorator
|
|
16
|
+
*/
|
|
17
|
+
export declare const cache: (cacheMode?: BringInit["cache"]) => BringInitDecorator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** cache(cacheMode): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* Sets the cache mode for the request.
|
|
4
|
+
* Possible values are "default", "no-store", "reload", "no-cache", "force-cache", and "only-if-cached".
|
|
5
|
+
* The default value is "default".
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const customGet = (url: string) => pipe(cache("no-cache"), method("GET"), bring)({ url })
|
|
9
|
+
*
|
|
10
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
|
|
11
|
+
*
|
|
12
|
+
* @param cacheMode - The cache mode to use for the request. "default", "no-store", "reload", "no-cache", "force-cache", and "only-if-cached"
|
|
13
|
+
* @returns BringInitDecorator
|
|
14
|
+
*/
|
|
15
|
+
export const cache = (cacheMode = "default") => (init) => {
|
|
16
|
+
init.cache = cacheMode;
|
|
17
|
+
return init;
|
|
18
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** cors(corsMode): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* Sets the CORS mode for the request.
|
|
6
|
+
*
|
|
7
|
+
* The default value is "cors".
|
|
8
|
+
*
|
|
9
|
+
* Possible values are: "cors", "no-cors", "same-origin".
|
|
10
|
+
* - "cors": CORS mode is enabled. This is the default value.
|
|
11
|
+
* - "no-cors": CORS mode is disabled.
|
|
12
|
+
* - "same-origin": CORS mode is enabled only for same-origin requests.
|
|
13
|
+
*
|
|
14
|
+
* An origin is the combination of protocol, host, and port.
|
|
15
|
+
* The path is not included in the origin.
|
|
16
|
+
*
|
|
17
|
+
* For example,
|
|
18
|
+
* - https://example.com is an origin.
|
|
19
|
+
* - https://example.com/path is the same origin.
|
|
20
|
+
* - https://example.com:8080 is a different origin.
|
|
21
|
+
* - https://sub.example.com/path is a different origin.
|
|
22
|
+
* - http://example.com is a different origin.
|
|
23
|
+
*
|
|
24
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/mode
|
|
25
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const customGet = (url: string) => pipe(cors("no-cors"), method("GET"), bring)({ url }
|
|
29
|
+
*
|
|
30
|
+
* @param corsMode - The mode to use for the request. "cors", "no-cors", "same-origin" (default: "cors").
|
|
31
|
+
* @returns BringInitDecorator
|
|
32
|
+
*/
|
|
33
|
+
export declare const cors: (corsMode?: BringInit["mode"]) => BringInitDecorator;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/** cors(corsMode): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* Sets the CORS mode for the request.
|
|
4
|
+
*
|
|
5
|
+
* The default value is "cors".
|
|
6
|
+
*
|
|
7
|
+
* Possible values are: "cors", "no-cors", "same-origin".
|
|
8
|
+
* - "cors": CORS mode is enabled. This is the default value.
|
|
9
|
+
* - "no-cors": CORS mode is disabled.
|
|
10
|
+
* - "same-origin": CORS mode is enabled only for same-origin requests.
|
|
11
|
+
*
|
|
12
|
+
* An origin is the combination of protocol, host, and port.
|
|
13
|
+
* The path is not included in the origin.
|
|
14
|
+
*
|
|
15
|
+
* For example,
|
|
16
|
+
* - https://example.com is an origin.
|
|
17
|
+
* - https://example.com/path is the same origin.
|
|
18
|
+
* - https://example.com:8080 is a different origin.
|
|
19
|
+
* - https://sub.example.com/path is a different origin.
|
|
20
|
+
* - http://example.com is a different origin.
|
|
21
|
+
*
|
|
22
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/mode
|
|
23
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* const customGet = (url: string) => pipe(cors("no-cors"), method("GET"), bring)({ url }
|
|
27
|
+
*
|
|
28
|
+
* @param corsMode - The mode to use for the request. "cors", "no-cors", "same-origin" (default: "cors").
|
|
29
|
+
* @returns BringInitDecorator
|
|
30
|
+
*/
|
|
31
|
+
export const cors = (corsMode = "cors") => (init) => {
|
|
32
|
+
init.mode = corsMode;
|
|
33
|
+
return init;
|
|
34
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** credentials(credentialsMode): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* Sets the credentials mode for the request.
|
|
6
|
+
*
|
|
7
|
+
* Credentials are cookies, TLS client certificates, or authentication headers containing a username and password.
|
|
8
|
+
*
|
|
9
|
+
* Possible values are:
|
|
10
|
+
* - "omit": Never send cookies.
|
|
11
|
+
* - "same-origin": Send cookies only if the URL is on the same origin as the calling script. This is the default value.
|
|
12
|
+
* - "include": Always send cookies, even for cross-origin calls.
|
|
13
|
+
*
|
|
14
|
+
* The default value is "same-origin".
|
|
15
|
+
*
|
|
16
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
|
|
17
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#including_credentials
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const customGet = (url: string) => pipe(credentials("include"), method("GET"), bring)({ url })
|
|
21
|
+
*
|
|
22
|
+
* @param credentialsMode
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare const credentials: (credentialsMode?: BringInit["credentials"]) => BringInitDecorator;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** credentials(credentialsMode): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* Sets the credentials mode for the request.
|
|
4
|
+
*
|
|
5
|
+
* Credentials are cookies, TLS client certificates, or authentication headers containing a username and password.
|
|
6
|
+
*
|
|
7
|
+
* Possible values are:
|
|
8
|
+
* - "omit": Never send cookies.
|
|
9
|
+
* - "same-origin": Send cookies only if the URL is on the same origin as the calling script. This is the default value.
|
|
10
|
+
* - "include": Always send cookies, even for cross-origin calls.
|
|
11
|
+
*
|
|
12
|
+
* The default value is "same-origin".
|
|
13
|
+
*
|
|
14
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/credentials
|
|
15
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#including_credentials
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* const customGet = (url: string) => pipe(credentials("include"), method("GET"), bring)({ url })
|
|
19
|
+
*
|
|
20
|
+
* @param credentialsMode
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export const credentials = (credentialsMode = "same-origin") => (init) => {
|
|
24
|
+
init.credentials = credentialsMode;
|
|
25
|
+
return init;
|
|
26
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
/** header(key: string, val: string): BringInitDecorator
|
|
3
|
+
*
|
|
4
|
+
* Sets a header on the request.
|
|
5
|
+
* If the header already exists, it will be overwritten.
|
|
6
|
+
*
|
|
7
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
|
|
8
|
+
*
|
|
9
|
+
* @param key The name of the header to set.
|
|
10
|
+
* @param val The value of the header to set.
|
|
11
|
+
* @returns BringDecorator
|
|
12
|
+
*/
|
|
13
|
+
export declare const header: (key: string, val: string) => BringInitDecorator;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** header(key: string, val: string): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* Sets a header on the request.
|
|
4
|
+
* If the header already exists, it will be overwritten.
|
|
5
|
+
*
|
|
6
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Headers
|
|
7
|
+
*
|
|
8
|
+
* @param key The name of the header to set.
|
|
9
|
+
* @param val The value of the header to set.
|
|
10
|
+
* @returns BringDecorator
|
|
11
|
+
*/
|
|
12
|
+
export const header = (key, val) => {
|
|
13
|
+
return (init) => {
|
|
14
|
+
init.headers ??= new Headers();
|
|
15
|
+
if (init.headers instanceof Headers) {
|
|
16
|
+
!init.headers.has(key)
|
|
17
|
+
? init.headers.append(key, val)
|
|
18
|
+
: init.headers.set(key, val);
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
init.headers[key] = val;
|
|
22
|
+
}
|
|
23
|
+
return init;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./cache";
|
|
2
|
+
export * from "./cors";
|
|
3
|
+
export * from "./credentials";
|
|
4
|
+
export * from "./header";
|
|
5
|
+
export * from "./integrity";
|
|
6
|
+
export * from "./keepalive";
|
|
7
|
+
export * from "./method";
|
|
8
|
+
export * from "./redirect";
|
|
9
|
+
export * from "./referrer";
|
|
10
|
+
export * from "./referrerPolicy";
|
|
11
|
+
export * from "./retry";
|
|
12
|
+
export * from "./body";
|
|
13
|
+
export * from "./jsonBody";
|
|
14
|
+
export * from "./priority";
|
|
15
|
+
export * from "./backoff";
|
|
16
|
+
export * from "./jitter";
|
|
17
|
+
export * from "./timeout";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * from "./cache";
|
|
2
|
+
export * from "./cors";
|
|
3
|
+
export * from "./credentials";
|
|
4
|
+
export * from "./header";
|
|
5
|
+
export * from "./integrity";
|
|
6
|
+
export * from "./keepalive";
|
|
7
|
+
export * from "./method";
|
|
8
|
+
export * from "./redirect";
|
|
9
|
+
export * from "./referrer";
|
|
10
|
+
export * from "./referrerPolicy";
|
|
11
|
+
export * from "./retry";
|
|
12
|
+
export * from "./body";
|
|
13
|
+
export * from "./jsonBody";
|
|
14
|
+
export * from "./priority";
|
|
15
|
+
export * from "./backoff";
|
|
16
|
+
export * from "./jitter";
|
|
17
|
+
export * from "./timeout";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** integrity(integrityMode): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* Sets the integrity mode of the request.
|
|
6
|
+
*
|
|
7
|
+
* The format of this option is <hash-algo>-<hash-source> where:
|
|
8
|
+
* - <hash-algo> is one of the following values: sha256, sha384, or sha512
|
|
9
|
+
* - <hash-source> is the Base64-encoding of the result of hashing the resource with the specified hash algorithm.
|
|
10
|
+
*
|
|
11
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#integrity
|
|
12
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/integrity
|
|
13
|
+
*
|
|
14
|
+
* @param integrityMode
|
|
15
|
+
* @returns BringDecorator
|
|
16
|
+
*/
|
|
17
|
+
export declare const integrity: (integrityMode?: BringInit["integrity"]) => BringInitDecorator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** integrity(integrityMode): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* Sets the integrity mode of the request.
|
|
4
|
+
*
|
|
5
|
+
* The format of this option is <hash-algo>-<hash-source> where:
|
|
6
|
+
* - <hash-algo> is one of the following values: sha256, sha384, or sha512
|
|
7
|
+
* - <hash-source> is the Base64-encoding of the result of hashing the resource with the specified hash algorithm.
|
|
8
|
+
*
|
|
9
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#integrity
|
|
10
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/integrity
|
|
11
|
+
*
|
|
12
|
+
* @param integrityMode
|
|
13
|
+
* @returns BringDecorator
|
|
14
|
+
*/
|
|
15
|
+
export const integrity = (integrityMode = "") => (init) => {
|
|
16
|
+
init.integrity = integrityMode;
|
|
17
|
+
return init;
|
|
18
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { JitterOptions } from "../helpers/randomJitter";
|
|
2
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
3
|
+
/** jitter(options?: JitterOptions): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* Sets a jitter function for retrying requests.
|
|
6
|
+
* Jitter is a random value added to the backoff time to prevent a thundering herd problem (when multiple clients retry at the same time).
|
|
7
|
+
*
|
|
8
|
+
* @param options (optional) Jitter options
|
|
9
|
+
* @param options.max (default 100) Maximum jitter time in milliseconds
|
|
10
|
+
* @param options.min (default 0) Minimum jitter time in milliseconds
|
|
11
|
+
* @returns BringInitDecorator
|
|
12
|
+
*/
|
|
13
|
+
export declare const jitter: (options?: JitterOptions) => BringInitDecorator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { randomJitter } from "../helpers/randomJitter";
|
|
2
|
+
/** jitter(options?: JitterOptions): BringInitDecorator
|
|
3
|
+
*
|
|
4
|
+
* Sets a jitter function for retrying requests.
|
|
5
|
+
* Jitter is a random value added to the backoff time to prevent a thundering herd problem (when multiple clients retry at the same time).
|
|
6
|
+
*
|
|
7
|
+
* @param options (optional) Jitter options
|
|
8
|
+
* @param options.max (default 100) Maximum jitter time in milliseconds
|
|
9
|
+
* @param options.min (default 0) Minimum jitter time in milliseconds
|
|
10
|
+
* @returns BringInitDecorator
|
|
11
|
+
*/
|
|
12
|
+
export const jitter = (options) => {
|
|
13
|
+
const jitterFun = () => randomJitter(options);
|
|
14
|
+
return (init) => ({ ...init, backoff: jitterFun });
|
|
15
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** jsonBody(body: BringInit["body"]): 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 declare const jsonBody: (body: BringInit["body"]) => BringInitDecorator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** jsonBody(body: BringInit["body"]): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* Sets the body of the request to a JSON string.
|
|
4
|
+
*
|
|
5
|
+
* @param body Any JSON serializable value
|
|
6
|
+
* @returns BringInitDecorator
|
|
7
|
+
*/
|
|
8
|
+
export const jsonBody = (body) => (init) => ({ ...init, body: JSON.stringify(body) });
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** keepalive(boolean): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* Sets the keepalive mode of the request.
|
|
6
|
+
*
|
|
7
|
+
* If set to true, the request will be kept alive until the browser is closed.
|
|
8
|
+
*
|
|
9
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/keepalive
|
|
10
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#keepalive
|
|
11
|
+
*
|
|
12
|
+
* @param keepaliveMode
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare const keepalive: (keepaliveMode?: BringInit["keepalive"]) => BringInitDecorator;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** keepalive(boolean): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* Sets the keepalive mode of the request.
|
|
4
|
+
*
|
|
5
|
+
* If set to true, the request will be kept alive until the browser is closed.
|
|
6
|
+
*
|
|
7
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/keepalive
|
|
8
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch#keepalive
|
|
9
|
+
*
|
|
10
|
+
* @param keepaliveMode
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export const keepalive = (keepaliveMode = false) => (init) => {
|
|
14
|
+
init.keepalive = keepaliveMode;
|
|
15
|
+
return init;
|
|
16
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** method(string): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* Sets the HTTP method of the request.
|
|
6
|
+
*
|
|
7
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/method
|
|
8
|
+
*
|
|
9
|
+
* @param method - The HTTP method to use for the request.
|
|
10
|
+
* @returns BringDecorator
|
|
11
|
+
*/
|
|
12
|
+
export declare const method: (method?: BringInit["method"]) => BringInitDecorator;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** method(string): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* Sets the HTTP method of the request.
|
|
4
|
+
*
|
|
5
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/method
|
|
6
|
+
*
|
|
7
|
+
* @param method - The HTTP method to use for the request.
|
|
8
|
+
* @returns BringDecorator
|
|
9
|
+
*/
|
|
10
|
+
export const method = (method = "GET") => (init) => ({
|
|
11
|
+
...init,
|
|
12
|
+
method,
|
|
13
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** priority("auto" | "high" | "low"): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* The priority of the request relative to other requests of the same type.
|
|
6
|
+
*
|
|
7
|
+
* Possible values are:
|
|
8
|
+
* - "auto" (default) No user preference for the fetch priority
|
|
9
|
+
* - "high" A high priority fetch request relative to other requests of the same type.
|
|
10
|
+
* - "low" A low priority fetch request relative to other requests of the same type.
|
|
11
|
+
*
|
|
12
|
+
* @param priorityMode "auto" | "high" | "low
|
|
13
|
+
* @returns BringInitDecorator
|
|
14
|
+
*/
|
|
15
|
+
export declare const priority: (priorityMode?: BringInit["priority"]) => BringInitDecorator;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** priority("auto" | "high" | "low"): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* The priority of the request relative to other requests of the same type.
|
|
4
|
+
*
|
|
5
|
+
* Possible values are:
|
|
6
|
+
* - "auto" (default) No user preference for the fetch priority
|
|
7
|
+
* - "high" A high priority fetch request relative to other requests of the same type.
|
|
8
|
+
* - "low" A low priority fetch request relative to other requests of the same type.
|
|
9
|
+
*
|
|
10
|
+
* @param priorityMode "auto" | "high" | "low
|
|
11
|
+
* @returns BringInitDecorator
|
|
12
|
+
*/
|
|
13
|
+
export const priority = (priorityMode = "auto") => {
|
|
14
|
+
return (init) => ({ ...init, priority: priorityMode });
|
|
15
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** redirect(string): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* Sets the redirect mode of the request.
|
|
6
|
+
*
|
|
7
|
+
* Possible values are:
|
|
8
|
+
* - "follow": Automatically follow redirects. This is the default value.
|
|
9
|
+
* - "error": Abort with an error if a redirect occurs.
|
|
10
|
+
* - "manual": Handle redirects manually.
|
|
11
|
+
*
|
|
12
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect
|
|
13
|
+
*
|
|
14
|
+
* @param redirectMode - The redirect mode to use. "follow" | "error" | "manual". Defaults to "follow".
|
|
15
|
+
* @returns BringIntDecorator
|
|
16
|
+
*/
|
|
17
|
+
export declare const redirect: (redirectMode?: BringInit["redirect"]) => BringInitDecorator;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** redirect(string): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* Sets the redirect mode of the request.
|
|
4
|
+
*
|
|
5
|
+
* Possible values are:
|
|
6
|
+
* - "follow": Automatically follow redirects. This is the default value.
|
|
7
|
+
* - "error": Abort with an error if a redirect occurs.
|
|
8
|
+
* - "manual": Handle redirects manually.
|
|
9
|
+
*
|
|
10
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect
|
|
11
|
+
*
|
|
12
|
+
* @param redirectMode - The redirect mode to use. "follow" | "error" | "manual". Defaults to "follow".
|
|
13
|
+
* @returns BringIntDecorator
|
|
14
|
+
*/
|
|
15
|
+
export const redirect = (redirectMode = "follow") => (init) => {
|
|
16
|
+
init.redirect = redirectMode;
|
|
17
|
+
return init;
|
|
18
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** referrer(string): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* A string specifying the value to use for the request's Referer header. One of the following:
|
|
6
|
+
* - A same-origin relative or absolute URL
|
|
7
|
+
* - An empty string, which indicates that no Referer header should be sent
|
|
8
|
+
* - "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).
|
|
9
|
+
*
|
|
10
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#referrer
|
|
11
|
+
*
|
|
12
|
+
* @param referrerMode
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export declare const referrer: (referrerMode?: BringInit["referrer"]) => BringInitDecorator;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** referrer(string): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* A string specifying the value to use for the request's Referer header. One of the following:
|
|
4
|
+
* - A same-origin relative or absolute URL
|
|
5
|
+
* - An empty string, which indicates that no Referer header should be sent
|
|
6
|
+
* - "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).
|
|
7
|
+
*
|
|
8
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#referrer
|
|
9
|
+
*
|
|
10
|
+
* @param referrerMode
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export const referrer = (referrerMode = "about:client") => (init) => {
|
|
14
|
+
init.referrer = referrerMode;
|
|
15
|
+
return init;
|
|
16
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** referrerPolicy(string): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* A string specifying the value of the referrer-policy header to use for the request.
|
|
6
|
+
*
|
|
7
|
+
* Possible values are:
|
|
8
|
+
* - "no-referrer" The Referer header will not be sent.
|
|
9
|
+
* - "no-referrer-when-downgrade" Send the origin, path, and query string in Referer when the protocol security level stays the same or improves
|
|
10
|
+
* - "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/.
|
|
11
|
+
* - "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).
|
|
12
|
+
* - "same-origin" Send the origin, path, and query string for same-origin requests. Don't send the Referer header for cross-origin requests.
|
|
13
|
+
* - "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).
|
|
14
|
+
* - "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).
|
|
15
|
+
* - "unsafe-url" Send the origin, path, and query string when performing any request, regardless of security.
|
|
16
|
+
*
|
|
17
|
+
* Default is "strict-origin-when-cross-origin"
|
|
18
|
+
*
|
|
19
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#referrerpolicy
|
|
20
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Referrer-Policy
|
|
21
|
+
*
|
|
22
|
+
* @param referrerPolicyMode
|
|
23
|
+
* @returns BringInitDecorator
|
|
24
|
+
*/
|
|
25
|
+
export declare const referrerPolicy: (referrerPolicyMode?: BringInit["referrerPolicy"]) => BringInitDecorator;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/** referrerPolicy(string): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* A string specifying the value of the referrer-policy header to use for the request.
|
|
4
|
+
*
|
|
5
|
+
* Possible values are:
|
|
6
|
+
* - "no-referrer" The Referer header will not be sent.
|
|
7
|
+
* - "no-referrer-when-downgrade" Send the origin, path, and query string in Referer when the protocol security level stays the same or improves
|
|
8
|
+
* - "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/.
|
|
9
|
+
* - "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).
|
|
10
|
+
* - "same-origin" Send the origin, path, and query string for same-origin requests. Don't send the Referer header for cross-origin requests.
|
|
11
|
+
* - "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).
|
|
12
|
+
* - "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).
|
|
13
|
+
* - "unsafe-url" Send the origin, path, and query string when performing any request, regardless of security.
|
|
14
|
+
*
|
|
15
|
+
* Default is "strict-origin-when-cross-origin"
|
|
16
|
+
*
|
|
17
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/RequestInit#referrerpolicy
|
|
18
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Referrer-Policy
|
|
19
|
+
*
|
|
20
|
+
* @param referrerPolicyMode
|
|
21
|
+
* @returns BringInitDecorator
|
|
22
|
+
*/
|
|
23
|
+
export const referrerPolicy = (referrerPolicyMode = "strict-origin-when-cross-origin") => (init) => {
|
|
24
|
+
init.referrerPolicy = referrerPolicyMode;
|
|
25
|
+
return init;
|
|
26
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** retry(number): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* Sets the number of times to retry the request.
|
|
6
|
+
*
|
|
7
|
+
* @param retry The number of times to retry the request.
|
|
8
|
+
* @returns BringInitDecorator
|
|
9
|
+
*/
|
|
10
|
+
export declare const retry: (retry: BringInit["retry"]) => BringInitDecorator;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BringInitDecorator } from "../types/BringDecorator";
|
|
2
|
+
import { BringInit } from "../types/BringInit";
|
|
3
|
+
/** shouldRetry((response: Response, retryNum: number) => boolean)): BringInitDecorator
|
|
4
|
+
*
|
|
5
|
+
* @param shouldRetry ((response: Response, retryNum: number) => boolean)
|
|
6
|
+
* @returns BringInitDecorator
|
|
7
|
+
*/
|
|
8
|
+
export declare const shouldRetry: (shouldRetry: BringInit["shouldRetry"]) => BringInitDecorator;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** shouldRetry((response: Response, retryNum: number) => boolean)): BringInitDecorator
|
|
2
|
+
*
|
|
3
|
+
* @param shouldRetry ((response: Response, retryNum: number) => boolean)
|
|
4
|
+
* @returns BringInitDecorator
|
|
5
|
+
*/
|
|
6
|
+
export const shouldRetry = (shouldRetry) => (init) => ({ ...init, shouldRetry });
|