@gcmdev/faxios 0.2.0 → 0.2.2

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 (186) hide show
  1. package/LICENSE +8 -0
  2. package/dist/index.d.ts +4 -3
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/adapters/fetch-helpers.d.ts +2 -1
  7. package/dist/lib/adapters/fetch-helpers.d.ts.map +1 -0
  8. package/dist/lib/adapters/fetch.d.ts +1 -0
  9. package/dist/lib/adapters/fetch.d.ts.map +1 -0
  10. package/dist/lib/adapters/fetch.js +86 -26
  11. package/dist/lib/adapters/fetch.js.map +1 -1
  12. package/dist/lib/cancel/CanceledError.d.ts +2 -1
  13. package/dist/lib/cancel/CanceledError.d.ts.map +1 -0
  14. package/dist/lib/cancel/isCancel.d.ts +1 -0
  15. package/dist/lib/cancel/isCancel.d.ts.map +1 -0
  16. package/dist/lib/core/Faxios.d.ts +4 -3
  17. package/dist/lib/core/Faxios.d.ts.map +1 -0
  18. package/dist/lib/core/Faxios.js +8 -4
  19. package/dist/lib/core/Faxios.js.map +1 -1
  20. package/dist/lib/core/FaxiosError.d.ts +3 -2
  21. package/dist/lib/core/FaxiosError.d.ts.map +1 -0
  22. package/dist/lib/core/FaxiosHeaders.d.ts +9 -8
  23. package/dist/lib/core/FaxiosHeaders.d.ts.map +1 -0
  24. package/dist/lib/core/buildFullPath.d.ts +1 -0
  25. package/dist/lib/core/buildFullPath.d.ts.map +1 -0
  26. package/dist/lib/core/define.d.ts +20 -3
  27. package/dist/lib/core/define.d.ts.map +1 -0
  28. package/dist/lib/core/define.js.map +1 -1
  29. package/dist/lib/core/dispatchRequest.d.ts +2 -1
  30. package/dist/lib/core/dispatchRequest.d.ts.map +1 -0
  31. package/dist/lib/core/mergeConfig.d.ts +3 -2
  32. package/dist/lib/core/mergeConfig.d.ts.map +1 -0
  33. package/dist/lib/core/mergeConfig.js +40 -2
  34. package/dist/lib/core/mergeConfig.js.map +1 -1
  35. package/dist/lib/core/prepareRequest.d.ts +1 -0
  36. package/dist/lib/core/prepareRequest.d.ts.map +1 -0
  37. package/dist/lib/core/route.d.ts +10 -1
  38. package/dist/lib/core/route.d.ts.map +1 -0
  39. package/dist/lib/core/route.js +2 -5
  40. package/dist/lib/core/route.js.map +1 -1
  41. package/dist/lib/core/settle.d.ts +1 -0
  42. package/dist/lib/core/settle.d.ts.map +1 -0
  43. package/dist/lib/core/transformData.d.ts +3 -2
  44. package/dist/lib/core/transformData.d.ts.map +1 -0
  45. package/dist/lib/core/validateSchema.d.ts +3 -2
  46. package/dist/lib/core/validateSchema.d.ts.map +1 -0
  47. package/dist/lib/defaults/index.d.ts +1 -0
  48. package/dist/lib/defaults/index.d.ts.map +1 -0
  49. package/dist/lib/defaults/transitional.d.ts +1 -0
  50. package/dist/lib/defaults/transitional.d.ts.map +1 -0
  51. package/dist/lib/env/data.d.ts +2 -1
  52. package/dist/lib/env/data.d.ts.map +1 -0
  53. package/dist/lib/env/data.js +1 -1
  54. package/dist/lib/faxios.d.ts +59 -38
  55. package/dist/lib/faxios.d.ts.map +1 -0
  56. package/dist/lib/faxios.js.map +1 -1
  57. package/dist/lib/helpers/FaxiosURLSearchParams.d.ts +1 -0
  58. package/dist/lib/helpers/FaxiosURLSearchParams.d.ts.map +1 -0
  59. package/dist/lib/helpers/HttpStatusCode.d.ts +1 -0
  60. package/dist/lib/helpers/HttpStatusCode.d.ts.map +1 -0
  61. package/dist/lib/helpers/buildURL.d.ts +1 -0
  62. package/dist/lib/helpers/buildURL.d.ts.map +1 -0
  63. package/dist/lib/helpers/cloneConfig.d.ts +1 -1
  64. package/dist/lib/helpers/cloneConfig.d.ts.map +1 -0
  65. package/dist/lib/helpers/cloneConfig.js +2 -2
  66. package/dist/lib/helpers/cloneConfig.js.map +1 -1
  67. package/dist/lib/helpers/combineURLs.d.ts +1 -0
  68. package/dist/lib/helpers/combineURLs.d.ts.map +1 -0
  69. package/dist/lib/helpers/composeSignals.d.ts +1 -0
  70. package/dist/lib/helpers/composeSignals.d.ts.map +1 -0
  71. package/dist/lib/helpers/cookies.d.ts +2 -1
  72. package/dist/lib/helpers/cookies.d.ts.map +1 -0
  73. package/dist/lib/helpers/estimateDataURLDecodedBytes.d.ts +1 -0
  74. package/dist/lib/helpers/estimateDataURLDecodedBytes.d.ts.map +1 -0
  75. package/dist/lib/helpers/formDataToJSON.d.ts +2 -1
  76. package/dist/lib/helpers/formDataToJSON.d.ts.map +1 -0
  77. package/dist/lib/helpers/formDataToJSON.js +1 -1
  78. package/dist/lib/helpers/formDataToJSON.js.map +1 -1
  79. package/dist/lib/helpers/isAbsoluteURL.d.ts +1 -0
  80. package/dist/lib/helpers/isAbsoluteURL.d.ts.map +1 -0
  81. package/dist/lib/helpers/isFaxiosError.d.ts +1 -0
  82. package/dist/lib/helpers/isFaxiosError.d.ts.map +1 -0
  83. package/dist/lib/helpers/isURLSameOrigin.d.ts +1 -0
  84. package/dist/lib/helpers/isURLSameOrigin.d.ts.map +1 -0
  85. package/dist/lib/helpers/parseHeaders.d.ts +2 -1
  86. package/dist/lib/helpers/parseHeaders.d.ts.map +1 -0
  87. package/dist/lib/helpers/progressEventReducer.d.ts +1 -0
  88. package/dist/lib/helpers/progressEventReducer.d.ts.map +1 -0
  89. package/dist/lib/helpers/sanitizeHeaderValue.d.ts +1 -0
  90. package/dist/lib/helpers/sanitizeHeaderValue.d.ts.map +1 -0
  91. package/dist/lib/helpers/speedometer.d.ts +1 -0
  92. package/dist/lib/helpers/speedometer.d.ts.map +1 -0
  93. package/dist/lib/helpers/substitutePathParams.d.ts +1 -0
  94. package/dist/lib/helpers/substitutePathParams.d.ts.map +1 -0
  95. package/dist/lib/helpers/substitutePathParams.js +11 -3
  96. package/dist/lib/helpers/substitutePathParams.js.map +1 -1
  97. package/dist/lib/helpers/throttle.d.ts +1 -0
  98. package/dist/lib/helpers/throttle.d.ts.map +1 -0
  99. package/dist/lib/helpers/toFormData.d.ts +1 -0
  100. package/dist/lib/helpers/toFormData.d.ts.map +1 -0
  101. package/dist/lib/helpers/toFormData.js +4 -2
  102. package/dist/lib/helpers/toFormData.js.map +1 -1
  103. package/dist/lib/helpers/toURLEncodedForm.d.ts +1 -0
  104. package/dist/lib/helpers/toURLEncodedForm.d.ts.map +1 -0
  105. package/dist/lib/helpers/trackStream.d.ts +1 -0
  106. package/dist/lib/helpers/trackStream.d.ts.map +1 -0
  107. package/dist/lib/helpers/validator.d.ts +2 -1
  108. package/dist/lib/helpers/validator.d.ts.map +1 -0
  109. package/dist/lib/platform.d.ts +1 -0
  110. package/dist/lib/platform.d.ts.map +1 -0
  111. package/dist/lib/plugins/attempt.d.ts +1 -0
  112. package/dist/lib/plugins/attempt.d.ts.map +1 -0
  113. package/dist/lib/plugins/authBearer.d.ts +10 -5
  114. package/dist/lib/plugins/authBearer.d.ts.map +1 -0
  115. package/dist/lib/plugins/authBearer.js +6 -0
  116. package/dist/lib/plugins/authBearer.js.map +1 -1
  117. package/dist/lib/plugins/definePlugin.d.ts +4 -3
  118. package/dist/lib/plugins/definePlugin.d.ts.map +1 -0
  119. package/dist/lib/plugins/retry.d.ts +24 -23
  120. package/dist/lib/plugins/retry.d.ts.map +1 -0
  121. package/dist/lib/plugins/timing.d.ts +9 -8
  122. package/dist/lib/plugins/timing.d.ts.map +1 -0
  123. package/dist/lib/types/standard-schema.d.ts +7 -6
  124. package/dist/lib/types/standard-schema.d.ts.map +1 -0
  125. package/dist/lib/types.d.ts +104 -92
  126. package/dist/lib/types.d.ts.map +1 -0
  127. package/dist/lib/utils.d.ts +5 -3
  128. package/dist/lib/utils.d.ts.map +1 -0
  129. package/dist/lib/utils.js +9 -2
  130. package/dist/lib/utils.js.map +1 -1
  131. package/package.json +8 -4
  132. package/skills/configure-requests/SKILL.md +53 -8
  133. package/skills/configure-requests/references/plugins.md +54 -6
  134. package/src/index.ts +57 -0
  135. package/src/lib/adapters/fetch-helpers.ts +167 -0
  136. package/src/lib/adapters/fetch.ts +871 -0
  137. package/src/lib/cancel/CanceledError.ts +23 -0
  138. package/src/lib/cancel/isCancel.ts +10 -0
  139. package/src/lib/core/Faxios.ts +517 -0
  140. package/src/lib/core/FaxiosError.ts +283 -0
  141. package/src/lib/core/FaxiosHeaders.ts +529 -0
  142. package/src/lib/core/buildFullPath.ts +51 -0
  143. package/src/lib/core/define.ts +127 -0
  144. package/src/lib/core/dispatchRequest.ts +171 -0
  145. package/src/lib/core/mergeConfig.ts +213 -0
  146. package/src/lib/core/prepareRequest.ts +155 -0
  147. package/src/lib/core/route.ts +65 -0
  148. package/src/lib/core/settle.ts +20 -0
  149. package/src/lib/core/transformData.ts +23 -0
  150. package/src/lib/core/validateSchema.ts +53 -0
  151. package/src/lib/defaults/index.ts +221 -0
  152. package/src/lib/defaults/transitional.ts +9 -0
  153. package/src/lib/env/data.ts +1 -0
  154. package/src/lib/faxios.ts +306 -0
  155. package/src/lib/helpers/FaxiosURLSearchParams.ts +52 -0
  156. package/src/lib/helpers/HttpStatusCode.ts +77 -0
  157. package/src/lib/helpers/buildURL.ts +77 -0
  158. package/src/lib/helpers/cloneConfig.ts +22 -0
  159. package/src/lib/helpers/combineURLs.ts +11 -0
  160. package/src/lib/helpers/composeSignals.ts +74 -0
  161. package/src/lib/helpers/cookies.ts +68 -0
  162. package/src/lib/helpers/deprecatedMethod.ts +32 -0
  163. package/src/lib/helpers/estimateDataURLDecodedBytes.ts +95 -0
  164. package/src/lib/helpers/formDataToJSON.ts +122 -0
  165. package/src/lib/helpers/isAbsoluteURL.ts +13 -0
  166. package/src/lib/helpers/isFaxiosError.ts +19 -0
  167. package/src/lib/helpers/isURLSameOrigin.ts +16 -0
  168. package/src/lib/helpers/parseHeaders.ts +76 -0
  169. package/src/lib/helpers/progressEventReducer.ts +57 -0
  170. package/src/lib/helpers/sanitizeHeaderValue.ts +61 -0
  171. package/src/lib/helpers/speedometer.ts +55 -0
  172. package/src/lib/helpers/substitutePathParams.ts +23 -0
  173. package/src/lib/helpers/throttle.ts +45 -0
  174. package/src/lib/helpers/toFormData.ts +298 -0
  175. package/src/lib/helpers/toURLEncodedForm.ts +14 -0
  176. package/src/lib/helpers/trackStream.ts +123 -0
  177. package/src/lib/helpers/validator.ts +114 -0
  178. package/src/lib/platform.ts +44 -0
  179. package/src/lib/plugins/attempt.ts +3 -0
  180. package/src/lib/plugins/authBearer.ts +129 -0
  181. package/src/lib/plugins/definePlugin.ts +34 -0
  182. package/src/lib/plugins/retry.ts +245 -0
  183. package/src/lib/plugins/timing.ts +76 -0
  184. package/src/lib/types/standard-schema.ts +58 -0
  185. package/src/lib/types.ts +496 -0
  186. package/src/lib/utils.ts +941 -0
@@ -0,0 +1,496 @@
1
+ // @ts-self-types="./types.d.ts"
2
+ // Internal shared types — imported by implementation files.
3
+ // Public API types in index.d.ts re-export or extend these.
4
+
5
+ import type { FaxiosHeadersInstance } from "./core/FaxiosHeaders.js";
6
+ import type { StandardSchemaV1 } from "./types/standard-schema.js";
7
+
8
+ export type StringLiteralsOrString<Literals extends string> =
9
+ | Literals
10
+ | (string & {});
11
+
12
+ export type FaxiosHeaderValue =
13
+ | Array<string>
14
+ | boolean
15
+ | null
16
+ | number
17
+ | string;
18
+
19
+ export interface RawFaxiosHeaders {
20
+ [key: string]: FaxiosHeaderValue;
21
+ }
22
+
23
+ type UppercaseMethod =
24
+ | "DELETE"
25
+ | "GET"
26
+ | "HEAD"
27
+ | "LINK"
28
+ | "OPTIONS"
29
+ | "PATCH"
30
+ | "POST"
31
+ | "PURGE"
32
+ | "PUT"
33
+ | "QUERY"
34
+ | "UNLINK";
35
+
36
+ export type Method = Lowercase<UppercaseMethod> | UppercaseMethod;
37
+
38
+ type CommonRequestHeadersList =
39
+ | "Accept"
40
+ | "Accept-Encoding"
41
+ | "Accept-Language"
42
+ | "Authorization"
43
+ | "Cache-Control"
44
+ | "Content-Encoding"
45
+ | "Content-Length"
46
+ | "If-Match"
47
+ | "If-Modified-Since"
48
+ | "If-None-Match"
49
+ | "Range"
50
+ | "User-Agent"
51
+ | "X-Requested-With";
52
+
53
+ type ContentType =
54
+ | Exclude<FaxiosHeaderValue, string>
55
+ | StringLiteralsOrString<
56
+ | "application/graphql-response+json"
57
+ | "application/json"
58
+ | "application/json-patch+json"
59
+ | "application/ld+json"
60
+ | "application/merge-patch+json"
61
+ | "application/octet-stream"
62
+ | "application/problem+json"
63
+ | "application/x-www-form-urlencoded"
64
+ | "multipart/form-data"
65
+ | "text/event-stream"
66
+ | "text/html"
67
+ | "text/plain"
68
+ >;
69
+
70
+ /**
71
+ * A header bag: header names mapped to header values. Any header name is
72
+ * accepted in any casing; common names and `Content-Type` values are suggested.
73
+ *
74
+ * - Strings, numbers and string arrays are sent (numbers and `true` as strings).
75
+ * - `undefined` drops a value inherited from defaults or an outer config;
76
+ * faxios may still set its own value (e.g. `Content-Type` for a JSON body).
77
+ * - `null` or `false` keeps the header off the request entirely; faxios does
78
+ * not fill it in, and later merges keep it off unless they force an overwrite.
79
+ */
80
+ export type RawFaxiosRequestHeaders =
81
+ & { [header: string]: FaxiosHeaderValue | undefined; }
82
+ & { [Header in CommonRequestHeadersList]?: FaxiosHeaderValue; }
83
+ & { "Content-Type"?: ContentType; };
84
+
85
+ export type ResponseType =
86
+ | "arraybuffer"
87
+ | "blob"
88
+ | "document"
89
+ | "formdata"
90
+ | "json"
91
+ | "response"
92
+ | "stream"
93
+ | "text";
94
+
95
+ type UppercaseResponseEncoding =
96
+ | "ANSI"
97
+ | "ASCII"
98
+ | "BASE64"
99
+ | "BASE64URL"
100
+ | "BINARY"
101
+ | "HEX"
102
+ | "LATIN1"
103
+ | "UCS2"
104
+ | "UCS-2"
105
+ | "UTF8"
106
+ | "UTF16LE"
107
+ | "UTF-8";
108
+
109
+ export type responseEncoding =
110
+ | Lowercase<UppercaseResponseEncoding>
111
+ | UppercaseResponseEncoding;
112
+
113
+ export interface TransitionalOptions {
114
+ advertiseZstdAcceptEncoding?: boolean;
115
+ clarifyTimeoutError?: boolean;
116
+ forcedJSONParsing?: boolean;
117
+ silentJSONParsing?: boolean;
118
+ validateStatusUndefinedResolves?: boolean;
119
+ }
120
+
121
+ export interface GenericAbortSignal {
122
+ readonly aborted: boolean;
123
+ addEventListener?: (...args: Array<unknown>) => unknown;
124
+ onabort?: ((event: Event) => void) | null;
125
+ removeEventListener?: (...args: Array<unknown>) => unknown;
126
+ }
127
+
128
+ export interface GenericFormData {
129
+ append: (name: string, value: unknown, options?: unknown) => unknown;
130
+ }
131
+
132
+ export interface GenericHTMLFormElement {
133
+ method: string;
134
+ name: string;
135
+ submit: () => void;
136
+ }
137
+
138
+ export interface FormDataVisitorHelpers {
139
+ convertValue: (value: unknown) => unknown;
140
+ defaultVisitor: SerializerVisitor;
141
+ isVisitable: (value: unknown) => boolean;
142
+ }
143
+
144
+ export interface SerializerVisitor {
145
+ (
146
+ this: GenericFormData,
147
+ value: unknown,
148
+ key: number | string,
149
+ path: Array<number | string> | null,
150
+ helpers: FormDataVisitorHelpers,
151
+ ): boolean;
152
+ }
153
+
154
+ export interface SerializerOptions {
155
+ dots?: boolean;
156
+ indexes?: boolean | null;
157
+ /** Maximum nesting depth to serialize; deeper objects throw `ERR_FORM_DATA_DEPTH_EXCEEDED`. `Infinity` disables the check. */
158
+ maxDepth?: number;
159
+ metaTokens?: boolean;
160
+ visitor?: SerializerVisitor;
161
+ }
162
+
163
+ // tslint:disable-next-line
164
+ export type FormSerializerOptions = SerializerOptions;
165
+
166
+ export interface ParamEncoder {
167
+ (value: string, defaultEncoder: (value: string) => string): string;
168
+ }
169
+
170
+ export interface CustomParamsSerializer {
171
+ (params: Record<string, unknown>, options?: ParamsSerializerOptions): string;
172
+ }
173
+
174
+ export interface ParamsSerializerOptions extends SerializerOptions {
175
+ encode?: ParamEncoder;
176
+ serialize?: CustomParamsSerializer;
177
+ }
178
+
179
+ type BrowserProgressEvent = unknown;
180
+ type Milliseconds = number;
181
+
182
+ export interface FaxiosProgressEvent {
183
+ bytes: number;
184
+ download?: boolean;
185
+ estimated?: number;
186
+ event?: BrowserProgressEvent;
187
+ lengthComputable: boolean;
188
+ loaded: number;
189
+ progress?: number;
190
+ rate?: number;
191
+ total?: number;
192
+ upload?: boolean;
193
+ }
194
+
195
+ export interface FaxiosBasicCredentials {
196
+ password: string;
197
+ username: string;
198
+ }
199
+
200
+ // forward-declared; implemented in core/FaxiosHeaders.ts
201
+ // Using a structural type that matches FaxiosHeaders class methods
202
+ type HeaderMatcher =
203
+ | ((value: string, name: string) => boolean)
204
+ | RegExp
205
+ | string;
206
+
207
+ type HeaderGetResult = Array<string> | null | Record<string, string> | RegExpExecArray | string | true | undefined;
208
+
209
+ export type FaxiosRequestHeaders = Record<string, FaxiosHeaderValue> & {
210
+ clear: (matcher?: HeaderMatcher) => boolean;
211
+ concat: (...targets: Array<unknown>) => FaxiosRequestHeaders;
212
+ delete: (header: Array<string> | string, matcher?: HeaderMatcher) => boolean;
213
+ get: (header: string, parser?: boolean | RegExp) => HeaderGetResult;
214
+ getAccept: (matcher?: HeaderMatcher) => HeaderGetResult;
215
+ getAcceptEncoding: (matcher?: HeaderMatcher) => HeaderGetResult;
216
+ getAuthorization: (matcher?: HeaderMatcher) => HeaderGetResult;
217
+ getContentLength: (matcher?: HeaderMatcher) => HeaderGetResult;
218
+ getContentType: (matcher?: HeaderMatcher) => HeaderGetResult;
219
+ getUserAgent: (matcher?: HeaderMatcher) => HeaderGetResult;
220
+ has: (header: string, matcher?: HeaderMatcher) => boolean;
221
+ hasAccept: (matcher?: HeaderMatcher) => boolean;
222
+ hasAcceptEncoding: (matcher?: HeaderMatcher) => boolean;
223
+ hasAuthorization: (matcher?: HeaderMatcher) => boolean;
224
+ hasContentLength: (matcher?: HeaderMatcher) => boolean;
225
+ hasContentType: (matcher?: HeaderMatcher) => boolean;
226
+ hasUserAgent: (matcher?: HeaderMatcher) => boolean;
227
+ normalize: (format?: boolean) => FaxiosRequestHeaders;
228
+ set: (header: Record<string, unknown> | string, value?: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
229
+ setAccept: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
230
+ setAcceptEncoding: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
231
+ setAuthorization: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
232
+
233
+ setContentLength: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
234
+ setContentType: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
235
+ setUserAgent: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
236
+ toJSON: (asStrings?: boolean) => Record<string, FaxiosHeaderValue>;
237
+ };
238
+
239
+ export interface FaxiosRequestTransformer {
240
+ (
241
+ this: InternalFaxiosRequestConfig,
242
+ data: unknown,
243
+ headers: FaxiosRequestHeaders,
244
+ ): unknown;
245
+ }
246
+
247
+ export interface FaxiosResponseTransformer {
248
+ (
249
+ this: InternalFaxiosRequestConfig,
250
+ data: unknown,
251
+ headers: RawFaxiosHeaders,
252
+ status?: number,
253
+ ): unknown;
254
+ }
255
+
256
+ export interface FaxiosRequestConfig<D = unknown> {
257
+ allowAbsoluteUrls?: boolean;
258
+ auth?: FaxiosBasicCredentials;
259
+ baseURL?: string;
260
+ data?: D;
261
+ env?: {
262
+ fetch?: (
263
+ input: Request | string | URL,
264
+ init?: RequestInit
265
+ ) => Promise<Response>;
266
+ /** Constructed with no arguments to serialize `multipart/form-data` payloads; `null` falls back to the global `FormData`. */
267
+ FormData?: (new () => object) | null;
268
+ /** `null` disables the constructor, e.g. when a custom `fetch` is incompatible with the global one. */
269
+ Request?: (new (
270
+ input: Request | string | URL,
271
+ init?: RequestInit,
272
+ ) => unknown) | null;
273
+ Response?: (new (...args: Array<unknown>) => unknown) | null;
274
+ };
275
+ fetchOptions?: Record<string, unknown>;
276
+ formDataHeaderPolicy?: "content-only" | "legacy";
277
+ formSerializer?: FormSerializerOptions;
278
+ headers?: FaxiosConfigHeaders;
279
+ maxBodyLength?: number;
280
+ maxContentLength?: number;
281
+ method?: StringLiteralsOrString<Method>;
282
+ onDownloadProgress?: (progressEvent: FaxiosProgressEvent) => void;
283
+ onUploadProgress?: (progressEvent: FaxiosProgressEvent) => void;
284
+ params?: Record<string, unknown> | URLSearchParams;
285
+ paramsSchema?: StandardSchemaV1;
286
+ paramsSerializer?: CustomParamsSerializer | ParamsSerializerOptions;
287
+ parseReviver?: (
288
+ this: unknown,
289
+ key: string,
290
+ value: unknown,
291
+ context?: { source?: string; }
292
+ ) => unknown;
293
+ /**
294
+ * Values for `{key}` placeholders in `url` (braces, not `:key`). Only own properties count.
295
+ * Each value goes through `String()` then `encodeURIComponent`. A placeholder whose key is
296
+ * missing, or whose value is `null` or `undefined`, rejects with `ERR_BAD_OPTION_VALUE`. Keys
297
+ * with no matching placeholder are ignored. Without `pathParams`, placeholders are sent literally.
298
+ */
299
+ pathParams?: Record<string, unknown>;
300
+ /**
301
+ * Standard Schema that validates `pathParams` before substitution; its output replaces
302
+ * `pathParams`. Requires `pathParams`, or the request rejects with `ERR_BAD_OPTION_VALUE`.
303
+ * A validation failure, or output that isn't a plain object, rejects with `ERR_BAD_PATH_PARAMS_SCHEMA`.
304
+ */
305
+ pathParamsSchema?: StandardSchemaV1<unknown, Record<string, unknown>>;
306
+ redact?: Array<string>;
307
+ requestSchema?: StandardSchemaV1;
308
+ responseEncoding?: StringLiteralsOrString<responseEncoding>;
309
+ responseSchema?: StandardSchemaV1;
310
+ responseType?: ResponseType;
311
+ signal?: AbortSignal | GenericAbortSignal;
312
+ timeout?: Milliseconds;
313
+ timeoutErrorMessage?: string;
314
+ transformRequest?: Array<FaxiosRequestTransformer> | FaxiosRequestTransformer;
315
+ transformResponse?:
316
+ | Array<FaxiosResponseTransformer>
317
+ | FaxiosResponseTransformer;
318
+ transitional?: TransitionalOptions;
319
+ url?: string;
320
+ validateStatus?: ((status: number) => boolean) | null;
321
+ withCredentials?: boolean;
322
+ withXSRFToken?:
323
+ | ((config: InternalFaxiosRequestConfig) => boolean | undefined)
324
+ | boolean;
325
+ xsrfCookieName?: string;
326
+ xsrfHeaderName?: string;
327
+ }
328
+
329
+ export type SchemaConfig<O, D = unknown> = FaxiosRequestConfig<D> & { responseSchema: StandardSchemaV1<unknown, O>; };
330
+
331
+ export type RawFaxiosRequestConfig<D = unknown> = FaxiosRequestConfig<D>;
332
+
333
+ export interface InternalFaxiosRequestConfig<
334
+ D = unknown
335
+ > extends FaxiosRequestConfig<D> {
336
+ headers: FaxiosRequestHeaders;
337
+ }
338
+
339
+ // export type RawFaxiosResponseHeaders = Partial<
340
+ // RawFaxiosHeaders & {
341
+ // "set-cookie": Array<string>;
342
+ // "content-type": string;
343
+ // "content-length": string;
344
+ // "cache-control": string;
345
+ // "content-encoding": string;
346
+ // server: string;
347
+ // }
348
+ // >;
349
+
350
+ // export type FaxiosResponseHeaders = RawFaxiosResponseHeaders &
351
+ // Record<string, FaxiosHeaderValue>;
352
+
353
+ export interface FaxiosResponseHeadersLike {
354
+ // Property access stays loose (matches the FaxiosHeaders runtime class), but
355
+ // get() is precisely typed so the common accessor isn't `unknown`.
356
+ [key: string]: unknown;
357
+ get: (header: string) => FaxiosHeaderValue | undefined;
358
+ }
359
+
360
+ export interface FaxiosResponse<T = unknown, D = unknown> {
361
+ config: InternalFaxiosRequestConfig<D>;
362
+ data: T;
363
+ headers: FaxiosResponseHeadersLike;
364
+ request?: null | Request;
365
+ status: number;
366
+ statusText: string;
367
+ }
368
+
369
+ export type FaxiosPromise<T = unknown> = Promise<FaxiosResponse<T>>;
370
+
371
+ export interface HeadersDefaults {
372
+ common: RawFaxiosRequestHeaders;
373
+ delete: RawFaxiosRequestHeaders;
374
+ get: RawFaxiosRequestHeaders;
375
+ head: RawFaxiosRequestHeaders;
376
+ link?: RawFaxiosRequestHeaders;
377
+ options?: RawFaxiosRequestHeaders;
378
+ patch: RawFaxiosRequestHeaders;
379
+ post: RawFaxiosRequestHeaders;
380
+ purge?: RawFaxiosRequestHeaders;
381
+ put: RawFaxiosRequestHeaders;
382
+ query?: RawFaxiosRequestHeaders;
383
+ unlink?: RawFaxiosRequestHeaders;
384
+ }
385
+
386
+ export interface FaxiosDefaults<D = unknown> extends Omit<
387
+ FaxiosRequestConfig<D>,
388
+ "headers"
389
+ > {
390
+ headers: HeadersDefaults;
391
+ }
392
+
393
+ /**
394
+ * The `headers` option on every request config and on `create()`: a header
395
+ * bag, method header groups (a header bag under `common` or a method name,
396
+ * applied only to requests with that method), both mixed in one object, or a
397
+ * `FaxiosHeaders` instance.
398
+ */
399
+ export type FaxiosConfigHeaders =
400
+ | FaxiosHeadersInstance
401
+ | Partial<HeadersDefaults>
402
+ | RawFaxiosRequestHeaders;
403
+
404
+ /** Config accepted by `create()`; identical to a request config. */
405
+ export type CreateFaxiosDefaults<D = unknown> = FaxiosRequestConfig<D>;
406
+
407
+ // Reading ctx.config.headers gives the accessor-typed headers; middleware may also assign a new
408
+ // FaxiosHeaders (dispatch normalizes it the same way). A plain object isn't accepted, because the
409
+ // next middleware would read it back expecting set()/get().
410
+ interface ContextHeaders {
411
+ get headers(): FaxiosRequestHeaders;
412
+ set headers(value: FaxiosHeadersInstance | FaxiosRequestHeaders);
413
+ }
414
+
415
+ /**
416
+ * Per-request state passed through `.use()` middleware. Created once per
417
+ * request, after the request config is merged with the instance defaults.
418
+ */
419
+ // `{}` defaults match a FaxiosInstance with no plugins, so a plain `FaxiosMiddleware` installs on one.
420
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- see above
421
+ export interface FaxiosContext<TOptions = {}, TCapabilities = {}> {
422
+ /** Values provided by installed plugins, shared by every request of the instance. */
423
+ capabilities: TCapabilities;
424
+ /** The merged request config. `headers` is a `FaxiosHeaders` instance. */
425
+ config: Omit<InternalFaxiosRequestConfig, "headers"> & ContextHeaders & TOptions;
426
+ /** Null-prototype scratch space shared by middleware for this request only. */
427
+ state: Record<PropertyKey, unknown>;
428
+ }
429
+
430
+ /**
431
+ * Runs the rest of the middleware chain, then dispatches a copy of `ctx.config`. It takes the same
432
+ * context type the middleware received, so a middleware can't pass on fewer capabilities or
433
+ * options than later middleware expects.
434
+ */
435
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- the `{}` defaults of FaxiosContext
436
+ export type FaxiosNext<TOptions = {}, TCapabilities = {}> =
437
+ (ctx: FaxiosContext<TOptions, TCapabilities>) => Promise<FaxiosResponse>;
438
+
439
+ /**
440
+ * Onion-style lifecycle hook: code before `await next(ctx)` runs on the way in,
441
+ * code after it on the way out. Returning without calling `next` skips dispatch.
442
+ */
443
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- the `{}` defaults of FaxiosContext
444
+ export type FaxiosMiddleware<TOptions = {}, TCapabilities = {}> = (
445
+ ctx: FaxiosContext<TOptions, TCapabilities>,
446
+ next: FaxiosNext<TOptions, TCapabilities>
447
+ ) => Promise<FaxiosResponse>;
448
+
449
+ /**
450
+ * The type slots of a `FaxiosPlugin`, all optional: `requires` holds the capabilities that must be
451
+ * installed before it, `provides` the capabilities it adds to `ctx.capabilities`, and `options`
452
+ * the request options it adds to every config-taking member.
453
+ */
454
+ export interface FaxiosPluginSpec {
455
+ options?: unknown;
456
+ provides?: unknown;
457
+ requires?: unknown;
458
+ }
459
+
460
+ // A slot the spec leaves out is `unknown`: nothing required, provided or added.
461
+ type PluginSlot<TSpec, K extends keyof FaxiosPluginSpec> = K extends keyof TSpec ? Required<TSpec>[K] : unknown;
462
+
463
+ // Any other key is `never`, so a misspelt slot (`require`) is an error instead of being ignored.
464
+ type OnlyPluginSlots<TSpec> = { [K in Exclude<keyof TSpec, keyof FaxiosPluginSpec>]: never; };
465
+
466
+ /**
467
+ * The parts of a plugin that `use()` reads its type parameters from. Internal: build plugins with
468
+ * `definePlugin()` or annotate them as `FaxiosPlugin`; `use()` infers `TRequires`, `TProvides`
469
+ * and `TOptions` through this.
470
+ */
471
+ export interface FaxiosPluginBase<TRequires = unknown, TProvides = unknown, TOptions = unknown> {
472
+ middleware: FaxiosMiddleware<TOptions, TRequires & TProvides>;
473
+ name: string;
474
+ /** Internal, type-only marker that carries the type parameters for inference. Never set it. */
475
+ readonly "~plugin"?: {
476
+ readonly options: TOptions;
477
+ readonly provides: TProvides;
478
+ readonly requires: TRequires;
479
+ };
480
+ }
481
+
482
+ /**
483
+ * Middleware bundled with the capabilities it requires and provides, typed by one
484
+ * `FaxiosPluginSpec`: `FaxiosPlugin<{ requires?; provides?; options? }>`. Declaring `provides`
485
+ * makes the `provides` value required, so a plugin can't claim a capability it never supplies.
486
+ */
487
+ // eslint-disable-next-line @typescript-eslint/no-empty-object-type -- `{}`: a plugin with no slots
488
+ export type FaxiosPlugin<TSpec extends FaxiosPluginSpec & OnlyPluginSlots<TSpec> = {}> =
489
+ FaxiosPluginBase<PluginSlot<TSpec, "requires">, PluginSlot<TSpec, "provides">, PluginSlot<TSpec, "options">>
490
+ & ([keyof PluginSlot<TSpec, "provides">] extends [never]
491
+ ? { provides?: PluginSlot<TSpec, "provides">; }
492
+ : { provides: PluginSlot<TSpec, "provides">; });
493
+
494
+ /** What `use()` and `eject()` accept as a plugin: the base plus an optional `provides`. Internal. */
495
+ export type FaxiosPluginArgument<TRequires = unknown, TProvides = unknown, TOptions = unknown> =
496
+ FaxiosPluginBase<TRequires, TProvides, TOptions> & { provides?: TProvides; };