@gcmdev/faxios 0.1.0 → 0.2.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.
Files changed (210) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +40 -1774
  3. package/dist/index.d.ts +9 -6
  4. package/dist/index.d.ts.map +1 -0
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/adapters/fetch-helpers.d.ts +1 -0
  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 +23 -3
  11. package/dist/lib/adapters/fetch.js.map +1 -1
  12. package/dist/lib/cancel/CanceledError.d.ts +1 -0
  13. package/dist/lib/cancel/CanceledError.d.ts.map +1 -0
  14. package/dist/lib/cancel/isCancel.d.ts +3 -1
  15. package/dist/lib/cancel/isCancel.d.ts.map +1 -0
  16. package/dist/lib/cancel/isCancel.js +3 -0
  17. package/dist/lib/cancel/isCancel.js.map +1 -1
  18. package/dist/lib/core/Faxios.d.ts +6 -17
  19. package/dist/lib/core/Faxios.d.ts.map +1 -0
  20. package/dist/lib/core/Faxios.js +144 -76
  21. package/dist/lib/core/Faxios.js.map +1 -1
  22. package/dist/lib/core/FaxiosError.d.ts +19 -6
  23. package/dist/lib/core/FaxiosError.d.ts.map +1 -0
  24. package/dist/lib/core/FaxiosError.js +16 -1
  25. package/dist/lib/core/FaxiosError.js.map +1 -1
  26. package/dist/lib/core/FaxiosHeaders.d.ts +12 -8
  27. package/dist/lib/core/FaxiosHeaders.d.ts.map +1 -0
  28. package/dist/lib/core/FaxiosHeaders.js +1 -0
  29. package/dist/lib/core/FaxiosHeaders.js.map +1 -1
  30. package/dist/lib/core/buildFullPath.d.ts +1 -0
  31. package/dist/lib/core/buildFullPath.d.ts.map +1 -0
  32. package/dist/lib/core/define.d.ts +19 -2
  33. package/dist/lib/core/define.d.ts.map +1 -0
  34. package/dist/lib/core/define.js.map +1 -1
  35. package/dist/lib/core/dispatchRequest.d.ts +1 -0
  36. package/dist/lib/core/dispatchRequest.d.ts.map +1 -0
  37. package/dist/lib/core/dispatchRequest.js +4 -0
  38. package/dist/lib/core/dispatchRequest.js.map +1 -1
  39. package/dist/lib/core/mergeConfig.d.ts +1 -0
  40. package/dist/lib/core/mergeConfig.d.ts.map +1 -0
  41. package/dist/lib/core/prepareRequest.d.ts +1 -0
  42. package/dist/lib/core/prepareRequest.d.ts.map +1 -0
  43. package/dist/lib/core/prepareRequest.js +1 -20
  44. package/dist/lib/core/prepareRequest.js.map +1 -1
  45. package/dist/lib/core/route.d.ts +11 -2
  46. package/dist/lib/core/route.d.ts.map +1 -0
  47. package/dist/lib/core/route.js.map +1 -1
  48. package/dist/lib/core/settle.d.ts +1 -0
  49. package/dist/lib/core/settle.d.ts.map +1 -0
  50. package/dist/lib/core/transformData.d.ts +1 -0
  51. package/dist/lib/core/transformData.d.ts.map +1 -0
  52. package/dist/lib/core/validateSchema.d.ts +1 -0
  53. package/dist/lib/core/validateSchema.d.ts.map +1 -0
  54. package/dist/lib/defaults/index.d.ts +1 -0
  55. package/dist/lib/defaults/index.d.ts.map +1 -0
  56. package/dist/lib/defaults/index.js +3 -3
  57. package/dist/lib/defaults/index.js.map +1 -1
  58. package/dist/lib/defaults/transitional.d.ts +1 -1
  59. package/dist/lib/defaults/transitional.d.ts.map +1 -0
  60. package/dist/lib/defaults/transitional.js +0 -1
  61. package/dist/lib/defaults/transitional.js.map +1 -1
  62. package/dist/lib/env/data.d.ts +2 -1
  63. package/dist/lib/env/data.d.ts.map +1 -0
  64. package/dist/lib/env/data.js +1 -1
  65. package/dist/lib/env/data.js.map +1 -1
  66. package/dist/lib/faxios.d.ts +115 -48
  67. package/dist/lib/faxios.d.ts.map +1 -0
  68. package/dist/lib/faxios.js +14 -2
  69. package/dist/lib/faxios.js.map +1 -1
  70. package/dist/lib/helpers/FaxiosURLSearchParams.d.ts +3 -1
  71. package/dist/lib/helpers/FaxiosURLSearchParams.d.ts.map +1 -0
  72. package/dist/lib/helpers/FaxiosURLSearchParams.js.map +1 -1
  73. package/dist/lib/helpers/HttpStatusCode.d.ts +1 -0
  74. package/dist/lib/helpers/HttpStatusCode.d.ts.map +1 -0
  75. package/dist/lib/helpers/buildURL.d.ts +1 -0
  76. package/dist/lib/helpers/buildURL.d.ts.map +1 -0
  77. package/dist/lib/helpers/buildURL.js +7 -1
  78. package/dist/lib/helpers/buildURL.js.map +1 -1
  79. package/dist/lib/helpers/cloneConfig.d.ts +4 -0
  80. package/dist/lib/helpers/cloneConfig.d.ts.map +1 -0
  81. package/dist/lib/helpers/cloneConfig.js +21 -0
  82. package/dist/lib/helpers/cloneConfig.js.map +1 -0
  83. package/dist/lib/helpers/combineURLs.d.ts +1 -0
  84. package/dist/lib/helpers/combineURLs.d.ts.map +1 -0
  85. package/dist/lib/helpers/composeSignals.d.ts +1 -0
  86. package/dist/lib/helpers/composeSignals.d.ts.map +1 -0
  87. package/dist/lib/helpers/composeSignals.js +8 -1
  88. package/dist/lib/helpers/composeSignals.js.map +1 -1
  89. package/dist/lib/helpers/cookies.d.ts +1 -0
  90. package/dist/lib/helpers/cookies.d.ts.map +1 -0
  91. package/dist/lib/helpers/estimateDataURLDecodedBytes.d.ts +1 -0
  92. package/dist/lib/helpers/estimateDataURLDecodedBytes.d.ts.map +1 -0
  93. package/dist/lib/helpers/formDataToJSON.d.ts +1 -0
  94. package/dist/lib/helpers/formDataToJSON.d.ts.map +1 -0
  95. package/dist/lib/helpers/isAbsoluteURL.d.ts +1 -0
  96. package/dist/lib/helpers/isAbsoluteURL.d.ts.map +1 -0
  97. package/dist/lib/helpers/isFaxiosError.d.ts +8 -2
  98. package/dist/lib/helpers/isFaxiosError.d.ts.map +1 -0
  99. package/dist/lib/helpers/isFaxiosError.js +5 -1
  100. package/dist/lib/helpers/isFaxiosError.js.map +1 -1
  101. package/dist/lib/helpers/isURLSameOrigin.d.ts +1 -0
  102. package/dist/lib/helpers/isURLSameOrigin.d.ts.map +1 -0
  103. package/dist/lib/helpers/parseHeaders.d.ts +1 -0
  104. package/dist/lib/helpers/parseHeaders.d.ts.map +1 -0
  105. package/dist/lib/helpers/progressEventReducer.d.ts +1 -0
  106. package/dist/lib/helpers/progressEventReducer.d.ts.map +1 -0
  107. package/dist/lib/helpers/sanitizeHeaderValue.d.ts +1 -0
  108. package/dist/lib/helpers/sanitizeHeaderValue.d.ts.map +1 -0
  109. package/dist/lib/helpers/speedometer.d.ts +1 -0
  110. package/dist/lib/helpers/speedometer.d.ts.map +1 -0
  111. package/dist/lib/helpers/substitutePathParams.d.ts +1 -0
  112. package/dist/lib/helpers/substitutePathParams.d.ts.map +1 -0
  113. package/dist/lib/helpers/throttle.d.ts +1 -0
  114. package/dist/lib/helpers/throttle.d.ts.map +1 -0
  115. package/dist/lib/helpers/toFormData.d.ts +1 -0
  116. package/dist/lib/helpers/toFormData.d.ts.map +1 -0
  117. package/dist/lib/helpers/toURLEncodedForm.d.ts +1 -0
  118. package/dist/lib/helpers/toURLEncodedForm.d.ts.map +1 -0
  119. package/dist/lib/helpers/trackStream.d.ts +1 -0
  120. package/dist/lib/helpers/trackStream.d.ts.map +1 -0
  121. package/dist/lib/helpers/validator.d.ts +1 -0
  122. package/dist/lib/helpers/validator.d.ts.map +1 -0
  123. package/dist/lib/platform.d.ts +2 -1
  124. package/dist/lib/platform.d.ts.map +1 -0
  125. package/dist/lib/plugins/attempt.d.ts +2 -0
  126. package/dist/lib/plugins/attempt.d.ts.map +1 -0
  127. package/dist/lib/plugins/attempt.js +4 -0
  128. package/dist/lib/plugins/attempt.js.map +1 -0
  129. package/dist/lib/plugins/authBearer.d.ts +31 -0
  130. package/dist/lib/plugins/authBearer.d.ts.map +1 -0
  131. package/dist/lib/plugins/authBearer.js +99 -0
  132. package/dist/lib/plugins/authBearer.js.map +1 -0
  133. package/dist/lib/plugins/definePlugin.d.ts +22 -0
  134. package/dist/lib/plugins/definePlugin.d.ts.map +1 -0
  135. package/dist/lib/plugins/definePlugin.js +14 -0
  136. package/dist/lib/plugins/definePlugin.js.map +1 -0
  137. package/dist/lib/plugins/retry.d.ts +66 -0
  138. package/dist/lib/plugins/retry.d.ts.map +1 -0
  139. package/dist/lib/plugins/retry.js +168 -0
  140. package/dist/lib/plugins/retry.js.map +1 -0
  141. package/dist/lib/plugins/timing.d.ts +32 -0
  142. package/dist/lib/plugins/timing.d.ts.map +1 -0
  143. package/dist/lib/plugins/timing.js +53 -0
  144. package/dist/lib/plugins/timing.js.map +1 -0
  145. package/dist/lib/types/standard-schema.d.ts +1 -0
  146. package/dist/lib/types/standard-schema.d.ts.map +1 -0
  147. package/dist/lib/types.d.ts +125 -34
  148. package/dist/lib/types.d.ts.map +1 -0
  149. package/dist/lib/utils.d.ts +1 -0
  150. package/dist/lib/utils.d.ts.map +1 -0
  151. package/package.json +42 -19
  152. package/skills/configure-requests/SKILL.md +380 -0
  153. package/skills/configure-requests/references/axios-differences.md +67 -0
  154. package/skills/configure-requests/references/plugins.md +127 -0
  155. package/src/index.ts +57 -0
  156. package/src/lib/adapters/fetch-helpers.ts +167 -0
  157. package/src/lib/adapters/fetch.ts +810 -0
  158. package/src/lib/cancel/CanceledError.ts +23 -0
  159. package/src/lib/cancel/isCancel.ts +10 -0
  160. package/src/lib/core/Faxios.ts +513 -0
  161. package/src/lib/core/FaxiosError.ts +283 -0
  162. package/src/lib/core/FaxiosHeaders.ts +529 -0
  163. package/src/lib/core/buildFullPath.ts +51 -0
  164. package/src/lib/core/define.ts +127 -0
  165. package/src/lib/core/dispatchRequest.ts +171 -0
  166. package/src/lib/core/mergeConfig.ts +175 -0
  167. package/src/lib/core/prepareRequest.ts +155 -0
  168. package/src/lib/core/route.ts +68 -0
  169. package/src/lib/core/settle.ts +20 -0
  170. package/src/lib/core/transformData.ts +23 -0
  171. package/src/lib/core/validateSchema.ts +53 -0
  172. package/src/lib/defaults/index.ts +221 -0
  173. package/src/lib/defaults/transitional.ts +9 -0
  174. package/src/lib/env/data.ts +1 -0
  175. package/src/lib/faxios.ts +306 -0
  176. package/src/lib/helpers/FaxiosURLSearchParams.ts +52 -0
  177. package/src/lib/helpers/HttpStatusCode.ts +77 -0
  178. package/src/lib/helpers/buildURL.ts +77 -0
  179. package/src/lib/helpers/cloneConfig.ts +23 -0
  180. package/src/lib/helpers/combineURLs.ts +11 -0
  181. package/src/lib/helpers/composeSignals.ts +74 -0
  182. package/src/lib/helpers/cookies.ts +68 -0
  183. package/src/lib/helpers/deprecatedMethod.ts +32 -0
  184. package/src/lib/helpers/estimateDataURLDecodedBytes.ts +95 -0
  185. package/src/lib/helpers/formDataToJSON.ts +122 -0
  186. package/src/lib/helpers/isAbsoluteURL.ts +13 -0
  187. package/src/lib/helpers/isFaxiosError.ts +19 -0
  188. package/src/lib/helpers/isURLSameOrigin.ts +16 -0
  189. package/src/lib/helpers/parseHeaders.ts +76 -0
  190. package/src/lib/helpers/progressEventReducer.ts +57 -0
  191. package/src/lib/helpers/sanitizeHeaderValue.ts +61 -0
  192. package/src/lib/helpers/speedometer.ts +55 -0
  193. package/src/lib/helpers/substitutePathParams.ts +13 -0
  194. package/src/lib/helpers/throttle.ts +45 -0
  195. package/src/lib/helpers/toFormData.ts +296 -0
  196. package/src/lib/helpers/toURLEncodedForm.ts +14 -0
  197. package/src/lib/helpers/trackStream.ts +123 -0
  198. package/src/lib/helpers/validator.ts +114 -0
  199. package/src/lib/platform.ts +44 -0
  200. package/src/lib/plugins/attempt.ts +3 -0
  201. package/src/lib/plugins/authBearer.ts +124 -0
  202. package/src/lib/plugins/definePlugin.ts +34 -0
  203. package/src/lib/plugins/retry.ts +245 -0
  204. package/src/lib/plugins/timing.ts +76 -0
  205. package/src/lib/types/standard-schema.ts +58 -0
  206. package/src/lib/types.ts +496 -0
  207. package/src/lib/utils.ts +932 -0
  208. package/dist/lib/core/InterceptorManager.d.ts +0 -9
  209. package/dist/lib/core/InterceptorManager.js +0 -28
  210. package/dist/lib/core/InterceptorManager.js.map +0 -1
@@ -0,0 +1,58 @@
1
+ // @ts-self-types="./standard-schema.d.ts"
2
+ /**
3
+ * Vendored Standard Schema v1 types.
4
+ * @see https://standardschema.dev
5
+ * @see https://github.com/standard-schema/standard-schema
6
+ */
7
+
8
+ /* eslint-disable sonarjs/no-redundant-optional */
9
+
10
+ export interface StandardSchemaV1<Input = unknown, Output = Input> {
11
+ readonly "~standard": StandardSchemaV1.Props<Input, Output>;
12
+ }
13
+
14
+ export declare namespace StandardSchemaV1 {
15
+ interface Props<Input = unknown, Output = Input> {
16
+ readonly version: 1;
17
+ readonly vendor: string;
18
+ readonly types?: Types<Input, Output>;
19
+ readonly validate: (
20
+ value: unknown
21
+ ) => Result<Output> | Promise<Result<Output>>;
22
+ }
23
+
24
+ interface Types<Input = unknown, Output = Input> {
25
+ readonly input: Input;
26
+ readonly output: Output;
27
+ }
28
+
29
+ type Result<Output> = SuccessResult<Output> | FailureResult;
30
+
31
+ interface SuccessResult<Output> {
32
+ readonly value: Output;
33
+ readonly issues?: undefined;
34
+ }
35
+
36
+ interface FailureResult {
37
+ readonly issues: ReadonlyArray<Issue>;
38
+ }
39
+
40
+ interface Issue {
41
+ readonly message: string;
42
+ readonly path?:
43
+ | ReadonlyArray<PropertyKey | PathSegment>
44
+ | undefined;
45
+ }
46
+
47
+ interface PathSegment {
48
+ readonly key: PropertyKey;
49
+ }
50
+
51
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<
52
+ Schema["~standard"]["types"]
53
+ >["input"];
54
+
55
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<
56
+ Schema["~standard"]["types"]
57
+ >["output"];
58
+ }
@@ -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
+ | string
14
+ | Array<string>
15
+ | number
16
+ | boolean
17
+ | null;
18
+
19
+ export interface RawFaxiosHeaders {
20
+ [key: string]: FaxiosHeaderValue;
21
+ }
22
+
23
+ type UppercaseMethod =
24
+ | "GET"
25
+ | "DELETE"
26
+ | "HEAD"
27
+ | "OPTIONS"
28
+ | "POST"
29
+ | "PUT"
30
+ | "PATCH"
31
+ | "PURGE"
32
+ | "LINK"
33
+ | "UNLINK"
34
+ | "QUERY";
35
+
36
+ export type Method = UppercaseMethod | Lowercase<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
+ | StringLiteralsOrString<
55
+ | "text/html"
56
+ | "text/plain"
57
+ | "multipart/form-data"
58
+ | "application/json"
59
+ | "application/x-www-form-urlencoded"
60
+ | "application/octet-stream"
61
+ | "application/problem+json"
62
+ | "application/ld+json"
63
+ | "text/event-stream"
64
+ | "application/graphql-response+json"
65
+ | "application/merge-patch+json"
66
+ | "application/json-patch+json"
67
+ >
68
+ | Exclude<FaxiosHeaderValue, string>;
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
+ | "json"
90
+ | "text"
91
+ | "stream"
92
+ | "formdata"
93
+ | "response";
94
+
95
+ type UppercaseResponseEncoding =
96
+ | "ASCII"
97
+ | "ANSI"
98
+ | "BINARY"
99
+ | "BASE64"
100
+ | "BASE64URL"
101
+ | "HEX"
102
+ | "LATIN1"
103
+ | "UCS-2"
104
+ | "UCS2"
105
+ | "UTF-8"
106
+ | "UTF8"
107
+ | "UTF16LE";
108
+
109
+ export type responseEncoding =
110
+ | UppercaseResponseEncoding
111
+ | Lowercase<UppercaseResponseEncoding>;
112
+
113
+ export interface TransitionalOptions {
114
+ silentJSONParsing?: boolean;
115
+ forcedJSONParsing?: boolean;
116
+ clarifyTimeoutError?: boolean;
117
+ advertiseZstdAcceptEncoding?: boolean;
118
+ validateStatusUndefinedResolves?: boolean;
119
+ }
120
+
121
+ export interface GenericAbortSignal {
122
+ readonly aborted: boolean;
123
+ onabort?: ((event: Event) => void) | null;
124
+ addEventListener?: (...args: Array<unknown>) => unknown;
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
+ name: string;
134
+ method: string;
135
+ submit: () => void;
136
+ }
137
+
138
+ export interface FormDataVisitorHelpers {
139
+ defaultVisitor: SerializerVisitor;
140
+ convertValue: (value: unknown) => unknown;
141
+ isVisitable: (value: unknown) => boolean;
142
+ }
143
+
144
+ export interface SerializerVisitor {
145
+ (
146
+ this: GenericFormData,
147
+ value: unknown,
148
+ key: string | number,
149
+ path: null | Array<string | number>,
150
+ helpers: FormDataVisitorHelpers,
151
+ ): boolean;
152
+ }
153
+
154
+ export interface SerializerOptions {
155
+ visitor?: SerializerVisitor;
156
+ dots?: boolean;
157
+ metaTokens?: boolean;
158
+ indexes?: boolean | null;
159
+ /** Maximum nesting depth to serialize; deeper objects throw `ERR_FORM_DATA_DEPTH_EXCEEDED`. `Infinity` disables the check. */
160
+ maxDepth?: number;
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
+ loaded: number;
184
+ total?: number;
185
+ progress?: number;
186
+ bytes: number;
187
+ rate?: number;
188
+ estimated?: number;
189
+ upload?: boolean;
190
+ download?: boolean;
191
+ event?: BrowserProgressEvent;
192
+ lengthComputable: boolean;
193
+ }
194
+
195
+ export interface FaxiosBasicCredentials {
196
+ username: string;
197
+ password: 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
+ | string
204
+ | RegExp
205
+ | ((value: string, name: string) => boolean);
206
+
207
+ type HeaderGetResult = string | Array<string> | Record<string, string> | RegExpExecArray | true | null | undefined;
208
+
209
+ export type FaxiosRequestHeaders = Record<string, FaxiosHeaderValue> & {
210
+ set: (header: string | Record<string, unknown>, value?: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
211
+ get: (header: string, parser?: boolean | RegExp) => HeaderGetResult;
212
+ has: (header: string, matcher?: HeaderMatcher) => boolean;
213
+ delete: (header: string | Array<string>, matcher?: HeaderMatcher) => boolean;
214
+ clear: (matcher?: HeaderMatcher) => boolean;
215
+ normalize: (format?: boolean) => FaxiosRequestHeaders;
216
+ concat: (...targets: Array<unknown>) => FaxiosRequestHeaders;
217
+ getContentType: (matcher?: HeaderMatcher) => HeaderGetResult;
218
+ setContentType: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
219
+ hasContentType: (matcher?: HeaderMatcher) => boolean;
220
+ getContentLength: (matcher?: HeaderMatcher) => HeaderGetResult;
221
+ setContentLength: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
222
+ hasContentLength: (matcher?: HeaderMatcher) => boolean;
223
+ getAccept: (matcher?: HeaderMatcher) => HeaderGetResult;
224
+ setAccept: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
225
+ hasAccept: (matcher?: HeaderMatcher) => boolean;
226
+ getAcceptEncoding: (matcher?: HeaderMatcher) => HeaderGetResult;
227
+ setAcceptEncoding: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
228
+ hasAcceptEncoding: (matcher?: HeaderMatcher) => boolean;
229
+ getUserAgent: (matcher?: HeaderMatcher) => HeaderGetResult;
230
+ setUserAgent: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
231
+ hasUserAgent: (matcher?: HeaderMatcher) => boolean;
232
+
233
+ getAuthorization: (matcher?: HeaderMatcher) => HeaderGetResult;
234
+ setAuthorization: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
235
+ hasAuthorization: (matcher?: HeaderMatcher) => boolean;
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
+ url?: string;
258
+ method?: StringLiteralsOrString<Method>;
259
+ baseURL?: string;
260
+ allowAbsoluteUrls?: boolean;
261
+ transformRequest?: FaxiosRequestTransformer | Array<FaxiosRequestTransformer>;
262
+ transformResponse?:
263
+ | FaxiosResponseTransformer
264
+ | Array<FaxiosResponseTransformer>;
265
+ headers?: FaxiosConfigHeaders;
266
+ params?: Record<string, unknown> | URLSearchParams;
267
+ paramsSerializer?: ParamsSerializerOptions | CustomParamsSerializer;
268
+ data?: D;
269
+ timeout?: Milliseconds;
270
+ timeoutErrorMessage?: string;
271
+ withCredentials?: boolean;
272
+ auth?: FaxiosBasicCredentials;
273
+ responseType?: ResponseType;
274
+ responseEncoding?: StringLiteralsOrString<responseEncoding>;
275
+ xsrfCookieName?: string;
276
+ xsrfHeaderName?: string;
277
+ onUploadProgress?: (progressEvent: FaxiosProgressEvent) => void;
278
+ onDownloadProgress?: (progressEvent: FaxiosProgressEvent) => void;
279
+ maxContentLength?: number;
280
+ validateStatus?: ((status: number) => boolean) | null;
281
+ maxBodyLength?: number;
282
+ transitional?: TransitionalOptions;
283
+ signal?: AbortSignal | GenericAbortSignal;
284
+ env?: {
285
+ /** Constructed with no arguments to serialize `multipart/form-data` payloads; `null` falls back to the global `FormData`. */
286
+ FormData?: (new () => object) | null;
287
+ fetch?: (
288
+ input: string | URL | Request,
289
+ init?: RequestInit
290
+ ) => Promise<Response>;
291
+ /** `null` disables the constructor, e.g. when a custom `fetch` is incompatible with the global one. */
292
+ Request?: (new (
293
+ input: string | URL | Request,
294
+ init?: RequestInit,
295
+ ) => unknown) | null;
296
+ Response?: (new (...args: Array<unknown>) => unknown) | null;
297
+ };
298
+ formSerializer?: FormSerializerOptions;
299
+ withXSRFToken?:
300
+ | boolean
301
+ | ((config: InternalFaxiosRequestConfig) => boolean | undefined);
302
+ parseReviver?: (
303
+ this: unknown,
304
+ key: string,
305
+ value: unknown,
306
+ context?: { source?: string; }
307
+ ) => unknown;
308
+ fetchOptions?: Record<string, unknown>;
309
+ formDataHeaderPolicy?: "legacy" | "content-only";
310
+ redact?: Array<string>;
311
+ responseSchema?: StandardSchemaV1;
312
+ requestSchema?: StandardSchemaV1;
313
+ paramsSchema?: StandardSchemaV1;
314
+ /**
315
+ * Values for `{key}` placeholders in `url` (braces, not `:key`). Only own properties count.
316
+ * Each value goes through `String()` then `encodeURIComponent`. A placeholder whose key is
317
+ * missing, or whose value is `null` or `undefined`, rejects with `ERR_BAD_OPTION_VALUE`. Keys
318
+ * with no matching placeholder are ignored. Without `pathParams`, placeholders are sent literally.
319
+ */
320
+ pathParams?: Record<string, unknown>;
321
+ /**
322
+ * Standard Schema that validates `pathParams` before substitution; its output replaces
323
+ * `pathParams`. Requires `pathParams`, or the request rejects with `ERR_BAD_OPTION_VALUE`.
324
+ * A validation failure, or output that isn't a plain object, rejects with `ERR_BAD_PATH_PARAMS_SCHEMA`.
325
+ */
326
+ pathParamsSchema?: StandardSchemaV1<unknown, Record<string, unknown>>;
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
+ data: T;
362
+ status: number;
363
+ statusText: string;
364
+ headers: FaxiosResponseHeadersLike;
365
+ config: InternalFaxiosRequestConfig<D>;
366
+ request?: Request | null;
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
+ post: RawFaxiosRequestHeaders;
377
+ put: RawFaxiosRequestHeaders;
378
+ patch: RawFaxiosRequestHeaders;
379
+ options?: RawFaxiosRequestHeaders;
380
+ purge?: RawFaxiosRequestHeaders;
381
+ link?: RawFaxiosRequestHeaders;
382
+ unlink?: RawFaxiosRequestHeaders;
383
+ query?: 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
+ | RawFaxiosRequestHeaders
401
+ | Partial<HeadersDefaults>
402
+ | FaxiosHeadersInstance;
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: FaxiosRequestHeaders | FaxiosHeadersInstance);
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
+ /** The merged request config. `headers` is a `FaxiosHeaders` instance. */
423
+ config: Omit<InternalFaxiosRequestConfig, "headers"> & ContextHeaders & TOptions;
424
+ /** Null-prototype scratch space shared by middleware for this request only. */
425
+ state: Record<PropertyKey, unknown>;
426
+ /** Values provided by installed plugins, shared by every request of the instance. */
427
+ capabilities: TCapabilities;
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
+ requires?: unknown;
456
+ provides?: unknown;
457
+ options?: 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
+ name: string;
473
+ middleware: FaxiosMiddleware<TOptions, TRequires & TProvides>;
474
+ /** Internal, type-only marker that carries the type parameters for inference. Never set it. */
475
+ readonly "~plugin"?: {
476
+ readonly requires: TRequires;
477
+ readonly provides: TProvides;
478
+ readonly options: TOptions;
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; };