{"version":3,"sources":["../../src/service-plugins-types.ts","../../src/interfaces-ecommerce-v1-inventory-provider.public.ts","../../src/interfaces-ecommerce-v1-inventory-provider.context.ts","../../src/service-plugins-error-classes.ts"],"sourcesContent":["export interface DecrementAvailabilityRequest {\n  /**\n   * Items for which to decrease their available stock quantity.\n   * @minSize 1\n   * @maxSize 300\n   */\n  items: Item[];\n  /**\n   * Whether to validate that the availability level doesn't become negative after the decrement.\n   *\n   * When set to `true`, the operation fails if any item would have negative availability after the decrement. When set to `false`, allows negative inventory levels.\n   */\n  restrictInventoryValue: boolean | null;\n  /**\n   * Order ID associated with this inventory change.\n   * @format GUID\n   */\n  orderId: string;\n  /** Reason for the inventory decrement. */\n  reason: Reason;\n}\n\n/** Inventory item that represents a product or service with stock availability that needs to be tracked and updated. */\nexport interface Item {\n  /**\n   * Catalog reference that uniquely identifies the item.\n   *\n   * Contains the app ID and catalog item ID required to locate the specific item in the catalog.\n   */\n  catalogReference?: CatalogReference;\n  /**\n   * Location ID where the inventory is managed.\n   *\n   * When not provided, the default location is used for inventory tracking.\n   * @format GUID\n   */\n  locationId?: string | null;\n  /**\n   * Quantity of the item to increment or decrement.\n   *\n   * For example, `5` to reduce availability by 5 units or increase availability by 5 units.\n   * @min 1\n   * @max 100000\n   */\n  quantity?: number;\n  /**\n   * Whether the item is part of a subscription order.\n   *\n   * Subscription items may be processed differently by inventory systems depending on their recurring nature.\n   */\n  subscriptionItem?: boolean;\n}\n\n/** Used for grouping line items. Sent when an item is added to a cart, checkout, or order. */\nexport interface CatalogReference {\n  /**\n   * ID of the item within the catalog it belongs to.\n   * @minLength 1\n   * @maxLength 36\n   */\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   * @minLength 1\n   */\n  appId?: string;\n  /**\n   * Additional item details in `key:value` pairs.\n   *\n   * Use this optional field for more specificity with item selection. The values of the `options` field differ depending on which catalog is providing the items.\n   *\n   * For Wix Stores products, learn more about integrating with [Catalog V3](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v3/e-commerce-integration)\n   * or [Catalog V1](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-v1/catalog/e-commerce-integration), depending on [the version the site uses](https://dev.wix.com/docs/api-reference/business-solutions/stores/catalog-versioning/introduction).\n   */\n  options?: Record<string, any> | null;\n}\n\nexport enum Reason {\n  /** Order was placed by a customer. */\n  ORDER_PLACED = 'ORDER_PLACED',\n  /** Order was paid for by a customer. */\n  ORDER_PAID = 'ORDER_PAID',\n  /** Order was canceled. */\n  ORDER_CANCELED = 'ORDER_CANCELED',\n  /** Order was refunded. */\n  ORDER_REFUNDED = 'ORDER_REFUNDED',\n  /** Order was edited by a merchant. */\n  ORDER_EDITED = 'ORDER_EDITED',\n  /** Order was rejected. */\n  ORDER_REJECTED = 'ORDER_REJECTED',\n}\n\nexport interface DecrementAvailabilityResponse {}\n\nexport interface IncrementAvailabilityRequest {\n  /**\n   * Items for which to increase their available stock quantity.\n   * @minSize 1\n   * @maxSize 300\n   */\n  items: Item[];\n  /**\n   * Order ID associated with this inventory change.\n   * @format GUID\n   */\n  orderId: string;\n  /** Reason for the inventory increment. */\n  reason: Reason;\n}\n\nexport interface IncrementAvailabilityResponse {}\n\n/** Configuration for the Inventory service plugin that defines how Wix communicates with the inventory provider. */\nexport interface InventorySpiConfig {\n  /**\n   * Base URI where the endpoints are called.\n   * Wix eCommerce appends the endpoint path to the base URI. For example, to call the Decrement Availability endpoint at `https://my-inventory.com/v1/decrement`, the base URI you provide here is `https://my-inventory.com/`.\n   * @minLength 1\n   * @maxLength 200\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  /**\n   * [ISO 4217](https://en.wikipedia.org/wiki/ISO_4217) 3-letter currency code.\n   * @format CURRENCY\n   */\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  /**\n   * The service provider app's instance ID.\n   * @format GUID\n   */\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  /**\n   * ID of a site visitor that has not logged in to the site.\n   * @format GUID\n   */\n  anonymousVisitorId?: string;\n  /**\n   * ID of a site visitor that has logged in to the site.\n   * @format GUID\n   */\n  memberId?: string;\n  /**\n   * ID of a Wix user (site owner, contributor, etc.).\n   * @format GUID\n   */\n  wixUserId?: string;\n  /**\n   * ID of an app.\n   * @format GUID\n   */\n  appId?: string;\n  /** @readonly */\n  identityType?: IdentityType;\n}\n\n/** @oneof */\nexport interface IdentificationDataIdOneOf {\n  /**\n   * ID of a site visitor that has not logged in to the site.\n   * @format GUID\n   */\n  anonymousVisitorId?: string;\n  /**\n   * ID of a site visitor that has logged in to the site.\n   * @format GUID\n   */\n  memberId?: string;\n  /**\n   * ID of a Wix user (site owner, contributor, etc.).\n   * @format GUID\n   */\n  wixUserId?: string;\n  /**\n   * ID of an app.\n   * @format GUID\n   */\n  appId?: string;\n}\n","import { ServicePluginDefinition } from '@wix/sdk-types';\nimport {\n  Context,\n  DecrementAvailabilityRequest,\n  DecrementAvailabilityResponse,\n  IncrementAvailabilityRequest,\n  IncrementAvailabilityResponse,\n} from './service-plugins-types.js';\nimport {\n  renameKeysFromSDKRequestToRESTRequest,\n  renameKeysFromRESTResponseToSDKResponse,\n} from '@wix/sdk-runtime/rename-all-nested-keys';\n\nexport interface DecrementAvailabilityEnvelope {\n  request: DecrementAvailabilityRequest;\n  metadata: Context;\n}\n\nexport interface IncrementAvailabilityEnvelope {\n  request: IncrementAvailabilityRequest;\n  metadata: Context;\n}\n\nexport const provideHandlers = ServicePluginDefinition<{\n  /**\n   *\n   * Reduces the available stock quantity for specified items.\n   *\n   * Use this method when inventory needs to be decremented due to order events such as order placement or payment. The method supports validation to prevent negative inventory levels when `restrictInventoryValue` is set to true. */\n  decrementAvailability(\n    payload: DecrementAvailabilityEnvelope\n  ): DecrementAvailabilityResponse | Promise<DecrementAvailabilityResponse>;\n\n  /**\n   *\n   * Increases the available stock quantity for specified items.\n   *\n   * Use this method when inventory needs to be incremented due to order events such as order cancellation, refund, or order editing.\n   * This method does not validate stock levels and allows negative inventory to be corrected. */\n  incrementAvailability(\n    payload: IncrementAvailabilityEnvelope\n  ): IncrementAvailabilityResponse | Promise<IncrementAvailabilityResponse>;\n}>('ECOM_INVENTORY', [\n  {\n    name: 'decrementAvailability',\n    primaryHttpMappingPath: '/v1/decrement',\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  {\n    name: 'incrementAvailability',\n    primaryHttpMappingPath: '/v1/increment',\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-inventory-provider.public.js';\nimport { createServicePluginModule } from '@wix/sdk-runtime/service-plugin-modules';\nimport { BuildServicePluginDefinition } from '@wix/sdk-types';\nimport { provideHandlers as publicProvideHandlers } from './interfaces-ecommerce-v1-inventory-provider.public.js';\n\nexport { publicProvideHandlers };\n\nexport const provideHandlers: BuildServicePluginDefinition<\n  typeof publicProvideHandlers\n> &\n  typeof publicProvideHandlers = createServicePluginModule(\n  publicProvideHandlers\n);\n","/**\n * Cannot decrement availability due to insufficient stock or invalid request parameters.\n */\nexport class DecrementNotPossibleWixError 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('DecrementNotPossible');\n\n    this.httpCode = 428;\n    this.statusCode = 'FAILED_PRECONDITION';\n    this.applicationCode = 'DECREMENT_NOT_POSSIBLE';\n    this.name = 'DecrementNotPossible';\n    this.errorType = 'SPI';\n    this.spiErrorData = {\n      name: 'DecrementNotPossible',\n      applicationCode: 'DECREMENT_NOT_POSSIBLE',\n    };\n  }\n\n  /** @hidden */\n  static readonly __type = 'wix_spi_error';\n}\n\n/**\n * Cannot increment availability due to invalid request parameters.\n */\nexport class IncrementNotPossibleWixError 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('IncrementNotPossible');\n\n    this.httpCode = 428;\n    this.statusCode = 'FAILED_PRECONDITION';\n    this.applicationCode = 'INCREMENT_NOT_POSSIBLE';\n    this.name = 'IncrementNotPossible';\n    this.errorType = 'SPI';\n    this.spiErrorData = {\n      name: 'IncrementNotPossible',\n      applicationCode: 'INCREMENT_NOT_POSSIBLE',\n    };\n  }\n\n  /** @hidden */\n  static readonly __type = 'wix_spi_error';\n}\n"],"mappings":";AAoFO,IAAK,SAAL,kBAAKA,YAAL;AAEL,EAAAA,QAAA,kBAAe;AAEf,EAAAA,QAAA,gBAAa;AAEb,EAAAA,QAAA,oBAAiB;AAEjB,EAAAA,QAAA,oBAAiB;AAEjB,EAAAA,QAAA,kBAAe;AAEf,EAAAA,QAAA,oBAAiB;AAZP,SAAAA;AAAA,GAAA;AA8EL,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;;;AClKZ,SAAS,+BAA+B;AAQxC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAYA,IAAM,kBAAkB,wBAmB5B,kBAAkB;AAAA,EACnB;AAAA,IACE,MAAM;AAAA,IACN,wBAAwB;AAAA,IACxB,iBAAiB;AAAA,MACf,QAAQ,CAAC,YAAiB;AACxB,cAAM,iBAAiB;AAEvB,eAAO,sCAAsC,cAAc;AAAA,MAC7D;AAAA,MACA,UAAU,CAAC,YAAiB;AAC1B,cAAM,kBAAkB;AAExB,eAAO,wCAAwC,eAAe;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AAAA,EAEA;AAAA,IACE,MAAM;AAAA,IACN,wBAAwB;AAAA,IACxB,iBAAiB;AAAA,MACf,QAAQ,CAAC,YAAiB;AACxB,cAAM,iBAAiB;AAEvB,eAAO,sCAAsC,cAAc;AAAA,MAC7D;AAAA,MACA,UAAU,CAAC,YAAiB;AAC1B,cAAM,kBAAkB;AAExB,eAAO,wCAAwC,eAAe;AAAA,MAChE;AAAA,IACF;AAAA,EACF;AACF,CAAC;;;AC3ED,SAAS,iCAAiC;AAMnC,IAAMC,mBAGoB;AAAA,EAC/B;AACF;;;ACTO,IAAM,+BAAN,cAA2C,MAAM;AAAA,EActD,cAAc;AACZ,UAAM,sBAAsB;AAE5B,SAAK,WAAW;AAChB,SAAK,aAAa;AAClB,SAAK,kBAAkB;AACvB,SAAK,OAAO;AACZ,SAAK,YAAY;AACjB,SAAK,eAAe;AAAA,MAClB,MAAM;AAAA,MACN,iBAAiB;AAAA,IACnB;AAAA,EACF;AAIF;AAAA;AA9Ba,6BA6BK,SAAS;AAMpB,IAAM,+BAAN,cAA2C,MAAM;AAAA,EActD,cAAc;AACZ,UAAM,sBAAsB;AAE5B,SAAK,WAAW;AAChB,SAAK,aAAa;AAClB,SAAK,kBAAkB;AACvB,SAAK,OAAO;AACZ,SAAK,YAAY;AACjB,SAAK,eAAe;AAAA,MAClB,MAAM;AAAA,MACN,iBAAiB;AAAA,IACnB;AAAA,EACF;AAIF;AAAA;AA9Ba,6BA6BK,SAAS;","names":["Reason","IdentityType","provideHandlers"]}