@@ -3,7 +3,7 @@ import type {
33 BasicRequestOptions ,
44 ApiClientConfig ,
55 Interceptors ,
6- RequestInitWithMethod ,
6+ RequestInitWithMethodAndURL ,
77 RequestOptions ,
88} from './types.js' ;
99
@@ -42,7 +42,7 @@ export class APIClient {
4242 }
4343
4444 async request ( endpoint : string , options : RequestOptions ) : Promise < Response > {
45- const url = new URL ( endpoint , this . baseUrl ) ;
45+ let url = new URL ( endpoint , this . baseUrl ) ;
4646
4747 if ( options . params ) {
4848 for ( const [ key , param ] of Object . entries ( options . params ) ) {
@@ -52,8 +52,9 @@ export class APIClient {
5252 }
5353 }
5454
55- let requestOptions : RequestInitWithMethod = {
55+ let requestOptions : RequestInitWithMethodAndURL = {
5656 method : options . method . toUpperCase ( ) ,
57+ url,
5758 ...this . config ,
5859 } ;
5960
@@ -87,10 +88,12 @@ export class APIClient {
8788
8889 if ( this . interceptors . request . length > 0 ) {
8990 for ( const interceptor of this . interceptors . request ) {
90- requestOptions = await interceptor ( url , requestOptions ) ;
91+ requestOptions = { ... requestOptions , ... ( await interceptor ( { ... requestOptions , url } ) ) } ;
9192 }
9293 }
9394
95+ url = requestOptions . url ;
96+
9497 const response = await fetch ( url , requestOptions ) ;
9598 if ( ! response . ok ) {
9699 throw new Error ( `Request failed with status code ${ response . status } ` ) ;
0 commit comments