export type GetApiApiImSyncStreamArgs = {token: string, since?: string | undefined}; export type GetApiApiImSyncStreamOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * SSE sync stream (continuous push) * * GET /api/im/sync/stream */ export const getApiApiImSyncStream = async (args: GetApiApiImSyncStreamArgs, options?: GetApiApiImSyncStreamOptions) => { const {baseUrl = "https://prismer.cloud", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/event-stream") if (args.token != null) query.append("token", String(args.token)) if (args.since != null) query.append("since", String(args.since)) const url = `${baseUrl.replace(/\/+$/, '')}/api/im/sync/stream${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };