@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.
- package/LICENSE +1 -0
- package/README.md +40 -1774
- package/dist/index.d.ts +9 -6
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/adapters/fetch-helpers.d.ts +1 -0
- package/dist/lib/adapters/fetch-helpers.d.ts.map +1 -0
- package/dist/lib/adapters/fetch.d.ts +1 -0
- package/dist/lib/adapters/fetch.d.ts.map +1 -0
- package/dist/lib/adapters/fetch.js +23 -3
- package/dist/lib/adapters/fetch.js.map +1 -1
- package/dist/lib/cancel/CanceledError.d.ts +1 -0
- package/dist/lib/cancel/CanceledError.d.ts.map +1 -0
- package/dist/lib/cancel/isCancel.d.ts +3 -1
- package/dist/lib/cancel/isCancel.d.ts.map +1 -0
- package/dist/lib/cancel/isCancel.js +3 -0
- package/dist/lib/cancel/isCancel.js.map +1 -1
- package/dist/lib/core/Faxios.d.ts +6 -17
- package/dist/lib/core/Faxios.d.ts.map +1 -0
- package/dist/lib/core/Faxios.js +144 -76
- package/dist/lib/core/Faxios.js.map +1 -1
- package/dist/lib/core/FaxiosError.d.ts +19 -6
- package/dist/lib/core/FaxiosError.d.ts.map +1 -0
- package/dist/lib/core/FaxiosError.js +16 -1
- package/dist/lib/core/FaxiosError.js.map +1 -1
- package/dist/lib/core/FaxiosHeaders.d.ts +12 -8
- package/dist/lib/core/FaxiosHeaders.d.ts.map +1 -0
- package/dist/lib/core/FaxiosHeaders.js +1 -0
- package/dist/lib/core/FaxiosHeaders.js.map +1 -1
- package/dist/lib/core/buildFullPath.d.ts +1 -0
- package/dist/lib/core/buildFullPath.d.ts.map +1 -0
- package/dist/lib/core/define.d.ts +19 -2
- package/dist/lib/core/define.d.ts.map +1 -0
- package/dist/lib/core/define.js.map +1 -1
- package/dist/lib/core/dispatchRequest.d.ts +1 -0
- package/dist/lib/core/dispatchRequest.d.ts.map +1 -0
- package/dist/lib/core/dispatchRequest.js +4 -0
- package/dist/lib/core/dispatchRequest.js.map +1 -1
- package/dist/lib/core/mergeConfig.d.ts +1 -0
- package/dist/lib/core/mergeConfig.d.ts.map +1 -0
- package/dist/lib/core/prepareRequest.d.ts +1 -0
- package/dist/lib/core/prepareRequest.d.ts.map +1 -0
- package/dist/lib/core/prepareRequest.js +1 -20
- package/dist/lib/core/prepareRequest.js.map +1 -1
- package/dist/lib/core/route.d.ts +11 -2
- package/dist/lib/core/route.d.ts.map +1 -0
- package/dist/lib/core/route.js.map +1 -1
- package/dist/lib/core/settle.d.ts +1 -0
- package/dist/lib/core/settle.d.ts.map +1 -0
- package/dist/lib/core/transformData.d.ts +1 -0
- package/dist/lib/core/transformData.d.ts.map +1 -0
- package/dist/lib/core/validateSchema.d.ts +1 -0
- package/dist/lib/core/validateSchema.d.ts.map +1 -0
- package/dist/lib/defaults/index.d.ts +1 -0
- package/dist/lib/defaults/index.d.ts.map +1 -0
- package/dist/lib/defaults/index.js +3 -3
- package/dist/lib/defaults/index.js.map +1 -1
- package/dist/lib/defaults/transitional.d.ts +1 -1
- package/dist/lib/defaults/transitional.d.ts.map +1 -0
- package/dist/lib/defaults/transitional.js +0 -1
- package/dist/lib/defaults/transitional.js.map +1 -1
- package/dist/lib/env/data.d.ts +2 -1
- package/dist/lib/env/data.d.ts.map +1 -0
- package/dist/lib/env/data.js +1 -1
- package/dist/lib/env/data.js.map +1 -1
- package/dist/lib/faxios.d.ts +115 -48
- package/dist/lib/faxios.d.ts.map +1 -0
- package/dist/lib/faxios.js +14 -2
- package/dist/lib/faxios.js.map +1 -1
- package/dist/lib/helpers/FaxiosURLSearchParams.d.ts +3 -1
- package/dist/lib/helpers/FaxiosURLSearchParams.d.ts.map +1 -0
- package/dist/lib/helpers/FaxiosURLSearchParams.js.map +1 -1
- package/dist/lib/helpers/HttpStatusCode.d.ts +1 -0
- package/dist/lib/helpers/HttpStatusCode.d.ts.map +1 -0
- package/dist/lib/helpers/buildURL.d.ts +1 -0
- package/dist/lib/helpers/buildURL.d.ts.map +1 -0
- package/dist/lib/helpers/buildURL.js +7 -1
- package/dist/lib/helpers/buildURL.js.map +1 -1
- package/dist/lib/helpers/cloneConfig.d.ts +4 -0
- package/dist/lib/helpers/cloneConfig.d.ts.map +1 -0
- package/dist/lib/helpers/cloneConfig.js +21 -0
- package/dist/lib/helpers/cloneConfig.js.map +1 -0
- package/dist/lib/helpers/combineURLs.d.ts +1 -0
- package/dist/lib/helpers/combineURLs.d.ts.map +1 -0
- package/dist/lib/helpers/composeSignals.d.ts +1 -0
- package/dist/lib/helpers/composeSignals.d.ts.map +1 -0
- package/dist/lib/helpers/composeSignals.js +8 -1
- package/dist/lib/helpers/composeSignals.js.map +1 -1
- package/dist/lib/helpers/cookies.d.ts +1 -0
- package/dist/lib/helpers/cookies.d.ts.map +1 -0
- package/dist/lib/helpers/estimateDataURLDecodedBytes.d.ts +1 -0
- package/dist/lib/helpers/estimateDataURLDecodedBytes.d.ts.map +1 -0
- package/dist/lib/helpers/formDataToJSON.d.ts +1 -0
- package/dist/lib/helpers/formDataToJSON.d.ts.map +1 -0
- package/dist/lib/helpers/isAbsoluteURL.d.ts +1 -0
- package/dist/lib/helpers/isAbsoluteURL.d.ts.map +1 -0
- package/dist/lib/helpers/isFaxiosError.d.ts +8 -2
- package/dist/lib/helpers/isFaxiosError.d.ts.map +1 -0
- package/dist/lib/helpers/isFaxiosError.js +5 -1
- package/dist/lib/helpers/isFaxiosError.js.map +1 -1
- package/dist/lib/helpers/isURLSameOrigin.d.ts +1 -0
- package/dist/lib/helpers/isURLSameOrigin.d.ts.map +1 -0
- package/dist/lib/helpers/parseHeaders.d.ts +1 -0
- package/dist/lib/helpers/parseHeaders.d.ts.map +1 -0
- package/dist/lib/helpers/progressEventReducer.d.ts +1 -0
- package/dist/lib/helpers/progressEventReducer.d.ts.map +1 -0
- package/dist/lib/helpers/sanitizeHeaderValue.d.ts +1 -0
- package/dist/lib/helpers/sanitizeHeaderValue.d.ts.map +1 -0
- package/dist/lib/helpers/speedometer.d.ts +1 -0
- package/dist/lib/helpers/speedometer.d.ts.map +1 -0
- package/dist/lib/helpers/substitutePathParams.d.ts +1 -0
- package/dist/lib/helpers/substitutePathParams.d.ts.map +1 -0
- package/dist/lib/helpers/throttle.d.ts +1 -0
- package/dist/lib/helpers/throttle.d.ts.map +1 -0
- package/dist/lib/helpers/toFormData.d.ts +1 -0
- package/dist/lib/helpers/toFormData.d.ts.map +1 -0
- package/dist/lib/helpers/toURLEncodedForm.d.ts +1 -0
- package/dist/lib/helpers/toURLEncodedForm.d.ts.map +1 -0
- package/dist/lib/helpers/trackStream.d.ts +1 -0
- package/dist/lib/helpers/trackStream.d.ts.map +1 -0
- package/dist/lib/helpers/validator.d.ts +1 -0
- package/dist/lib/helpers/validator.d.ts.map +1 -0
- package/dist/lib/platform.d.ts +2 -1
- package/dist/lib/platform.d.ts.map +1 -0
- package/dist/lib/plugins/attempt.d.ts +2 -0
- package/dist/lib/plugins/attempt.d.ts.map +1 -0
- package/dist/lib/plugins/attempt.js +4 -0
- package/dist/lib/plugins/attempt.js.map +1 -0
- package/dist/lib/plugins/authBearer.d.ts +31 -0
- package/dist/lib/plugins/authBearer.d.ts.map +1 -0
- package/dist/lib/plugins/authBearer.js +99 -0
- package/dist/lib/plugins/authBearer.js.map +1 -0
- package/dist/lib/plugins/definePlugin.d.ts +22 -0
- package/dist/lib/plugins/definePlugin.d.ts.map +1 -0
- package/dist/lib/plugins/definePlugin.js +14 -0
- package/dist/lib/plugins/definePlugin.js.map +1 -0
- package/dist/lib/plugins/retry.d.ts +66 -0
- package/dist/lib/plugins/retry.d.ts.map +1 -0
- package/dist/lib/plugins/retry.js +168 -0
- package/dist/lib/plugins/retry.js.map +1 -0
- package/dist/lib/plugins/timing.d.ts +32 -0
- package/dist/lib/plugins/timing.d.ts.map +1 -0
- package/dist/lib/plugins/timing.js +53 -0
- package/dist/lib/plugins/timing.js.map +1 -0
- package/dist/lib/types/standard-schema.d.ts +1 -0
- package/dist/lib/types/standard-schema.d.ts.map +1 -0
- package/dist/lib/types.d.ts +125 -34
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/lib/utils.d.ts +1 -0
- package/dist/lib/utils.d.ts.map +1 -0
- package/package.json +42 -19
- package/skills/configure-requests/SKILL.md +380 -0
- package/skills/configure-requests/references/axios-differences.md +67 -0
- package/skills/configure-requests/references/plugins.md +127 -0
- package/src/index.ts +57 -0
- package/src/lib/adapters/fetch-helpers.ts +167 -0
- package/src/lib/adapters/fetch.ts +810 -0
- package/src/lib/cancel/CanceledError.ts +23 -0
- package/src/lib/cancel/isCancel.ts +10 -0
- package/src/lib/core/Faxios.ts +513 -0
- package/src/lib/core/FaxiosError.ts +283 -0
- package/src/lib/core/FaxiosHeaders.ts +529 -0
- package/src/lib/core/buildFullPath.ts +51 -0
- package/src/lib/core/define.ts +127 -0
- package/src/lib/core/dispatchRequest.ts +171 -0
- package/src/lib/core/mergeConfig.ts +175 -0
- package/src/lib/core/prepareRequest.ts +155 -0
- package/src/lib/core/route.ts +68 -0
- package/src/lib/core/settle.ts +20 -0
- package/src/lib/core/transformData.ts +23 -0
- package/src/lib/core/validateSchema.ts +53 -0
- package/src/lib/defaults/index.ts +221 -0
- package/src/lib/defaults/transitional.ts +9 -0
- package/src/lib/env/data.ts +1 -0
- package/src/lib/faxios.ts +306 -0
- package/src/lib/helpers/FaxiosURLSearchParams.ts +52 -0
- package/src/lib/helpers/HttpStatusCode.ts +77 -0
- package/src/lib/helpers/buildURL.ts +77 -0
- package/src/lib/helpers/cloneConfig.ts +23 -0
- package/src/lib/helpers/combineURLs.ts +11 -0
- package/src/lib/helpers/composeSignals.ts +74 -0
- package/src/lib/helpers/cookies.ts +68 -0
- package/src/lib/helpers/deprecatedMethod.ts +32 -0
- package/src/lib/helpers/estimateDataURLDecodedBytes.ts +95 -0
- package/src/lib/helpers/formDataToJSON.ts +122 -0
- package/src/lib/helpers/isAbsoluteURL.ts +13 -0
- package/src/lib/helpers/isFaxiosError.ts +19 -0
- package/src/lib/helpers/isURLSameOrigin.ts +16 -0
- package/src/lib/helpers/parseHeaders.ts +76 -0
- package/src/lib/helpers/progressEventReducer.ts +57 -0
- package/src/lib/helpers/sanitizeHeaderValue.ts +61 -0
- package/src/lib/helpers/speedometer.ts +55 -0
- package/src/lib/helpers/substitutePathParams.ts +13 -0
- package/src/lib/helpers/throttle.ts +45 -0
- package/src/lib/helpers/toFormData.ts +296 -0
- package/src/lib/helpers/toURLEncodedForm.ts +14 -0
- package/src/lib/helpers/trackStream.ts +123 -0
- package/src/lib/helpers/validator.ts +114 -0
- package/src/lib/platform.ts +44 -0
- package/src/lib/plugins/attempt.ts +3 -0
- package/src/lib/plugins/authBearer.ts +124 -0
- package/src/lib/plugins/definePlugin.ts +34 -0
- package/src/lib/plugins/retry.ts +245 -0
- package/src/lib/plugins/timing.ts +76 -0
- package/src/lib/types/standard-schema.ts +58 -0
- package/src/lib/types.ts +496 -0
- package/src/lib/utils.ts +932 -0
- package/dist/lib/core/InterceptorManager.d.ts +0 -9
- package/dist/lib/core/InterceptorManager.js +0 -28
- package/dist/lib/core/InterceptorManager.js.map +0 -1
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import FaxiosError from "../core/FaxiosError.js";
|
|
4
|
+
import type FaxiosHeaders from "../core/FaxiosHeaders.js";
|
|
5
|
+
import type {
|
|
6
|
+
InternalFaxiosRequestConfig,
|
|
7
|
+
FaxiosRequestHeaders,
|
|
8
|
+
FaxiosResponse
|
|
9
|
+
} from "../types.js";
|
|
10
|
+
import utils from "../utils.js";
|
|
11
|
+
|
|
12
|
+
export type ComposedSignal = AbortSignal & { unsubscribe?: () => void; };
|
|
13
|
+
export type PendingBodyErrorRef = { value: (FaxiosError & { request?: unknown; }) | null; };
|
|
14
|
+
|
|
15
|
+
const _textEncoder: TextEncoder | undefined =
|
|
16
|
+
typeof globalThis.TextEncoder === "function" ? new globalThis.TextEncoder() : undefined;
|
|
17
|
+
|
|
18
|
+
// ponytail: exported for unit testing only — not part of public API
|
|
19
|
+
export const checkDeclaredContentLength = (
|
|
20
|
+
responseHeaders: FaxiosHeaders,
|
|
21
|
+
hasMaxContentLength: boolean,
|
|
22
|
+
maxContentLength: number,
|
|
23
|
+
config: InternalFaxiosRequestConfig,
|
|
24
|
+
request: unknown
|
|
25
|
+
): void => {
|
|
26
|
+
if (!hasMaxContentLength) return;
|
|
27
|
+
const declaredLength = utils.toFiniteNumber(
|
|
28
|
+
(responseHeaders.getContentLength as () => unknown)()
|
|
29
|
+
);
|
|
30
|
+
if (declaredLength != null && declaredLength > maxContentLength) {
|
|
31
|
+
throw new FaxiosError(
|
|
32
|
+
"maxContentLength size of " + maxContentLength + " exceeded",
|
|
33
|
+
FaxiosError.ERR_BAD_RESPONSE,
|
|
34
|
+
config,
|
|
35
|
+
request
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// ponytail: exported for unit testing only — not part of public API
|
|
41
|
+
export const checkMaterializedSize = (
|
|
42
|
+
responseData: unknown,
|
|
43
|
+
hasMaxContentLength: boolean,
|
|
44
|
+
maxContentLength: number,
|
|
45
|
+
isStreamResponse: boolean,
|
|
46
|
+
supportsResponseStream: boolean,
|
|
47
|
+
config: InternalFaxiosRequestConfig,
|
|
48
|
+
request: unknown
|
|
49
|
+
): void => {
|
|
50
|
+
if (!hasMaxContentLength || supportsResponseStream || isStreamResponse) return;
|
|
51
|
+
if (responseData == null) return;
|
|
52
|
+
let materializedSize: number | undefined;
|
|
53
|
+
const rd = responseData as Record<string, unknown>;
|
|
54
|
+
if (typeof rd["byteLength"] === "number") {
|
|
55
|
+
materializedSize = rd["byteLength"];
|
|
56
|
+
}
|
|
57
|
+
else if (typeof rd["size"] === "number") {
|
|
58
|
+
materializedSize = rd["size"];
|
|
59
|
+
}
|
|
60
|
+
else if (typeof responseData === "string") {
|
|
61
|
+
materializedSize = _textEncoder
|
|
62
|
+
? _textEncoder.encode(responseData).byteLength
|
|
63
|
+
: responseData.length;
|
|
64
|
+
}
|
|
65
|
+
if (typeof materializedSize === "number" && materializedSize > maxContentLength) {
|
|
66
|
+
throw new FaxiosError(
|
|
67
|
+
"maxContentLength size of " + maxContentLength + " exceeded",
|
|
68
|
+
FaxiosError.ERR_BAD_RESPONSE,
|
|
69
|
+
config,
|
|
70
|
+
request
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// ponytail: exported for unit testing only — not part of public API
|
|
76
|
+
export const handleFetchCaughtError = (
|
|
77
|
+
err: unknown,
|
|
78
|
+
composedSignal: ComposedSignal | undefined,
|
|
79
|
+
pendingBodyErrorRef: PendingBodyErrorRef,
|
|
80
|
+
config: InternalFaxiosRequestConfig,
|
|
81
|
+
request: unknown
|
|
82
|
+
): never => {
|
|
83
|
+
// Safari can surface fetch aborts as a DOMException-like object whose
|
|
84
|
+
// branded getters throw. Prefer our composed signal reason before reading
|
|
85
|
+
// the caught error, preserving timeout vs cancellation semantics.
|
|
86
|
+
if (
|
|
87
|
+
composedSignal &&
|
|
88
|
+
composedSignal.aborted &&
|
|
89
|
+
composedSignal.reason instanceof FaxiosError
|
|
90
|
+
) {
|
|
91
|
+
const canceledError = composedSignal.reason;
|
|
92
|
+
canceledError.config = config;
|
|
93
|
+
request && (canceledError.request = request);
|
|
94
|
+
err !== canceledError && (canceledError.cause = err as Error);
|
|
95
|
+
throw canceledError;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Surface a maxBodyLength violation we raised while the request body was
|
|
99
|
+
// being streamed. Matching by identity keeps the error deterministic across
|
|
100
|
+
// runtimes and avoids prototype-pollution reads.
|
|
101
|
+
if (pendingBodyErrorRef.value) {
|
|
102
|
+
const _pbe = pendingBodyErrorRef.value;
|
|
103
|
+
request && !_pbe.request && (_pbe.request = request);
|
|
104
|
+
throw _pbe;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Re-throw FaxiosErrors we raised synchronously without re-wrapping them.
|
|
108
|
+
if (err instanceof FaxiosError) {
|
|
109
|
+
request && !err.request && (err.request = request);
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const _err = err as Record<string, unknown> & Error;
|
|
114
|
+
if (
|
|
115
|
+
_err.name === "TypeError" &&
|
|
116
|
+
/Load failed|fetch/i.test(_err.message)
|
|
117
|
+
) {
|
|
118
|
+
throw Object.assign(
|
|
119
|
+
new FaxiosError(
|
|
120
|
+
"Network Error",
|
|
121
|
+
FaxiosError.ERR_NETWORK,
|
|
122
|
+
config,
|
|
123
|
+
request,
|
|
124
|
+
_err["response"] as FaxiosResponse | undefined
|
|
125
|
+
),
|
|
126
|
+
{
|
|
127
|
+
cause: _err["cause"] || _err,
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
throw FaxiosError.from(
|
|
133
|
+
_err,
|
|
134
|
+
_err["code"] as string | undefined,
|
|
135
|
+
config,
|
|
136
|
+
request,
|
|
137
|
+
_err["response"] as FaxiosResponse | undefined
|
|
138
|
+
);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// ponytail: exported for unit testing only — not part of public API
|
|
142
|
+
export const cleanFormDataContentType = (
|
|
143
|
+
data: unknown,
|
|
144
|
+
headers: FaxiosRequestHeaders
|
|
145
|
+
): void => {
|
|
146
|
+
if (utils.isFormData(data)) {
|
|
147
|
+
const contentType = headers.getContentType() as string | null | undefined;
|
|
148
|
+
if (
|
|
149
|
+
contentType &&
|
|
150
|
+
/^multipart\/form-data/i.test(contentType) &&
|
|
151
|
+
!/boundary=/i.test(contentType)
|
|
152
|
+
) {
|
|
153
|
+
headers.delete("content-type");
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// ponytail: exported for unit testing only — not part of public API
|
|
159
|
+
export const encodeBodyIfNeeded = (
|
|
160
|
+
data: unknown,
|
|
161
|
+
headers: Record<string, unknown>,
|
|
162
|
+
encode: (str: string) => Promise<Uint8Array> | Uint8Array
|
|
163
|
+
): Promise<unknown> | unknown => {
|
|
164
|
+
if (!utils.isString(data) || utils.findKey(headers, "content-type")) return data;
|
|
165
|
+
// ponytail: skip await when TextEncoder is sync (avoids microtask hop on every string body)
|
|
166
|
+
return encode(data as string);
|
|
167
|
+
};
|