type ObjectKey = string | number | symbol; type EmptyObject = Record; type OnValueChangeCallback = (newValue: T, oldValue: T) => unknown | Promise; type UnwatchFunction = () => void; interface WatchOptions { /** * Whether the callback should be called only once. The default value is false. */ once?: boolean; /** * A function that returns a boolean to determine if the callback should be called. * The guard not set by default. * * @since 5.1.0 */ guard?: (newValue: T, oldValue: T) => boolean; /** * Whether the callback should be removed after calling the clear method. The default value is true. */ clearable?: boolean; /** * An AbortSignal. The watch callback will be removed when the abort() method of the AbortController which owns the AbortSignal is called. * See [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) for details. * * @since 5.1.0 */ signal?: AbortSignal; /** * Whether the callback should be called immediately after being added. The default value is false. * * @since 5.1.0 */ immediate?: boolean; } interface Watchable { /** * Current value of the observable property. */ value: T; /** * Previous value of the observable property. */ get oldValue(): T; /** * Subscribes to the value changes. * * When the value is changed, the [Core.Watchable.OnValueChangeCallback] callback is triggered. * * Returns [Core.Watchable.UnwatchFunction], to unwatch observable value changes. * * @param onValueChangeCallback Observer to be triggered when the value is changed * @param options Options */ watch: (onValueChangeCallback: OnValueChangeCallback, options?: WatchOptions) => UnwatchFunction; /** * Stops triggering the specified callback on the value change. * * @param onValueChangeCallback Observer that should not be triggered anymore */ unwatch: (onValueChangeCallback: OnValueChangeCallback) => void; /** * Clears all observers for this watchable excluding the ones created with [Core.Watchable.WatchOptions.clearable]: false. */ clear: () => void; /** * Locks the watchable from mutations. The value becomes readonly. * @hidden */ lock: (key: string) => void; /** * Unlocks the watchable. The value becomes mutable again. * @hidden */ unlock: (key: string) => void; } interface BaseBusEvent { name: string; } interface ListenerOptions { /** * Whether a listener should be invoked at most once after being added. * The default value is false. */ once?: boolean; /** * A function that returns a boolean to determine if the listener should be called. * The guard not set by default. * * @since 5.1.0 */ guard?: (event: Extract) => boolean; /** * An AbortSignal. The listener will be removed when the abort() method of the AbortController which owns the AbortSignal is called. * See [AbortController](https://developer.mozilla.org/en-US/docs/Web/API/AbortController) for details. * * @since 5.1.0 */ signal?: AbortSignal; } type Listener = (event: Extract) => void | Promise; type AddEventListener = (event: EventName, listener: Listener, options?: ListenerOptions) => void; type RemoveEventListener = (event: EventName, listener: Listener) => void; declare enum ContainerEvent { ModuleRegistered = "MODULE_REGISTERED" } interface ModuleRegisteredEvent extends BaseBusEvent { name: ContainerEvent.ModuleRegistered; token: Token; } type ContainerEvents = ModuleRegisteredEvent; interface Container { readonly key: string; registerModule: (module: ModuleLoader) => void; registerModules: (modules: ModuleLoader[]) => void; getModule(token: Token, required?: false): Module | undefined; getModule(token: Token, required: true): Module; getModuleAsync: (token: Token) => Promise; addEventListener: AddEventListener; removeEventListener: RemoveEventListener; } interface Token { name: string; module?: ModuleType; } interface InitModuleOptions { container: Container; key: string; } interface ModuleLoader { token: Token; options: Options; required: Token[]; setup: (initOptions: InitModuleOptions) => ModuleType; } type ModuleFactory = Options extends EmptyObject ? () => ModuleLoader : (options: Options) => ModuleLoader; interface BaseModule { /** * @hidden */ container: Container; } declare global { interface Navigator { getBattery?: () => Promise; } } interface BatteryManager extends EventTarget { level: number; charging: boolean; chargingTime: number; dischargingTime: number; } declare const WEB_SDK_ERROR_SYMBOL: unique symbol; declare class WebSDKError extends Error { /** * @hidden */ [WEB_SDK_ERROR_SYMBOL]?: boolean; /** * Because of using class in different modules (bundled js files) need to override instanceof operator - * different physical instances of the class in different modules should be treated as the same class * @hidden */ static [Symbol.hasInstance](instance: unknown): instance is WebSDKError; } /** * Options to log in with a password. */ export interface PasswordLoginOptions { /** * Full user name, including app and account name, e.g., someuser@someapp.youraccount.voximplant.com. */ username: string; /** * User password. */ password: string; /** * Optional device (browser) identifier. * * If a web application is going to authenticate with a renewable tokens via [Core.Client.loginAccessToken], * it is required to provide this identifier. */ deviceToken?: string; } /** * Options to log in with a one-time key. */ export interface OneTimeKeyLoginOptions { /** * Full user name, including app and account name, e.g., someuser@someapp.youraccount.voximplant.com. */ username: string; /** * Hash that has been generated via the following formula: `MD5(oneTimeKey+"|"+MD5(user+":voximplant.com:"+password))`. */ hash: string; /** * Optional device (browser) identifier. * * If a web application is going to authenticate with a renewable tokens via [Core.Client.loginAccessToken], * it is required to provide this identifier. */ deviceToken?: string; } /** * Options to request a one-time key. */ export interface RequestOneTimeKeyOptions { /** * Full user name, including app and account name, e.g., someuser@someapp.youraccount.voximplant.com. */ username: string; } /** * Options to log in with an access token. */ export interface AccessTokenLoginOptions { /** * Full user name, including app and account name, e.g., someuser@someapp.youraccount.voximplant.com. */ username: string; /** * Access token. * * It is obtained either from [Core.LoginResult.loginTokens], or via [Core.Client.refreshTokens]. */ accessToken: string; /** * Device (browser) identifier. * * Should be the same as the identifier provided for [Core.Client.login] or [Core.Client.loginOneTimeKey]. */ deviceToken: string; } /** * Options to refresh tokens. */ export interface RefreshTokenOptions { /** * Full user name, including app and account name, e.g., someuser@someapp.youraccount.voximplant.com. */ username: string; /** * Refresh token obtained from [Core.LoginResult.loginTokens]. */ refreshToken: string; /** * Device (browser) identifier. * * Should be the same as the identifier provided for [Core.Client.login] or [Core.Client.loginOneTimeKey]. */ deviceToken: string; } /** * Auth parameters that can be used to log in via an access token. */ export interface LoginTokens { /** * Time in seconds for the access token to expire. */ accessExpire: number; /** * Access token that can be used before accessExpire. */ accessToken: string; /** * Time in seconds for the refresh token to expire. */ refreshExpire: number; /** * Refresh token that can be used one time before refreshExpire. */ refreshToken: string; } /** * Interface that is provided when the login process is completed successfully. */ export interface LoginResult { /** * Display name of the logged in user. */ displayName?: string; /** * Auth parameters that can be used to log in via an access token. */ loginTokens?: LoginTokens; } /** * @hidden */ export declare enum LoginState { NotLoggedIn = "NOT_LOGGED_IN", LoggingIn = "LOGGING_IN", LoggedIn = "LOGGED_IN" } /** * @hidden */ export interface Login extends BaseModule { state: Watchable; username: Watchable; login: (options: PasswordLoginOptions) => Promise; loginOneTimeKey: (options: OneTimeKeyLoginOptions) => Promise; loginAccessToken: (options: AccessTokenLoginOptions) => Promise; requestOneTimeKey: (options: RequestOneTimeKeyOptions) => Promise; refreshTokens: (options: RefreshTokenOptions) => Promise; } /** * @hidden */ export declare const loginToken: Token; /** * @hidden */ export declare enum LoginErrorCode { InvalidPassword = 401, MauAccessDenied = 402, AccountFrozen = 403, InvalidUsername = 404, Timeout = 408, InvalidState = 491, InternalError = 500, NetworkIssues = 503, TokenExpired = 701 } /** * @hidden */ export declare const LoginLoader: ModuleFactory; /** * Error object that is the base for all login errors. * * @folder LoginErrors * @hideconstructor */ export declare class LoginError extends WebSDKError { } /** * Thrown if a login has failed due to a timeout. * * @folder LoginErrors * @hideconstructor */ export declare class LoginTimeoutError extends LoginError { constructor(); } /** * Thrown if a login has failed due to an invalid client state. * * @folder LoginErrors * @hideconstructor */ export declare class LoginInvalidStateError extends LoginError { constructor(reason?: string); } /** * Thrown on the attempt to log in with an incorrect password. * * @folder LoginErrors * @hideconstructor */ export declare class LoginInvalidPasswordError extends LoginError { constructor(); } /** * Thrown if Monthly Active Users (MAU) limit is reached. Payment is required. * * @folder LoginErrors * @hideconstructor */ export declare class LoginMauAccessDeniedError extends LoginError { constructor(); } /** * Thrown if the Voximplant account is frozen. * * @folder LoginErrors * @hideconstructor */ export declare class LoginAccountFrozenError extends LoginError { constructor(); } /** * Thrown on the attempt to log in with an incorrect username. * * @folder LoginErrors * @hideconstructor */ export declare class LoginInvalidUserError extends LoginError { constructor(); } /** * Thrown if an internal error has occurred. * * @folder LoginErrors * @hideconstructor */ export declare class LoginInternalError extends LoginError { constructor(description?: string); } /** * Thrown if the connection to the Voximplant Cloud is closed due to network issues. * * @folder LoginErrors * @hideconstructor */ export declare class LoginNetworkIssuesError extends LoginError { constructor(); } /** * Thrown if an access or refresh token has expired. * * @folder LoginErrors * @hideconstructor */ export declare class LoginTokenExpiredError extends LoginError { constructor(); } /** * @hidden */ export declare const getErrorByCode: (code: LoginErrorCode, reason?: string) => LoginError; export {};