export type CreateApiV1StatisticsEventArgs = {event: 'listingViewed' | 'listingImageGalleryViewed' | 'listingImageViewed' | 'listingMapViewed' | 'listingVideoViewed' | 'listingFloorPlanViewed' | 'listingAddedToShortlist' | 'listingAgentCalled' | 'listingAgentPhoneRevealed' | 'listingNotesAdded' | 'listingEmailedToAFriend' | 'listingEnquirySent' | 'loanEventRaised', body: Record}; export type CreateApiV1StatisticsEventOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Record a statistic event along with its associated metadata (if applicable) * * POST /v1/statistics/{event} * * Also accepts auth: oauth2 */ export const createApiV1StatisticsEvent = async (args: CreateApiV1StatisticsEventArgs, options?: CreateApiV1StatisticsEventOptions) => { const {baseUrl = "https://api.domain.com.au", fetch: fetchFn = fetch, apikey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apikey !== undefined) headers.set("x-api-key", apikey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/statistics/${encodeURIComponent(String(args.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 };