export type StorefrontEventSchema = {anonymousId?: string | undefined, cart?: (Record | null) | undefined, cartLine?: Record | undefined, checkout?: Record | undefined, collection?: Record | undefined, customer?: (Record | null) | undefined, customerEmail?: string | undefined, customerPhone?: string | undefined, eventId: string, eventName: 'product_added_to_cart' | 'product_removed_from_cart' | 'product_viewed' | 'checkout_started' | 'checkout_completed' | 'checkout_contact_info_submitted' | 'page_viewed' | 'collection_viewed', productVariant?: Record | undefined, source: 'AIMERCE', timestamp: string, urlWithParams?: string | undefined, urlWithoutParams?: string | undefined} | {[key: string]: unknown}; export type CreateApiStoresStoreIdStorefrontEventsArgs = {storeId: string, body: StorefrontEventSchema}; export type CreateApiStoresStoreIdStorefrontEventsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * Receive Storefront Events * * POST /stores/{storeId}/storefront/events */ export const createApiStoresStoreIdStorefrontEvents = async (args: CreateApiStoresStoreIdStorefrontEventsArgs, options?: CreateApiStoresStoreIdStorefrontEventsOptions) => { const {baseUrl = "https://api.getredo.com/v2.2", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/stores/${encodeURIComponent(String(args.storeId))}/storefront/events${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 };