UNPKG

@joeldodge/extension-sdk

Version:
162 lines (161 loc) 5.99 kB
import { ChattyHostConnection } from '@looker/chatty'; export declare enum ExtensionEvent { EXTENSION_HOST_NOTIFICATION = "EXTENSION_NOTIFICATION", EXTENSION_API_REQUEST = "EXTENSION_API_REQUEST" } export declare enum ExtensionRequestType { CONTEXT_DATA = "CONTEXT_DATA", VERIFY_HOST = "VERIFY_HOST", INVOKE_CORE_SDK = "INVOKE_CORE_SDK", RAW_INVOKE_CORE_SDK = "RAW_INVOKE_CORE_SDK", UPDATE_TITLE = "UPDATE_TITLE", UPDATE_LOCATION = "UPDATE_LOCATION", ROUTE_CHANGED = "ROUTE_CHANGED", CLOSE_HOST_POPOVERS = "CLOSE_HOST_POPOVERS", LOCAL_STORAGE = "LOCAL_STORAGE", USER_ATTRIBUTE = "USER_ATTRIBUTE", TRACK_ACTION = "TRACK_ACTION", ERROR_EVENT = "ERROR_EVENT", INVOKE_EXTERNAL_API = "INVOKE_EXTERNAL_API", EXTENSION_UNLOADED = "EXTENSION_UNLOADED", SPARTAN_LOGOUT = "SPARTAN_LOGOUT" } export interface ExtensionRequest { type: ExtensionRequestType; payload?: InvokeCoreSdkRequest | undefined; } export declare enum ApiVersion { sdk31 = "3.1", sdk40 = "4.0" } export interface InvokeCoreSdkRequest { apiMethodName?: string; httpMethod?: string; path?: string; body?: any; params?: any; options?: any; apiVersion?: ApiVersion; } export interface UpdateTitleRequest { title: string; } export interface UpdateLocationRequest { url: string; state?: any; } export interface ExtensionHostApi extends ExtensionSDK { handleNotification(message: ExtensionNotification): ExtensionInitializationResponse | undefined; invokeCoreSdk(httpMethod: string, path: string, body?: any, params?: any, authenticator?: any, options?: any, apiVersion?: ApiVersion): Promise<any>; invokeCoreSdkRaw(httpMethod: string, path: string, body?: any, params?: any, apiVersion?: ApiVersion): Promise<any>; unloaded(): void; } export interface ExtensionClientApi { handleRequest(message: ExtensionRequest): any | void; } export interface ContextDataRequest { type: 'save' | 'refresh'; contextData?: string; } export interface RouteChangeRequest { route: string; } export interface LocalStorageRequest { type: 'get' | 'set' | 'remove'; name: string; value?: string; } export interface TrackActionRequest { name: string; trackAction: string; attributes?: Record<string, any>; } export interface ErrorEventRequest { errorEvent: ErrorEvent; } export declare enum FetchResponseBodyType { json = "json", text = "text" } export interface FetchDataRequest { resource: string; init?: Extract<RequestInit, 'method' | 'headers' | 'body' | 'credentials'>; responseBodyType?: FetchResponseBodyType; } export declare enum ExtensionNotificationType { ROUTE_CHANGED = "ROUTE_CHANGED", INITIALIZE = "INITIALIZE" } export interface RouteChangeData { route?: string; routeState?: any; } export interface LookerHostData { extensionId: string; lookerVersion: string; route?: string; routeState?: any; hostUrl?: string; contextData?: string; } export interface ExtensionNotification { type: ExtensionNotificationType; payload?: LookerHostData | RouteChangeData | undefined; } export interface ExtensionInitializationResponse { extensionSdkVersion: string; errorMessage?: string; } export interface ExtensionHostConfiguration { initializedCallback?: (errorMessage?: string) => void; setInitialRoute?: (route: string, routeState?: any) => void; requiredLookerVersion?: string; hostChangedRoute?: (route: string, routeState?: any) => void; chattyTimeout?: number; } export interface ExtensionHostApiConfiguration extends ExtensionHostConfiguration { chattyHost: ChattyHostConnection; } export interface FetchCustomParameters { method?: 'POST' | 'GET' | 'DELETE' | 'PATCH' | 'PUT' | 'HEAD'; headers?: Record<string, string>; body?: string; credentials?: 'omit' | 'same-origin' | 'include'; } export interface FetchProxyDataResponse { ok: boolean; status: number; statusText?: string; headers: Record<string, string>; body?: any; } export interface FetchProxy { fetchProxy(resource: string, init?: FetchCustomParameters, responseBodyType?: FetchResponseBodyType): Promise<FetchProxyDataResponse>; } export interface ExtensionSDK { lookerHostData?: Readonly<LookerHostData>; createSecretKeyTag(keyName: string): string; verifyHostConnection(): Promise<boolean>; updateTitle(title: string): void; updateLocation(url: string, state?: any, target?: string): void; openBrowserWindow(url: string, target?: string): void; closeHostPopovers(): void; localStorageSetItem(name: string, value?: string): Promise<boolean>; localStorageRemoveItem(name: string): Promise<boolean>; localStorageGetItem(name: string): Promise<string | null>; userAttributeSetItem(name: string, value?: string): Promise<boolean>; userAttributeGetItem(name: string): Promise<string | null>; userAttributeResetItem(name: string): Promise<void>; track(name: string, trackAction: string, attributes?: Record<string, any>): void; error(errorEvent: ErrorEvent): void; clientRouteChanged(route: string, routeState?: any): void; getContextData(): any; saveContextData(contextData: any): Promise<any>; refreshContextData(): Promise<any>; createFetchProxy(baseUrl?: string, init?: FetchCustomParameters, responseBodyType?: FetchResponseBodyType): FetchProxy; fetchProxy(resource: string, init?: FetchCustomParameters, responseBodyType?: FetchResponseBodyType): Promise<FetchProxyDataResponse>; serverProxy(resource: string, init?: FetchCustomParameters, responseBodyType?: FetchResponseBodyType): Promise<FetchProxyDataResponse>; oauth2Authenticate(authEndpoint: string, authParameters: Record<string, string>, httpMethod?: string): Promise<any>; oauth2ExchangeCodeForToken(authEndpoint: string, authParameters: Record<string, string>): Promise<any>; spartanLogout(): void; }