@@ -273,6 +273,13 @@ export class Writer {
273273 } ) ;
274274 }
275275
276+ /**
277+ * Check whether the base URL is set to its default.
278+ */
279+ #baseURLOverridden( ) : boolean {
280+ return this . baseURL !== 'https://api.writer.com' ;
281+ }
282+
276283 protected defaultQuery ( ) : Record < string , string | undefined > | undefined {
277284 return this . _options . defaultQuery ;
278285 }
@@ -322,11 +329,16 @@ export class Writer {
322329 return Errors . APIError . generate ( status , error , message , headers ) ;
323330 }
324331
325- buildURL ( path : string , query : Record < string , unknown > | null | undefined ) : string {
332+ buildURL (
333+ path : string ,
334+ query : Record < string , unknown > | null | undefined ,
335+ defaultBaseURL ?: string | undefined ,
336+ ) : string {
337+ const baseURL = ( ! this . #baseURLOverridden( ) && defaultBaseURL ) || this . baseURL ;
326338 const url =
327339 isAbsoluteURL ( path ) ?
328340 new URL ( path )
329- : new URL ( this . baseURL + ( this . baseURL . endsWith ( '/' ) && path . startsWith ( '/' ) ? path . slice ( 1 ) : path ) ) ;
341+ : new URL ( baseURL + ( baseURL . endsWith ( '/' ) && path . startsWith ( '/' ) ? path . slice ( 1 ) : path ) ) ;
330342
331343 const defaultQuery = this . defaultQuery ( ) ;
332344 if ( ! isEmptyObj ( defaultQuery ) ) {
@@ -686,9 +698,9 @@ export class Writer {
686698 { retryCount = 0 } : { retryCount ?: number } = { } ,
687699 ) : { req : FinalizedRequestInit ; url : string ; timeout : number } {
688700 const options = { ...inputOptions } ;
689- const { method, path, query } = options ;
701+ const { method, path, query, defaultBaseURL } = options ;
690702
691- const url = this . buildURL ( path ! , query as Record < string , unknown > ) ;
703+ const url = this . buildURL ( path ! , query as Record < string , unknown > , defaultBaseURL ) ;
692704 if ( 'timeout' in options ) validatePositiveInteger ( 'timeout' , options . timeout ) ;
693705 options . timeout = options . timeout ?? this . timeout ;
694706 const { bodyHeaders, body } = this . buildBody ( { options } ) ;
0 commit comments