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.
@@ -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 method: HttpMethod;
10
- protected url: string;
11
- protected requestOptions: RequestOptions;
12
- protected abortController?: AbortController;
13
- protected customFetch?: FetchFunction;
14
- protected queryParams: URLSearchParams;
15
- protected autoApplyCsrfProtection: boolean;
16
- private requestInterceptors;
17
- private responseInterceptors;
18
- private errorInterceptors;
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 getGraphQLOptions(): GraphQLOptions | undefined;
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 createFluentSetter;
30
- private validateUrl;
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 encodeBase64;
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 getHeadersRecord;
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 hasHeader;
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 applyCsrfProtection;
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 formatUrlWithQueryParams;
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 executeWithRetries;
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 runRequestInterceptors;
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 runResponseInterceptors;
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 runErrorInterceptors;
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 createAbortSignal;
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 combineSignalsManually;
860
+ private _combine;
861
861
  /**
862
862
  * Convert fetchOptions to RequestConfig with proper typing
863
863
  */
864
- private createRequestConfig;
864
+ private _config;
865
865
  /**
866
866
  * Apply interceptor results back to fetchOptions
867
867
  */
868
- private applyRequestConfig;
869
- private executeRequest;
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 body?: Body;
9
- private bodyType?;
10
- private graphQLOptions;
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 hasContentType;
90
- private setContentTypeIfNeeded;
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 getGraphQLOptions(): GraphQLOptions | undefined;
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 parsedBody?;
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 response;
22
- private graphQLOptions?;
23
- private cachedBlob?;
24
- private cachedText?;
25
- private cachedJson?;
26
- private cachedArrayBuffer?;
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 checkBodyNotConsumed;
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 checkGraphQLErrors;
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.
@@ -1,85 +1,94 @@
1
1
  /**
2
2
  * Enum for HTTP methods
3
3
  */
4
- export declare enum HttpMethod {
5
- GET = "GET",
6
- PUT = "PUT",
7
- POST = "POST",
8
- HEAD = "HEAD",
9
- PATCH = "PATCH",
10
- DELETE = "DELETE",
11
- OPTIONS = "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 enum RequestPriority {
17
- LOW = "low",
18
- HIGH = "high",
19
- AUTO = "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 enum CredentialsPolicy {
25
- OMIT = "omit",
26
- INCLUDE = "include",
27
- SAME_ORIGIN = "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 enum RequestMode {
33
- CORS = "cors",
34
- NO_CORS = "no-cors",
35
- SAME_ORIGIN = "same-origin",
36
- NAVIGATE = "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 enum RedirectMode {
42
- ERROR = "error",
43
- FOLLOW = "follow",
44
- MANUAL = "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 enum SameSitePolicy {
50
- LAX = "Lax",
51
- NONE = "None",
52
- STRICT = "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 enum BodyType {
58
- JSON = "json",
59
- STRING = "string",
60
- BINARY = "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 enum ReferrerPolicy {
66
- ORIGIN = "origin",
67
- UNSAFE_URL = "unsafe-url",
68
- SAME_ORIGIN = "same-origin",
69
- NO_REFERRER = "no-referrer",
70
- STRICT_ORIGIN = "strict-origin",
71
- ORIGIN_WHEN_CROSS_ORIGIN = "origin-when-cross-origin",
72
- NO_REFERRER_WHEN_DOWNGRADE = "no-referrer-when-downgrade",
73
- STRICT_ORIGIN_WHEN_CROSS_ORIGIN = "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 enum CacheMode {
79
- RELOAD = "reload",
80
- DEFAULT = "default",
81
- NO_CACHE = "no-cache",
82
- NO_STORE = "no-store",
83
- FORCE_CACHE = "force-cache",
84
- ONLY_IF_CACHED = "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];