export type GetApiCatalogProductsArgs = {page?: number | undefined, per_page?: number | undefined, product_id?: string | undefined, sku?: string | undefined, name?: string | undefined, type?: ('simple' | 'configurable' | 'bundle' | 'grouped' | 'downloadable' | 'virtual' | 'booking') | undefined, status?: (0 | 1) | undefined, attribute_family?: number | undefined, channel?: string | undefined, locale?: string | undefined, price_from?: number | undefined, price_to?: number | undefined, price?: string | undefined, sort?: ('name' | 'sku' | 'attribute_family' | 'price' | 'quantity' | 'product_id' | 'status' | 'type' | 'channel') | undefined, order?: ('asc' | 'desc') | undefined}; export type GetApiCatalogProductsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * List catalog products (datagrid parity) * * GET /catalog/products */ export const getApiCatalogProducts = async (args: GetApiCatalogProductsArgs, options?: GetApiCatalogProductsOptions) => { const {baseUrl = "http://localhost:8000/api/admin", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.product_id != null) query.append("product_id", String(args.product_id)) if (args.sku != null) query.append("sku", String(args.sku)) if (args.name != null) query.append("name", String(args.name)) if (args.type != null) query.append("type", String(args.type)) if (args.status != null) query.append("status", String(args.status)) if (args.attribute_family != null) query.append("attribute_family", String(args.attribute_family)) if (args.channel != null) query.append("channel", String(args.channel)) if (args.locale != null) query.append("locale", String(args.locale)) if (args.price_from != null) query.append("price_from", String(args.price_from)) if (args.price_to != null) query.append("price_to", String(args.price_to)) if (args.price != null) query.append("price", String(args.price)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.order != null) query.append("order", String(args.order)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/catalog/products${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 (await res.json()) as unknown };