import {z} from 'zod' export type Promotion = {id?: string | undefined, display_id?: string | undefined, name?: string | undefined, type?: string | undefined, start_time?: string | undefined, end_time?: string | undefined, warehouse_ids?: Array | undefined, customer_tags?: Array | undefined, order_sources?: Array> | undefined, group_name?: string | undefined, is_activated?: boolean | undefined, is_variation?: boolean | undefined, is_used?: boolean | undefined, is_free_shipping?: boolean | undefined, is_discount_in_birthday_customer?: boolean | undefined, coupon_info?: ({discount?: number | undefined, is_percent?: boolean | undefined}) | undefined, promo_code_info?: ({discount?: number | undefined, is_percent?: boolean | undefined, max_discount_by_percent?: number | undefined}) | undefined, discount_by_quantity?: number | undefined, items?: (Array<{id?: string | undefined, promotion_advance_id?: string | undefined, shop_id?: number | undefined, product_id?: (string | null) | undefined, variation_id?: (string | null) | undefined, category_id?: (string | null) | undefined, product?: (Record | null) | undefined, variation?: (Record | null) | undefined, level_info?: (Array<{discount?: number | undefined, is_percent?: boolean | undefined, from_quantity?: number | undefined, to_quantity?: number | undefined}>) | undefined, fixed_prices?: number | undefined, coupon_item_info?: ({discount?: number | undefined, is_percent?: boolean | undefined}) | undefined, limited_quantity?: number | undefined, limited_quantity_used?: number | undefined, attachment_product_info?: (Array<{product_id?: (string | null) | undefined, variation_id?: (string | null) | undefined, quantity?: number | undefined}>) | undefined, discount_info_by_attachment_product?: ({discount?: number | undefined, is_percent?: boolean | undefined, quantity?: number | undefined} | null) | undefined, inserted_at?: string | undefined, updated_at?: string | undefined}>) | undefined, bonus_items?: Array> | undefined, total_quantity_bonus?: number | undefined, arr_level_promotion?: Array> | undefined, level_order_prices?: Array> | undefined, priority_level?: number | undefined, type_employee?: string | undefined, post_ids?: Array | undefined, shop_id?: number | undefined, creator_id?: string | undefined, inserted_at?: string | undefined, updated_at?: string | undefined}; export type UpdateApiShopsSHOPIDPromotionAdvancePROMOTIONIDArgs = {SHOP_ID: number, PROMOTION_ID: string, body: {promotion_advance: Promotion}}; export type UpdateApiShopsSHOPIDPromotionAdvancePROMOTIONIDOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const updateApiShopsSHOPIDPromotionAdvancePROMOTIONIDResponse = 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 }; /** * Update promotion product * * PUT /shops/{SHOP_ID}/promotion_advance/{PROMOTION_ID} */ export const updateApiShopsSHOPIDPromotionAdvancePROMOTIONID = async (args: UpdateApiShopsSHOPIDPromotionAdvancePROMOTIONIDArgs, options?: UpdateApiShopsSHOPIDPromotionAdvancePROMOTIONIDOptions) => { 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/${encodeURIComponent(String(args.PROMOTION_ID))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiShopsSHOPIDPromotionAdvancePROMOTIONIDResponse, await res.json()) };