@medusajs/order 0.1.3 → 1.0.0-rc-20241003153304
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.ts +6 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -26
- package/dist/index.js.map +1 -1
- package/dist/joiner-config.d.ts +2 -5
- package/dist/joiner-config.d.ts.map +1 -0
- package/dist/joiner-config.js +21 -28
- package/dist/joiner-config.js.map +1 -1
- package/dist/migrations/Migration20240219102530.d.ts +1 -0
- package/dist/migrations/Migration20240219102530.d.ts.map +1 -0
- package/dist/migrations/Migration20240219102530.js +53 -19
- package/dist/migrations/Migration20240219102530.js.map +1 -1
- package/dist/migrations/Migration20240604100512.d.ts +5 -0
- package/dist/migrations/Migration20240604100512.d.ts.map +1 -0
- package/dist/migrations/Migration20240604100512.js +371 -0
- package/dist/migrations/Migration20240604100512.js.map +1 -0
- package/dist/migrations/Migration20240715102100.d.ts +5 -0
- package/dist/migrations/Migration20240715102100.d.ts.map +1 -0
- package/dist/migrations/Migration20240715102100.js +15 -0
- package/dist/migrations/Migration20240715102100.js.map +1 -0
- package/dist/migrations/Migration20240715174100.d.ts +5 -0
- package/dist/migrations/Migration20240715174100.d.ts.map +1 -0
- package/dist/migrations/Migration20240715174100.js +21 -0
- package/dist/migrations/Migration20240715174100.js.map +1 -0
- package/dist/migrations/Migration20240716081800.d.ts +5 -0
- package/dist/migrations/Migration20240716081800.d.ts.map +1 -0
- package/dist/migrations/Migration20240716081800.js +67 -0
- package/dist/migrations/Migration20240716081800.js.map +1 -0
- package/dist/migrations/Migration20240801085921.d.ts +5 -0
- package/dist/migrations/Migration20240801085921.d.ts.map +1 -0
- package/dist/migrations/Migration20240801085921.js +30 -0
- package/dist/migrations/Migration20240801085921.js.map +1 -0
- package/dist/migrations/Migration20240821164505.d.ts +6 -0
- package/dist/migrations/Migration20240821164505.d.ts.map +1 -0
- package/dist/migrations/Migration20240821164505.js +26 -0
- package/dist/migrations/Migration20240821164505.js.map +1 -0
- package/dist/migrations/Migration20240821170920.d.ts +6 -0
- package/dist/migrations/Migration20240821170920.d.ts.map +1 -0
- package/dist/migrations/Migration20240821170920.js +18 -0
- package/dist/migrations/Migration20240821170920.js.map +1 -0
- package/dist/migrations/Migration20240827133639.d.ts +6 -0
- package/dist/migrations/Migration20240827133639.d.ts.map +1 -0
- package/dist/migrations/Migration20240827133639.js +17 -0
- package/dist/migrations/Migration20240827133639.js.map +1 -0
- package/dist/migrations/Migration20240902195921.d.ts +6 -0
- package/dist/migrations/Migration20240902195921.d.ts.map +1 -0
- package/dist/migrations/Migration20240902195921.js +16 -0
- package/dist/migrations/Migration20240902195921.js.map +1 -0
- package/dist/migrations/Migration20240913092514.d.ts +6 -0
- package/dist/migrations/Migration20240913092514.d.ts.map +1 -0
- package/dist/migrations/Migration20240913092514.js +17 -0
- package/dist/migrations/Migration20240913092514.js.map +1 -0
- package/dist/models/address.d.ts +4 -3
- package/dist/models/address.d.ts.map +1 -0
- package/dist/models/address.js +22 -22
- package/dist/models/address.js.map +1 -1
- package/dist/models/adjustment-line.d.ts +5 -3
- package/dist/models/adjustment-line.d.ts.map +1 -0
- package/dist/models/adjustment-line.js +6 -1
- package/dist/models/adjustment-line.js.map +1 -1
- package/dist/models/claim-item-image.d.ts +19 -0
- package/dist/models/claim-item-image.d.ts.map +1 -0
- package/dist/models/claim-item-image.js +109 -0
- package/dist/models/claim-item-image.js.map +1 -0
- package/dist/models/claim-item.d.ts +29 -0
- package/dist/models/claim-item.d.ts.map +1 -0
- package/dist/models/claim-item.js +157 -0
- package/dist/models/claim-item.js.map +1 -0
- package/dist/models/claim.d.ts +37 -0
- package/dist/models/claim.d.ts.map +1 -0
- package/dist/models/claim.js +201 -0
- package/dist/models/claim.js.map +1 -0
- package/dist/models/exchange-item.d.ts +24 -0
- package/dist/models/exchange-item.d.ts.map +1 -0
- package/dist/models/exchange-item.js +138 -0
- package/dist/models/exchange-item.js.map +1 -0
- package/dist/models/exchange.d.ts +35 -0
- package/dist/models/exchange.d.ts.map +1 -0
- package/dist/models/exchange.js +194 -0
- package/dist/models/exchange.js.map +1 -0
- package/dist/models/index.d.ts +18 -9
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +26 -10
- package/dist/models/index.js.map +1 -1
- package/dist/models/line-item-adjustment.d.ts +5 -3
- package/dist/models/line-item-adjustment.d.ts.map +1 -0
- package/dist/models/line-item-adjustment.js +12 -12
- package/dist/models/line-item-adjustment.js.map +1 -1
- package/dist/models/line-item-tax-line.d.ts +5 -3
- package/dist/models/line-item-tax-line.d.ts.map +1 -0
- package/dist/models/line-item-tax-line.js +12 -12
- package/dist/models/line-item-tax-line.js.map +1 -1
- package/dist/models/line-item.d.ts +11 -8
- package/dist/models/line-item.d.ts.map +1 -0
- package/dist/models/line-item.js +58 -39
- package/dist/models/line-item.js.map +1 -1
- package/dist/models/order-change-action.d.ts +17 -6
- package/dist/models/order-change-action.d.ts.map +1 -0
- package/dist/models/order-change-action.js +110 -8
- package/dist/models/order-change-action.js.map +1 -1
- package/dist/models/order-change.d.ts +18 -6
- package/dist/models/order-change.d.ts.map +1 -0
- package/dist/models/order-change.js +108 -6
- package/dist/models/order-change.js.map +1 -1
- package/dist/models/order-item.d.ts +10 -7
- package/dist/models/order-item.d.ts.map +1 -0
- package/dist/models/order-item.js +29 -19
- package/dist/models/order-item.js.map +1 -1
- package/dist/models/order-shipping-method.d.ts +17 -7
- package/dist/models/order-shipping-method.d.ts.map +1 -0
- package/dist/models/order-shipping-method.js +113 -33
- package/dist/models/order-shipping-method.js.map +1 -1
- package/dist/models/order-summary.d.ts +7 -8
- package/dist/models/order-summary.d.ts.map +1 -0
- package/dist/models/order-summary.js +14 -10
- package/dist/models/order-summary.js.map +1 -1
- package/dist/models/order.d.ts +13 -11
- package/dist/models/order.d.ts.map +1 -0
- package/dist/models/order.js +12 -2
- package/dist/models/order.js.map +1 -1
- package/dist/models/return-item.d.ts +31 -0
- package/dist/models/return-item.d.ts.map +1 -0
- package/dist/models/return-item.js +180 -0
- package/dist/models/return-item.js.map +1 -0
- package/dist/models/return-reason.d.ts +22 -0
- package/dist/models/return-reason.d.ts.map +1 -0
- package/dist/models/return-reason.js +122 -0
- package/dist/models/return-reason.js.map +1 -0
- package/dist/models/return.d.ts +41 -0
- package/dist/models/return.d.ts.map +1 -0
- package/dist/models/return.js +227 -0
- package/dist/models/return.js.map +1 -0
- package/dist/models/shipping-method-adjustment.d.ts +5 -3
- package/dist/models/shipping-method-adjustment.d.ts.map +1 -0
- package/dist/models/shipping-method-adjustment.js +12 -12
- package/dist/models/shipping-method-adjustment.js.map +1 -1
- package/dist/models/shipping-method-tax-line.d.ts +5 -3
- package/dist/models/shipping-method-tax-line.d.ts.map +1 -0
- package/dist/models/shipping-method-tax-line.js +12 -12
- package/dist/models/shipping-method-tax-line.js.map +1 -1
- package/dist/models/shipping-method.d.ts +10 -7
- package/dist/models/shipping-method.d.ts.map +1 -0
- package/dist/models/shipping-method.js +42 -24
- package/dist/models/shipping-method.js.map +1 -1
- package/dist/models/tax-line.d.ts +4 -2
- package/dist/models/tax-line.d.ts.map +1 -0
- package/dist/models/tax-line.js +8 -1
- package/dist/models/tax-line.js.map +1 -1
- package/dist/models/transaction.d.ts +18 -6
- package/dist/models/transaction.d.ts.map +1 -0
- package/dist/models/transaction.js +133 -24
- package/dist/models/transaction.js.map +1 -1
- package/dist/repositories/claim.d.ts +9 -0
- package/dist/repositories/claim.d.ts.map +1 -0
- package/dist/repositories/claim.js +11 -0
- package/dist/repositories/claim.js.map +1 -0
- package/dist/repositories/exchange.d.ts +9 -0
- package/dist/repositories/exchange.d.ts.map +1 -0
- package/dist/repositories/exchange.js +11 -0
- package/dist/repositories/exchange.js.map +1 -0
- package/dist/repositories/index.d.ts +5 -2
- package/dist/repositories/index.d.ts.map +1 -0
- package/dist/repositories/index.js +8 -17
- package/dist/repositories/index.js.map +1 -1
- package/dist/repositories/order.d.ts +2 -4
- package/dist/repositories/order.d.ts.map +1 -0
- package/dist/repositories/order.js +3 -86
- package/dist/repositories/order.js.map +1 -1
- package/dist/repositories/return.d.ts +9 -0
- package/dist/repositories/return.d.ts.map +1 -0
- package/dist/repositories/return.js +11 -0
- package/dist/repositories/return.js.map +1 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +556 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/services/actions/cancel-claim.d.ts +3 -0
- package/dist/services/actions/cancel-claim.d.ts.map +1 -0
- package/dist/services/actions/cancel-claim.js +85 -0
- package/dist/services/actions/cancel-claim.js.map +1 -0
- package/dist/services/actions/cancel-exchange.d.ts +3 -0
- package/dist/services/actions/cancel-exchange.d.ts.map +1 -0
- package/dist/services/actions/cancel-exchange.js +71 -0
- package/dist/services/actions/cancel-exchange.js.map +1 -0
- package/dist/services/actions/cancel-fulfillment.d.ts +3 -0
- package/dist/services/actions/cancel-fulfillment.d.ts.map +1 -0
- package/dist/services/actions/cancel-fulfillment.js +31 -0
- package/dist/services/actions/cancel-fulfillment.js.map +1 -0
- package/dist/services/actions/cancel-return.d.ts +3 -0
- package/dist/services/actions/cancel-return.d.ts.map +1 -0
- package/dist/services/actions/cancel-return.js +69 -0
- package/dist/services/actions/cancel-return.js.map +1 -0
- package/dist/services/actions/create-claim.d.ts +3 -0
- package/dist/services/actions/create-claim.d.ts.map +1 -0
- package/dist/services/actions/create-claim.js +225 -0
- package/dist/services/actions/create-claim.js.map +1 -0
- package/dist/services/actions/create-exchange.d.ts +3 -0
- package/dist/services/actions/create-exchange.d.ts.map +1 -0
- package/dist/services/actions/create-exchange.js +191 -0
- package/dist/services/actions/create-exchange.js.map +1 -0
- package/dist/services/actions/create-return.d.ts +3 -0
- package/dist/services/actions/create-return.d.ts.map +1 -0
- package/dist/services/actions/create-return.js +100 -0
- package/dist/services/actions/create-return.js.map +1 -0
- package/dist/services/actions/index.d.ts +12 -0
- package/dist/services/actions/index.d.ts.map +1 -0
- package/dist/services/actions/index.js +28 -0
- package/dist/services/actions/index.js.map +1 -0
- package/dist/services/actions/receive-return.d.ts +3 -0
- package/dist/services/actions/receive-return.d.ts.map +1 -0
- package/dist/services/actions/receive-return.js +71 -0
- package/dist/services/actions/receive-return.js.map +1 -0
- package/dist/services/actions/register-delivery.d.ts +3 -0
- package/dist/services/actions/register-delivery.d.ts.map +1 -0
- package/dist/services/actions/register-delivery.js +29 -0
- package/dist/services/actions/register-delivery.js.map +1 -0
- package/dist/services/actions/register-fulfillment.d.ts +3 -0
- package/dist/services/actions/register-fulfillment.d.ts.map +1 -0
- package/dist/services/actions/register-fulfillment.js +29 -0
- package/dist/services/actions/register-fulfillment.js.map +1 -0
- package/dist/services/actions/register-shipment.d.ts +3 -0
- package/dist/services/actions/register-shipment.d.ts.map +1 -0
- package/dist/services/actions/register-shipment.js +37 -0
- package/dist/services/actions/register-shipment.js.map +1 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +1 -3
- package/dist/services/index.js.map +1 -1
- package/dist/services/order-module-service.d.ts +191 -109
- package/dist/services/order-module-service.d.ts.map +1 -0
- package/dist/services/order-module-service.js +1165 -425
- package/dist/services/order-module-service.js.map +1 -1
- package/dist/services/order-service.d.ts +6 -5
- package/dist/services/order-service.d.ts.map +1 -0
- package/dist/services/order-service.js +2 -2
- package/dist/services/order-service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/dist/types/address.d.ts +2 -1
- package/dist/types/address.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -2
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/line-item-adjustment.d.ts +2 -1
- package/dist/types/line-item-adjustment.d.ts.map +1 -0
- package/dist/types/line-item-tax-line.d.ts +1 -0
- package/dist/types/line-item-tax-line.d.ts.map +1 -0
- package/dist/types/line-item.d.ts +2 -1
- package/dist/types/line-item.d.ts.map +1 -0
- package/dist/types/order-change.d.ts +4 -0
- package/dist/types/order-change.d.ts.map +1 -0
- package/dist/types/order-change.js +3 -0
- package/dist/types/order-change.js.map +1 -0
- package/dist/types/order-detail.d.ts +3 -2
- package/dist/types/order-detail.d.ts.map +1 -0
- package/dist/types/order.d.ts +4 -3
- package/dist/types/order.d.ts.map +1 -0
- package/dist/types/return-reason.d.ts +5 -0
- package/dist/types/return-reason.d.ts.map +1 -0
- package/dist/types/return-reason.js +3 -0
- package/dist/types/return-reason.js.map +1 -0
- package/dist/types/shipping-method-adjustment.d.ts +2 -1
- package/dist/types/shipping-method-adjustment.d.ts.map +1 -0
- package/dist/types/shipping-method-tax-line.d.ts +1 -0
- package/dist/types/shipping-method-tax-line.d.ts.map +1 -0
- package/dist/types/shipping-method.d.ts +5 -1
- package/dist/types/shipping-method.d.ts.map +1 -0
- package/dist/types/tax-line.d.ts +2 -1
- package/dist/types/tax-line.d.ts.map +1 -0
- package/dist/types/transaction.d.ts +2 -1
- package/dist/types/transaction.d.ts.map +1 -0
- package/dist/types/utils/index.d.ts +41 -23
- package/dist/types/utils/index.d.ts.map +1 -0
- package/dist/types/utils/index.js +0 -1
- package/dist/types/utils/index.js.map +1 -1
- package/dist/utils/actions/cancel-item-fulfillment.d.ts +2 -0
- package/dist/utils/actions/cancel-item-fulfillment.d.ts.map +1 -0
- package/dist/utils/actions/cancel-item-fulfillment.js +34 -0
- package/dist/utils/actions/cancel-item-fulfillment.js.map +1 -0
- package/dist/utils/actions/cancel-return.d.ts +1 -0
- package/dist/utils/actions/cancel-return.d.ts.map +1 -0
- package/dist/utils/actions/cancel-return.js +9 -16
- package/dist/utils/actions/cancel-return.js.map +1 -1
- package/dist/utils/actions/deliver-item.d.ts +2 -0
- package/dist/utils/actions/deliver-item.d.ts.map +1 -0
- package/dist/utils/actions/deliver-item.js +38 -0
- package/dist/utils/actions/deliver-item.js.map +1 -0
- package/dist/utils/actions/fulfill-item.d.ts +1 -0
- package/dist/utils/actions/fulfill-item.d.ts.map +1 -0
- package/dist/utils/actions/fulfill-item.js +8 -12
- package/dist/utils/actions/fulfill-item.js.map +1 -1
- package/dist/utils/actions/index.d.ts +7 -1
- package/dist/utils/actions/index.d.ts.map +1 -0
- package/dist/utils/actions/index.js +6 -1
- package/dist/utils/actions/index.js.map +1 -1
- package/dist/utils/actions/item-add.d.ts +1 -0
- package/dist/utils/actions/item-add.d.ts.map +1 -0
- package/dist/utils/actions/item-add.js +17 -26
- package/dist/utils/actions/item-add.js.map +1 -1
- package/dist/utils/actions/item-remove.d.ts +1 -0
- package/dist/utils/actions/item-remove.d.ts.map +1 -0
- package/dist/utils/actions/item-remove.js +10 -30
- package/dist/utils/actions/item-remove.js.map +1 -1
- package/dist/utils/actions/item-update.d.ts +2 -0
- package/dist/utils/actions/item-update.d.ts.map +1 -0
- package/dist/utils/actions/item-update.js +37 -0
- package/dist/utils/actions/item-update.js.map +1 -0
- package/dist/utils/actions/receive-damaged-return-item.d.ts +1 -0
- package/dist/utils/actions/receive-damaged-return-item.d.ts.map +1 -0
- package/dist/utils/actions/receive-damaged-return-item.js +11 -37
- package/dist/utils/actions/receive-damaged-return-item.js.map +1 -1
- package/dist/utils/actions/receive-return-item.d.ts +1 -0
- package/dist/utils/actions/receive-return-item.d.ts.map +1 -0
- package/dist/utils/actions/receive-return-item.js +9 -38
- package/dist/utils/actions/receive-return-item.js.map +1 -1
- package/dist/utils/actions/reinstate-item.d.ts +2 -0
- package/dist/utils/actions/reinstate-item.d.ts.map +1 -0
- package/dist/utils/actions/reinstate-item.js +32 -0
- package/dist/utils/actions/reinstate-item.js.map +1 -0
- package/dist/utils/actions/return-item.d.ts +1 -0
- package/dist/utils/actions/return-item.d.ts.map +1 -0
- package/dist/utils/actions/return-item.js +10 -15
- package/dist/utils/actions/return-item.js.map +1 -1
- package/dist/utils/actions/ship-item.d.ts +1 -0
- package/dist/utils/actions/ship-item.d.ts.map +1 -0
- package/dist/utils/actions/ship-item.js +8 -12
- package/dist/utils/actions/ship-item.js.map +1 -1
- package/dist/utils/actions/shipping-add.d.ts +1 -0
- package/dist/utils/actions/shipping-add.d.ts.map +1 -0
- package/dist/utils/actions/shipping-add.js +18 -18
- package/dist/utils/actions/shipping-add.js.map +1 -1
- package/dist/utils/actions/shipping-remove.d.ts +2 -0
- package/dist/utils/actions/shipping-remove.d.ts.map +1 -0
- package/dist/utils/actions/shipping-remove.js +22 -0
- package/dist/utils/actions/shipping-remove.js.map +1 -0
- package/dist/utils/actions/write-off-item.d.ts +1 -0
- package/dist/utils/actions/write-off-item.d.ts.map +1 -0
- package/dist/utils/actions/write-off-item.js +8 -12
- package/dist/utils/actions/write-off-item.js.map +1 -1
- package/dist/utils/apply-order-changes.d.ts +18 -0
- package/dist/utils/apply-order-changes.d.ts.map +1 -0
- package/dist/utils/apply-order-changes.js +98 -0
- package/dist/utils/apply-order-changes.js.map +1 -0
- package/dist/utils/base-repository-find.d.ts +3 -0
- package/dist/utils/base-repository-find.d.ts.map +1 -0
- package/dist/utils/base-repository-find.js +154 -0
- package/dist/utils/base-repository-find.js.map +1 -0
- package/dist/utils/calculate-order-change.d.ts +12 -6
- package/dist/utils/calculate-order-change.d.ts.map +1 -0
- package/dist/utils/calculate-order-change.js +56 -187
- package/dist/utils/calculate-order-change.js.map +1 -1
- package/dist/utils/index.d.ts +4 -1
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/set-action-reference.d.ts +2 -0
- package/dist/utils/set-action-reference.d.ts.map +1 -0
- package/dist/utils/set-action-reference.js +10 -0
- package/dist/utils/set-action-reference.js.map +1 -0
- package/dist/utils/transform-order.d.ts +5 -4
- package/dist/utils/transform-order.d.ts.map +1 -0
- package/dist/utils/transform-order.js +138 -21
- package/dist/utils/transform-order.js.map +1 -1
- package/package.json +25 -26
- package/dist/module-definition.d.ts +0 -2
- package/dist/module-definition.js +0 -59
- package/dist/module-definition.js.map +0 -1
- package/dist/scripts/bin/run-seed.d.ts +0 -3
- package/dist/scripts/bin/run-seed.js +0 -49
- package/dist/scripts/bin/run-seed.js.map +0 -1
- package/dist/services/order-change-service.d.ts +0 -15
- package/dist/services/order-change-service.js +0 -96
- package/dist/services/order-change-service.js.map +0 -1
- package/dist/utils/action-key.d.ts +0 -13
- package/dist/utils/action-key.js +0 -18
- package/dist/utils/action-key.js.map +0 -1
- package/dist/utils/actions/cancel.d.ts +0 -1
- package/dist/utils/actions/cancel.js +0 -8
- package/dist/utils/actions/cancel.js.map +0 -1
@@ -0,0 +1,37 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
4
|
+
const calculate_order_change_1 = require("../calculate-order-change");
|
5
|
+
const set_action_reference_1 = require("../set-action-reference");
|
6
|
+
calculate_order_change_1.OrderChangeProcessing.registerActionType(utils_1.ChangeActionType.ITEM_UPDATE, {
|
7
|
+
operation({ action, currentOrder, options }) {
|
8
|
+
const existingIndex = currentOrder.items.findIndex((item) => item.id === action.details.reference_id);
|
9
|
+
const existing = currentOrder.items[existingIndex];
|
10
|
+
existing.detail.quantity ??= 0;
|
11
|
+
const quantityDiff = utils_1.MathBN.sub(action.details.quantity, existing.detail.quantity);
|
12
|
+
const quant = new utils_1.BigNumber(action.details.quantity);
|
13
|
+
existing.quantity = quant;
|
14
|
+
existing.detail.quantity = quant;
|
15
|
+
(0, set_action_reference_1.setActionReference)(existing, action, options);
|
16
|
+
return utils_1.MathBN.mult(existing.unit_price, quantityDiff);
|
17
|
+
},
|
18
|
+
validate({ action, currentOrder }) {
|
19
|
+
const refId = action.details?.reference_id;
|
20
|
+
if (refId == null) {
|
21
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Reference ID is required.");
|
22
|
+
}
|
23
|
+
const existing = currentOrder.items.find((item) => item.id === refId);
|
24
|
+
if (!existing) {
|
25
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Item ID "${refId}" not found.`);
|
26
|
+
}
|
27
|
+
if (action.details?.quantity == null) {
|
28
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Quantity of item ${refId} is required.`);
|
29
|
+
}
|
30
|
+
action.details.quantity ??= 0;
|
31
|
+
const lower = utils_1.MathBN.lt(action.details.quantity, existing.detail?.fulfilled_quantity);
|
32
|
+
if (lower) {
|
33
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Item ${refId} has already been fulfilled and quantity cannot be lower than ${existing.detail?.fulfilled_quantity}.`);
|
34
|
+
}
|
35
|
+
},
|
36
|
+
});
|
37
|
+
//# sourceMappingURL=item-update.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"item-update.js","sourceRoot":"","sources":["../../../src/utils/actions/item-update.ts"],"names":[],"mappings":";;AAAA,qDAKkC;AAClC,sEAAiE;AACjE,kEAA4D;AAE5D,8CAAqB,CAAC,kBAAkB,CAAC,wBAAgB,CAAC,WAAW,EAAE;IACrE,SAAS,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE;QACzC,MAAM,aAAa,GAAG,YAAY,CAAC,KAAK,CAAC,SAAS,CAChD,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,YAAY,CAClD,CAAA;QAED,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;QAElD,QAAQ,CAAC,MAAM,CAAC,QAAQ,KAAK,CAAC,CAAA;QAE9B,MAAM,YAAY,GAAG,cAAM,CAAC,GAAG,CAC7B,MAAM,CAAC,OAAO,CAAC,QAAQ,EACvB,QAAQ,CAAC,MAAM,CAAC,QAAQ,CACzB,CAAA;QAED,MAAM,KAAK,GAAG,IAAI,iBAAS,CAAC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;QACpD,QAAQ,CAAC,QAAQ,GAAG,KAAK,CAAA;QAC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AiE,QAAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,CACrH,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"receive-damaged-return-item.d.ts","sourceRoot":"","sources":["../../../src/utils/actions/receive-damaged-return-item.ts"],"names":[],"mappings":""}
|
@@ -1,56 +1,30 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const utils_1 = require("@medusajs/utils");
|
4
|
-
const _types_1 = require("../../types");
|
5
|
-
const action_key_1 = require("../action-key");
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
6
4
|
const calculate_order_change_1 = require("../calculate-order-change");
|
7
|
-
|
5
|
+
const set_action_reference_1 = require("../set-action-reference");
|
6
|
+
calculate_order_change_1.OrderChangeProcessing.registerActionType(utils_1.ChangeActionType.RECEIVE_DAMAGED_RETURN_ITEM, {
|
8
7
|
isDeduction: true,
|
9
|
-
|
10
|
-
operation({ action, currentOrder, previousEvents }) {
|
11
|
-
var _a, _b;
|
8
|
+
operation({ action, currentOrder, previousEvents, options }) {
|
12
9
|
const existing = currentOrder.items.find((item) => item.id === action.details.reference_id);
|
13
10
|
let toReturn = action.details.quantity;
|
14
|
-
|
15
|
-
|
11
|
+
existing.detail.return_dismissed_quantity ??= 0;
|
12
|
+
existing.detail.return_requested_quantity ??= 0;
|
16
13
|
existing.detail.return_dismissed_quantity = utils_1.MathBN.add(existing.detail.return_dismissed_quantity, toReturn);
|
17
14
|
existing.detail.return_requested_quantity = utils_1.MathBN.sub(existing.detail.return_requested_quantity, toReturn);
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
let ret = utils_1.MathBN.min(toReturn, previousEvent.details.quantity);
|
22
|
-
toReturn = utils_1.MathBN.sub(toReturn, ret);
|
23
|
-
previousEvent.details.quantity = utils_1.MathBN.sub(previousEvent.details.quantity, ret);
|
24
|
-
if (utils_1.MathBN.lte(previousEvent.details.quantity, 0)) {
|
25
|
-
previousEvent.status = _types_1.EVENT_STATUS.DONE;
|
26
|
-
}
|
27
|
-
}
|
28
|
-
}
|
15
|
+
existing.detail.written_off_quantity ??= 0;
|
16
|
+
existing.detail.written_off_quantity = utils_1.MathBN.add(existing.detail.written_off_quantity, action.details.quantity);
|
17
|
+
(0, set_action_reference_1.setActionReference)(existing, action, options);
|
29
18
|
return utils_1.MathBN.mult(existing.unit_price, action.details.quantity);
|
30
19
|
},
|
31
|
-
revert({ action, currentOrder, previousEvents }) {
|
32
|
-
const existing = currentOrder.items.find((item) => item.id === action.details.reference_id);
|
33
|
-
existing.detail.return_dismissed_quantity = utils_1.MathBN.sub(existing.detail.return_dismissed_quantity, action.details.quantity);
|
34
|
-
existing.detail.return_requested_quantity = utils_1.MathBN.add(existing.detail.return_requested_quantity, action.details.quantity);
|
35
|
-
if (previousEvents) {
|
36
|
-
for (const previousEvent of previousEvents) {
|
37
|
-
if (!previousEvent.original_) {
|
38
|
-
continue;
|
39
|
-
}
|
40
|
-
previousEvent.details = JSON.parse(JSON.stringify(previousEvent.original_.details));
|
41
|
-
delete previousEvent.original_;
|
42
|
-
previousEvent.status = _types_1.EVENT_STATUS.PENDING;
|
43
|
-
}
|
44
|
-
}
|
45
|
-
},
|
46
20
|
validate({ action, currentOrder }) {
|
47
21
|
const refId = action.details?.reference_id;
|
48
|
-
if (
|
22
|
+
if (refId == null) {
|
49
23
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Details reference ID is required.");
|
50
24
|
}
|
51
25
|
const existing = currentOrder.items.find((item) => item.id === refId);
|
52
26
|
if (!existing) {
|
53
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `
|
27
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Item ID "${refId}" not found.`);
|
54
28
|
}
|
55
29
|
if (!action.details?.quantity) {
|
56
30
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Quantity to return of item ${refId} is required.`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"receive-damaged-return-item.js","sourceRoot":"","sources":["../../../src/utils/actions/receive-damaged-return-item.ts"],"names":[],"mappings":";;AAAA,
|
1
|
+
{"version":3,"file":"receive-damaged-return-item.js","sourceRoot":"","sources":["../../../src/utils/actions/receive-damaged-return-item.ts"],"names":[],"mappings":";;AAAA,qDAIkC;AAClC,sEAAiE;AACjE,kEAA4D;AAE5D,8CAAqB,CAAC,kBAAkB,CACtC,wBAAgB,CAAC,2BAA2B,EAC5C;IACE,WAAW,EAAE,IAAI;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE;QACzD,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CACtC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,YAAY,CACjD,CAAA;QAEF,IAAI,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAA;QAEtC,QAAQ,CAAC,MAAM,CAAC,yBAAyB,KAAK,CAAC,CAAA;QAC/C,QAAQ,CAAC,MAAM,CAAC,yBAAyB,KAAK,CAAC,CAAA;QAE/C,QAAQ,CAAC,MAAM,CAAC,yBAAyB,GAAG,cAAM,CAAC,GAAG,CACpD,QAAQ,CAAC,MAAM,CAAC,yBAAyB,EACzC,QAAQ,CACT,CAAA;QACD,QAAQ,CAAC,MAAM,CAAC,yBAAyB,GAAG,cAAM,CAAC,GAAG,CACpD,QAAQ,CAAC,MAAM,CAAC,yBAAyB,EACzC,QAAQ,CACT,CAAA;QAED,QAAQ,CAAC,MAAM,CAAC,oBAAoB,KAAK,CAAC,CAAA;QAC1C,QAAQ,CAAC,MAAM,CAAC,oBAAoB,GAAG,cAAM,CAAC,GAAG,CAC/C,QAAQ,CAAC,MAAM,CAAC,oBAAoB,EACpC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 -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"receive-return-item.d.ts","sourceRoot":"","sources":["../../../src/utils/actions/receive-return-item.ts"],"names":[],"mappings":""}
|
@@ -1,57 +1,28 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const utils_1 = require("@medusajs/utils");
|
4
|
-
const _types_1 = require("../../types");
|
5
|
-
const action_key_1 = require("../action-key");
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
6
4
|
const calculate_order_change_1 = require("../calculate-order-change");
|
7
|
-
|
5
|
+
const set_action_reference_1 = require("../set-action-reference");
|
6
|
+
calculate_order_change_1.OrderChangeProcessing.registerActionType(utils_1.ChangeActionType.RECEIVE_RETURN_ITEM, {
|
8
7
|
isDeduction: true,
|
9
|
-
|
10
|
-
operation({ action, currentOrder, previousEvents }) {
|
11
|
-
var _a, _b;
|
8
|
+
operation({ action, currentOrder, previousEvents, options }) {
|
12
9
|
const existing = currentOrder.items.find((item) => item.id === action.details.reference_id);
|
13
10
|
let toReturn = action.details.quantity;
|
14
|
-
|
15
|
-
|
11
|
+
existing.detail.return_received_quantity ??= 0;
|
12
|
+
existing.detail.return_requested_quantity ??= 0;
|
16
13
|
existing.detail.return_received_quantity = utils_1.MathBN.add(existing.detail.return_received_quantity, toReturn);
|
17
14
|
existing.detail.return_requested_quantity = utils_1.MathBN.sub(existing.detail.return_requested_quantity, toReturn);
|
18
|
-
|
19
|
-
for (const previousEvent of previousEvents) {
|
20
|
-
previousEvent.original_ = JSON.parse(JSON.stringify(previousEvent));
|
21
|
-
let ret = utils_1.MathBN.min(toReturn, previousEvent.details.quantity);
|
22
|
-
toReturn = utils_1.MathBN.sub(toReturn, ret);
|
23
|
-
previousEvent.details.quantity = utils_1.MathBN.sub(previousEvent.details.quantity, ret);
|
24
|
-
if (utils_1.MathBN.lte(previousEvent.details.quantity, 0)) {
|
25
|
-
previousEvent.status = _types_1.EVENT_STATUS.DONE;
|
26
|
-
}
|
27
|
-
}
|
28
|
-
}
|
15
|
+
(0, set_action_reference_1.setActionReference)(existing, action, options);
|
29
16
|
return utils_1.MathBN.mult(existing.unit_price, action.details.quantity);
|
30
17
|
},
|
31
|
-
revert({ action, currentOrder, previousEvents }) {
|
32
|
-
const existing = currentOrder.items.find((item) => item.id === action.details.reference_id);
|
33
|
-
existing.detail.return_received_quantity = utils_1.MathBN.sub(existing.detail.return_received_quantity, action.details.quantity);
|
34
|
-
existing.detail.return_requested_quantity = utils_1.MathBN.add(existing.detail.return_requested_quantity, action.details.quantity);
|
35
|
-
if (previousEvents) {
|
36
|
-
for (const previousEvent of previousEvents) {
|
37
|
-
if (!previousEvent.original_) {
|
38
|
-
continue;
|
39
|
-
}
|
40
|
-
previousEvent.details = JSON.parse(JSON.stringify(previousEvent.original_.details));
|
41
|
-
(0, utils_1.transformPropertiesToBigNumber)(previousEvent.details?.metadata);
|
42
|
-
delete previousEvent.original_;
|
43
|
-
previousEvent.status = _types_1.EVENT_STATUS.PENDING;
|
44
|
-
}
|
45
|
-
}
|
46
|
-
},
|
47
18
|
validate({ action, currentOrder }) {
|
48
19
|
const refId = action.details?.reference_id;
|
49
|
-
if (
|
20
|
+
if (refId == null) {
|
50
21
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Details reference ID is required.");
|
51
22
|
}
|
52
23
|
const existing = currentOrder.items.find((item) => item.id === refId);
|
53
24
|
if (!existing) {
|
54
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `
|
25
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Item ID "${refId}" not found.`);
|
55
26
|
}
|
56
27
|
if (!action.details?.quantity) {
|
57
28
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Quantity to receive return of item ${refId} is required.`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"receive-return-item.js","sourceRoot":"","sources":["../../../src/utils/actions/receive-return-item.ts"],"names":[],"mappings":";;AAAA,
|
1
|
+
{"version":3,"file":"receive-return-item.js","sourceRoot":"","sources":["../../../src/utils/actions/receive-return-item.ts"],"names":[],"mappings":";;AAAA,qDAIkC;AAClC,sEAAiE;AACjE,kEAA4D;AAE5D,8CAAqB,CAAC,kBAAkB,CAAC,wBAAgB,CAAC,mBAAmB,EAAE;IAC7E,WAAW,EAAE,IAAI;IACjB,SAAS,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,cAAc,EAAE,OAAO,EAAE;QACzD,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CACtC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,YAAY,CACjD,CAAA;QAEF,IAAI,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAA;QAEtC,QAAQ,CAAC,MAAM,CAAC,wBAAwB,KAAK,CAAC,CAAA;QAC9C,QAAQ,CAAC,MAAM,CAAC,yBAAyB,KAAK,CAAC,CAAA;QAE/C,QAAQ,CAAC,MAAM,CAAC,wBAAwB,GAAG,cAAM,CAAC,GAAG,CACnD,QAAQ,CAAC,MAAM,CAAC,wBAAwB,EACxC,QAAQ,CACT,CAAA;QACD,QAAQ,CAAC,MAAM,CAAC,yBAAyB,GAAG,cAAM,CAAC,GAAG,CACpD,QAAQ,CAAC,MAAM,CAAC,yBAAyB,EACzC,QAAQ,CACT,CAAA;QAED,IAAA,yCAAkB,EAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;QAE7C,OAAO,cAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IAClE,CAAC;IACD,QAAQ,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,EAAE,YAAY,CAAA;QAC1C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,mCAAmC,CACpC,CAAA;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,CAAA;QAErE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,YAAY,KAAK,cAAc,CAChC,CAAA;QACH,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;YAC9B,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,sCAAsC,KAAK,eAAe,CAC3D,CAAA;QACH,CAAC;QAED,MAAM,iBAAiB,GAAG,QAAQ,EAAE,MAAM,EAAE,yBAAyB,IAAI,CAAC,CAAA;QAE1E,MAAM,OAAO,GAAG,cAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAA;QACtE,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,6EAA6E,KAAK,GAAG,CACtF,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"reinstate-item.d.ts","sourceRoot":"","sources":["../../../src/utils/actions/reinstate-item.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
4
|
+
const calculate_order_change_1 = require("../calculate-order-change");
|
5
|
+
const set_action_reference_1 = require("../set-action-reference");
|
6
|
+
calculate_order_change_1.OrderChangeProcessing.registerActionType(utils_1.ChangeActionType.REINSTATE_ITEM, {
|
7
|
+
operation({ action, currentOrder, options }) {
|
8
|
+
const existing = currentOrder.items.find((item) => item.id === action.details.reference_id);
|
9
|
+
existing.detail.written_off_quantity ??= 0;
|
10
|
+
existing.detail.written_off_quantity = utils_1.MathBN.sub(existing.detail.written_off_quantity, action.details.quantity);
|
11
|
+
(0, set_action_reference_1.setActionReference)(existing, action, options);
|
12
|
+
},
|
13
|
+
validate({ action, currentOrder }) {
|
14
|
+
const refId = action.details?.reference_id;
|
15
|
+
if (refId == null) {
|
16
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Details reference ID is required.");
|
17
|
+
}
|
18
|
+
const existing = currentOrder.items.find((item) => item.id === refId);
|
19
|
+
if (!existing) {
|
20
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Item ID "${refId}" not found.`);
|
21
|
+
}
|
22
|
+
if (!action.details?.quantity) {
|
23
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Quantity to reinstate item ${refId} is required.`);
|
24
|
+
}
|
25
|
+
const quantityAvailable = existing.quantity ?? 0;
|
26
|
+
const greater = utils_1.MathBN.gt(action.details?.quantity, quantityAvailable);
|
27
|
+
if (greater) {
|
28
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Cannot unclaim more items than what was ordered.");
|
29
|
+
}
|
30
|
+
},
|
31
|
+
});
|
32
|
+
//# sourceMappingURL=reinstate-item.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"reinstate-item.js","sourceRoot":"","sources":["../../../src/utils/actions/reinstate-item.ts"],"names":[],"mappings":";;AAAA,qDAIkC;AAClC,sEAAiE;AACjE,kEAA4D;AAE5D,8CAAqB,CAAC,kBAAkB,CAAC,wBAAgB,CAAC,cAAc,EAAE;IACxE,SAAS,C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QAAS,CAAC,QAAQ,IAAI,CAAC,CAAA;QACjD,MAAM,OAAO,GAAG,cAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAA;QACtE,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,kDAAkD,CACnD,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"return-item.d.ts","sourceRoot":"","sources":["../../../src/utils/actions/return-item.ts"],"names":[],"mappings":""}
|
@@ -1,38 +1,33 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const utils_1 = require("@medusajs/utils");
|
4
|
-
const action_key_1 = require("../action-key");
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
5
4
|
const calculate_order_change_1 = require("../calculate-order-change");
|
6
|
-
|
5
|
+
const set_action_reference_1 = require("../set-action-reference");
|
6
|
+
calculate_order_change_1.OrderChangeProcessing.registerActionType(utils_1.ChangeActionType.RETURN_ITEM, {
|
7
7
|
isDeduction: true,
|
8
|
-
|
9
|
-
operation({ action, currentOrder }) {
|
10
|
-
var _a;
|
8
|
+
operation({ action, currentOrder, options }) {
|
11
9
|
const existing = currentOrder.items.find((item) => item.id === action.details.reference_id);
|
12
|
-
|
10
|
+
existing.detail.return_requested_quantity ??= 0;
|
13
11
|
existing.detail.return_requested_quantity = utils_1.MathBN.add(existing.detail.return_requested_quantity, action.details.quantity);
|
12
|
+
(0, set_action_reference_1.setActionReference)(existing, action, options);
|
14
13
|
return utils_1.MathBN.mult(existing.unit_price, action.details.quantity);
|
15
14
|
},
|
16
|
-
revert({ action, currentOrder }) {
|
17
|
-
const existing = currentOrder.items.find((item) => item.id === action.details.reference_id);
|
18
|
-
existing.detail.return_requested_quantity = utils_1.MathBN.sub(existing.detail.return_requested_quantity, action.details.quantity);
|
19
|
-
},
|
20
15
|
validate({ action, currentOrder }) {
|
21
16
|
const refId = action.details?.reference_id;
|
22
|
-
if (
|
17
|
+
if (refId == null) {
|
23
18
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Details reference ID is required.");
|
24
19
|
}
|
25
20
|
const existing = currentOrder.items.find((item) => item.id === refId);
|
26
21
|
if (!existing) {
|
27
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `
|
22
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Item ID "${refId}" not found.`);
|
28
23
|
}
|
29
24
|
if (!action.details?.quantity) {
|
30
25
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Quantity to return of item ${refId} is required.`);
|
31
26
|
}
|
32
|
-
const quantityAvailable = utils_1.MathBN.sub(existing.detail?.
|
27
|
+
const quantityAvailable = utils_1.MathBN.sub(existing.detail?.fulfilled_quantity ?? 0, existing.detail?.return_requested_quantity ?? 0);
|
33
28
|
const greater = utils_1.MathBN.gt(action.details?.quantity, quantityAvailable);
|
34
29
|
if (greater) {
|
35
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Cannot request to return more items than what was
|
30
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Cannot request to return more items than what was fulfilled for item ${refId}.`);
|
36
31
|
}
|
37
32
|
},
|
38
33
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"return-item.js","sourceRoot":"","sources":["../../../src/utils/actions/return-item.ts"],"names":[],"mappings":";;AAAA,
|
1
|
+
{"version":3,"file":"return-item.js","sourceRoot":"","sources":["../../../src/utils/actions/return-item.ts"],"names":[],"mappings":";;AAAA,qDAIkC;AAClC,sEAAiE;AACjE,kEAA4D;AAE5D,8CAAqB,CAAC,kBAAkB,CAAC,wBAAgB,CAAC,WAAW,EAAE;IACrE,W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,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,8BAA8B,KAAK,eAAe,CACnD,CAAA;QACH,CAAC;QAED,MAAM,iBAAiB,GAAG,cAAM,CAAC,GAAG,CAClC,QAAS,CAAC,MAAM,EAAE,kBAAkB,IAAI,CAAC,EACzC,QAAS,CAAC,MAAM,EAAE,yBAAyB,IAAI,CAAC,CACjD,CAAA;QAED,MAAM,OAAO,GAAG,cAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAA;QACtE,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,wEAAwE,KAAK,GAAG,CACjF,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"ship-item.d.ts","sourceRoot":"","sources":["../../../src/utils/actions/ship-item.ts"],"names":[],"mappings":""}
|
@@ -1,27 +1,23 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const utils_1 = require("@medusajs/utils");
|
4
|
-
const action_key_1 = require("../action-key");
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
5
4
|
const calculate_order_change_1 = require("../calculate-order-change");
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
const set_action_reference_1 = require("../set-action-reference");
|
6
|
+
calculate_order_change_1.OrderChangeProcessing.registerActionType(utils_1.ChangeActionType.SHIP_ITEM, {
|
7
|
+
operation({ action, currentOrder, options }) {
|
9
8
|
const existing = currentOrder.items.find((item) => item.id === action.details.reference_id);
|
10
|
-
|
9
|
+
existing.detail.shipped_quantity ??= 0;
|
11
10
|
existing.detail.shipped_quantity = utils_1.MathBN.add(existing.detail.shipped_quantity, action.details.quantity);
|
12
|
-
|
13
|
-
revert({ action, currentOrder }) {
|
14
|
-
const existing = currentOrder.items.find((item) => item.id === action.reference_id);
|
15
|
-
existing.detail.shipped_quantity = utils_1.MathBN.sub(existing.detail.shipped_quantity, action.details.quantity);
|
11
|
+
(0, set_action_reference_1.setActionReference)(existing, action, options);
|
16
12
|
},
|
17
13
|
validate({ action, currentOrder }) {
|
18
14
|
const refId = action.details?.reference_id;
|
19
|
-
if (
|
15
|
+
if (refId == null) {
|
20
16
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Reference ID is required.");
|
21
17
|
}
|
22
18
|
const existing = currentOrder.items.find((item) => item.id === refId);
|
23
19
|
if (!existing) {
|
24
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `
|
20
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Item ID "${refId}" not found.`);
|
25
21
|
}
|
26
22
|
if (!action.details?.quantity) {
|
27
23
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Quantity to ship of item ${refId} is required.`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ship-item.js","sourceRoot":"","sources":["../../../src/utils/actions/ship-item.ts"],"names":[],"mappings":";;AAAA,
|
1
|
+
{"version":3,"file":"ship-item.js","sourceRoot":"","sources":["../../../src/utils/actions/ship-item.ts"],"names":[],"mappings":";;AAAA,qDAIkC;AAClC,sEAAiE;AACjE,kEAA4D;AAE5D,8CAAqB,CAAC,kBAAkB,CAAC,wBAAgB,CAAC,SAAS,EAAE;IACnE,SAAS,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE;QACzC,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CACtC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,YAAY,CACjD,CAAA;QAEF,QAAQ,CAAC,MAAM,CAAC,gBAAgB,KAAK,CAAC,CAAA;QAEtC,QAA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nC,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAClC,CAAA;QAED,MAAM,OAAO,GAAG,cAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAA;QAC/D,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,2DAA2D,KAAK,GAAG,CACpE,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"shipping-add.d.ts","sourceRoot":"","sources":["../../../src/utils/actions/shipping-add.ts"],"names":[],"mappings":""}
|
@@ -1,33 +1,33 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const utils_1 = require("@medusajs/utils");
|
4
|
-
const action_key_1 = require("../action-key");
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
5
4
|
const calculate_order_change_1 = require("../calculate-order-change");
|
6
|
-
|
7
|
-
|
5
|
+
const set_action_reference_1 = require("../set-action-reference");
|
6
|
+
calculate_order_change_1.OrderChangeProcessing.registerActionType(utils_1.ChangeActionType.SHIPPING_ADD, {
|
7
|
+
operation({ action, currentOrder, options }) {
|
8
8
|
const shipping = Array.isArray(currentOrder.shipping_methods)
|
9
9
|
? currentOrder.shipping_methods
|
10
10
|
: [currentOrder.shipping_methods];
|
11
|
-
shipping.
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
if (existingIndex > -1) {
|
23
|
-
shipping.splice(existingIndex, 1);
|
11
|
+
let existing = shipping.find((sh) => sh.id === action.reference_id);
|
12
|
+
if (!existing) {
|
13
|
+
existing = {
|
14
|
+
id: action.reference_id,
|
15
|
+
order_id: currentOrder.id,
|
16
|
+
return_id: action.return_id,
|
17
|
+
claim_id: action.claim_id,
|
18
|
+
exchange_id: action.exchange_id,
|
19
|
+
amount: action.amount,
|
20
|
+
};
|
21
|
+
shipping.push(existing);
|
24
22
|
}
|
23
|
+
(0, set_action_reference_1.setActionReference)(existing, action, options);
|
24
|
+
currentOrder.shipping_methods = shipping;
|
25
25
|
},
|
26
26
|
validate({ action }) {
|
27
27
|
if (!action.reference_id) {
|
28
28
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Reference ID is required.");
|
29
29
|
}
|
30
|
-
if (
|
30
|
+
if (action.amount == null) {
|
31
31
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Amount is required.");
|
32
32
|
}
|
33
33
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"shipping-add.js","sourceRoot":"","sources":["../../../src/utils/actions/shipping-add.ts"],"names":[],"mappings":";;AAAA,
|
1
|
+
{"version":3,"file":"shipping-add.js","sourceRoot":"","sources":["../../../src/utils/actions/shipping-add.ts"],"names":[],"mappings":";;AAAA,qDAAyE;AACzE,sEAAiE;AACjE,kEAA4D;AAE5D,8CAAqB,CAAC,kBAAkB,CAAC,wBAAgB,CAAC,YAAY,EAAE;IACtE,SAAS,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE;QACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC;YAC3D,CAAC,CAAC,YAAY,CAAC,gBAAgB;YAC/B,CAAC,CAAC,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAA;QAEnC,IAAI,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,MAAM,CAAC,YAAY,CAAC,CAAA;QAEnE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG;gBACT,EAAE,EAAE,MAAM,CAAC,YAAa;gBACxB,QAAQ,EAAE,YAAY,CAAC,EAAE;gBACzB,SAAS,EAAE,MAAM,CAAC,SAAS;gBAC3B,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,WAAW,EAAE,MAAM,CAAC,WAAW;gBAC/B,MAAM,EAAE,MAAM,CAAC,MAAgB;aAChC,CAAA;YACD,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACzB,CAAC;QAED,IAAA,yCAAkB,EAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;QAC7C,YAAY,CAAC,gBAAgB,GAAG,QAAQ,CAAA;IAC1C,CAAC;IACD,QAAQ,CAAC,EAAE,MAAM,EAAE;QACjB,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;YACzB,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,2BAA2B,CAC5B,CAAA;QACH,CAAC;QAED,IAAI,MAAM,CAAC,MAAM,IAAI,IAAI,EAAE,CAAC;YAC1B,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,qBAAqB,CACtB,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"shipping-remove.d.ts","sourceRoot":"","sources":["../../../src/utils/actions/shipping-remove.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
4
|
+
const calculate_order_change_1 = require("../calculate-order-change");
|
5
|
+
calculate_order_change_1.OrderChangeProcessing.registerActionType(utils_1.ChangeActionType.SHIPPING_REMOVE, {
|
6
|
+
operation({ action, currentOrder, options }) {
|
7
|
+
const shipping = Array.isArray(currentOrder.shipping_methods)
|
8
|
+
? currentOrder.shipping_methods
|
9
|
+
: [currentOrder.shipping_methods];
|
10
|
+
const existingIndex = shipping.findIndex((item) => item.id === action.reference_id);
|
11
|
+
if (existingIndex > -1) {
|
12
|
+
shipping.splice(existingIndex, 1);
|
13
|
+
}
|
14
|
+
currentOrder.shipping_methods = shipping;
|
15
|
+
},
|
16
|
+
validate({ action }) {
|
17
|
+
if (!action.reference_id) {
|
18
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Reference ID is required.");
|
19
|
+
}
|
20
|
+
},
|
21
|
+
});
|
22
|
+
//# sourceMappingURL=shipping-remove.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"shipping-remove.js","sourceRoot":"","sources":["../../../src/utils/actions/shipping-remove.ts"],"names":[],"mappings":";;AAAA,qDAAyE;AACzE,sEAAiE;AAEjE,8CAAqB,CAAC,kBAAkB,CAAC,wBAAgB,CAAC,eAAe,EAAE;IACzE,SAAS,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE;QACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,gBAAgB,CAAC;YAC3D,CAAC,CAAC,YAAY,CAAC,gBAAgB;YAC/B,CAAC,CAAC,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAA;QAEnC,MAAM,aAAa,GAAG,QAAQ,CAAC,SAAS,CACtC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,YAAY,CAC1C,CAAA;QAED,IAAI,aAAa,GAAG,CAAC,CAAC,EAAE,CAAC;YACvB,QAAQ,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC,CAAA;QACnC,CAAC;QAED,YAAY,CAAC,gBAAgB,GAAG,QAAQ,CAAA;IAC1C,CAAC;IACD,QAAQ,CAAC,EAAE,MAAM,EAAE;QACjB,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;YACzB,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,2BAA2B,CAC5B,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"write-off-item.d.ts","sourceRoot":"","sources":["../../../src/utils/actions/write-off-item.ts"],"names":[],"mappings":""}
|
@@ -1,27 +1,23 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const utils_1 = require("@medusajs/utils");
|
4
|
-
const action_key_1 = require("../action-key");
|
3
|
+
const utils_1 = require("@medusajs/framework/utils");
|
5
4
|
const calculate_order_change_1 = require("../calculate-order-change");
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
const set_action_reference_1 = require("../set-action-reference");
|
6
|
+
calculate_order_change_1.OrderChangeProcessing.registerActionType(utils_1.ChangeActionType.WRITE_OFF_ITEM, {
|
7
|
+
operation({ action, currentOrder, options }) {
|
9
8
|
const existing = currentOrder.items.find((item) => item.id === action.details.reference_id);
|
10
|
-
|
9
|
+
existing.detail.written_off_quantity ??= 0;
|
11
10
|
existing.detail.written_off_quantity = utils_1.MathBN.add(existing.detail.written_off_quantity, action.details.quantity);
|
12
|
-
|
13
|
-
revert({ action, currentOrder }) {
|
14
|
-
const existing = currentOrder.items.find((item) => item.id === action.details.reference_id);
|
15
|
-
existing.detail.written_off_quantity = utils_1.MathBN.sub(existing.detail.written_off_quantity, action.details.quantity);
|
11
|
+
(0, set_action_reference_1.setActionReference)(existing, action, options);
|
16
12
|
},
|
17
13
|
validate({ action, currentOrder }) {
|
18
14
|
const refId = action.details?.reference_id;
|
19
|
-
if (
|
15
|
+
if (refId == null) {
|
20
16
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Details reference ID is required.");
|
21
17
|
}
|
22
18
|
const existing = currentOrder.items.find((item) => item.id === refId);
|
23
19
|
if (!existing) {
|
24
|
-
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `
|
20
|
+
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Item ID "${refId}" not found.`);
|
25
21
|
}
|
26
22
|
if (!action.details?.quantity) {
|
27
23
|
throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Quantity to write-off item ${refId} is required.`);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"write-off-item.js","sourceRoot":"","sources":["../../../src/utils/actions/write-off-item.ts"],"names":[],"mappings":";;AAAA,
|
1
|
+
{"version":3,"file":"write-off-item.js","sourceRoot":"","sources":["../../../src/utils/actions/write-off-item.ts"],"names":[],"mappings":";;AAAA,qDAIkC;AAClC,sEAAiE;AACjE,kEAA4D;AAE5D,8CAAqB,CAAC,kBAAkB,CAAC,wBAAgB,CAAC,cAAc,EAAE;IACxE,SAAS,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE;QACzC,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CACtC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,MAAM,CAAC,OAAO,CAAC,YAAY,CACjD,CAAA;QAEF,QAAQ,CAAC,MAAM,CAAC,oBAAoB,KAAK,CAAC,CAAA;QAC1C,QAAQ,CAAC,MAAM,CAAC,oBAAoB,GAAG,cAAM,CAAC,GAAG,CAC/C,QAAQ,CAAC,MAAM,CAAC,oBAAoB,EACpC,MAAM,CAAC,OAAO,CAAC,QAAQ,CACxB,CAAA;QAED,IAAA,yCAAkB,EAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/C,CAAC;IACD,QAAQ,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE;QAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,EAAE,YAAY,CAAA;QAC1C,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;YAClB,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,mCAAmC,CACpC,CAAA;QACH,CAAC;QAED,MAAM,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,KAAK,CAAC,CAAA;QAErE,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,YAAY,KAAK,cAAc,CAChC,CAAA;QACH,CAAC;QAED,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,CAAC;YAC9B,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,8BAA8B,KAAK,eAAe,CACnD,CAAA;QACH,CAAC;QAED,MAAM,iBAAiB,GAAG,QAAS,CAAC,QAAQ,IAAI,CAAC,CAAA;QACjD,MAAM,OAAO,GAAG,cAAM,CAAC,EAAE,CAAC,MAAM,CAAC,OAAO,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAA;QACtE,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,gDAAgD,CACjD,CAAA;QACH,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
import { OrderChangeActionDTO } from "@medusajs/framework/types";
|
2
|
+
import { OrderItem, OrderShippingMethod } from "../models";
|
3
|
+
export interface ApplyOrderChangeDTO extends OrderChangeActionDTO {
|
4
|
+
id: string;
|
5
|
+
order_id: string;
|
6
|
+
version: number;
|
7
|
+
applied: boolean;
|
8
|
+
}
|
9
|
+
export declare function applyChangesToOrder(orders: any[], actionsMap: Record<string, any[]>, options?: {
|
10
|
+
addActionReferenceToObject?: boolean;
|
11
|
+
}): {
|
12
|
+
itemsToUpsert: OrderItem[];
|
13
|
+
shippingMethodsToUpsert: OrderShippingMethod[];
|
14
|
+
summariesToUpsert: any[];
|
15
|
+
orderToUpdate: any[];
|
16
|
+
calculatedOrders: {};
|
17
|
+
};
|
18
|
+
//# sourceMappingURL=apply-order-changes.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"apply-order-changes.d.ts","sourceRoot":"","sources":["../../src/utils/apply-order-changes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAA;AAOhE,OAAO,EAAE,SAAS,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAGxD,MAAM,WAAW,mBAAoB,SAAQ,oBAAoB;IAC/D,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,GAAG,EAAE,EACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,CAAC,EACjC,OAAO,CAAC,EAAE;IACR,0BAA0B,CAAC,EAAE,OAAO,CAAA;CACrC;;;;;;EA4GF"}
|