export type GetApiInventoryRulesCsvArgs = {productId?: (number | null) | undefined, download?: (boolean | null) | undefined}; export type GetApiInventoryRulesCsvOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * GET /inventory-rules.csv */ export const getApiInventoryRulesCsv = async (args: GetApiInventoryRulesCsvArgs, options: GetApiInventoryRulesCsvOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/plain") if (args.productId != null) query.append("productId", String(args.productId)) if (args.download != null) query.append("download", String(args.download)) const url = `${baseUrl.replace(/\/+$/, '')}/inventory-rules.csv${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 res.text() };