@zayne-labs/callapi-plugins 4.0.26 → 4.0.28

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.
Files changed (2) hide show
  1. package/dist/index.d.ts +975 -1003
  2. package/package.json +7 -7
package/dist/index.d.ts CHANGED
@@ -10,7 +10,7 @@ declare const fallBackRouteSchemaKey = "@default";
10
10
  type FallBackRouteSchemaKey = typeof fallBackRouteSchemaKey;
11
11
  //#endregion
12
12
  //#endregion
13
- //#region ../callapi/dist/validation-BeCBQ6_6.d.ts
13
+ //#region ../callapi/dist/index-j55-O6zR.d.ts
14
14
  //#region src/types/type-helpers.d.ts
15
15
  type AnyString = string & NonNullable<unknown>;
16
16
  type AnyNumber = number & NonNullable<unknown>;
@@ -75,948 +75,708 @@ type CustomAuth = {
75
75
  };
76
76
  type Auth = PossibleAuthValueOrGetter | BearerOrTokenAuth | BasicAuth | CustomAuth;
77
77
  //#endregion
78
- //#region src/utils/external/body.d.ts
79
-
80
- //#endregion
81
- //#region src/types/default-types.d.ts
82
- type DefaultDataType = unknown;
83
- type DefaultPluginArray = CallApiPlugin[];
84
- type DefaultThrowOnError = boolean;
85
- //#endregion
86
- //#region src/types/standard-schema.d.ts
87
- /**
88
- * The Standard Schema interface.
89
- * @see https://github.com/standard-schema/standard-schema
90
- */
91
- interface StandardSchemaV1<Input$1 = unknown, Output$1 = Input$1> {
92
- /**
93
- * The Standard Schema properties.
94
- */
95
- readonly "~standard": StandardSchemaV1.Props<Input$1, Output$1>;
96
- }
97
- declare namespace StandardSchemaV1 {
98
- /**
99
- * The Standard Schema properties interface.
100
- */
101
- interface Props<Input = unknown, Output = Input> {
102
- /**
103
- * Inferred types associated with the schema.
104
- */
105
- readonly types?: Types<Input, Output> | undefined;
106
- /**
107
- * Validates unknown input values.
108
- */
109
- readonly validate: (value: unknown) => Promise<Result<Output>> | Result<Output>;
110
- /**
111
- * The vendor name of the schema library.
112
- */
113
- readonly vendor: string;
114
- /**
115
- * The version number of the standard.
116
- */
117
- readonly version: 1;
118
- }
119
- /**
120
- * The result interface of the validate function.
121
- */
122
- type Result<Output> = FailureResult | SuccessResult<Output>;
123
- /**
124
- * The result interface if validation succeeds.
125
- */
126
- interface SuccessResult<Output> {
127
- /**
128
- * The non-existent issues.
129
- */
130
- readonly issues?: undefined;
131
- /**
132
- * The typed output value.
133
- */
134
- readonly value: Output;
135
- }
136
- /**
137
- * The result interface if validation fails.
138
- */
139
- interface FailureResult {
140
- /**
141
- * The issues of failed validation.
142
- */
143
- readonly issues: readonly Issue[];
144
- }
145
- /**
146
- * The issue interface of the failure output.
147
- */
148
- interface Issue {
149
- /**
150
- * The error message of the issue.
151
- */
152
- readonly message: string;
153
- /**
154
- * The path of the issue, if any.
155
- */
156
- readonly path?: ReadonlyArray<PathSegment | PropertyKey> | undefined;
157
- }
158
- /**
159
- * The path segment interface of the issue.
160
- */
161
- interface PathSegment {
162
- /**
163
- * The key representing a path segment.
164
- */
165
- readonly key: PropertyKey;
166
- }
167
- /**
168
- * The Standard Schema types interface.
169
- */
170
- interface Types<Input = unknown, Output = Input> {
171
- /** The input type of the schema. */
172
- readonly input: Input;
173
- /** The output type of the schema. */
174
- readonly output: Output;
175
- }
176
- /**
177
- * Infers the input type of a Standard Schema.
178
- */
179
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
180
- /**
181
- * Infers the output type of a Standard Schema.
182
- */
183
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
184
- }
185
- //#endregion
186
- //#region src/utils/external/error.d.ts
187
- type HTTPErrorDetails<TErrorData$1> = Pick<CallApiExtraOptions, "defaultHTTPErrorMessage"> & {
188
- errorData: TErrorData$1;
189
- response: Response;
190
- };
191
- declare class HTTPError<TErrorData$1 = Record<string, unknown>> extends Error {
192
- errorData: HTTPErrorDetails<TErrorData$1>["errorData"];
193
- readonly httpErrorSymbol: symbol;
194
- name: "HTTPError";
195
- response: HTTPErrorDetails<TErrorData$1>["response"];
196
- constructor(errorDetails: HTTPErrorDetails<TErrorData$1>, errorOptions?: ErrorOptions);
197
- /**
198
- * @description Checks if the given error is an instance of HTTPError
199
- * @param error - The error to check
200
- * @returns true if the error is an instance of HTTPError, false otherwise
201
- */
202
- static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData$1>;
203
- }
204
- type SafeExtract<TUnion, TKey extends TUnion> = Extract<TUnion, TKey>;
205
- type ValidationErrorDetails = {
206
- /**
207
- * The cause of the validation error.
208
- *
209
- * It's either the name the schema for which validation failed, or the name of the schema config option that led to the validation error.
210
- */
211
- issueCause: "unknown" | `schemaConfig-(${SafeExtract<keyof CallApiSchemaConfig, "strict">})` | keyof CallApiSchema;
212
- /**
213
- * The issues that caused the validation error.
214
- */
215
- issues: readonly StandardSchemaV1.Issue[];
216
- /**
217
- * The response from server, if any.
218
- */
219
- response: Response | null;
220
- };
221
- declare class ValidationError extends Error {
222
- errorData: ValidationErrorDetails["issues"];
223
- issueCause: ValidationErrorDetails["issueCause"];
224
- name: "ValidationError";
225
- response: ValidationErrorDetails["response"];
226
- readonly validationErrorSymbol: symbol;
227
- constructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions);
228
- /**
229
- * @description Checks if the given error is an instance of ValidationError
230
- * @param error - The error to check
231
- * @returns true if the error is an instance of ValidationError, false otherwise
232
- */
233
- static isError(error: unknown): error is ValidationError;
234
- }
235
- //#endregion
236
- //#region src/result.d.ts
237
- type Parser<TData$1> = (responseString: string) => Awaitable<TData$1>;
238
- declare const getResponseType: <TResponse>(response: Response, parser: Parser<TResponse>) => {
239
- arrayBuffer: () => Promise<ArrayBuffer>;
240
- blob: () => Promise<Blob>;
241
- formData: () => Promise<FormData>;
242
- json: () => Promise<TResponse>;
243
- stream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
244
- text: () => Promise<string>;
245
- };
246
- type InitResponseTypeMap<TResponse$1 = unknown> = ReturnType<typeof getResponseType<TResponse$1>>;
247
- type ResponseTypeUnion = keyof InitResponseTypeMap;
248
- type ResponseTypePlaceholder = null;
249
- type ResponseTypeType = ResponseTypePlaceholder | ResponseTypeUnion;
250
- type ResponseTypeMap<TResponse$1> = { [Key in keyof InitResponseTypeMap<TResponse$1>]: Awaited<ReturnType<InitResponseTypeMap<TResponse$1>[Key]>> };
251
- type GetResponseType<TResponse$1, TResponseType extends ResponseTypeType, TComputedResponseTypeMap extends ResponseTypeMap<TResponse$1> = ResponseTypeMap<TResponse$1>> = null extends TResponseType ? TComputedResponseTypeMap["json"] : TResponseType extends NonNullable<ResponseTypeType> ? TComputedResponseTypeMap[TResponseType] : never;
252
- type CallApiResultSuccessVariant<TData$1> = {
253
- data: NoInfer<TData$1>;
254
- error: null;
255
- response: Response;
256
- };
257
- type PossibleJavaScriptError = UnmaskType<{
258
- errorData: false;
259
- message: string;
260
- name: "AbortError" | "Error" | "SyntaxError" | "TimeoutError" | "TypeError" | AnyString;
261
- originalError: DOMException | Error | SyntaxError | TypeError;
262
- }>;
263
- type PossibleHTTPError<TErrorData$1> = UnmaskType<{
264
- errorData: NoInfer<TErrorData$1>;
265
- message: string;
266
- name: "HTTPError";
267
- originalError: HTTPError;
268
- }>;
269
- type PossibleValidationError = UnmaskType<{
270
- errorData: ValidationError["errorData"];
271
- issueCause: ValidationError["issueCause"];
272
- message: string;
273
- name: "ValidationError";
274
- originalError: ValidationError;
275
- }>;
276
- type PossibleJavaScriptOrValidationError = UnmaskType<PossibleJavaScriptError | PossibleValidationError>;
277
- type CallApiResultErrorVariant<TErrorData$1> = {
278
- data: null;
279
- error: PossibleHTTPError<TErrorData$1>;
280
- response: Response;
281
- } | {
282
- data: null;
283
- error: PossibleJavaScriptOrValidationError;
284
- response: Response | null;
285
- };
286
- type CallApiSuccessOrErrorVariant<TData$1, TError> = CallApiResultErrorVariant<TError> | CallApiResultSuccessVariant<TData$1>;
287
- type ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType extends ResponseTypeType, TComputedData = GetResponseType<TData$1, TResponseType>, TComputedErrorData = GetResponseType<TErrorData$1, TResponseType>, TComputedResult extends CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData> = CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData>> = UnmaskType<{
288
- all: TComputedResult;
289
- onlyData: TComputedResult["data"];
290
- onlyResponse: TComputedResult["response"];
291
- withoutResponse: DistributiveOmit<TComputedResult, "response">;
292
- }>;
293
- type ResultModeMapWithException<TData$1, TResponseType extends ResponseTypeType, TComputedData = GetResponseType<TData$1, TResponseType>, TComputedResult extends CallApiResultSuccessVariant<TComputedData> = CallApiResultSuccessVariant<TComputedData>> = {
294
- all: TComputedResult;
295
- onlyData: TComputedResult["data"];
296
- onlyResponse: TComputedResult["response"];
297
- withoutResponse: DistributiveOmit<TComputedResult, "response">;
298
- };
299
- type ResultModeMap<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResponseType extends ResponseTypeType = ResponseTypeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError> = TThrowOnError extends true ? ResultModeMapWithException<TData$1, TResponseType> : ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType>;
300
- type ResultModePlaceholder = null;
301
- type ResultModeUnion = keyof ResultModeMap;
302
- type ResultModeType = ResultModePlaceholder | ResultModeUnion;
303
- //#endregion
304
- //#region src/middlewares.d.ts
305
- type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
306
- interface Middlewares {
307
- /**
308
- * Wraps the fetch implementation to intercept requests at the network layer.
309
- *
310
- * Takes a context object containing the current fetch function and returns a new fetch function.
311
- * Use it to cache responses, add logging, handle offline mode, or short-circuit requests etc.
312
- * Multiple middleware compose in order: plugins → base config → per-request.
313
- *
314
- * Unlike `customFetchImpl`, middleware can call through to the original fetch.
315
- *
316
- * @example
317
- * ```ts
318
- * // Cache responses
319
- * const cache = new Map();
320
- * fetchMiddleware: (ctx) => async (input, init) => {
321
- * const key = input.toString();
322
- * if (cache.has(key)) return cache.get(key).clone();
323
- *
324
- * const response = await ctx.fetchImpl(input, init);
325
- * cache.set(key, response.clone());
326
- * return response;
327
- * }
328
- *
329
- * // Handle offline
330
- * fetchMiddleware: (ctx) => async (input, init) => {
331
- * if (!navigator.onLine) {
332
- * return new Response('{"error": "offline"}', { status: 503 });
333
- * }
334
- * return ctx.fetchImpl(input, init);
335
- * }
336
- * ```
337
- */
338
- fetchMiddleware?: (context: RequestContext & {
339
- fetchImpl: FetchImpl;
340
- }) => FetchImpl;
341
- }
342
- //#endregion
343
- //#region src/url.d.ts
344
- type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
345
- type RecordStyleParams = UnmaskType<Record<string, AllowedQueryParamValues>>;
346
- type TupleStyleParams = UnmaskType<AllowedQueryParamValues[]>;
347
- type Params = UnmaskType<RecordStyleParams | TupleStyleParams>;
348
- type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;
349
- type InitURLOrURLObject = AnyString | RouteKeyMethodsURLUnion | URL;
350
- interface URLOptions {
351
- /**
352
- * Base URL for all API requests. Will only be prepended to relative URLs.
353
- *
354
- * Absolute URLs (starting with http/https) will not be prepended by the baseURL.
355
- *
356
- * @example
357
- * ```ts
358
- * // Set base URL for all requests
359
- * baseURL: "https://api.example.com/v1"
360
- *
361
- * // Then use relative URLs in requests
362
- * callApi("/users") // → https://api.example.com/v1/users
363
- * callApi("/posts/123") // → https://api.example.com/v1/posts/123
364
- *
365
- * // Environment-specific base URLs
366
- * baseURL: process.env.NODE_ENV === "production"
367
- * ? "https://api.example.com"
368
- * : "http://localhost:3000/api"
369
- * ```
370
- */
371
- baseURL?: string;
372
- /**
373
- * Resolved request URL after processing baseURL, parameters, and query strings (readonly)
374
- *
375
- * This is the final URL that will be used for the HTTP request, computed from
376
- * baseURL, initURL, params, and query parameters.
377
- *
378
- */
379
- readonly fullURL?: string;
380
- /**
381
- * The original URL string passed to the callApi instance (readonly)
382
- *
383
- * This preserves the original URL as provided, including any method modifiers like "@get/" or "@post/".
384
- *
385
- */
386
- readonly initURL?: string;
387
- /**
388
- * The URL string after normalization, with method modifiers removed(readonly)
389
- *
390
- * Method modifiers like "@get/", "@post/" are stripped to create a clean URL
391
- * for parameter substitution and final URL construction.
392
- *
393
- */
394
- readonly initURLNormalized?: string;
395
- /**
396
- * Parameters to be substituted into URL path segments.
397
- *
398
- * Supports both object-style (named parameters) and array-style (positional parameters)
399
- * for flexible URL parameter substitution.
400
- *
401
- * @example
402
- * ```typescript
403
- * // Object-style parameters (recommended)
404
- * const namedParams: URLOptions = {
405
- * initURL: "/users/:userId/posts/:postId",
406
- * params: { userId: "123", postId: "456" }
407
- * };
408
- * // Results in: /users/123/posts/456
409
- *
410
- * // Array-style parameters (positional)
411
- * const positionalParams: URLOptions = {
412
- * initURL: "/users/:userId/posts/:postId",
413
- * params: ["123", "456"] // Maps in order: userId=123, postId=456
414
- * };
415
- * // Results in: /users/123/posts/456
416
- *
417
- * // Single parameter
418
- * const singleParam: URLOptions = {
419
- * initURL: "/users/:id",
420
- * params: { id: "user-123" }
421
- * };
422
- * // Results in: /users/user-123
423
- * ```
424
- */
425
- params?: Params;
426
- /**
427
- * Query parameters to append to the URL as search parameters.
428
- *
429
- * These will be serialized into the URL query string using standard
430
- * URL encoding practices.
431
- *
432
- * @example
433
- * ```typescript
434
- * // Basic query parameters
435
- * const queryOptions: URLOptions = {
436
- * initURL: "/users",
437
- * query: {
438
- * page: 1,
439
- * limit: 10,
440
- * search: "john doe",
441
- * active: true
442
- * }
443
- * };
444
- * // Results in: /users?page=1&limit=10&search=john%20doe&active=true
445
- *
446
- * // Filtering and sorting
447
- * const filterOptions: URLOptions = {
448
- * initURL: "/products",
449
- * query: {
450
- * category: "electronics",
451
- * minPrice: 100,
452
- * maxPrice: 500,
453
- * sortBy: "price",
454
- * order: "asc"
455
- * }
456
- * };
457
- * // Results in: /products?category=electronics&minPrice=100&maxPrice=500&sortBy=price&order=asc
458
- * ```
459
- */
460
- query?: Query;
461
- }
462
- //#endregion
463
- //#region src/plugins.d.ts
464
- type PluginSetupContext<TPluginExtraOptions = unknown> = PluginExtraOptions<TPluginExtraOptions> & RequestContext & {
465
- initURL: string;
466
- };
467
- type PluginInitResult = Partial<Omit<PluginSetupContext, "initURL" | "request"> & {
468
- initURL: InitURLOrURLObject;
469
- request: CallApiRequestOptions;
470
- }>;
471
- type PluginHooks<TData$1 = never, TErrorData$1 = never, TMoreOptions = unknown> = HooksOrHooksArray<TData$1, TErrorData$1, TMoreOptions>;
472
- interface CallApiPlugin {
473
- /**
474
- * Defines additional options that can be passed to callApi
475
- */
476
- defineExtraOptions?: (...params: never[]) => unknown;
477
- /**
478
- * A description for the plugin
479
- */
480
- description?: string;
481
- /**
482
- * Hooks for the plugin
483
- */
484
- hooks?: PluginHooks | ((context: PluginSetupContext) => Awaitable<PluginHooks>);
485
- /**
486
- * A unique id for the plugin
487
- */
488
- id: string;
489
- /**
490
- * Middlewares that for the plugin
491
- */
492
- middlewares?: Middlewares | ((context: PluginSetupContext) => Awaitable<Middlewares>);
493
- /**
494
- * A name for the plugin
495
- */
496
- name: string;
497
- /**
498
- * Base schema for the client.
499
- */
500
- schema?: BaseCallApiSchemaAndConfig;
501
- /**
502
- * A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.
503
- */
504
- setup?: (context: PluginSetupContext) => Awaitable<PluginInitResult> | Awaitable<void>;
505
- /**
506
- * A version for the plugin
507
- */
508
- version?: string;
509
- }
510
- //#endregion
511
- //#region src/utils/external/define.d.ts
512
-
513
- //#endregion
514
- //#region src/stream.d.ts
515
- type StreamProgressEvent = {
516
- /**
517
- * Current chunk of data being streamed
518
- */
519
- chunk: Uint8Array;
520
- /**
521
- * Progress in percentage
522
- */
523
- progress: number;
524
- /**
525
- * Total size of data in bytes
526
- */
527
- totalBytes: number;
78
+ //#region src/dedupe.d.ts
79
+ type DedupeStrategyUnion = UnmaskType<"cancel" | "defer" | "none">;
80
+ type DedupeOptionKeys = Exclude<keyof DedupeOptions, "dedupe">;
81
+ type InnerDedupeOptions = { [Key in DedupeOptionKeys as RemovePrefix<"dedupe", Key>]?: DedupeOptions[Key] };
82
+ type DedupeOptions = {
528
83
  /**
529
- * Amount of data transferred so far
84
+ * All dedupe options in a single object instead of separate properties
530
85
  */
531
- transferredBytes: number;
532
- };
533
- declare global {
534
- interface ReadableStream<R> {
535
- [Symbol.asyncIterator]: () => AsyncIterableIterator<R>;
536
- }
537
- }
538
- //#endregion
539
- //#region src/hooks.d.ts
540
- type PluginExtraOptions<TPluginOptions = unknown> = {
541
- /** Plugin-specific options passed to the plugin configuration */
542
- options: Partial<TPluginOptions>;
543
- };
544
- interface Hooks<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TPluginOptions = unknown> {
86
+ dedupe?: InnerDedupeOptions;
545
87
  /**
546
- * Hook called when any error occurs within the request/response lifecycle.
88
+ * Controls the scope of request deduplication caching.
547
89
  *
548
- * This is a unified error handler that catches both request errors (network failures,
549
- * timeouts, etc.) and response errors (HTTP error status codes). It's essentially
550
- * a combination of `onRequestError` and `onResponseError` hooks.
90
+ * - `"global"`: Shares deduplication cache across all `createFetchClient` instances with the same `dedupeCacheScopeKey`.
91
+ * Useful for applications with multiple API clients that should share deduplication state.
92
+ * - `"local"`: Limits deduplication to requests within the same `createFetchClient` instance.
93
+ * Provides better isolation and is recommended for most use cases.
551
94
  *
552
- * @param context - Error context containing error details, request info, and response (if available)
553
- * @returns Promise or void - Hook can be async or sync
554
- */
555
- onError?: (context: ErrorContext<TErrorData$1> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
556
- /**
557
- * Hook called before the HTTP request is sent and before any internal processing of the request object begins.
558
95
  *
559
- * This is the ideal place to modify request headers, add authentication,
560
- * implement request logging, or perform any setup before the network call.
96
+ * **Real-world Scenarios:**
97
+ * - Use `"global"` when you have multiple API clients (user service, auth service, etc.) that might make overlapping requests
98
+ * - Use `"local"` (default) for single-purpose clients or when you want strict isolation between different parts of your app
561
99
  *
562
- * @param context - Request context with mutable request object and configuration
563
- * @returns Promise or void - Hook can be async or sync
100
+ * @example
101
+ * ```ts
102
+ * // Local scope - each client has its own deduplication cache
103
+ * const userClient = createFetchClient({ baseURL: "/api/users" });
104
+ * const postClient = createFetchClient({ baseURL: "/api/posts" });
105
+ * // These clients won't share deduplication state
106
+ *
107
+ * // Global scope - share cache across related clients
108
+ * const userClient = createFetchClient({
109
+ * baseURL: "/api/users",
110
+ * dedupeCacheScope: "global",
111
+ * });
112
+ * const postClient = createFetchClient({
113
+ * baseURL: "/api/posts",
114
+ * dedupeCacheScope: "global",
115
+ * });
116
+ * // These clients will share deduplication state
117
+ * ```
564
118
  *
119
+ * @default "local"
565
120
  */
566
- onRequest?: (context: RequestContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
121
+ dedupeCacheScope?: "global" | "local";
567
122
  /**
568
- * Hook called when an error occurs during the fetch request itself.
123
+ * Unique namespace for the global deduplication cache when using `dedupeCacheScope: "global"`.
569
124
  *
570
- * This handles network-level errors like connection failures, timeouts,
571
- * DNS resolution errors, or other issues that prevent getting an HTTP response.
572
- * Note that HTTP error status codes (4xx, 5xx) are handled by `onResponseError`.
125
+ * This creates logical groupings of deduplication caches. All instances with the same key
126
+ * will share the same cache namespace, allowing fine-grained control over which clients
127
+ * share deduplication state.
573
128
  *
574
- * @param context - Request error context with error details and null response
575
- * @returns Promise or void - Hook can be async or sync
576
- */
577
- onRequestError?: (context: RequestErrorContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
578
- /**
579
- * Hook called just before the HTTP request is sent and after the request has been processed.
129
+ * **Best Practices:**
130
+ * - Use descriptive names that reflect the logical grouping (e.g., "user-service", "analytics-api")
131
+ * - Keep scope keys consistent across related API clients
132
+ * - Consider using different scope keys for different environments (dev, staging, prod)
133
+ * - Avoid overly broad scope keys that might cause unintended cache sharing
580
134
  *
581
- * @param context - Request context with mutable request object and configuration
582
- */
583
- onRequestReady?: (context: RequestContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
584
- /**
585
- * Hook called during upload stream progress tracking.
135
+ * **Cache Management:**
136
+ * - Each scope key maintains its own independent cache
137
+ * - Caches are automatically cleaned up when no references remain
138
+ * - Consider the memory implications of multiple global scopes
586
139
  *
587
- * This hook is triggered when uploading data (like file uploads) and provides
588
- * progress information about the upload. Useful for implementing progress bars
589
- * or upload status indicators.
140
+ * @example
141
+ * ```ts
142
+ * // Group related API clients together
143
+ * const userClient = createFetchClient({
144
+ * baseURL: "/api/users",
145
+ * dedupeCacheScope: "global",
146
+ * dedupeCacheScopeKey: "user-service"
147
+ * });
148
+ * const profileClient = createFetchClient({
149
+ * baseURL: "/api/profiles",
150
+ * dedupeCacheScope: "global",
151
+ * dedupeCacheScopeKey: "user-service" // Same scope - will share cache
152
+ * });
590
153
  *
591
- * @param context - Request stream context with progress event and request instance
592
- * @returns Promise or void - Hook can be async or sync
154
+ * // Separate analytics client with its own cache
155
+ * const analyticsClient = createFetchClient({
156
+ * baseURL: "/api/analytics",
157
+ * dedupeCacheScope: "global",
158
+ * dedupeCacheScopeKey: "analytics-service" // Different scope
159
+ * });
160
+ *
161
+ * // Environment-specific scoping
162
+ * const apiClient = createFetchClient({
163
+ * dedupeCacheScope: "global",
164
+ * dedupeCacheScopeKey: `api-${process.env.NODE_ENV}` // "api-development", "api-production", etc.
165
+ * });
166
+ * ```
593
167
  *
168
+ * @default "default"
594
169
  */
595
- onRequestStream?: (context: RequestStreamContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
170
+ dedupeCacheScopeKey?: "default" | AnyString | ((context: RequestContext) => string | undefined);
596
171
  /**
597
- * Hook called when any HTTP response is received from the API.
172
+ * Custom key generator for request deduplication.
598
173
  *
599
- * This hook is triggered for both successful (2xx) and error (4xx, 5xx) responses.
600
- * It's useful for response logging, metrics collection, or any processing that
601
- * should happen regardless of response status.
174
+ * Override the default key generation strategy to control exactly which requests
175
+ * are considered duplicates. The default key combines URL, method, body, and
176
+ * relevant headers (excluding volatile ones like 'Date', 'Authorization', etc.).
602
177
  *
603
- * @param context - Response context with either success data or error information
604
- * @returns Promise or void - Hook can be async or sync
178
+ * **Default Key Generation:**
179
+ * The auto-generated key includes:
180
+ * - Full request URL (including query parameters)
181
+ * - HTTP method (GET, POST, etc.)
182
+ * - Request body (for POST/PUT/PATCH requests)
183
+ * - Stable headers (excludes Date, Authorization, User-Agent, etc.)
605
184
  *
606
- */
607
- onResponse?: (context: ResponseContext<TData$1, TErrorData$1> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
608
- /**
609
- * Hook called when an HTTP error response (4xx, 5xx) is received from the API.
185
+ * **Custom Key Best Practices:**
186
+ * - Include only the parts of the request that should affect deduplication
187
+ * - Avoid including volatile data (timestamps, random IDs, etc.)
188
+ * - Consider performance - simpler keys are faster to compute and compare
189
+ * - Ensure keys are deterministic for the same logical request
190
+ * - Use consistent key formats across your application
610
191
  *
611
- * This handles server-side errors where an HTTP response was successfully received
612
- * but indicates an error condition. Different from `onRequestError` which handles
613
- * network-level failures.
192
+ * **Performance Considerations:**
193
+ * - Function-based keys are computed on every request - keep them lightweight
194
+ * - String keys are fastest but least flexible
195
+ * - Consider caching expensive key computations if needed
614
196
  *
615
- * @param context - Response error context with HTTP error details and response
616
- * @returns Promise or void - Hook can be async or sync
617
- */
618
- onResponseError?: (context: ResponseErrorContext<TErrorData$1> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
619
- /**
620
- * Hook called during download stream progress tracking.
197
+ * @example
198
+ * ```ts
199
+ * import { callApi } from "@zayne-labs/callapi";
621
200
  *
622
- * This hook is triggered when downloading data (like file downloads) and provides
623
- * progress information about the download. Useful for implementing progress bars
624
- * or download status indicators.
201
+ * // Simple static key - useful for singleton requests
202
+ * const config = callApi("/api/config", {
203
+ * dedupeKey: "app-config",
204
+ * dedupeStrategy: "defer" // Share the same config across all requests
205
+ * });
625
206
  *
626
- * @param context - Response stream context with progress event and response
627
- * @returns Promise or void - Hook can be async or sync
207
+ * // URL and method only - ignore headers and body
208
+ * const userData = callApi("/api/user/123", {
209
+ * dedupeKey: (context) => `${context.options.method}:${context.options.fullURL}`
210
+ * });
211
+ *
212
+ * // Include specific headers in deduplication
213
+ * const apiCall = callApi("/api/data", {
214
+ * dedupeKey: (context) => {
215
+ * const authHeader = context.request.headers.get("Authorization");
216
+ * return `${context.options.fullURL}-${authHeader}`;
217
+ * }
218
+ * });
219
+ *
220
+ * // User-specific deduplication
221
+ * const userSpecificCall = callApi("/api/dashboard", {
222
+ * dedupeKey: (context) => {
223
+ * const userId = context.options.fullURL.match(/user\/(\d+)/)?.[1];
224
+ * return `dashboard-${userId}`;
225
+ * }
226
+ * });
227
+ *
228
+ * // Ignore certain query parameters
229
+ * const searchCall = callApi("/api/search?q=test&timestamp=123456", {
230
+ * dedupeKey: (context) => {
231
+ * const url = new URL(context.options.fullURL);
232
+ * url.searchParams.delete("timestamp"); // Remove volatile param
233
+ * return `search:${url.toString()}`;
234
+ * }
235
+ * });
236
+ * ```
628
237
  *
238
+ * @default Auto-generated from request details
629
239
  */
630
- onResponseStream?: (context: ResponseStreamContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
240
+ dedupeKey?: string | ((context: RequestContext) => string | undefined);
631
241
  /**
632
- * Hook called when a request is being retried.
242
+ * Strategy for handling duplicate requests. Can be a static string or callback function.
633
243
  *
634
- * This hook is triggered before each retry attempt, providing information about
635
- * the previous failure and the current retry attempt number. Useful for implementing
636
- * custom retry logic, exponential backoff, or retry logging.
244
+ * **Available Strategies:**
245
+ * - `"cancel"`: Cancel previous request when new one starts (good for search)
246
+ * - `"defer"`: Share response between duplicate requests (good for config loading)
247
+ * - `"none"`: No deduplication, all requests execute independently
637
248
  *
638
- * @param context - Retry context with error details and retry attempt count
639
- * @returns Promise or void - Hook can be async or sync
249
+ * @example
250
+ * ```ts
251
+ * // Static strategies
252
+ * const searchClient = createFetchClient({
253
+ * dedupeStrategy: "cancel" // Cancel previous searches
254
+ * });
255
+ *
256
+ * const configClient = createFetchClient({
257
+ * dedupeStrategy: "defer" // Share config across components
258
+ * });
259
+ *
260
+ * // Dynamic strategy based on request
261
+ * const smartClient = createFetchClient({
262
+ * dedupeStrategy: (context) => {
263
+ * return context.options.method === "GET" ? "defer" : "cancel";
264
+ * }
265
+ * });
266
+ *
267
+ * // Search-as-you-type with cancel strategy
268
+ * const handleSearch = async (query: string) => {
269
+ * try {
270
+ * const { data } = await callApi("/api/search", {
271
+ * method: "POST",
272
+ * body: { query },
273
+ * dedupeStrategy: "cancel",
274
+ * dedupeKey: "search" // Cancel previous searches, only latest one goes through
275
+ * });
276
+ *
277
+ * updateSearchResults(data);
278
+ * } catch (error) {
279
+ * if (error.name === "AbortError") {
280
+ * // Previous search cancelled - (expected behavior)
281
+ * return;
282
+ * }
283
+ * console.error("Search failed:", error);
284
+ * }
285
+ * };
640
286
  *
287
+ * ```
288
+ *
289
+ * @default "cancel"
641
290
  */
642
- onRetry?: (response: RetryContext<TErrorData$1> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
291
+ dedupeStrategy?: DedupeStrategyUnion | ((context: RequestContext) => DedupeStrategyUnion);
292
+ };
293
+ //#endregion
294
+ //#region src/middlewares.d.ts
295
+ type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
296
+ interface Middlewares<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> {
643
297
  /**
644
- * Hook called when a successful response (2xx status) is received from the API.
645
- *
646
- * This hook is triggered only for successful responses and provides access to
647
- * the parsed response data. Ideal for success logging, caching, or post-processing
648
- * of successful API responses.
298
+ * Wraps the fetch implementation to intercept requests at the network layer.
649
299
  *
650
- * @param context - Success context with parsed response data and response object
651
- * @returns Promise or void - Hook can be async or sync
300
+ * Takes a context object containing the current fetch function and returns a new fetch function.
301
+ * Use it to cache responses, add logging, handle offline mode, or short-circuit requests etc.
302
+ * Multiple middleware compose in order: plugins → base config → per-request.
652
303
  *
653
- */
654
- onSuccess?: (context: SuccessContext<TData$1> & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
655
- /**
656
- * Hook called when a validation error occurs.
304
+ * Unlike `customFetchImpl`, middleware can call through to the original fetch.
657
305
  *
658
- * This hook is triggered when request or response data fails validation against
659
- * a defined schema. It provides access to the validation error details and can
660
- * be used for custom error handling, logging, or fallback behavior.
306
+ * @example
307
+ * ```ts
308
+ * // Cache responses
309
+ * const cache = new Map();
310
+ * fetchMiddleware: (ctx) => async (input, init) => {
311
+ * const key = input.toString();
312
+ * if (cache.has(key)) return cache.get(key).clone();
661
313
  *
662
- * @param context - Validation error context with error details and response (if available)
663
- * @returns Promise or void - Hook can be async or sync
314
+ * const response = await ctx.fetchImpl(input, init);
315
+ * cache.set(key, response.clone());
316
+ * return response;
317
+ * }
664
318
  *
319
+ * // Handle offline
320
+ * fetchMiddleware: (ctx) => async (input, init) => {
321
+ * if (!navigator.onLine) {
322
+ * return new Response('{"error": "offline"}', { status: 503 });
323
+ * }
324
+ * return ctx.fetchImpl(input, init);
325
+ * }
326
+ * ```
665
327
  */
666
- onValidationError?: (context: ValidationErrorContext & PluginExtraOptions<TPluginOptions>) => Awaitable<unknown>;
328
+ fetchMiddleware?: (context: RequestContext<TCallApiContext$1> & {
329
+ fetchImpl: FetchImpl;
330
+ }) => FetchImpl;
667
331
  }
668
- type HooksOrHooksArray<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TMoreOptions = unknown> = { [Key in keyof Hooks<TData$1, TErrorData$1, TMoreOptions>]: Hooks<TData$1, TErrorData$1, TMoreOptions>[Key] | Array<Hooks<TData$1, TErrorData$1, TMoreOptions>[Key]> };
669
- interface HookConfigOptions {
332
+ //#endregion
333
+ //#region src/url.d.ts
334
+ type AllowedQueryParamValues = UnmaskType<boolean | number | string>;
335
+ type RecordStyleParams = UnmaskType<Record<string, AllowedQueryParamValues>>;
336
+ type TupleStyleParams = UnmaskType<AllowedQueryParamValues[]>;
337
+ type Params = UnmaskType<RecordStyleParams | TupleStyleParams>;
338
+ type Query = UnmaskType<Record<string, AllowedQueryParamValues>>;
339
+ type InitURLOrURLObject = AnyString | RouteKeyMethodsURLUnion | URL;
340
+ interface URLOptions {
670
341
  /**
671
- * Controls the execution mode of all composed hooks (main + plugin hooks).
672
- *
673
- * - **"parallel"**: All hooks execute simultaneously via Promise.all() for better performance
674
- * - **"sequential"**: All hooks execute one by one in registration order via await in a loop
675
- *
676
- * This affects how ALL hooks execute together, regardless of their source (main or plugin).
342
+ * Base URL for all API requests. Will only be prepended to relative URLs.
677
343
  *
678
- * @default "parallel"
344
+ * Absolute URLs (starting with http/https) will not be prepended by the baseURL.
679
345
  *
680
346
  * @example
681
347
  * ```ts
682
- * // Parallel execution (default) - all hooks run simultaneously
683
- * hooksExecutionMode: "parallel"
684
- *
685
- * // Sequential execution - hooks run one after another
686
- * hooksExecutionMode: "sequential"
687
- *
688
- * // Use case: Hooks have dependencies and must run in order
689
- * const client = callApi.create({
690
- * hooksExecutionMode: "sequential",
691
- * plugins: [transformPlugin],
692
- * onRequest: (ctx) => {
693
- * // This runs first, then transform plugin runs
694
- * ctx.request.headers["x-request-id"] = generateId();
695
- * }
696
- * });
348
+ * // Set base URL for all requests
349
+ * baseURL: "https://api.example.com/v1"
697
350
  *
698
- * // Use case: Independent operations can run in parallel for speed
699
- * const client = callApi.create({
700
- * hooksExecutionMode: "parallel", // Default
701
- * plugins: [metricsPlugin, cachePlugin, loggingPlugin],
702
- * onRequest: (ctx) => {
703
- * // All hooks (main + plugins) run simultaneously
704
- * addRequestTimestamp(ctx.request);
705
- * }
706
- * });
351
+ * // Then use relative URLs in requests
352
+ * callApi("/users") // https://api.example.com/v1/users
353
+ * callApi("/posts/123") // → https://api.example.com/v1/posts/123
707
354
  *
708
- * // Use case: Error handling hooks that need sequential processing
709
- * const client = callApi.create({
710
- * hooksExecutionMode: "sequential",
711
- * onError: [
712
- * (ctx) => logError(ctx.error), // Log first
713
- * (ctx) => reportError(ctx.error), // Then report
714
- * (ctx) => cleanupResources(ctx) // Finally cleanup
715
- * ]
716
- * });
355
+ * // Environment-specific base URLs
356
+ * baseURL: process.env.NODE_ENV === "production"
357
+ * ? "https://api.example.com"
358
+ * : "http://localhost:3000/api"
717
359
  * ```
718
360
  */
719
- hooksExecutionMode?: "parallel" | "sequential";
720
- }
721
- type RequestContext = {
361
+ baseURL?: string;
722
362
  /**
723
- * Base configuration object passed to createFetchClient.
363
+ * Resolved request URL after processing baseURL, parameters, and query strings (readonly)
724
364
  *
725
- * Contains the foundational configuration that applies to all requests
726
- * made by this client instance, such as baseURL, default headers, and
727
- * global options.
728
- */
729
- baseConfig: Exclude<BaseCallApiConfig, AnyFunction$1>;
730
- /**
731
- * Instance-specific configuration object passed to the callApi instance.
365
+ * This is the final URL that will be used for the HTTP request, computed from
366
+ * baseURL, initURL, params, and query parameters.
732
367
  *
733
- * Contains configuration specific to this particular API call, which
734
- * can override or extend the base configuration.
735
368
  */
736
- config: CallApiConfig;
369
+ readonly fullURL?: string;
737
370
  /**
738
- * Merged options combining base config, instance config, and default options.
371
+ * The original URL string passed to the callApi instance (readonly)
739
372
  *
740
- * This is the final resolved configuration that will be used for the request,
741
- * with proper precedence applied (instance > base > defaults).
742
- */
743
- options: CallApiExtraOptionsForHooks;
744
- /**
745
- * Merged request object ready to be sent.
373
+ * This preserves the original URL as provided, including any method modifiers like "@get/" or "@post/".
746
374
  *
747
- * Contains the final request configuration including URL, method, headers,
748
- * body, and other fetch options. This object can be modified in onRequest
749
- * hooks to customize the outgoing request.
750
- */
751
- request: CallApiRequestOptionsForHooks;
752
- };
753
- type ValidationErrorContext = UnmaskType<RequestContext & {
754
- /** Validation error containing details about what failed validation */
755
- error: PossibleValidationError;
756
- /** HTTP response object if validation failed on response, null if on request */
757
- response: Response | null;
758
- }>;
759
- type SuccessContext<TData$1> = UnmaskType<RequestContext & {
760
- /** Parsed response data with the expected success type */
761
- data: TData$1;
762
- /** HTTP response object for the successful request */
763
- response: Response;
764
- }>;
765
- type ResponseContext<TData$1, TErrorData$1> = UnmaskType<RequestContext & (Prettify<CallApiResultSuccessVariant<TData$1>> | Prettify<Extract<CallApiResultErrorVariant<TErrorData$1>, {
766
- error: PossibleHTTPError<TErrorData$1>;
767
- }>>)>;
768
- type RequestErrorContext = RequestContext & {
769
- /** Error that occurred during the request (network, timeout, etc.) */
770
- error: PossibleJavaScriptError;
771
- /** Always null for request errors since no response was received */
772
- response: null;
773
- };
774
- type ErrorContext<TErrorData$1> = UnmaskType<RequestContext & ({
775
- /** HTTP error with response data */
776
- error: PossibleHTTPError<TErrorData$1>;
777
- /** HTTP response object containing error status */
778
- response: Response;
779
- } | {
780
- /** Request-level error (network, timeout, validation, etc.) */
781
- error: PossibleJavaScriptOrValidationError;
782
- /** Response object if available, null for request errors */
783
- response: Response | null;
784
- })>;
785
- type ResponseErrorContext<TErrorData$1> = UnmaskType<Extract<ErrorContext<TErrorData$1>, {
786
- error: PossibleHTTPError<TErrorData$1>;
787
- }> & RequestContext>;
788
- type RetryContext<TErrorData$1> = UnmaskType<ErrorContext<TErrorData$1> & {
789
- /** Current retry attempt number (1-based, so 1 = first retry) */
790
- retryAttemptCount: number;
791
- }>;
792
- type RequestStreamContext = UnmaskType<RequestContext & {
793
- /** Progress event containing loaded/total bytes information */
794
- event: StreamProgressEvent;
795
- /** The actual Request instance being uploaded */
796
- requestInstance: Request;
797
- }>;
798
- type ResponseStreamContext = UnmaskType<RequestContext & {
799
- /** Progress event containing loaded/total bytes information */
800
- event: StreamProgressEvent;
801
- /** HTTP response object being downloaded */
802
- response: Response;
803
- }>;
804
- //#endregion
805
- //#region src/dedupe.d.ts
806
- type DedupeStrategyUnion = UnmaskType<"cancel" | "defer" | "none">;
807
- type DedupeOptionKeys = Exclude<keyof DedupeOptions, "dedupe">;
808
- type InnerDedupeOptions = { [Key in DedupeOptionKeys as RemovePrefix<"dedupe", Key>]?: DedupeOptions[Key] };
809
- type DedupeOptions = {
810
- /**
811
- * All dedupe options in a single object instead of separate properties
812
375
  */
813
- dedupe?: InnerDedupeOptions;
376
+ readonly initURL?: string;
814
377
  /**
815
- * Controls the scope of request deduplication caching.
378
+ * The URL string after normalization, with method modifiers removed(readonly)
816
379
  *
817
- * - `"global"`: Shares deduplication cache across all `createFetchClient` instances with the same `dedupeCacheScopeKey`.
818
- * Useful for applications with multiple API clients that should share deduplication state.
819
- * - `"local"`: Limits deduplication to requests within the same `createFetchClient` instance.
820
- * Provides better isolation and is recommended for most use cases.
380
+ * Method modifiers like "@get/", "@post/" are stripped to create a clean URL
381
+ * for parameter substitution and final URL construction.
821
382
  *
383
+ */
384
+ readonly initURLNormalized?: string;
385
+ /**
386
+ * Parameters to be substituted into URL path segments.
822
387
  *
823
- * **Real-world Scenarios:**
824
- * - Use `"global"` when you have multiple API clients (user service, auth service, etc.) that might make overlapping requests
825
- * - Use `"local"` (default) for single-purpose clients or when you want strict isolation between different parts of your app
388
+ * Supports both object-style (named parameters) and array-style (positional parameters)
389
+ * for flexible URL parameter substitution.
826
390
  *
827
391
  * @example
828
- * ```ts
829
- * // Local scope - each client has its own deduplication cache
830
- * const userClient = createFetchClient({ baseURL: "/api/users" });
831
- * const postClient = createFetchClient({ baseURL: "/api/posts" });
832
- * // These clients won't share deduplication state
392
+ * ```typescript
393
+ * // Object-style parameters (recommended)
394
+ * const namedParams: URLOptions = {
395
+ * initURL: "/users/:userId/posts/:postId",
396
+ * params: { userId: "123", postId: "456" }
397
+ * };
398
+ * // Results in: /users/123/posts/456
833
399
  *
834
- * // Global scope - share cache across related clients
835
- * const userClient = createFetchClient({
836
- * baseURL: "/api/users",
837
- * dedupeCacheScope: "global",
838
- * });
839
- * const postClient = createFetchClient({
840
- * baseURL: "/api/posts",
841
- * dedupeCacheScope: "global",
842
- * });
843
- * // These clients will share deduplication state
844
- * ```
400
+ * // Array-style parameters (positional)
401
+ * const positionalParams: URLOptions = {
402
+ * initURL: "/users/:userId/posts/:postId",
403
+ * params: ["123", "456"] // Maps in order: userId=123, postId=456
404
+ * };
405
+ * // Results in: /users/123/posts/456
845
406
  *
846
- * @default "local"
407
+ * // Single parameter
408
+ * const singleParam: URLOptions = {
409
+ * initURL: "/users/:id",
410
+ * params: { id: "user-123" }
411
+ * };
412
+ * // Results in: /users/user-123
413
+ * ```
847
414
  */
848
- dedupeCacheScope?: "global" | "local";
415
+ params?: Params;
849
416
  /**
850
- * Unique namespace for the global deduplication cache when using `dedupeCacheScope: "global"`.
851
- *
852
- * This creates logical groupings of deduplication caches. All instances with the same key
853
- * will share the same cache namespace, allowing fine-grained control over which clients
854
- * share deduplication state.
855
- *
856
- * **Best Practices:**
857
- * - Use descriptive names that reflect the logical grouping (e.g., "user-service", "analytics-api")
858
- * - Keep scope keys consistent across related API clients
859
- * - Consider using different scope keys for different environments (dev, staging, prod)
860
- * - Avoid overly broad scope keys that might cause unintended cache sharing
417
+ * Query parameters to append to the URL as search parameters.
861
418
  *
862
- * **Cache Management:**
863
- * - Each scope key maintains its own independent cache
864
- * - Caches are automatically cleaned up when no references remain
865
- * - Consider the memory implications of multiple global scopes
419
+ * These will be serialized into the URL query string using standard
420
+ * URL encoding practices.
866
421
  *
867
422
  * @example
868
- * ```ts
869
- * // Group related API clients together
870
- * const userClient = createFetchClient({
871
- * baseURL: "/api/users",
872
- * dedupeCacheScope: "global",
873
- * dedupeCacheScopeKey: "user-service"
874
- * });
875
- * const profileClient = createFetchClient({
876
- * baseURL: "/api/profiles",
877
- * dedupeCacheScope: "global",
878
- * dedupeCacheScopeKey: "user-service" // Same scope - will share cache
879
- * });
880
- *
881
- * // Separate analytics client with its own cache
882
- * const analyticsClient = createFetchClient({
883
- * baseURL: "/api/analytics",
884
- * dedupeCacheScope: "global",
885
- * dedupeCacheScopeKey: "analytics-service" // Different scope
886
- * });
423
+ * ```typescript
424
+ * // Basic query parameters
425
+ * const queryOptions: URLOptions = {
426
+ * initURL: "/users",
427
+ * query: {
428
+ * page: 1,
429
+ * limit: 10,
430
+ * search: "john doe",
431
+ * active: true
432
+ * }
433
+ * };
434
+ * // Results in: /users?page=1&limit=10&search=john%20doe&active=true
887
435
  *
888
- * // Environment-specific scoping
889
- * const apiClient = createFetchClient({
890
- * dedupeCacheScope: "global",
891
- * dedupeCacheScopeKey: `api-${process.env.NODE_ENV}` // "api-development", "api-production", etc.
892
- * });
436
+ * // Filtering and sorting
437
+ * const filterOptions: URLOptions = {
438
+ * initURL: "/products",
439
+ * query: {
440
+ * category: "electronics",
441
+ * minPrice: 100,
442
+ * maxPrice: 500,
443
+ * sortBy: "price",
444
+ * order: "asc"
445
+ * }
446
+ * };
447
+ * // Results in: /products?category=electronics&minPrice=100&maxPrice=500&sortBy=price&order=asc
893
448
  * ```
894
- *
895
- * @default "default"
896
449
  */
897
- dedupeCacheScopeKey?: "default" | AnyString | ((context: RequestContext) => string | undefined);
450
+ query?: Query;
451
+ }
452
+ //#endregion
453
+ //#region src/types/conditional-types.d.ts
454
+ /**
455
+ * @description Makes a type partial if the output type of TSchema is not provided or has undefined in the union, otherwise makes it required
456
+ */
457
+ type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaOutput<TSchemaOption, undefined> ? TObject : Required<TObject>;
458
+ type ApplyURLBasedConfig<TSchemaConfig$1 extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig$1["prefix"] extends string ? `${TSchemaConfig$1["prefix"]}${TSchemaRouteKeys}` : TSchemaConfig$1["baseURL"] extends string ? `${TSchemaConfig$1["baseURL"]}${TSchemaRouteKeys}` : TSchemaRouteKeys;
459
+ type ApplyStrictConfig<TSchemaConfig$1 extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig$1["strict"] extends true ? TSchemaRouteKeys :
460
+ // eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
461
+ TSchemaRouteKeys | Exclude<InitURLOrURLObject, RouteKeyMethodsURLUnion>;
462
+ type ApplySchemaConfiguration<TSchemaConfig$1 extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = ApplyStrictConfig<TSchemaConfig$1, ApplyURLBasedConfig<TSchemaConfig$1, TSchemaRouteKeys>>;
463
+ type InferAllRouteKeys<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TSchemaConfig$1 extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig$1, Exclude<Extract<keyof TBaseSchemaRoutes$1, string>, FallBackRouteSchemaKey>>;
464
+ type InferInitURL<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TSchemaConfig$1 extends CallApiSchemaConfig> = keyof TBaseSchemaRoutes$1 extends never ? InitURLOrURLObject : InferAllRouteKeys<TBaseSchemaRoutes$1, TSchemaConfig$1>;
465
+ type GetCurrentRouteSchema<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey$1 extends string, TComputedFallBackRouteSchema = TBaseSchemaRoutes$1[FallBackRouteSchemaKey], TComputedCurrentRouteSchema = TBaseSchemaRoutes$1[TCurrentRouteSchemaKey$1], TComputedRouteSchema extends CallApiSchema = NonNullable<Omit<TComputedFallBackRouteSchema, keyof TComputedCurrentRouteSchema> & TComputedCurrentRouteSchema>> = TComputedRouteSchema extends CallApiSchema ? Writeable<TComputedRouteSchema, "deep"> : CallApiSchema;
466
+ type JsonPrimitive = boolean | number | string | null | undefined;
467
+ type SerializableObject = Record<PropertyKey, unknown>;
468
+ type SerializableArray = Array<JsonPrimitive | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableObject>;
469
+ type Body = UnmaskType<Exclude<RequestInit["body"], undefined> | SerializableArray | SerializableObject>;
470
+ type InferBodyOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["body"], {
898
471
  /**
899
- * Custom key generator for request deduplication.
900
- *
901
- * Override the default key generation strategy to control exactly which requests
902
- * are considered duplicates. The default key combines URL, method, body, and
903
- * relevant headers (excluding volatile ones like 'Date', 'Authorization', etc.).
904
- *
905
- * **Default Key Generation:**
906
- * The auto-generated key includes:
907
- * - Full request URL (including query parameters)
908
- * - HTTP method (GET, POST, etc.)
909
- * - Request body (for POST/PUT/PATCH requests)
910
- * - Stable headers (excludes Date, Authorization, User-Agent, etc.)
911
- *
912
- * **Custom Key Best Practices:**
913
- * - Include only the parts of the request that should affect deduplication
914
- * - Avoid including volatile data (timestamps, random IDs, etc.)
915
- * - Consider performance - simpler keys are faster to compute and compare
916
- * - Ensure keys are deterministic for the same logical request
917
- * - Use consistent key formats across your application
472
+ * Body of the request, can be a object or any other supported body type.
473
+ */
474
+ body?: InferSchemaOutput<TSchema$1["body"], Body>;
475
+ }>;
476
+ type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
477
+ type InferMethodFromURL<TInitURL$1> = string extends TInitURL$1 ? MethodUnion : TInitURL$1 extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
478
+ type InferMethodOption<TSchema$1 extends CallApiSchema, TInitURL$1> = MakeSchemaOptionRequiredIfDefined<TSchema$1["method"], {
479
+ /**
480
+ * HTTP method for the request.
481
+ * @default "GET"
482
+ */
483
+ method?: InferSchemaOutput<TSchema$1["method"], InferMethodFromURL<TInitURL$1>>;
484
+ }>;
485
+ type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders | undefined> | Record<"Content-Type", CommonContentTypes | undefined> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | Array<[string, string]>>;
486
+ type InferHeadersOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["headers"], {
487
+ /**
488
+ * Headers to be used in the request.
489
+ */
490
+ headers?: InferSchemaOutput<TSchema$1["headers"], HeadersOption> | ((context: {
491
+ baseHeaders: NonNullable<HeadersOption>;
492
+ }) => InferSchemaOutput<TSchema$1["headers"], HeadersOption>);
493
+ }>;
494
+ type InferRequestOptions<TSchema$1 extends CallApiSchema, TInitURL$1 extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema$1> & InferHeadersOption<TSchema$1> & InferMethodOption<TSchema$1, TInitURL$1>;
495
+ type InferMetaOption<TSchema$1 extends CallApiSchema, TCallApiContext$1 extends CallApiContext> = MakeSchemaOptionRequiredIfDefined<TSchema$1["meta"], {
496
+ /**
497
+ * - An optional field you can fill with additional information,
498
+ * to associate with the request, typically used for logging or tracing.
918
499
  *
919
- * **Performance Considerations:**
920
- * - Function-based keys are computed on every request - keep them lightweight
921
- * - String keys are fastest but least flexible
922
- * - Consider caching expensive key computations if needed
500
+ * - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
923
501
  *
924
502
  * @example
925
503
  * ```ts
926
- * import { callApi } from "@zayne-labs/callapi";
927
- *
928
- * // Simple static key - useful for singleton requests
929
- * const config = callApi("/api/config", {
930
- * dedupeKey: "app-config",
931
- * dedupeStrategy: "defer" // Share the same config across all requests
932
- * });
933
- *
934
- * // URL and method only - ignore headers and body
935
- * const userData = callApi("/api/user/123", {
936
- * dedupeKey: (context) => `${context.options.method}:${context.options.fullURL}`
937
- * });
938
- *
939
- * // Include specific headers in deduplication
940
- * const apiCall = callApi("/api/data", {
941
- * dedupeKey: (context) => {
942
- * const authHeader = context.request.headers.get("Authorization");
943
- * return `${context.options.fullURL}-${authHeader}`;
944
- * }
945
- * });
946
- *
947
- * // User-specific deduplication
948
- * const userSpecificCall = callApi("/api/dashboard", {
949
- * dedupeKey: (context) => {
950
- * const userId = context.options.fullURL.match(/user\/(\d+)/)?.[1];
951
- * return `dashboard-${userId}`;
952
- * }
504
+ * const callMainApi = callApi.create({
505
+ * baseURL: "https://main-api.com",
506
+ * onResponseError: ({ response, options }) => {
507
+ * if (options.meta?.userId) {
508
+ * console.error(`User ${options.meta.userId} made an error`);
509
+ * }
510
+ * },
953
511
  * });
954
512
  *
955
- * // Ignore certain query parameters
956
- * const searchCall = callApi("/api/search?q=test&timestamp=123456", {
957
- * dedupeKey: (context) => {
958
- * const url = new URL(context.options.fullURL);
959
- * url.searchParams.delete("timestamp"); // Remove volatile param
960
- * return `search:${url.toString()}`;
961
- * }
513
+ * const response = await callMainApi({
514
+ * url: "https://example.com/api/data",
515
+ * meta: { userId: "123" },
962
516
  * });
963
517
  * ```
964
- *
965
- * @default Auto-generated from request details
966
518
  */
967
- dedupeKey?: string | ((context: RequestContext) => string | undefined);
519
+ meta?: InferSchemaOutput<TSchema$1["meta"], TCallApiContext$1["Meta"]>;
520
+ }>;
521
+ type InferQueryOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["query"], {
522
+ /**
523
+ * Parameters to be appended to the URL (i.e: /:id)
524
+ */
525
+ query?: InferSchemaOutput<TSchema$1["query"], Query>;
526
+ }>;
527
+ type EmptyString = "";
528
+ type EmptyTuple = readonly [];
529
+ type StringTuple = readonly string[];
530
+ type PossibleParamNamePatterns = `${string}:${string}` | `${string}{${string}}${"" | AnyString}`;
531
+ type ExtractRouteParamNames<TCurrentRoute$1, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute$1 extends PossibleParamNamePatterns ? TCurrentRoute$1 extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute$1 extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
532
+ type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
533
+ type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
534
+ type InferParamsFromRoute<TCurrentRoute$1> = ExtractRouteParamNames<TCurrentRoute$1> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute$1> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute$1>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute$1>> : Params;
535
+ type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey$1 extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey$1> ? TObject : TCurrentRouteSchemaKey$1 extends Extract<keyof TBaseSchemaRoutes$1, TCurrentRouteSchemaKey$1> ? undefined extends InferSchemaOutput<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
536
+ type InferParamsOption<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey$1 extends string> = MakeParamsOptionRequired<TSchema$1["params"], TBaseSchemaRoutes$1, TCurrentRouteSchemaKey$1, {
537
+ /**
538
+ * Parameters to be appended to the URL (i.e: /:id)
539
+ */
540
+ params?: InferSchemaOutput<TSchema$1["params"], InferParamsFromRoute<TCurrentRouteSchemaKey$1>>;
541
+ }>;
542
+ type InferExtraOptions<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey$1 extends string, TCallApiContext$1 extends CallApiContext> = InferMetaOption<TSchema$1, TCallApiContext$1> & InferParamsOption<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey$1> & InferQueryOption<TSchema$1>;
543
+ type InferPluginOptions<TPluginArray$1 extends CallApiPlugin[]> = UnionToIntersection<TPluginArray$1 extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction$1<infer TReturnedSchema> ? InferSchemaOutput<TReturnedSchema> : never : never : never>;
544
+ type ResultModeOption<TErrorData$1, TResultMode$1 extends ResultModeType> = TErrorData$1 extends false ? {
545
+ resultMode: "onlyData";
546
+ } : TErrorData$1 extends false | undefined ? {
547
+ resultMode?: "onlyData";
548
+ } : {
549
+ resultMode?: TResultMode$1;
550
+ };
551
+ type ThrowOnErrorUnion = boolean;
552
+ type ThrowOnErrorType<TErrorData$1, TThrowOnError$1 extends ThrowOnErrorUnion> = TThrowOnError$1 | ((context: ErrorContext<{
553
+ ErrorData: TErrorData$1;
554
+ }>) => TThrowOnError$1);
555
+ type ThrowOnErrorOption<TErrorData$1, TThrowOnError$1 extends ThrowOnErrorUnion> = TErrorData$1 extends false ? {
556
+ throwOnError: true;
557
+ } : TErrorData$1 extends false | undefined ? {
558
+ throwOnError?: true;
559
+ } : {
560
+ throwOnError?: ThrowOnErrorType<TErrorData$1, TThrowOnError$1>;
561
+ };
562
+ //#endregion
563
+ //#region src/types/standard-schema.d.ts
564
+ /**
565
+ * The Standard Schema interface.
566
+ * @see https://github.com/standard-schema/standard-schema
567
+ */
568
+ interface StandardSchemaV1<Input$1 = unknown, Output$1 = Input$1> {
569
+ /**
570
+ * The Standard Schema properties.
571
+ */
572
+ readonly "~standard": StandardSchemaV1.Props<Input$1, Output$1>;
573
+ }
574
+ declare namespace StandardSchemaV1 {
575
+ /**
576
+ * The Standard Schema properties interface.
577
+ */
578
+ interface Props<Input = unknown, Output = Input> {
579
+ /**
580
+ * Inferred types associated with the schema.
581
+ */
582
+ readonly types?: Types<Input, Output> | undefined;
583
+ /**
584
+ * Validates unknown input values.
585
+ */
586
+ readonly validate: (value: unknown) => Promise<Result<Output>> | Result<Output>;
587
+ /**
588
+ * The vendor name of the schema library.
589
+ */
590
+ readonly vendor: string;
591
+ /**
592
+ * The version number of the standard.
593
+ */
594
+ readonly version: 1;
595
+ }
596
+ /**
597
+ * The result interface of the validate function.
598
+ */
599
+ type Result<Output> = FailureResult | SuccessResult<Output>;
600
+ /**
601
+ * The result interface if validation succeeds.
602
+ */
603
+ interface SuccessResult<Output> {
604
+ /**
605
+ * The non-existent issues.
606
+ */
607
+ readonly issues?: undefined;
608
+ /**
609
+ * The typed output value.
610
+ */
611
+ readonly value: Output;
612
+ }
613
+ /**
614
+ * The result interface if validation fails.
615
+ */
616
+ interface FailureResult {
617
+ /**
618
+ * The issues of failed validation.
619
+ */
620
+ readonly issues: readonly Issue[];
621
+ }
622
+ /**
623
+ * The issue interface of the failure output.
624
+ */
625
+ interface Issue {
626
+ /**
627
+ * The error message of the issue.
628
+ */
629
+ readonly message: string;
630
+ /**
631
+ * The path of the issue, if any.
632
+ */
633
+ readonly path?: ReadonlyArray<PathSegment | PropertyKey> | undefined;
634
+ }
635
+ /**
636
+ * The path segment interface of the issue.
637
+ */
638
+ interface PathSegment {
639
+ /**
640
+ * The key representing a path segment.
641
+ */
642
+ readonly key: PropertyKey;
643
+ }
644
+ /**
645
+ * The Standard Schema types interface.
646
+ */
647
+ interface Types<Input = unknown, Output = Input> {
648
+ /** The input type of the schema. */
649
+ readonly input: Input;
650
+ /** The output type of the schema. */
651
+ readonly output: Output;
652
+ }
653
+ /**
654
+ * Infers the input type of a Standard Schema.
655
+ */
656
+ type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
968
657
  /**
969
- * Strategy for handling duplicate requests. Can be a static string or callback function.
970
- *
971
- * **Available Strategies:**
972
- * - `"cancel"`: Cancel previous request when new one starts (good for search)
973
- * - `"defer"`: Share response between duplicate requests (good for config loading)
974
- * - `"none"`: No deduplication, all requests execute independently
975
- *
976
- * @example
977
- * ```ts
978
- * // Static strategies
979
- * const searchClient = createFetchClient({
980
- * dedupeStrategy: "cancel" // Cancel previous searches
981
- * });
982
- *
983
- * const configClient = createFetchClient({
984
- * dedupeStrategy: "defer" // Share config across components
985
- * });
986
- *
987
- * // Dynamic strategy based on request
988
- * const smartClient = createFetchClient({
989
- * dedupeStrategy: (context) => {
990
- * return context.options.method === "GET" ? "defer" : "cancel";
991
- * }
992
- * });
993
- *
994
- * // Search-as-you-type with cancel strategy
995
- * const handleSearch = async (query: string) => {
996
- * try {
997
- * const { data } = await callApi("/api/search", {
998
- * method: "POST",
999
- * body: { query },
1000
- * dedupeStrategy: "cancel",
1001
- * dedupeKey: "search" // Cancel previous searches, only latest one goes through
1002
- * });
1003
- *
1004
- * updateSearchResults(data);
1005
- * } catch (error) {
1006
- * if (error.name === "AbortError") {
1007
- * // Previous search cancelled - (expected behavior)
1008
- * return;
1009
- * }
1010
- * console.error("Search failed:", error);
1011
- * }
1012
- * };
1013
- *
1014
- * ```
658
+ * Infers the output type of a Standard Schema.
659
+ */
660
+ type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
661
+ }
662
+ //#endregion
663
+ //#region src/utils/external/error.d.ts
664
+ type HTTPErrorDetails<TErrorData$1> = Pick<CallApiExtraOptions, "defaultHTTPErrorMessage"> & {
665
+ errorData: TErrorData$1;
666
+ response: Response;
667
+ };
668
+ declare class HTTPError<TErrorData$1 = Record<string, unknown>> extends Error {
669
+ errorData: HTTPErrorDetails<TErrorData$1>["errorData"];
670
+ readonly httpErrorSymbol: symbol;
671
+ name: "HTTPError";
672
+ response: HTTPErrorDetails<TErrorData$1>["response"];
673
+ constructor(errorDetails: HTTPErrorDetails<TErrorData$1>, errorOptions?: ErrorOptions);
674
+ /**
675
+ * @description Checks if the given error is an instance of HTTPError
676
+ * @param error - The error to check
677
+ * @returns true if the error is an instance of HTTPError, false otherwise
678
+ */
679
+ static isError<TErrorData>(error: unknown): error is HTTPError<TErrorData$1>;
680
+ }
681
+ type SafeExtract<TUnion, TKey extends TUnion> = Extract<TUnion, TKey>;
682
+ type ValidationErrorDetails = {
683
+ /**
684
+ * The cause of the validation error.
1015
685
  *
1016
- * @default "cancel"
686
+ * It's either the name the schema for which validation failed, or the name of the schema config option that led to the validation error.
1017
687
  */
1018
- dedupeStrategy?: DedupeStrategyUnion | ((context: RequestContext) => DedupeStrategyUnion);
688
+ issueCause: "unknown" | `schemaConfig-(${SafeExtract<keyof CallApiSchemaConfig, "strict">})` | keyof CallApiSchema;
689
+ /**
690
+ * The issues that caused the validation error.
691
+ */
692
+ issues: readonly StandardSchemaV1.Issue[];
693
+ /**
694
+ * The response from server, if any.
695
+ */
696
+ response: Response | null;
697
+ };
698
+ declare class ValidationError extends Error {
699
+ errorData: ValidationErrorDetails["issues"];
700
+ issueCause: ValidationErrorDetails["issueCause"];
701
+ name: "ValidationError";
702
+ response: ValidationErrorDetails["response"];
703
+ readonly validationErrorSymbol: symbol;
704
+ constructor(details: ValidationErrorDetails, errorOptions?: ErrorOptions);
705
+ /**
706
+ * @description Checks if the given error is an instance of ValidationError
707
+ * @param error - The error to check
708
+ * @returns true if the error is an instance of ValidationError, false otherwise
709
+ */
710
+ static isError(error: unknown): error is ValidationError;
711
+ }
712
+ //#endregion
713
+ //#region src/result.d.ts
714
+ type Parser<TData$1> = (responseString: string) => Awaitable<TData$1>;
715
+ declare const getResponseType: <TResponse>(response: Response, parser: Parser<TResponse>) => {
716
+ arrayBuffer: () => Promise<ArrayBuffer>;
717
+ blob: () => Promise<Blob>;
718
+ formData: () => Promise<FormData>;
719
+ json: () => Promise<TResponse>;
720
+ stream: () => ReadableStream<Uint8Array<ArrayBuffer>> | null;
721
+ text: () => Promise<string>;
722
+ };
723
+ type InitResponseTypeMap<TResponse$1 = unknown> = ReturnType<typeof getResponseType<TResponse$1>>;
724
+ type ResponseTypeUnion = keyof InitResponseTypeMap;
725
+ type ResponseTypePlaceholder = null;
726
+ type ResponseTypeType = ResponseTypePlaceholder | ResponseTypeUnion;
727
+ type ResponseTypeMap<TResponse$1> = { [Key in keyof InitResponseTypeMap<TResponse$1>]: Awaited<ReturnType<InitResponseTypeMap<TResponse$1>[Key]>> };
728
+ type GetResponseType<TResponse$1, TResponseType$1 extends ResponseTypeType, TComputedResponseTypeMap extends ResponseTypeMap<TResponse$1> = ResponseTypeMap<TResponse$1>> = null extends TResponseType$1 ? TComputedResponseTypeMap["json"] : TResponseType$1 extends NonNullable<ResponseTypeType> ? TComputedResponseTypeMap[TResponseType$1] : never;
729
+ type CallApiResultSuccessVariant<TData$1> = {
730
+ data: NoInfer<TData$1>;
731
+ error: null;
732
+ response: Response;
733
+ };
734
+ type PossibleJavaScriptError = UnmaskType<{
735
+ errorData: false;
736
+ message: string;
737
+ name: "AbortError" | "Error" | "SyntaxError" | "TimeoutError" | "TypeError" | AnyString;
738
+ originalError: DOMException | Error | SyntaxError | TypeError;
739
+ }>;
740
+ type PossibleHTTPError<TErrorData$1> = UnmaskType<{
741
+ errorData: NoInfer<TErrorData$1>;
742
+ message: string;
743
+ name: "HTTPError";
744
+ originalError: HTTPError;
745
+ }>;
746
+ type PossibleValidationError = UnmaskType<{
747
+ errorData: ValidationError["errorData"];
748
+ issueCause: ValidationError["issueCause"];
749
+ message: string;
750
+ name: "ValidationError";
751
+ originalError: ValidationError;
752
+ }>;
753
+ type PossibleJavaScriptOrValidationError = UnmaskType<PossibleJavaScriptError | PossibleValidationError>;
754
+ type CallApiResultErrorVariant<TErrorData$1> = {
755
+ data: null;
756
+ error: PossibleHTTPError<TErrorData$1>;
757
+ response: Response;
758
+ } | {
759
+ data: null;
760
+ error: PossibleJavaScriptOrValidationError;
761
+ response: Response | null;
762
+ };
763
+ type CallApiSuccessOrErrorVariant<TData$1, TError> = CallApiResultErrorVariant<TError> | CallApiResultSuccessVariant<TData$1>;
764
+ type ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType$1 extends ResponseTypeType, TComputedData = GetResponseType<TData$1, TResponseType$1>, TComputedErrorData = GetResponseType<TErrorData$1, TResponseType$1>, TComputedResult$1 extends CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData> = CallApiSuccessOrErrorVariant<TComputedData, TComputedErrorData>> = UnmaskType<{
765
+ all: TComputedResult$1;
766
+ onlyData: TComputedResult$1["data"];
767
+ onlyResponse: TComputedResult$1["response"];
768
+ withoutResponse: DistributiveOmit<TComputedResult$1, "response">;
769
+ }>;
770
+ type ResultModeMapWithException<TData$1, TResponseType$1 extends ResponseTypeType, TComputedData = GetResponseType<TData$1, TResponseType$1>, TComputedResult$1 extends CallApiResultSuccessVariant<TComputedData> = CallApiResultSuccessVariant<TComputedData>> = {
771
+ all: TComputedResult$1;
772
+ onlyData: TComputedResult$1["data"];
773
+ onlyResponse: TComputedResult$1["response"];
774
+ withoutResponse: DistributiveOmit<TComputedResult$1, "response">;
1019
775
  };
776
+ type ResultModeMap<TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResponseType$1 extends ResponseTypeType = ResponseTypeType, TThrowOnError$1 extends ThrowOnErrorUnion = DefaultThrowOnError> = TThrowOnError$1 extends true ? ResultModeMapWithException<TData$1, TResponseType$1> : ResultModeMapWithoutException<TData$1, TErrorData$1, TResponseType$1>;
777
+ type ResultModePlaceholder = null;
778
+ type ResultModeUnion = keyof ResultModeMap;
779
+ type ResultModeType = ResultModePlaceholder | ResultModeUnion;
1020
780
  //#endregion
1021
781
  //#region src/retry.d.ts
1022
782
  declare const defaultRetryStatusCodesLookup: () => Readonly<{
@@ -1030,7 +790,9 @@ declare const defaultRetryStatusCodesLookup: () => Readonly<{
1030
790
  504: "Gateway Timeout";
1031
791
  }>;
1032
792
  type RetryStatusCodes = UnmaskType<AnyNumber | keyof ReturnType<typeof defaultRetryStatusCodesLookup>>;
1033
- type RetryCondition<TErrorData$1> = (context: ErrorContext<TErrorData$1>) => Awaitable<boolean>;
793
+ type RetryCondition<TErrorData$1> = (context: ErrorContext<{
794
+ ErrorData: TErrorData$1;
795
+ }>) => Awaitable<boolean>;
1034
796
  type RetryOptionKeys<TErrorData$1> = Exclude<keyof RetryOptions<TErrorData$1>, "~retryAttemptCount" | "retry">;
1035
797
  type InnerRetryOptions<TErrorData$1> = { [Key in RetryOptionKeys<TErrorData$1> as RemovePrefix<"retry", Key>]?: RetryOptions<TErrorData$1>[Key] };
1036
798
  interface RetryOptions<TErrorData$1> {
@@ -1073,129 +835,25 @@ interface RetryOptions<TErrorData$1> {
1073
835
  */
1074
836
  retryStatusCodes?: RetryStatusCodes[];
1075
837
  /**
1076
- * Strategy to use when retrying
1077
- * @default "linear"
1078
- */
1079
- retryStrategy?: "exponential" | "linear";
1080
- }
1081
- //#endregion
1082
- //#region src/types/conditional-types.d.ts
1083
- /**
1084
- * @description Makes a type partial if the output type of TSchema is not provided or has undefined in the union, otherwise makes it required
1085
- */
1086
- type MakeSchemaOptionRequiredIfDefined<TSchemaOption extends CallApiSchema[keyof CallApiSchema], TObject> = undefined extends InferSchemaOutput<TSchemaOption, undefined> ? TObject : Required<TObject>;
1087
- type ApplyURLBasedConfig<TSchemaConfig$1 extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig$1["prefix"] extends string ? `${TSchemaConfig$1["prefix"]}${TSchemaRouteKeys}` : TSchemaConfig$1["baseURL"] extends string ? `${TSchemaConfig$1["baseURL"]}${TSchemaRouteKeys}` : TSchemaRouteKeys;
1088
- type ApplyStrictConfig<TSchemaConfig$1 extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = TSchemaConfig$1["strict"] extends true ? TSchemaRouteKeys :
1089
- // eslint-disable-next-line perfectionist/sort-union-types -- Don't sort union types
1090
- TSchemaRouteKeys | Exclude<InitURLOrURLObject, RouteKeyMethodsURLUnion>;
1091
- type ApplySchemaConfiguration<TSchemaConfig$1 extends CallApiSchemaConfig, TSchemaRouteKeys extends string> = ApplyStrictConfig<TSchemaConfig$1, ApplyURLBasedConfig<TSchemaConfig$1, TSchemaRouteKeys>>;
1092
- type InferAllRouteKeys<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TSchemaConfig$1 extends CallApiSchemaConfig> = ApplySchemaConfiguration<TSchemaConfig$1, Exclude<Extract<keyof TBaseSchemaRoutes$1, string>, FallBackRouteSchemaKey>>;
1093
- type InferInitURL<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TSchemaConfig$1 extends CallApiSchemaConfig> = keyof TBaseSchemaRoutes$1 extends never ? InitURLOrURLObject : InferAllRouteKeys<TBaseSchemaRoutes$1, TSchemaConfig$1>;
1094
- type GetCurrentRouteSchema<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TComputedFallBackRouteSchema = TBaseSchemaRoutes$1[FallBackRouteSchemaKey], TComputedCurrentRouteSchema = TBaseSchemaRoutes$1[TCurrentRouteSchemaKey], TComputedRouteSchema extends CallApiSchema = NonNullable<Omit<TComputedFallBackRouteSchema, keyof TComputedCurrentRouteSchema> & TComputedCurrentRouteSchema>> = TComputedRouteSchema extends CallApiSchema ? Writeable<TComputedRouteSchema, "deep"> : CallApiSchema;
1095
- type JsonPrimitive = boolean | number | string | null | undefined;
1096
- type SerializableObject = Record<PropertyKey, unknown>;
1097
- type SerializableArray = Array<JsonPrimitive | SerializableObject> | ReadonlyArray<JsonPrimitive | SerializableObject>;
1098
- type Body = UnmaskType<Exclude<RequestInit["body"], undefined> | SerializableArray | SerializableObject>;
1099
- type InferBodyOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["body"], {
1100
- /**
1101
- * Body of the request, can be a object or any other supported body type.
1102
- */
1103
- body?: InferSchemaOutput<TSchema$1["body"], Body>;
1104
- }>;
1105
- type MethodUnion = UnmaskType<"CONNECT" | "DELETE" | "GET" | "HEAD" | "OPTIONS" | "PATCH" | "POST" | "PUT" | "TRACE" | AnyString>;
1106
- type InferMethodFromURL<TInitURL> = string extends TInitURL ? MethodUnion : TInitURL extends `@${infer TMethod extends RouteKeyMethods}/${string}` ? Uppercase<TMethod> : MethodUnion;
1107
- type InferMethodOption<TSchema$1 extends CallApiSchema, TInitURL> = MakeSchemaOptionRequiredIfDefined<TSchema$1["method"], {
1108
- /**
1109
- * HTTP method for the request.
1110
- * @default "GET"
1111
- */
1112
- method?: InferSchemaOutput<TSchema$1["method"], InferMethodFromURL<TInitURL>>;
1113
- }>;
1114
- type HeadersOption = UnmaskType<Record<"Authorization", CommonAuthorizationHeaders | undefined> | Record<"Content-Type", CommonContentTypes | undefined> | Record<CommonRequestHeaders, string | undefined> | Record<string, string | undefined> | Array<[string, string]>>;
1115
- type InferHeadersOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["headers"], {
1116
- /**
1117
- * Headers to be used in the request.
1118
- */
1119
- headers?: InferSchemaOutput<TSchema$1["headers"], HeadersOption> | ((context: {
1120
- baseHeaders: NonNullable<HeadersOption>;
1121
- }) => InferSchemaOutput<TSchema$1["headers"], HeadersOption>);
1122
- }>;
1123
- type InferRequestOptions<TSchema$1 extends CallApiSchema, TInitURL extends InferInitURL<BaseCallApiSchemaRoutes, CallApiSchemaConfig>> = InferBodyOption<TSchema$1> & InferHeadersOption<TSchema$1> & InferMethodOption<TSchema$1, TInitURL>;
1124
- type InferMetaOption<TSchema$1 extends CallApiSchema, TCallApiContext extends CallApiContext> = MakeSchemaOptionRequiredIfDefined<TSchema$1["meta"], {
1125
- /**
1126
- * - An optional field you can fill with additional information,
1127
- * to associate with the request, typically used for logging or tracing.
1128
- *
1129
- * - A good use case for this, would be to use the info to handle specific cases in any of the shared interceptors.
1130
- *
1131
- * @example
1132
- * ```ts
1133
- * const callMainApi = callApi.create({
1134
- * baseURL: "https://main-api.com",
1135
- * onResponseError: ({ response, options }) => {
1136
- * if (options.meta?.userId) {
1137
- * console.error(`User ${options.meta.userId} made an error`);
1138
- * }
1139
- * },
1140
- * });
1141
- *
1142
- * const response = await callMainApi({
1143
- * url: "https://example.com/api/data",
1144
- * meta: { userId: "123" },
1145
- * });
1146
- * ```
1147
- */
1148
- meta?: InferSchemaOutput<TSchema$1["meta"], TCallApiContext["Meta"]>;
1149
- }>;
1150
- type InferQueryOption<TSchema$1 extends CallApiSchema> = MakeSchemaOptionRequiredIfDefined<TSchema$1["query"], {
1151
- /**
1152
- * Parameters to be appended to the URL (i.e: /:id)
1153
- */
1154
- query?: InferSchemaOutput<TSchema$1["query"], Query>;
1155
- }>;
1156
- type EmptyString = "";
1157
- type EmptyTuple = readonly [];
1158
- type StringTuple = readonly string[];
1159
- type PossibleParamNamePatterns = `${string}:${string}` | `${string}{${string}}${"" | AnyString}`;
1160
- type ExtractRouteParamNames<TCurrentRoute$1, TParamNamesAccumulator extends StringTuple = EmptyTuple> = TCurrentRoute$1 extends PossibleParamNamePatterns ? TCurrentRoute$1 extends `${infer TRoutePrefix}:${infer TParamAndRemainingRoute}` ? TParamAndRemainingRoute extends `${infer TCurrentParam}/${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}/${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamAndRemainingRoute extends `${infer TCurrentParam}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : ExtractRouteParamNames<TRoutePrefix, [...TParamNamesAccumulator, TCurrentParam]> : ExtractRouteParamNames<TRoutePrefix, TParamNamesAccumulator> : TCurrentRoute$1 extends `${infer TRoutePrefix}{${infer TCurrentParam}}${infer TRemainingRoute}` ? TCurrentParam extends EmptyString ? ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, TParamNamesAccumulator> : ExtractRouteParamNames<`${TRoutePrefix}${TRemainingRoute}`, [...TParamNamesAccumulator, TCurrentParam]> : TParamNamesAccumulator : TParamNamesAccumulator;
1161
- type ConvertParamNamesToRecord<TParamNames extends StringTuple> = Prettify<TParamNames extends (readonly [infer TFirstParamName extends string, ...infer TRemainingParamNames extends StringTuple]) ? Record<TFirstParamName, AllowedQueryParamValues> & ConvertParamNamesToRecord<TRemainingParamNames> : NonNullable<unknown>>;
1162
- type ConvertParamNamesToTuple<TParamNames extends StringTuple> = TParamNames extends readonly [string, ...infer TRemainingParamNames extends StringTuple] ? [AllowedQueryParamValues, ...ConvertParamNamesToTuple<TRemainingParamNames>] : [];
1163
- type InferParamsFromRoute<TCurrentRoute$1> = ExtractRouteParamNames<TCurrentRoute$1> extends StringTuple ? ExtractRouteParamNames<TCurrentRoute$1> extends EmptyTuple ? Params : ConvertParamNamesToRecord<ExtractRouteParamNames<TCurrentRoute$1>> | ConvertParamNamesToTuple<ExtractRouteParamNames<TCurrentRoute$1>> : Params;
1164
- type MakeParamsOptionRequired<TParamsSchemaOption extends CallApiSchema["params"], TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TObject> = MakeSchemaOptionRequiredIfDefined<TParamsSchemaOption, Params extends InferParamsFromRoute<TCurrentRouteSchemaKey> ? TObject : TCurrentRouteSchemaKey extends Extract<keyof TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> ? undefined extends InferSchemaOutput<TParamsSchemaOption, null> ? TObject : Required<TObject> : TObject>;
1165
- type InferParamsOption<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = MakeParamsOptionRequired<TSchema$1["params"], TBaseSchemaRoutes$1, TCurrentRouteSchemaKey, {
1166
- /**
1167
- * Parameters to be appended to the URL (i.e: /:id)
1168
- */
1169
- params?: InferSchemaOutput<TSchema$1["params"], InferParamsFromRoute<TCurrentRouteSchemaKey>>;
1170
- }>;
1171
- type InferExtraOptions<TSchema$1 extends CallApiSchema, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string, TCallApiContext extends CallApiContext> = InferMetaOption<TSchema$1, TCallApiContext> & InferParamsOption<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey> & InferQueryOption<TSchema$1>;
1172
- type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<TPluginArray extends Array<infer TPlugin> ? TPlugin extends CallApiPlugin ? TPlugin["defineExtraOptions"] extends AnyFunction$1<infer TReturnedSchema> ? InferSchemaOutput<TReturnedSchema> : never : never : never>;
1173
- type ResultModeOption<TErrorData$1, TResultMode extends ResultModeType> = TErrorData$1 extends false ? {
1174
- resultMode: "onlyData";
1175
- } : TErrorData$1 extends false | undefined ? {
1176
- resultMode?: "onlyData";
1177
- } : {
1178
- resultMode?: TResultMode;
1179
- };
1180
- type ThrowOnErrorUnion = boolean;
1181
- type ThrowOnErrorType<TErrorData$1, TThrowOnError extends ThrowOnErrorUnion> = TThrowOnError | ((context: ErrorContext<TErrorData$1>) => TThrowOnError);
1182
- type ThrowOnErrorOption<TErrorData$1, TThrowOnError extends ThrowOnErrorUnion> = TErrorData$1 extends false ? {
1183
- throwOnError: true;
1184
- } : TErrorData$1 extends false | undefined ? {
1185
- throwOnError?: true;
1186
- } : {
1187
- throwOnError?: ThrowOnErrorType<TErrorData$1, TThrowOnError>;
1188
- };
838
+ * Strategy to use when retrying
839
+ * @default "linear"
840
+ */
841
+ retryStrategy?: "exponential" | "linear";
842
+ }
1189
843
  //#endregion
1190
844
  //#region src/types/common.d.ts
1191
845
  interface Register {}
1192
- type MetaObjectType = Record<string, unknown>;
1193
846
  type GlobalMeta = Register extends {
1194
- meta?: infer TMeta extends MetaObjectType;
1195
- } ? TMeta : never;
847
+ meta?: infer TMeta extends DefaultMetaObject;
848
+ } ? TMeta : DefaultMetaObject;
1196
849
  type CallApiContext = {
1197
- Meta?: MetaObjectType;
850
+ Data?: DefaultDataType;
851
+ ErrorData?: DefaultDataType;
852
+ InferredPluginOptions?: unknown;
853
+ Meta?: DefaultMetaObject;
854
+ ResultMode?: ResultModeType;
1198
855
  };
856
+ type GetMergedCallApiContext<TFullCallApiContext extends CallApiContext, TOverrideCallApiContext extends CallApiContext> = Omit<TFullCallApiContext, keyof TOverrideCallApiContext> & TOverrideCallApiContext;
1199
857
  type FetchSpecificKeysUnion = Exclude<(typeof fetchSpecificKeys)[number], "body" | "headers" | "method">;
1200
858
  type ModifiedRequestInit = RequestInit & {
1201
859
  duplex?: "half";
@@ -1218,7 +876,9 @@ type CallApiRequestOptions = Prettify<{
1218
876
  type CallApiRequestOptionsForHooks = Omit<CallApiRequestOptions, "headers"> & {
1219
877
  headers: Record<string, string | undefined>;
1220
878
  };
1221
- type SharedExtraOptions<TCallApiContext extends CallApiContext = CallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<TData$1, TErrorData$1, Partial<InferPluginOptions<TPluginArray>>> & Middlewares & Partial<InferPluginOptions<TPluginArray>> & ResultModeOption<TErrorData$1, TResultMode> & RetryOptions<TErrorData$1> & ThrowOnErrorOption<TErrorData$1, TThrowOnError> & URLOptions & {
879
+ type SharedExtraOptions<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode$1 extends ResultModeType = ResultModeType, TThrowOnError$1 extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType$1 extends ResponseTypeType = ResponseTypeType, TPluginArray$1 extends CallApiPlugin[] = DefaultPluginArray, TComputedMergedPluginOptions = Partial<InferPluginOptions<TPluginArray$1> & TCallApiContext$1["InferredPluginOptions"]>> = DedupeOptions & HookConfigOptions & HooksOrHooksArray<GetMergedCallApiContext<TCallApiContext$1, {
880
+ InferredPluginOptions: TComputedMergedPluginOptions;
881
+ }>> & Middlewares & ResultModeOption<TErrorData$1, TResultMode$1> & RetryOptions<TErrorData$1> & TComputedMergedPluginOptions & ThrowOnErrorOption<TErrorData$1, TThrowOnError$1> & URLOptions & {
1222
882
  /**
1223
883
  * Automatically add an Authorization header value.
1224
884
  *
@@ -1396,7 +1056,7 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = CallApiContext,
1396
1056
  * });
1397
1057
  * ```
1398
1058
  */
1399
- meta?: TCallApiContext["Meta"];
1059
+ meta?: TCallApiContext$1["Meta"] extends DefaultMetaObject ? TCallApiContext$1["Meta"] : DefaultCallApiContext["Meta"];
1400
1060
  /**
1401
1061
  * Custom function to parse response strings into actual value instead of the default response.json().
1402
1062
  *
@@ -1466,7 +1126,7 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = CallApiContext,
1466
1126
  * // Usage: const stream = await callApi("/large-dataset", { responseType: "stream" });
1467
1127
  * ```
1468
1128
  */
1469
- responseType?: TResponseType;
1129
+ responseType?: TResponseType$1;
1470
1130
  /**
1471
1131
  * Controls what data is included in the returned result object.
1472
1132
  *
@@ -1521,7 +1181,7 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = CallApiContext,
1521
1181
  * }
1522
1182
  * ```
1523
1183
  */
1524
- resultMode?: TResultMode;
1184
+ resultMode?: TResultMode$1;
1525
1185
  /**
1526
1186
  * Controls whether errors are thrown as exceptions or returned in the result.
1527
1187
  *
@@ -1566,7 +1226,7 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = CallApiContext,
1566
1226
  * }
1567
1227
  * ```
1568
1228
  */
1569
- throwOnError?: ThrowOnErrorType<TErrorData$1, TThrowOnError>;
1229
+ throwOnError?: ThrowOnErrorType<TErrorData$1, TThrowOnError$1>;
1570
1230
  /**
1571
1231
  * Request timeout in milliseconds. Request will be aborted if it takes longer.
1572
1232
  *
@@ -1592,7 +1252,7 @@ type SharedExtraOptions<TCallApiContext extends CallApiContext = CallApiContext,
1592
1252
  */
1593
1253
  timeout?: number;
1594
1254
  };
1595
- type BaseCallApiExtraOptions<TBaseCallApiContext extends CallApiContext = CallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig> = SharedExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray> & {
1255
+ type BaseCallApiExtraOptions<TBaseCallApiContext$1 extends CallApiContext = DefaultCallApiContext, TBaseData$1 = DefaultDataType, TBaseErrorData$1 = DefaultDataType, TBaseResultMode$1 extends ResultModeType = ResultModeType, TBaseThrowOnError$1 extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType$1 extends ResponseTypeType = ResponseTypeType, TBasePluginArray$1 extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaAndConfig$1 extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig> = SharedExtraOptions<TBaseCallApiContext$1, TBaseData$1, TBaseErrorData$1, TBaseResultMode$1, TBaseThrowOnError$1, TBaseResponseType$1, TBasePluginArray$1> & {
1596
1256
  /**
1597
1257
  * Array of base CallApi plugins to extend library functionality.
1598
1258
  *
@@ -1615,7 +1275,7 @@ type BaseCallApiExtraOptions<TBaseCallApiContext extends CallApiContext = CallAp
1615
1275
  *
1616
1276
  * ```
1617
1277
  */
1618
- plugins?: TBasePluginArray;
1278
+ plugins?: TBasePluginArray$1;
1619
1279
  /**
1620
1280
  * Base validation schemas for the client configuration.
1621
1281
  *
@@ -1623,7 +1283,7 @@ type BaseCallApiExtraOptions<TBaseCallApiContext extends CallApiContext = CallAp
1623
1283
  * instances created from this base configuration. Provides type safety
1624
1284
  * and runtime validation for API interactions.
1625
1285
  */
1626
- schema?: TBaseSchemaAndConfig;
1286
+ schema?: TBaseSchemaAndConfig$1;
1627
1287
  /**
1628
1288
  * Controls which configuration parts skip automatic merging between base and instance configs.
1629
1289
  *
@@ -1692,17 +1352,17 @@ type BaseCallApiExtraOptions<TBaseCallApiContext extends CallApiContext = CallAp
1692
1352
  */
1693
1353
  skipAutoMergeFor?: "all" | "options" | "request";
1694
1354
  };
1695
- type InferExtendSchemaContext<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey extends string> = {
1355
+ type InferExtendSchemaContext<TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes, TCurrentRouteSchemaKey$1 extends string> = {
1696
1356
  baseSchemaRoutes: TBaseSchemaRoutes$1;
1697
- currentRouteSchema: GetCurrentRouteSchema<TBaseSchemaRoutes$1, TCurrentRouteSchemaKey>;
1357
+ currentRouteSchema: GetCurrentRouteSchema<TBaseSchemaRoutes$1, TCurrentRouteSchemaKey$1>;
1698
1358
  };
1699
- type InferExtendSchemaConfigContext<TBaseSchemaConfig extends CallApiSchemaConfig> = {
1359
+ type GetExtendSchemaConfigContext<TBaseSchemaConfig extends CallApiSchemaConfig> = {
1700
1360
  baseSchemaConfig: TBaseSchemaConfig;
1701
1361
  };
1702
- type InferExtendPluginContext<TBasePluginArray extends CallApiPlugin[]> = {
1703
- basePlugins: TBasePluginArray;
1362
+ type InferExtendPluginContext<TBasePluginArray$1 extends CallApiPlugin[]> = {
1363
+ basePlugins: TBasePluginArray$1;
1704
1364
  };
1705
- type CallApiExtraOptions<TCallApiContext extends CallApiContext = CallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey extends string = string, TComputedPluginContext = InferExtendPluginContext<TBasePluginArray>, TComputedSchemaContext = InferExtendSchemaContext<TBaseSchemaRoutes$1, TCurrentRouteSchemaKey>, TComputedSchemaConfigContext = InferExtendSchemaConfigContext<TBaseSchemaConfig>> = SharedExtraOptions<TCallApiContext, TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TPluginArray> & {
1365
+ type CallApiExtraOptions<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode$1 extends ResultModeType = ResultModeType, TThrowOnError$1 extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType$1 extends ResponseTypeType = ResponseTypeType, TBasePluginArray$1 extends CallApiPlugin[] = DefaultPluginArray, TPluginArray$1 extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TCurrentRouteSchemaKey$1 extends string = string, TComputedPluginContext = InferExtendPluginContext<TBasePluginArray$1>, TComputedSchemaContext = InferExtendSchemaContext<TBaseSchemaRoutes$1, TCurrentRouteSchemaKey$1>, TComputedSchemaConfigContext = GetExtendSchemaConfigContext<TBaseSchemaConfig>> = SharedExtraOptions<TCallApiContext$1, TData$1, TErrorData$1, TResultMode$1, TThrowOnError$1, TResponseType$1, TPluginArray$1> & {
1706
1366
  /**
1707
1367
  * Array of instance-specific CallApi plugins or a function to configure plugins.
1708
1368
  *
@@ -1711,7 +1371,7 @@ type CallApiExtraOptions<TCallApiContext extends CallApiContext = CallApiContext
1711
1371
  * that receives base plugins and returns the instance plugins.
1712
1372
  *
1713
1373
  */
1714
- plugins?: TPluginArray | ((context: TComputedPluginContext) => TPluginArray);
1374
+ plugins?: TPluginArray$1 | ((context: TComputedPluginContext) => TPluginArray$1);
1715
1375
  /**
1716
1376
  * For instance-specific validation schemas
1717
1377
  *
@@ -1730,14 +1390,307 @@ type CallApiExtraOptions<TCallApiContext extends CallApiContext = CallApiContext
1730
1390
  */
1731
1391
  schemaConfig?: TSchemaConfig$1 | ((context: TComputedSchemaConfigContext) => TSchemaConfig$1);
1732
1392
  };
1733
- type CallApiExtraOptionsForHooks<TCallApiContext extends CallApiContext = CallApiContext> = Hooks & Omit<CallApiExtraOptions<TCallApiContext>, keyof Hooks>;
1393
+ type CallApiExtraOptionsForHooks<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> = Hooks & Omit<CallApiExtraOptions<TCallApiContext$1>, keyof Hooks>;
1734
1394
  type InstanceContext = {
1735
1395
  initURL: string;
1736
1396
  options: CallApiExtraOptions;
1737
1397
  request: CallApiRequestOptions;
1738
1398
  };
1739
- type BaseCallApiConfig<TBaseCallApiContext extends CallApiContext = CallApiContext, TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeType = ResultModeType, TBaseThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaAndConfig extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseCallApiContext, TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemaAndConfig>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: InstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
1740
- type CallApiConfig<TCallApiContext extends CallApiContext = CallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode extends ResultModeType = ResultModeType, TThrowOnError extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey extends string = string, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TPluginArray extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey, TCallApiContext> & InferRequestOptions<TSchema$1, TInitURL> & Omit<CallApiExtraOptions<TCallApiContext, TData$1, TErrorData$1, TResultMode, TThrowOnError, TResponseType, TBasePluginArray, TPluginArray, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TCurrentRouteSchemaKey>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string, CallApiContext>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
1399
+ type BaseCallApiConfig<TBaseCallApiContext$1 extends CallApiContext = DefaultCallApiContext, TBaseData$1 = DefaultDataType, TBaseErrorData$1 = DefaultDataType, TBaseResultMode$1 extends ResultModeType = ResultModeType, TBaseThrowOnError$1 extends ThrowOnErrorUnion = DefaultThrowOnError, TBaseResponseType$1 extends ResponseTypeType = ResponseTypeType, TBaseSchemaAndConfig$1 extends BaseCallApiSchemaAndConfig = BaseCallApiSchemaAndConfig, TBasePluginArray$1 extends CallApiPlugin[] = DefaultPluginArray, TComputedBaseConfig = BaseCallApiExtraOptions<TBaseCallApiContext$1, TBaseData$1, TBaseErrorData$1, TBaseResultMode$1, TBaseThrowOnError$1, TBaseResponseType$1, TBasePluginArray$1, TBaseSchemaAndConfig$1>> = (CallApiRequestOptions & TComputedBaseConfig) | ((context: InstanceContext) => CallApiRequestOptions & TComputedBaseConfig);
1400
+ type CallApiConfig<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext, TData$1 = DefaultDataType, TErrorData$1 = DefaultDataType, TResultMode$1 extends ResultModeType = ResultModeType, TThrowOnError$1 extends ThrowOnErrorUnion = DefaultThrowOnError, TResponseType$1 extends ResponseTypeType = ResponseTypeType, TBaseSchemaRoutes$1 extends BaseCallApiSchemaRoutes = BaseCallApiSchemaRoutes, TSchema$1 extends CallApiSchema = CallApiSchema, TBaseSchemaConfig extends CallApiSchemaConfig = CallApiSchemaConfig, TSchemaConfig$1 extends CallApiSchemaConfig = CallApiSchemaConfig, TInitURL$1 extends InitURLOrURLObject = InitURLOrURLObject, TCurrentRouteSchemaKey$1 extends string = string, TBasePluginArray$1 extends CallApiPlugin[] = DefaultPluginArray, TPluginArray$1 extends CallApiPlugin[] = DefaultPluginArray> = InferExtraOptions<TSchema$1, TBaseSchemaRoutes$1, TCurrentRouteSchemaKey$1, TCallApiContext$1> & InferRequestOptions<TSchema$1, TInitURL$1> & Omit<CallApiExtraOptions<TCallApiContext$1, TData$1, TErrorData$1, TResultMode$1, TThrowOnError$1, TResponseType$1, TBasePluginArray$1, TPluginArray$1, TBaseSchemaRoutes$1, TSchema$1, TBaseSchemaConfig, TSchemaConfig$1, TCurrentRouteSchemaKey$1>, keyof InferExtraOptions<CallApiSchema, BaseCallApiSchemaRoutes, string, CallApiContext>> & Omit<CallApiRequestOptions, keyof InferRequestOptions<CallApiSchema, string>>;
1401
+ //#endregion
1402
+ //#region src/stream.d.ts
1403
+ type StreamProgressEvent = {
1404
+ /**
1405
+ * Current chunk of data being streamed
1406
+ */
1407
+ chunk: Uint8Array;
1408
+ /**
1409
+ * Progress in percentage
1410
+ */
1411
+ progress: number;
1412
+ /**
1413
+ * Total size of data in bytes
1414
+ */
1415
+ totalBytes: number;
1416
+ /**
1417
+ * Amount of data transferred so far
1418
+ */
1419
+ transferredBytes: number;
1420
+ };
1421
+ declare global {
1422
+ interface ReadableStream<R> {
1423
+ [Symbol.asyncIterator]: () => AsyncIterableIterator<R>;
1424
+ }
1425
+ }
1426
+ //#endregion
1427
+ //#region src/hooks.d.ts
1428
+ interface Hooks<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> {
1429
+ /**
1430
+ * Hook called when any error occurs within the request/response lifecycle.
1431
+ *
1432
+ * This is a unified error handler that catches both request errors (network failures,
1433
+ * timeouts, etc.) and response errors (HTTP error status codes). It's essentially
1434
+ * a combination of `onRequestError` and `onResponseError` hooks.
1435
+ *
1436
+ * @param context - Error context containing error details, request info, and response (if available)
1437
+ * @returns Promise or void - Hook can be async or sync
1438
+ */
1439
+ onError?: (context: ErrorContext<TCallApiContext$1>) => Awaitable<unknown>;
1440
+ /**
1441
+ * Hook called before the HTTP request is sent and before any internal processing of the request object begins.
1442
+ *
1443
+ * This is the ideal place to modify request headers, add authentication,
1444
+ * implement request logging, or perform any setup before the network call.
1445
+ *
1446
+ * @param context - Request context with mutable request object and configuration
1447
+ * @returns Promise or void - Hook can be async or sync
1448
+ *
1449
+ */
1450
+ onRequest?: (context: RequestContext<TCallApiContext$1>) => Awaitable<unknown>;
1451
+ /**
1452
+ * Hook called when an error occurs during the fetch request itself.
1453
+ *
1454
+ * This handles network-level errors like connection failures, timeouts,
1455
+ * DNS resolution errors, or other issues that prevent getting an HTTP response.
1456
+ * Note that HTTP error status codes (4xx, 5xx) are handled by `onResponseError`.
1457
+ *
1458
+ * @param context - Request error context with error details and null response
1459
+ * @returns Promise or void - Hook can be async or sync
1460
+ */
1461
+ onRequestError?: (context: RequestErrorContext<TCallApiContext$1>) => Awaitable<unknown>;
1462
+ /**
1463
+ * Hook called just before the HTTP request is sent and after the request has been processed.
1464
+ *
1465
+ * @param context - Request context with mutable request object and configuration
1466
+ */
1467
+ onRequestReady?: (context: RequestContext<TCallApiContext$1>) => Awaitable<unknown>;
1468
+ /**
1469
+ * Hook called during upload stream progress tracking.
1470
+ *
1471
+ * This hook is triggered when uploading data (like file uploads) and provides
1472
+ * progress information about the upload. Useful for implementing progress bars
1473
+ * or upload status indicators.
1474
+ *
1475
+ * @param context - Request stream context with progress event and request instance
1476
+ * @returns Promise or void - Hook can be async or sync
1477
+ *
1478
+ */
1479
+ onRequestStream?: (context: RequestStreamContext<TCallApiContext$1>) => Awaitable<unknown>;
1480
+ /**
1481
+ * Hook called when any HTTP response is received from the API.
1482
+ *
1483
+ * This hook is triggered for both successful (2xx) and error (4xx, 5xx) responses.
1484
+ * It's useful for response logging, metrics collection, or any processing that
1485
+ * should happen regardless of response status.
1486
+ *
1487
+ * @param context - Response context with either success data or error information
1488
+ * @returns Promise or void - Hook can be async or sync
1489
+ *
1490
+ */
1491
+ onResponse?: (context: ResponseContext<TCallApiContext$1>) => Awaitable<unknown>;
1492
+ /**
1493
+ * Hook called when an HTTP error response (4xx, 5xx) is received from the API.
1494
+ *
1495
+ * This handles server-side errors where an HTTP response was successfully received
1496
+ * but indicates an error condition. Different from `onRequestError` which handles
1497
+ * network-level failures.
1498
+ *
1499
+ * @param context - Response error context with HTTP error details and response
1500
+ * @returns Promise or void - Hook can be async or sync
1501
+ */
1502
+ onResponseError?: (context: ResponseErrorContext<TCallApiContext$1>) => Awaitable<unknown>;
1503
+ /**
1504
+ * Hook called during download stream progress tracking.
1505
+ *
1506
+ * This hook is triggered when downloading data (like file downloads) and provides
1507
+ * progress information about the download. Useful for implementing progress bars
1508
+ * or download status indicators.
1509
+ *
1510
+ * @param context - Response stream context with progress event and response
1511
+ * @returns Promise or void - Hook can be async or sync
1512
+ *
1513
+ */
1514
+ onResponseStream?: (context: ResponseStreamContext<TCallApiContext$1>) => Awaitable<unknown>;
1515
+ /**
1516
+ * Hook called when a request is being retried.
1517
+ *
1518
+ * This hook is triggered before each retry attempt, providing information about
1519
+ * the previous failure and the current retry attempt number. Useful for implementing
1520
+ * custom retry logic, exponential backoff, or retry logging.
1521
+ *
1522
+ * @param context - Retry context with error details and retry attempt count
1523
+ * @returns Promise or void - Hook can be async or sync
1524
+ *
1525
+ */
1526
+ onRetry?: (response: RetryContext<TCallApiContext$1>) => Awaitable<unknown>;
1527
+ /**
1528
+ * Hook called when a successful response (2xx status) is received from the API.
1529
+ *
1530
+ * This hook is triggered only for successful responses and provides access to
1531
+ * the parsed response data. Ideal for success logging, caching, or post-processing
1532
+ * of successful API responses.
1533
+ *
1534
+ * @param context - Success context with parsed response data and response object
1535
+ * @returns Promise or void - Hook can be async or sync
1536
+ *
1537
+ */
1538
+ onSuccess?: (context: SuccessContext<TCallApiContext$1>) => Awaitable<unknown>;
1539
+ /**
1540
+ * Hook called when a validation error occurs.
1541
+ *
1542
+ * This hook is triggered when request or response data fails validation against
1543
+ * a defined schema. It provides access to the validation error details and can
1544
+ * be used for custom error handling, logging, or fallback behavior.
1545
+ *
1546
+ * @param context - Validation error context with error details and response (if available)
1547
+ * @returns Promise or void - Hook can be async or sync
1548
+ *
1549
+ */
1550
+ onValidationError?: (context: ValidationErrorContext<TCallApiContext$1>) => Awaitable<unknown>;
1551
+ }
1552
+ type HooksOrHooksArray<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> = { [Key in keyof Hooks<TCallApiContext$1>]: Hooks<TCallApiContext$1>[Key] | Array<Hooks<TCallApiContext$1>[Key]> };
1553
+ interface HookConfigOptions {
1554
+ /**
1555
+ * Controls the execution mode of all composed hooks (main + plugin hooks).
1556
+ *
1557
+ * - **"parallel"**: All hooks execute simultaneously via Promise.all() for better performance
1558
+ * - **"sequential"**: All hooks execute one by one in registration order via await in a loop
1559
+ *
1560
+ * This affects how ALL hooks execute together, regardless of their source (main or plugin).
1561
+ *
1562
+ * @default "parallel"
1563
+ */
1564
+ hooksExecutionMode?: "parallel" | "sequential";
1565
+ }
1566
+ type RequestContext<TCallApiContext$1 extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = {
1567
+ /**
1568
+ * Base configuration object passed to createFetchClient.
1569
+ *
1570
+ * Contains the foundational configuration that applies to all requests
1571
+ * made by this client instance, such as baseURL, default headers, and
1572
+ * global options.
1573
+ */
1574
+ baseConfig: Exclude<BaseCallApiConfig, AnyFunction$1>;
1575
+ /**
1576
+ * Instance-specific configuration object passed to the callApi instance.
1577
+ *
1578
+ * Contains configuration specific to this particular API call, which
1579
+ * can override or extend the base configuration.
1580
+ */
1581
+ config: CallApiConfig;
1582
+ /**
1583
+ * Merged options combining base config, instance config, and default options.
1584
+ *
1585
+ * This is the final resolved configuration that will be used for the request,
1586
+ * with proper precedence applied (instance > base > defaults).
1587
+ */
1588
+ options: CallApiExtraOptionsForHooks<TCallApiContext$1>;
1589
+ /**
1590
+ * Merged request object ready to be sent.
1591
+ *
1592
+ * Contains the final request configuration including URL, method, headers,
1593
+ * body, and other fetch options. This object can be modified in onRequest
1594
+ * hooks to customize the outgoing request.
1595
+ */
1596
+ request: CallApiRequestOptionsForHooks;
1597
+ };
1598
+ type ValidationErrorContext<TCallApiContext$1 extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<RequestContext<TCallApiContext$1> & {
1599
+ error: PossibleValidationError;
1600
+ response: Response | null;
1601
+ }>;
1602
+ type SuccessContext<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<RequestContext<TCallApiContext$1> & {
1603
+ data: NoInfer<TCallApiContext$1["Data"]>;
1604
+ response: Response;
1605
+ }>;
1606
+ type ResponseContext<TCallApiContext$1 extends Pick<CallApiContext, "Data" | "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<RequestContext<TCallApiContext$1> & (Prettify<CallApiResultSuccessVariant<TCallApiContext$1["Data"]>> | Prettify<Extract<CallApiResultErrorVariant<TCallApiContext$1["ErrorData"]>, {
1607
+ error: PossibleHTTPError<TCallApiContext$1["ErrorData"]>;
1608
+ }>>)>;
1609
+ type RequestErrorContext<TCallApiContext$1 extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = RequestContext<TCallApiContext$1> & {
1610
+ error: PossibleJavaScriptError;
1611
+ response: null;
1612
+ };
1613
+ type ErrorContext<TCallApiContext$1 extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<RequestContext<TCallApiContext$1> & ({
1614
+ error: PossibleHTTPError<TCallApiContext$1["ErrorData"]>;
1615
+ response: Response;
1616
+ } | {
1617
+ error: PossibleJavaScriptOrValidationError;
1618
+ response: Response | null;
1619
+ })>;
1620
+ type ResponseErrorContext<TCallApiContext$1 extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<Extract<ErrorContext<TCallApiContext$1>, {
1621
+ error: PossibleHTTPError<TCallApiContext$1["ErrorData"]>;
1622
+ }> & RequestContext<TCallApiContext$1>>;
1623
+ type RetryContext<TCallApiContext$1 extends Pick<CallApiContext, "ErrorData" | "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<ErrorContext<TCallApiContext$1> & {
1624
+ retryAttemptCount: number;
1625
+ }>;
1626
+ type RequestStreamContext<TCallApiContext$1 extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<RequestContext<TCallApiContext$1> & {
1627
+ event: StreamProgressEvent;
1628
+ requestInstance: Request;
1629
+ }>;
1630
+ type ResponseStreamContext<TCallApiContext$1 extends Pick<CallApiContext, "InferredPluginOptions" | "Meta"> = DefaultCallApiContext> = UnmaskType<RequestContext<TCallApiContext$1> & {
1631
+ event: StreamProgressEvent;
1632
+ response: Response;
1633
+ }>;
1634
+ //#endregion
1635
+ //#region src/plugins.d.ts
1636
+ type PluginSetupContext<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> = RequestContext<TCallApiContext$1> & {
1637
+ initURL: string;
1638
+ };
1639
+ type PluginInitResult<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> = Partial<Omit<PluginSetupContext<TCallApiContext$1>, "initURL" | "request"> & {
1640
+ initURL: InitURLOrURLObject;
1641
+ request: CallApiRequestOptions;
1642
+ }>;
1643
+ type PluginHooks<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> = HooksOrHooksArray<GetMergedCallApiContext<TCallApiContext$1, {
1644
+ Data: DefaultDataType extends TCallApiContext$1["Data"] ? never : TCallApiContext$1["Data"];
1645
+ ErrorData: DefaultDataType extends TCallApiContext$1["ErrorData"] ? never : TCallApiContext$1["ErrorData"];
1646
+ }>>;
1647
+ interface CallApiPlugin<TCallApiContext$1 extends CallApiContext = DefaultCallApiContext> {
1648
+ /**
1649
+ * Defines additional options that can be passed to callApi
1650
+ */
1651
+ defineExtraOptions?: (...params: never[]) => unknown;
1652
+ /**
1653
+ * A description for the plugin
1654
+ */
1655
+ description?: string;
1656
+ /**
1657
+ * Hooks for the plugin
1658
+ */
1659
+ hooks?: PluginHooks<TCallApiContext$1> | ((context: PluginSetupContext<TCallApiContext$1>) => Awaitable<PluginHooks<TCallApiContext$1>>);
1660
+ /**
1661
+ * A unique id for the plugin
1662
+ */
1663
+ id: string;
1664
+ /**
1665
+ * Middlewares that for the plugin
1666
+ */
1667
+ middlewares?: Middlewares<TCallApiContext$1> | ((context: PluginSetupContext<TCallApiContext$1>) => Awaitable<Middlewares<TCallApiContext$1>>);
1668
+ /**
1669
+ * A name for the plugin
1670
+ */
1671
+ name: string;
1672
+ /**
1673
+ * Base schema for the client.
1674
+ */
1675
+ schema?: BaseCallApiSchemaAndConfig;
1676
+ /**
1677
+ * A function that will be called when the plugin is initialized. This will be called before the any of the other internal functions.
1678
+ */
1679
+ setup?: (context: PluginSetupContext<TCallApiContext$1>) => Awaitable<PluginInitResult<TCallApiContext$1>> | Awaitable<void>;
1680
+ /**
1681
+ * A version for the plugin
1682
+ */
1683
+ version?: string;
1684
+ }
1685
+ //#endregion
1686
+ //#region src/types/default-types.d.ts
1687
+ type DefaultDataType = unknown;
1688
+ type DefaultPluginArray = CallApiPlugin[];
1689
+ type DefaultThrowOnError = boolean;
1690
+ type DefaultMetaObject = Record<string, unknown>;
1691
+ type DefaultCallApiContext = Omit<Required<CallApiContext>, "Meta"> & {
1692
+ Meta: GlobalMeta;
1693
+ };
1741
1694
  //#endregion
1742
1695
  //#region src/validation.d.ts
1743
1696
  type ResultVariant = "infer-input" | "infer-output";
@@ -1823,6 +1776,7 @@ type BaseCallApiSchemaAndConfig = {
1823
1776
  routes: BaseCallApiSchemaRoutes;
1824
1777
  };
1825
1778
  //#endregion
1779
+ //#region src/createFetchClient.d.ts
1826
1780
  //#endregion
1827
1781
  //#region src/logger/logger.d.ts
1828
1782
  type ConsoleLikeObject = {
@@ -1862,12 +1816,21 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
1862
1816
  name: "Logger";
1863
1817
  version: "1.1.0";
1864
1818
  hooks: {
1865
- onRequest: (ctx: RequestContext & PluginExtraOptions<unknown>) => void;
1866
- onRequestError: (ctx: RequestContext & {
1819
+ onRequest: (ctx: RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1820
+ Data: never;
1821
+ ErrorData: never;
1822
+ }>) => void;
1823
+ onRequestError: (ctx: RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1824
+ Data: never;
1825
+ ErrorData: never;
1826
+ }> & {
1867
1827
  error: PossibleJavaScriptError;
1868
1828
  response: null;
1869
- } & PluginExtraOptions<unknown>) => void;
1870
- onResponseError: (ctx: RequestContext & {
1829
+ }) => void;
1830
+ onResponseError: (ctx: RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1831
+ Data: never;
1832
+ ErrorData: never;
1833
+ }> & {
1871
1834
  error: {
1872
1835
  errorData: never;
1873
1836
  message: string;
@@ -1875,8 +1838,11 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
1875
1838
  originalError: _zayne_labs_callapi_utils0.HTTPError;
1876
1839
  };
1877
1840
  response: Response;
1878
- } & PluginExtraOptions<unknown>) => void;
1879
- onRetry: (ctx: ((RequestContext & ({
1841
+ }) => void;
1842
+ onRetry: (ctx: (RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1843
+ Data: never;
1844
+ ErrorData: never;
1845
+ }> & ({
1880
1846
  error: PossibleJavaScriptOrValidationError;
1881
1847
  response: Response | null;
1882
1848
  } | {
@@ -1889,15 +1855,21 @@ declare const loggerPlugin: (options?: LoggerOptions) => {
1889
1855
  response: Response;
1890
1856
  })) & {
1891
1857
  retryAttemptCount: number;
1892
- }) & PluginExtraOptions<unknown>) => void;
1893
- onSuccess: (ctx: RequestContext & {
1858
+ }) => void;
1859
+ onSuccess: (ctx: RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1860
+ Data: never;
1861
+ ErrorData: never;
1862
+ }> & {
1894
1863
  data: never;
1895
1864
  response: Response;
1896
- } & PluginExtraOptions<unknown>) => void;
1897
- onValidationError: (ctx: RequestContext & {
1865
+ }) => void;
1866
+ onValidationError: (ctx: RequestContext<Omit<DefaultCallApiContext, "Data" | "ErrorData"> & {
1867
+ Data: never;
1868
+ ErrorData: never;
1869
+ }> & {
1898
1870
  error: PossibleValidationError;
1899
1871
  response: Response | null;
1900
- } & PluginExtraOptions<unknown>) => void;
1872
+ }) => void;
1901
1873
  };
1902
1874
  };
1903
1875
  //#endregion