export type GetApiApiLiveDeliveryTargetArgs = {target: string, timeout?: number | undefined}; export type GetApiApiLiveDeliveryTargetOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Stream outbound-delivery diagnostics as Server-Sent Events * * GET /api/live/delivery/{target} * * Also accepts auth: basicAuth, liveToken */ export const getApiApiLiveDeliveryTarget = async (args: GetApiApiLiveDeliveryTargetArgs, options?: GetApiApiLiveDeliveryTargetOptions) => { const {baseUrl = "https://mail.example.com", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/event-stream") if (args.timeout != null) query.append("timeout", String(args.timeout)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/live/delivery/${encodeURIComponent(String(args.target))}${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() };