export type GetApiProductsArgs = {page?: number | undefined, per_page?: number | undefined, query?: string | undefined, sku?: string | undefined, type?: ('simple' | 'configurable' | 'bundle' | 'downloadable' | 'grouped' | 'virtual' | 'booking') | undefined, status?: (0 | 1) | undefined, categoryId?: number | undefined, exclude_customizable_products?: boolean | undefined, customerId?: number | undefined, channel?: string | undefined, locale?: string | undefined, sort?: ('id' | 'sku' | 'created_at' | 'updated_at') | undefined, order?: ('asc' | 'desc') | undefined}; export type GetApiProductsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Search/list products (admin) * * GET /products */ export const getApiProducts = async (args: GetApiProductsArgs, options?: GetApiProductsOptions) => { 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.query != null) query.append("query", String(args.query)) if (args.sku != null) query.append("sku", String(args.sku)) if (args.type != null) query.append("type", String(args.type)) if (args.status != null) query.append("status", String(args.status)) if (args.categoryId != null) query.append("categoryId", String(args.categoryId)) if (args.exclude_customizable_products != null) query.append("exclude_customizable_products", String(args.exclude_customizable_products)) if (args.customerId != null) query.append("customerId", String(args.customerId)) if (args.channel != null) query.append("channel", String(args.channel)) if (args.locale != null) query.append("locale", String(args.locale)) 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(/\/+$/, '')}/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 };