export type MobileSessionInfo = {fcmTokenTimestamp?: number | undefined}; export type CreateApiApiUserMobileSessionArgs = {'X-Mobile-Token': string, body: MobileSessionInfo}; export type CreateApiApiUserMobileSessionOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * POST /api/user/mobile/session */ export const createApiApiUserMobileSession = async (args: CreateApiApiUserMobileSessionArgs, options?: CreateApiApiUserMobileSessionOptions) => { const {baseUrl = "https://demo.thingsboard.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (args['X-Mobile-Token'] != null) headers.set("X-Mobile-Token", String(args['X-Mobile-Token'])) const url = `${baseUrl.replace(/\/+$/, '')}/api/user/mobile/session${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };