import { HttpMethods , HttpOperationResponse , ParameterValue , ServiceClient , WebResource } from "@azure/ms-rest-js" ; import { TokenCredentialsBase } from "@azure/ms-rest-nodeauth" ; import requestPromise from 'request-promise' ; import { appendExtensionUserAgent , createGenericClient } from "vscode-azureextensionui" ; export type nRequest = WebResource & requestPromise . RequestPromiseOptions ; export async function request ( credentials , url , method , queryParameters ? , body ? ) { const client = await createGenericClient ( credentials ) ; return await client . sendRequest ( { method : method , url : url , queryParameters : queryParameters , body : body } ) ; } export async function sendRequest < T > ( httpReq ) { return await < Thenable < T > > requestPromise ( httpReq ) . promise ( ) ; } export async function getBearerToken ( url , method , credentials ) { const requestOptions = new WebResource ( ) ; requestOptions . headers . set ( "User-Agent" , appendExtensionUserAgent ( ) ) ; requestOptions . url = url ; requestOptions . method = method ; try { await credentials . signRequest ( requestOptions ) ; } catch ( err ) { throw err ; } const headers = requestOptions . headers ; const authToken = headers [ 'authorization' ] ; if ( authToken === undefined ) { throw new Error ( "Authorization header is missing" ) ; } else { return authToken ; } }