create-request 1.6.0 → 1.6.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/dist/library/BaseRequest.d.ts +27 -27
- package/dist/library/BodyRequest.d.ts +6 -7
- package/dist/library/RequestError.d.ts +11 -1
- package/dist/library/ResponseWrapper.d.ts +19 -8
- package/dist/library/enums.d.ts +67 -58
- package/dist/library/index.cjs +429 -595
- package/dist/library/index.cjs.map +1 -1
- package/dist/library/index.esm.js +421 -595
- package/dist/library/index.esm.js.map +1 -1
- package/dist/library/index.esm.min.js +1 -1
- package/dist/library/index.esm.min.js.map +1 -1
- package/dist/library/index.min.cjs +1 -1
- package/dist/library/index.min.cjs.map +1 -1
- package/dist/library/requestMethods.d.ts +7 -14
- package/dist/library/utils/Config.d.ts +11 -11
- package/package.json +1 -1
|
@@ -6,28 +6,28 @@ import { ResponseWrapper } from "./ResponseWrapper.js";
|
|
|
6
6
|
* Provides the core request building and execution capabilities.
|
|
7
7
|
*/
|
|
8
8
|
export declare abstract class BaseRequest {
|
|
9
|
-
protected abstract
|
|
10
|
-
protected
|
|
11
|
-
protected
|
|
12
|
-
protected
|
|
13
|
-
protected
|
|
14
|
-
protected
|
|
15
|
-
protected
|
|
16
|
-
private
|
|
17
|
-
private
|
|
18
|
-
private
|
|
9
|
+
protected abstract _method: HttpMethod;
|
|
10
|
+
protected _url: string;
|
|
11
|
+
protected _opts: RequestOptions;
|
|
12
|
+
protected _ctrl?: AbortController;
|
|
13
|
+
protected _fetch?: FetchFunction;
|
|
14
|
+
protected _query: URLSearchParams;
|
|
15
|
+
protected _autoCsrf: boolean;
|
|
16
|
+
private _reqI;
|
|
17
|
+
private _resI;
|
|
18
|
+
private _errI;
|
|
19
19
|
constructor(url: string);
|
|
20
20
|
/**
|
|
21
21
|
* Get GraphQL options if set (only for BodyRequest subclasses)
|
|
22
22
|
* @returns GraphQL options or undefined
|
|
23
23
|
*/
|
|
24
|
-
protected
|
|
24
|
+
protected _gql(): GraphQLOptions | undefined;
|
|
25
25
|
/**
|
|
26
26
|
* Creates a fluent API for setting enum-based options
|
|
27
27
|
* Combines direct setter with convenience methods
|
|
28
28
|
*/
|
|
29
|
-
private
|
|
30
|
-
private
|
|
29
|
+
private _fluent;
|
|
30
|
+
private _validateUrl;
|
|
31
31
|
/**
|
|
32
32
|
* Add multiple HTTP headers to the request
|
|
33
33
|
*
|
|
@@ -538,7 +538,7 @@ export declare abstract class BaseRequest {
|
|
|
538
538
|
* Cross-environment base64 encoding
|
|
539
539
|
* Works in both browser and Node.js environments
|
|
540
540
|
*/
|
|
541
|
-
private
|
|
541
|
+
private _b64;
|
|
542
542
|
/**
|
|
543
543
|
* Sets a Bearer token for authentication.
|
|
544
544
|
* Shorthand for `withAuthorization('Bearer ' + token)`.
|
|
@@ -557,13 +557,13 @@ export declare abstract class BaseRequest {
|
|
|
557
557
|
* Safely get headers as a Record<string, string>
|
|
558
558
|
* @returns The headers object
|
|
559
559
|
*/
|
|
560
|
-
private
|
|
560
|
+
private _headers;
|
|
561
561
|
/**
|
|
562
562
|
* Helper function to check for header presence in a case-insensitive way
|
|
563
563
|
* @param headerName Header name to check
|
|
564
564
|
* @returns Boolean indicating if the header exists (case-insensitive)
|
|
565
565
|
*/
|
|
566
|
-
private
|
|
566
|
+
private _hasHeader;
|
|
567
567
|
/**
|
|
568
568
|
* Sets cookies for the request.
|
|
569
569
|
* Cookies are sent in the Cookie header. Multiple calls will merge cookies.
|
|
@@ -815,13 +815,13 @@ export declare abstract class BaseRequest {
|
|
|
815
815
|
/**
|
|
816
816
|
* Apply CSRF protection headers based on configuration
|
|
817
817
|
*/
|
|
818
|
-
private
|
|
818
|
+
private _applyCsrf;
|
|
819
819
|
/**
|
|
820
820
|
* Formats the URL with any query parameters
|
|
821
821
|
* @param url The base URL
|
|
822
822
|
* @returns The URL with query parameters appended
|
|
823
823
|
*/
|
|
824
|
-
private
|
|
824
|
+
private _fullUrl;
|
|
825
825
|
/**
|
|
826
826
|
* Executes a request with configured retry logic
|
|
827
827
|
* @param url The formatted URL to send the request to
|
|
@@ -829,42 +829,42 @@ export declare abstract class BaseRequest {
|
|
|
829
829
|
* @returns A wrapped response object
|
|
830
830
|
* @throws RequestError if the request fails after all retries
|
|
831
831
|
*/
|
|
832
|
-
private
|
|
832
|
+
private _retry;
|
|
833
833
|
/**
|
|
834
834
|
* Run request interceptors in order: global interceptors first, then per-request
|
|
835
835
|
* @param configParam - The request configuration
|
|
836
836
|
* @returns Modified config or a Response to short-circuit
|
|
837
837
|
*/
|
|
838
|
-
private
|
|
838
|
+
private _runReqI;
|
|
839
839
|
/**
|
|
840
840
|
* Run response interceptors in reverse order: per-request interceptors first, then global in reverse
|
|
841
841
|
* @param response - The response wrapper
|
|
842
842
|
* @returns Modified response wrapper
|
|
843
843
|
*/
|
|
844
|
-
private
|
|
844
|
+
private _runResI;
|
|
845
845
|
/**
|
|
846
846
|
* Run error interceptors in reverse order: per-request interceptors first, then global in reverse
|
|
847
847
|
* @param error - The error that occurred
|
|
848
848
|
* @returns Modified error or a ResponseWrapper to recover
|
|
849
849
|
*/
|
|
850
|
-
private
|
|
850
|
+
private _runErrI;
|
|
851
851
|
/**
|
|
852
852
|
* Helper to create an abort signal with timeout support
|
|
853
853
|
* Handles various AbortSignal API levels gracefully
|
|
854
854
|
*/
|
|
855
|
-
private
|
|
855
|
+
private _signal;
|
|
856
856
|
/**
|
|
857
857
|
* Manually combine two abort signals for older environments
|
|
858
858
|
* Returns the first signal and listens to the second
|
|
859
859
|
*/
|
|
860
|
-
private
|
|
860
|
+
private _combine;
|
|
861
861
|
/**
|
|
862
862
|
* Convert fetchOptions to RequestConfig with proper typing
|
|
863
863
|
*/
|
|
864
|
-
private
|
|
864
|
+
private _config;
|
|
865
865
|
/**
|
|
866
866
|
* Apply interceptor results back to fetchOptions
|
|
867
867
|
*/
|
|
868
|
-
private
|
|
869
|
-
private
|
|
868
|
+
private _applyConfig;
|
|
869
|
+
private _run;
|
|
870
870
|
}
|
|
@@ -5,10 +5,9 @@ import type { ResponseWrapper } from "./ResponseWrapper.js";
|
|
|
5
5
|
* Base class for requests that can have a body (POST, PUT, PATCH)
|
|
6
6
|
*/
|
|
7
7
|
export declare abstract class BodyRequest extends BaseRequest {
|
|
8
|
-
protected
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
constructor(url: string);
|
|
8
|
+
protected _body?: Body;
|
|
9
|
+
private _bodyType?;
|
|
10
|
+
private _gqlOpts;
|
|
12
11
|
/**
|
|
13
12
|
* Sets the request body. Automatically detects the body type and sets appropriate Content-Type header.
|
|
14
13
|
* Supports JSON objects/arrays, strings, FormData, Blob, ArrayBuffer, URLSearchParams, and ReadableStream.
|
|
@@ -86,13 +85,13 @@ export declare abstract class BodyRequest extends BaseRequest {
|
|
|
86
85
|
/**
|
|
87
86
|
* Check if Content-Type header is already set (case-insensitive)
|
|
88
87
|
*/
|
|
89
|
-
private
|
|
90
|
-
private
|
|
88
|
+
private _hasCT;
|
|
89
|
+
private _setCT;
|
|
91
90
|
/**
|
|
92
91
|
* Get the GraphQL options if set
|
|
93
92
|
* @returns The GraphQL options or undefined
|
|
94
93
|
*/
|
|
95
|
-
protected
|
|
94
|
+
protected _gql(): GraphQLOptions | undefined;
|
|
96
95
|
/**
|
|
97
96
|
* Execute the request and return the ResponseWrapper
|
|
98
97
|
* Overrides the base implementation to add body handling
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract a message from an unknown thrown value
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export declare const errorMessage: (e: unknown) => string;
|
|
6
|
+
/**
|
|
7
|
+
* Coerce an unknown thrown value to an Error
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const toError: (e: unknown) => Error;
|
|
1
11
|
/**
|
|
2
12
|
* Error class for HTTP request failures.
|
|
3
13
|
* Extends the standard Error class with additional context about the failed request.
|
|
@@ -38,7 +48,7 @@ export declare class RequestError extends Error {
|
|
|
38
48
|
/** Whether the request was aborted (cancelled) */
|
|
39
49
|
readonly isAborted: boolean;
|
|
40
50
|
/** Cached result of parsing `body` as JSON (lazily populated by getJson) */
|
|
41
|
-
private
|
|
51
|
+
private _parsed?;
|
|
42
52
|
/**
|
|
43
53
|
* Creates a new RequestError instance.
|
|
44
54
|
*
|
|
@@ -18,12 +18,12 @@ export declare class ResponseWrapper {
|
|
|
18
18
|
readonly url?: string;
|
|
19
19
|
/** The HTTP method that was used (if available) */
|
|
20
20
|
readonly method?: string;
|
|
21
|
-
private readonly
|
|
22
|
-
private
|
|
23
|
-
private
|
|
24
|
-
private
|
|
25
|
-
private
|
|
26
|
-
private
|
|
21
|
+
private readonly _res;
|
|
22
|
+
private _gqlOpts?;
|
|
23
|
+
private _blob?;
|
|
24
|
+
private _text?;
|
|
25
|
+
private _json?;
|
|
26
|
+
private _buf?;
|
|
27
27
|
constructor(response: Response, url?: string, method?: string, graphQLOptions?: GraphQLOptions);
|
|
28
28
|
/**
|
|
29
29
|
* HTTP status code (e.g., 200, 404, 500)
|
|
@@ -46,17 +46,28 @@ export declare class ResponseWrapper {
|
|
|
46
46
|
* Use this if you need direct access to the underlying Response.
|
|
47
47
|
*/
|
|
48
48
|
get raw(): Response;
|
|
49
|
+
/**
|
|
50
|
+
* Create a RequestError carrying this response's context
|
|
51
|
+
* @param message - The error message
|
|
52
|
+
* @param withBody - Whether to attach the cached body text to the error
|
|
53
|
+
*/
|
|
54
|
+
private _err;
|
|
55
|
+
/**
|
|
56
|
+
* Read the response body via the given reader, wrapping failures in a RequestError
|
|
57
|
+
* @throws RequestError if the body has already been consumed or reading fails
|
|
58
|
+
*/
|
|
59
|
+
private _read;
|
|
49
60
|
/**
|
|
50
61
|
* Check if the response body has already been consumed and throw an error if so
|
|
51
62
|
* @throws RequestError if the body has already been consumed
|
|
52
63
|
*/
|
|
53
|
-
private
|
|
64
|
+
private _checkUsed;
|
|
54
65
|
/**
|
|
55
66
|
* Check for GraphQL errors and throw if throwOnError is enabled
|
|
56
67
|
* @param data - The parsed JSON data
|
|
57
68
|
* @throws RequestError if GraphQL response contains errors and throwOnError is enabled
|
|
58
69
|
*/
|
|
59
|
-
private
|
|
70
|
+
private _checkGql;
|
|
60
71
|
/**
|
|
61
72
|
* Parse the response body as JSON
|
|
62
73
|
* If GraphQL options are set with throwOnError=true, will check for GraphQL errors and throw.
|
package/dist/library/enums.d.ts
CHANGED
|
@@ -1,85 +1,94 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Enum for HTTP methods
|
|
3
3
|
*/
|
|
4
|
-
export declare
|
|
5
|
-
GET
|
|
6
|
-
PUT
|
|
7
|
-
POST
|
|
8
|
-
HEAD
|
|
9
|
-
PATCH
|
|
10
|
-
DELETE
|
|
11
|
-
OPTIONS
|
|
12
|
-
}
|
|
4
|
+
export declare const HttpMethod: {
|
|
5
|
+
readonly GET: "GET";
|
|
6
|
+
readonly PUT: "PUT";
|
|
7
|
+
readonly POST: "POST";
|
|
8
|
+
readonly HEAD: "HEAD";
|
|
9
|
+
readonly PATCH: "PATCH";
|
|
10
|
+
readonly DELETE: "DELETE";
|
|
11
|
+
readonly OPTIONS: "OPTIONS";
|
|
12
|
+
};
|
|
13
|
+
export type HttpMethod = (typeof HttpMethod)[keyof typeof HttpMethod];
|
|
13
14
|
/**
|
|
14
15
|
* Enum for request priorities
|
|
15
16
|
*/
|
|
16
|
-
export declare
|
|
17
|
-
LOW
|
|
18
|
-
HIGH
|
|
19
|
-
AUTO
|
|
20
|
-
}
|
|
17
|
+
export declare const RequestPriority: {
|
|
18
|
+
readonly LOW: "low";
|
|
19
|
+
readonly HIGH: "high";
|
|
20
|
+
readonly AUTO: "auto";
|
|
21
|
+
};
|
|
22
|
+
export type RequestPriority = (typeof RequestPriority)[keyof typeof RequestPriority];
|
|
21
23
|
/**
|
|
22
24
|
* Enum for credentials policies
|
|
23
25
|
*/
|
|
24
|
-
export declare
|
|
25
|
-
OMIT
|
|
26
|
-
INCLUDE
|
|
27
|
-
SAME_ORIGIN
|
|
28
|
-
}
|
|
26
|
+
export declare const CredentialsPolicy: {
|
|
27
|
+
readonly OMIT: "omit";
|
|
28
|
+
readonly INCLUDE: "include";
|
|
29
|
+
readonly SAME_ORIGIN: "same-origin";
|
|
30
|
+
};
|
|
31
|
+
export type CredentialsPolicy = (typeof CredentialsPolicy)[keyof typeof CredentialsPolicy];
|
|
29
32
|
/**
|
|
30
33
|
* Enum for request modes
|
|
31
34
|
*/
|
|
32
|
-
export declare
|
|
33
|
-
CORS
|
|
34
|
-
NO_CORS
|
|
35
|
-
SAME_ORIGIN
|
|
36
|
-
NAVIGATE
|
|
37
|
-
}
|
|
35
|
+
export declare const RequestMode: {
|
|
36
|
+
readonly CORS: "cors";
|
|
37
|
+
readonly NO_CORS: "no-cors";
|
|
38
|
+
readonly SAME_ORIGIN: "same-origin";
|
|
39
|
+
readonly NAVIGATE: "navigate";
|
|
40
|
+
};
|
|
41
|
+
export type RequestMode = (typeof RequestMode)[keyof typeof RequestMode];
|
|
38
42
|
/**
|
|
39
43
|
* Enum for redirect modes
|
|
40
44
|
*/
|
|
41
|
-
export declare
|
|
42
|
-
ERROR
|
|
43
|
-
FOLLOW
|
|
44
|
-
MANUAL
|
|
45
|
-
}
|
|
45
|
+
export declare const RedirectMode: {
|
|
46
|
+
readonly ERROR: "error";
|
|
47
|
+
readonly FOLLOW: "follow";
|
|
48
|
+
readonly MANUAL: "manual";
|
|
49
|
+
};
|
|
50
|
+
export type RedirectMode = (typeof RedirectMode)[keyof typeof RedirectMode];
|
|
46
51
|
/**
|
|
47
52
|
* Enum for cookie SameSite policies
|
|
48
53
|
*/
|
|
49
|
-
export declare
|
|
50
|
-
LAX
|
|
51
|
-
NONE
|
|
52
|
-
STRICT
|
|
53
|
-
}
|
|
54
|
+
export declare const SameSitePolicy: {
|
|
55
|
+
readonly LAX: "Lax";
|
|
56
|
+
readonly NONE: "None";
|
|
57
|
+
readonly STRICT: "Strict";
|
|
58
|
+
};
|
|
59
|
+
export type SameSitePolicy = (typeof SameSitePolicy)[keyof typeof SameSitePolicy];
|
|
54
60
|
/**
|
|
55
61
|
* Enum for body types
|
|
56
62
|
*/
|
|
57
|
-
export declare
|
|
58
|
-
JSON
|
|
59
|
-
STRING
|
|
60
|
-
BINARY
|
|
61
|
-
}
|
|
63
|
+
export declare const BodyType: {
|
|
64
|
+
readonly JSON: "json";
|
|
65
|
+
readonly STRING: "string";
|
|
66
|
+
readonly BINARY: "binary";
|
|
67
|
+
};
|
|
68
|
+
export type BodyType = (typeof BodyType)[keyof typeof BodyType];
|
|
62
69
|
/**
|
|
63
70
|
* Referrer policies for fetch requests
|
|
64
71
|
*/
|
|
65
|
-
export declare
|
|
66
|
-
ORIGIN
|
|
67
|
-
UNSAFE_URL
|
|
68
|
-
SAME_ORIGIN
|
|
69
|
-
NO_REFERRER
|
|
70
|
-
STRICT_ORIGIN
|
|
71
|
-
ORIGIN_WHEN_CROSS_ORIGIN
|
|
72
|
-
NO_REFERRER_WHEN_DOWNGRADE
|
|
73
|
-
STRICT_ORIGIN_WHEN_CROSS_ORIGIN
|
|
74
|
-
}
|
|
72
|
+
export declare const ReferrerPolicy: {
|
|
73
|
+
readonly ORIGIN: "origin";
|
|
74
|
+
readonly UNSAFE_URL: "unsafe-url";
|
|
75
|
+
readonly SAME_ORIGIN: "same-origin";
|
|
76
|
+
readonly NO_REFERRER: "no-referrer";
|
|
77
|
+
readonly STRICT_ORIGIN: "strict-origin";
|
|
78
|
+
readonly ORIGIN_WHEN_CROSS_ORIGIN: "origin-when-cross-origin";
|
|
79
|
+
readonly NO_REFERRER_WHEN_DOWNGRADE: "no-referrer-when-downgrade";
|
|
80
|
+
readonly STRICT_ORIGIN_WHEN_CROSS_ORIGIN: "strict-origin-when-cross-origin";
|
|
81
|
+
};
|
|
82
|
+
export type ReferrerPolicy = (typeof ReferrerPolicy)[keyof typeof ReferrerPolicy];
|
|
75
83
|
/**
|
|
76
84
|
* Cache modes for fetch requests
|
|
77
85
|
*/
|
|
78
|
-
export declare
|
|
79
|
-
RELOAD
|
|
80
|
-
DEFAULT
|
|
81
|
-
NO_CACHE
|
|
82
|
-
NO_STORE
|
|
83
|
-
FORCE_CACHE
|
|
84
|
-
ONLY_IF_CACHED
|
|
85
|
-
}
|
|
86
|
+
export declare const CacheMode: {
|
|
87
|
+
readonly RELOAD: "reload";
|
|
88
|
+
readonly DEFAULT: "default";
|
|
89
|
+
readonly NO_CACHE: "no-cache";
|
|
90
|
+
readonly NO_STORE: "no-store";
|
|
91
|
+
readonly FORCE_CACHE: "force-cache";
|
|
92
|
+
readonly ONLY_IF_CACHED: "only-if-cached";
|
|
93
|
+
};
|
|
94
|
+
export type CacheMode = (typeof CacheMode)[keyof typeof CacheMode];
|