import { Observable } from 'rxjs'; import { AjaxError, AjaxRequest } from 'rxjs/ajax'; import { RpcForwardResponse } from '../rpc/forward/rpc-forward-model'; import { Rpc } from '../rpc/rpc'; import { RpcRelationshipType } from '../rpc/rpc-base'; import { RpcServiceForwarder } from '../rpc/rpc-forwarder'; import { AuthorizationManager } from '../security/authorization-manager'; import { GatewayUrlBuilder } from './gateway-url-builder'; import { Http, HttpResponseRetryHandler } from './http'; /** * Gateway Request options that we use to extend the AjaxRequest interface */ export interface GatewayRequestOptions { /** * Retry handler implementation for a request. * These handlers are used to invoke specific functionality for non-200 status codes in the http response. */ retryHandlers?: HttpResponseRetryHandler[]; /** * Determines the maximum number of times that any of the retry handlers will be tried. * before giving up and surfacing the error to the original caller */ maxRetryCount?: number; /** * Observable handler to insert asynchronous logic before the actual http response is sent. * For Example: Waiting for pending authentication to complete before adding an authentication header */ beforeCall?: (request: GatewayRequest) => Observable; } /** * Extension of AjaxRequest interface for calling the Gateway API */ export interface GatewayRequest extends AjaxRequest, GatewayRequestOptions { } /** * Initialization object data for the Gateway's base class. */ export interface GatewayRPCForwardedProperties { /** * The gateway URL. */ gatewayName: string; /** * Indicate whether gatewayUrl option was specified. (default to be false) */ gatewayUrlSpecified: boolean; /** * The stative version. (default to be null) */ staticVersion: string; } /** * The gateway information on current gateway URL. */ export interface GatewayInformation { /** * The name of gateway node. */ name: string; /** * Indicating if https is used. */ secure: boolean; /** * The port number of gateway. */ port: number; } /** * Condition of gateway. */ export interface GatewayCondition { /** * the gateway is running as service mode (installed on server operating system). */ isServiceMode: boolean; /** * the gateway is elevated on the desktop mode. */ isGatewayProcessElevated: boolean; /** * the user account is a member of the gateway administrators. */ isGatewayAdmin: boolean; } /** * The Gateway Connection class for creating requests and calling the Gateway's REST API */ export declare class GatewayConnection extends RpcServiceForwarder { http: Http; private authorizationManager; private static rpcCommands; /** * The IPv4 address for localhost */ private readonly localhostIpV4; /** * The IPv6 address for localhost */ private readonly localhostIpV6; /** * The localhost name */ private readonly localhost; /** * Time interval to check for internalGatewayStatus refresh. */ private readonly lastUpdatedInternalGatewayStatusInterval; /** * internally maintained gateway URL. */ private internalGatewayUrl; /** * internally maintained static version. */ private internalStaticVersion; /** * gatewayUrl param is specified. */ private internalGatewayUrlSpecified; /** * Last time internal gateway status was updated in milliseconds */ private lastUpdatedInternalGatewayStatus; /** * Internally maintained gateway status. */ private internalGatewayStatus; /** * The replay subject for gateway url to settle. */ private gatewayUrlAwaiter; /** * The RPC observable elevate client. */ private elevateClient; /** * The RPC observable elevate server. */ private elevateServer; /** * The elevate callback observable. */ private elevateCallbackInternal; /** * The replay subject for navigation ready state. */ private navigationReady; /** * Sets the elevate callback observable. */ set elevateCallback(value: () => Observable); /** * Indicates that the gateway is disabled and therefore should not be called. */ get disabled(): boolean; /** * Gets the gateway URL to connect to. */ get gatewayUrl(): string; /** * Gets the gateway URL specified state. */ get staticVersion(): string; /** * Gets the gateway URL specified state. */ get gatewayUrlSpecified(): boolean; /** * Gets the gateway URL observable while setting up. */ get gatewayUrlObservable(): Observable; /** * Gets the navigation ready observable. */ get navigationReadyObservable(): Observable; /** * Sets the navigation ready status. */ set navigationReadyStatus(ready: boolean); /** * Gets the gateway information. */ get gatewayInfo(): GatewayInformation; /** * Gets the gateway node name to make a CIM/PowerShell query to the gateway node. */ get gatewayName(): string; /** * Gets gateway status from cache or sets cache if it doesn't exist. */ private get gatewayStatus(); /** * Initializes a new instance of the Gateway class. * * @param http the Http object. * @param rpc the Rpc class. * @patam authorizationManager the authorization manager class object. */ constructor(http: Http, rpc: Rpc, authorizationManager: AuthorizationManager); /** * Configure the gateway URL to connect to. */ configureGatewayEnvironment(url: string, urlSpecified: boolean, staticVersion: string): void; /** * Update the url with static version option. * @param url the original URL including options. * @returns updated url with "version=" option if staticVersion present. */ addStaticVersion(url: string): string; /** * Makes a POST call to the gateway * * @param relativeUrl the relative Url after "/api" * @param body the body string JSON.stringfy'ed * @param request the gateway request object. */ post(relativeUrl: string, body?: any, request?: GatewayRequest): Observable; /** * Makes a GET call to the gateway * * @param relativeUrl the relative Url after "/api" * @param request the gateway request object. */ get(relativeUrl: string, request?: GatewayRequest): Observable; /** * Makes a PUT call to the gateway * * @param relativeUrl the relative Url after "/api" * @param body the body string JSON.stringfy'ed * @param request the gateway request object. */ put(relativeUrl: string, body?: string, request?: GatewayRequest): Observable; /** * Makes a PATCH call to the gateway * * @param relativeUrl the relative Url after "/api" * @param body the body string JSON.stringfy'ed * @param request the gateway request object. */ patch(relativeUrl: string, body?: string, request?: GatewayRequest): Observable; /** * Makes a DELETE call to the gateway * * @param relativeUrl the relative Url after "/api" * @param body the body string JSON.stringfy'ed * @param request the gateway request object. */ delete(relativeUrl: string, body?: string, request?: GatewayRequest): Observable; /** * Makes a DELETE call to the gateway without waiting for the response. * * @param relativeUrl the relative Url after "/api" * @param request the gateway request object. */ deleteQuick(relativeUrl: string, headers?: any): void; /** * Creates a GatewayRequest. * * @param method the http method to use * @param relativeUrl the relative Url after "/api/" * @param body the body string JSON.stringfy'ed * @param request the gateway request object to extend. */ createRequest(method: string, relativeUrl: string, body?: any, request?: GatewayRequest): GatewayRequest; /** * Make a request. * * @param request the request to execute against the gateway. * @return Observable the query result observable. */ call(request: GatewayRequest): Observable; /** * Gets default secure request options. * * @returns updated request object. */ get defaultHttpSecureOptions(): AjaxRequest; /** * Check if elevation is required from the error object. * * @param error the ajax error object. */ isElevationRequired(error: AjaxError): boolean; /** * Elevate the gateway if it's desktop mode running. */ elevate(): Observable; /** * Creates and returns a new URL builder for the current connection. */ url(): GatewayUrlBuilder; /** * Clear the DNS cache. */ clearDnsCache(): Observable; /** * Polling to check if the gateway is elevated. */ pollingGatewayElevated(): Observable; /** * Perform gateway status query but cut off if it exceeds 2.5 seconds. */ getElevatedStatus(): Observable<{ error: boolean; isGatewayProcessElevated: boolean; completed: boolean; id: string; }>; /** * Gets gateway machine if found in list of given nodes * @param nodes Node names or IPs to check * @returns Node name of gateway if found, null otherwise */ getGateway(nodes: string[]): Observable; /** * Check gateway condition. */ checkCondition(): Observable; /** * Get gateway status. */ getStatus(): Observable; /** * Get user access check. */ getAccessCheck(): Observable; /** * Called on a child service instance when onForwardInit returns from the parent * Initialize telemetry from within here so we can leverage gateway status for telemetry metadata. * @param data The response from the forwardInit call */ protected onForwardInitResponse(data: RpcForwardResponse): void; /** * Called when a new instance of the service in another window is initialized and needs to synchronize with its parent * @param from The RpcRelationshipType that this request is from * @returns an observable for the all the values needed to initialize the service */ protected onForwardInit(): Observable; /** * Called when the forwarded services counterpart wants to get data from the parent * @param from The RpcRelationshipType that this request is from * @param name The name of the method to forward to * @param args The arguments of the method * @returns an observable for the result of the method call */ protected onForwardExecute(from: RpcRelationshipType, name: string): Observable; /** * Called when the forwarded services counterpart sends a notify message * @param from The RpcRelationshipType that this request is from * @param name The name of the property to change * @param value The new value of the property * @returns an observable that completes when the property has been changed. */ protected onForwardNotify(from: RpcRelationshipType, name: string): Observable; }