export type CreateApiMarketingCartRulesArgs = {body: {name: string, description?: string | undefined, channels: Array, customer_groups: Array, coupon_type: 0 | 1, use_auto_generation?: (0 | 1) | undefined, coupon_code?: string | undefined, uses_per_coupon?: number | undefined, usage_per_customer?: number | undefined, condition_type?: (1 | 2) | undefined, conditions?: Array> | undefined, action_type: 'by_percent' | 'by_fixed' | 'cart_fixed' | 'buy_x_get_y', discount_amount: number, discount_quantity?: number | undefined, discount_step?: number | undefined, apply_to_shipping?: (0 | 1) | undefined, free_shipping?: (0 | 1) | undefined, end_other_rules?: (0 | 1) | undefined, sort_order?: number | undefined, starts_from?: string | undefined, ends_till?: string | undefined, status?: (0 | 1) | undefined}}; export type CreateApiMarketingCartRulesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create a new cart rule * * POST /marketing/cart-rules */ export const createApiMarketingCartRules = async (args: CreateApiMarketingCartRulesArgs, options?: CreateApiMarketingCartRulesOptions) => { const {baseUrl = "http://localhost:8000/api/admin", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/marketing/cart-rules${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) 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 };