@gcmdev/faxios 0.2.1 → 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.
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/adapters/fetch-helpers.d.ts +1 -1
- package/dist/lib/adapters/fetch-helpers.d.ts.map +1 -1
- package/dist/lib/adapters/fetch.d.ts.map +1 -1
- package/dist/lib/adapters/fetch.js +86 -26
- package/dist/lib/adapters/fetch.js.map +1 -1
- package/dist/lib/cancel/CanceledError.d.ts +1 -1
- package/dist/lib/cancel/CanceledError.d.ts.map +1 -1
- package/dist/lib/core/Faxios.d.ts +3 -3
- package/dist/lib/core/Faxios.d.ts.map +1 -1
- package/dist/lib/core/Faxios.js +8 -4
- package/dist/lib/core/Faxios.js.map +1 -1
- package/dist/lib/core/FaxiosError.d.ts +2 -2
- package/dist/lib/core/FaxiosError.d.ts.map +1 -1
- package/dist/lib/core/FaxiosHeaders.d.ts +8 -8
- package/dist/lib/core/FaxiosHeaders.d.ts.map +1 -1
- package/dist/lib/core/define.d.ts +3 -3
- package/dist/lib/core/define.d.ts.map +1 -1
- package/dist/lib/core/dispatchRequest.d.ts +1 -1
- package/dist/lib/core/dispatchRequest.d.ts.map +1 -1
- package/dist/lib/core/mergeConfig.d.ts +2 -2
- package/dist/lib/core/mergeConfig.d.ts.map +1 -1
- package/dist/lib/core/mergeConfig.js +40 -2
- package/dist/lib/core/mergeConfig.js.map +1 -1
- package/dist/lib/core/route.d.ts +1 -1
- package/dist/lib/core/route.d.ts.map +1 -1
- package/dist/lib/core/route.js +2 -5
- package/dist/lib/core/route.js.map +1 -1
- package/dist/lib/core/transformData.d.ts +2 -2
- package/dist/lib/core/transformData.d.ts.map +1 -1
- package/dist/lib/core/validateSchema.d.ts +2 -2
- package/dist/lib/core/validateSchema.d.ts.map +1 -1
- package/dist/lib/env/data.d.ts +1 -1
- package/dist/lib/env/data.js +1 -1
- package/dist/lib/faxios.d.ts +50 -50
- package/dist/lib/faxios.d.ts.map +1 -1
- package/dist/lib/helpers/cloneConfig.d.ts +0 -1
- package/dist/lib/helpers/cloneConfig.d.ts.map +1 -1
- package/dist/lib/helpers/cloneConfig.js +2 -2
- package/dist/lib/helpers/cloneConfig.js.map +1 -1
- package/dist/lib/helpers/cookies.d.ts +1 -1
- package/dist/lib/helpers/cookies.d.ts.map +1 -1
- package/dist/lib/helpers/formDataToJSON.d.ts +1 -1
- package/dist/lib/helpers/formDataToJSON.d.ts.map +1 -1
- package/dist/lib/helpers/formDataToJSON.js +1 -1
- package/dist/lib/helpers/formDataToJSON.js.map +1 -1
- package/dist/lib/helpers/parseHeaders.d.ts +1 -1
- package/dist/lib/helpers/parseHeaders.d.ts.map +1 -1
- package/dist/lib/helpers/substitutePathParams.d.ts.map +1 -1
- package/dist/lib/helpers/substitutePathParams.js +11 -3
- package/dist/lib/helpers/substitutePathParams.js.map +1 -1
- package/dist/lib/helpers/toFormData.d.ts.map +1 -1
- package/dist/lib/helpers/toFormData.js +4 -2
- package/dist/lib/helpers/toFormData.js.map +1 -1
- package/dist/lib/helpers/validator.d.ts +1 -1
- package/dist/lib/helpers/validator.d.ts.map +1 -1
- package/dist/lib/platform.d.ts.map +1 -1
- package/dist/lib/plugins/authBearer.d.ts +9 -5
- package/dist/lib/plugins/authBearer.d.ts.map +1 -1
- package/dist/lib/plugins/authBearer.js +6 -0
- package/dist/lib/plugins/authBearer.js.map +1 -1
- package/dist/lib/plugins/definePlugin.d.ts +3 -3
- package/dist/lib/plugins/definePlugin.d.ts.map +1 -1
- package/dist/lib/plugins/retry.d.ts +23 -23
- package/dist/lib/plugins/retry.d.ts.map +1 -1
- package/dist/lib/plugins/timing.d.ts +8 -8
- package/dist/lib/plugins/timing.d.ts.map +1 -1
- package/dist/lib/types/standard-schema.d.ts +6 -6
- package/dist/lib/types/standard-schema.d.ts.map +1 -1
- package/dist/lib/types.d.ts +92 -92
- package/dist/lib/types.d.ts.map +1 -1
- package/dist/lib/utils.d.ts +4 -3
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +9 -2
- package/dist/lib/utils.js.map +1 -1
- package/package.json +7 -4
- package/skills/configure-requests/SKILL.md +8 -5
- package/skills/configure-requests/references/plugins.md +37 -6
- package/src/index.ts +15 -15
- package/src/lib/adapters/fetch-helpers.ts +3 -3
- package/src/lib/adapters/fetch.ts +125 -64
- package/src/lib/cancel/CanceledError.ts +1 -1
- package/src/lib/core/Faxios.ts +17 -13
- package/src/lib/core/FaxiosError.ts +3 -3
- package/src/lib/core/FaxiosHeaders.ts +16 -16
- package/src/lib/core/define.ts +7 -7
- package/src/lib/core/dispatchRequest.ts +2 -2
- package/src/lib/core/mergeConfig.ts +42 -4
- package/src/lib/core/prepareRequest.ts +1 -1
- package/src/lib/core/route.ts +3 -6
- package/src/lib/core/transformData.ts +2 -2
- package/src/lib/core/validateSchema.ts +4 -4
- package/src/lib/defaults/index.ts +1 -1
- package/src/lib/env/data.ts +1 -1
- package/src/lib/faxios.ts +55 -55
- package/src/lib/helpers/HttpStatusCode.ts +1 -1
- package/src/lib/helpers/cloneConfig.ts +2 -3
- package/src/lib/helpers/composeSignals.ts +4 -4
- package/src/lib/helpers/cookies.ts +3 -3
- package/src/lib/helpers/formDataToJSON.ts +4 -4
- package/src/lib/helpers/parseHeaders.ts +2 -2
- package/src/lib/helpers/progressEventReducer.ts +1 -1
- package/src/lib/helpers/sanitizeHeaderValue.ts +1 -1
- package/src/lib/helpers/substitutePathParams.ts +13 -3
- package/src/lib/helpers/throttle.ts +1 -1
- package/src/lib/helpers/toFormData.ts +11 -9
- package/src/lib/helpers/trackStream.ts +3 -3
- package/src/lib/helpers/validator.ts +3 -3
- package/src/lib/platform.ts +4 -4
- package/src/lib/plugins/authBearer.ts +14 -9
- package/src/lib/plugins/definePlugin.ts +3 -3
- package/src/lib/plugins/retry.ts +27 -27
- package/src/lib/plugins/timing.ts +5 -5
- package/src/lib/types/standard-schema.ts +6 -6
- package/src/lib/types.ts +125 -125
- package/src/lib/utils.ts +21 -12
package/src/lib/types.ts
CHANGED
|
@@ -10,30 +10,30 @@ export type StringLiteralsOrString<Literals extends string> =
|
|
|
10
10
|
| (string & {});
|
|
11
11
|
|
|
12
12
|
export type FaxiosHeaderValue =
|
|
13
|
-
| string
|
|
14
13
|
| Array<string>
|
|
15
|
-
| number
|
|
16
14
|
| boolean
|
|
17
|
-
| null
|
|
15
|
+
| null
|
|
16
|
+
| number
|
|
17
|
+
| string;
|
|
18
18
|
|
|
19
19
|
export interface RawFaxiosHeaders {
|
|
20
20
|
[key: string]: FaxiosHeaderValue;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
type UppercaseMethod =
|
|
24
|
-
| "GET"
|
|
25
24
|
| "DELETE"
|
|
25
|
+
| "GET"
|
|
26
26
|
| "HEAD"
|
|
27
|
+
| "LINK"
|
|
27
28
|
| "OPTIONS"
|
|
28
|
-
| "POST"
|
|
29
|
-
| "PUT"
|
|
30
29
|
| "PATCH"
|
|
30
|
+
| "POST"
|
|
31
31
|
| "PURGE"
|
|
32
|
-
| "
|
|
33
|
-
| "
|
|
34
|
-
| "
|
|
32
|
+
| "PUT"
|
|
33
|
+
| "QUERY"
|
|
34
|
+
| "UNLINK";
|
|
35
35
|
|
|
36
|
-
export type Method = UppercaseMethod |
|
|
36
|
+
export type Method = Lowercase<UppercaseMethod> | UppercaseMethod;
|
|
37
37
|
|
|
38
38
|
type CommonRequestHeadersList =
|
|
39
39
|
| "Accept"
|
|
@@ -51,21 +51,21 @@ type CommonRequestHeadersList =
|
|
|
51
51
|
| "X-Requested-With";
|
|
52
52
|
|
|
53
53
|
type ContentType =
|
|
54
|
+
| Exclude<FaxiosHeaderValue, string>
|
|
54
55
|
| StringLiteralsOrString<
|
|
55
|
-
| "
|
|
56
|
-
| "text/plain"
|
|
57
|
-
| "multipart/form-data"
|
|
56
|
+
| "application/graphql-response+json"
|
|
58
57
|
| "application/json"
|
|
59
|
-
| "application/
|
|
58
|
+
| "application/json-patch+json"
|
|
59
|
+
| "application/ld+json"
|
|
60
|
+
| "application/merge-patch+json"
|
|
60
61
|
| "application/octet-stream"
|
|
61
62
|
| "application/problem+json"
|
|
62
|
-
| "application/
|
|
63
|
+
| "application/x-www-form-urlencoded"
|
|
64
|
+
| "multipart/form-data"
|
|
63
65
|
| "text/event-stream"
|
|
64
|
-
| "
|
|
65
|
-
| "
|
|
66
|
-
|
|
67
|
-
>
|
|
68
|
-
| Exclude<FaxiosHeaderValue, string>;
|
|
66
|
+
| "text/html"
|
|
67
|
+
| "text/plain"
|
|
68
|
+
>;
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* A header bag: header names mapped to header values. Any header name is
|
|
@@ -86,42 +86,42 @@ export type ResponseType =
|
|
|
86
86
|
| "arraybuffer"
|
|
87
87
|
| "blob"
|
|
88
88
|
| "document"
|
|
89
|
+
| "formdata"
|
|
89
90
|
| "json"
|
|
90
|
-
| "
|
|
91
|
+
| "response"
|
|
91
92
|
| "stream"
|
|
92
|
-
| "
|
|
93
|
-
| "response";
|
|
93
|
+
| "text";
|
|
94
94
|
|
|
95
95
|
type UppercaseResponseEncoding =
|
|
96
|
-
| "ASCII"
|
|
97
96
|
| "ANSI"
|
|
98
|
-
| "
|
|
97
|
+
| "ASCII"
|
|
99
98
|
| "BASE64"
|
|
100
99
|
| "BASE64URL"
|
|
100
|
+
| "BINARY"
|
|
101
101
|
| "HEX"
|
|
102
102
|
| "LATIN1"
|
|
103
|
-
| "UCS-2"
|
|
104
103
|
| "UCS2"
|
|
105
|
-
| "
|
|
104
|
+
| "UCS-2"
|
|
106
105
|
| "UTF8"
|
|
107
|
-
| "UTF16LE"
|
|
106
|
+
| "UTF16LE"
|
|
107
|
+
| "UTF-8";
|
|
108
108
|
|
|
109
109
|
export type responseEncoding =
|
|
110
|
-
| UppercaseResponseEncoding
|
|
111
|
-
|
|
|
110
|
+
| Lowercase<UppercaseResponseEncoding>
|
|
111
|
+
| UppercaseResponseEncoding;
|
|
112
112
|
|
|
113
113
|
export interface TransitionalOptions {
|
|
114
|
-
silentJSONParsing?: boolean;
|
|
115
|
-
forcedJSONParsing?: boolean;
|
|
116
|
-
clarifyTimeoutError?: boolean;
|
|
117
114
|
advertiseZstdAcceptEncoding?: boolean;
|
|
115
|
+
clarifyTimeoutError?: boolean;
|
|
116
|
+
forcedJSONParsing?: boolean;
|
|
117
|
+
silentJSONParsing?: boolean;
|
|
118
118
|
validateStatusUndefinedResolves?: boolean;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
export interface GenericAbortSignal {
|
|
122
122
|
readonly aborted: boolean;
|
|
123
|
-
onabort?: ((event: Event) => void) | null;
|
|
124
123
|
addEventListener?: (...args: Array<unknown>) => unknown;
|
|
124
|
+
onabort?: ((event: Event) => void) | null;
|
|
125
125
|
removeEventListener?: (...args: Array<unknown>) => unknown;
|
|
126
126
|
}
|
|
127
127
|
|
|
@@ -130,14 +130,14 @@ export interface GenericFormData {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
export interface GenericHTMLFormElement {
|
|
133
|
-
name: string;
|
|
134
133
|
method: string;
|
|
134
|
+
name: string;
|
|
135
135
|
submit: () => void;
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
export interface FormDataVisitorHelpers {
|
|
139
|
-
defaultVisitor: SerializerVisitor;
|
|
140
139
|
convertValue: (value: unknown) => unknown;
|
|
140
|
+
defaultVisitor: SerializerVisitor;
|
|
141
141
|
isVisitable: (value: unknown) => boolean;
|
|
142
142
|
}
|
|
143
143
|
|
|
@@ -145,19 +145,19 @@ export interface SerializerVisitor {
|
|
|
145
145
|
(
|
|
146
146
|
this: GenericFormData,
|
|
147
147
|
value: unknown,
|
|
148
|
-
key:
|
|
149
|
-
path:
|
|
148
|
+
key: number | string,
|
|
149
|
+
path: Array<number | string> | null,
|
|
150
150
|
helpers: FormDataVisitorHelpers,
|
|
151
151
|
): boolean;
|
|
152
152
|
}
|
|
153
153
|
|
|
154
154
|
export interface SerializerOptions {
|
|
155
|
-
visitor?: SerializerVisitor;
|
|
156
155
|
dots?: boolean;
|
|
157
|
-
metaTokens?: boolean;
|
|
158
156
|
indexes?: boolean | null;
|
|
159
157
|
/** Maximum nesting depth to serialize; deeper objects throw `ERR_FORM_DATA_DEPTH_EXCEEDED`. `Infinity` disables the check. */
|
|
160
158
|
maxDepth?: number;
|
|
159
|
+
metaTokens?: boolean;
|
|
160
|
+
visitor?: SerializerVisitor;
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
// tslint:disable-next-line
|
|
@@ -180,59 +180,59 @@ type BrowserProgressEvent = unknown;
|
|
|
180
180
|
type Milliseconds = number;
|
|
181
181
|
|
|
182
182
|
export interface FaxiosProgressEvent {
|
|
183
|
-
loaded: number;
|
|
184
|
-
total?: number;
|
|
185
|
-
progress?: number;
|
|
186
183
|
bytes: number;
|
|
187
|
-
rate?: number;
|
|
188
|
-
estimated?: number;
|
|
189
|
-
upload?: boolean;
|
|
190
184
|
download?: boolean;
|
|
185
|
+
estimated?: number;
|
|
191
186
|
event?: BrowserProgressEvent;
|
|
192
187
|
lengthComputable: boolean;
|
|
188
|
+
loaded: number;
|
|
189
|
+
progress?: number;
|
|
190
|
+
rate?: number;
|
|
191
|
+
total?: number;
|
|
192
|
+
upload?: boolean;
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
export interface FaxiosBasicCredentials {
|
|
196
|
-
username: string;
|
|
197
196
|
password: string;
|
|
197
|
+
username: string;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
200
|
// forward-declared; implemented in core/FaxiosHeaders.ts
|
|
201
201
|
// Using a structural type that matches FaxiosHeaders class methods
|
|
202
202
|
type HeaderMatcher =
|
|
203
|
-
| string
|
|
203
|
+
| ((value: string, name: string) => boolean)
|
|
204
204
|
| RegExp
|
|
205
|
-
|
|
|
205
|
+
| string;
|
|
206
206
|
|
|
207
|
-
type HeaderGetResult =
|
|
207
|
+
type HeaderGetResult = Array<string> | null | Record<string, string> | RegExpExecArray | string | true | undefined;
|
|
208
208
|
|
|
209
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
210
|
clear: (matcher?: HeaderMatcher) => boolean;
|
|
215
|
-
normalize: (format?: boolean) => FaxiosRequestHeaders;
|
|
216
211
|
concat: (...targets: Array<unknown>) => FaxiosRequestHeaders;
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
hasContentType: (matcher?: HeaderMatcher) => boolean;
|
|
220
|
-
getContentLength: (matcher?: HeaderMatcher) => HeaderGetResult;
|
|
221
|
-
setContentLength: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
|
|
222
|
-
hasContentLength: (matcher?: HeaderMatcher) => boolean;
|
|
212
|
+
delete: (header: Array<string> | string, matcher?: HeaderMatcher) => boolean;
|
|
213
|
+
get: (header: string, parser?: boolean | RegExp) => HeaderGetResult;
|
|
223
214
|
getAccept: (matcher?: HeaderMatcher) => HeaderGetResult;
|
|
224
|
-
setAccept: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
|
|
225
|
-
hasAccept: (matcher?: HeaderMatcher) => boolean;
|
|
226
215
|
getAcceptEncoding: (matcher?: HeaderMatcher) => HeaderGetResult;
|
|
227
|
-
|
|
228
|
-
|
|
216
|
+
getAuthorization: (matcher?: HeaderMatcher) => HeaderGetResult;
|
|
217
|
+
getContentLength: (matcher?: HeaderMatcher) => HeaderGetResult;
|
|
218
|
+
getContentType: (matcher?: HeaderMatcher) => HeaderGetResult;
|
|
229
219
|
getUserAgent: (matcher?: HeaderMatcher) => HeaderGetResult;
|
|
230
|
-
|
|
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;
|
|
231
226
|
hasUserAgent: (matcher?: HeaderMatcher) => boolean;
|
|
232
|
-
|
|
233
|
-
|
|
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;
|
|
234
231
|
setAuthorization: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
|
|
235
|
-
|
|
232
|
+
|
|
233
|
+
setContentLength: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
|
|
234
|
+
setContentType: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
|
|
235
|
+
setUserAgent: (value: FaxiosHeaderValue, rewrite?: boolean) => FaxiosRequestHeaders;
|
|
236
236
|
toJSON: (asStrings?: boolean) => Record<string, FaxiosHeaderValue>;
|
|
237
237
|
};
|
|
238
238
|
|
|
@@ -254,63 +254,42 @@ export interface FaxiosResponseTransformer {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
export interface FaxiosRequestConfig<D = unknown> {
|
|
257
|
-
url?: string;
|
|
258
|
-
method?: StringLiteralsOrString<Method>;
|
|
259
|
-
baseURL?: string;
|
|
260
257
|
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
258
|
auth?: FaxiosBasicCredentials;
|
|
273
|
-
|
|
274
|
-
|
|
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;
|
|
259
|
+
baseURL?: string;
|
|
260
|
+
data?: D;
|
|
284
261
|
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
262
|
fetch?: (
|
|
288
|
-
input:
|
|
263
|
+
input: Request | string | URL,
|
|
289
264
|
init?: RequestInit
|
|
290
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;
|
|
291
268
|
/** `null` disables the constructor, e.g. when a custom `fetch` is incompatible with the global one. */
|
|
292
269
|
Request?: (new (
|
|
293
|
-
input:
|
|
270
|
+
input: Request | string | URL,
|
|
294
271
|
init?: RequestInit,
|
|
295
272
|
) => unknown) | null;
|
|
296
273
|
Response?: (new (...args: Array<unknown>) => unknown) | null;
|
|
297
274
|
};
|
|
275
|
+
fetchOptions?: Record<string, unknown>;
|
|
276
|
+
formDataHeaderPolicy?: "content-only" | "legacy";
|
|
298
277
|
formSerializer?: FormSerializerOptions;
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
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;
|
|
302
287
|
parseReviver?: (
|
|
303
288
|
this: unknown,
|
|
304
289
|
key: string,
|
|
305
290
|
value: unknown,
|
|
306
291
|
context?: { source?: string; }
|
|
307
292
|
) => 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
293
|
/**
|
|
315
294
|
* Values for `{key}` placeholders in `url` (braces, not `:key`). Only own properties count.
|
|
316
295
|
* Each value goes through `String()` then `encodeURIComponent`. A placeholder whose key is
|
|
@@ -324,6 +303,27 @@ export interface FaxiosRequestConfig<D = unknown> {
|
|
|
324
303
|
* A validation failure, or output that isn't a plain object, rejects with `ERR_BAD_PATH_PARAMS_SCHEMA`.
|
|
325
304
|
*/
|
|
326
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
327
|
}
|
|
328
328
|
|
|
329
329
|
export type SchemaConfig<O, D = unknown> = FaxiosRequestConfig<D> & { responseSchema: StandardSchemaV1<unknown, O>; };
|
|
@@ -358,12 +358,12 @@ export interface FaxiosResponseHeadersLike {
|
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
export interface FaxiosResponse<T = unknown, D = unknown> {
|
|
361
|
+
config: InternalFaxiosRequestConfig<D>;
|
|
361
362
|
data: T;
|
|
363
|
+
headers: FaxiosResponseHeadersLike;
|
|
364
|
+
request?: null | Request;
|
|
362
365
|
status: number;
|
|
363
366
|
statusText: string;
|
|
364
|
-
headers: FaxiosResponseHeadersLike;
|
|
365
|
-
config: InternalFaxiosRequestConfig<D>;
|
|
366
|
-
request?: Request | null;
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
export type FaxiosPromise<T = unknown> = Promise<FaxiosResponse<T>>;
|
|
@@ -373,14 +373,14 @@ export interface HeadersDefaults {
|
|
|
373
373
|
delete: RawFaxiosRequestHeaders;
|
|
374
374
|
get: RawFaxiosRequestHeaders;
|
|
375
375
|
head: RawFaxiosRequestHeaders;
|
|
376
|
-
|
|
377
|
-
put: RawFaxiosRequestHeaders;
|
|
378
|
-
patch: RawFaxiosRequestHeaders;
|
|
376
|
+
link?: RawFaxiosRequestHeaders;
|
|
379
377
|
options?: RawFaxiosRequestHeaders;
|
|
378
|
+
patch: RawFaxiosRequestHeaders;
|
|
379
|
+
post: RawFaxiosRequestHeaders;
|
|
380
380
|
purge?: RawFaxiosRequestHeaders;
|
|
381
|
-
|
|
382
|
-
unlink?: RawFaxiosRequestHeaders;
|
|
381
|
+
put: RawFaxiosRequestHeaders;
|
|
383
382
|
query?: RawFaxiosRequestHeaders;
|
|
383
|
+
unlink?: RawFaxiosRequestHeaders;
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
export interface FaxiosDefaults<D = unknown> extends Omit<
|
|
@@ -397,9 +397,9 @@ export interface FaxiosDefaults<D = unknown> extends Omit<
|
|
|
397
397
|
* `FaxiosHeaders` instance.
|
|
398
398
|
*/
|
|
399
399
|
export type FaxiosConfigHeaders =
|
|
400
|
-
|
|
|
400
|
+
| FaxiosHeadersInstance
|
|
401
401
|
| Partial<HeadersDefaults>
|
|
402
|
-
|
|
|
402
|
+
| RawFaxiosRequestHeaders;
|
|
403
403
|
|
|
404
404
|
/** Config accepted by `create()`; identical to a request config. */
|
|
405
405
|
export type CreateFaxiosDefaults<D = unknown> = FaxiosRequestConfig<D>;
|
|
@@ -409,7 +409,7 @@ export type CreateFaxiosDefaults<D = unknown> = FaxiosRequestConfig<D>;
|
|
|
409
409
|
// next middleware would read it back expecting set()/get().
|
|
410
410
|
interface ContextHeaders {
|
|
411
411
|
get headers(): FaxiosRequestHeaders;
|
|
412
|
-
set headers(value:
|
|
412
|
+
set headers(value: FaxiosHeadersInstance | FaxiosRequestHeaders);
|
|
413
413
|
}
|
|
414
414
|
|
|
415
415
|
/**
|
|
@@ -419,12 +419,12 @@ interface ContextHeaders {
|
|
|
419
419
|
// `{}` defaults match a FaxiosInstance with no plugins, so a plain `FaxiosMiddleware` installs on one.
|
|
420
420
|
// eslint-disable-next-line @typescript-eslint/no-empty-object-type -- see above
|
|
421
421
|
export interface FaxiosContext<TOptions = {}, TCapabilities = {}> {
|
|
422
|
+
/** Values provided by installed plugins, shared by every request of the instance. */
|
|
423
|
+
capabilities: TCapabilities;
|
|
422
424
|
/** The merged request config. `headers` is a `FaxiosHeaders` instance. */
|
|
423
425
|
config: Omit<InternalFaxiosRequestConfig, "headers"> & ContextHeaders & TOptions;
|
|
424
426
|
/** Null-prototype scratch space shared by middleware for this request only. */
|
|
425
427
|
state: Record<PropertyKey, unknown>;
|
|
426
|
-
/** Values provided by installed plugins, shared by every request of the instance. */
|
|
427
|
-
capabilities: TCapabilities;
|
|
428
428
|
}
|
|
429
429
|
|
|
430
430
|
/**
|
|
@@ -452,9 +452,9 @@ export type FaxiosMiddleware<TOptions = {}, TCapabilities = {}> = (
|
|
|
452
452
|
* the request options it adds to every config-taking member.
|
|
453
453
|
*/
|
|
454
454
|
export interface FaxiosPluginSpec {
|
|
455
|
-
requires?: unknown;
|
|
456
|
-
provides?: unknown;
|
|
457
455
|
options?: unknown;
|
|
456
|
+
provides?: unknown;
|
|
457
|
+
requires?: unknown;
|
|
458
458
|
}
|
|
459
459
|
|
|
460
460
|
// A slot the spec leaves out is `unknown`: nothing required, provided or added.
|
|
@@ -469,13 +469,13 @@ type OnlyPluginSlots<TSpec> = { [K in Exclude<keyof TSpec, keyof FaxiosPluginSpe
|
|
|
469
469
|
* and `TOptions` through this.
|
|
470
470
|
*/
|
|
471
471
|
export interface FaxiosPluginBase<TRequires = unknown, TProvides = unknown, TOptions = unknown> {
|
|
472
|
-
name: string;
|
|
473
472
|
middleware: FaxiosMiddleware<TOptions, TRequires & TProvides>;
|
|
473
|
+
name: string;
|
|
474
474
|
/** Internal, type-only marker that carries the type parameters for inference. Never set it. */
|
|
475
475
|
readonly "~plugin"?: {
|
|
476
|
-
readonly requires: TRequires;
|
|
477
|
-
readonly provides: TProvides;
|
|
478
476
|
readonly options: TOptions;
|
|
477
|
+
readonly provides: TProvides;
|
|
478
|
+
readonly requires: TRequires;
|
|
479
479
|
};
|
|
480
480
|
}
|
|
481
481
|
|
package/src/lib/utils.ts
CHANGED
|
@@ -8,6 +8,13 @@ const { iterator, toStringTag } = Symbol;
|
|
|
8
8
|
|
|
9
9
|
const hasOwnProperty = (obj: unknown, prop: PropertyKey) => Object.hasOwn(obj as object, prop);
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* The one dangerous-key check: `__proto__`, `constructor` and `prototype` are skipped wherever
|
|
13
|
+
* config, route or form data keys are materialized into objects, to block prototype-pollution writes.
|
|
14
|
+
*/
|
|
15
|
+
const isDangerousKey = (key: PropertyKey): boolean =>
|
|
16
|
+
key === "__proto__" || key === "constructor" || key === "prototype";
|
|
17
|
+
|
|
11
18
|
/**
|
|
12
19
|
* Walk the prototype chain (excluding the shared Object.prototype) looking for
|
|
13
20
|
* an own `prop`. This distinguishes genuine own/inherited members — including
|
|
@@ -21,7 +28,7 @@ const hasOwnProperty = (obj: unknown, prop: PropertyKey) => Object.hasOwn(obj as
|
|
|
21
28
|
* @returns {boolean} True when `prop` is owned below Object.prototype
|
|
22
29
|
*/
|
|
23
30
|
const hasOwnInPrototypeChain = (thing: unknown, prop: PropertyKey): boolean => {
|
|
24
|
-
let obj:
|
|
31
|
+
let obj: null | object = thing != null && typeof thing === "object" ? thing : null;
|
|
25
32
|
if (obj === null) return false;
|
|
26
33
|
const seen: Array<object> = [];
|
|
27
34
|
|
|
@@ -34,7 +41,7 @@ const hasOwnInPrototypeChain = (thing: unknown, prop: PropertyKey): boolean => {
|
|
|
34
41
|
if (hasOwnProperty(obj, prop)) {
|
|
35
42
|
return true;
|
|
36
43
|
}
|
|
37
|
-
obj = getPrototypeOf(obj) as
|
|
44
|
+
obj = getPrototypeOf(obj) as null | object;
|
|
38
45
|
}
|
|
39
46
|
return false;
|
|
40
47
|
};
|
|
@@ -390,7 +397,7 @@ function forEach(obj: unknown, fn: (value: unknown, key: unknown, obj: unknown)
|
|
|
390
397
|
* @param {string} key - The key to find (case-insensitive).
|
|
391
398
|
* @returns {?string} The actual key name if found, otherwise null.
|
|
392
399
|
*/
|
|
393
|
-
function findKey(obj: unknown, key: string):
|
|
400
|
+
function findKey(obj: unknown, key: string): null | string {
|
|
394
401
|
if (isBuffer(obj)) {
|
|
395
402
|
return null;
|
|
396
403
|
}
|
|
@@ -411,8 +418,8 @@ function findKey(obj: unknown, key: string): string | null {
|
|
|
411
418
|
type GlobalWithEvents = typeof globalThis & {
|
|
412
419
|
addEventListener?: (type: string, listener: (event: Record<string, unknown>) => void, capture?: boolean) => void;
|
|
413
420
|
postMessage?: (message: unknown, targetOrigin: string) => void;
|
|
414
|
-
setImmediate?: (cb: () => void) => void;
|
|
415
421
|
process?: { nextTick?: (cb: () => void) => void; };
|
|
422
|
+
setImmediate?: (cb: () => void) => void;
|
|
416
423
|
};
|
|
417
424
|
const _global = globalThis as GlobalWithEvents;
|
|
418
425
|
|
|
@@ -437,14 +444,14 @@ const isContextDefined = (context: unknown) => !isUndefined(context) && context
|
|
|
437
444
|
* @returns {Object} Result of all merge properties
|
|
438
445
|
*/
|
|
439
446
|
function merge(this: unknown, ...objs: Array<unknown>): Record<string, unknown> {
|
|
440
|
-
const ctx = (isContextDefined(this) && this) as { caseless?: unknown; skipUndefined?: unknown; }
|
|
447
|
+
const ctx = (isContextDefined(this) && this) as false | { caseless?: unknown; skipUndefined?: unknown; };
|
|
441
448
|
const caseless = ctx && ctx.caseless;
|
|
442
449
|
const skipUndefined = ctx && ctx.skipUndefined;
|
|
443
450
|
const result: Record<string | symbol, unknown> = {};
|
|
444
451
|
const assignValue = (val: unknown, key: unknown) => {
|
|
445
452
|
const keyStr = key as string | symbol;
|
|
446
453
|
// Skip dangerous property names to prevent prototype pollution
|
|
447
|
-
if (keyStr
|
|
454
|
+
if (isDangerousKey(keyStr)) {
|
|
448
455
|
return;
|
|
449
456
|
}
|
|
450
457
|
|
|
@@ -556,7 +563,8 @@ const toFlatObject = (sourceObj: unknown, destObj?: Record<string, unknown>, fil
|
|
|
556
563
|
let props: Array<string>;
|
|
557
564
|
let i: number;
|
|
558
565
|
let prop: string | undefined;
|
|
559
|
-
|
|
566
|
+
// Null prototype: a polluted Object.prototype[prop] must not mark an own prop as already copied.
|
|
567
|
+
const merged: Record<string, boolean> = Object.create(null);
|
|
560
568
|
|
|
561
569
|
const dest: Record<string, unknown> = destObj ?? {};
|
|
562
570
|
|
|
@@ -596,7 +604,7 @@ const toArray = (thing?: unknown): Array<unknown> | null => {
|
|
|
596
604
|
* @returns {Array}
|
|
597
605
|
*/
|
|
598
606
|
|
|
599
|
-
const isTypedArray = ((TypedArray:
|
|
607
|
+
const isTypedArray = ((TypedArray: (abstract new (...args: Array<unknown>) => unknown) | false) =>
|
|
600
608
|
|
|
601
609
|
(thing: unknown) => TypedArray && thing instanceof TypedArray
|
|
602
610
|
)(typeof Uint8Array !== "undefined" && getPrototypeOf(Uint8Array) as abstract new (...args: Array<unknown>) => unknown);
|
|
@@ -616,7 +624,7 @@ const forEachEntry = (obj: unknown, fn: (key: unknown, value: unknown) => void)
|
|
|
616
624
|
* @returns {Array<boolean>}
|
|
617
625
|
*/
|
|
618
626
|
const matchAll = (regExp: RegExp, str: string) => {
|
|
619
|
-
let matches:
|
|
627
|
+
let matches: null | RegExpExecArray;
|
|
620
628
|
const arr: Array<RegExpExecArray> = [];
|
|
621
629
|
|
|
622
630
|
while ((matches = regExp.exec(str)) !== null) {
|
|
@@ -644,7 +652,7 @@ const { propertyIsEnumerable } = Object.prototype;
|
|
|
644
652
|
*/
|
|
645
653
|
const isRegExp = kindOfTest("RegExp");
|
|
646
654
|
|
|
647
|
-
const reduceDescriptors = (obj: object, reducer: (descriptor: PropertyDescriptor, name: string, obj: object) =>
|
|
655
|
+
const reduceDescriptors = (obj: object, reducer: (descriptor: PropertyDescriptor, name: string, obj: object) => false | PropertyDescriptor | undefined) => {
|
|
648
656
|
const descriptors = Object.getOwnPropertyDescriptors(obj);
|
|
649
657
|
const reducedDescriptors: PropertyDescriptorMap = {};
|
|
650
658
|
|
|
@@ -665,7 +673,7 @@ const reduceDescriptors = (obj: object, reducer: (descriptor: PropertyDescriptor
|
|
|
665
673
|
|
|
666
674
|
const freezeMethods = (obj: object) => {
|
|
667
675
|
// eslint-disable-next-line sonarjs/function-return-type
|
|
668
|
-
reduceDescriptors(obj, (descriptor, name):
|
|
676
|
+
reduceDescriptors(obj, (descriptor, name): false | PropertyDescriptor => {
|
|
669
677
|
// skip restricted props in strict mode
|
|
670
678
|
if (isFunction(obj) && [ "arguments", "caller", "callee" ].includes(name)) {
|
|
671
679
|
return false;
|
|
@@ -759,7 +767,7 @@ const toJSONObject = (obj: unknown): unknown => {
|
|
|
759
767
|
if (!("toJSON" in source)) {
|
|
760
768
|
// add-on descent / delete-on-ascent: preserves path semantics, so DAG nodes serialise at every occurrence (see #7230).
|
|
761
769
|
visited.add(source);
|
|
762
|
-
const target: Record<
|
|
770
|
+
const target: Record<number | string, unknown> = isArray(source) ? ([] as Record<number, unknown>) : {};
|
|
763
771
|
|
|
764
772
|
forEach(source, (value, key) => {
|
|
765
773
|
const reducedValue = visit(value);
|
|
@@ -910,6 +918,7 @@ export default {
|
|
|
910
918
|
isHTMLForm,
|
|
911
919
|
hasOwnProperty,
|
|
912
920
|
hasOwnProp: hasOwnProperty, // an alias to avoid ESLint no-prototype-builtins detection
|
|
921
|
+
isDangerousKey,
|
|
913
922
|
hasOwnInPrototypeChain,
|
|
914
923
|
getSafeProp,
|
|
915
924
|
reduceDescriptors,
|