@npora/request 1.14.4 → 1.15.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/README.md +253 -4
- package/dist/MockAdapter-ChWzzSnH.d.cts +71 -0
- package/dist/MockAdapter-H50LoFDu.d.ts +71 -0
- package/dist/Plugin-0Eh51_et.d.ts +124 -0
- package/dist/Plugin-YysllE6z.d.cts +124 -0
- package/dist/PluginError-CcuPSIRv.js +1 -0
- package/dist/PluginError-DT3VnlUB.cjs +1 -0
- package/dist/PluginError-DVP3pUt_.d.cts +18 -0
- package/dist/PluginError-DVP3pUt_.d.ts +18 -0
- package/dist/RequestError-BH6V64XR.js +1 -0
- package/dist/RequestError-DPSv-HVF.cjs +1 -0
- package/dist/SchemaValidationError-CjvWT8YA.d.ts +166 -0
- package/dist/SchemaValidationError-WMTfqSBV.d.cts +166 -0
- package/dist/adapter-BeVVCcNG.d.cts +21 -0
- package/dist/adapter-ODzpt_dM.d.ts +21 -0
- package/dist/authPlugin-6E6_0dAO.d.ts +53 -0
- package/dist/authPlugin-B_YpkyC8.d.cts +53 -0
- package/dist/buildRequest-BRZwRLoN.cjs +1 -0
- package/dist/buildRequest-Cwt8XEWO.js +1 -0
- package/dist/cachePlugin-B9Hvsprg.d.cts +297 -0
- package/dist/cachePlugin-CSHwJYwI.js +1 -0
- package/dist/cachePlugin-CvH26DBo.d.ts +297 -0
- package/dist/cachePlugin-ZPYdHbsM.cjs +1 -0
- package/dist/circuitBreakerPlugin-B45xghq9.d.cts +59 -0
- package/dist/circuitBreakerPlugin-DsH6YCNe.d.ts +59 -0
- package/dist/concurrencyPlugin-CuJMua41.d.cts +48 -0
- package/dist/concurrencyPlugin-dwGNFYrM.d.ts +48 -0
- package/dist/core.cjs +1 -0
- package/dist/core.d.cts +6 -0
- package/dist/core.d.ts +6 -0
- package/dist/core.js +1 -0
- package/dist/createAbortError-D4rRBq2B.js +1 -0
- package/dist/createAbortError-DJqbdYgk.cjs +1 -0
- package/dist/createClient-CibOTVAy.cjs +1 -0
- package/dist/createClient-I13D6XsD.js +1 -0
- package/dist/downloadPlugin-CEXXJiDo.d.cts +17 -0
- package/dist/downloadPlugin-s8VS8t9r.d.ts +17 -0
- package/dist/index.cjs +1 -4
- package/dist/index.d.cts +15 -1028
- package/dist/index.d.ts +15 -1028
- package/dist/index.js +1 -4
- package/dist/isPromiseLike-BuAv3bAe.js +1 -0
- package/dist/isPromiseLike-C8e95Or2.cjs +1 -0
- package/dist/isURLSearchParams-B93cMCGj.js +1 -0
- package/dist/isURLSearchParams-o-c8Q42t.cjs +1 -0
- package/dist/loggerPlugin-C15EW7Sc.d.ts +6 -0
- package/dist/loggerPlugin-uOFiUtBi.d.cts +6 -0
- package/dist/maxTimerDelay-Hn7X0Wuh.js +1 -0
- package/dist/maxTimerDelay-NH5XeTXb.cjs +1 -0
- package/dist/plugins/auth.cjs +1 -0
- package/dist/plugins/auth.d.cts +2 -0
- package/dist/plugins/auth.d.ts +2 -0
- package/dist/plugins/auth.js +1 -0
- package/dist/plugins/cache.cjs +1 -0
- package/dist/plugins/cache.d.cts +2 -0
- package/dist/plugins/cache.d.ts +2 -0
- package/dist/plugins/cache.js +1 -0
- package/dist/plugins/circuit-breaker.cjs +1 -0
- package/dist/plugins/circuit-breaker.d.cts +2 -0
- package/dist/plugins/circuit-breaker.d.ts +2 -0
- package/dist/plugins/circuit-breaker.js +1 -0
- package/dist/plugins/concurrency.cjs +1 -0
- package/dist/plugins/concurrency.d.cts +2 -0
- package/dist/plugins/concurrency.d.ts +2 -0
- package/dist/plugins/concurrency.js +1 -0
- package/dist/plugins/download.cjs +1 -0
- package/dist/plugins/download.d.cts +2 -0
- package/dist/plugins/download.d.ts +2 -0
- package/dist/plugins/download.js +1 -0
- package/dist/plugins/logger.cjs +1 -0
- package/dist/plugins/logger.d.cts +2 -0
- package/dist/plugins/logger.d.ts +2 -0
- package/dist/plugins/logger.js +1 -0
- package/dist/plugins/retry.cjs +1 -0
- package/dist/plugins/retry.d.cts +2 -0
- package/dist/plugins/retry.d.ts +2 -0
- package/dist/plugins/retry.js +1 -0
- package/dist/plugins/upload.cjs +1 -0
- package/dist/plugins/upload.d.cts +2 -0
- package/dist/plugins/upload.d.ts +2 -0
- package/dist/plugins/upload.js +1 -0
- package/dist/plugins.cjs +1 -0
- package/dist/plugins.d.cts +11 -0
- package/dist/plugins.d.ts +11 -0
- package/dist/plugins.js +1 -0
- package/dist/resolveExtensionConfig-BHHfQwjF.cjs +1 -0
- package/dist/resolveExtensionConfig-QAFHZVte.js +1 -0
- package/dist/resolveRequestOrigin-BndIJeZ7.js +1 -0
- package/dist/resolveRequestOrigin-CRATeWff.cjs +1 -0
- package/dist/response-BhyS3PAL.d.cts +441 -0
- package/dist/response-BhyS3PAL.d.ts +441 -0
- package/dist/retryPlugin-2mYKvWy3.d.ts +6 -0
- package/dist/retryPlugin-BqlUpmd0.d.cts +6 -0
- package/dist/testing.cjs +1 -0
- package/dist/testing.d.cts +2 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +1 -0
- package/dist/uploadPlugin-AfhFIsO7.d.cts +5 -0
- package/dist/uploadPlugin-Bb7EawRX.d.ts +5 -0
- package/dist/validateResponseStatus-Dqzr342t.js +4 -0
- package/dist/validateResponseStatus-QAjcah2i.cjs +4 -0
- package/dist/waitForSignal-DyyPvJd5.js +1 -0
- package/dist/waitForSignal-yR1BeU8f.cjs +1 -0
- package/dist/xhrTransport-C0pg00i5.js +1 -0
- package/dist/xhrTransport-CeW2DDzo.cjs +1 -0
- package/package.json +65 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/plugins/PluginError.d.ts
|
|
2
|
+
type PluginErrorCode = 'MISSING_DEPENDENCY' | 'PLUGIN_CONFLICT' | 'DEPENDENCY_IN_USE';
|
|
3
|
+
interface PluginErrorOptions {
|
|
4
|
+
code: PluginErrorCode;
|
|
5
|
+
plugin: string;
|
|
6
|
+
relatedPlugin: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Stable error thrown for invalid plugin lifecycle operations.
|
|
10
|
+
*/
|
|
11
|
+
declare class PluginError extends Error {
|
|
12
|
+
readonly code: PluginErrorCode;
|
|
13
|
+
readonly plugin: string;
|
|
14
|
+
readonly relatedPlugin: string;
|
|
15
|
+
constructor(message: string, options: PluginErrorOptions);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { PluginErrorCode as n, PluginErrorOptions as r, PluginError as t };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region src/plugins/PluginError.d.ts
|
|
2
|
+
type PluginErrorCode = 'MISSING_DEPENDENCY' | 'PLUGIN_CONFLICT' | 'DEPENDENCY_IN_USE';
|
|
3
|
+
interface PluginErrorOptions {
|
|
4
|
+
code: PluginErrorCode;
|
|
5
|
+
plugin: string;
|
|
6
|
+
relatedPlugin: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Stable error thrown for invalid plugin lifecycle operations.
|
|
10
|
+
*/
|
|
11
|
+
declare class PluginError extends Error {
|
|
12
|
+
readonly code: PluginErrorCode;
|
|
13
|
+
readonly plugin: string;
|
|
14
|
+
readonly relatedPlugin: string;
|
|
15
|
+
constructor(message: string, options: PluginErrorOptions);
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { PluginErrorCode as n, PluginErrorOptions as r, PluginError as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var RequestError=class extends Error{constructor(e,t){super(e),this.name=`RequestError`,this.code=t.code,this.status=t.status??t.response?.status,this.data=t.data??t.response?.data,this.response=t.response,this.config=t.config??t.response?.config,this.cause=t.cause}};export{RequestError as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var RequestError=class extends Error{constructor(e,t){super(e),this.name=`RequestError`,this.code=t.code,this.status=t.status??t.response?.status,this.data=t.data??t.response?.data,this.response=t.response,this.config=t.config??t.response?.config,this.cause=t.cause}};Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return RequestError}});
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { A as StandardSchemaV1, n as ServerSentEvent, o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.js";
|
|
2
|
+
import { t as Adapter } from "./adapter-ODzpt_dM.js";
|
|
3
|
+
import { s as InterceptorManager, t as Plugin } from "./Plugin-0Eh51_et.js";
|
|
4
|
+
//#region src/types/client.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Client creation options.
|
|
7
|
+
*/
|
|
8
|
+
interface ClientOptions extends Partial<Omit<RequestConfig, 'url' | 'method' | 'schema'>> {
|
|
9
|
+
/**
|
|
10
|
+
* Request adapter.
|
|
11
|
+
*
|
|
12
|
+
* @default FetchAdapter
|
|
13
|
+
*/
|
|
14
|
+
adapter?: Adapter;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/client/Client.d.ts
|
|
18
|
+
type MethodConfig = Omit<RequestConfig, 'url' | 'method'>;
|
|
19
|
+
type SchemaMethodConfig<Schema extends StandardSchemaV1> = Omit<MethodConfig, 'schema'> & {
|
|
20
|
+
schema: Schema;
|
|
21
|
+
};
|
|
22
|
+
declare class Client {
|
|
23
|
+
private readonly defaults;
|
|
24
|
+
private readonly adapter;
|
|
25
|
+
private readonly installedPlugins;
|
|
26
|
+
private readonly hooks;
|
|
27
|
+
readonly interceptors: {
|
|
28
|
+
request: InterceptorManager<RequestConfig>;
|
|
29
|
+
response: InterceptorManager<NporaResponse<unknown>>;
|
|
30
|
+
error: InterceptorManager<unknown>;
|
|
31
|
+
};
|
|
32
|
+
private readonly pipeline;
|
|
33
|
+
constructor(options?: ClientOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Create an isolated client that inherits this client's defaults.
|
|
36
|
+
*/
|
|
37
|
+
extend(options?: ClientOptions): Client;
|
|
38
|
+
use(plugin: Plugin): this;
|
|
39
|
+
unuse(pluginName: string): this;
|
|
40
|
+
hasPlugin(pluginName: string): boolean;
|
|
41
|
+
request<Schema extends StandardSchemaV1>(config: RequestConfig & {
|
|
42
|
+
schema: Schema;
|
|
43
|
+
}): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
44
|
+
request<T = unknown>(config: RequestConfig): Promise<T>;
|
|
45
|
+
requestResponse<Schema extends StandardSchemaV1>(config: RequestConfig & {
|
|
46
|
+
schema: Schema;
|
|
47
|
+
}): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
48
|
+
requestResponse<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
49
|
+
get<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
50
|
+
get<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
51
|
+
getResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
52
|
+
getResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
53
|
+
post<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
54
|
+
post<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
55
|
+
postResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
56
|
+
postResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
57
|
+
put<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
58
|
+
put<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
59
|
+
putResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
60
|
+
putResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
61
|
+
patch<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
62
|
+
patch<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
63
|
+
patchResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
64
|
+
patchResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
65
|
+
delete<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
66
|
+
delete<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
67
|
+
deleteResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
68
|
+
deleteResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
69
|
+
head(url: string, config?: Omit<MethodConfig, 'schema'>): Promise<void>;
|
|
70
|
+
headResponse(url: string, config?: Omit<MethodConfig, 'schema'>): Promise<NporaResponse<void>>;
|
|
71
|
+
options<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
72
|
+
options<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
73
|
+
optionsResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
74
|
+
optionsResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
75
|
+
/**
|
|
76
|
+
* Consume a server-sent event response as a lazy async iterable.
|
|
77
|
+
*/
|
|
78
|
+
sse(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<AsyncIterable<ServerSentEvent>>;
|
|
79
|
+
/**
|
|
80
|
+
* Consume a server-sent event response with complete response metadata.
|
|
81
|
+
*/
|
|
82
|
+
sseResponse(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<NporaResponse<AsyncIterable<ServerSentEvent>>>;
|
|
83
|
+
/**
|
|
84
|
+
* Consume newline-delimited JSON records as a lazy async iterable.
|
|
85
|
+
*/
|
|
86
|
+
ndjson<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<AsyncIterable<T>>;
|
|
87
|
+
/**
|
|
88
|
+
* Consume newline-delimited JSON with complete response metadata.
|
|
89
|
+
*/
|
|
90
|
+
ndjsonResponse<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<NporaResponse<AsyncIterable<T>>>;
|
|
91
|
+
private requestMethod;
|
|
92
|
+
private requestMethodResponse;
|
|
93
|
+
private mergeMethodConfig;
|
|
94
|
+
private createPipeline;
|
|
95
|
+
private validatePlugin;
|
|
96
|
+
private findDependent;
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/client/createClient.d.ts
|
|
100
|
+
/**
|
|
101
|
+
* Create an HTTP client instance.
|
|
102
|
+
*/
|
|
103
|
+
declare function createClient(options?: ClientOptions): Client;
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/adapters/FetchAdapter.d.ts
|
|
106
|
+
declare class FetchAdapter implements Adapter {
|
|
107
|
+
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
108
|
+
requestValidated<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
|
|
109
|
+
private execute;
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/errors/RequestError.d.ts
|
|
113
|
+
/**
|
|
114
|
+
* Public request error codes.
|
|
115
|
+
*/
|
|
116
|
+
type RequestErrorCode = 'CONFIG_ERROR' | 'HTTP_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'ABORT_ERROR' | 'PARSER_ERROR' | 'SCHEMA_ERROR' | 'REQUEST_TOO_LARGE' | 'RESPONSE_TOO_LARGE' | 'CIRCUIT_OPEN' | 'CONCURRENCY_LIMIT';
|
|
117
|
+
interface RequestErrorOptions<T = unknown> {
|
|
118
|
+
/**
|
|
119
|
+
* Stable machine-readable error code.
|
|
120
|
+
*/
|
|
121
|
+
code: RequestErrorCode;
|
|
122
|
+
/**
|
|
123
|
+
* HTTP response status when available.
|
|
124
|
+
*/
|
|
125
|
+
status?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Parsed response body when the server returned a response.
|
|
128
|
+
*/
|
|
129
|
+
data?: T;
|
|
130
|
+
/**
|
|
131
|
+
* Complete response metadata when the server returned a response.
|
|
132
|
+
*/
|
|
133
|
+
response?: NporaResponse<T>;
|
|
134
|
+
/**
|
|
135
|
+
* Effective request configuration.
|
|
136
|
+
*/
|
|
137
|
+
config?: RequestConfig;
|
|
138
|
+
/**
|
|
139
|
+
* Original error.
|
|
140
|
+
*/
|
|
141
|
+
cause?: unknown;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Unified public error for all request failures.
|
|
145
|
+
*/
|
|
146
|
+
declare class RequestError<T = unknown> extends Error {
|
|
147
|
+
readonly code: RequestErrorCode;
|
|
148
|
+
readonly status?: number;
|
|
149
|
+
readonly data?: T;
|
|
150
|
+
readonly response?: NporaResponse<T>;
|
|
151
|
+
readonly config?: RequestConfig;
|
|
152
|
+
readonly cause?: unknown;
|
|
153
|
+
constructor(message: string, options: RequestErrorOptions<T>);
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/errors/SchemaValidationError.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* Response failure reported by a Standard Schema compatible validator.
|
|
159
|
+
*/
|
|
160
|
+
declare class SchemaValidationError<T = unknown> extends RequestError<T> {
|
|
161
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
162
|
+
readonly schemaVendor: string;
|
|
163
|
+
constructor(message: string, response: NporaResponse<T>, schemaVendor: string, issues?: ReadonlyArray<StandardSchemaV1.Issue>, cause?: unknown);
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
export { FetchAdapter as a, ClientOptions as c, RequestErrorOptions as i, RequestError as n, createClient as o, RequestErrorCode as r, Client as s, SchemaValidationError as t };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { A as StandardSchemaV1, n as ServerSentEvent, o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.cjs";
|
|
2
|
+
import { t as Adapter } from "./adapter-BeVVCcNG.cjs";
|
|
3
|
+
import { s as InterceptorManager, t as Plugin } from "./Plugin-YysllE6z.cjs";
|
|
4
|
+
//#region src/types/client.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Client creation options.
|
|
7
|
+
*/
|
|
8
|
+
interface ClientOptions extends Partial<Omit<RequestConfig, 'url' | 'method' | 'schema'>> {
|
|
9
|
+
/**
|
|
10
|
+
* Request adapter.
|
|
11
|
+
*
|
|
12
|
+
* @default FetchAdapter
|
|
13
|
+
*/
|
|
14
|
+
adapter?: Adapter;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/client/Client.d.ts
|
|
18
|
+
type MethodConfig = Omit<RequestConfig, 'url' | 'method'>;
|
|
19
|
+
type SchemaMethodConfig<Schema extends StandardSchemaV1> = Omit<MethodConfig, 'schema'> & {
|
|
20
|
+
schema: Schema;
|
|
21
|
+
};
|
|
22
|
+
declare class Client {
|
|
23
|
+
private readonly defaults;
|
|
24
|
+
private readonly adapter;
|
|
25
|
+
private readonly installedPlugins;
|
|
26
|
+
private readonly hooks;
|
|
27
|
+
readonly interceptors: {
|
|
28
|
+
request: InterceptorManager<RequestConfig>;
|
|
29
|
+
response: InterceptorManager<NporaResponse<unknown>>;
|
|
30
|
+
error: InterceptorManager<unknown>;
|
|
31
|
+
};
|
|
32
|
+
private readonly pipeline;
|
|
33
|
+
constructor(options?: ClientOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Create an isolated client that inherits this client's defaults.
|
|
36
|
+
*/
|
|
37
|
+
extend(options?: ClientOptions): Client;
|
|
38
|
+
use(plugin: Plugin): this;
|
|
39
|
+
unuse(pluginName: string): this;
|
|
40
|
+
hasPlugin(pluginName: string): boolean;
|
|
41
|
+
request<Schema extends StandardSchemaV1>(config: RequestConfig & {
|
|
42
|
+
schema: Schema;
|
|
43
|
+
}): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
44
|
+
request<T = unknown>(config: RequestConfig): Promise<T>;
|
|
45
|
+
requestResponse<Schema extends StandardSchemaV1>(config: RequestConfig & {
|
|
46
|
+
schema: Schema;
|
|
47
|
+
}): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
48
|
+
requestResponse<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
49
|
+
get<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
50
|
+
get<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
51
|
+
getResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
52
|
+
getResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
53
|
+
post<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
54
|
+
post<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
55
|
+
postResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
56
|
+
postResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
57
|
+
put<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
58
|
+
put<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
59
|
+
putResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
60
|
+
putResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
61
|
+
patch<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
62
|
+
patch<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
63
|
+
patchResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
64
|
+
patchResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
65
|
+
delete<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
66
|
+
delete<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
67
|
+
deleteResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
68
|
+
deleteResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
69
|
+
head(url: string, config?: Omit<MethodConfig, 'schema'>): Promise<void>;
|
|
70
|
+
headResponse(url: string, config?: Omit<MethodConfig, 'schema'>): Promise<NporaResponse<void>>;
|
|
71
|
+
options<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<StandardSchemaV1.InferOutput<Schema>>;
|
|
72
|
+
options<T = unknown>(url: string, config?: MethodConfig): Promise<T>;
|
|
73
|
+
optionsResponse<Schema extends StandardSchemaV1>(url: string, config: SchemaMethodConfig<Schema>): Promise<NporaResponse<StandardSchemaV1.InferOutput<Schema>>>;
|
|
74
|
+
optionsResponse<T = unknown>(url: string, config?: MethodConfig): Promise<NporaResponse<T>>;
|
|
75
|
+
/**
|
|
76
|
+
* Consume a server-sent event response as a lazy async iterable.
|
|
77
|
+
*/
|
|
78
|
+
sse(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<AsyncIterable<ServerSentEvent>>;
|
|
79
|
+
/**
|
|
80
|
+
* Consume a server-sent event response with complete response metadata.
|
|
81
|
+
*/
|
|
82
|
+
sseResponse(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<NporaResponse<AsyncIterable<ServerSentEvent>>>;
|
|
83
|
+
/**
|
|
84
|
+
* Consume newline-delimited JSON records as a lazy async iterable.
|
|
85
|
+
*/
|
|
86
|
+
ndjson<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<AsyncIterable<T>>;
|
|
87
|
+
/**
|
|
88
|
+
* Consume newline-delimited JSON with complete response metadata.
|
|
89
|
+
*/
|
|
90
|
+
ndjsonResponse<T = unknown>(url: string, config?: Omit<RequestConfig, 'url' | 'method' | 'responseType' | 'schema'>): Promise<NporaResponse<AsyncIterable<T>>>;
|
|
91
|
+
private requestMethod;
|
|
92
|
+
private requestMethodResponse;
|
|
93
|
+
private mergeMethodConfig;
|
|
94
|
+
private createPipeline;
|
|
95
|
+
private validatePlugin;
|
|
96
|
+
private findDependent;
|
|
97
|
+
}
|
|
98
|
+
//#endregion
|
|
99
|
+
//#region src/client/createClient.d.ts
|
|
100
|
+
/**
|
|
101
|
+
* Create an HTTP client instance.
|
|
102
|
+
*/
|
|
103
|
+
declare function createClient(options?: ClientOptions): Client;
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/adapters/FetchAdapter.d.ts
|
|
106
|
+
declare class FetchAdapter implements Adapter {
|
|
107
|
+
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
108
|
+
requestValidated<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
|
|
109
|
+
private execute;
|
|
110
|
+
}
|
|
111
|
+
//#endregion
|
|
112
|
+
//#region src/errors/RequestError.d.ts
|
|
113
|
+
/**
|
|
114
|
+
* Public request error codes.
|
|
115
|
+
*/
|
|
116
|
+
type RequestErrorCode = 'CONFIG_ERROR' | 'HTTP_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT_ERROR' | 'ABORT_ERROR' | 'PARSER_ERROR' | 'SCHEMA_ERROR' | 'REQUEST_TOO_LARGE' | 'RESPONSE_TOO_LARGE' | 'CIRCUIT_OPEN' | 'CONCURRENCY_LIMIT';
|
|
117
|
+
interface RequestErrorOptions<T = unknown> {
|
|
118
|
+
/**
|
|
119
|
+
* Stable machine-readable error code.
|
|
120
|
+
*/
|
|
121
|
+
code: RequestErrorCode;
|
|
122
|
+
/**
|
|
123
|
+
* HTTP response status when available.
|
|
124
|
+
*/
|
|
125
|
+
status?: number;
|
|
126
|
+
/**
|
|
127
|
+
* Parsed response body when the server returned a response.
|
|
128
|
+
*/
|
|
129
|
+
data?: T;
|
|
130
|
+
/**
|
|
131
|
+
* Complete response metadata when the server returned a response.
|
|
132
|
+
*/
|
|
133
|
+
response?: NporaResponse<T>;
|
|
134
|
+
/**
|
|
135
|
+
* Effective request configuration.
|
|
136
|
+
*/
|
|
137
|
+
config?: RequestConfig;
|
|
138
|
+
/**
|
|
139
|
+
* Original error.
|
|
140
|
+
*/
|
|
141
|
+
cause?: unknown;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Unified public error for all request failures.
|
|
145
|
+
*/
|
|
146
|
+
declare class RequestError<T = unknown> extends Error {
|
|
147
|
+
readonly code: RequestErrorCode;
|
|
148
|
+
readonly status?: number;
|
|
149
|
+
readonly data?: T;
|
|
150
|
+
readonly response?: NporaResponse<T>;
|
|
151
|
+
readonly config?: RequestConfig;
|
|
152
|
+
readonly cause?: unknown;
|
|
153
|
+
constructor(message: string, options: RequestErrorOptions<T>);
|
|
154
|
+
}
|
|
155
|
+
//#endregion
|
|
156
|
+
//#region src/errors/SchemaValidationError.d.ts
|
|
157
|
+
/**
|
|
158
|
+
* Response failure reported by a Standard Schema compatible validator.
|
|
159
|
+
*/
|
|
160
|
+
declare class SchemaValidationError<T = unknown> extends RequestError<T> {
|
|
161
|
+
readonly issues: ReadonlyArray<StandardSchemaV1.Issue>;
|
|
162
|
+
readonly schemaVendor: string;
|
|
163
|
+
constructor(message: string, response: NporaResponse<T>, schemaVendor: string, issues?: ReadonlyArray<StandardSchemaV1.Issue>, cause?: unknown);
|
|
164
|
+
}
|
|
165
|
+
//#endregion
|
|
166
|
+
export { FetchAdapter as a, ClientOptions as c, RequestErrorOptions as i, RequestError as n, createClient as o, RequestErrorCode as r, Client as s, SchemaValidationError as t };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.cjs";
|
|
2
|
+
//#region src/types/adapter.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Request adapter.
|
|
5
|
+
*/
|
|
6
|
+
interface Adapter {
|
|
7
|
+
/**
|
|
8
|
+
* Send request.
|
|
9
|
+
*/
|
|
10
|
+
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
11
|
+
/**
|
|
12
|
+
* Optional first-attempt fast path for built-in adapters.
|
|
13
|
+
*
|
|
14
|
+
* Custom adapters do not need to implement this method.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
requestValidated?<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Adapter as t };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { o as RequestConfig, t as NporaResponse } from "./response-BhyS3PAL.js";
|
|
2
|
+
//#region src/types/adapter.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Request adapter.
|
|
5
|
+
*/
|
|
6
|
+
interface Adapter {
|
|
7
|
+
/**
|
|
8
|
+
* Send request.
|
|
9
|
+
*/
|
|
10
|
+
request<T = unknown>(config: RequestConfig): Promise<NporaResponse<T>>;
|
|
11
|
+
/**
|
|
12
|
+
* Optional first-attempt fast path for built-in adapters.
|
|
13
|
+
*
|
|
14
|
+
* Custom adapters do not need to implement this method.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
requestValidated?<T = unknown>(config: RequestConfig, validatedHeaders: Headers, preserveRaw?: boolean): Promise<NporaResponse<T>>;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { Adapter as t };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { t as Plugin } from "./Plugin-0Eh51_et.js";
|
|
2
|
+
//#region src/plugins/authPlugin.d.ts
|
|
3
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
4
|
+
/**
|
|
5
|
+
* Token storage used by the authentication extension.
|
|
6
|
+
*
|
|
7
|
+
* Storage implementation is supplied by the application.
|
|
8
|
+
* The request library does not access localStorage or sessionStorage directly.
|
|
9
|
+
*/
|
|
10
|
+
interface AuthTokenStorage {
|
|
11
|
+
get(): MaybePromise<string | null | undefined>;
|
|
12
|
+
set(token: string): MaybePromise<void>;
|
|
13
|
+
remove(): MaybePromise<void>;
|
|
14
|
+
}
|
|
15
|
+
interface AuthPluginOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Access token or access-token provider.
|
|
18
|
+
*
|
|
19
|
+
* When both token and storage are provided,
|
|
20
|
+
* the request-level token has the highest priority,
|
|
21
|
+
* followed by this token option, then storage.
|
|
22
|
+
*/
|
|
23
|
+
token?: string | (() => MaybePromise<string>);
|
|
24
|
+
/**
|
|
25
|
+
* Authorization scheme.
|
|
26
|
+
*
|
|
27
|
+
* @default 'Bearer'
|
|
28
|
+
*/
|
|
29
|
+
scheme?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Optional access-token storage.
|
|
32
|
+
*/
|
|
33
|
+
storage?: AuthTokenStorage;
|
|
34
|
+
/**
|
|
35
|
+
* Refresh the access token.
|
|
36
|
+
*
|
|
37
|
+
* Returning a token stores it through storage when configured.
|
|
38
|
+
* Returning void allows the callback to update external state itself.
|
|
39
|
+
*/
|
|
40
|
+
refreshToken?: () => MaybePromise<string | void>;
|
|
41
|
+
/**
|
|
42
|
+
* Determine whether an error should trigger token refresh.
|
|
43
|
+
*
|
|
44
|
+
* @default HTTP status 401
|
|
45
|
+
*/
|
|
46
|
+
shouldRefresh?: (error: unknown) => MaybePromise<boolean>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Authentication plugin.
|
|
50
|
+
*/
|
|
51
|
+
declare function authPlugin(options?: AuthPluginOptions): Plugin;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { AuthTokenStorage as n, authPlugin as r, AuthPluginOptions as t };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { t as Plugin } from "./Plugin-YysllE6z.cjs";
|
|
2
|
+
//#region src/plugins/authPlugin.d.ts
|
|
3
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
4
|
+
/**
|
|
5
|
+
* Token storage used by the authentication extension.
|
|
6
|
+
*
|
|
7
|
+
* Storage implementation is supplied by the application.
|
|
8
|
+
* The request library does not access localStorage or sessionStorage directly.
|
|
9
|
+
*/
|
|
10
|
+
interface AuthTokenStorage {
|
|
11
|
+
get(): MaybePromise<string | null | undefined>;
|
|
12
|
+
set(token: string): MaybePromise<void>;
|
|
13
|
+
remove(): MaybePromise<void>;
|
|
14
|
+
}
|
|
15
|
+
interface AuthPluginOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Access token or access-token provider.
|
|
18
|
+
*
|
|
19
|
+
* When both token and storage are provided,
|
|
20
|
+
* the request-level token has the highest priority,
|
|
21
|
+
* followed by this token option, then storage.
|
|
22
|
+
*/
|
|
23
|
+
token?: string | (() => MaybePromise<string>);
|
|
24
|
+
/**
|
|
25
|
+
* Authorization scheme.
|
|
26
|
+
*
|
|
27
|
+
* @default 'Bearer'
|
|
28
|
+
*/
|
|
29
|
+
scheme?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Optional access-token storage.
|
|
32
|
+
*/
|
|
33
|
+
storage?: AuthTokenStorage;
|
|
34
|
+
/**
|
|
35
|
+
* Refresh the access token.
|
|
36
|
+
*
|
|
37
|
+
* Returning a token stores it through storage when configured.
|
|
38
|
+
* Returning void allows the callback to update external state itself.
|
|
39
|
+
*/
|
|
40
|
+
refreshToken?: () => MaybePromise<string | void>;
|
|
41
|
+
/**
|
|
42
|
+
* Determine whether an error should trigger token refresh.
|
|
43
|
+
*
|
|
44
|
+
* @default HTTP status 401
|
|
45
|
+
*/
|
|
46
|
+
shouldRefresh?: (error: unknown) => MaybePromise<boolean>;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Authentication plugin.
|
|
50
|
+
*/
|
|
51
|
+
declare function authPlugin(options?: AuthPluginOptions): Plugin;
|
|
52
|
+
//#endregion
|
|
53
|
+
export { AuthTokenStorage as n, authPlugin as r, AuthPluginOptions as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./RequestError-DPSv-HVF.cjs"),t=require("./isURLSearchParams-o-c8Q42t.cjs");function createTimeoutSignal(t,n){if(!n||n<=0||t?.aborted)return{signal:t,clear:noop$1};let r=new AbortController,i,onAbort,clear=()=>{if(i!==void 0&&(clearTimeout(i),i=void 0),t&&onAbort){try{t.removeEventListener(`abort`,onAbort)}catch{}onAbort=void 0}};if(t){onAbort=()=>{clear(),r.abort(t.reason??new e.t(`Request aborted`,{code:`ABORT_ERROR`}))};try{t.addEventListener(`abort`,onAbort,{once:!0})}catch(e){throw clear(),e}if(r.signal.aborted)return{signal:r.signal,clear}}try{i=setTimeout(()=>{clear(),r.abort(new e.t(`Request timeout after ${n}ms`,{code:`TIMEOUT_ERROR`}))},n)}catch(e){throw clear(),e}return r.signal.aborted&&clear(),{signal:r.signal,clear}}function noop$1(){}const n=Object.prototype.hasOwnProperty;function buildRequest(e){return buildRequestWithHeaders(e,new Headers(e.headers))}function buildRequestWithHeaders(e,t){let n=buildBody(e,t);validateRequestBodySize(n,e);let r=buildURL(e),i={...e.fetchOptions,method:e.method??`GET`,headers:t,body:n,signal:e.signal};n&&typeof ReadableStream<`u`&&n instanceof ReadableStream&&(i.duplex=`half`);let a=e.timeout&&e.timeout>0?createTimeoutSignal(e.signal,e.timeout):void 0;return a&&(i.signal=a.signal),{url:r,init:i,clear:a?.clear??noop}}function buildURL(e){let t=joinURL(e.baseURL,e.url);if(!e.query&&!e.searchParams)return t;let n=e.searchParams?e.searchParams.toString():stringifyQuery(e.query);if(!n)return t;let r=t.indexOf(`#`),i=r===-1?t:t.slice(0,r),a=r===-1?``:t.slice(r);return`${i}${i.includes(`?`)?`&`:`?`}${n}${a}`}function joinURL(e,t){if(!e||isAbsoluteURL(t))return t;if(!t)return e;let n=e.length,r=0;for(;n>0&&e.charCodeAt(n-1)===47;)--n;for(;r<t.length&&t.charCodeAt(r)===47;)r+=1;return`${e.slice(0,n)}/${t.slice(r)}`}function isAbsoluteURL(e){if(e.startsWith(`//`))return!0;let t=e.indexOf(`:`);return t<=0?!1:/^[a-z][a-z\d+\-.]*$/i.test(e.slice(0,t))}function stringifyQuery(e){let t=new URLSearchParams;for(let r in e)n.call(e,r)&&appendQuery(t,r,e[r]);return t.toString()}function appendQuery(e,t,n){if(n!==void 0){if(n===null){e.append(t,``);return}if(Array.isArray(n)){for(let r of n)r!==void 0&&e.append(t,r===null?``:String(r));return}e.append(t,String(n))}}function buildBody(e,t){if(e.json!==void 0)return setContentType(t,`application/json`),JSON.stringify(e.json);if(e.form!==void 0)return setContentType(t,`application/x-www-form-urlencoded;charset=UTF-8`),buildURLSearchParams(e.form);if(e.formData!==void 0)return buildFormData(e.formData,e.maxFormDataDepth);if(e.body!==null&&e.body!==void 0)return isPlainObject(e.body)?(setContentType(t,`application/json`),JSON.stringify(e.body)):e.body}function buildURLSearchParams(e){if(t.t(e))return e;let r=new URLSearchParams;for(let t in e)n.call(e,t)&&appendQuery(r,t,e[t]);return r}function buildFormData(e,t=32){if(e instanceof FormData)return e;let r=new FormData,i=new WeakSet;for(let a in e)n.call(e,a)&&appendFormDataValue(r,a,e[a],0,t,i);return r}function appendFormDataValue(e,t,n,r,i,a){if(n!=null){if(Array.isArray(n)){if(a.has(n))throw TypeError(`FormData arrays cannot contain circular references`);let o=r+1;if(o>i)throw RangeError(`FormData array depth exceeds maxFormDataDepth ${i}`);a.add(n);try{for(let r of n)appendFormDataValue(e,t,r,o,i,a)}finally{a.delete(n)}return}if(n instanceof Blob){e.append(t,n);return}e.append(t,String(n))}}function setContentType(e,t){e.has(`content-type`)||e.set(`content-type`,t)}function validateRequestBodySize(t,n){let r=n.maxRequestSize;if(!Number.isFinite(r)||t===void 0)return;let i=getRequestBodySize(t);if(i!==void 0&&i>(r??1/0))throw new e.t(`Request body exceeds maxRequestSize ${r}`,{code:`REQUEST_TOO_LARGE`,config:n})}function getRequestBodySize(e){if(typeof e==`string`)return utf8ByteLength(e);if(t.t(e))return utf8ByteLength(e.toString());if(typeof Blob<`u`&&e instanceof Blob)return e.size;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return e.byteLength}function utf8ByteLength(e){let t=0;for(let n=0;n<e.length;n+=1){let r=e.charCodeAt(n);if(r<128)t+=1;else if(r<2048)t+=2;else if(r>=55296&&r<=56319&&n+1<e.length){let r=e.charCodeAt(n+1);r>=56320&&r<=57343?(t+=4,n+=1):t+=3}else t+=3}return t}function isPlainObject(e){return Object.prototype.toString.call(e)===`[object Object]`}function noop(){}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return n}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return buildRequestWithHeaders}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return isAbsoluteURL}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return buildRequest}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{t as e}from"./RequestError-BH6V64XR.js";import{t}from"./isURLSearchParams-B93cMCGj.js";function createTimeoutSignal(t,n){if(!n||n<=0||t?.aborted)return{signal:t,clear:noop$1};let r=new AbortController,i,onAbort,clear=()=>{if(i!==void 0&&(clearTimeout(i),i=void 0),t&&onAbort){try{t.removeEventListener(`abort`,onAbort)}catch{}onAbort=void 0}};if(t){onAbort=()=>{clear(),r.abort(t.reason??new e(`Request aborted`,{code:`ABORT_ERROR`}))};try{t.addEventListener(`abort`,onAbort,{once:!0})}catch(e){throw clear(),e}if(r.signal.aborted)return{signal:r.signal,clear}}try{i=setTimeout(()=>{clear(),r.abort(new e(`Request timeout after ${n}ms`,{code:`TIMEOUT_ERROR`}))},n)}catch(e){throw clear(),e}return r.signal.aborted&&clear(),{signal:r.signal,clear}}function noop$1(){}const n=Object.prototype.hasOwnProperty;function buildRequest(e){return buildRequestWithHeaders(e,new Headers(e.headers))}function buildRequestWithHeaders(e,t){let n=buildBody(e,t);validateRequestBodySize(n,e);let r=buildURL(e),i={...e.fetchOptions,method:e.method??`GET`,headers:t,body:n,signal:e.signal};n&&typeof ReadableStream<`u`&&n instanceof ReadableStream&&(i.duplex=`half`);let a=e.timeout&&e.timeout>0?createTimeoutSignal(e.signal,e.timeout):void 0;return a&&(i.signal=a.signal),{url:r,init:i,clear:a?.clear??noop}}function buildURL(e){let t=joinURL(e.baseURL,e.url);if(!e.query&&!e.searchParams)return t;let n=e.searchParams?e.searchParams.toString():stringifyQuery(e.query);if(!n)return t;let r=t.indexOf(`#`),i=r===-1?t:t.slice(0,r),a=r===-1?``:t.slice(r);return`${i}${i.includes(`?`)?`&`:`?`}${n}${a}`}function joinURL(e,t){if(!e||isAbsoluteURL(t))return t;if(!t)return e;let n=e.length,r=0;for(;n>0&&e.charCodeAt(n-1)===47;)--n;for(;r<t.length&&t.charCodeAt(r)===47;)r+=1;return`${e.slice(0,n)}/${t.slice(r)}`}function isAbsoluteURL(e){if(e.startsWith(`//`))return!0;let t=e.indexOf(`:`);return t<=0?!1:/^[a-z][a-z\d+\-.]*$/i.test(e.slice(0,t))}function stringifyQuery(e){let t=new URLSearchParams;for(let r in e)n.call(e,r)&&appendQuery(t,r,e[r]);return t.toString()}function appendQuery(e,t,n){if(n!==void 0){if(n===null){e.append(t,``);return}if(Array.isArray(n)){for(let r of n)r!==void 0&&e.append(t,r===null?``:String(r));return}e.append(t,String(n))}}function buildBody(e,t){if(e.json!==void 0)return setContentType(t,`application/json`),JSON.stringify(e.json);if(e.form!==void 0)return setContentType(t,`application/x-www-form-urlencoded;charset=UTF-8`),buildURLSearchParams(e.form);if(e.formData!==void 0)return buildFormData(e.formData,e.maxFormDataDepth);if(e.body!==null&&e.body!==void 0)return isPlainObject(e.body)?(setContentType(t,`application/json`),JSON.stringify(e.body)):e.body}function buildURLSearchParams(e){if(t(e))return e;let r=new URLSearchParams;for(let t in e)n.call(e,t)&&appendQuery(r,t,e[t]);return r}function buildFormData(e,t=32){if(e instanceof FormData)return e;let r=new FormData,i=new WeakSet;for(let a in e)n.call(e,a)&&appendFormDataValue(r,a,e[a],0,t,i);return r}function appendFormDataValue(e,t,n,r,i,a){if(n!=null){if(Array.isArray(n)){if(a.has(n))throw TypeError(`FormData arrays cannot contain circular references`);let o=r+1;if(o>i)throw RangeError(`FormData array depth exceeds maxFormDataDepth ${i}`);a.add(n);try{for(let r of n)appendFormDataValue(e,t,r,o,i,a)}finally{a.delete(n)}return}if(n instanceof Blob){e.append(t,n);return}e.append(t,String(n))}}function setContentType(e,t){e.has(`content-type`)||e.set(`content-type`,t)}function validateRequestBodySize(t,n){let r=n.maxRequestSize;if(!Number.isFinite(r)||t===void 0)return;let i=getRequestBodySize(t);if(i!==void 0&&i>(r??1/0))throw new e(`Request body exceeds maxRequestSize ${r}`,{code:`REQUEST_TOO_LARGE`,config:n})}function getRequestBodySize(e){if(typeof e==`string`)return utf8ByteLength(e);if(t(e))return utf8ByteLength(e.toString());if(typeof Blob<`u`&&e instanceof Blob)return e.size;if(e instanceof ArrayBuffer||ArrayBuffer.isView(e))return e.byteLength}function utf8ByteLength(e){let t=0;for(let n=0;n<e.length;n+=1){let r=e.charCodeAt(n);if(r<128)t+=1;else if(r<2048)t+=2;else if(r>=55296&&r<=56319&&n+1<e.length){let r=e.charCodeAt(n+1);r>=56320&&r<=57343?(t+=4,n+=1):t+=3}else t+=3}return t}function isPlainObject(e){return Object.prototype.toString.call(e)===`[object Object]`}function noop(){}export{n as i,buildRequestWithHeaders as n,isAbsoluteURL as r,buildRequest as t};
|