module Sfx { export declare namespace Standalone . http { type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE" | "HEAD" | "CONNECT" | "OPTIONS" | "TRACE" ; interface IHttpHeader { name : string ; value : string ; } interface IHttpResponse { httpVersion : string ; statusCode : number ; statusMessage : string ; data : any ; headers : Array < IHttpHeader > ; body : Array < number > ; } interface IHttpRequest { method : HttpMethod ; url : string ; headers ? : Array < IHttpHeader > ; body ? : any ; } interface IHttpClient { getRequestTemplateAsync ( ) : Promise < IHttpRequest > ; setRequestTemplateAsync ( template ) : Promise < void > ; getAsync < T > ( url ) : Promise < T > ; postAsync < T > ( url , data ) : Promise < T > ; putAsync < T > ( url , data ) : Promise < T > ; patchAsync < T > ( url , data ) : Promise < T > ; deleteAsync < T > ( url ) : Promise < T > ; headAsync < T > ( url ) : Promise < T > ; optionsAsync < T > ( url , data ) : Promise < T > ; traceAsync < T > ( url , data ) : Promise < T > ; requestAsync ( request ) : Promise < IHttpResponse > ; } } declare const sfxModuleManager ; export class StandaloneIntegration { private static _clusterUrl : string = null ; public static isStandalone ( ) { return typeof sfxModuleManager !== "undefined" && sfxModuleManager !== null ; } public static get clusterUrl ( ) : string { if ( StandaloneIntegration . _clusterUrl == null ) { if ( StandaloneIntegration . isStandalone ( ) ) { StandaloneIntegration . _clusterUrl = StandaloneIntegration . extractQueryItem ( window . location . search , "targetcluster" ) ; } else { StandaloneIntegration . _clusterUrl = "" ; } } return StandaloneIntegration . _clusterUrl ; } public static getHttpClient ( ) { if ( this . isStandalone ( ) ) { return sfxModuleManager . getComponentAsync < Standalone . http . IHttpClient > ( "http.http-client.service-fabric" ) ; } return undefined ; } private static extractQueryItem ( queryString , name ) { if ( queryString ) { let urlParameters = window . location . search . split ( "?" ) [ 1 ] ; let queryParams = urlParameters . split ( "&" ) ; for ( let i = 0 ; i < queryParams . length ; i ++ ) { let queryParam = queryParams [ i ] . split ( "=" ) ; if ( queryParam [ 0 ] === name ) { return decodeURIComponent ( queryParam [ 1 ] ) ; } } } return null ; } } }