export type CreateApiEventArgs = {body: {distinct_id: string, event: string, properties?: ({$attachments?: (Array<{url: string, filename?: string | undefined, ignore_if_error?: boolean | undefined} | {data: string, filename?: string | undefined, contentType?: string | undefined}>) | undefined} | {[key: string]: string}) | undefined, tenant_id?: string | undefined, $idempotency_key?: string | undefined, cancellation_key?: string | undefined}}; export type CreateApiEventOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Trigger an Event * * POST /event/ */ export const createApiEvent = async (args: CreateApiEventArgs, options?: CreateApiEventOptions) => { 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(/\/+$/, '')}/event/${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() };