@indra211/exios 0.0.0-stage → 2.0.0
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 +21 -0
- package/README.md +187 -2
- package/dist/index.cjs +2007 -0
- package/dist/index.d.cts +38 -0
- package/dist/index.d.ts +299 -0
- package/dist/index.js +1987 -0
- package/dist/index.node.cjs +2545 -0
- package/dist/index.node.js +2515 -0
- package/package.json +106 -4
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type * as Pkg from './index.js' with { 'resolution-mode': 'import' };
|
|
2
|
+
|
|
3
|
+
declare const exios: Pkg.ExiosDefault & { default: Pkg.ExiosDefault };
|
|
4
|
+
declare namespace exios {
|
|
5
|
+
type AdapterConfig = Pkg.AdapterConfig;
|
|
6
|
+
type AdapterFn = Pkg.AdapterFn;
|
|
7
|
+
type AdapterName = Pkg.AdapterName;
|
|
8
|
+
type CancelToken = Pkg.CancelToken;
|
|
9
|
+
type CancelTokenSource = Pkg.CancelTokenSource;
|
|
10
|
+
type Canceler = Pkg.Canceler;
|
|
11
|
+
type BreakerConfig = Pkg.BreakerConfig;
|
|
12
|
+
type BreakerState = Pkg.BreakerState;
|
|
13
|
+
type CanceledError<T = any, D = any> = Pkg.CanceledError<T, D>;
|
|
14
|
+
type CircuitOpenError = Pkg.CircuitOpenError;
|
|
15
|
+
type ExiosDefault = Pkg.ExiosDefault;
|
|
16
|
+
type ExiosDefaults<D = any> = Pkg.ExiosDefaults<D>;
|
|
17
|
+
type ExiosError<T = any, D = any> = Pkg.ExiosError<T, D>;
|
|
18
|
+
type ExiosInstance = Pkg.ExiosInstance;
|
|
19
|
+
type ExiosRequestConfig<D = any> = Pkg.ExiosRequestConfig<D>;
|
|
20
|
+
type ExiosResponse<T = any, D = any> = Pkg.ExiosResponse<T, D>;
|
|
21
|
+
type ExiosStatic = Pkg.ExiosStatic;
|
|
22
|
+
type HeaderValue = Pkg.HeaderValue;
|
|
23
|
+
type HeadersDefaults = Pkg.HeadersDefaults;
|
|
24
|
+
type InterceptorHandler<V> = Pkg.InterceptorHandler<V>;
|
|
25
|
+
type InterceptorManager<V> = Pkg.InterceptorManager<V>;
|
|
26
|
+
type InterceptorOptions = Pkg.InterceptorOptions;
|
|
27
|
+
type InternalConfig<D = any> = Pkg.InternalConfig<D>;
|
|
28
|
+
type Method = Pkg.Method;
|
|
29
|
+
type Outcome = Pkg.Outcome;
|
|
30
|
+
type ProgressEvent = Pkg.ProgressEvent;
|
|
31
|
+
type ProxyConfig = Pkg.ProxyConfig;
|
|
32
|
+
type RawHeaders = Pkg.RawHeaders;
|
|
33
|
+
type RequestBreakerOverride = Pkg.RequestBreakerOverride;
|
|
34
|
+
type ResponseType = Pkg.ResponseType;
|
|
35
|
+
type RetryConfig = Pkg.RetryConfig;
|
|
36
|
+
type Transformer = Pkg.Transformer;
|
|
37
|
+
}
|
|
38
|
+
export = exios;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
declare class ExiosError<T = any, D = any> extends Error {
|
|
2
|
+
static readonly ERR_BAD_REQUEST = "ERR_BAD_REQUEST";
|
|
3
|
+
static readonly ERR_BAD_RESPONSE = "ERR_BAD_RESPONSE";
|
|
4
|
+
static readonly ERR_NETWORK = "ERR_NETWORK";
|
|
5
|
+
static readonly ECONNABORTED = "ECONNABORTED";
|
|
6
|
+
static readonly ETIMEDOUT = "ETIMEDOUT";
|
|
7
|
+
static readonly ERR_CANCELED = "ERR_CANCELED";
|
|
8
|
+
static readonly ERR_BAD_OPTION_VALUE = "ERR_BAD_OPTION_VALUE";
|
|
9
|
+
static readonly ERR_CIRCUIT_OPEN = "ERR_CIRCUIT_OPEN";
|
|
10
|
+
static readonly ERR_NOT_SUPPORT = "ERR_NOT_SUPPORT";
|
|
11
|
+
static readonly ERR_FR_TOO_MANY_REDIRECTS = "ERR_FR_TOO_MANY_REDIRECTS";
|
|
12
|
+
code?: string;
|
|
13
|
+
config?: InternalConfig<D>;
|
|
14
|
+
request?: any;
|
|
15
|
+
response?: ExiosResponse<T, D>;
|
|
16
|
+
status?: number;
|
|
17
|
+
readonly isExiosError: true;
|
|
18
|
+
meta: {
|
|
19
|
+
attempts: number;
|
|
20
|
+
};
|
|
21
|
+
constructor(message: string, code?: string, config?: InternalConfig<D>, request?: any, response?: ExiosResponse<T, D>);
|
|
22
|
+
toJSON(): Record<string, unknown>;
|
|
23
|
+
static from<T = any, D = any>(err: unknown, code: string | undefined, config?: InternalConfig<D>, request?: any, response?: ExiosResponse<T, D>): ExiosError<T, D>;
|
|
24
|
+
}
|
|
25
|
+
declare class CanceledError<T = any, D = any> extends ExiosError<T, D> {
|
|
26
|
+
constructor(message?: string, config?: InternalConfig<D>, request?: any);
|
|
27
|
+
}
|
|
28
|
+
declare class CircuitOpenError extends ExiosError {
|
|
29
|
+
origin: string;
|
|
30
|
+
retryAt: number;
|
|
31
|
+
constructor(origin: string, retryAt: number, config?: InternalConfig);
|
|
32
|
+
}
|
|
33
|
+
declare function isExiosError(v: unknown): v is ExiosError;
|
|
34
|
+
/** Also true for a canceled error from another copy of the package (dual-package hazard). */
|
|
35
|
+
declare function isCancel(v: unknown): v is CanceledError;
|
|
36
|
+
|
|
37
|
+
type Canceler = (message?: string, config?: InternalConfig, request?: any) => void;
|
|
38
|
+
interface CancelTokenSource {
|
|
39
|
+
token: CancelToken;
|
|
40
|
+
cancel: Canceler;
|
|
41
|
+
}
|
|
42
|
+
type Listener = (reason: CanceledError) => void;
|
|
43
|
+
/**
|
|
44
|
+
* axios-compatible cancel token, built on AbortSignal.
|
|
45
|
+
* @deprecated Use `signal` with an AbortController (same as axios).
|
|
46
|
+
*/
|
|
47
|
+
declare class CancelToken {
|
|
48
|
+
reason?: CanceledError;
|
|
49
|
+
readonly promise: Promise<CanceledError>;
|
|
50
|
+
private listeners;
|
|
51
|
+
constructor(executor: (cancel: Canceler) => void);
|
|
52
|
+
throwIfRequested(): void;
|
|
53
|
+
subscribe(listener: Listener): void;
|
|
54
|
+
unsubscribe(listener: Listener): void;
|
|
55
|
+
/** An AbortSignal that aborts with the reason; call `signal.unsubscribe()` when done with it. */
|
|
56
|
+
toAbortSignal(): AbortSignal & {
|
|
57
|
+
unsubscribe(): void;
|
|
58
|
+
};
|
|
59
|
+
static source(): CancelTokenSource;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
type Method = "get" | "post" | "put" | "patch" | "delete" | "head" | "options" | "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS";
|
|
63
|
+
type ResponseType = "json" | "text" | "blob" | "arraybuffer" | "formData" | "stream";
|
|
64
|
+
type HeaderValue = string | number | boolean | null | undefined;
|
|
65
|
+
type RawHeaders = Record<string, HeaderValue> | Headers;
|
|
66
|
+
/** Per-method header buckets on `defaults.headers` (axios shape); every bucket always exists. */
|
|
67
|
+
type HeadersDefaults = {
|
|
68
|
+
common: Record<string, HeaderValue>;
|
|
69
|
+
} & Record<Lowercase<Method>, Record<string, HeaderValue>>;
|
|
70
|
+
type AdapterName = "xhr" | "http" | "fetch";
|
|
71
|
+
type AdapterFn = (config: InternalConfig) => Promise<ExiosResponse>;
|
|
72
|
+
type AdapterConfig = AdapterName | AdapterFn | Array<AdapterName | AdapterFn>;
|
|
73
|
+
interface ProxyConfig {
|
|
74
|
+
protocol?: string;
|
|
75
|
+
host: string;
|
|
76
|
+
port: number;
|
|
77
|
+
auth?: {
|
|
78
|
+
username: string;
|
|
79
|
+
password: string;
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
interface Outcome {
|
|
83
|
+
error?: ExiosError;
|
|
84
|
+
response?: ExiosResponse;
|
|
85
|
+
}
|
|
86
|
+
interface RetryConfig {
|
|
87
|
+
retries: number;
|
|
88
|
+
methods: Lowercase<Method>[];
|
|
89
|
+
statusCodes: number[];
|
|
90
|
+
retryOnNetworkError: boolean;
|
|
91
|
+
baseDelayMs: number;
|
|
92
|
+
maxDelayMs: number;
|
|
93
|
+
factor: number;
|
|
94
|
+
jitter: "full" | "none";
|
|
95
|
+
respectRetryAfter: boolean;
|
|
96
|
+
maxElapsedMs?: number;
|
|
97
|
+
shouldRetry?: (ctx: Outcome & {
|
|
98
|
+
attempt: number;
|
|
99
|
+
config: InternalConfig;
|
|
100
|
+
}) => boolean | Promise<boolean>;
|
|
101
|
+
onRetry?: (ctx: Outcome & {
|
|
102
|
+
attempt: number;
|
|
103
|
+
delayMs: number;
|
|
104
|
+
}) => void;
|
|
105
|
+
}
|
|
106
|
+
interface BreakerConfig {
|
|
107
|
+
failureThreshold: number;
|
|
108
|
+
windowMs?: number;
|
|
109
|
+
minRequests: number;
|
|
110
|
+
failureRateThreshold: number;
|
|
111
|
+
resetTimeoutMs: number;
|
|
112
|
+
halfOpenMaxRequests: number;
|
|
113
|
+
successThreshold: number;
|
|
114
|
+
isFailure?: (o: Outcome) => boolean;
|
|
115
|
+
key?: (config: InternalConfig) => string;
|
|
116
|
+
onStateChange?: (key: string, from: BreakerState, to: BreakerState) => void;
|
|
117
|
+
}
|
|
118
|
+
type BreakerState = "closed" | "open" | "half-open";
|
|
119
|
+
type RequestBreakerOverride = false | Pick<Partial<BreakerConfig>, "key" | "isFailure">;
|
|
120
|
+
interface ProgressEvent {
|
|
121
|
+
loaded: number;
|
|
122
|
+
total?: number;
|
|
123
|
+
progress?: number;
|
|
124
|
+
bytes: number;
|
|
125
|
+
rate?: number;
|
|
126
|
+
estimated?: number;
|
|
127
|
+
upload?: true;
|
|
128
|
+
download?: true;
|
|
129
|
+
event?: undefined;
|
|
130
|
+
}
|
|
131
|
+
type Transformer = (this: InternalConfig, data: any, headers: Record<string, string>, status?: number) => any;
|
|
132
|
+
interface ExiosRequestConfig<D = any> {
|
|
133
|
+
url?: string;
|
|
134
|
+
method?: Method;
|
|
135
|
+
baseURL?: string;
|
|
136
|
+
allowAbsoluteUrls?: boolean;
|
|
137
|
+
headers?: RawHeaders | (Partial<HeadersDefaults> & Record<string, HeaderValue | Record<string, HeaderValue>>);
|
|
138
|
+
params?: any;
|
|
139
|
+
paramsSerializer?: ((params: any) => string) | {
|
|
140
|
+
serialize?: (p: any) => string;
|
|
141
|
+
indexes?: boolean | null;
|
|
142
|
+
encode?: (s: string) => string;
|
|
143
|
+
};
|
|
144
|
+
data?: D;
|
|
145
|
+
transformRequest?: Transformer | Transformer[];
|
|
146
|
+
transformResponse?: Transformer | Transformer[];
|
|
147
|
+
timeout?: number;
|
|
148
|
+
timeoutErrorMessage?: string;
|
|
149
|
+
withCredentials?: boolean;
|
|
150
|
+
auth?: {
|
|
151
|
+
username: string;
|
|
152
|
+
password: string;
|
|
153
|
+
};
|
|
154
|
+
responseType?: ResponseType;
|
|
155
|
+
responseEncoding?: string;
|
|
156
|
+
validateStatus?: ((status: number) => boolean) | null;
|
|
157
|
+
signal?: AbortSignal;
|
|
158
|
+
onDownloadProgress?: (e: ProgressEvent) => void;
|
|
159
|
+
maxContentLength?: number;
|
|
160
|
+
maxBodyLength?: number;
|
|
161
|
+
transitional?: {
|
|
162
|
+
silentJSONParsing?: boolean;
|
|
163
|
+
clarifyTimeoutError?: boolean;
|
|
164
|
+
};
|
|
165
|
+
adapter?: AdapterConfig;
|
|
166
|
+
onUploadProgress?: (e: ProgressEvent) => void;
|
|
167
|
+
xsrfCookieName?: string;
|
|
168
|
+
xsrfHeaderName?: string;
|
|
169
|
+
withXSRFToken?: boolean | ((config: InternalConfig) => boolean | undefined);
|
|
170
|
+
/** @deprecated Use `signal` (AbortController), as in axios. */
|
|
171
|
+
cancelToken?: CancelToken;
|
|
172
|
+
/** Node http adapter: proxy server, or `false` to ignore HTTP(S)_PROXY env vars. */
|
|
173
|
+
proxy?: ProxyConfig | false;
|
|
174
|
+
/** Node http adapter: `http.Agent` used for http: URLs. */
|
|
175
|
+
httpAgent?: unknown;
|
|
176
|
+
/** Node http adapter: `https.Agent` used for https: URLs. */
|
|
177
|
+
httpsAgent?: unknown;
|
|
178
|
+
/** Node http adapter: redirects to follow (default 21; 0 = return the 3xx). */
|
|
179
|
+
maxRedirects?: number;
|
|
180
|
+
beforeRedirect?: (options: Record<string, any>, responseDetails: {
|
|
181
|
+
headers: Record<string, string | string[]>;
|
|
182
|
+
statusCode: number;
|
|
183
|
+
}) => void;
|
|
184
|
+
/** Node http adapter: unix socket path. */
|
|
185
|
+
socketPath?: string | null;
|
|
186
|
+
/** Node http adapter: decode gzip/deflate/br responses (default true). */
|
|
187
|
+
decompress?: boolean;
|
|
188
|
+
insecureHTTPParser?: boolean;
|
|
189
|
+
fetch?: typeof fetch;
|
|
190
|
+
fetchOptions?: Omit<RequestInit, "body" | "headers" | "method" | "signal">;
|
|
191
|
+
redirect?: RequestRedirect;
|
|
192
|
+
retry?: false | Partial<RetryConfig>;
|
|
193
|
+
breaker?: false | Partial<BreakerConfig>;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Type of `instance.defaults`: like a request config, but every header bucket, `retry` and `breaker`
|
|
197
|
+
* always exist. Partial retry/breaker objects are allowed; unset fields fall back to the library defaults.
|
|
198
|
+
*/
|
|
199
|
+
interface ExiosDefaults<D = any> extends Omit<ExiosRequestConfig<D>, "headers" | "retry" | "breaker"> {
|
|
200
|
+
headers: HeadersDefaults & Record<string, HeaderValue | Record<string, HeaderValue>>;
|
|
201
|
+
retry: false | Partial<RetryConfig>;
|
|
202
|
+
breaker: false | Partial<BreakerConfig>;
|
|
203
|
+
}
|
|
204
|
+
interface InternalConfig<D = any> extends Omit<ExiosRequestConfig<D>, "headers" | "retry" | "breaker"> {
|
|
205
|
+
method: Lowercase<Method>;
|
|
206
|
+
headers: Record<string, string>;
|
|
207
|
+
retry: false | RetryConfig;
|
|
208
|
+
breaker: false | BreakerConfig;
|
|
209
|
+
}
|
|
210
|
+
interface ExiosResponse<T = any, D = any> {
|
|
211
|
+
data: T;
|
|
212
|
+
status: number;
|
|
213
|
+
statusText: string;
|
|
214
|
+
headers: Record<string, string | string[]>;
|
|
215
|
+
config: InternalConfig<D>;
|
|
216
|
+
/** XMLHttpRequest (xhr), ClientRequest (http) or Request (fetch). */
|
|
217
|
+
request: any;
|
|
218
|
+
meta: {
|
|
219
|
+
attempts: number;
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
interface InterceptorOptions {
|
|
224
|
+
synchronous?: boolean;
|
|
225
|
+
runWhen?: (config: InternalConfig) => boolean;
|
|
226
|
+
}
|
|
227
|
+
interface InterceptorHandler<V> {
|
|
228
|
+
fulfilled?: ((value: V) => V | Promise<V>) | null;
|
|
229
|
+
rejected?: ((error: any) => any) | null;
|
|
230
|
+
synchronous: boolean;
|
|
231
|
+
runWhen: ((config: InternalConfig) => boolean) | null;
|
|
232
|
+
}
|
|
233
|
+
/** axios-style interceptor registry: ids are array indexes, ejected slots become null. */
|
|
234
|
+
declare class InterceptorManager<V> {
|
|
235
|
+
private handlers;
|
|
236
|
+
use(onFulfilled?: ((value: V) => V | Promise<V>) | null, onRejected?: ((error: any) => any) | null, opts?: InterceptorOptions): number;
|
|
237
|
+
eject(id: number): void;
|
|
238
|
+
clear(): void;
|
|
239
|
+
forEach(fn: (handler: InterceptorHandler<V>) => void): void;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
type Cfg<D> = ExiosRequestConfig<D>;
|
|
243
|
+
declare class Exios {
|
|
244
|
+
defaults: ExiosDefaults;
|
|
245
|
+
interceptors: {
|
|
246
|
+
request: InterceptorManager<InternalConfig<any>>;
|
|
247
|
+
response: InterceptorManager<ExiosResponse<any, any>>;
|
|
248
|
+
};
|
|
249
|
+
breaker: {
|
|
250
|
+
state(key: string): BreakerState;
|
|
251
|
+
reset(key?: string): void;
|
|
252
|
+
};
|
|
253
|
+
private readonly registry;
|
|
254
|
+
constructor(defaults: ExiosDefaults);
|
|
255
|
+
request<T = any, R = ExiosResponse<T>, D = any>(configOrUrl: string | Cfg<D>, config?: Cfg<D>): Promise<R>;
|
|
256
|
+
/** Runs every request interceptor in this tick with promise-chain semantics, then dispatches. */
|
|
257
|
+
private runSync;
|
|
258
|
+
getUri(config?: ExiosRequestConfig): string;
|
|
259
|
+
private noData;
|
|
260
|
+
private withData;
|
|
261
|
+
get<T = any, R = ExiosResponse<T>, D = any>(url: string, config?: Cfg<D>): Promise<R>;
|
|
262
|
+
delete<T = any, R = ExiosResponse<T>, D = any>(url: string, config?: Cfg<D>): Promise<R>;
|
|
263
|
+
head<T = any, R = ExiosResponse<T>, D = any>(url: string, config?: Cfg<D>): Promise<R>;
|
|
264
|
+
options<T = any, R = ExiosResponse<T>, D = any>(url: string, config?: Cfg<D>): Promise<R>;
|
|
265
|
+
post<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
266
|
+
put<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
267
|
+
patch<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
268
|
+
postForm<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
269
|
+
putForm<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
270
|
+
patchForm<T = any, R = ExiosResponse<T>, D = any>(url: string, data?: D, config?: Cfg<D>): Promise<R>;
|
|
271
|
+
}
|
|
272
|
+
declare const METHODS: readonly ["request", "getUri", "get", "delete", "head", "options", "post", "put", "patch", "postForm", "putForm", "patchForm"];
|
|
273
|
+
interface ExiosStatic extends Pick<Exios, (typeof METHODS)[number] | "defaults" | "interceptors" | "breaker"> {
|
|
274
|
+
<T = any, R = ExiosResponse<T>, D = any>(config: ExiosRequestConfig<D>): Promise<R>;
|
|
275
|
+
<T = any, R = ExiosResponse<T>, D = any>(url: string, config?: ExiosRequestConfig<D>): Promise<R>;
|
|
276
|
+
create(config?: ExiosRequestConfig): ExiosStatic;
|
|
277
|
+
}
|
|
278
|
+
type ExiosInstance = ExiosStatic;
|
|
279
|
+
|
|
280
|
+
declare function mergeConfig(a: ExiosRequestConfig, b?: ExiosRequestConfig): ExiosRequestConfig;
|
|
281
|
+
|
|
282
|
+
declare function toFormData(obj: object, fd?: FormData): FormData;
|
|
283
|
+
|
|
284
|
+
declare const statics: {
|
|
285
|
+
CancelToken: typeof CancelToken;
|
|
286
|
+
ExiosError: typeof ExiosError;
|
|
287
|
+
CanceledError: typeof CanceledError;
|
|
288
|
+
CircuitOpenError: typeof CircuitOpenError;
|
|
289
|
+
isExiosError: typeof isExiosError;
|
|
290
|
+
isCancel: typeof isCancel;
|
|
291
|
+
mergeConfig: typeof mergeConfig;
|
|
292
|
+
toFormData: typeof toFormData;
|
|
293
|
+
};
|
|
294
|
+
type ExiosDefault = ExiosStatic & typeof statics;
|
|
295
|
+
declare const exios: ExiosDefault;
|
|
296
|
+
declare const create: (config?: ExiosRequestConfig) => ExiosStatic;
|
|
297
|
+
|
|
298
|
+
export { CancelToken, CanceledError, CircuitOpenError, ExiosError, InterceptorManager, create, exios as default, isCancel, isExiosError, mergeConfig, toFormData };
|
|
299
|
+
export type { AdapterConfig, AdapterFn, AdapterName, BreakerConfig, BreakerState, CancelTokenSource, Canceler, ExiosDefault, ExiosDefaults, ExiosInstance, ExiosRequestConfig, ExiosResponse, ExiosStatic, HeaderValue, HeadersDefaults, InterceptorHandler, InterceptorOptions, InternalConfig, Method, Outcome, ProgressEvent, ProxyConfig, RawHeaders, RequestBreakerOverride, ResponseType, RetryConfig, Transformer };
|