@zayne-labs/callapi 1.7.2 → 1.7.4

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.
@@ -65,6 +65,34 @@ type CommonRequestHeaders = "Access-Control-Allow-Credentials" | "Access-Control
65
65
  type CommonAuthorizationHeaders = `${"Basic" | "Bearer" | "Token"} ${string}`;
66
66
  type CommonContentTypes = "application/epub+zip" | "application/gzip" | "application/json" | "application/ld+json" | "application/octet-stream" | "application/ogg" | "application/pdf" | "application/rtf" | "application/vnd.ms-fontobject" | "application/wasm" | "application/xhtml+xml" | "application/xml" | "application/zip" | "audio/aac" | "audio/mpeg" | "audio/ogg" | "audio/opus" | "audio/webm" | "audio/x-midi" | "font/otf" | "font/ttf" | "font/woff" | "font/woff2" | "image/avif" | "image/bmp" | "image/gif" | "image/jpeg" | "image/png" | "image/svg+xml" | "image/tiff" | "image/webp" | "image/x-icon" | "model/gltf-binary" | "model/gltf+json" | "text/calendar" | "text/css" | "text/csv" | "text/html" | "text/javascript" | "text/plain" | "video/3gpp" | "video/3gpp2" | "video/av1" | "video/mp2t" | "video/mp4" | "video/mpeg" | "video/ogg" | "video/webm" | "video/x-msvideo" | AnyString;
67
67
 
68
+ type ErrorDetails<TErrorResponse> = {
69
+ defaultErrorMessage: string;
70
+ errorData: TErrorResponse;
71
+ response: Response;
72
+ };
73
+ type ErrorOptions = {
74
+ cause?: unknown;
75
+ };
76
+ declare class HTTPError<TErrorResponse = Record<string, unknown>> {
77
+ cause: ErrorOptions["cause"];
78
+ errorData: ErrorDetails<TErrorResponse>["errorData"];
79
+ isHTTPError: boolean;
80
+ message: string;
81
+ name: "HTTPError";
82
+ response: ErrorDetails<TErrorResponse>["response"];
83
+ constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
84
+ }
85
+ type PossibleJavaScriptError = UnmaskType<{
86
+ errorData: DOMException | Error | SyntaxError | TypeError;
87
+ message: string;
88
+ name: "AbortError" | "Error" | "SyntaxError" | "TimeoutError" | "TypeError" | (`${string}Error` & {});
89
+ }>;
90
+ type PossibleHTTPError<TErrorData> = UnmaskType<{
91
+ errorData: TErrorData;
92
+ message: string;
93
+ name: "HTTPError";
94
+ }>;
95
+
68
96
  /**
69
97
  * The Standard Schema interface.
70
98
  * @see https://github.com/standard-schema/standard-schema
@@ -164,6 +192,24 @@ declare namespace StandardSchemaV1 {
164
192
  type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
165
193
  }
166
194
 
195
+ type Params = UnmaskType<Record<string, boolean | number | string> | Array<boolean | number | string>>;
196
+ type Query = UnmaskType<Record<string, boolean | number | string>>;
197
+ type InitURL = UnmaskType<string | URL>;
198
+ interface UrlOptions<TSchemas extends CallApiSchemas> {
199
+ /**
200
+ * URL to be used in the request.
201
+ */
202
+ readonly initURL?: string;
203
+ /**
204
+ * Parameters to be appended to the URL (i.e: /:id)
205
+ */
206
+ params?: InferSchemaResult<TSchemas["params"], Params>;
207
+ /**
208
+ * Query parameters to append to the URL.
209
+ */
210
+ query?: InferSchemaResult<TSchemas["query"], Query>;
211
+ }
212
+
167
213
  interface CallApiSchemas {
168
214
  /**
169
215
  * The schema to use for validating the request body.
@@ -215,72 +261,6 @@ interface CallApiValidators<TData = unknown, TErrorData = unknown> {
215
261
  }
216
262
  type InferSchemaResult<TSchema, TData> = TSchema extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<TSchema> : TData;
217
263
 
218
- type Params = UnmaskType<Record<string, boolean | number | string> | Array<boolean | number | string>>;
219
- type Query = UnmaskType<Record<string, boolean | number | string>>;
220
- type InitURL = UnmaskType<string | URL>;
221
- interface UrlOptions<TSchemas extends CallApiSchemas> {
222
- /**
223
- * URL to be used in the request.
224
- */
225
- readonly initURL?: string;
226
- /**
227
- * Parameters to be appended to the URL (i.e: /:id)
228
- */
229
- params?: InferSchemaResult<TSchemas["params"], Params>;
230
- /**
231
- * Query parameters to append to the URL.
232
- */
233
- query?: InferSchemaResult<TSchemas["query"], Query>;
234
- }
235
-
236
- type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;
237
- interface RetryOptions<TErrorData> {
238
- /**
239
- * Keeps track of the number of times the request has already been retried
240
- * @deprecated This property is used internally to track retries. Please abstain from modifying it.
241
- */
242
- readonly ["~retryCount"]?: number;
243
- /**
244
- * Number of allowed retry attempts on HTTP errors
245
- * @default 0
246
- */
247
- retryAttempts?: number;
248
- /**
249
- * Callback whose return value determines if a request should be retried or not
250
- */
251
- retryCondition?: RetryCondition<TErrorData>;
252
- /**
253
- * Delay between retries in milliseconds
254
- * @default 1000
255
- */
256
- retryDelay?: number;
257
- /**
258
- * Maximum delay in milliseconds. Only applies to exponential strategy
259
- * @default 10000
260
- */
261
- retryMaxDelay?: number;
262
- /**
263
- * HTTP methods that are allowed to retry
264
- * @default ["GET", "POST"]
265
- */
266
- retryMethods?: Method[];
267
- /**
268
- * HTTP status codes that trigger a retry
269
- * @default [409, 425, 429, 500, 502, 503, 504]
270
- */
271
- retryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>;
272
- /**
273
- * Strategy to use when retrying
274
- * @default "linear"
275
- */
276
- retryStrategy?: "exponential" | "linear";
277
- }
278
-
279
- type DefaultDataType = unknown;
280
- type DefaultMoreOptions = NonNullable<unknown>;
281
- type DefaultPluginArray = CallApiPlugin[];
282
- type DefaultThrowOnError = boolean;
283
-
284
264
  type Parser = (responseString: string) => Awaitable<Record<string, unknown>>;
285
265
  declare const getResponseType: <TResponse>(response: Response, parser?: Parser) => {
286
266
  arrayBuffer: () => Promise<ArrayBuffer>;
@@ -315,18 +295,6 @@ type StreamProgressEvent = {
315
295
  */
316
296
  transferredBytes: number;
317
297
  };
318
- type RequestStreamContext = {
319
- event: StreamProgressEvent;
320
- options: CombinedCallApiExtraOptions;
321
- request: CallApiRequestOptionsForHooks;
322
- requestInstance: Request;
323
- };
324
- type ResponseStreamContext = {
325
- event: StreamProgressEvent;
326
- options: CombinedCallApiExtraOptions;
327
- request: CallApiRequestOptionsForHooks;
328
- response: Response;
329
- };
330
298
  declare global {
331
299
  interface ReadableStream<R> {
332
300
  [Symbol.asyncIterator]: () => AsyncIterableIterator<R>;
@@ -336,13 +304,9 @@ declare global {
336
304
  type UnionToIntersection<TUnion> = (TUnion extends unknown ? (param: TUnion) => void : never) extends (param: infer TParam) => void ? TParam : never;
337
305
  type InferSchema<TResult> = TResult extends StandardSchemaV1 ? InferSchemaResult<TResult, NonNullable<unknown>> : TResult;
338
306
  type InferPluginOptions<TPluginArray extends CallApiPlugin[]> = UnionToIntersection<InferSchema<ReturnType<NonNullable<TPluginArray[number]["createExtraOptions"]>>>>;
339
- type PluginInitContext<TMoreOptions = DefaultMoreOptions> = WithMoreOptions<TMoreOptions> & {
340
- baseConfig: BaseCallApiExtraOptions & CallApiRequestOptions;
341
- config: CallApiExtraOptions & CallApiRequestOptions;
307
+ type PluginInitContext<TMoreOptions = DefaultMoreOptions> = Prettify<SharedHookContext & WithMoreOptions<TMoreOptions> & {
342
308
  initURL: InitURL | undefined;
343
- options: CombinedCallApiExtraOptions;
344
- request: CallApiRequestOptionsForHooks;
345
- };
309
+ }>;
346
310
  type PluginInitResult = Partial<Omit<PluginInitContext, "request"> & {
347
311
  request: CallApiRequestOptions;
348
312
  }>;
@@ -358,7 +322,7 @@ interface CallApiPlugin<TData = never, TErrorData = never> {
358
322
  /**
359
323
  * Hooks / Interceptors for the plugin
360
324
  */
361
- hooks?: InterceptorsOrInterceptorArray<TData, TErrorData>;
325
+ hooks?: hooksOrHooksArray<TData, TErrorData>;
362
326
  /**
363
327
  * A unique id for the plugin
364
328
  */
@@ -379,6 +343,156 @@ interface CallApiPlugin<TData = never, TErrorData = never> {
379
343
  declare const definePlugin: <TPlugin extends CallApiPlugin | AnyFunction<CallApiPlugin>>(plugin: TPlugin) => TPlugin;
380
344
  type Plugins<TPluginArray extends CallApiPlugin[]> = TPluginArray;
381
345
 
346
+ type DefaultDataType = unknown;
347
+ type DefaultMoreOptions = NonNullable<unknown>;
348
+ type DefaultPluginArray = CallApiPlugin[];
349
+ type DefaultThrowOnError = boolean;
350
+
351
+ type WithMoreOptions<TMoreOptions = DefaultMoreOptions> = {
352
+ options: CombinedCallApiExtraOptions & Partial<TMoreOptions>;
353
+ };
354
+ type Hooks<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> = {
355
+ /**
356
+ * Hook that will be called when any error occurs within the request/response lifecycle, regardless of whether the error is from the api or not.
357
+ * It is basically a combination of `onRequestError` and `onResponseError` hooks
358
+ */
359
+ onError?: (context: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
360
+ /**
361
+ * Hook that will be called just before the request is made, allowing for modifications or additional operations.
362
+ */
363
+ onRequest?: (context: Prettify<RequestContext & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
364
+ /**
365
+ * Hook that will be called when an error occurs during the fetch request.
366
+ */
367
+ onRequestError?: (context: Prettify<RequestErrorContext & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
368
+ /**
369
+ * Hook that will be called when upload stream progress is tracked
370
+ */
371
+ onRequestStream?: (context: Prettify<RequestStreamContext & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
372
+ /**
373
+ * Hook that will be called when any response is received from the api, whether successful or not
374
+ */
375
+ onResponse?: (context: ResponseContext<TData, TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
376
+ /**
377
+ * Hook that will be called when an error response is received from the api.
378
+ */
379
+ onResponseError?: (context: Prettify<ResponseErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
380
+ /**
381
+ * Hook that will be called when download stream progress is tracked
382
+ */
383
+ onResponseStream?: (context: Prettify<ResponseStreamContext & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
384
+ /**
385
+ * Hook that will be called when a request is retried.
386
+ */
387
+ onRetry?: (response: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
388
+ /**
389
+ * Hook that will be called when a successful response is received from the api.
390
+ */
391
+ onSuccess?: (context: Prettify<SuccessContext<TData> & WithMoreOptions<TMoreOptions>>) => Awaitable<unknown>;
392
+ };
393
+ type hooksOrHooksArray<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> = {
394
+ [Key in keyof Hooks<TData, TErrorData, TMoreOptions>]: Hooks<TData, TErrorData, TMoreOptions>[Key] | Array<Hooks<TData, TErrorData, TMoreOptions>[Key]>;
395
+ };
396
+ type SharedHookContext = {
397
+ /**
398
+ * Config object passed to createFetchClient
399
+ */
400
+ baseConfig: BaseCallApiExtraOptions & CallApiRequestOptions;
401
+ /**
402
+ * Config object passed to the callApi instance
403
+ */
404
+ config: CallApiExtraOptions & CallApiRequestOptions;
405
+ /**
406
+ * Merged options consisting of extra options from createFetchClient, the callApi instance and default options.
407
+ *
408
+ */
409
+ options: CombinedCallApiExtraOptions;
410
+ /**
411
+ * Merged request consisting of request options from createFetchClient, the callApi instance and default request options.
412
+ */
413
+ request: CallApiRequestOptionsForHooks;
414
+ };
415
+ type RequestContext = UnmaskType<SharedHookContext>;
416
+ type ResponseContext<TData, TErrorData> = UnmaskType<Prettify<SharedHookContext & {
417
+ data: TData;
418
+ error: null;
419
+ response: Response;
420
+ }> | Prettify<SharedHookContext & {
421
+ data: null;
422
+ error: PossibleHTTPError<TErrorData>;
423
+ response: Response;
424
+ }>>;
425
+ type SuccessContext<TData> = UnmaskType<Prettify<SharedHookContext & {
426
+ data: TData;
427
+ response: Response;
428
+ }>>;
429
+ type RequestErrorContext = UnmaskType<Prettify<SharedHookContext & {
430
+ error: PossibleJavaScriptError;
431
+ response: null;
432
+ }>>;
433
+ type ResponseErrorContext<TErrorData> = UnmaskType<Prettify<SharedHookContext & {
434
+ error: PossibleHTTPError<TErrorData>;
435
+ response: Response;
436
+ }>>;
437
+ type ErrorContext<TErrorData> = UnmaskType<Prettify<SharedHookContext & {
438
+ error: PossibleHTTPError<TErrorData>;
439
+ response: Response;
440
+ }> | Prettify<SharedHookContext & {
441
+ error: PossibleJavaScriptError;
442
+ response: null;
443
+ }>>;
444
+ type RequestStreamContext = UnmaskType<Prettify<SharedHookContext & {
445
+ event: StreamProgressEvent;
446
+ requestInstance: Request;
447
+ }>>;
448
+ type ResponseStreamContext = UnmaskType<Prettify<SharedHookContext & {
449
+ event: StreamProgressEvent;
450
+ response: Response;
451
+ }>>;
452
+
453
+ type RetryCondition<TErrorData> = (context: ErrorContext<TErrorData>) => Awaitable<boolean>;
454
+ interface RetryOptions<TErrorData> {
455
+ /**
456
+ * Keeps track of the number of times the request has already been retried
457
+ * @deprecated This property is used internally to track retries. Please abstain from modifying it.
458
+ */
459
+ readonly ["~retryCount"]?: number;
460
+ /**
461
+ * Number of allowed retry attempts on HTTP errors
462
+ * @default 0
463
+ */
464
+ retryAttempts?: number;
465
+ /**
466
+ * Callback whose return value determines if a request should be retried or not
467
+ */
468
+ retryCondition?: RetryCondition<TErrorData>;
469
+ /**
470
+ * Delay between retries in milliseconds
471
+ * @default 1000
472
+ */
473
+ retryDelay?: number;
474
+ /**
475
+ * Maximum delay in milliseconds. Only applies to exponential strategy
476
+ * @default 10000
477
+ */
478
+ retryMaxDelay?: number;
479
+ /**
480
+ * HTTP methods that are allowed to retry
481
+ * @default ["GET", "POST"]
482
+ */
483
+ retryMethods?: Method[];
484
+ /**
485
+ * HTTP status codes that trigger a retry
486
+ * @default [409, 425, 429, 500, 502, 503, 504]
487
+ */
488
+ retryStatusCodes?: Array<409 | 425 | 429 | 500 | 502 | 503 | 504 | AnyNumber>;
489
+ /**
490
+ * Strategy to use when retrying
491
+ * @default "linear"
492
+ */
493
+ retryStrategy?: "exponential" | "linear";
494
+ }
495
+
382
496
  type ModifiedRequestInit = RequestInit & {
383
497
  duplex?: "half";
384
498
  };
@@ -478,51 +592,6 @@ type CallApiRequestOptions<TSchemas extends CallApiSchemas = DefaultMoreOptions>
478
592
  type CallApiRequestOptionsForHooks<TSchemas extends CallApiSchemas = DefaultMoreOptions> = Omit<CallApiRequestOptions<TSchemas>, "headers"> & {
479
593
  headers?: Record<string, string | undefined>;
480
594
  };
481
- type WithMoreOptions<TMoreOptions = DefaultMoreOptions> = {
482
- options: CombinedCallApiExtraOptions & Partial<TMoreOptions>;
483
- };
484
- interface Interceptors<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> {
485
- /**
486
- * Interceptor that will be called when any error occurs within the request/response lifecycle, regardless of whether the error is from the api or not.
487
- * It is basically a combination of `onRequestError` and `onResponseError` interceptors
488
- */
489
- onError?: (context: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
490
- /**
491
- * Interceptor that will be called just before the request is made, allowing for modifications or additional operations.
492
- */
493
- onRequest?: (context: RequestContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
494
- /**
495
- * Interceptor that will be called when an error occurs during the fetch request.
496
- */
497
- onRequestError?: (context: RequestErrorContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
498
- /**
499
- * Interceptor that will be called when upload stream progress is tracked
500
- */
501
- onRequestStream?: (context: RequestStreamContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
502
- /**
503
- * Interceptor that will be called when any response is received from the api, whether successful or not
504
- */
505
- onResponse?: (context: ResponseContext<TData, TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
506
- /**
507
- * Interceptor that will be called when an error response is received from the api.
508
- */
509
- onResponseError?: (context: ResponseErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
510
- /**
511
- * Interceptor that will be called when download stream progress is tracked
512
- */
513
- onResponseStream?: (context: ResponseStreamContext & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
514
- /**
515
- * Interceptor that will be called when a request is retried.
516
- */
517
- onRetry?: (response: ErrorContext<TErrorData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
518
- /**
519
- * Interceptor that will be called when a successful response is received from the api.
520
- */
521
- onSuccess?: (context: SuccessContext<TData> & WithMoreOptions<TMoreOptions>) => Awaitable<unknown>;
522
- }
523
- type InterceptorsOrInterceptorArray<TData = DefaultDataType, TErrorData = DefaultDataType, TMoreOptions = DefaultMoreOptions> = {
524
- [Key in keyof Interceptors<TData, TErrorData, TMoreOptions>]: Interceptors<TData, TErrorData, TMoreOptions>[Key] | Array<Interceptors<TData, TErrorData, TMoreOptions>[Key]>;
525
- };
526
595
  type FetchImpl = UnmaskType<(input: string | Request | URL, init?: RequestInit) => Promise<Response>>;
527
596
  type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = DefaultMoreOptions> = {
528
597
  /**
@@ -569,7 +638,7 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
569
638
  * If true, forces the calculation of the total byte size from the request or response body, in case the content-length header is not present or is incorrect.
570
639
  * @default false
571
640
  */
572
- forceStreamSizeCalc?: boolean | {
641
+ forceCalculateStreamSize?: boolean | {
573
642
  request?: boolean;
574
643
  response?: boolean;
575
644
  };
@@ -578,14 +647,14 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
578
647
  */
579
648
  readonly fullURL?: string;
580
649
  /**
581
- * Defines the mode in which the merged hooks are executed, can be set to "parallel" | "sequential".
650
+ * Defines the mode in which the composed hooks are executed".
582
651
  * - If set to "parallel", main and plugin hooks will be executed in parallel.
583
652
  * - If set to "sequential", the plugin hooks will be executed first, followed by the main hook.
584
653
  * @default "parallel"
585
654
  */
586
655
  mergedHooksExecutionMode?: "parallel" | "sequential";
587
656
  /**
588
- * - Controls what order in which the merged hooks execute
657
+ * - Controls what order in which the composed hooks execute
589
658
  * @default "mainHooksAfterPlugins"
590
659
  */
591
660
  mergedHooksExecutionOrder?: "mainHooksAfterPlugins" | "mainHooksBeforePlugins";
@@ -594,7 +663,7 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
594
663
  */
595
664
  plugins?: Plugins<TPluginArray>;
596
665
  /**
597
- * Custom function to parse the response string into a object.
666
+ * Custom function to parse the response string
598
667
  */
599
668
  responseParser?: (responseString: string) => Awaitable<Record<string, unknown>>;
600
669
  /**
@@ -626,27 +695,44 @@ type ExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResult
626
695
  * Custom validation functions for response validation
627
696
  */
628
697
  validators?: CallApiValidators<TData, TErrorData>;
629
- } & InterceptorsOrInterceptorArray<TData, TErrorData> & Partial<InferPluginOptions<TPluginArray>> & MetaOption<TSchemas> & RetryOptions<TErrorData> & ResultModeOption<TErrorData, TResultMode> & UrlOptions<TSchemas>;
630
- declare const optionsEnumToExtendFromBase: ("plugins" | "schemas" | "validators")[];
698
+ } & hooksOrHooksArray<TData, TErrorData> & Partial<InferPluginOptions<TPluginArray>> & MetaOption<TSchemas> & RetryOptions<TErrorData> & ResultModeOption<TErrorData, TResultMode> & UrlOptions<TSchemas>;
631
699
  type CallApiExtraOptions<TData = DefaultDataType, TErrorData = DefaultDataType, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = DefaultMoreOptions> = ExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas> & {
632
- /**
633
- * Options that should extend the base options.
634
- */
635
- extend?: Pick<ExtraOptions<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>, (typeof optionsEnumToExtendFromBase)[number]>;
700
+ plugins?: Plugins<TPluginArray> | ((context: {
701
+ basePlugins: Plugins<TPluginArray>;
702
+ }) => Plugins<TPluginArray>);
703
+ schemas?: TSchemas | ((context: {
704
+ baseSchemas: TSchemas;
705
+ }) => TSchemas);
706
+ validators?: CallApiValidators<TData, TErrorData> | ((context: {
707
+ baseValidators: CallApiValidators<TData, TErrorData>;
708
+ }) => CallApiValidators<TData, TErrorData>);
636
709
  };
637
- declare const optionsEnumToOmitFromBase: ("dedupeKey" | "extend")[];
710
+ declare const optionsEnumToOmitFromBase: "dedupeKey"[];
638
711
  type BaseCallApiExtraOptions<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions> = Omit<Partial<CallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>>, (typeof optionsEnumToOmitFromBase)[number]> & {
639
712
  /**
640
- * If true, the base options will not be merged with the main options by default.
713
+ * Specifies which configuration parts should skip automatic merging between base and main configs.
714
+ * Use this when you need manual control over how configs are combined.
641
715
  *
642
- * It's recommended to set this to true when you want to handle the options merge manually from the createFetchClient config function signature.
716
+ * @values
717
+ * - "all" - Disables automatic merging for both request and options
718
+ * - "options" - Disables automatic merging of options only
719
+ * - "request" - Disables automatic merging of request only
643
720
  *
644
- * This helps prevent main options from overriding base options by default.
645
- * @default false
721
+ * @example
722
+ * ```ts
723
+ * const client = createFetchClient((ctx) => ({
724
+ * skipAutoMergeFor: "options",
725
+ *
726
+ * // Now you can manually merge options in your config function
727
+ * ...ctx.options,
728
+ * }));
729
+ * ```
646
730
  */
647
- mergeMainOptionsManuallyFromBase?: boolean;
731
+ skipAutoMergeFor?: "all" | "options" | "request";
648
732
  };
649
- type CombinedCallApiExtraOptions = Interceptors & Omit<BaseCallApiExtraOptions & CallApiExtraOptions, keyof Interceptors>;
733
+ type CombinedExtraOptionsWithoutHooks = Omit<BaseCallApiExtraOptions & CallApiExtraOptions, keyof Hooks>;
734
+ type ResolvedHooks = Hooks;
735
+ type CombinedCallApiExtraOptions = CombinedExtraOptionsWithoutHooks & ResolvedHooks;
650
736
  type BaseCallApiConfig<TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions> = (CallApiRequestOptions<TBaseSchemas> & BaseCallApiExtraOptions<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>) | ((context: {
651
737
  initURL: string;
652
738
  options: CallApiExtraOptions;
@@ -657,63 +743,6 @@ type CallApiParameters<TData = DefaultDataType, TErrorData = DefaultDataType, TR
657
743
  initURL: InferSchemaResult<TSchemas["initURL"], InitURL>,
658
744
  config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>
659
745
  ];
660
- type RequestContext = UnmaskType<{
661
- options: CombinedCallApiExtraOptions;
662
- request: CallApiRequestOptionsForHooks;
663
- }>;
664
- type ResponseContext<TData, TErrorData> = UnmaskType<{
665
- data: TData;
666
- error: null;
667
- options: CombinedCallApiExtraOptions;
668
- request: CallApiRequestOptionsForHooks;
669
- response: Response;
670
- } | {
671
- data: null;
672
- error: PossibleHTTPError<TErrorData>;
673
- options: CombinedCallApiExtraOptions;
674
- request: CallApiRequestOptionsForHooks;
675
- response: Response;
676
- }>;
677
- type SuccessContext<TData> = UnmaskType<{
678
- data: TData;
679
- options: CombinedCallApiExtraOptions;
680
- request: CallApiRequestOptionsForHooks;
681
- response: Response;
682
- }>;
683
- type PossibleJavascriptErrorNames = "AbortError" | "Error" | "SyntaxError" | "TimeoutError" | "TypeError" | (`${string}Error` & DefaultMoreOptions);
684
- type PossibleJavaScriptError = UnmaskType<{
685
- errorData: DOMException | Error | SyntaxError | TypeError;
686
- message: string;
687
- name: PossibleJavascriptErrorNames;
688
- }>;
689
- type PossibleHTTPError<TErrorData> = UnmaskType<{
690
- errorData: TErrorData;
691
- message: string;
692
- name: "HTTPError";
693
- }>;
694
- type RequestErrorContext = UnmaskType<{
695
- error: PossibleJavaScriptError;
696
- options: CombinedCallApiExtraOptions;
697
- request: CallApiRequestOptionsForHooks;
698
- response: null;
699
- }>;
700
- type ResponseErrorContext<TErrorData> = UnmaskType<{
701
- error: PossibleHTTPError<TErrorData>;
702
- options: CombinedCallApiExtraOptions;
703
- request: CallApiRequestOptionsForHooks;
704
- response: Response;
705
- }>;
706
- type ErrorContext<TErrorData> = UnmaskType<{
707
- error: PossibleHTTPError<TErrorData>;
708
- options: CombinedCallApiExtraOptions;
709
- request: CallApiRequestOptionsForHooks;
710
- response: Response;
711
- } | {
712
- error: PossibleJavaScriptError;
713
- options: CombinedCallApiExtraOptions;
714
- request: CallApiRequestOptionsForHooks;
715
- response: null;
716
- }>;
717
746
  type CallApiResultSuccessVariant<TData> = {
718
747
  data: TData;
719
748
  error: null;
@@ -742,20 +771,4 @@ type ResultModeUnion = keyof ResultModeMap | undefined;
742
771
  type GetCallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = TErrorData extends false | undefined ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : ResultModeUnion | undefined extends TResultMode ? TThrowOnError extends true ? ResultModeMap<TData, TErrorData, TResponseType>["allWithException"] : ResultModeMap<TData, TErrorData, TResponseType>["all"] : TResultMode extends NonNullable<ResultModeUnion> ? TResultMode extends "onlySuccess" ? ResultModeMap<TData, TErrorData, TResponseType>["onlySuccessWithException"] : TResultMode extends "onlyResponse" ? ResultModeMap<TData, TErrorData, TResponseType>["onlyResponseWithException"] : ResultModeMap<TData, TErrorData, TResponseType>[TResultMode] : never;
743
772
  type CallApiResult<TData, TErrorData, TResultMode extends ResultModeUnion, TThrowOnError extends boolean, TResponseType extends ResponseTypeUnion> = Promise<GetCallApiResult<TData, TErrorData, TResultMode, TThrowOnError, TResponseType>>;
744
773
 
745
- type ErrorDetails<TErrorResponse> = {
746
- defaultErrorMessage: string;
747
- errorData: TErrorResponse;
748
- response: Response;
749
- };
750
- type ErrorOptions = {
751
- cause?: unknown;
752
- };
753
- declare class HTTPError<TErrorResponse = Record<string, unknown>> extends Error {
754
- errorData: ErrorDetails<TErrorResponse>["errorData"];
755
- isHTTPError: boolean;
756
- name: "HTTPError";
757
- response: ErrorDetails<TErrorResponse>["response"];
758
- constructor(errorDetails: ErrorDetails<TErrorResponse>, errorOptions?: ErrorOptions);
759
- }
760
-
761
- export { type ResponseContext as A, type BaseCallApiConfig as B, type CallApiPlugin as C, type DefaultPluginArray as D, type ErrorContext as E, type ResponseErrorContext as F, HTTPError as H, type InferSchemaResult as I, type PluginInitContext as P, type ResultModeUnion as R, type SuccessContext as S, type ResponseTypeUnion as a, type CallApiSchemas as b, type CallApiConfig as c, type CallApiResult as d, type DefaultDataType as e, type DefaultThrowOnError as f, type DefaultMoreOptions as g, type CallApiParameters as h, definePlugin as i, getDefaultOptions as j, type RetryOptions as k, type BaseCallApiExtraOptions as l, type CallApiExtraOptions as m, type PossibleJavaScriptError as n, type PossibleHTTPError as o, type CallApiRequestOptions as p, type CallApiRequestOptionsForHooks as q, type CallApiResultErrorVariant as r, type CallApiResultSuccessVariant as s, type CombinedCallApiExtraOptions as t, type Interceptors as u, type InterceptorsOrInterceptorArray as v, type PossibleJavascriptErrorNames as w, type Register as x, type RequestContext as y, type RequestErrorContext as z };
774
+ export { type CallApiResultErrorVariant as A, type BaseCallApiConfig as B, type CallApiPlugin as C, type DefaultPluginArray as D, type ErrorContext as E, type CallApiResultSuccessVariant as F, type CombinedCallApiExtraOptions as G, HTTPError as H, type InferSchemaResult as I, type Register as J, type PluginInitContext as P, type ResultModeUnion as R, type SharedHookContext as S, type ResponseTypeUnion as a, type CallApiSchemas as b, type CallApiConfig as c, type CallApiResult as d, type DefaultDataType as e, type DefaultThrowOnError as f, type DefaultMoreOptions as g, type CallApiParameters as h, definePlugin as i, getDefaultOptions as j, type RetryOptions as k, type PossibleHTTPError as l, type PossibleJavaScriptError as m, type Hooks as n, type hooksOrHooksArray as o, type RequestContext as p, type RequestErrorContext as q, type RequestStreamContext as r, type ResponseContext as s, type ResponseErrorContext as t, type ResponseStreamContext as u, type SuccessContext as v, type BaseCallApiExtraOptions as w, type CallApiExtraOptions as x, type CallApiRequestOptions as y, type CallApiRequestOptionsForHooks as z };
@@ -1,7 +1,7 @@
1
- import { R as ResultModeUnion, a as ResponseTypeUnion, C as CallApiPlugin, D as DefaultPluginArray, b as CallApiSchemas, I as InferSchemaResult, c as CallApiConfig, d as CallApiResult, e as DefaultDataType, f as DefaultThrowOnError, g as DefaultMoreOptions, B as BaseCallApiConfig, h as CallApiParameters } from './error-By05WYGj.js';
2
- export { l as BaseCallApiExtraOptions, m as CallApiExtraOptions, p as CallApiRequestOptions, q as CallApiRequestOptionsForHooks, r as CallApiResultErrorVariant, s as CallApiResultSuccessVariant, t as CombinedCallApiExtraOptions, E as ErrorContext, H as HTTPError, u as Interceptors, v as InterceptorsOrInterceptorArray, P as PluginInitContext, o as PossibleHTTPError, n as PossibleJavaScriptError, w as PossibleJavascriptErrorNames, x as Register, y as RequestContext, z as RequestErrorContext, A as ResponseContext, F as ResponseErrorContext, k as RetryOptions, S as SuccessContext, i as definePlugin, j as getDefaultOptions } from './error-By05WYGj.js';
1
+ import { R as ResultModeUnion, a as ResponseTypeUnion, C as CallApiPlugin, D as DefaultPluginArray, b as CallApiSchemas, I as InferSchemaResult, c as CallApiConfig, d as CallApiResult, e as DefaultDataType, f as DefaultThrowOnError, g as DefaultMoreOptions, B as BaseCallApiConfig, h as CallApiParameters } from './common-DiBiESb2.js';
2
+ export { w as BaseCallApiExtraOptions, x as CallApiExtraOptions, y as CallApiRequestOptions, z as CallApiRequestOptionsForHooks, A as CallApiResultErrorVariant, F as CallApiResultSuccessVariant, G as CombinedCallApiExtraOptions, E as ErrorContext, H as HTTPError, n as Hooks, P as PluginInitContext, l as PossibleHTTPError, m as PossibleJavaScriptError, J as Register, p as RequestContext, q as RequestErrorContext, r as RequestStreamContext, s as ResponseContext, t as ResponseErrorContext, u as ResponseStreamContext, k as RetryOptions, S as SharedHookContext, v as SuccessContext, i as definePlugin, j as getDefaultOptions, o as hooksOrHooksArray } from './common-DiBiESb2.js';
3
3
 
4
- declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions>(baseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>) => <TData = InferSchemaResult<TBaseSchemas["data"], TBaseData>, TErrorData = InferSchemaResult<TBaseSchemas["errorData"], TBaseErrorData>, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends boolean = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, TPluginArray extends CallApiPlugin[] = TBasePluginArray, TSchemas extends CallApiSchemas = TBaseSchemas>(initURL: InferSchemaResult<TSchemas["initURL"], string | URL>, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas> | undefined) => CallApiResult<InferSchemaResult<TSchemas["data"], TData>, InferSchemaResult<TSchemas["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
4
+ declare const createFetchClient: <TBaseData = DefaultDataType, TBaseErrorData = DefaultDataType, TBaseResultMode extends ResultModeUnion = ResultModeUnion, TBaseThrowOnError extends boolean = DefaultThrowOnError, TBaseResponseType extends ResponseTypeUnion = ResponseTypeUnion, TBasePluginArray extends CallApiPlugin[] = DefaultPluginArray, TBaseSchemas extends CallApiSchemas = DefaultMoreOptions>(initBaseConfig?: BaseCallApiConfig<TBaseData, TBaseErrorData, TBaseResultMode, TBaseThrowOnError, TBaseResponseType, TBasePluginArray, TBaseSchemas>) => <TData = InferSchemaResult<TBaseSchemas["data"], TBaseData>, TErrorData = InferSchemaResult<TBaseSchemas["errorData"], TBaseErrorData>, TResultMode extends ResultModeUnion = TBaseResultMode, TThrowOnError extends boolean = TBaseThrowOnError, TResponseType extends ResponseTypeUnion = TBaseResponseType, TPluginArray extends CallApiPlugin[] = TBasePluginArray, TSchemas extends CallApiSchemas = TBaseSchemas>(initURL: InferSchemaResult<TSchemas["initURL"], string | URL>, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas> | undefined) => CallApiResult<InferSchemaResult<TSchemas["data"], TData>, InferSchemaResult<TSchemas["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
5
5
  declare const callApi: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = boolean, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = {}>(initURL: InferSchemaResult<TSchemas["initURL"], string | URL>, config?: CallApiConfig<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas> | undefined) => CallApiResult<InferSchemaResult<TSchemas["data"], TData>, InferSchemaResult<TSchemas["errorData"], TErrorData>, TResultMode, TThrowOnError, TResponseType>;
6
6
 
7
7
  declare const defineParameters: <TData = unknown, TErrorData = unknown, TResultMode extends ResultModeUnion = ResultModeUnion, TThrowOnError extends boolean = DefaultThrowOnError, TResponseType extends ResponseTypeUnion = ResponseTypeUnion, TPluginArray extends CallApiPlugin[] = DefaultPluginArray, TSchemas extends CallApiSchemas = DefaultMoreOptions>(...parameters: CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>) => CallApiParameters<TData, TErrorData, TResultMode, TThrowOnError, TResponseType, TPluginArray, TSchemas>;