export type Product = {productId: string, currencyCode: string, price: number, title: string, imageuri: string}; export type ProductDetail = {product: Product, quantity?: number | undefined}; export type RetailQuery = {timestamp: number, visitorId: string, sessionId: string, queryId: string, ipAddress?: string | undefined, searchTerms: string, productDetails: Array, sourceId: string, uri: string}; export type RetailQuerySignals = Array; export type CreateApiRetailSignalsQueryArgs = {body: RetailQuerySignals}; export type CreateApiRetailSignalsQueryOptions = {baseUrl?: string | undefined, authToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * Query signals * * POST /retail/signals/query */ export const createApiRetailSignalsQuery = async (args: CreateApiRetailSignalsQueryArgs, options?: CreateApiRetailSignalsQueryOptions) => { const {baseUrl = "https://commerce_studio_id.experiencemanager.lucidworks.com", fetch: fetchFn = fetch, authToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (authToken !== undefined) headers.set('authorization', `Bearer ${authToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/retail/signals/query${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 };