{"version":3,"sources":["../src/service-plugins-types.ts","../src/interfaces-ecommerce-v1-discounts-provider.public.ts","../src/interfaces-ecommerce-v1-discounts-provider.context.ts","../src/service-plugins-error-classes.ts"],"sourcesContent":["export interface GetEligibleDiscountsRequest {\n  /** Line items */\n  lineItems?: LineItem[];\n  /** Persistent ID that correlates between the various eCommerce elements: cart, checkout, and order. */\n  purchaseFlowId?: string | null;\n  /** Number of coupons is limited to 1 due to limitations in Checkout. */\n  couponCodes?: string[];\n  /** Buyer email */\n  buyerEmail?: string | null;\n}\n\nexport interface LineItem {\n  /** Line item ID. */\n  _id?: string;\n  /** Line item quantity. */\n  quantity?: number | null;\n  /** Catalog and item reference info. Learn more about [integrating Wix Stores products with Wix eCommerce](https://dev.wix.com/api/rest/wix-stores/catalog/ecommerce-integration). */\n  catalogReference?: CatalogReference;\n  /** Line item price. */\n  price?: string;\n}\n\n/** Used for grouping line items. Sent when an item is added to a cart, checkout, or order. */\nexport interface CatalogReference {\n  /** ID of the item within the catalog it belongs to. */\n  catalogItemId?: string;\n  /**\n   * ID of the app providing the catalog.\n   *\n   * You can get your app's ID from its page in the [app dashboard](https://dev.wix.com/dc3/my-apps/).\n   *\n   * For items from Wix catalogs, the following values always apply:\n   * + Wix Stores: `\"215238eb-22a5-4c36-9e7b-e7c08025e04e\"`\n   * + Wix Bookings: `\"13d21c63-b5ec-5912-8397-c3a5ddb27a97\"`\n   * + Wix Restaurants: `\"9a5d83fd-8570-482e-81ab-cfa88942ee60\"`\n   */\n  appId?: string;\n  /**\n   * Additional item details in key:value pairs. Use this optional field to provide more specificity with item selection. The `options` field values differ depending on which catalog is providing the items.\n   *\n   * For products and variants from a Wix Stores catalog, learn more about [eCommerce integration](https://dev.wix.com/docs/rest/business-solutions/stores/catalog/e-commerce-integration).\n   */\n  options?: Record<string, any> | null;\n}\n\nexport interface GetEligibleDiscountsResponse {\n  /** List of discounts to apply */\n  discounts?: Discount[];\n}\n\n/** Discount */\nexport interface Discount\n  extends DiscountDiscountTypeOneOf,\n    DiscountDiscountScopesOneOf {\n  /** Global discounts */\n  globalDiscounts?: BaseDiscounts;\n  /** Shipping discounts */\n  shippingDiscounts?: BaseDiscounts;\n  /** line items discounts */\n  lineItemsDiscounts?: LineItemsDiscounts;\n  /** Coupon options */\n  couponOptions?: CouponOptions;\n  /** Target type */\n  targetType?: TargetType;\n  /** Name */\n  name?: DiscountName;\n  /** external id used by the implementor */\n  externalId?: string | null;\n  /** Source */\n  source?: DiscountSource;\n}\n\n/** @oneof */\nexport interface DiscountDiscountTypeOneOf {\n  /** Global discounts */\n  globalDiscounts?: BaseDiscounts;\n  /** Shipping discounts */\n  shippingDiscounts?: BaseDiscounts;\n  /** line items discounts */\n  lineItemsDiscounts?: LineItemsDiscounts;\n}\n\n/** @oneof */\nexport interface DiscountDiscountScopesOneOf {\n  /** Coupon options */\n  couponOptions?: CouponOptions;\n}\n\nexport enum TargetType {\n  UNKNOWN_TARGET = 'UNKNOWN_TARGET',\n  GLOBAL = 'GLOBAL',\n  SHIPPING = 'SHIPPING',\n  LINE_ITEMS = 'LINE_ITEMS',\n}\n\nexport interface DiscountName {\n  /** Original discount rule name (in site's default language). */\n  original?: string;\n  /**\n   * Translated discount rule name according to buyer language.\n   *\n   * Default: `original`\n   */\n  translated?: string | null;\n}\n\nexport interface BaseDiscounts {\n  /** The rate of the discount. */\n  rate?: DiscountRate;\n}\n\nexport interface DiscountRate extends DiscountRateRateOneOf {\n  /** Global discounts */\n  fixedAmountValue?: string;\n  /** Shipping discounts */\n  percentageValue?: string;\n  /** Type of calculation */\n  type?: Type;\n}\n\n/** @oneof */\nexport interface DiscountRateRateOneOf {\n  /** Global discounts */\n  fixedAmountValue?: string;\n  /** Shipping discounts */\n  percentageValue?: string;\n}\n\nexport enum Type {\n  UNKNOWN_RATE = 'UNKNOWN_RATE',\n  FIXED_AMOUNT = 'FIXED_AMOUNT',\n  PERCENTAGE = 'PERCENTAGE',\n}\n\nexport interface LineItemsDiscounts {\n  /** Line items */\n  lineItems?: LineItemRate[];\n}\n\nexport interface LineItemRate {\n  /** The rate of the discount. */\n  rate?: DiscountRate;\n  /** id of the line item. */\n  _id?: string;\n}\n\nexport enum DiscountSource {\n  UNKNOWN_SOURCE = 'UNKNOWN_SOURCE',\n  COUPON = 'COUPON',\n  AUTOMATIC = 'AUTOMATIC',\n  CUSTOM = 'CUSTOM',\n}\n\nexport interface CouponOptions {\n  /** Coupon code, only relevant when source is coupon. */\n  code?: string | null;\n}\n\nexport interface DiscountsSPIConfig {\n  /**\n   * Base URI where the endpoints are called.\n   * Wix eCommerce appends the endpoint path to the base URI.\n   */\n  deploymentUri?: string;\n}\n\n/**\n * this message is not directly used by any service,\n * it exists to describe the expected parameters that SHOULD be provided to invoked Velo methods as part of open-platform.\n * e.g. SPIs, event-handlers, etc..\n * NOTE: this context object MUST be provided as the last argument in each Velo method signature.\n *\n * Example:\n * ```typescript\n * export function wixStores_onOrderCanceled({ event, metadata }: OrderCanceledEvent) {\n * ...\n * }\n * ```\n */\nexport interface Context {\n  /** A unique identifier of the request. You may print this ID to your logs to help with future debugging and easier correlation with Wix's logs. */\n  requestId?: string | null;\n  /** [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) 3-letter currency code. */\n  currency?: string | null;\n  /** An object that describes the identity that triggered this request. */\n  identity?: IdentificationData;\n  /** A string representing a language and region in the format of `\"xx-XX\"`. First 2 letters represent the language code according to ISO 639-1. This is followed by a dash \"-\", and then a by 2 capital letters representing the region according to ISO 3166-2. For example, `\"en-US\"`. */\n  languages?: string[];\n  /** The service provider app's instance ID. */\n  instanceId?: string | null;\n}\n\nexport enum IdentityType {\n  UNKNOWN = 'UNKNOWN',\n  ANONYMOUS_VISITOR = 'ANONYMOUS_VISITOR',\n  MEMBER = 'MEMBER',\n  WIX_USER = 'WIX_USER',\n  APP = 'APP',\n}\n\nexport interface IdentificationData extends IdentificationDataIdOneOf {\n  /** ID of a site visitor that has not logged in to the site. */\n  anonymousVisitorId?: string;\n  /** ID of a site visitor that has logged in to the site. */\n  memberId?: string;\n  /** ID of a Wix user (site owner, contributor, etc.). */\n  wixUserId?: string;\n  /** ID of an app. */\n  appId?: string;\n  /** @readonly */\n  identityType?: IdentityType;\n}\n\n/** @oneof */\nexport interface IdentificationDataIdOneOf {\n  /** ID of a site visitor that has not logged in to the site. */\n  anonymousVisitorId?: string;\n  /** ID of a site visitor that has logged in to the site. */\n  memberId?: string;\n  /** ID of a Wix user (site owner, contributor, etc.). */\n  wixUserId?: string;\n  /** ID of an app. */\n  appId?: string;\n}\n","import { ServicePluginDefinition } from '@wix/sdk-types';\nimport {\n  Context,\n  GetEligibleDiscountsRequest,\n  GetEligibleDiscountsResponse,\n} from './service-plugins-types.js';\nimport {\n  renameKeysFromSDKRequestToRESTRequest,\n  renameKeysFromRESTResponseToSDKResponse,\n} from '@wix/sdk-runtime/rename-all-nested-keys';\n\nexport interface GetEligibleDiscountsEnvelope {\n  request: GetEligibleDiscountsRequest;\n  metadata: Context;\n}\n\nexport const provideHandlers = ServicePluginDefinition<{\n  /**\n   *\n   * Wix calls this method when certain actions are performed on the cart or checkout.\n   * For example, when an item is added to the cart or the amount of an item is updated in the checkout. */\n  getEligibleDiscounts(\n    payload: GetEligibleDiscountsEnvelope\n  ): GetEligibleDiscountsResponse | Promise<GetEligibleDiscountsResponse>;\n}>('ECOM_DISCOUNTS', [\n  {\n    name: 'getEligibleDiscounts',\n    primaryHttpMappingPath: '/v1/eligible-discounts',\n    transformations: {\n      toREST: (payload: any) => {\n        const toRestResponse = payload;\n\n        return renameKeysFromSDKRequestToRESTRequest(toRestResponse);\n      },\n      fromREST: (payload: any) => {\n        const fromRestRequest = payload;\n\n        return renameKeysFromRESTResponseToSDKResponse(fromRestRequest);\n      },\n    },\n  },\n]);\n","import './interfaces-ecommerce-v1-discounts-provider.public.js';\nimport { createServicePluginModule } from '@wix/sdk-runtime/service-plugin-modules';\nimport { provideHandlers as publicProvideHandlers } from './interfaces-ecommerce-v1-discounts-provider.public.js';\n\nexport { publicProvideHandlers };\n\nexport const provideHandlers: ReturnType<\n  typeof createServicePluginModule<typeof publicProvideHandlers>\n> = createServicePluginModule(publicProvideHandlers);\n","export class CouponLimitPerCustomerExceededWixError extends Error {\n  /** @hidden */\n  httpCode: number;\n  /** @hidden */\n  statusCode: string;\n  /** @hidden */\n  applicationCode: string;\n  /** @hidden */\n  name: string;\n  /** @hidden */\n  errorType: string;\n  /** @hidden */\n  spiErrorData: object;\n\n  constructor() {\n    super('CouponLimitPerCustomerExceeded');\n\n    this.httpCode = 428;\n    this.statusCode = 'FAILED_PRECONDITION';\n    this.applicationCode = 'ERROR_COUPON_LIMIT_PER_CUSTOMER_EXCEEDED';\n    this.name = 'CouponLimitPerCustomerExceeded';\n    this.errorType = 'SPI';\n    this.spiErrorData = {\n      name: 'CouponLimitPerCustomerExceeded',\n      applicationCode: 'ERROR_COUPON_LIMIT_PER_CUSTOMER_EXCEEDED',\n    };\n  }\n\n  /** @hidden */\n  static readonly __type = 'wix_spi_error';\n}\n\nexport class CouponIsDisabledWixError extends Error {\n  /** @hidden */\n  httpCode: number;\n  /** @hidden */\n  statusCode: string;\n  /** @hidden */\n  applicationCode: string;\n  /** @hidden */\n  name: string;\n  /** @hidden */\n  errorType: string;\n  /** @hidden */\n  spiErrorData: object;\n\n  constructor() {\n    super('CouponIsDisabled');\n\n    this.httpCode = 428;\n    this.statusCode = 'FAILED_PRECONDITION';\n    this.applicationCode = 'ERROR_COUPON_IS_DISABLED';\n    this.name = 'CouponIsDisabled';\n    this.errorType = 'SPI';\n    this.spiErrorData = {\n      name: 'CouponIsDisabled',\n      applicationCode: 'ERROR_COUPON_IS_DISABLED',\n    };\n  }\n\n  /** @hidden */\n  static readonly __type = 'wix_spi_error';\n}\n\nexport class CouponUsageExceededWixError extends Error {\n  /** @hidden */\n  httpCode: number;\n  /** @hidden */\n  statusCode: string;\n  /** @hidden */\n  applicationCode: string;\n  /** @hidden */\n  name: string;\n  /** @hidden */\n  errorType: string;\n  /** @hidden */\n  spiErrorData: object;\n\n  constructor() {\n    super('CouponUsageExceeded');\n\n    this.httpCode = 428;\n    this.statusCode = 'FAILED_PRECONDITION';\n    this.applicationCode = 'ERROR_COUPON_USAGE_EXCEEDED';\n    this.name = 'CouponUsageExceeded';\n    this.errorType = 'SPI';\n    this.spiErrorData = {\n      name: 'CouponUsageExceeded',\n      applicationCode: 'ERROR_COUPON_USAGE_EXCEEDED',\n    };\n  }\n\n  /** @hidden */\n  static readonly __type = 'wix_spi_error';\n}\n\nexport class CouponHasExpiredWixError extends Error {\n  /** @hidden */\n  httpCode: number;\n  /** @hidden */\n  statusCode: string;\n  /** @hidden */\n  applicationCode: string;\n  /** @hidden */\n  name: string;\n  /** @hidden */\n  errorType: string;\n  /** @hidden */\n  spiErrorData: object;\n\n  constructor() {\n    super('CouponHasExpired');\n\n    this.httpCode = 428;\n    this.statusCode = 'FAILED_PRECONDITION';\n    this.applicationCode = 'ERROR_COUPON_HAS_EXPIRED';\n    this.name = 'CouponHasExpired';\n    this.errorType = 'SPI';\n    this.spiErrorData = {\n      name: 'CouponHasExpired',\n      applicationCode: 'ERROR_COUPON_HAS_EXPIRED',\n    };\n  }\n\n  /** @hidden */\n  static readonly __type = 'wix_spi_error';\n}\n\nexport class CouponIsNotActiveYetWixError extends Error {\n  /** @hidden */\n  httpCode: number;\n  /** @hidden */\n  statusCode: string;\n  /** @hidden */\n  applicationCode: string;\n  /** @hidden */\n  name: string;\n  /** @hidden */\n  errorType: string;\n  /** @hidden */\n  spiErrorData: object;\n\n  constructor() {\n    super('CouponIsNotActiveYet');\n\n    this.httpCode = 428;\n    this.statusCode = 'FAILED_PRECONDITION';\n    this.applicationCode = 'ERROR_COUPON_IS_NOT_ACTIVE_YET';\n    this.name = 'CouponIsNotActiveYet';\n    this.errorType = 'SPI';\n    this.spiErrorData = {\n      name: 'CouponIsNotActiveYet',\n      applicationCode: 'ERROR_COUPON_IS_NOT_ACTIVE_YET',\n    };\n  }\n\n  /** @hidden */\n  static readonly __type = 'wix_spi_error';\n}\n\nexport class CouponDoesNotExistWixError extends Error {\n  /** @hidden */\n  httpCode: number;\n  /** @hidden */\n  statusCode: string;\n  /** @hidden */\n  applicationCode: string;\n  /** @hidden */\n  name: string;\n  /** @hidden */\n  errorType: string;\n  /** @hidden */\n  spiErrorData: object;\n\n  constructor() {\n    super('CouponDoesNotExist');\n\n    this.httpCode = 404;\n    this.statusCode = 'NOT_FOUND';\n    this.applicationCode = 'ERROR_COUPON_DOES_NOT_EXIST';\n    this.name = 'CouponDoesNotExist';\n    this.errorType = 'SPI';\n    this.spiErrorData = {\n      name: 'CouponDoesNotExist',\n      applicationCode: 'ERROR_COUPON_DOES_NOT_EXIST',\n    };\n  }\n\n  /** @hidden */\n  static readonly __type = 'wix_spi_error';\n}\n"],"mappings":";AAwFO,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,oBAAiB;AACjB,EAAAA,YAAA,YAAS;AACT,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,gBAAa;AAJH,SAAAA;AAAA,GAAA;AAwCL,IAAK,OAAL,kBAAKC,UAAL;AACL,EAAAA,MAAA,kBAAe;AACf,EAAAA,MAAA,kBAAe;AACf,EAAAA,MAAA,gBAAa;AAHH,SAAAA;AAAA,GAAA;AAkBL,IAAK,iBAAL,kBAAKC,oBAAL;AACL,EAAAA,gBAAA,oBAAiB;AACjB,EAAAA,gBAAA,YAAS;AACT,EAAAA,gBAAA,eAAY;AACZ,EAAAA,gBAAA,YAAS;AAJC,SAAAA;AAAA,GAAA;AA8CL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,aAAU;AACV,EAAAA,cAAA,uBAAoB;AACpB,EAAAA,cAAA,YAAS;AACT,EAAAA,cAAA,cAAW;AACX,EAAAA,cAAA,SAAM;AALI,SAAAA;AAAA,GAAA;;;AChMZ,SAAS,+BAA+B;AAMxC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAOA,IAAM,kBAAkB,wB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