@medusajs/medusa 1.7.2 → 1.7.3-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-test.log +0 -75
- package/CHANGELOG.md +50 -0
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/middlewares/check-registered-modules.d.ts +4 -0
- package/dist/api/middlewares/check-registered-modules.js +78 -0
- package/dist/api/middlewares/check-registered-modules.js.map +1 -0
- package/dist/api/routes/admin/discounts/add-resources-to-condition-batch.d.ts +1 -1
- package/dist/api/routes/admin/discounts/add-resources-to-condition-batch.js +1 -1
- package/dist/api/routes/admin/discounts/delete-resources-from-condition-batch.d.ts +1 -1
- package/dist/api/routes/admin/discounts/delete-resources-from-condition-batch.js +1 -1
- package/dist/api/routes/admin/discounts/list-discounts.d.ts +1 -1
- package/dist/api/routes/admin/index.js +4 -0
- package/dist/api/routes/admin/index.js.map +1 -1
- package/dist/api/routes/admin/order-edits/add-line-item.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/add-line-item.js +1 -1
- package/dist/api/routes/admin/order-edits/delete-line-item.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/delete-line-item.js +1 -1
- package/dist/api/routes/admin/order-edits/delete-order-edit-item-change.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/delete-order-edit-item-change.js +1 -1
- package/dist/api/routes/admin/order-edits/delete-order-edit.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/delete-order-edit.js +1 -1
- package/dist/api/routes/admin/order-edits/get-order-edit.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/get-order-edit.js +1 -1
- package/dist/api/routes/admin/order-edits/list-order-edit.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/request-confirmation.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/request-confirmation.js +1 -1
- package/dist/api/routes/admin/order-edits/update-order-edit-line-item.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/update-order-edit-line-item.js +1 -1
- package/dist/api/routes/admin/order-edits/update-order-edit.d.ts +1 -1
- package/dist/api/routes/admin/order-edits/update-order-edit.js +1 -1
- package/dist/api/routes/admin/orders/cancel-fulfillment.d.ts +5 -0
- package/dist/api/routes/admin/orders/cancel-fulfillment.js +46 -2
- package/dist/api/routes/admin/orders/cancel-fulfillment.js.map +1 -1
- package/dist/api/routes/admin/orders/create-fulfillment.d.ts +1 -0
- package/dist/api/routes/admin/orders/create-fulfillment.js +87 -5
- package/dist/api/routes/admin/orders/create-fulfillment.js.map +1 -1
- package/dist/api/routes/admin/orders/index.js +3 -7
- package/dist/api/routes/admin/orders/index.js.map +1 -1
- package/dist/api/routes/admin/payment-collections/delete-payment-collection.d.ts +1 -1
- package/dist/api/routes/admin/payment-collections/delete-payment-collection.js +1 -1
- package/dist/api/routes/admin/payment-collections/get-payment-collection.d.ts +1 -1
- package/dist/api/routes/admin/payment-collections/get-payment-collection.js +1 -1
- package/dist/api/routes/admin/payment-collections/mark-authorized-payment-collection.d.ts +1 -1
- package/dist/api/routes/admin/payment-collections/mark-authorized-payment-collection.js +1 -1
- package/dist/api/routes/admin/payment-collections/update-payment-collection.d.ts +1 -1
- package/dist/api/routes/admin/payment-collections/update-payment-collection.js +1 -1
- package/dist/api/routes/admin/price-lists/list-price-list-products.d.ts +2 -2
- package/dist/api/routes/admin/price-lists/list-price-list-products.js +1 -1
- package/dist/api/routes/admin/product-categories/delete-product-category.d.ts +64 -0
- package/dist/api/routes/admin/product-categories/delete-product-category.js +129 -0
- package/dist/api/routes/admin/product-categories/delete-product-category.js.map +1 -0
- package/dist/api/routes/admin/product-categories/get-product-category.d.ts +58 -0
- package/dist/api/routes/admin/product-categories/get-product-category.js +134 -0
- package/dist/api/routes/admin/product-categories/get-product-category.js.map +1 -0
- package/dist/api/routes/admin/product-categories/index.d.ts +7 -0
- package/dist/api/routes/admin/product-categories/index.js +68 -0
- package/dist/api/routes/admin/product-categories/index.js.map +1 -0
- package/dist/api/routes/admin/product-categories/list-product-categories.d.ts +78 -0
- package/dist/api/routes/admin/product-categories/list-product-categories.js +206 -0
- package/dist/api/routes/admin/product-categories/list-product-categories.js.map +1 -0
- package/dist/api/routes/admin/publishable-api-keys/add-channels-batch.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/add-channels-batch.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/create-publishable-api-key.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/create-publishable-api-key.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/delete-channels-batch.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/delete-channels-batch.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/delete-publishable-api-key.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/delete-publishable-api-key.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/get-publishable-api-key.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/get-publishable-api-key.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/list-publishable-api-key-sales-channels.d.ts +2 -2
- package/dist/api/routes/admin/publishable-api-keys/list-publishable-api-key-sales-channels.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/list-publishable-api-keys.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/revoke-publishable-api-key.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/revoke-publishable-api-key.js +1 -1
- package/dist/api/routes/admin/publishable-api-keys/update-publishable-api-key.d.ts +1 -1
- package/dist/api/routes/admin/publishable-api-keys/update-publishable-api-key.js +1 -1
- package/dist/api/routes/admin/returns/cancel-return.js.map +1 -1
- package/dist/api/routes/admin/returns/receive-return.d.ts +1 -0
- package/dist/api/routes/admin/returns/receive-return.js +8 -1
- package/dist/api/routes/admin/returns/receive-return.js.map +1 -1
- package/dist/api/routes/admin/sales-channels/associate-stock-location.d.ts +79 -0
- package/dist/api/routes/admin/sales-channels/associate-stock-location.js +163 -0
- package/dist/api/routes/admin/sales-channels/associate-stock-location.js.map +1 -0
- package/dist/api/routes/admin/sales-channels/index.d.ts +2 -0
- package/dist/api/routes/admin/sales-channels/index.js +6 -0
- package/dist/api/routes/admin/sales-channels/index.js.map +1 -1
- package/dist/api/routes/admin/sales-channels/list-sales-channels.d.ts +1 -1
- package/dist/api/routes/admin/sales-channels/remove-stock-location.d.ts +88 -0
- package/dist/api/routes/admin/sales-channels/remove-stock-location.js +174 -0
- package/dist/api/routes/admin/sales-channels/remove-stock-location.js.map +1 -0
- package/dist/api/routes/admin/stock-locations/create-stock-location.d.ts +105 -0
- package/dist/api/routes/admin/stock-locations/create-stock-location.js +240 -0
- package/dist/api/routes/admin/stock-locations/create-stock-location.js.map +1 -0
- package/dist/api/routes/admin/stock-locations/get-stock-location.d.ts +48 -0
- package/dist/api/routes/admin/stock-locations/get-stock-location.js +121 -0
- package/dist/api/routes/admin/stock-locations/get-stock-location.js.map +1 -0
- package/dist/api/routes/admin/stock-locations/index.d.ts +18 -0
- package/dist/api/routes/admin/stock-locations/index.js +78 -0
- package/dist/api/routes/admin/stock-locations/index.js.map +1 -0
- package/dist/api/routes/admin/stock-locations/list-stock-locations.d.ts +144 -0
- package/dist/api/routes/admin/stock-locations/list-stock-locations.js +265 -0
- package/dist/api/routes/admin/stock-locations/list-stock-locations.js.map +1 -0
- package/dist/api/routes/admin/stock-locations/update-stock-location.d.ts +103 -0
- package/dist/api/routes/admin/stock-locations/update-stock-location.js +240 -0
- package/dist/api/routes/admin/stock-locations/update-stock-location.js.map +1 -0
- package/dist/api/routes/admin/uploads/create-protected-upload.d.ts +2 -2
- package/dist/api/routes/admin/uploads/create-protected-upload.js +2 -2
- package/dist/api/routes/admin/uploads/delete-upload.d.ts +1 -1
- package/dist/api/routes/admin/uploads/delete-upload.js +1 -1
- package/dist/api/routes/admin/uploads/get-download-url.d.ts +1 -1
- package/dist/api/routes/admin/uploads/get-download-url.js +1 -1
- package/dist/api/routes/store/order-edits/complete-order-edit.js +35 -34
- package/dist/api/routes/store/order-edits/complete-order-edit.js.map +1 -1
- package/dist/api/routes/store/orders/confirm-order-request.d.ts +2 -2
- package/dist/api/routes/store/orders/confirm-order-request.js +2 -2
- package/dist/api/routes/store/orders/request-order.d.ts +1 -1
- package/dist/api/routes/store/orders/request-order.js +1 -1
- package/dist/api/routes/store/payment-collections/authorize-batch-payment-sessions.d.ts +2 -2
- package/dist/api/routes/store/payment-collections/authorize-batch-payment-sessions.js +2 -2
- package/dist/api/routes/store/payment-collections/authorize-payment-session.d.ts +2 -2
- package/dist/api/routes/store/payment-collections/authorize-payment-session.js +2 -2
- package/dist/api/routes/store/payment-collections/get-payment-collection.d.ts +2 -2
- package/dist/api/routes/store/payment-collections/get-payment-collection.js +2 -2
- package/dist/api/routes/store/payment-collections/manage-batch-payment-sessions.d.ts +2 -2
- package/dist/api/routes/store/payment-collections/manage-batch-payment-sessions.js +2 -2
- package/dist/api/routes/store/payment-collections/manage-payment-session.d.ts +2 -2
- package/dist/api/routes/store/payment-collections/manage-payment-session.js +2 -2
- package/dist/api/routes/store/payment-collections/refresh-payment-session.d.ts +1 -1
- package/dist/api/routes/store/payment-collections/refresh-payment-session.js +1 -1
- package/dist/commands/develop.js +24 -0
- package/dist/commands/develop.js.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces/payment-processor.d.ts +102 -0
- package/dist/interfaces/payment-processor.js +31 -0
- package/dist/interfaces/payment-processor.js.map +1 -0
- package/dist/interfaces/payment-service.d.ts +92 -1
- package/dist/interfaces/payment-service.js +10 -0
- package/dist/interfaces/payment-service.js.map +1 -1
- package/dist/interfaces/services/event-bus.d.ts +3 -0
- package/dist/interfaces/services/event-bus.js +3 -0
- package/dist/interfaces/services/event-bus.js.map +1 -0
- package/dist/interfaces/services/index.d.ts +3 -0
- package/dist/interfaces/services/index.js +3 -0
- package/dist/interfaces/services/index.js.map +1 -1
- package/dist/interfaces/services/inventory.d.ts +24 -0
- package/dist/interfaces/services/inventory.js +3 -0
- package/dist/interfaces/services/inventory.js.map +1 -0
- package/dist/interfaces/services/stock-location.d.ts +9 -0
- package/dist/interfaces/services/stock-location.js +3 -0
- package/dist/interfaces/services/stock-location.js.map +1 -0
- package/dist/loaders/feature-flags/product-categories.d.ts +3 -0
- package/dist/loaders/feature-flags/product-categories.js +10 -0
- package/dist/loaders/feature-flags/product-categories.js.map +1 -0
- package/dist/loaders/feature-flags/publishable-api-keys.js +1 -1
- package/dist/loaders/feature-flags/publishable-api-keys.js.map +1 -1
- package/dist/loaders/feature-flags/sales-channels.js +1 -1
- package/dist/loaders/feature-flags/sales-channels.js.map +1 -1
- package/dist/loaders/plugins.d.ts +1 -0
- package/dist/loaders/plugins.js +3 -1
- package/dist/loaders/plugins.js.map +1 -1
- package/dist/migrations/1671711415179-multi_location.d.ts +6 -0
- package/dist/migrations/1671711415179-multi_location.js +119 -0
- package/dist/migrations/1671711415179-multi_location.js.map +1 -0
- package/dist/migrations/1672906846559-product-category.d.ts +6 -0
- package/dist/migrations/1672906846559-product-category.js +83 -0
- package/dist/migrations/1672906846559-product-category.js.map +1 -0
- package/dist/migrations/1672906846560-payment-session-is-initiated.d.ts +6 -0
- package/dist/migrations/1672906846560-payment-session-is-initiated.js +81 -0
- package/dist/migrations/1672906846560-payment-session-is-initiated.js.map +1 -0
- package/dist/migrations/1673003729870-staged_job_options.d.ts +6 -0
- package/dist/migrations/1673003729870-staged_job_options.js +71 -0
- package/dist/migrations/1673003729870-staged_job_options.js.map +1 -0
- package/dist/models/fulfillment.d.ts +5 -0
- package/dist/models/fulfillment.js +8 -0
- package/dist/models/fulfillment.js.map +1 -1
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +4 -0
- package/dist/models/index.js.map +1 -1
- package/dist/models/line-item.d.ts +6 -6
- package/dist/models/line-item.js +9 -9
- package/dist/models/line-item.js.map +1 -1
- package/dist/models/payment-session.d.ts +6 -0
- package/dist/models/payment-session.js +9 -0
- package/dist/models/payment-session.js.map +1 -1
- package/dist/models/product-category.d.ts +67 -0
- package/dist/models/product-category.js +144 -0
- package/dist/models/product-category.js.map +1 -0
- package/dist/models/product-variant-inventory-item.d.ts +7 -0
- package/dist/models/product-variant-inventory-item.js +66 -0
- package/dist/models/product-variant-inventory-item.js.map +1 -0
- package/dist/models/return.d.ts +7 -6
- package/dist/models/return.js +14 -9
- package/dist/models/return.js.map +1 -1
- package/dist/models/sales-channel-location.d.ts +6 -0
- package/dist/models/sales-channel-location.js +62 -0
- package/dist/models/sales-channel-location.js.map +1 -0
- package/dist/models/staged-job.d.ts +1 -0
- package/dist/models/staged-job.js +4 -0
- package/dist/models/staged-job.js.map +1 -1
- package/dist/models/store.d.ts +6 -5
- package/dist/models/store.js +11 -7
- package/dist/models/store.js.map +1 -1
- package/dist/repositories/customer-group.js +18 -2
- package/dist/repositories/customer-group.js.map +1 -1
- package/dist/repositories/product-category.d.ts +6 -0
- package/dist/repositories/product-category.js +125 -0
- package/dist/repositories/product-category.js.map +1 -0
- package/dist/repositories/product-variant.js +30 -5
- package/dist/repositories/product-variant.js.map +1 -1
- package/dist/repositories/product.js +7 -2
- package/dist/repositories/product.js.map +1 -1
- package/dist/scripts/migrate-inventory-items.d.ts +1 -0
- package/dist/scripts/migrate-inventory-items.js +197 -0
- package/dist/scripts/migrate-inventory-items.js.map +1 -0
- package/dist/services/cache.js +2 -5
- package/dist/services/cache.js.map +1 -1
- package/dist/services/cart.d.ts +9 -26
- package/dist/services/cart.js +276 -182
- package/dist/services/cart.js.map +1 -1
- package/dist/services/claim-item.js +3 -0
- package/dist/services/claim-item.js.map +1 -1
- package/dist/services/claim.d.ts +4 -4
- package/dist/services/claim.js +132 -166
- package/dist/services/claim.js.map +1 -1
- package/dist/services/event-bus.d.ts +23 -10
- package/dist/services/event-bus.js +106 -42
- package/dist/services/event-bus.js.map +1 -1
- package/dist/services/fulfillment.d.ts +7 -3
- package/dist/services/fulfillment.js +79 -90
- package/dist/services/fulfillment.js.map +1 -1
- package/dist/services/index.d.ts +4 -1
- package/dist/services/index.js +10 -4
- package/dist/services/index.js.map +1 -1
- package/dist/services/line-item.d.ts +5 -5
- package/dist/services/line-item.js +2 -1
- package/dist/services/line-item.js.map +1 -1
- package/dist/services/order.d.ts +5 -19
- package/dist/services/order.js +146 -181
- package/dist/services/order.js.map +1 -1
- package/dist/services/payment-collection.d.ts +2 -2
- package/dist/services/payment-collection.js +88 -128
- package/dist/services/payment-collection.js.map +1 -1
- package/dist/services/payment-provider.d.ts +2 -1
- package/dist/services/payment-provider.js +32 -27
- package/dist/services/payment-provider.js.map +1 -1
- package/dist/services/product-category.d.ts +41 -0
- package/dist/services/product-category.js +190 -0
- package/dist/services/product-category.js.map +1 -0
- package/dist/services/product-variant-inventory.d.ts +115 -0
- package/dist/services/product-variant-inventory.js +747 -0
- package/dist/services/product-variant-inventory.js.map +1 -0
- package/dist/services/return.d.ts +7 -12
- package/dist/services/return.js +12 -9
- package/dist/services/return.js.map +1 -1
- package/dist/services/sales-channel-inventory.d.ts +24 -0
- package/dist/services/sales-channel-inventory.js +70 -0
- package/dist/services/sales-channel-inventory.js.map +1 -0
- package/dist/services/sales-channel-location.d.ts +41 -0
- package/dist/services/sales-channel-location.js +159 -0
- package/dist/services/sales-channel-location.js.map +1 -0
- package/dist/services/swap.d.ts +4 -4
- package/dist/services/swap.js +78 -127
- package/dist/services/swap.js.map +1 -1
- package/dist/services/totals.d.ts +2 -2
- package/dist/services/totals.js +2 -2
- package/dist/services/totals.js.map +1 -1
- package/dist/strategies/batch-jobs/product/import.d.ts +1 -1
- package/dist/strategies/batch-jobs/product/import.js +4 -3
- package/dist/strategies/batch-jobs/product/import.js.map +1 -1
- package/dist/strategies/cart-completion.d.ts +14 -9
- package/dist/strategies/cart-completion.js +111 -48
- package/dist/strategies/cart-completion.js.map +1 -1
- package/dist/subscribers/cart.d.ts +2 -4
- package/dist/subscribers/cart.js +8 -21
- package/dist/subscribers/cart.js.map +1 -1
- package/dist/subscribers/product.d.ts +1 -5
- package/dist/subscribers/product.js +15 -5
- package/dist/subscribers/product.js.map +1 -1
- package/dist/types/inventory.d.ts +106 -0
- package/dist/types/inventory.js +3 -0
- package/dist/types/inventory.js.map +1 -0
- package/dist/types/payment.d.ts +1 -0
- package/dist/types/product.d.ts +1 -0
- package/dist/types/product.js.map +1 -1
- package/dist/types/stock-location.d.ts +245 -0
- package/dist/types/stock-location.js +3 -0
- package/dist/types/stock-location.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/repository.d.ts +4 -3
- package/dist/utils/repository.js +43 -23
- package/dist/utils/repository.js.map +1 -1
- package/package.json +2 -2
- package/dist/services/inventory.d.ts +0 -31
- package/dist/services/inventory.js +0 -151
- package/dist/services/inventory.js.map +0 -1
|
@@ -0,0 +1,747 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
+
function step(op) {
|
|
42
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
+
while (_) try {
|
|
44
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
+
switch (op[0]) {
|
|
47
|
+
case 0: case 1: t = op; break;
|
|
48
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
+
default:
|
|
52
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
+
if (t[2]) _.ops.pop();
|
|
57
|
+
_.trys.pop(); continue;
|
|
58
|
+
}
|
|
59
|
+
op = body.call(thisArg, _);
|
|
60
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
65
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
66
|
+
if (!m) return o;
|
|
67
|
+
var i = m.call(o), r, ar = [], e;
|
|
68
|
+
try {
|
|
69
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
70
|
+
}
|
|
71
|
+
catch (error) { e = { error: error }; }
|
|
72
|
+
finally {
|
|
73
|
+
try {
|
|
74
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
75
|
+
}
|
|
76
|
+
finally { if (e) throw e.error; }
|
|
77
|
+
}
|
|
78
|
+
return ar;
|
|
79
|
+
};
|
|
80
|
+
var __values = (this && this.__values) || function(o) {
|
|
81
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
82
|
+
if (m) return m.call(o);
|
|
83
|
+
if (o && typeof o.length === "number") return {
|
|
84
|
+
next: function () {
|
|
85
|
+
if (o && i >= o.length) o = void 0;
|
|
86
|
+
return { value: o && o[i++], done: !o };
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
90
|
+
};
|
|
91
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
92
|
+
var medusa_core_utils_1 = require("medusa-core-utils");
|
|
93
|
+
var typeorm_1 = require("typeorm");
|
|
94
|
+
var interfaces_1 = require("../interfaces");
|
|
95
|
+
var product_variant_inventory_item_1 = require("../models/product-variant-inventory-item");
|
|
96
|
+
var ProductVariantInventoryService = /** @class */ (function (_super) {
|
|
97
|
+
__extends(ProductVariantInventoryService, _super);
|
|
98
|
+
function ProductVariantInventoryService(_a) {
|
|
99
|
+
var manager = _a.manager, stockLocationService = _a.stockLocationService, salesChannelLocationService = _a.salesChannelLocationService, productVariantService = _a.productVariantService, inventoryService = _a.inventoryService;
|
|
100
|
+
var _this =
|
|
101
|
+
// eslint-disable-next-line prefer-rest-params
|
|
102
|
+
_super.call(this, arguments[0]) || this;
|
|
103
|
+
_this.manager_ = manager;
|
|
104
|
+
_this.salesChannelLocationService_ = salesChannelLocationService;
|
|
105
|
+
_this.stockLocationService_ = stockLocationService;
|
|
106
|
+
_this.productVariantService_ = productVariantService;
|
|
107
|
+
_this.inventoryService_ = inventoryService;
|
|
108
|
+
return _this;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* confirms if requested inventory is available
|
|
112
|
+
* @param variantId id of the variant to confirm inventory for
|
|
113
|
+
* @param quantity quantity of inventory to confirm is available
|
|
114
|
+
* @param context optionally include a sales channel if applicable
|
|
115
|
+
* @returns boolean indicating if inventory is available
|
|
116
|
+
*/
|
|
117
|
+
ProductVariantInventoryService.prototype.confirmInventory = function (variantId, quantity, context) {
|
|
118
|
+
if (context === void 0) { context = {}; }
|
|
119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
+
var manager, productVariant, variantInventory, locations, stockLocations, hasInventory;
|
|
121
|
+
var _this = this;
|
|
122
|
+
return __generator(this, function (_a) {
|
|
123
|
+
switch (_a.label) {
|
|
124
|
+
case 0:
|
|
125
|
+
if (!variantId) {
|
|
126
|
+
return [2 /*return*/, true];
|
|
127
|
+
}
|
|
128
|
+
manager = this.transactionManager_ || this.manager_;
|
|
129
|
+
return [4 /*yield*/, this.productVariantService_
|
|
130
|
+
.withTransaction(manager)
|
|
131
|
+
.retrieve(variantId, {
|
|
132
|
+
select: [
|
|
133
|
+
"id",
|
|
134
|
+
"allow_backorder",
|
|
135
|
+
"manage_inventory",
|
|
136
|
+
"inventory_quantity",
|
|
137
|
+
],
|
|
138
|
+
})
|
|
139
|
+
// If the variant allows backorders or if inventory isn't managed we
|
|
140
|
+
// don't need to check inventory
|
|
141
|
+
];
|
|
142
|
+
case 1:
|
|
143
|
+
productVariant = _a.sent();
|
|
144
|
+
// If the variant allows backorders or if inventory isn't managed we
|
|
145
|
+
// don't need to check inventory
|
|
146
|
+
if (productVariant.allow_backorder || !productVariant.manage_inventory) {
|
|
147
|
+
return [2 /*return*/, true];
|
|
148
|
+
}
|
|
149
|
+
if (!this.inventoryService_) {
|
|
150
|
+
return [2 /*return*/, productVariant.inventory_quantity >= quantity];
|
|
151
|
+
}
|
|
152
|
+
return [4 /*yield*/, this.listByVariant(variantId)
|
|
153
|
+
// If there are no inventory items attached to the variant we default
|
|
154
|
+
// to true
|
|
155
|
+
];
|
|
156
|
+
case 2:
|
|
157
|
+
variantInventory = _a.sent();
|
|
158
|
+
// If there are no inventory items attached to the variant we default
|
|
159
|
+
// to true
|
|
160
|
+
if (variantInventory.length === 0) {
|
|
161
|
+
return [2 /*return*/, true];
|
|
162
|
+
}
|
|
163
|
+
locations = [];
|
|
164
|
+
if (!context.salesChannelId) return [3 /*break*/, 4];
|
|
165
|
+
return [4 /*yield*/, this.salesChannelLocationService_.listLocations(context.salesChannelId)];
|
|
166
|
+
case 3:
|
|
167
|
+
locations = _a.sent();
|
|
168
|
+
return [3 /*break*/, 6];
|
|
169
|
+
case 4: return [4 /*yield*/, this.stockLocationService_.list({}, { select: ["id"] })];
|
|
170
|
+
case 5:
|
|
171
|
+
stockLocations = _a.sent();
|
|
172
|
+
locations = stockLocations.map(function (l) { return l.id; });
|
|
173
|
+
_a.label = 6;
|
|
174
|
+
case 6: return [4 /*yield*/, Promise.all(variantInventory.map(function (inventoryPart) { return __awaiter(_this, void 0, void 0, function () {
|
|
175
|
+
var itemQuantity;
|
|
176
|
+
return __generator(this, function (_a) {
|
|
177
|
+
switch (_a.label) {
|
|
178
|
+
case 0:
|
|
179
|
+
itemQuantity = inventoryPart.quantity * quantity;
|
|
180
|
+
return [4 /*yield*/, this.inventoryService_.confirmInventory(inventoryPart.inventory_item_id, locations, itemQuantity)];
|
|
181
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}); }))];
|
|
185
|
+
case 7:
|
|
186
|
+
hasInventory = _a.sent();
|
|
187
|
+
return [2 /*return*/, hasInventory.every(Boolean)];
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Retrieves a product variant inventory item by its inventory item ID and variant ID.
|
|
194
|
+
*
|
|
195
|
+
* @param inventoryItemId - The ID of the inventory item to retrieve.
|
|
196
|
+
* @param variantId - The ID of the variant to retrieve.
|
|
197
|
+
* @returns A promise that resolves with the product variant inventory item.
|
|
198
|
+
*/
|
|
199
|
+
ProductVariantInventoryService.prototype.retrieve = function (inventoryItemId, variantId) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
201
|
+
var manager, variantInventoryRepo, variantInventory;
|
|
202
|
+
return __generator(this, function (_a) {
|
|
203
|
+
switch (_a.label) {
|
|
204
|
+
case 0:
|
|
205
|
+
manager = this.transactionManager_ || this.manager_;
|
|
206
|
+
variantInventoryRepo = manager.getRepository(product_variant_inventory_item_1.ProductVariantInventoryItem);
|
|
207
|
+
return [4 /*yield*/, variantInventoryRepo.findOne({
|
|
208
|
+
where: { inventory_item_id: inventoryItemId, variant_id: variantId },
|
|
209
|
+
})];
|
|
210
|
+
case 1:
|
|
211
|
+
variantInventory = _a.sent();
|
|
212
|
+
if (!variantInventory) {
|
|
213
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_FOUND, "Inventory item with id ".concat(inventoryItemId, " not found"));
|
|
214
|
+
}
|
|
215
|
+
return [2 /*return*/, variantInventory];
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* list registered inventory items
|
|
222
|
+
* @param itemIds list inventory item ids
|
|
223
|
+
* @returns list of inventory items
|
|
224
|
+
*/
|
|
225
|
+
ProductVariantInventoryService.prototype.listByItem = function (itemIds) {
|
|
226
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
227
|
+
var manager, variantInventoryRepo, variantInventory;
|
|
228
|
+
return __generator(this, function (_a) {
|
|
229
|
+
switch (_a.label) {
|
|
230
|
+
case 0:
|
|
231
|
+
manager = this.transactionManager_ || this.manager_;
|
|
232
|
+
variantInventoryRepo = manager.getRepository(product_variant_inventory_item_1.ProductVariantInventoryItem);
|
|
233
|
+
return [4 /*yield*/, variantInventoryRepo.find({
|
|
234
|
+
where: { inventory_item_id: (0, typeorm_1.In)(itemIds) },
|
|
235
|
+
})];
|
|
236
|
+
case 1:
|
|
237
|
+
variantInventory = _a.sent();
|
|
238
|
+
return [2 /*return*/, variantInventory];
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
/**
|
|
244
|
+
* List inventory items for a specific variant
|
|
245
|
+
* @param variantId variant id
|
|
246
|
+
* @returns variant inventory items for the variant id
|
|
247
|
+
*/
|
|
248
|
+
ProductVariantInventoryService.prototype.listByVariant = function (variantId) {
|
|
249
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
250
|
+
var manager, variantInventoryRepo, ids, variantInventory;
|
|
251
|
+
return __generator(this, function (_a) {
|
|
252
|
+
switch (_a.label) {
|
|
253
|
+
case 0:
|
|
254
|
+
manager = this.transactionManager_ || this.manager_;
|
|
255
|
+
variantInventoryRepo = manager.getRepository(product_variant_inventory_item_1.ProductVariantInventoryItem);
|
|
256
|
+
ids = Array.isArray(variantId) ? variantId : [variantId];
|
|
257
|
+
return [4 /*yield*/, variantInventoryRepo.find({
|
|
258
|
+
where: { variant_id: (0, typeorm_1.In)(ids) },
|
|
259
|
+
})];
|
|
260
|
+
case 1:
|
|
261
|
+
variantInventory = _a.sent();
|
|
262
|
+
return [2 /*return*/, variantInventory];
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* lists variant by inventory item id
|
|
269
|
+
* @param itemId item id
|
|
270
|
+
* @returns a list of product variants that are associated with the item id
|
|
271
|
+
*/
|
|
272
|
+
ProductVariantInventoryService.prototype.listVariantsByItem = function (itemId) {
|
|
273
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
274
|
+
var variantInventory, items;
|
|
275
|
+
return __generator(this, function (_a) {
|
|
276
|
+
switch (_a.label) {
|
|
277
|
+
case 0:
|
|
278
|
+
if (!this.inventoryService_) {
|
|
279
|
+
return [2 /*return*/, []];
|
|
280
|
+
}
|
|
281
|
+
return [4 /*yield*/, this.listByItem([itemId])];
|
|
282
|
+
case 1:
|
|
283
|
+
variantInventory = _a.sent();
|
|
284
|
+
return [4 /*yield*/, this.productVariantService_.list({
|
|
285
|
+
id: variantInventory.map(function (i) { return i.variant_id; }),
|
|
286
|
+
})];
|
|
287
|
+
case 2:
|
|
288
|
+
items = _a.sent();
|
|
289
|
+
return [2 /*return*/, items];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
};
|
|
294
|
+
/**
|
|
295
|
+
* lists inventory items for a given variant
|
|
296
|
+
* @param variantId variant id
|
|
297
|
+
* @returns lidt of inventory items for the variant
|
|
298
|
+
*/
|
|
299
|
+
ProductVariantInventoryService.prototype.listInventoryItemsByVariant = function (variantId) {
|
|
300
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
301
|
+
var variantInventory, _a, items;
|
|
302
|
+
return __generator(this, function (_b) {
|
|
303
|
+
switch (_b.label) {
|
|
304
|
+
case 0:
|
|
305
|
+
if (!this.inventoryService_) {
|
|
306
|
+
return [2 /*return*/, []];
|
|
307
|
+
}
|
|
308
|
+
return [4 /*yield*/, this.listByVariant(variantId)];
|
|
309
|
+
case 1:
|
|
310
|
+
variantInventory = _b.sent();
|
|
311
|
+
return [4 /*yield*/, this.inventoryService_.listInventoryItems({
|
|
312
|
+
id: variantInventory.map(function (i) { return i.inventory_item_id; }),
|
|
313
|
+
})];
|
|
314
|
+
case 2:
|
|
315
|
+
_a = __read.apply(void 0, [_b.sent(), 1]), items = _a[0];
|
|
316
|
+
return [2 /*return*/, items];
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Attach a variant to an inventory item
|
|
323
|
+
* @param variantId variant id
|
|
324
|
+
* @param inventoryItemId inventory item id
|
|
325
|
+
* @param quantity quantity of variant to attach
|
|
326
|
+
* @returns the variant inventory item
|
|
327
|
+
*/
|
|
328
|
+
ProductVariantInventoryService.prototype.attachInventoryItem = function (variantId, inventoryItemId, quantity) {
|
|
329
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
330
|
+
var manager, variantInventoryRepo, existing, quantityToStore, variantInventory;
|
|
331
|
+
return __generator(this, function (_a) {
|
|
332
|
+
switch (_a.label) {
|
|
333
|
+
case 0:
|
|
334
|
+
manager = this.transactionManager_ || this.manager_;
|
|
335
|
+
// Verify that variant exists
|
|
336
|
+
return [4 /*yield*/, this.productVariantService_
|
|
337
|
+
.withTransaction(manager)
|
|
338
|
+
.retrieve(variantId, {
|
|
339
|
+
select: ["id"],
|
|
340
|
+
})
|
|
341
|
+
// Verify that item exists
|
|
342
|
+
];
|
|
343
|
+
case 1:
|
|
344
|
+
// Verify that variant exists
|
|
345
|
+
_a.sent();
|
|
346
|
+
// Verify that item exists
|
|
347
|
+
return [4 /*yield*/, this.inventoryService_.retrieveInventoryItem(inventoryItemId, {
|
|
348
|
+
select: ["id"],
|
|
349
|
+
})];
|
|
350
|
+
case 2:
|
|
351
|
+
// Verify that item exists
|
|
352
|
+
_a.sent();
|
|
353
|
+
variantInventoryRepo = manager.getRepository(product_variant_inventory_item_1.ProductVariantInventoryItem);
|
|
354
|
+
return [4 /*yield*/, variantInventoryRepo.findOne({
|
|
355
|
+
where: {
|
|
356
|
+
variant_id: variantId,
|
|
357
|
+
inventory_item_id: inventoryItemId,
|
|
358
|
+
},
|
|
359
|
+
})];
|
|
360
|
+
case 3:
|
|
361
|
+
existing = _a.sent();
|
|
362
|
+
if (existing) {
|
|
363
|
+
return [2 /*return*/, existing];
|
|
364
|
+
}
|
|
365
|
+
quantityToStore = 1;
|
|
366
|
+
if (typeof quantity !== "undefined") {
|
|
367
|
+
if (quantity < 1) {
|
|
368
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Quantity must be greater than 0");
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
quantityToStore = quantity;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
variantInventory = variantInventoryRepo.create({
|
|
375
|
+
variant_id: variantId,
|
|
376
|
+
inventory_item_id: inventoryItemId,
|
|
377
|
+
quantity: quantityToStore,
|
|
378
|
+
});
|
|
379
|
+
return [4 /*yield*/, variantInventoryRepo.save(variantInventory)];
|
|
380
|
+
case 4: return [2 /*return*/, _a.sent()];
|
|
381
|
+
}
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
};
|
|
385
|
+
/**
|
|
386
|
+
* Remove a variant from an inventory item
|
|
387
|
+
* @param variantId variant id
|
|
388
|
+
* @param inventoryItemId inventory item id
|
|
389
|
+
*/
|
|
390
|
+
ProductVariantInventoryService.prototype.detachInventoryItem = function (variantId, inventoryItemId) {
|
|
391
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
392
|
+
var manager, variantInventoryRepo, existing;
|
|
393
|
+
return __generator(this, function (_a) {
|
|
394
|
+
switch (_a.label) {
|
|
395
|
+
case 0:
|
|
396
|
+
manager = this.transactionManager_ || this.manager_;
|
|
397
|
+
variantInventoryRepo = manager.getRepository(product_variant_inventory_item_1.ProductVariantInventoryItem);
|
|
398
|
+
return [4 /*yield*/, variantInventoryRepo.findOne({
|
|
399
|
+
where: {
|
|
400
|
+
variant_id: variantId,
|
|
401
|
+
inventory_item_id: inventoryItemId,
|
|
402
|
+
},
|
|
403
|
+
})];
|
|
404
|
+
case 1:
|
|
405
|
+
existing = _a.sent();
|
|
406
|
+
if (!existing) return [3 /*break*/, 3];
|
|
407
|
+
return [4 /*yield*/, variantInventoryRepo.remove(existing)];
|
|
408
|
+
case 2:
|
|
409
|
+
_a.sent();
|
|
410
|
+
_a.label = 3;
|
|
411
|
+
case 3: return [2 /*return*/];
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
});
|
|
415
|
+
};
|
|
416
|
+
/**
|
|
417
|
+
* Reserves a quantity of a variant
|
|
418
|
+
* @param variantId variant id
|
|
419
|
+
* @param quantity quantity to reserve
|
|
420
|
+
* @param context optional parameters
|
|
421
|
+
*/
|
|
422
|
+
ProductVariantInventoryService.prototype.reserveQuantity = function (variantId, quantity, context) {
|
|
423
|
+
if (context === void 0) { context = {}; }
|
|
424
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
425
|
+
var manager, toReserve, variantInventory, locationId, locations;
|
|
426
|
+
var _this = this;
|
|
427
|
+
return __generator(this, function (_a) {
|
|
428
|
+
switch (_a.label) {
|
|
429
|
+
case 0:
|
|
430
|
+
manager = this.transactionManager_ || this.manager_;
|
|
431
|
+
if (!this.inventoryService_) {
|
|
432
|
+
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
433
|
+
var variantServiceTx, variant;
|
|
434
|
+
return __generator(this, function (_a) {
|
|
435
|
+
switch (_a.label) {
|
|
436
|
+
case 0:
|
|
437
|
+
variantServiceTx = this.productVariantService_.withTransaction(manager);
|
|
438
|
+
return [4 /*yield*/, variantServiceTx.retrieve(variantId, {
|
|
439
|
+
select: ["id", "inventory_quantity"],
|
|
440
|
+
})];
|
|
441
|
+
case 1:
|
|
442
|
+
variant = _a.sent();
|
|
443
|
+
return [4 /*yield*/, variantServiceTx.update(variant.id, {
|
|
444
|
+
inventory_quantity: variant.inventory_quantity - quantity,
|
|
445
|
+
})];
|
|
446
|
+
case 2:
|
|
447
|
+
_a.sent();
|
|
448
|
+
return [2 /*return*/];
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
}); })];
|
|
452
|
+
}
|
|
453
|
+
toReserve = {
|
|
454
|
+
type: "order",
|
|
455
|
+
line_item_id: context.lineItemId,
|
|
456
|
+
};
|
|
457
|
+
return [4 /*yield*/, this.listByVariant(variantId)];
|
|
458
|
+
case 1:
|
|
459
|
+
variantInventory = _a.sent();
|
|
460
|
+
if (variantInventory.length === 0) {
|
|
461
|
+
return [2 /*return*/];
|
|
462
|
+
}
|
|
463
|
+
locationId = context.locationId;
|
|
464
|
+
if (!(!(0, medusa_core_utils_1.isDefined)(locationId) && context.salesChannelId)) return [3 /*break*/, 3];
|
|
465
|
+
return [4 /*yield*/, this.salesChannelLocationService_
|
|
466
|
+
.withTransaction(manager)
|
|
467
|
+
.listLocations(context.salesChannelId)];
|
|
468
|
+
case 2:
|
|
469
|
+
locations = _a.sent();
|
|
470
|
+
if (!locations.length) {
|
|
471
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.INVALID_DATA, "Must provide location_id or sales_channel_id to a Sales Channel that has associated Stock Locations");
|
|
472
|
+
}
|
|
473
|
+
locationId = locations[0];
|
|
474
|
+
_a.label = 3;
|
|
475
|
+
case 3: return [4 /*yield*/, Promise.all(variantInventory.map(function (inventoryPart) { return __awaiter(_this, void 0, void 0, function () {
|
|
476
|
+
var itemQuantity;
|
|
477
|
+
return __generator(this, function (_a) {
|
|
478
|
+
switch (_a.label) {
|
|
479
|
+
case 0:
|
|
480
|
+
itemQuantity = inventoryPart.quantity * quantity;
|
|
481
|
+
return [4 /*yield*/, this.inventoryService_.createReservationItem(__assign(__assign({}, toReserve), { location_id: locationId, inventory_item_id: inventoryPart.inventory_item_id, quantity: itemQuantity }))];
|
|
482
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
483
|
+
}
|
|
484
|
+
});
|
|
485
|
+
}); }))];
|
|
486
|
+
case 4:
|
|
487
|
+
_a.sent();
|
|
488
|
+
return [2 /*return*/];
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
});
|
|
492
|
+
};
|
|
493
|
+
/**
|
|
494
|
+
* Adjusts the quantity of reservations for a line item by a given amount.
|
|
495
|
+
* @param {string} lineItemId - The ID of the line item
|
|
496
|
+
* @param {string} variantId - The ID of the variant
|
|
497
|
+
* @param {string} locationId - The ID of the location to prefer adjusting quantities at
|
|
498
|
+
* @param {number} quantity - The amount to adjust the quantity by
|
|
499
|
+
*/
|
|
500
|
+
ProductVariantInventoryService.prototype.adjustReservationsQuantityByLineItem = function (lineItemId, variantId, locationId, quantity) {
|
|
501
|
+
var _a;
|
|
502
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
503
|
+
var _b, reservations, reservationCount, reservation, productVariantInventory, reservationQtyUpdate;
|
|
504
|
+
var _this = this;
|
|
505
|
+
return __generator(this, function (_c) {
|
|
506
|
+
switch (_c.label) {
|
|
507
|
+
case 0:
|
|
508
|
+
if (!this.inventoryService_) {
|
|
509
|
+
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
510
|
+
var variantServiceTx, variant;
|
|
511
|
+
return __generator(this, function (_a) {
|
|
512
|
+
switch (_a.label) {
|
|
513
|
+
case 0:
|
|
514
|
+
variantServiceTx = this.productVariantService_.withTransaction(manager);
|
|
515
|
+
return [4 /*yield*/, variantServiceTx.retrieve(variantId, {
|
|
516
|
+
select: ["id", "inventory_quantity", "manage_inventory"],
|
|
517
|
+
})];
|
|
518
|
+
case 1:
|
|
519
|
+
variant = _a.sent();
|
|
520
|
+
if (!variant.manage_inventory) {
|
|
521
|
+
return [2 /*return*/];
|
|
522
|
+
}
|
|
523
|
+
return [4 /*yield*/, variantServiceTx.update(variantId, {
|
|
524
|
+
inventory_quantity: variant.inventory_quantity - quantity,
|
|
525
|
+
})];
|
|
526
|
+
case 2:
|
|
527
|
+
_a.sent();
|
|
528
|
+
return [2 /*return*/];
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}); })];
|
|
532
|
+
}
|
|
533
|
+
return [4 /*yield*/, this.inventoryService_.listReservationItems({
|
|
534
|
+
line_item_id: lineItemId,
|
|
535
|
+
}, {
|
|
536
|
+
order: { created_at: "DESC" },
|
|
537
|
+
})];
|
|
538
|
+
case 1:
|
|
539
|
+
_b = __read.apply(void 0, [_c.sent(), 2]), reservations = _b[0], reservationCount = _b[1];
|
|
540
|
+
if (!reservationCount) return [3 /*break*/, 6];
|
|
541
|
+
reservation = reservations[0];
|
|
542
|
+
reservation =
|
|
543
|
+
(_a = reservations.find(function (r) { return r.location_id === locationId && r.quantity >= quantity; })) !== null && _a !== void 0 ? _a : reservation;
|
|
544
|
+
return [4 /*yield*/, this.retrieve(reservation.inventory_item_id, variantId)];
|
|
545
|
+
case 2:
|
|
546
|
+
productVariantInventory = _c.sent();
|
|
547
|
+
reservationQtyUpdate = reservation.quantity - quantity * productVariantInventory.quantity;
|
|
548
|
+
if (!(reservationQtyUpdate === 0)) return [3 /*break*/, 4];
|
|
549
|
+
return [4 /*yield*/, this.inventoryService_.deleteReservationItem(reservation.id)];
|
|
550
|
+
case 3:
|
|
551
|
+
_c.sent();
|
|
552
|
+
return [3 /*break*/, 6];
|
|
553
|
+
case 4: return [4 /*yield*/, this.inventoryService_.updateReservationItem(reservation.id, {
|
|
554
|
+
quantity: reservationQtyUpdate,
|
|
555
|
+
})];
|
|
556
|
+
case 5:
|
|
557
|
+
_c.sent();
|
|
558
|
+
_c.label = 6;
|
|
559
|
+
case 6: return [2 /*return*/];
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
});
|
|
563
|
+
};
|
|
564
|
+
/**
|
|
565
|
+
* Validate stock at a location for fulfillment items
|
|
566
|
+
* @param items Fulfillment Line items to validate quantities for
|
|
567
|
+
* @param locationId Location to validate stock at
|
|
568
|
+
* @returns nothing if successful, throws error if not
|
|
569
|
+
*/
|
|
570
|
+
ProductVariantInventoryService.prototype.validateInventoryAtLocation = function (items, locationId) {
|
|
571
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
572
|
+
var itemsToValidate, itemsToValidate_1, itemsToValidate_1_1, item, pvInventoryItems, _a, inventoryLevels, pviMap, inventoryLevels_1, inventoryLevels_1_1, inventoryLevel, pvInventoryItem, e_1_1;
|
|
573
|
+
var e_1, _b, e_2, _c;
|
|
574
|
+
return __generator(this, function (_d) {
|
|
575
|
+
switch (_d.label) {
|
|
576
|
+
case 0:
|
|
577
|
+
if (!this.inventoryService_) {
|
|
578
|
+
return [2 /*return*/];
|
|
579
|
+
}
|
|
580
|
+
itemsToValidate = items.filter(function (item) { return item.variant_id; });
|
|
581
|
+
_d.label = 1;
|
|
582
|
+
case 1:
|
|
583
|
+
_d.trys.push([1, 7, 8, 9]);
|
|
584
|
+
itemsToValidate_1 = __values(itemsToValidate), itemsToValidate_1_1 = itemsToValidate_1.next();
|
|
585
|
+
_d.label = 2;
|
|
586
|
+
case 2:
|
|
587
|
+
if (!!itemsToValidate_1_1.done) return [3 /*break*/, 6];
|
|
588
|
+
item = itemsToValidate_1_1.value;
|
|
589
|
+
return [4 /*yield*/, this.listByVariant(item.variant_id)];
|
|
590
|
+
case 3:
|
|
591
|
+
pvInventoryItems = _d.sent();
|
|
592
|
+
return [4 /*yield*/, this.inventoryService_.listInventoryLevels({
|
|
593
|
+
inventory_item_id: pvInventoryItems.map(function (i) { return i.inventory_item_id; }),
|
|
594
|
+
location_id: locationId,
|
|
595
|
+
})];
|
|
596
|
+
case 4:
|
|
597
|
+
_a = __read.apply(void 0, [_d.sent(), 1]), inventoryLevels = _a[0];
|
|
598
|
+
pviMap = new Map(pvInventoryItems.map(function (pvi) { return [pvi.inventory_item_id, pvi]; }));
|
|
599
|
+
try {
|
|
600
|
+
for (inventoryLevels_1 = (e_2 = void 0, __values(inventoryLevels)), inventoryLevels_1_1 = inventoryLevels_1.next(); !inventoryLevels_1_1.done; inventoryLevels_1_1 = inventoryLevels_1.next()) {
|
|
601
|
+
inventoryLevel = inventoryLevels_1_1.value;
|
|
602
|
+
pvInventoryItem = pviMap[inventoryLevel.inventory_item_id];
|
|
603
|
+
if (!pvInventoryItem ||
|
|
604
|
+
pvInventoryItem.quantity * item.quantity >
|
|
605
|
+
inventoryLevel.stocked_quantity) {
|
|
606
|
+
throw new medusa_core_utils_1.MedusaError(medusa_core_utils_1.MedusaError.Types.NOT_ALLOWED, "Insufficient stock for item: ".concat(item.title));
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
611
|
+
finally {
|
|
612
|
+
try {
|
|
613
|
+
if (inventoryLevels_1_1 && !inventoryLevels_1_1.done && (_c = inventoryLevels_1.return)) _c.call(inventoryLevels_1);
|
|
614
|
+
}
|
|
615
|
+
finally { if (e_2) throw e_2.error; }
|
|
616
|
+
}
|
|
617
|
+
_d.label = 5;
|
|
618
|
+
case 5:
|
|
619
|
+
itemsToValidate_1_1 = itemsToValidate_1.next();
|
|
620
|
+
return [3 /*break*/, 2];
|
|
621
|
+
case 6: return [3 /*break*/, 9];
|
|
622
|
+
case 7:
|
|
623
|
+
e_1_1 = _d.sent();
|
|
624
|
+
e_1 = { error: e_1_1 };
|
|
625
|
+
return [3 /*break*/, 9];
|
|
626
|
+
case 8:
|
|
627
|
+
try {
|
|
628
|
+
if (itemsToValidate_1_1 && !itemsToValidate_1_1.done && (_b = itemsToValidate_1.return)) _b.call(itemsToValidate_1);
|
|
629
|
+
}
|
|
630
|
+
finally { if (e_1) throw e_1.error; }
|
|
631
|
+
return [7 /*endfinally*/];
|
|
632
|
+
case 9: return [2 /*return*/];
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
});
|
|
636
|
+
};
|
|
637
|
+
/**
|
|
638
|
+
* delete a reservation of variant quantity
|
|
639
|
+
* @param lineItemId line item id
|
|
640
|
+
* @param variantId variant id
|
|
641
|
+
* @param quantity quantity to release
|
|
642
|
+
*/
|
|
643
|
+
ProductVariantInventoryService.prototype.deleteReservationsByLineItem = function (lineItemId, variantId, quantity) {
|
|
644
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
645
|
+
var _this = this;
|
|
646
|
+
return __generator(this, function (_a) {
|
|
647
|
+
switch (_a.label) {
|
|
648
|
+
case 0:
|
|
649
|
+
if (!this.inventoryService_) {
|
|
650
|
+
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
651
|
+
var productVariantServiceTx, variant;
|
|
652
|
+
return __generator(this, function (_a) {
|
|
653
|
+
switch (_a.label) {
|
|
654
|
+
case 0:
|
|
655
|
+
productVariantServiceTx = this.productVariantService_.withTransaction(manager);
|
|
656
|
+
return [4 /*yield*/, productVariantServiceTx.retrieve(variantId, {
|
|
657
|
+
select: ["id", "inventory_quantity", "manage_inventory"],
|
|
658
|
+
})];
|
|
659
|
+
case 1:
|
|
660
|
+
variant = _a.sent();
|
|
661
|
+
if (!variant.manage_inventory) {
|
|
662
|
+
return [2 /*return*/];
|
|
663
|
+
}
|
|
664
|
+
return [4 /*yield*/, productVariantServiceTx.update(variantId, {
|
|
665
|
+
inventory_quantity: variant.inventory_quantity + quantity,
|
|
666
|
+
})];
|
|
667
|
+
case 2:
|
|
668
|
+
_a.sent();
|
|
669
|
+
return [2 /*return*/];
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
}); })];
|
|
673
|
+
}
|
|
674
|
+
return [4 /*yield*/, this.inventoryService_.deleteReservationItemsByLineItem(lineItemId)];
|
|
675
|
+
case 1:
|
|
676
|
+
_a.sent();
|
|
677
|
+
return [2 /*return*/];
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
};
|
|
682
|
+
/**
|
|
683
|
+
* Adjusts inventory of a variant on a location
|
|
684
|
+
* @param variantId variant id
|
|
685
|
+
* @param locationId location id
|
|
686
|
+
* @param quantity quantity to adjust
|
|
687
|
+
*/
|
|
688
|
+
ProductVariantInventoryService.prototype.adjustInventory = function (variantId, locationId, quantity) {
|
|
689
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
690
|
+
var variantInventory;
|
|
691
|
+
var _this = this;
|
|
692
|
+
return __generator(this, function (_a) {
|
|
693
|
+
switch (_a.label) {
|
|
694
|
+
case 0:
|
|
695
|
+
if (!!this.inventoryService_) return [3 /*break*/, 1];
|
|
696
|
+
return [2 /*return*/, this.atomicPhase_(function (manager) { return __awaiter(_this, void 0, void 0, function () {
|
|
697
|
+
var productVariantServiceTx, variant;
|
|
698
|
+
return __generator(this, function (_a) {
|
|
699
|
+
switch (_a.label) {
|
|
700
|
+
case 0:
|
|
701
|
+
productVariantServiceTx = this.productVariantService_.withTransaction(manager);
|
|
702
|
+
return [4 /*yield*/, productVariantServiceTx.retrieve(variantId, {
|
|
703
|
+
select: ["id", "inventory_quantity", "manage_inventory"],
|
|
704
|
+
})];
|
|
705
|
+
case 1:
|
|
706
|
+
variant = _a.sent();
|
|
707
|
+
if (!variant.manage_inventory) {
|
|
708
|
+
return [2 /*return*/];
|
|
709
|
+
}
|
|
710
|
+
return [4 /*yield*/, productVariantServiceTx.update(variantId, {
|
|
711
|
+
inventory_quantity: variant.inventory_quantity + quantity,
|
|
712
|
+
})];
|
|
713
|
+
case 2:
|
|
714
|
+
_a.sent();
|
|
715
|
+
return [2 /*return*/];
|
|
716
|
+
}
|
|
717
|
+
});
|
|
718
|
+
}); })];
|
|
719
|
+
case 1: return [4 /*yield*/, this.listByVariant(variantId)];
|
|
720
|
+
case 2:
|
|
721
|
+
variantInventory = _a.sent();
|
|
722
|
+
if (variantInventory.length === 0) {
|
|
723
|
+
return [2 /*return*/];
|
|
724
|
+
}
|
|
725
|
+
return [4 /*yield*/, Promise.all(variantInventory.map(function (inventoryPart) { return __awaiter(_this, void 0, void 0, function () {
|
|
726
|
+
var itemQuantity;
|
|
727
|
+
return __generator(this, function (_a) {
|
|
728
|
+
switch (_a.label) {
|
|
729
|
+
case 0:
|
|
730
|
+
itemQuantity = inventoryPart.quantity * quantity;
|
|
731
|
+
return [4 /*yield*/, this.inventoryService_.adjustInventory(inventoryPart.inventory_item_id, locationId, itemQuantity)];
|
|
732
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
}); }))];
|
|
736
|
+
case 3:
|
|
737
|
+
_a.sent();
|
|
738
|
+
_a.label = 4;
|
|
739
|
+
case 4: return [2 /*return*/];
|
|
740
|
+
}
|
|
741
|
+
});
|
|
742
|
+
});
|
|
743
|
+
};
|
|
744
|
+
return ProductVariantInventoryService;
|
|
745
|
+
}(interfaces_1.TransactionBaseService));
|
|
746
|
+
exports.default = ProductVariantInventoryService;
|
|
747
|
+
//# sourceMappingURL=product-variant-inventory.js.map
|