packageDocumentation module import { AccessToken , Logger } from "@itwin/core-bentley" ; import * as deepAssign from "deep-assign" ; import { IModelHubClientLoggerCategory } from "../IModelHubClientLoggerCategories" ; import { request , RequestOptions } from "../itwin-client/Request" ; const loggerCategory = IModelHubClientLoggerCategory . Clients ; internal export class DefaultRequestOptionsProvider { protected _defaultOptions : RequestOptions ; /** Creates an instance of DefaultRequestOptionsProvider and sets up the default options. */ constructor ( ) { this . _defaultOptions = { method : "GET" , useCorsProxy : false } ; } note param options public async assignOptions ( options ) { const clonedOptions = { ... options } ; deepAssign . default ( options , this . _defaultOptions ) ; deepAssign . default ( options , clonedOptions ) ; } } beta export abstract class Client { private static _defaultRequestOptionsProvider : DefaultRequestOptionsProvider ; protected _url ? : string ; /**
      * Sets the default base URL to use with this client.
      */ protected baseUrl ? : string ; /**  Creates an instance of Client. */ protected constructor ( ) { } note param options returns internal protected async setupOptionDefaults ( options ) { if ( ! Client . _defaultRequestOptionsProvider ) Client . _defaultRequestOptionsProvider = new DefaultRequestOptionsProvider ( ) ; return Client . _defaultRequestOptionsProvider . assignOptions ( options ) ; } returns public async getUrl ( ) { if ( this . _url ) return this . _url ; if ( ! this . baseUrl ) { throw new Error ( "The client is missing a default url." ) ; } const prefix = process . env . IMJS_URL_PREFIX ; if ( prefix ) { const baseUrl = new URL ( this . baseUrl ) ; baseUrl . hostname = prefix + baseUrl . hostname ; this . _url = baseUrl . href ; } else { this . _url = this . baseUrl ; } this . _url = this . _url . replace ( /\/$/ , "" ) ; return this . _url ; } /** used by clients to send delete requests */ protected async delete ( accessToken , relativeUrlPath ) { const url = await this . getUrl ( ) + relativeUrlPath ; Logger . logInfo ( loggerCategory , "Sending DELETE request" , ( ) => ( { url } ) ) ; const options = { method : "DELETE" , headers : { authorization : accessToken } } ; await this . setupOptionDefaults ( options ) ; await request ( url , options ) ; Logger . logTrace ( loggerCategory , "Successful DELETE request" , ( ) => ( { url } ) ) ; } }