export type ProductCsvProcessorMode = 'DEFAULTS' | 'OVERRIDES'; export type CreateApiProductsCsvArgs = {mode: ProductCsvProcessorMode, body: BodyInit}; export type CreateApiProductsCsvOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * POST /products.csv */ export const createApiProductsCsv = async (args: CreateApiProductsCsvArgs, options: CreateApiProductsCsvOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/plain") if (args.mode != null) query.append("mode", String(args.mode)) const url = `${baseUrl.replace(/\/+$/, '')}/products.csv${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };