@medusajs/core-flows 0.0.2-next-20231124140416

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.
Files changed (241) hide show
  1. package/dist/definition/cart/create-cart.d.ts +9 -0
  2. package/dist/definition/cart/create-cart.js +148 -0
  3. package/dist/definition/cart/create-cart.js.map +1 -0
  4. package/dist/definition/cart/index.d.ts +1 -0
  5. package/dist/definition/cart/index.js +18 -0
  6. package/dist/definition/cart/index.js.map +1 -0
  7. package/dist/definition/index.d.ts +4 -0
  8. package/dist/definition/index.js +21 -0
  9. package/dist/definition/index.js.map +1 -0
  10. package/dist/definition/inventory/create-inventory-item.d.ts +14 -0
  11. package/dist/definition/inventory/create-inventory-item.js +41 -0
  12. package/dist/definition/inventory/create-inventory-item.js.map +1 -0
  13. package/dist/definition/inventory/index.d.ts +1 -0
  14. package/dist/definition/inventory/index.js +18 -0
  15. package/dist/definition/inventory/index.js.map +1 -0
  16. package/dist/definition/price-list/create-price-lists.d.ts +13 -0
  17. package/dist/definition/price-list/create-price-lists.js +55 -0
  18. package/dist/definition/price-list/create-price-lists.js.map +1 -0
  19. package/dist/definition/price-list/index.d.ts +6 -0
  20. package/dist/definition/price-list/index.js +23 -0
  21. package/dist/definition/price-list/index.js.map +1 -0
  22. package/dist/definition/price-list/remove-price-list-prices.d.ts +11 -0
  23. package/dist/definition/price-list/remove-price-list-prices.js +50 -0
  24. package/dist/definition/price-list/remove-price-list-prices.js.map +1 -0
  25. package/dist/definition/price-list/remove-price-lists.d.ts +12 -0
  26. package/dist/definition/price-list/remove-price-lists.js +40 -0
  27. package/dist/definition/price-list/remove-price-lists.js.map +1 -0
  28. package/dist/definition/price-list/remove-product-prices.d.ts +11 -0
  29. package/dist/definition/price-list/remove-product-prices.js +51 -0
  30. package/dist/definition/price-list/remove-product-prices.js.map +1 -0
  31. package/dist/definition/price-list/remove-variant-prices.d.ts +11 -0
  32. package/dist/definition/price-list/remove-variant-prices.js +51 -0
  33. package/dist/definition/price-list/remove-variant-prices.js.map +1 -0
  34. package/dist/definition/price-list/update-price-lists.d.ts +13 -0
  35. package/dist/definition/price-list/update-price-lists.js +51 -0
  36. package/dist/definition/price-list/update-price-lists.js.map +1 -0
  37. package/dist/definition/product/create-product-variants.d.ts +15 -0
  38. package/dist/definition/product/create-product-variants.js +91 -0
  39. package/dist/definition/product/create-product-variants.js.map +1 -0
  40. package/dist/definition/product/create-products.d.ts +18 -0
  41. package/dist/definition/product/create-products.js +211 -0
  42. package/dist/definition/product/create-products.js.map +1 -0
  43. package/dist/definition/product/index.d.ts +4 -0
  44. package/dist/definition/product/index.js +34 -0
  45. package/dist/definition/product/index.js.map +1 -0
  46. package/dist/definition/product/prepare-create-inventory-items.d.ts +23 -0
  47. package/dist/definition/product/prepare-create-inventory-items.js +28 -0
  48. package/dist/definition/product/prepare-create-inventory-items.js.map +1 -0
  49. package/dist/definition/product/update-product-variants.d.ts +15 -0
  50. package/dist/definition/product/update-product-variants.js +81 -0
  51. package/dist/definition/product/update-product-variants.js.map +1 -0
  52. package/dist/definition/product/update-products.d.ts +19 -0
  53. package/dist/definition/product/update-products.js +328 -0
  54. package/dist/definition/product/update-products.js.map +1 -0
  55. package/dist/definitions.d.ts +27 -0
  56. package/dist/definitions.js +37 -0
  57. package/dist/definitions.js.map +1 -0
  58. package/dist/handlers/address/find-or-create-addresses.d.ts +24 -0
  59. package/dist/handlers/address/find-or-create-addresses.js +66 -0
  60. package/dist/handlers/address/find-or-create-addresses.js.map +1 -0
  61. package/dist/handlers/address/index.d.ts +1 -0
  62. package/dist/handlers/address/index.js +18 -0
  63. package/dist/handlers/address/index.js.map +1 -0
  64. package/dist/handlers/cart/attach-line-items-to-cart.d.ts +21 -0
  65. package/dist/handlers/cart/attach-line-items-to-cart.js +35 -0
  66. package/dist/handlers/cart/attach-line-items-to-cart.js.map +1 -0
  67. package/dist/handlers/cart/create-cart.d.ts +36 -0
  68. package/dist/handlers/cart/create-cart.js +27 -0
  69. package/dist/handlers/cart/create-cart.js.map +1 -0
  70. package/dist/handlers/cart/index.d.ts +4 -0
  71. package/dist/handlers/cart/index.js +21 -0
  72. package/dist/handlers/cart/index.js.map +1 -0
  73. package/dist/handlers/cart/remove-cart.d.ts +14 -0
  74. package/dist/handlers/cart/remove-cart.js +17 -0
  75. package/dist/handlers/cart/remove-cart.js.map +1 -0
  76. package/dist/handlers/cart/retrieve-cart.d.ts +22 -0
  77. package/dist/handlers/cart/retrieve-cart.js +18 -0
  78. package/dist/handlers/cart/retrieve-cart.js.map +1 -0
  79. package/dist/handlers/common/index.d.ts +1 -0
  80. package/dist/handlers/common/index.js +18 -0
  81. package/dist/handlers/common/index.js.map +1 -0
  82. package/dist/handlers/common/set-context.d.ts +17 -0
  83. package/dist/handlers/common/set-context.js +16 -0
  84. package/dist/handlers/common/set-context.js.map +1 -0
  85. package/dist/handlers/customer/find-or-create-customer.d.ts +19 -0
  86. package/dist/handlers/customer/find-or-create-customer.js +38 -0
  87. package/dist/handlers/customer/find-or-create-customer.js.map +1 -0
  88. package/dist/handlers/customer/index.d.ts +1 -0
  89. package/dist/handlers/customer/index.js +18 -0
  90. package/dist/handlers/customer/index.js.map +1 -0
  91. package/dist/handlers/index.d.ts +10 -0
  92. package/dist/handlers/index.js +37 -0
  93. package/dist/handlers/index.js.map +1 -0
  94. package/dist/handlers/inventory/attach-inventory-items.d.ts +16 -0
  95. package/dist/handlers/inventory/attach-inventory-items.js +23 -0
  96. package/dist/handlers/inventory/attach-inventory-items.js.map +1 -0
  97. package/dist/handlers/inventory/create-inventory-items.d.ts +17 -0
  98. package/dist/handlers/inventory/create-inventory-items.js +31 -0
  99. package/dist/handlers/inventory/create-inventory-items.js.map +1 -0
  100. package/dist/handlers/inventory/detach-inventory-items.d.ts +16 -0
  101. package/dist/handlers/inventory/detach-inventory-items.js +22 -0
  102. package/dist/handlers/inventory/detach-inventory-items.js.map +1 -0
  103. package/dist/handlers/inventory/index.d.ts +5 -0
  104. package/dist/handlers/inventory/index.js +22 -0
  105. package/dist/handlers/inventory/index.js.map +1 -0
  106. package/dist/handlers/inventory/remove-inventory-items.d.ts +14 -0
  107. package/dist/handlers/inventory/remove-inventory-items.js +18 -0
  108. package/dist/handlers/inventory/remove-inventory-items.js.map +1 -0
  109. package/dist/handlers/inventory/restore-inventory-items.d.ts +12 -0
  110. package/dist/handlers/inventory/restore-inventory-items.js +18 -0
  111. package/dist/handlers/inventory/restore-inventory-items.js.map +1 -0
  112. package/dist/handlers/middlewares/create-products-prepare-create-prices-compensation.d.ts +26 -0
  113. package/dist/handlers/middlewares/create-products-prepare-create-prices-compensation.js +31 -0
  114. package/dist/handlers/middlewares/create-products-prepare-create-prices-compensation.js.map +1 -0
  115. package/dist/handlers/middlewares/extract-variants.d.ts +18 -0
  116. package/dist/handlers/middlewares/extract-variants.js +23 -0
  117. package/dist/handlers/middlewares/extract-variants.js.map +1 -0
  118. package/dist/handlers/middlewares/index.d.ts +6 -0
  119. package/dist/handlers/middlewares/index.js +23 -0
  120. package/dist/handlers/middlewares/index.js.map +1 -0
  121. package/dist/handlers/middlewares/map-data.d.ts +11 -0
  122. package/dist/handlers/middlewares/map-data.js +19 -0
  123. package/dist/handlers/middlewares/map-data.js.map +1 -0
  124. package/dist/handlers/middlewares/update-products-extract-created-variants.d.ts +19 -0
  125. package/dist/handlers/middlewares/update-products-extract-created-variants.js +27 -0
  126. package/dist/handlers/middlewares/update-products-extract-created-variants.js.map +1 -0
  127. package/dist/handlers/middlewares/update-products-extract-deleted-variants.d.ts +19 -0
  128. package/dist/handlers/middlewares/update-products-extract-deleted-variants.js +29 -0
  129. package/dist/handlers/middlewares/update-products-extract-deleted-variants.js.map +1 -0
  130. package/dist/handlers/middlewares/use-variants-inventory-items.d.ts +24 -0
  131. package/dist/handlers/middlewares/use-variants-inventory-items.js +31 -0
  132. package/dist/handlers/middlewares/use-variants-inventory-items.js.map +1 -0
  133. package/dist/handlers/price-list/create-price-list.d.ts +18 -0
  134. package/dist/handlers/price-list/create-price-list.js +18 -0
  135. package/dist/handlers/price-list/create-price-list.js.map +1 -0
  136. package/dist/handlers/price-list/index.d.ts +10 -0
  137. package/dist/handlers/price-list/index.js +27 -0
  138. package/dist/handlers/price-list/index.js.map +1 -0
  139. package/dist/handlers/price-list/prepare-create-price-list.d.ts +17 -0
  140. package/dist/handlers/price-list/prepare-create-price-list.js +57 -0
  141. package/dist/handlers/price-list/prepare-create-price-list.js.map +1 -0
  142. package/dist/handlers/price-list/prepare-remove-price-list-prices.d.ts +15 -0
  143. package/dist/handlers/price-list/prepare-remove-price-list-prices.js +23 -0
  144. package/dist/handlers/price-list/prepare-remove-price-list-prices.js.map +1 -0
  145. package/dist/handlers/price-list/prepare-remove-product-prices.d.ts +10 -0
  146. package/dist/handlers/price-list/prepare-remove-product-prices.js +35 -0
  147. package/dist/handlers/price-list/prepare-remove-product-prices.js.map +1 -0
  148. package/dist/handlers/price-list/prepare-remove-variant-prices.d.ts +10 -0
  149. package/dist/handlers/price-list/prepare-remove-variant-prices.js +33 -0
  150. package/dist/handlers/price-list/prepare-remove-variant-prices.js.map +1 -0
  151. package/dist/handlers/price-list/prepare-update-price-lists.d.ts +15 -0
  152. package/dist/handlers/price-list/prepare-update-price-lists.js +58 -0
  153. package/dist/handlers/price-list/prepare-update-price-lists.js.map +1 -0
  154. package/dist/handlers/price-list/remove-price-list.d.ts +14 -0
  155. package/dist/handlers/price-list/remove-price-list.js +14 -0
  156. package/dist/handlers/price-list/remove-price-list.js.map +1 -0
  157. package/dist/handlers/price-list/remove-price-set-price-list-prices.d.ts +5 -0
  158. package/dist/handlers/price-list/remove-price-set-price-list-prices.js +25 -0
  159. package/dist/handlers/price-list/remove-price-set-price-list-prices.js.map +1 -0
  160. package/dist/handlers/price-list/remove-prices.d.ts +13 -0
  161. package/dist/handlers/price-list/remove-prices.js +17 -0
  162. package/dist/handlers/price-list/remove-prices.js.map +1 -0
  163. package/dist/handlers/price-list/update-price-lists.d.ts +15 -0
  164. package/dist/handlers/price-list/update-price-lists.js +38 -0
  165. package/dist/handlers/price-list/update-price-lists.js.map +1 -0
  166. package/dist/handlers/product/attach-sales-channel-to-products.d.ts +18 -0
  167. package/dist/handlers/product/attach-sales-channel-to-products.js +30 -0
  168. package/dist/handlers/product/attach-sales-channel-to-products.js.map +1 -0
  169. package/dist/handlers/product/attach-shipping-profile-to-products.d.ts +18 -0
  170. package/dist/handlers/product/attach-shipping-profile-to-products.js +28 -0
  171. package/dist/handlers/product/attach-shipping-profile-to-products.js.map +1 -0
  172. package/dist/handlers/product/create-product-variants-prepare-data.d.ts +21 -0
  173. package/dist/handlers/product/create-product-variants-prepare-data.js +35 -0
  174. package/dist/handlers/product/create-product-variants-prepare-data.js.map +1 -0
  175. package/dist/handlers/product/create-product-variants.d.ts +23 -0
  176. package/dist/handlers/product/create-product-variants.js +22 -0
  177. package/dist/handlers/product/create-product-variants.js.map +1 -0
  178. package/dist/handlers/product/create-products-prepare-data.d.ts +28 -0
  179. package/dist/handlers/product/create-products-prepare-data.js +77 -0
  180. package/dist/handlers/product/create-products-prepare-data.js.map +1 -0
  181. package/dist/handlers/product/create-products.d.ts +12 -0
  182. package/dist/handlers/product/create-products.js +14 -0
  183. package/dist/handlers/product/create-products.js.map +1 -0
  184. package/dist/handlers/product/detach-sales-channel-from-products.d.ts +18 -0
  185. package/dist/handlers/product/detach-sales-channel-from-products.js +30 -0
  186. package/dist/handlers/product/detach-sales-channel-from-products.js.map +1 -0
  187. package/dist/handlers/product/detach-shipping-profile-from-products.d.ts +18 -0
  188. package/dist/handlers/product/detach-shipping-profile-from-products.js +28 -0
  189. package/dist/handlers/product/detach-shipping-profile-from-products.js.map +1 -0
  190. package/dist/handlers/product/index.d.ts +19 -0
  191. package/dist/handlers/product/index.js +36 -0
  192. package/dist/handlers/product/index.js.map +1 -0
  193. package/dist/handlers/product/list-products.d.ts +13 -0
  194. package/dist/handlers/product/list-products.js +31 -0
  195. package/dist/handlers/product/list-products.js.map +1 -0
  196. package/dist/handlers/product/remove-product-variants.d.ts +13 -0
  197. package/dist/handlers/product/remove-product-variants.js +16 -0
  198. package/dist/handlers/product/remove-product-variants.js.map +1 -0
  199. package/dist/handlers/product/remove-products.d.ts +13 -0
  200. package/dist/handlers/product/remove-products.js +16 -0
  201. package/dist/handlers/product/remove-products.js.map +1 -0
  202. package/dist/handlers/product/revert-update-products.d.ts +14 -0
  203. package/dist/handlers/product/revert-update-products.js +20 -0
  204. package/dist/handlers/product/revert-update-products.js.map +1 -0
  205. package/dist/handlers/product/revert-variant-prices.d.ts +14 -0
  206. package/dist/handlers/product/revert-variant-prices.js +28 -0
  207. package/dist/handlers/product/revert-variant-prices.js.map +1 -0
  208. package/dist/handlers/product/update-product-variants-prepare-data.d.ts +21 -0
  209. package/dist/handlers/product/update-product-variants-prepare-data.js +48 -0
  210. package/dist/handlers/product/update-product-variants-prepare-data.js.map +1 -0
  211. package/dist/handlers/product/update-product-variants.d.ts +12 -0
  212. package/dist/handlers/product/update-product-variants.js +23 -0
  213. package/dist/handlers/product/update-product-variants.js.map +1 -0
  214. package/dist/handlers/product/update-products-prepare-data.d.ts +25 -0
  215. package/dist/handlers/product/update-products-prepare-data.js +65 -0
  216. package/dist/handlers/product/update-products-prepare-data.js.map +1 -0
  217. package/dist/handlers/product/update-products-variants-prices.d.ts +18 -0
  218. package/dist/handlers/product/update-products-variants-prices.js +90 -0
  219. package/dist/handlers/product/update-products-variants-prices.js.map +1 -0
  220. package/dist/handlers/product/update-products.d.ts +12 -0
  221. package/dist/handlers/product/update-products.js +29 -0
  222. package/dist/handlers/product/update-products.js.map +1 -0
  223. package/dist/handlers/product/upsert-variant-prices.d.ts +25 -0
  224. package/dist/handlers/product/upsert-variant-prices.js +122 -0
  225. package/dist/handlers/product/upsert-variant-prices.js.map +1 -0
  226. package/dist/handlers/region/find-region.d.ts +17 -0
  227. package/dist/handlers/region/find-region.js +29 -0
  228. package/dist/handlers/region/find-region.js.map +1 -0
  229. package/dist/handlers/region/index.d.ts +1 -0
  230. package/dist/handlers/region/index.js +18 -0
  231. package/dist/handlers/region/index.js.map +1 -0
  232. package/dist/handlers/sales-channel/find-sales-channel.d.ts +20 -0
  233. package/dist/handlers/sales-channel/find-sales-channel.js +41 -0
  234. package/dist/handlers/sales-channel/find-sales-channel.js.map +1 -0
  235. package/dist/handlers/sales-channel/index.d.ts +1 -0
  236. package/dist/handlers/sales-channel/index.js +18 -0
  237. package/dist/handlers/sales-channel/index.js.map +1 -0
  238. package/dist/index.d.ts +3 -0
  239. package/dist/index.js +33 -0
  240. package/dist/index.js.map +1 -0
  241. package/package.json +42 -0
@@ -0,0 +1,25 @@
1
+ import { ProductDTO, SalesChannelDTO, WorkflowTypes } from "@medusajs/types";
2
+ import { WorkflowArguments } from "@medusajs/workflows-sdk";
3
+ type ProductWithSalesChannelsDTO = ProductDTO & {
4
+ sales_channels?: SalesChannelDTO[];
5
+ };
6
+ type VariantPrice = {
7
+ region_id?: string;
8
+ currency_code?: string;
9
+ amount: number;
10
+ min_quantity?: number;
11
+ max_quantity?: number;
12
+ };
13
+ export type UpdateProductsPreparedData = {
14
+ originalProducts: ProductWithSalesChannelsDTO[];
15
+ productHandleAddedChannelsMap: Map<string, string[]>;
16
+ productHandleRemovedChannelsMap: Map<string, string[]>;
17
+ variantPricesMap: Map<string, VariantPrice[]>;
18
+ };
19
+ export declare function updateProductsPrepareData({ container, context, data, }: WorkflowArguments<WorkflowTypes.ProductWorkflow.UpdateProductsWorkflowInputDTO>): Promise<UpdateProductsPreparedData>;
20
+ export declare namespace updateProductsPrepareData {
21
+ var aliases: {
22
+ preparedData: string;
23
+ };
24
+ }
25
+ export {};
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateProductsPrepareData = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ async function updateProductsPrepareData({ container, context, data, }) {
6
+ const featureFlagRouter = container.resolve("featureFlagRouter");
7
+ const isPricingDomainEnabled = featureFlagRouter.isFeatureEnabled(utils_1.MedusaV2Flag.key);
8
+ const variantPricesMap = new Map();
9
+ const ids = data.products.map((product) => product.id);
10
+ const productHandleAddedChannelsMap = new Map();
11
+ const productHandleRemovedChannelsMap = new Map();
12
+ const productService = container.resolve("productService");
13
+ const productServiceTx = productService.withTransaction(context.manager);
14
+ const products = await productServiceTx.list(
15
+ // TODO: use RemoteQuery - sales_channels needs to be added to the joiner config
16
+ { id: ids }, {
17
+ relations: [
18
+ "variants",
19
+ "variants.options",
20
+ "images",
21
+ "options",
22
+ "tags",
23
+ "collection",
24
+ "sales_channels",
25
+ ],
26
+ });
27
+ data.products.forEach((productInput) => {
28
+ const removedChannels = [];
29
+ const addedChannels = [];
30
+ const currentProduct = products.find((p) => p.id === productInput.id);
31
+ if (productInput.sales_channels) {
32
+ productInput.sales_channels.forEach((channel) => {
33
+ if (!currentProduct.sales_channels?.find((sc) => sc.id === channel.id)) {
34
+ addedChannels.push(channel.id);
35
+ }
36
+ });
37
+ currentProduct.sales_channels?.forEach((channel) => {
38
+ if (!productInput.sales_channels.find((sc) => sc.id === channel.id)) {
39
+ removedChannels.push(channel.id);
40
+ }
41
+ });
42
+ }
43
+ for (const variantInput of productInput.variants || []) {
44
+ if (variantInput.id) {
45
+ variantPricesMap.set(variantInput.id, variantInput.prices || []);
46
+ }
47
+ if (isPricingDomainEnabled) {
48
+ delete variantInput.prices;
49
+ }
50
+ }
51
+ productHandleAddedChannelsMap.set(currentProduct.handle, addedChannels);
52
+ productHandleRemovedChannelsMap.set(currentProduct.handle, removedChannels);
53
+ });
54
+ return {
55
+ originalProducts: products,
56
+ productHandleAddedChannelsMap,
57
+ productHandleRemovedChannelsMap,
58
+ variantPricesMap,
59
+ };
60
+ }
61
+ exports.updateProductsPrepareData = updateProductsPrepareData;
62
+ updateProductsPrepareData.aliases = {
63
+ preparedData: "preparedData",
64
+ };
65
+ //# sourceMappingURL=update-products-prepare-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-products-pr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+EC;AAED,yBAAyB,CAAC,OAAO,GAAG;IAClC,YAAY,EAAE,cAAc;CAC7B,CAAA"}
@@ -0,0 +1,18 @@
1
+ import { ProductTypes, WorkflowTypes } from "@medusajs/types";
2
+ import { WorkflowArguments } from "@medusajs/workflows-sdk";
3
+ type ProductHandle = string;
4
+ type VariantIndexAndPrices = {
5
+ index: number;
6
+ prices: WorkflowTypes.ProductWorkflow.CreateProductVariantPricesInputDTO[];
7
+ };
8
+ type HandlerInput = {
9
+ productsHandleVariantsIndexPricesMap: Map<ProductHandle, VariantIndexAndPrices[]>;
10
+ products: ProductTypes.ProductDTO[];
11
+ };
12
+ export declare function updateProductsVariantsPrices({ container, context, data, }: WorkflowArguments<HandlerInput>): Promise<void>;
13
+ export declare namespace updateProductsVariantsPrices {
14
+ var aliases: {
15
+ products: string;
16
+ };
17
+ }
18
+ export {};
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateProductsVariantsPrices = void 0;
4
+ const modules_sdk_1 = require("@medusajs/modules-sdk");
5
+ const utils_1 = require("@medusajs/utils");
6
+ async function updateProductsVariantsPrices({ container, context, data, }) {
7
+ const { manager } = context;
8
+ const products = data.products;
9
+ const productsHandleVariantsIndexPricesMap = data.productsHandleVariantsIndexPricesMap;
10
+ const productVariantService = container.resolve("productVariantService");
11
+ const regionService = container.resolve("regionService");
12
+ const featureFlagRouter = container.resolve("featureFlagRouter");
13
+ const productVariantServiceTx = productVariantService.withTransaction(manager);
14
+ const variantIdsPricesData = [];
15
+ const variantPricesMap = new Map();
16
+ const productsMap = new Map(products.map((p) => [p.handle, p]));
17
+ const regionIds = new Set();
18
+ for (const mapData of productsHandleVariantsIndexPricesMap.entries()) {
19
+ const [handle, variantData] = mapData;
20
+ const product = productsMap.get(handle);
21
+ if (!product) {
22
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Product with handle ${handle} not found`);
23
+ }
24
+ variantData.forEach((item, index) => {
25
+ const variant = product.variants[index];
26
+ variantIdsPricesData.push({
27
+ variantId: variant.id,
28
+ prices: item.prices,
29
+ });
30
+ const prices = [];
31
+ variantPricesMap.set(variant.id, prices);
32
+ item.prices.forEach((price) => {
33
+ const obj = {
34
+ amount: price.amount,
35
+ currency_code: price.currency_code,
36
+ rules: {},
37
+ };
38
+ if (price.region_id) {
39
+ regionIds.add(price.region_id);
40
+ obj.region_id = price.region_id;
41
+ }
42
+ prices.push(obj);
43
+ });
44
+ });
45
+ }
46
+ if (regionIds.size) {
47
+ const regions = await regionService.list({
48
+ id: [...regionIds],
49
+ });
50
+ const regionMap = new Map(regions.map((r) => [r.id, r]));
51
+ for (const [, prices] of variantPricesMap.entries()) {
52
+ prices.forEach((price) => {
53
+ if (price.region_id) {
54
+ const region = regionMap.get(price.region_id);
55
+ price.currency_code = region?.currency_code;
56
+ price.rules = {
57
+ region_id: price.region_id,
58
+ };
59
+ delete price.region_id;
60
+ }
61
+ });
62
+ }
63
+ }
64
+ if (featureFlagRouter.isFeatureEnabled(utils_1.MedusaV2Flag.key)) {
65
+ const remoteLink = container.resolve("remoteLink");
66
+ const pricingModuleService = container.resolve(modules_sdk_1.ModuleRegistrationName.PRICING);
67
+ const priceSetsToCreate = variantIdsPricesData.map(({ variantId }) => ({
68
+ rules: [{ rule_attribute: "region_id" }],
69
+ prices: variantPricesMap.get(variantId),
70
+ }));
71
+ const priceSets = await pricingModuleService.create(priceSetsToCreate);
72
+ const links = priceSets.map((priceSet, index) => ({
73
+ productService: {
74
+ variant_id: variantIdsPricesData[index].variantId,
75
+ },
76
+ pricingService: {
77
+ price_set_id: priceSet.id,
78
+ },
79
+ }));
80
+ await remoteLink.create(links);
81
+ }
82
+ else {
83
+ await productVariantServiceTx.updateVariantPrices(variantIdsPricesData);
84
+ }
85
+ }
86
+ exports.updateProductsVariantsPrices = updateProductsVariantsPrices;
87
+ updateProductsVariantsPrices.aliases = {
88
+ products: "products",
89
+ };
90
+ //# sourceMappingURL=update-products-variants-prices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-products-variants-prices.js","sourceRoot":"","sources":["../../../src/handlers/product/update-products-variants-prices.ts"],"names":[],"mappings":";;;AAEA,uDAA8D;AAC9D,2CAA2D;AAgBpD,KAAK,UAAU,4BAA4B,CAAC,EACjD,SAAS,EACT,OAAO,EACP,IAAI,GAC4B;IAChC,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAA;IAC3B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAA;IAC9B,MAAM,oCAAoC,GACxC,IAAI,CAAC,oCAAoC,CAAA;IAE3C,MAAM,qBAAqB,GAAG,SAAS,CAAC,OAAO,CAAC,uBAAuB,CAAC,CAAA;IACxE,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;IACxD,MAAM,iBAAiB,GAAG,SAAS,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;IAChE,MAAM,uBAAuB,GAAG,qBAAqB,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;IAC9E,MAAM,oBAAoB,GAAU,EAAE,CAAA;IACtC,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAiB,CAAA;IAEjD,MAAM,WAAW,GAAG,IAAI,GAAG,CACzB,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAO,EAAE,CAAC,CAAC,CAAC,CACpC,CAAA;IAED,MAAM,SAAS,GAAG,IAAI,GAAG,EAAE,CAAA;IAE3B,KAAK,MAAM,OAAO,IAAI,oCAAoC,CAAC,OAAO,EAAE,EAAE;QACpE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,OAAO,CAAA;QAErC,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;QACvC,IAAI,CAAC,OAAO,EAAE;YACZ,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,K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AC,CAAA;QAEH,MAAM,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;KAC/B;SAAM;QACL,MAAM,uBAAuB,CAAC,mBAAmB,CAAC,oBAAoB,CAAC,CAAA;KACxE;AACH,CAAC;AA5GD,oEA4GC;AAED,4BAA4B,CAAC,OAAO,GAAG;IACrC,QAAQ,EAAE,UAAU;CACrB,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { ProductDTO, ProductTypes } from "@medusajs/types";
2
+ import { WorkflowArguments } from "@medusajs/workflows-sdk";
3
+ type HandlerInput = {
4
+ products: ProductTypes.UpdateProductDTO[];
5
+ };
6
+ export declare function updateProducts({ container, context, data, }: WorkflowArguments<HandlerInput>): Promise<ProductDTO[]>;
7
+ export declare namespace updateProducts {
8
+ var aliases: {
9
+ products: string;
10
+ };
11
+ }
12
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateProducts = void 0;
4
+ const modules_sdk_1 = require("@medusajs/modules-sdk");
5
+ async function updateProducts({ container, context, data, }) {
6
+ if (!data.products.length) {
7
+ return [];
8
+ }
9
+ const productModuleService = container.resolve(modules_sdk_1.ModulesDefinition[modules_sdk_1.Modules.PRODUCT].registrationName);
10
+ const products = await productModuleService.update(data.products);
11
+ return await productModuleService.list({ id: products.map((p) => p.id) }, {
12
+ relations: [
13
+ "variants",
14
+ "variants.options",
15
+ "images",
16
+ "options",
17
+ "tags",
18
+ // "type",
19
+ "collection",
20
+ // "profiles",
21
+ // "sales_channels",
22
+ ],
23
+ });
24
+ }
25
+ exports.updateProducts = updateProducts;
26
+ updateProducts.aliases = {
27
+ products: "products",
28
+ };
29
+ //# sourceMappingURL=update-products.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-products.js","sourceRoot":"","sources":["../../../src/handlers/product/update-products.ts"],"names":[],"mappings":";;;AAAA,uDAAkE;AAS3D,KAAK,UAAU,cAAc,CAAC,EACnC,SAAS,EACT,OAAO,EACP,IAAI,GAC4B;IAChC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE;QACzB,OAAO,EAAE,CAAA;KACV;IAED,MAAM,oBAAoB,GACxB,SAAS,CAAC,OAAO,CAAC,+BAAiB,CAAC,qBAAO,CAAC,OAAO,CAAC,CAAC,gBAAgB,CAAC,CAAA;IAExE,MAAM,QAAQ,GAAG,MAAM,oBAAoB,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAEjE,OAAO,MAAM,oBAAoB,CAAC,IAAI,CACpC,EAAE,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EACjC;QACE,SAAS,EAAE;YACT,UAAU;YACV,kBAAkB;YAClB,QAAQ;YACR,SAAS;YACT,MAAM;YACN,UAAU;YACV,YAAY;YACZ,cAAc;YACd,oBAAoB;SACrB;KACF,CACF,CAAA;AACH,CAAC;AA9BD,wCA8BC;AAED,cAAc,CAAC,OAAO,GAAG;IACvB,QAAQ,EAAE,UAAU;CACrB,CAAA"}
@@ -0,0 +1,25 @@
1
+ import { PricingTypes } from "@medusajs/types";
2
+ import { WorkflowArguments } from "@medusajs/workflows-sdk";
3
+ type VariantPrice = {
4
+ id?: string;
5
+ region_id?: string;
6
+ currency_code: string;
7
+ amount: number;
8
+ min_quantity?: number;
9
+ max_quantity?: number;
10
+ rules: Record<string, string>;
11
+ };
12
+ type HandlerInput = {
13
+ variantPricesMap: Map<string, VariantPrice[]>;
14
+ };
15
+ export declare function upsertVariantPrices({ container, data, }: WorkflowArguments<HandlerInput>): Promise<{
16
+ createdLinks: any;
17
+ originalMoneyAmounts: any;
18
+ createdPriceSets: PricingTypes.PriceSetDTO[];
19
+ }>;
20
+ export declare namespace upsertVariantPrices {
21
+ var aliases: {
22
+ productVariantsPrices: string;
23
+ };
24
+ }
25
+ export {};
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.upsertVariantPrices = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ async function upsertVariantPrices({ container, data, }) {
6
+ const { variantPricesMap } = data;
7
+ const featureFlagRouter = container.resolve("featureFlagRouter");
8
+ if (!featureFlagRouter.isFeatureEnabled(utils_1.MedusaV2Flag.key)) {
9
+ return {
10
+ createdLinks: [],
11
+ originalMoneyAmounts: [],
12
+ createdPriceSets: [],
13
+ };
14
+ }
15
+ const pricingModuleService = container.resolve("pricingModuleService");
16
+ const regionService = container.resolve("regionService");
17
+ const remoteLink = container.resolve("remoteLink");
18
+ const remoteQuery = container.resolve("remoteQuery");
19
+ const variables = {
20
+ variant_id: [...variantPricesMap.keys()],
21
+ };
22
+ const query = {
23
+ product_variant_price_set: {
24
+ __args: variables,
25
+ fields: ["variant_id", "price_set_id"],
26
+ },
27
+ };
28
+ const variantPriceSets = await remoteQuery(query);
29
+ const variantIdToPriceSetIdMap = new Map(variantPriceSets.map((variantPriceSet) => [
30
+ variantPriceSet.variant_id,
31
+ variantPriceSet.price_set_id,
32
+ ]));
33
+ const moneyAmountsToUpdate = [];
34
+ const createdPriceSets = [];
35
+ const ruleSetPricesToAdd = [];
36
+ const linksToCreate = [];
37
+ for (const [variantId, prices = []] of variantPricesMap) {
38
+ const priceSetToCreate = {
39
+ rules: [{ rule_attribute: "region_id" }],
40
+ prices: [],
41
+ };
42
+ const regionIds = prices.map((price) => price.region_id);
43
+ const regions = await regionService.list({ id: regionIds });
44
+ const regionsMap = new Map(regions.map((region) => [region.id, region]));
45
+ for (const price of prices) {
46
+ const region = price.region_id && regionsMap.get(price.region_id);
47
+ let region_currency_code;
48
+ let region_rules;
49
+ if (region) {
50
+ region_currency_code = region.currency_code;
51
+ region_rules = {
52
+ region_id: region.id,
53
+ };
54
+ }
55
+ if (price.id) {
56
+ const priceToUpdate = {
57
+ id: price.id,
58
+ min_quantity: price.min_quantity,
59
+ max_quantity: price.max_quantity,
60
+ amount: price.amount,
61
+ currency_code: region_currency_code ?? price.currency_code,
62
+ };
63
+ moneyAmountsToUpdate.push(priceToUpdate);
64
+ }
65
+ else {
66
+ const variantPrice = {
67
+ min_quantity: price.min_quantity,
68
+ max_quantity: price.max_quantity,
69
+ amount: price.amount,
70
+ currency_code: region_currency_code ?? price.currency_code,
71
+ rules: region_rules ?? {},
72
+ };
73
+ delete price.region_id;
74
+ if (variantIdToPriceSetIdMap.get(variantId)) {
75
+ ruleSetPricesToAdd.push(variantPrice);
76
+ }
77
+ else {
78
+ priceSetToCreate.prices?.push(variantPrice);
79
+ }
80
+ }
81
+ }
82
+ let priceSetId = variantIdToPriceSetIdMap.get(variantId);
83
+ if (priceSetId) {
84
+ await pricingModuleService.addPrices({
85
+ priceSetId,
86
+ prices: ruleSetPricesToAdd,
87
+ });
88
+ }
89
+ else {
90
+ const createdPriceSet = await pricingModuleService.create(priceSetToCreate);
91
+ priceSetId = createdPriceSet?.id;
92
+ createdPriceSets.push(createdPriceSet);
93
+ linksToCreate.push({
94
+ productService: {
95
+ variant_id: variantId,
96
+ },
97
+ pricingService: {
98
+ price_set_id: priceSetId,
99
+ },
100
+ });
101
+ }
102
+ }
103
+ const createdLinks = await remoteLink.create(linksToCreate);
104
+ let originalMoneyAmounts = await pricingModuleService.listMoneyAmounts({
105
+ id: moneyAmountsToUpdate.map((matu) => matu.id),
106
+ }, {
107
+ select: ["id", "currency_code", "amount", "min_quantity", "max_quantity"],
108
+ });
109
+ if (moneyAmountsToUpdate.length) {
110
+ await pricingModuleService.updateMoneyAmounts(moneyAmountsToUpdate);
111
+ }
112
+ return {
113
+ createdLinks,
114
+ originalMoneyAmounts,
115
+ createdPriceSets,
116
+ };
117
+ }
118
+ exports.upsertVariantPrices = upsertVariantPrices;
119
+ upsertVariantPrices.aliases = {
120
+ productVariantsPrices: "productVariantsPrices",
121
+ };
122
+ //# sourceMappingURL=upsert-variant-prices.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upsert-variant-prices.js","sourceRoot":"","sources":["../../../src/handlers/product/upsert-variant-prices.ts"],"names":[],"mappings":";;;AACA,2CAA8C;AAsBvC,KAAK,UAAU,mBAAmB,CAAC,EACxC,SAAS,EACT,IAAI,GAC4B;IAChC,MAAM,EAAE,gBAAgB,EAAE,GAAG,IAAI,CAAA;IACjC,MAAM,iBAAiB,GAAG,SAAS,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAA;IAEhE,IAAI,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,oBAAY,CAAC,GAAG,CAAC,EAAE;QACzD,OAAO;YACL,YAAY,EAAE,EAAE;YAChB,oBAAoB,EAAE,EAAE;YACxB,gBAAgB,EAAE,EAAE;SACrB,CAAA;KACF;IAED,MAAM,oBAAoB,GAAG,SAAS,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAA;IACtE,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;IACxD,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;IAClD,MAAM,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,aAAa,CAAC,CAAA;IAEpD,MAAM,SAAS,GAAG;QAChB,UAAU,EAAE,CAAC,GAAG,gBAAgB,CAAC,IAAI,EAAE,CAAC;KACzC,CAAA;IAED,MAAM,KAAK,GAAG;QACZ,yBAAyB,EAAE;YACzB,MAAM,EAAE,SAAS;YACjB,MAAM,EAAE,CAAC,YAAY,EAAE,cAAc,CAAC;SACvC;KACF,CAAA;IAED,MAAM,gBAAgB,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,CAAA;IAEjD,MAAM,wBAAwB,GAAwB,IAAI,GAAG,CAC3D,gBAAgB,CAAC,GAAG,CAAC,CAAC,eAAe,EAAE,EAAE,CAAC;QACxC,eAAe,CAAC,UAAU;QAC1B,eAAe,CAAC,YAAY;KAC7B,CAAC,CACH,CAAA;IAED,MAAM,oBAAoB,GAAwC,E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IAAI,oBAAoB,GAAG,MAAM,oBAAoB,CAAC,gBAAgB,CACpE;QACE,EAAE,EAAE,oBAAoB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;KAChD,EACD;QACE,MAAM,EAAE,CAAC,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,CAAC;KAC1E,CACF,CAAA;IAED,IAAI,oBAAoB,CAAC,MAAM,EAAE;QAC/B,MAAM,oBAAoB,CAAC,kBAAkB,CAAC,oBAAoB,CAAC,CAAA;KACpE;IAED,OAAO;QACL,YAAY;QACZ,oBAAoB;QACpB,gBAAgB;KACjB,CAAA;AACH,CAAC;AA/ID,kDA+IC;AAED,mBAAmB,CAAC,OAAO,GAAG;IAC5B,qBAAqB,EAAE,uBAAuB;CAC/C,CAAA"}
@@ -0,0 +1,17 @@
1
+ import { WorkflowArguments } from "@medusajs/workflows-sdk";
2
+ type RegionDTO = {
3
+ region_id?: string;
4
+ };
5
+ type HandlerInputData = {
6
+ region: {
7
+ region_id: string;
8
+ };
9
+ };
10
+ declare enum Aliases {
11
+ Region = "region"
12
+ }
13
+ export declare function findRegion({ container, data, }: WorkflowArguments<HandlerInputData>): Promise<RegionDTO>;
14
+ export declare namespace findRegion {
15
+ var aliases: typeof Aliases;
16
+ }
17
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findRegion = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ const medusa_core_utils_1 = require("medusa-core-utils");
6
+ var Aliases;
7
+ (function (Aliases) {
8
+ Aliases["Region"] = "region";
9
+ })(Aliases || (Aliases = {}));
10
+ async function findRegion({ container, data, }) {
11
+ const regionService = container.resolve("regionService");
12
+ let regionId;
13
+ const regionDTO = {};
14
+ if ((0, medusa_core_utils_1.isDefined)(data[Aliases.Region].region_id)) {
15
+ regionId = data[Aliases.Region].region_id;
16
+ }
17
+ else {
18
+ const regions = await regionService.list({}, {});
19
+ if (!regions?.length) {
20
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `A region is required to create a cart`);
21
+ }
22
+ regionId = regions[0].id;
23
+ }
24
+ regionDTO.region_id = regionId;
25
+ return regionDTO;
26
+ }
27
+ exports.findRegion = findRegion;
28
+ findRegion.aliases = Aliases;
29
+ //# sourceMappingURL=find-region.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-region.js","sourceRoot":"","sources":["../../../src/handlers/region/find-region.ts"],"names":[],"mappings":";;;AAAA,2CAA6C;AAC7C,yDAA6C;AAc7C,IAAK,OAEJ;AAFD,WAAK,OAAO;IACV,4BAAiB,CAAA;AACnB,CAAC,EAFI,OAAO,KAAP,OAAO,QAEX;AAEM,KAAK,UAAU,UAAU,CAAC,EAC/B,SAAS,EACT,IAAI,GACgC;IACpC,MAAM,aAAa,GAAG,SAAS,CAAC,OAAO,CAAC,eAAe,CAAC,CAAA;IAExD,IAAI,QAAgB,CAAA;IACpB,MAAM,SAAS,GAAc,EAAE,CAAA;IAE/B,IAAI,IAAA,6BAAS,EAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAAE;QAC7C,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAA;KAC1C;SAAM;QACL,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAA;QAEhD,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE;YACpB,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,uCAAuC,CACxC,CAAA;SACF;QAED,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;KACzB;IAED,SAAS,CAAC,SAAS,GAAG,QAAQ,CAAA;IAE9B,OAAO,SAAS,CAAA;AAClB,CAAC;AA3BD,gCA2BC;AAED,UAAU,CAAC,OAAO,GAAG,OAAO,CAAA"}
@@ -0,0 +1 @@
1
+ export * from "./find-region";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./find-region"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/handlers/region/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,gDAA6B"}
@@ -0,0 +1,20 @@
1
+ import { WorkflowArguments } from "@medusajs/workflows-sdk";
2
+ type AttachSalesChannelDTO = {
3
+ sales_channel_id?: string;
4
+ };
5
+ type HandlerInputData = {
6
+ sales_channel: {
7
+ sales_channel_id?: string;
8
+ publishableApiKeyScopes?: {
9
+ sales_channel_ids?: string[];
10
+ };
11
+ };
12
+ };
13
+ declare enum Aliases {
14
+ SalesChannel = "sales_channel"
15
+ }
16
+ export declare function findSalesChannel({ container, data, }: WorkflowArguments<HandlerInputData>): Promise<AttachSalesChannelDTO>;
17
+ export declare namespace findSalesChannel {
18
+ var aliases: typeof Aliases;
19
+ }
20
+ export {};
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findSalesChannel = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ const medusa_core_utils_1 = require("medusa-core-utils");
6
+ var Aliases;
7
+ (function (Aliases) {
8
+ Aliases["SalesChannel"] = "sales_channel";
9
+ })(Aliases || (Aliases = {}));
10
+ async function findSalesChannel({ container, data, }) {
11
+ const salesChannelService = container.resolve("salesChannelService");
12
+ const storeService = container.resolve("storeService");
13
+ let salesChannelId = data[Aliases.SalesChannel].sales_channel_id;
14
+ let salesChannel;
15
+ const salesChannelDTO = {};
16
+ const publishableApiKeyScopes = data[Aliases.SalesChannel].publishableApiKeyScopes || {};
17
+ delete data[Aliases.SalesChannel].publishableApiKeyScopes;
18
+ if (!(0, medusa_core_utils_1.isDefined)(salesChannelId) &&
19
+ publishableApiKeyScopes?.sales_channel_ids?.length) {
20
+ if (publishableApiKeyScopes.sales_channel_ids.length > 1) {
21
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.UNEXPECTED_STATE, "The provided PublishableApiKey has multiple associated sales channels.");
22
+ }
23
+ salesChannelId = publishableApiKeyScopes.sales_channel_ids[0];
24
+ }
25
+ if ((0, medusa_core_utils_1.isDefined)(salesChannelId)) {
26
+ salesChannel = await salesChannelService.retrieve(salesChannelId);
27
+ }
28
+ else {
29
+ salesChannel = (await storeService.retrieve({
30
+ relations: ["default_sales_channel"],
31
+ })).default_sales_channel;
32
+ }
33
+ if (salesChannel.is_disabled) {
34
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Unable to assign the cart to a disabled Sales Channel "${salesChannel.name}"`);
35
+ }
36
+ salesChannelDTO.sales_channel_id = salesChannel?.id;
37
+ return salesChannelDTO;
38
+ }
39
+ exports.findSalesChannel = findSalesChannel;
40
+ findSalesChannel.aliases = Aliases;
41
+ //# sourceMappingURL=find-sales-channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"find-sales-channel.js","sourceRoot":"","sources":["../../../src/handlers/sales-channel/find-sales-channel.ts"],"names":[],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CAAA;KACxB;IAED,IAAI,YAAY,CAAC,WAAW,EAAE;QAC5B,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,0DAA0D,YAAY,CAAC,IAAI,GAAG,CAC/E,CAAA;KACF;IAED,eAAe,CAAC,gBAAgB,GAAG,YAAY,EAAE,EAAE,CAAA;IAEnD,OAAO,eAAe,CAAA;AACxB,CAAC;AAjDD,4CAiDC;AAED,gBAAgB,CAAC,OAAO,GAAG,OAAO,CAAA"}
@@ -0,0 +1 @@
1
+ export * from "./find-sales-channel";
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./find-sales-channel"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/handlers/sales-channel/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAoC"}
@@ -0,0 +1,3 @@
1
+ export * from "./definition";
2
+ export * from "./definitions";
3
+ export * as Handlers from "./handlers";
package/dist/index.js ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.Handlers = void 0;
30
+ __exportStar(require("./definition"), exports);
31
+ __exportStar(require("./definitions"), exports);
32
+ exports.Handlers = __importStar(require("./handlers"));
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAA4B;AAC5B,gDAA6B;AAC7B,uDAAsC"}