export type CreateApiWorkspaceKeyBroadcastArgs = {workspace_key: string, body: {list_id: string, template: string, notification_category: string, channels?: Array | undefined, data?: Record | undefined, delay?: string | undefined, trigger_at?: string | undefined, precompute?: boolean | undefined, tenant_id?: string | undefined, cancellation_key?: string | undefined}}; export type CreateApiWorkspaceKeyBroadcastOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Trigger Broadcast * * POST /{workspace_key}/broadcast/ */ export const createApiWorkspaceKeyBroadcast = async (args: CreateApiWorkspaceKeyBroadcastArgs, options?: CreateApiWorkspaceKeyBroadcastOptions) => { const {baseUrl = "https://hub.suprsend.com", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "text/plain") if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.workspace_key))}/broadcast/${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 res.text() };