export type EventParameter = {name?: string | undefined, value?: Record | undefined}; export type Event = {eventTypeKey: string, params?: Array | undefined}; export type CreateApiApiV2EventArgs = {body: Event}; export type CreateApiApiV2EventOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Generate event v2 * * POST /api/v2/event */ export const createApiApiV2Event = async (args: CreateApiApiV2EventArgs, options?: CreateApiApiV2EventOptions) => { const {baseUrl = "https://api.reteno.com", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/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 undefined };