export type Discount = {unit: '%OFF' | 'AMOUNT_OFF' | 'FIXED', value: number, discountId?: string | undefined, autoAdd?: boolean | undefined, ON: {kind: 'SKU' | 'CART' | 'SERVICE' | 'SERVICE_CART', value: string | Array>, quantity?: number | undefined, includeOperator?: ('AND' | 'OR') | undefined, excludeOperator?: ('AND' | 'OR') | undefined}, set?: (Array<'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'>) | undefined}; export type TargetProduct = {kind: 'SKU' | 'CATEGORY' | 'ATTRIBUTE' | 'PRICE_KIND' | 'PREVIOUS_DISCOUNT', value: string | Array, operator: 'IN' | 'NOT_IN' | 'EQUAL' | 'GREATER_THAN', discountId?: string | undefined}; export type Condition = {key: 'SKU' | 'QUANTITY' | 'CATEGORY' | 'ATTRIBUTE' | 'PRICE_KIND' | 'CHANEL' | 'ORDER_VALUE' | 'USER_SEGMENT' | 'USER_KIND', value: string | Array, operator: 'NOT_EQUAL' | 'EQUAL' | 'GREATER_THAN' | 'LESS_THAN' | 'GREATER_THAN_OR_EQUAL_TO' | 'LESS_THAN_OR_EQUAL_TO' | 'NOT_IN' | 'IN'}; export type PromoCondition = {operator: 'AND' | 'OR', includeOperator?: ('AND' | 'OR') | undefined, excludeOperator?: ('AND' | 'OR') | undefined, conditions: Array, set?: ('A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z') | undefined}; export type TermsAndConditions = {title?: string | undefined, description?: string | undefined}; export type PromotionMessage = {title?: string | undefined, message?: string | undefined, pages?: Array | undefined, locales?: Array | undefined}; export type ProximityMessage = {threshold?: number | undefined, localizedMessages?: (Array<{locales?: Array | undefined, message?: string | undefined}>) | undefined}; export type CreateCoupon = {title: string, buyOperator?: ('AND' | 'OR') | undefined, promo: Array<{discount: Array, targetProducts: Array, condition: Array}>, startDate: string, endDate: string, isExclusive: boolean, type: 'PRODUCT' | 'CART' | 'QUANTITY' | 'BOGO' | 'SHIPPING' | 'BUYGET' | 'SPEND_GET', stackingType?: ('STACKABLE' | 'EXCLUSIVE' | 'TYPE_EXCLUSIVE' | 'UNIVERSAL') | undefined, level?: number | undefined, termsAndConditions?: Array | undefined, promotionMessages?: Array | undefined, proximityMessages?: Array | undefined, shipmentMethodIds?: Array | undefined, eligiblePriceList?: Array | undefined, note?: string | undefined, promoCodes: Array, limits?: (Array<{kind: 'PER_USER' | 'SITE_WIDE' | 'ORDER', value: number}>) | undefined, additionalAttributes?: (Array<{key?: string | undefined, value?: (string | Array) | undefined, attributeId?: number | undefined}>) | undefined}; export type CreateApiApiOffersCouponCreateArgs = {'x-site-context': string, body: CreateCoupon}; export type CreateApiApiOffersCouponCreateOptions = {baseUrl?: string | undefined, AuthorizationToken?: string | undefined, fetch?: typeof fetch | undefined}; /** * Create coupon * * POST /api-offers/coupon/create */ export const createApiApiOffersCouponCreate = async (args: CreateApiApiOffersCouponCreateArgs, options?: CreateApiApiOffersCouponCreateOptions) => { const {baseUrl = "https://live.copilot.fabric.inc", fetch: fetchFn = fetch, AuthorizationToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application./json") if (args['x-site-context'] != null) headers.set("x-site-context", String(args['x-site-context'])) if (AuthorizationToken !== undefined) headers.set('authorization', `Bearer ${AuthorizationToken}`) const url = `${baseUrl.replace(/\/+$/, '')}/api-offers/coupon/create${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 res.blob() };