UNPKG

@etsoo/materialui

Version:

TypeScript Material-UI Implementation

92 lines (91 loc) 3.16 kB
import { ApiRefreshTokenDto, AppLoginParams, AppTryLoginParams, ExternalEndpoint, IApi, IApiPayload, TokenAuthRQ } from "@etsoo/appscript"; import { IServiceApp } from "./IServiceApp"; import { IServiceAppSettings } from "./IServiceAppSettings"; import { IServiceUser, ServiceUserToken } from "./IServiceUser"; import { ReactApp } from "./ReactApp"; import { IActionResult } from "@etsoo/shared"; /** * Core Service App * Service login to core system, get the refesh token and access token * Use the acess token to the service api, get a service access token * Use the new acess token and refresh token to login */ export declare class ServiceApp<U extends IServiceUser = IServiceUser, S extends IServiceAppSettings = IServiceAppSettings> extends ReactApp<S, U> implements IServiceApp { /** * Core endpoint */ protected coreEndpoint: ExternalEndpoint; /** * Core system API */ readonly coreApi: IApi; /** * Core system origin */ readonly coreOrigin: string; private coreAccessToken; /** * Constructor * @param settings Settings * @param name Application name * @param debug Debug mode */ constructor(settings: S, name: string, debug?: boolean); /** * Get token authorization request data * @param api API, if not provided, use the core API * @returns Result */ getTokenAuthRQ(api?: IApi): TokenAuthRQ; /** * Load core system UI * @param tryLogin Try login or not */ loadCore(tryLogin?: boolean): void; /** * Go to the login page * @param data Login parameters */ toLoginPage(data?: AppLoginParams): void; /** * Load URL with core origin * @param url URL */ loadUrlEx(url: string): void; /** * Signout, with userLogout and toLoginPage * @param action Callback */ signout(action?: () => void | boolean): Promise<void>; /** * * @param user Current user * @param core Core system API token data * @param keep Keep in local storage or not * @param dispatch User state dispatch */ userLoginEx(user: U & ServiceUserToken, core?: ApiRefreshTokenDto, dispatch?: boolean): void; /** * Save core system data * @param data Data */ protected saveCoreToken(data: ApiRefreshTokenDto): void; /** * On switch organization handler * This method is called when the organization is switched successfully */ protected onSwitchOrg(): Promise<void> | void; /** * Switch organization * @param organizationId Organization ID * @param fromOrganizationId From organization ID * @param payload Payload */ switchOrg(organizationId: number, fromOrganizationId?: number, payload?: IApiPayload<IActionResult<U & ServiceUserToken>>): Promise<IActionResult<U & ServiceUserToken> | undefined>; protected refreshTokenSucceed(user: U, token: string, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>; /** * Try login * @param params Login parameters */ tryLogin(params?: AppTryLoginParams): Promise<boolean>; }