export type GetApiProductsDealsArgs = {currency?: string | undefined, country_code?: string | undefined, min_discount?: number | undefined, limit?: number | undefined, offset?: number | undefined, deliver_to?: string | undefined, include_unshippable?: boolean | undefined}; export type GetApiProductsDealsOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get discounted products sorted by discount percentage * * GET /products/deals */ export const getApiProductsDeals = async (args: GetApiProductsDealsArgs, options?: GetApiProductsDealsOptions) => { const {baseUrl = "https://api.buywhere.ai/v1", fetch: fetchFn = fetch, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.currency != null) query.append("currency", String(args.currency)) if (args.country_code != null) query.append("country_code", String(args.country_code)) if (args.min_discount != null) query.append("min_discount", String(args.min_discount)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.deliver_to != null) query.append("deliver_to", String(args.deliver_to)) if (args.include_unshippable != null) query.append("include_unshippable", String(args.include_unshippable)) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/products/deals${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };