export type Parameter = {name?: string | undefined, value?: string | undefined}; export type EventDto = {eventTypeKey: string, keyValue?: string | undefined, params?: Array | undefined}; export type CreateApiApiV1EventArgs = {body: EventDto}; export type CreateApiApiV1EventOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Generate events v1 * * POST /api/v1/event */ export const createApiApiV1Event = async (args: CreateApiApiV1EventArgs, options?: CreateApiApiV1EventOptions) => { 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/v1/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 };