import {z} from 'zod' export type CreateApiShopsSHOPIDPromotionAdvanceArgs = {SHOP_ID: number, body: {promotion_advance: {name: string, start_time?: number | undefined, end_time?: number | undefined, warehouse_ids?: Array | undefined, customer_tags?: Array | undefined, order_sources?: Array> | undefined, type: 'discount_by_product' | 'discount_by_order_price' | 'fixed_prices' | 'coupon' | 'double_reward_point' | 'discount_by_coupon_id' | 'discount_by_attachment_products', group_name?: string | undefined, is_activated?: boolean | undefined, is_variation?: boolean | undefined, coupon_info?: ({discount?: number | undefined, is_percent?: boolean | undefined, is_categories?: boolean | undefined, category_ids?: Array | undefined}) | undefined, promo_code_info?: ({discount?: number | undefined, is_percent?: boolean | undefined, max_discount_by_percent?: number | undefined}) | undefined, items?: (Array<{variation_id?: string | undefined, product_id?: (string | null) | undefined, category_id?: (string | null) | undefined, category?: Record | undefined, level_info?: (Array<{from_quantity?: number | undefined, to_quantity?: number | undefined, discount?: number | undefined, is_percent?: boolean | undefined}>) | undefined, fixed_prices?: number | undefined, coupon_item_info?: ({discount?: number | undefined, is_percent?: boolean | undefined, max_discount_by_percent?: number | undefined}) | undefined}>) | undefined, is_free_shipping?: boolean | undefined, discount_by_quantity?: number | undefined, bonus_items?: Array> | undefined, is_discount_in_birthday_customer?: boolean | undefined, arr_level_promotion?: Array> | undefined, total_quantity_bonus?: number | undefined, priority_level?: number | undefined, type_employee?: string | undefined, free_products?: (Array<{is_active?: boolean | undefined, products_count?: number | undefined, count_free_products?: number | undefined, type?: string | undefined}>) | undefined}}}; export type CreateApiShopsSHOPIDPromotionAdvanceOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const createApiShopsSHOPIDPromotionAdvanceResponse = z.object({success: z.boolean().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create promotion product * * POST /shops/{SHOP_ID}/promotion_advance */ export const createApiShopsSHOPIDPromotionAdvance = async (args: CreateApiShopsSHOPIDPromotionAdvanceArgs, options?: CreateApiShopsSHOPIDPromotionAdvanceOptions) => { const {baseUrl = "https://pos.pages.fm/api/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) query.set("api_key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/shops/${encodeURIComponent(String(args.SHOP_ID))}/promotion_advance${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 validateResponse(createApiShopsSHOPIDPromotionAdvanceResponse, await res.json()) };