export type GetApiCatalogCategoriesArgs = {page?: number | undefined, per_page?: number | undefined, category_id?: string | undefined, name?: string | undefined, position?: number | undefined, status?: (0 | 1) | undefined, parent_id?: number | undefined, locale?: string | undefined, sort?: ('id' | 'name' | 'position' | 'status') | undefined, order?: ('asc' | 'desc') | undefined}; export type GetApiCatalogCategoriesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * List categories (datagrid parity) * * GET /catalog/categories */ export const getApiCatalogCategories = async (args: GetApiCatalogCategoriesArgs, options?: GetApiCatalogCategoriesOptions) => { 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.category_id != null) query.append("category_id", String(args.category_id)) if (args.name != null) query.append("name", String(args.name)) if (args.position != null) query.append("position", String(args.position)) if (args.status != null) query.append("status", String(args.status)) if (args.parent_id != null) query.append("parent_id", String(args.parent_id)) 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(/\/+$/, '')}/catalog/categories${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 };