@@ -19,14 +19,7 @@ import type {
1919import type { DefaultCallApiContext } from "./types/default-types" ;
2020import type { AnyFunction , Awaitable , Prettify , UnmaskType } from "./types/type-helpers" ;
2121
22- export interface Hooks <
23- TCallApiContext extends Pick <
24- CallApiContext ,
25- "Data" | "ErrorData" | "InferredPluginOptions" | "Meta"
26- > = DefaultCallApiContext ,
27- TData = TCallApiContext [ "Data" ] ,
28- TErrorData = TCallApiContext [ "ErrorData" ] ,
29- > {
22+ export interface Hooks < TCallApiContext extends CallApiContext = DefaultCallApiContext > {
3023 /**
3124 * Hook called when any error occurs within the request/response lifecycle.
3225 *
@@ -37,7 +30,7 @@ export interface Hooks<
3730 * @param context - Error context containing error details, request info, and response (if available)
3831 * @returns Promise or void - Hook can be async or sync
3932 */
40- onError ?: ( context : ErrorContext < TCallApiContext , TErrorData > ) => Awaitable < unknown > ;
33+ onError ?: ( context : ErrorContext < TCallApiContext > ) => Awaitable < unknown > ;
4134
4235 /**
4336 * Hook called before the HTTP request is sent and before any internal processing of the request object begins.
@@ -94,7 +87,7 @@ export interface Hooks<
9487 * @returns Promise or void - Hook can be async or sync
9588 *
9689 */
97- onResponse ?: ( context : ResponseContext < TCallApiContext , TData , TErrorData > ) => Awaitable < unknown > ;
90+ onResponse ?: ( context : ResponseContext < TCallApiContext > ) => Awaitable < unknown > ;
9891
9992 /**
10093 * Hook called when an HTTP error response (4xx, 5xx) is received from the API.
@@ -106,7 +99,7 @@ export interface Hooks<
10699 * @param context - Response error context with HTTP error details and response
107100 * @returns Promise or void - Hook can be async or sync
108101 */
109- onResponseError ?: ( context : ResponseErrorContext < TCallApiContext , TErrorData > ) => Awaitable < unknown > ;
102+ onResponseError ?: ( context : ResponseErrorContext < TCallApiContext > ) => Awaitable < unknown > ;
110103
111104 /**
112105 * Hook called during download stream progress tracking.
@@ -132,7 +125,7 @@ export interface Hooks<
132125 * @returns Promise or void - Hook can be async or sync
133126 *
134127 */
135- onRetry ?: ( response : RetryContext < TCallApiContext , TErrorData > ) => Awaitable < unknown > ;
128+ onRetry ?: ( response : RetryContext < TCallApiContext > ) => Awaitable < unknown > ;
136129
137130 /**
138131 * Hook called when a successful response (2xx status) is received from the API.
@@ -145,7 +138,7 @@ export interface Hooks<
145138 * @returns Promise or void - Hook can be async or sync
146139 *
147140 */
148- onSuccess ?: ( context : SuccessContext < TCallApiContext , TData > ) => Awaitable < unknown > ;
141+ onSuccess ?: ( context : SuccessContext < TCallApiContext > ) => Awaitable < unknown > ;
149142
150143 /**
151144 * Hook called when a validation error occurs.
@@ -161,15 +154,11 @@ export interface Hooks<
161154 onValidationError ?: ( context : ValidationErrorContext < TCallApiContext > ) => Awaitable < unknown > ;
162155}
163156
164- export type HooksOrHooksArray <
165- TCallApiContext extends CallApiContext = DefaultCallApiContext ,
166- TData = TCallApiContext [ "Data" ] ,
167- TErrorData = TCallApiContext [ "ErrorData" ] ,
168- > = {
169- [ Key in keyof Hooks < TCallApiContext , TData , TErrorData > ] :
170- | Hooks < TCallApiContext , TData , TErrorData > [ Key ]
157+ export type HooksOrHooksArray < TCallApiContext extends CallApiContext = DefaultCallApiContext > = {
158+ [ Key in keyof Hooks < TCallApiContext > ] :
159+ | Hooks < TCallApiContext > [ Key ]
171160 // eslint-disable-next-line perfectionist/sort-union-types -- I need arrays to be last
172- | Array < Hooks < TCallApiContext , TData , TErrorData > [ Key ] > ;
161+ | Array < Hooks < TCallApiContext > [ Key ] > ;
173162} ;
174163
175164export interface HookConfigOptions {
@@ -238,10 +227,9 @@ export type SuccessContext<
238227 CallApiContext ,
239228 "Data" | "InferredPluginOptions" | "Meta"
240229 > = DefaultCallApiContext ,
241- TData = TCallApiContext [ "Data" ] ,
242230> = UnmaskType <
243231 RequestContext < TCallApiContext > & {
244- data : NoInfer < TData > ;
232+ data : NoInfer < TCallApiContext [ "Data" ] > ;
245233 response : Response ;
246234 }
247235> ;
@@ -251,14 +239,15 @@ export type ResponseContext<
251239 CallApiContext ,
252240 "Data" | "ErrorData" | "InferredPluginOptions" | "Meta"
253241 > = DefaultCallApiContext ,
254- TData = TCallApiContext [ "Data" ] ,
255- TErrorData = TCallApiContext [ "ErrorData" ] ,
256242> = UnmaskType <
257243 RequestContext < TCallApiContext >
258244 & (
259- | Prettify < CallApiResultSuccessVariant < TData > >
245+ | Prettify < CallApiResultSuccessVariant < TCallApiContext [ "Data" ] > >
260246 | Prettify <
261- Extract < CallApiResultErrorVariant < TErrorData > , { error : PossibleHTTPError < TErrorData > } >
247+ Extract <
248+ CallApiResultErrorVariant < TCallApiContext [ "ErrorData" ] > ,
249+ { error : PossibleHTTPError < TCallApiContext [ "ErrorData" ] > }
250+ >
262251 >
263252 )
264253> ;
@@ -275,12 +264,11 @@ export type ErrorContext<
275264 CallApiContext ,
276265 "ErrorData" | "InferredPluginOptions" | "Meta"
277266 > = DefaultCallApiContext ,
278- TErrorData = TCallApiContext [ "ErrorData" ] ,
279267> = UnmaskType <
280268 RequestContext < TCallApiContext >
281269 & (
282270 | {
283- error : PossibleHTTPError < TErrorData > ;
271+ error : PossibleHTTPError < TCallApiContext [ "ErrorData" ] > ;
284272 response : Response ;
285273 }
286274 | {
@@ -295,9 +283,8 @@ export type ResponseErrorContext<
295283 CallApiContext ,
296284 "ErrorData" | "InferredPluginOptions" | "Meta"
297285 > = DefaultCallApiContext ,
298- TErrorData = TCallApiContext [ "ErrorData" ] ,
299286> = UnmaskType <
300- Extract < ErrorContext < TCallApiContext , TErrorData > , { error : PossibleHTTPError < TErrorData > } >
287+ Extract < ErrorContext < TCallApiContext > , { error : PossibleHTTPError < TCallApiContext [ "ErrorData" ] > } >
301288 & RequestContext < TCallApiContext >
302289> ;
303290
@@ -306,9 +293,8 @@ export type RetryContext<
306293 CallApiContext ,
307294 "ErrorData" | "InferredPluginOptions" | "Meta"
308295 > = DefaultCallApiContext ,
309- TErrorData = TCallApiContext [ "ErrorData" ] ,
310296> = UnmaskType <
311- ErrorContext < TCallApiContext , TErrorData > & {
297+ ErrorContext < TCallApiContext > & {
312298 retryAttemptCount : number ;
313299 }
314300> ;
0 commit comments