@microsoft/teams-js
Version:
Microsoft Client SDK for building app for Microsoft hosts
152 lines (151 loc) • 9.43 kB
TypeScript
import { FrameContexts } from '../public/constants';
import { ISerializable } from '../public/serializable.interface';
import { NestedAppAuthRequest } from './nestedAppAuthUtils';
import { ResponseHandler, SimpleType } from './responseHandler';
/**
* @internal
* Limited to Microsoft-internal use
*/
export declare class Communication {
static currentWindow: Window | any;
static parentOrigin: string | null;
static parentWindow: Window | any;
static topWindow: Window | any;
static topOrigin: string | null;
}
/**
* @internal
* Limited to Microsoft-internal use
*/
interface InitializeResponse {
context: FrameContexts;
clientType: string;
runtimeConfig: string;
clientSupportedSDKVersion: string;
}
/**
* @internal
* Limited to Microsoft-internal use
*/
export declare function initializeCommunication(validMessageOrigins: string[] | undefined, apiVersionTag: string): Promise<InitializeResponse>;
/**
* @internal
* Limited to Microsoft-internal use
*/
export declare function uninitializeCommunication(): void;
/**
* @deprecated This function is deprecated and will be removed in a future release. Please use {@link callFunctionInHostAndHandleResponse} or {@link callFunctionInHost} instead.
* @hidden
* Send a message to parent and then unwrap result. Uses nativeInterface on mobile to communicate with parent context
* Additional apiVersionTag parameter is added, which provides the ability to send api version number to parent
* for telemetry work.
*
* @internal
* Limited to Microsoft-internal use
*/
export declare function sendAndUnwrap<T>(apiVersionTag: string, actionName: string, ...args: any[]): Promise<T>;
/**
* @deprecated This function is deprecated and will be removed in a future release. Please use {@link callFunctionInHostAndHandleResponse} or {@link callFunctionInHost} instead.
* @hidden
* Send a message to parent and then handle status and reason. Uses nativeInterface on mobile to communicate with parent context
* Additional apiVersionTag parameter is added, which provides the ability to send api version number to parent
* for telemetry work.
*/
export declare function sendAndHandleStatusAndReason(apiVersionTag: string, actionName: string, ...args: any[]): Promise<void>;
/**
* @deprecated This function is deprecated and will be removed in a future release. Please use {@link callFunctionInHostAndHandleResponse} or {@link callFunctionInHost} instead.
* @hidden
* Send a message to parent and then handle status and reason with default error. Uses nativeInterface on mobile to communicate with parent context
* Additional apiVersionTag parameter is added, which provides the ability to send api version number to parent
* for telemetry work.
*
* @internal
* Limited to Microsoft-internal use
*/
export declare function sendAndHandleStatusAndReasonWithDefaultError(apiVersionTag: string, actionName: string, defaultError: string, ...args: any[]): Promise<void>;
/**
* @deprecated This function is deprecated and will be removed in a future release. Please use {@link callFunctionInHostAndHandleResponse} or {@link callFunctionInHost} instead.
* @hidden
* Send a message to parent and then handle SDK error. Uses nativeInterface on mobile to communicate with parent context
* Additional apiVersionTag parameter is added, which provides the ability to send api version number to parent
* for telemetry work.
*
* @internal
* Limited to Microsoft-internal use
*/
export declare function sendAndHandleSdkError<T>(apiVersionTag: string, actionName: string, ...args: any[]): Promise<T>;
/**
* @deprecated This function will no longer be exported in a future release. Please use {@link callFunctionInHostAndHandleResponse} or {@link callFunctionInHost} instead.
* @hidden
* Send a message to parent asynchronously. Uses nativeInterface on mobile to communicate with parent context
* Additional apiVersionTag parameter is added, which provides the ability to send api version number to parent
* for telemetry work.
*
* @internal
* Limited to Microsoft-internal use
*/
export declare function sendMessageToParentAsync<T>(apiVersionTag: string, actionName: string, args?: any[] | undefined): Promise<T>;
/**
* Call a function in the host and receive a response. If the host returns an {@link SdkError} instead of a normal response, this function will throw a new Error containing the SdkError's information
*
* @param functionName The function name to call in the host.
* @param args A collection of data to pass to the host. This data must be an array of either simple types or objects that implement {@link ISerializable}.
* @param responseHandler When the host responds, this handler will validate and deserialize the response.
* @param apiVersionTag A unique tag used to identify the API version for telemetry purposes. This should be set using {@link getApiVersionTag}, which should be passed a unique string identifying the function being called by the app developer as well as a version number that is incremented whenever meaningful changes are made to that function.
* @param isResponseAReportableError This optional property can be used to override the default ErrorChecking this function uses to decide whether to throw the host response as a new Error. Specify this if your function needs to do any logic verifying that the object received is an error that goes beyond the logic found in {@link isSdkError}.
*
* @returns The response received from the host after deserialization.
*
* @throws An Error containing the SdkError information ({@link SdkError.errorCode} and {@link SdkError.message}) if the host returns an SdkError, or an Error if the response from the host is an unexpected format.
*/
export declare function callFunctionInHostAndHandleResponse<SerializedReturnValueFromHost, DeserializedReturnValueFromHost>(functionName: string, args: (SimpleType | ISerializable)[], responseHandler: ResponseHandler<SerializedReturnValueFromHost, DeserializedReturnValueFromHost>, apiVersionTag: string, isResponseAReportableError?: (response: unknown) => response is {
errorCode: number | string;
message?: string;
}): Promise<DeserializedReturnValueFromHost>;
/**
* Call a function in the host that receives either an {@link SdkError} or undefined as a response. If the host returns an {@link SdkError} this function will throw a new Error containing the SdkError's information.
*
* @param functionName The function name to call in the host.
* @param args A collection of data to pass to the host. This data must be an array of either simple types or objects that implement {@link ISerializable}.
* @param apiVersionTag A unique tag used to identify the API version for telemetry purposes. This should be set using {@link getApiVersionTag}, which should be passed a unique string identifying the function being called by the app developer as well as a version number that is incremented whenever meaningful changes are made to that function.
* @param isResponseAReportableError This optional property can be used to override the default ErrorChecking this function uses to decide whether to throw the host response as a new Error. Specify this is your function needs to do any logic verifying that the object received is an error that goes beyond the logic found in {@link isSdkError}.
*
* @throws An Error containing the SdkError information ({@link SdkError.errorCode} and {@link SdkError.message}) if the host returns an SdkError, or an Error if the response from the host is an unexpected format.
*/
export declare function callFunctionInHost(functionName: string, args: (SimpleType | ISerializable)[], apiVersionTag: string, isResponseAReportableError?: (response: unknown) => response is {
errorCode: number | string;
message?: string;
}): Promise<void>;
/**
* @hidden
* Send a message to parent requesting a MessageChannel Port.
* @internal
* Limited to Microsoft-internal use
*/
export declare function requestPortFromParentWithVersion(apiVersionTag: string, actionName: string, args?: any[] | undefined): Promise<MessagePort>;
/**
* @deprecated This function is deprecated and will be removed in a future release. Please use {@link callFunctionInHostAndHandleResponse} or {@link callFunctionInHost} instead.
* @internal
* Limited to Microsoft-internal use
*/
export declare function sendMessageToParent(apiVersionTag: string, actionName: string, callback?: Function): void;
/**
* @deprecated This function is deprecated and will be removed in a future release. Please use {@link callFunctionInHostAndHandleResponse} or {@link callFunctionInHost} instead.
* @hidden
* Send a message to parent. Uses nativeInterface on mobile to communicate with parent context
*
* @internal
* Limited to Microsoft-internal use
*/
export declare function sendMessageToParent(apiVersionTag: string, actionName: string, args: any[] | undefined, callback?: Function): void;
/**
* @internal
* Limited to Microsoft-internal use
*/
export declare function sendNestedAuthRequestToTopWindow(message: string, apiVersionTag: string): NestedAppAuthRequest;
/**
* @internal
* Limited to Microsoft-internal use
*/
export declare function waitForMessageQueue(targetWindow: Window, callback: () => void): void;
export {};