import { createCommands } from '@jolibox/common'; import { canIUse } from './can-i-use'; import { ResponseType, StandardResponse } from '@jolibox/types'; const commands = createCommands(); /** * Data structure for successful login. * @public */ export interface ILoginSuccessData { isLogin: boolean; token?: string; } /** * @public * Initiates the Jolibox login process. * @returns A promise that resolves with the standard response containing login status and token if successful, or an error-like object if platform does not support login. */ export async function login(): Promise< StandardResponse | { code: ResponseType; message: string } > { if (!canIUse('login')) { return { code: 'FAILURE' as ResponseType, message: '[Jolibox SDK]login is not supported in this platform' }; } return (await commands.executeCommand('API.login')) as StandardResponse; } /** * Data structure for successful session check. * @public */ export interface ICheckSessionSuccessData { isLogin: boolean; isSubUser?: boolean; } /** * @public * Checks the current session status. * @returns A promise that resolves with the standard response containing session status if successful, or an error-like object if platform does not support checkSession. */ export async function checkSession(): Promise< StandardResponse | { code: ResponseType; message: string } > { if (!canIUse('checkSession')) { return { code: 'FAILURE' as ResponseType, message: '[Jolibox SDK]checkSession is not supported in this platform' }; } return (await commands.executeCommand('API.checkSession')) as StandardResponse; }