import { BrowserAuth } from "../../browser-auth" ; import { CredentialAuth } from "../../credential-auth" ; import { isTokenRotation , TokenRotation } from "../../mindconnect-base" ; import { TokenManagerAuth } from "../../tokenmanager-auth" ; import { AppCredentials , isAppCredentials , isServiceCredentials , MindSphereCredentials , ServiceCrendtials , } from "./credentials" ; export abstract class SdkClient { public async GetToken ( ) { return await this . _authenticator . GetToken ( ) ; } public async RenewToken ( ) { return await this . _authenticator . RenewToken ( ) ; } public GetGateway ( ) { return this . _authenticator . GetGateway ( ) ; } public GetTenant ( ) { return this . _authenticator . GetTenant ( ) ; } protected _authenticator : TokenRotation ; public async HttpAction ( { verb , gateway , baseUrl , authorization , body , message , octetStream , multiPartFormData , additionalHeaders , noResponse , rawResponse , returnHeaders , ignoreCodes , } ) { return this . _authenticator . HttpAction ( { verb , gateway , baseUrl , authorization , body , message , octetStream , multiPartFormData , additionalHeaders , noResponse , rawResponse , returnHeaders , ignoreCodes , } ) ; } param { ( TokenRotation | ServiceCrendtials | AppCredentials ) } credentialsOrAuthorizer memberOf constructor ( credentialsOrAuthorizer ? ) { if ( credentialsOrAuthorizer === undefined ) { this . _authenticator = new BrowserAuth ( ) ; } else if ( isTokenRotation ( credentialsOrAuthorizer ) ) { this . _authenticator = credentialsOrAuthorizer as TokenRotation ; } else if ( isAppCredentials ( credentialsOrAuthorizer ) ) { const appCredentials = credentialsOrAuthorizer as AppCredentials ; this . _authenticator = new TokenManagerAuth ( appCredentials . gateway , appCredentials . basicAuth , appCredentials . tenant , appCredentials . usertenant , appCredentials . appName , appCredentials . appVersion ) ; } else if ( isServiceCredentials ( credentialsOrAuthorizer ) ) { const credentialsAuth = credentialsOrAuthorizer as MindSphereCredentials ; this . _authenticator = new CredentialAuth ( credentialsAuth . gateway , credentialsAuth . basicAuth , credentialsAuth . tenant ) ; } else { throw new Error ( "invalid constructor" ) ; } } }