@ahoo-wang/fetcher 3.0.3 → 3.0.6
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/fetcher.d.ts +3 -3
- package/dist/fetcher.d.ts.map +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/types.d.ts +80 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/urlBuilder.d.ts +2 -2
- package/dist/urlBuilder.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Fetcher } from './fetcher';
|
|
1
2
|
/**
|
|
2
3
|
* Creates a new type by making specified properties of an existing type optional.
|
|
3
4
|
*
|
|
@@ -179,5 +180,84 @@ declare global {
|
|
|
179
180
|
json<T = any>(): Promise<T>;
|
|
180
181
|
}
|
|
181
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Interface for configuring Fetcher instances.
|
|
185
|
+
*
|
|
186
|
+
* This interface defines a contract for objects that can configure a Fetcher instance
|
|
187
|
+
* with specific interceptors, middleware, or other customizations. Implementations of
|
|
188
|
+
* this interface provide a standardized way to apply configuration to Fetcher objects,
|
|
189
|
+
* enabling modular and reusable configuration patterns.
|
|
190
|
+
*
|
|
191
|
+
* @interface FetcherConfigurer
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* class AuthConfigurer implements FetcherConfigurer {
|
|
196
|
+
* configure(fetcher: Fetcher): void {
|
|
197
|
+
* // Add authentication interceptors
|
|
198
|
+
* fetcher.interceptors.request.use(new AuthRequestInterceptor());
|
|
199
|
+
* fetcher.interceptors.response.use(new AuthResponseInterceptor());
|
|
200
|
+
* }
|
|
201
|
+
* }
|
|
202
|
+
*
|
|
203
|
+
* // Usage
|
|
204
|
+
* const fetcher = new Fetcher({ baseURL: '/api' });
|
|
205
|
+
* const configurer = new AuthConfigurer();
|
|
206
|
+
* configurer.configure(fetcher);
|
|
207
|
+
* ```
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* ```typescript
|
|
211
|
+
* // Multiple configurers can be applied
|
|
212
|
+
* const configurers: FetcherConfigurer[] = [
|
|
213
|
+
* new AuthConfigurer(),
|
|
214
|
+
* new LoggingConfigurer(),
|
|
215
|
+
* new RetryConfigurer()
|
|
216
|
+
* ];
|
|
217
|
+
*
|
|
218
|
+
* const fetcher = new Fetcher({ baseURL: '/api' });
|
|
219
|
+
* configurers.forEach(configurer => configurer.configure(fetcher));
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
export interface FetcherConfigurer {
|
|
223
|
+
/**
|
|
224
|
+
* Applies configuration to the provided Fetcher instance.
|
|
225
|
+
*
|
|
226
|
+
* This method should apply all necessary configuration to the Fetcher instance,
|
|
227
|
+
* such as adding interceptors, setting default headers, or configuring other
|
|
228
|
+
* behavior. The method should be idempotent - calling it multiple times on
|
|
229
|
+
* the same Fetcher instance should not cause issues.
|
|
230
|
+
*
|
|
231
|
+
* @param fetcher - The Fetcher instance to configure
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* applyTo(fetcher: Fetcher): void {
|
|
236
|
+
* // Add request interceptor for authentication
|
|
237
|
+
* fetcher.interceptors.request.use({
|
|
238
|
+
* onFulfilled: config => {
|
|
239
|
+
* config.headers = {
|
|
240
|
+
* ...config.headers,
|
|
241
|
+
* 'Authorization': `Bearer ${getToken()}`
|
|
242
|
+
* };
|
|
243
|
+
* return config;
|
|
244
|
+
* }
|
|
245
|
+
* });
|
|
246
|
+
*
|
|
247
|
+
* // Add response interceptor for error handling
|
|
248
|
+
* fetcher.interceptors.response.use({
|
|
249
|
+
* onRejected: error => {
|
|
250
|
+
* if (error.response?.status === 401) {
|
|
251
|
+
* // Handle unauthorized
|
|
252
|
+
* redirectToLogin();
|
|
253
|
+
* }
|
|
254
|
+
* return Promise.reject(error);
|
|
255
|
+
* }
|
|
256
|
+
* });
|
|
257
|
+
* }
|
|
258
|
+
* ```
|
|
259
|
+
*/
|
|
260
|
+
applyTo(fetcher: Fetcher): void;
|
|
261
|
+
}
|
|
182
262
|
export {};
|
|
183
263
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAE/E;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GACvD,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;AAEvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI;KACnC,CAAC,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,GACjE,KAAK,GACL,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CACb,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC,IACb,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAA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F;;;;;;;;;;;;;GAaG;AACH,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC,IACb,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,GAC/D,IAAI,GACJ,KAAK,CAAC;AAEZ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;GASG;AACH,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,QAAQ;QAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WAwCG;QACH,IAAI,CAAC,CAAC,GAAG,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;KAC7B;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;CACjC"}
|
package/dist/urlBuilder.d.ts
CHANGED
|
@@ -54,8 +54,8 @@ export declare class UrlBuilder implements BaseURLCapable {
|
|
|
54
54
|
*
|
|
55
55
|
* This is typically the root of your API endpoint (e.g., 'https://api.example.com').
|
|
56
56
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
baseURL: string;
|
|
58
|
+
urlTemplateResolver: UrlTemplateResolver;
|
|
59
59
|
/**
|
|
60
60
|
* Initializes a new UrlBuilder instance.
|
|
61
61
|
*
|
package/dist/urlBuilder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlBuilder.d.ts","sourceRoot":"","sources":["../src/urlBuilder.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK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;;;;;;;OAQG;IACH,iBAAiB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;CAGjD;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,UAAU,EAAE,UAAU,CAAC;CACxB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ahoo-wang/fetcher",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"description": "Fetcher is not just another HTTP client—it's a complete ecosystem designed for modern web development with native LLM\nstreaming API support. Built on the native Fetch API, Fetcher provides an Axios-like experience with powerful features\nwhile maintaining an incredibly small footprint.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fetch",
|