@medusajs/promotion 0.0.6 → 1.0.0-rc-20241003153304

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. package/dist/index.d.ts +5 -4
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +6 -20
  4. package/dist/index.js.map +1 -0
  5. package/dist/joiner-config.d.ts +1 -8
  6. package/dist/joiner-config.d.ts.map +1 -1
  7. package/dist/joiner-config.js +11 -36
  8. package/dist/joiner-config.js.map +1 -0
  9. package/dist/migrations/Migration20240227120221.d.ts.map +1 -1
  10. package/dist/migrations/Migration20240227120221.js +11 -2
  11. package/dist/migrations/Migration20240227120221.js.map +1 -0
  12. package/dist/migrations/Migration20240617102917.d.ts +6 -0
  13. package/dist/migrations/Migration20240617102917.d.ts.map +1 -0
  14. package/dist/migrations/Migration20240617102917.js +16 -0
  15. package/dist/migrations/Migration20240617102917.js.map +1 -0
  16. package/dist/migrations/Migration20240624153824.d.ts +6 -0
  17. package/dist/migrations/Migration20240624153824.d.ts.map +1 -0
  18. package/dist/migrations/Migration20240624153824.js +16 -0
  19. package/dist/migrations/Migration20240624153824.js.map +1 -0
  20. package/dist/models/application-method.d.ts +5 -7
  21. package/dist/models/application-method.d.ts.map +1 -1
  22. package/dist/models/application-method.js +18 -7
  23. package/dist/models/application-method.js.map +1 -0
  24. package/dist/models/campaign-budget.d.ts +8 -7
  25. package/dist/models/campaign-budget.d.ts.map +1 -1
  26. package/dist/models/campaign-budget.js +10 -5
  27. package/dist/models/campaign-budget.js.map +1 -0
  28. package/dist/models/campaign.d.ts +4 -5
  29. package/dist/models/campaign.d.ts.map +1 -1
  30. package/dist/models/campaign.js +12 -14
  31. package/dist/models/campaign.js.map +1 -0
  32. package/dist/models/index.js +1 -0
  33. package/dist/models/index.js.map +1 -0
  34. package/dist/models/promotion-rule-value.d.ts +2 -1
  35. package/dist/models/promotion-rule-value.d.ts.map +1 -1
  36. package/dist/models/promotion-rule-value.js +3 -2
  37. package/dist/models/promotion-rule-value.js.map +1 -0
  38. package/dist/models/promotion-rule.d.ts +2 -2
  39. package/dist/models/promotion-rule.d.ts.map +1 -1
  40. package/dist/models/promotion-rule.js +2 -1
  41. package/dist/models/promotion-rule.js.map +1 -0
  42. package/dist/models/promotion.d.ts +6 -5
  43. package/dist/models/promotion.d.ts.map +1 -1
  44. package/dist/models/promotion.js +10 -5
  45. package/dist/models/promotion.js.map +1 -0
  46. package/dist/schema/index.d.ts +3 -0
  47. package/dist/schema/index.d.ts.map +1 -0
  48. package/dist/schema/index.js +99 -0
  49. package/dist/schema/index.js.map +1 -0
  50. package/dist/services/index.js +1 -0
  51. package/dist/services/index.js.map +1 -0
  52. package/dist/services/promotion-module.d.ts +41 -26
  53. package/dist/services/promotion-module.d.ts.map +1 -1
  54. package/dist/services/promotion-module.js +293 -100
  55. package/dist/services/promotion-module.js.map +1 -0
  56. package/dist/tsconfig.tsbuildinfo +1 -0
  57. package/dist/types/application-method.d.ts +12 -10
  58. package/dist/types/application-method.d.ts.map +1 -1
  59. package/dist/types/application-method.js +1 -0
  60. package/dist/types/application-method.js.map +1 -0
  61. package/dist/types/campaign-budget.d.ts +8 -6
  62. package/dist/types/campaign-budget.d.ts.map +1 -1
  63. package/dist/types/campaign-budget.js +1 -0
  64. package/dist/types/campaign-budget.js.map +1 -0
  65. package/dist/types/campaign.d.ts +7 -9
  66. package/dist/types/campaign.d.ts.map +1 -1
  67. package/dist/types/campaign.js +1 -0
  68. package/dist/types/campaign.js.map +1 -0
  69. package/dist/types/index.d.ts +1 -1
  70. package/dist/types/index.d.ts.map +1 -1
  71. package/dist/types/index.js +1 -0
  72. package/dist/types/index.js.map +1 -0
  73. package/dist/types/promotion-rule-value.d.ts +1 -1
  74. package/dist/types/promotion-rule-value.d.ts.map +1 -1
  75. package/dist/types/promotion-rule-value.js +1 -0
  76. package/dist/types/promotion-rule-value.js.map +1 -0
  77. package/dist/types/promotion-rule.d.ts +1 -1
  78. package/dist/types/promotion-rule.d.ts.map +1 -1
  79. package/dist/types/promotion-rule.js +1 -0
  80. package/dist/types/promotion-rule.js.map +1 -0
  81. package/dist/types/promotion.d.ts +3 -3
  82. package/dist/types/promotion.d.ts.map +1 -1
  83. package/dist/types/promotion.js +1 -0
  84. package/dist/types/promotion.js.map +1 -0
  85. package/dist/utils/compute-actions/buy-get.d.ts +6 -3
  86. package/dist/utils/compute-actions/buy-get.d.ts.map +1 -1
  87. package/dist/utils/compute-actions/buy-get.js +98 -34
  88. package/dist/utils/compute-actions/buy-get.js.map +1 -0
  89. package/dist/utils/compute-actions/index.js +1 -0
  90. package/dist/utils/compute-actions/index.js.map +1 -0
  91. package/dist/utils/compute-actions/line-items.d.ts +2 -2
  92. package/dist/utils/compute-actions/line-items.d.ts.map +1 -1
  93. package/dist/utils/compute-actions/line-items.js +10 -10
  94. package/dist/utils/compute-actions/line-items.js.map +1 -0
  95. package/dist/utils/compute-actions/shipping-methods.d.ts +3 -3
  96. package/dist/utils/compute-actions/shipping-methods.d.ts.map +1 -1
  97. package/dist/utils/compute-actions/shipping-methods.js +20 -22
  98. package/dist/utils/compute-actions/shipping-methods.js.map +1 -0
  99. package/dist/utils/compute-actions/usage.d.ts +2 -3
  100. package/dist/utils/compute-actions/usage.d.ts.map +1 -1
  101. package/dist/utils/compute-actions/usage.js +6 -13
  102. package/dist/utils/compute-actions/usage.js.map +1 -0
  103. package/dist/utils/index.js +1 -0
  104. package/dist/utils/index.js.map +1 -0
  105. package/dist/utils/validations/application-method.d.ts.map +1 -1
  106. package/dist/utils/validations/application-method.js +6 -5
  107. package/dist/utils/validations/application-method.js.map +1 -0
  108. package/dist/utils/validations/index.js +1 -0
  109. package/dist/utils/validations/index.js.map +1 -0
  110. package/dist/utils/validations/promotion-rule.d.ts +2 -2
  111. package/dist/utils/validations/promotion-rule.d.ts.map +1 -1
  112. package/dist/utils/validations/promotion-rule.js +27 -7
  113. package/dist/utils/validations/promotion-rule.js.map +1 -0
  114. package/package.json +25 -26
  115. package/dist/initialize/index.d.ts +0 -5
  116. package/dist/initialize/index.d.ts.map +0 -1
  117. package/dist/initialize/index.js +0 -16
  118. package/dist/loaders/connection.d.ts +0 -5
  119. package/dist/loaders/connection.d.ts.map +0 -1
  120. package/dist/loaders/connection.js +0 -41
  121. package/dist/loaders/container.d.ts +0 -3
  122. package/dist/loaders/container.d.ts.map +0 -1
  123. package/dist/loaders/container.js +0 -34
  124. package/dist/loaders/index.d.ts +0 -3
  125. package/dist/loaders/index.d.ts.map +0 -1
  126. package/dist/loaders/index.js +0 -18
  127. package/dist/module-definition.d.ts +0 -5
  128. package/dist/module-definition.d.ts.map +0 -1
  129. package/dist/module-definition.js +0 -50
  130. package/dist/repositories/campaign.d.ts +0 -16
  131. package/dist/repositories/campaign.d.ts.map +0 -1
  132. package/dist/repositories/campaign.js +0 -90
  133. package/dist/repositories/index.d.ts +0 -3
  134. package/dist/repositories/index.d.ts.map +0 -1
  135. package/dist/repositories/index.js +0 -7
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getComputedActionsForOrder = exports.getComputedActionsForShippingMethods = exports.getComputedActionsForItems = void 0;
4
- const utils_1 = require("@medusajs/utils");
3
+ exports.getComputedActionsForItems = getComputedActionsForItems;
4
+ exports.getComputedActionsForShippingMethods = getComputedActionsForShippingMethods;
5
+ exports.getComputedActionsForOrder = getComputedActionsForOrder;
6
+ const utils_1 = require("@medusajs/framework/utils");
5
7
  const validations_1 = require("../validations");
6
8
  const usage_1 = require("./usage");
7
9
  function validateContext(contextKey, context) {
@@ -13,16 +15,13 @@ function getComputedActionsForItems(promotion, items, appliedPromotionsMap, allo
13
15
  validateContext("items", items);
14
16
  return applyPromotionToItems(promotion, items, appliedPromotionsMap, allocationOverride);
15
17
  }
16
- exports.getComputedActionsForItems = getComputedActionsForItems;
17
18
  function getComputedActionsForShippingMethods(promotion, shippingMethods, appliedPromotionsMap) {
18
19
  validateContext("shipping_methods", shippingMethods);
19
20
  return applyPromotionToItems(promotion, shippingMethods, appliedPromotionsMap);
20
21
  }
21
- exports.getComputedActionsForShippingMethods = getComputedActionsForShippingMethods;
22
22
  function getComputedActionsForOrder(promotion, itemApplicationContext, methodIdPromoValueMap) {
23
23
  return getComputedActionsForItems(promotion, itemApplicationContext[utils_1.ApplicationMethodTargetType.ITEMS], methodIdPromoValueMap, utils_1.ApplicationMethodAllocation.ACROSS);
24
24
  }
25
- exports.getComputedActionsForOrder = getComputedActionsForOrder;
26
25
  function applyPromotionToItems(promotion, items, appliedPromotionsMap, allocationOverride) {
27
26
  const { application_method: applicationMethod } = promotion;
28
27
  const allocation = applicationMethod?.allocation || allocationOverride;
@@ -32,9 +31,9 @@ function applyPromotionToItems(promotion, items, appliedPromotionsMap, allocatio
32
31
  const isTargetShippingMethod = target === utils_1.ApplicationMethodTargetType.SHIPPING_METHODS;
33
32
  const isTargetLineItems = target === utils_1.ApplicationMethodTargetType.ITEMS;
34
33
  const isTargetOrder = target === utils_1.ApplicationMethodTargetType.ORDER;
35
- let lineItemsTotal = 0;
34
+ let lineItemsTotal = utils_1.MathBN.convert(0);
36
35
  if (allocation === utils_1.ApplicationMethodAllocation.ACROSS) {
37
- lineItemsTotal = applicableItems.reduce((acc, item) => acc + item.subtotal - (appliedPromotionsMap.get(item.id) ?? 0), 0);
36
+ lineItemsTotal = applicableItems.reduce((acc, item) => utils_1.MathBN.sub(utils_1.MathBN.add(acc, item.subtotal), appliedPromotionsMap.get(item.id) ?? 0), utils_1.MathBN.convert(0));
38
37
  }
39
38
  for (const item of applicableItems) {
40
39
  const appliedPromoValue = appliedPromotionsMap.get(item.id) ?? 0;
@@ -51,7 +50,7 @@ function applyPromotionToItems(promotion, items, appliedPromotionsMap, allocatio
51
50
  type: applicationMethod?.type,
52
51
  allocation,
53
52
  }, lineItemsTotal);
54
- if (amount <= 0) {
53
+ if (utils_1.MathBN.lte(amount, 0)) {
55
54
  continue;
56
55
  }
57
56
  const budgetExceededAction = (0, usage_1.computeActionForBudgetExceeded)(promotion, amount);
@@ -59,7 +58,7 @@ function applyPromotionToItems(promotion, items, appliedPromotionsMap, allocatio
59
58
  computedActions.push(budgetExceededAction);
60
59
  continue;
61
60
  }
62
- appliedPromotionsMap.set(item.id, appliedPromoValue + amount);
61
+ appliedPromotionsMap.set(item.id, utils_1.MathBN.add(appliedPromoValue, amount));
63
62
  if (isTargetLineItems || isTargetOrder) {
64
63
  computedActions.push({
65
64
  action: utils_1.ComputedActions.ADD_ITEM_ADJUSTMENT,
@@ -84,9 +83,10 @@ function getValidItemsForPromotion(items, promotion) {
84
83
  return (items?.filter((item) => {
85
84
  const isSubtotalPresent = "subtotal" in item;
86
85
  const isQuantityPresent = "quantity" in item;
87
- const isPromotionApplicableToItem = (0, validations_1.areRulesValidForContext)(promotion?.application_method?.target_rules, item);
86
+ const isPromotionApplicableToItem = (0, validations_1.areRulesValidForContext)(promotion?.application_method?.target_rules, item, utils_1.ApplicationMethodTargetType.ITEMS);
88
87
  return (isPromotionApplicableToItem &&
89
88
  (isQuantityPresent || isTargetShippingMethod) &&
90
89
  isSubtotalPresent);
91
90
  }) || []);
92
91
  }
92
+ //# sourceMappingURL=line-items.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"line-items.js","sourceRoot":"","sources":["../../../src/utils/compute-actions/line-items.ts"],"names":[],"mappings":";;AA6BA,gEAcC;AAED,oFAQC;AAED,gEAWC;AA7DD,qDAQkC;AAClC,gDAAwD;AACxD,mCAAwD;AAExD,SAAS,eAAe,CACtB,UAAkB,EAClB,OAAwD;IAExD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,IAAI,UAAU,mEAAmE,CAClF,CAAA;IACH,CAAC;AACH,CAAC;AAED,SAAgB,0BAA0B,CACxC,SAAsC,EACtC,KAA4D,EAC5D,oBAAyC,EACzC,kBAAsD;IAEtD,eAAe,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;IAE/B,OAAO,qB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aAAa,EAAE,CAAC;YACvC,eAAe,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,uBAAe,CAAC,mBAAmB;gBAC3C,OAAO,EAAE,IAAI,CAAC,EAAE;gBAChB,MAAM;gBACN,IAAI,EAAE,SAAS,CAAC,IAAK;aACtB,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,sBAAsB,EAAE,CAAC;YAC3B,eAAe,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,uBAAe,CAAC,8BAA8B;gBACtD,kBAAkB,EAAE,IAAI,CAAC,EAAE;gBAC3B,MAAM;gBACN,IAAI,EAAE,SAAS,CAAC,IAAK;aACtB,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,eAAe,CAAA;AACxB,CAAC;AAED,SAAS,yBAAyB,CAChC,KAEoE,EACpE,SAAsC;IAEtC,MAAM,sBAAsB,GAC1B,SAAS,CAAC,kBAAkB,EAAE,WAAW,KAAK,mCAAU,CAAC,gBAAgB,CAAA;IAE3E,OAAO,CACL,KAAK,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE;QACrB,MAAM,iBAAiB,GAAG,UAAU,IAAI,IAAI,CAAA;QAC5C,MAAM,iBAAiB,GAAG,UAAU,IAAI,IAAI,CAAA;QAC5C,MAAM,2BAA2B,GAAG,IAAA,qCAAuB,EACzD,SAAS,EAAE,kBAAkB,EAAE,YAAa,EAC5C,IAAI,EACJ,mCAA2B,CAAC,KAAK,CAClC,CAAA;QAED,OAAO,CACL,2BAA2B;YAC3B,CAAC,iBAAiB,IAAI,sBAAsB,CAAC;YAC7C,iBAAiB,CAClB,CAAA;IACH,CAAC,CAAC,IAAI,EAAE,CACT,CAAA;AACH,CAAC"}
@@ -1,5 +1,5 @@
1
- import { PromotionTypes } from "@medusajs/types";
2
- import { ApplicationMethodTargetType } from "@medusajs/utils";
1
+ import { BigNumberInput, PromotionTypes } from "@medusajs/framework/types";
2
+ import { ApplicationMethodTargetType } from "@medusajs/framework/utils";
3
3
  export declare function getComputedActionsForShippingMethods(promotion: PromotionTypes.PromotionDTO, shippingMethodApplicationContext: PromotionTypes.ComputeActionContext[ApplicationMethodTargetType.SHIPPING_METHODS], methodIdPromoValueMap: Map<string, number>): PromotionTypes.ComputeActions[];
4
- export declare function applyPromotionToShippingMethods(promotion: PromotionTypes.PromotionDTO, shippingMethods: PromotionTypes.ComputeActionContext[ApplicationMethodTargetType.SHIPPING_METHODS], methodIdPromoValueMap: Map<string, number>): PromotionTypes.ComputeActions[];
4
+ export declare function applyPromotionToShippingMethods(promotion: PromotionTypes.PromotionDTO, shippingMethods: PromotionTypes.ComputeActionContext[ApplicationMethodTargetType.SHIPPING_METHODS], methodIdPromoValueMap: Map<string, BigNumberInput>): PromotionTypes.ComputeActions[];
5
5
  //# sourceMappingURL=shipping-methods.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shipping-methods.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/shipping-methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChD,OAAO,EAEL,2BAA2B,EAI5B,MAAM,iBAAiB,CAAA;AAIxB,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,gCAAgC,EAAE,cAAc,CAAC,oBAAoB,CAAC,2BAA2B,CAAC,gBAAgB,CAAC,EACnH,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,cAAc,EAAE,CA6BjC;AAED,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,eAAe,EAAE,cAAc,CAAC,oBAAoB,CAAC,2BAA2B,CAAC,gBAAgB,CAAC,EAClG,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,cAAc,EAAE,CA0GjC"}
1
+ {"version":3,"file":"shipping-methods.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/shipping-methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,EAEL,2BAA2B,EAK5B,MAAM,2BAA2B,CAAA;AAIlC,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,gCAAgC,EAAE,cAAc,CAAC,oBAAoB,CAAC,2BAA2B,CAAC,gBAAgB,CAAC,EACnH,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,cAAc,EAAE,CA8BjC;AAED,wBAAgB,+BAA+B,CAC7C,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,eAAe,EAAE,cAAc,CAAC,oBAAoB,CAAC,2BAA2B,CAAC,gBAAgB,CAAC,EAClG,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,GACjD,cAAc,CAAC,cAAc,EAAE,CAyHjC"}
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applyPromotionToShippingMethods = exports.getComputedActionsForShippingMethods = void 0;
4
- const utils_1 = require("@medusajs/utils");
3
+ exports.getComputedActionsForShippingMethods = getComputedActionsForShippingMethods;
4
+ exports.applyPromotionToShippingMethods = applyPromotionToShippingMethods;
5
+ const utils_1 = require("@medusajs/framework/utils");
5
6
  const validations_1 = require("../validations");
6
7
  const usage_1 = require("./usage");
7
8
  function getComputedActionsForShippingMethods(promotion, shippingMethodApplicationContext, methodIdPromoValueMap) {
@@ -10,7 +11,7 @@ function getComputedActionsForShippingMethods(promotion, shippingMethodApplicati
10
11
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `"shipping_methods" should be present as an array in the context for computeActions`);
11
12
  }
12
13
  for (const shippingMethodContext of shippingMethodApplicationContext) {
13
- const isPromotionApplicableToItem = (0, validations_1.areRulesValidForContext)(promotion.application_method?.target_rules, shippingMethodContext);
14
+ const isPromotionApplicableToItem = (0, validations_1.areRulesValidForContext)(promotion.application_method?.target_rules, shippingMethodContext, utils_1.ApplicationMethodTargetType.SHIPPING_METHODS);
14
15
  if (!isPromotionApplicableToItem) {
15
16
  continue;
16
17
  }
@@ -18,7 +19,6 @@ function getComputedActionsForShippingMethods(promotion, shippingMethodApplicati
18
19
  }
19
20
  return applyPromotionToShippingMethods(promotion, applicableShippingItems, methodIdPromoValueMap);
20
21
  }
21
- exports.getComputedActionsForShippingMethods = getComputedActionsForShippingMethods;
22
22
  function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPromoValueMap) {
23
23
  const { application_method: applicationMethod } = promotion;
24
24
  const allocation = applicationMethod?.allocation;
@@ -29,13 +29,13 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
29
29
  continue;
30
30
  }
31
31
  const appliedPromoValue = methodIdPromoValueMap.get(method.id) ?? 0;
32
- let promotionValue = applicationMethod?.value ?? 0;
33
- const applicableTotal = method.subtotal - appliedPromoValue;
32
+ let promotionValue = utils_1.MathBN.convert(applicationMethod?.value ?? 0);
33
+ const applicableTotal = utils_1.MathBN.sub(method.subtotal, appliedPromoValue);
34
34
  if (applicationMethod?.type === utils_1.ApplicationMethodType.PERCENTAGE) {
35
- promotionValue = (promotionValue / 100) * applicableTotal;
35
+ promotionValue = utils_1.MathBN.mult(utils_1.MathBN.div(promotionValue, 100), applicableTotal);
36
36
  }
37
- const amount = Math.min(promotionValue, applicableTotal);
38
- if (amount <= 0) {
37
+ const amount = utils_1.MathBN.min(promotionValue, applicableTotal);
38
+ if (utils_1.MathBN.lte(amount, 0)) {
39
39
  continue;
40
40
  }
41
41
  const budgetExceededAction = (0, usage_1.computeActionForBudgetExceeded)(promotion, amount);
@@ -43,7 +43,7 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
43
43
  computedActions.push(budgetExceededAction);
44
44
  continue;
45
45
  }
46
- methodIdPromoValueMap.set(method.id, appliedPromoValue + amount);
46
+ methodIdPromoValueMap.set(method.id, utils_1.MathBN.add(appliedPromoValue, amount));
47
47
  computedActions.push({
48
48
  action: utils_1.ComputedActions.ADD_SHIPPING_METHOD_ADJUSTMENT,
49
49
  shipping_method_id: method.id,
@@ -55,9 +55,9 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
55
55
  if (allocation === utils_1.ApplicationMethodAllocation.ACROSS) {
56
56
  const totalApplicableValue = shippingMethods.reduce((acc, method) => {
57
57
  const appliedPromoValue = methodIdPromoValueMap.get(method.id) ?? 0;
58
- return acc + (method.subtotal ?? 0) - appliedPromoValue;
59
- }, 0);
60
- if (totalApplicableValue <= 0) {
58
+ return utils_1.MathBN.add(acc, utils_1.MathBN.sub(method.subtotal ?? 0, appliedPromoValue));
59
+ }, utils_1.MathBN.convert(0));
60
+ if (utils_1.MathBN.lte(totalApplicableValue, 0)) {
61
61
  return computedActions;
62
62
  }
63
63
  for (const method of shippingMethods) {
@@ -67,15 +67,13 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
67
67
  const promotionValue = applicationMethod?.value ?? 0;
68
68
  const applicableTotal = method.subtotal;
69
69
  const appliedPromoValue = methodIdPromoValueMap.get(method.id) ?? 0;
70
- // TODO: should we worry about precision here?
71
- let applicablePromotionValue = (applicableTotal / totalApplicableValue) * promotionValue -
72
- appliedPromoValue;
70
+ const div = utils_1.MathBN.eq(totalApplicableValue, 0) ? 1 : totalApplicableValue;
71
+ let applicablePromotionValue = utils_1.MathBN.sub(utils_1.MathBN.mult(utils_1.MathBN.div(applicableTotal, div), promotionValue), appliedPromoValue);
73
72
  if (applicationMethod?.type === utils_1.ApplicationMethodType.PERCENTAGE) {
74
- applicablePromotionValue =
75
- (promotionValue / 100) * (applicableTotal - appliedPromoValue);
73
+ applicablePromotionValue = utils_1.MathBN.sub(utils_1.MathBN.mult(utils_1.MathBN.div(promotionValue, 100), applicableTotal), appliedPromoValue);
76
74
  }
77
- const amount = Math.min(applicablePromotionValue, applicableTotal);
78
- if (amount <= 0) {
75
+ const amount = utils_1.MathBN.min(applicablePromotionValue, applicableTotal);
76
+ if (utils_1.MathBN.lte(amount, 0)) {
79
77
  continue;
80
78
  }
81
79
  const budgetExceededAction = (0, usage_1.computeActionForBudgetExceeded)(promotion, amount);
@@ -83,7 +81,7 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
83
81
  computedActions.push(budgetExceededAction);
84
82
  continue;
85
83
  }
86
- methodIdPromoValueMap.set(method.id, appliedPromoValue + amount);
84
+ methodIdPromoValueMap.set(method.id, utils_1.MathBN.add(appliedPromoValue, amount));
87
85
  computedActions.push({
88
86
  action: utils_1.ComputedActions.ADD_SHIPPING_METHOD_ADJUSTMENT,
89
87
  shipping_method_id: method.id,
@@ -94,4 +92,4 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
94
92
  }
95
93
  return computedActions;
96
94
  }
97
- exports.applyPromotionToShippingMethods = applyPromotionToShippingMethods;
95
+ //# sourceMappingURL=shipping-methods.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shipping-methods.js","sourceRoot":"","sources":["../../../src/utils/compute-actions/shipping-methods.ts"],"names":[],"mappings":";;AAYA,oFAkCC;AAED,0EA6HC;AA5KD,qDAOkC;AAClC,gDAAwD;AACxD,mCAAwD;AAExD,SAAgB,oCAAoC,CAClD,SAAsC,EACtC,gCAAmH,EACnH,qBAA0C;IAE1C,MAAM,uBAAuB,GAC3B,EAAE,CAAA;IAEJ,IAAI,CAAC,gCAAgC,EAAE,CAAC;QACtC,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,oFAAoF,CACrF,CAAA;IACH,CAAC;IAED,KAAK,MAAM,qBAAqB,IAAI,gCAAgC,EAAE,CAAC;QACrE,MAAM,2BAA2B,GAAG,IAAA,qCAAuB,EACzD,SAAS,CAAC,kBAAkB,EAAE,YAAa,EAC3C,qBAAqB,EACrB,m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AA;YAED,eAAe,CAAC,IAAI,CAAC;gBACnB,MAAM,EAAE,uBAAe,CAAC,8BAA8B;gBACtD,kBAAkB,EAAE,MAAM,CAAC,EAAE;gBAC7B,MAAM;gBACN,IAAI,EAAE,SAAS,CAAC,IAAK;aACtB,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,eAAe,CAAA;AACxB,CAAC"}
@@ -1,4 +1,3 @@
1
- import { CampaignBudgetExceededAction, ComputeActions, PromotionDTO } from "@medusajs/types";
2
- export declare function canRegisterUsage(computedAction: ComputeActions): boolean;
3
- export declare function computeActionForBudgetExceeded(promotion: PromotionDTO, amount: number): CampaignBudgetExceededAction | void;
1
+ import { BigNumberInput, CampaignBudgetExceededAction, PromotionDTO } from "@medusajs/framework/types";
2
+ export declare function computeActionForBudgetExceeded(promotion: PromotionDTO, amount: BigNumberInput): CampaignBudgetExceededAction | void;
4
3
  //# sourceMappingURL=usage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,4BAA4B,EAC5B,cAAc,EACd,YAAY,EACb,MAAM,iBAAiB,CAAA;AAGxB,wBAAgB,gBAAgB,CAAC,cAAc,EAAE,cAAc,GAAG,OAAO,CAOxE;AAED,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,YAAY,EACvB,MAAM,EAAE,MAAM,GACb,4BAA4B,GAAG,IAAI,CAmBrC"}
1
+ {"version":3,"file":"usage.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/usage.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,4BAA4B,EAC5B,YAAY,EACb,MAAM,2BAA2B,CAAA;AAOlC,wBAAgB,8BAA8B,CAC5C,SAAS,EAAE,YAAY,EACvB,MAAM,EAAE,cAAc,GACrB,4BAA4B,GAAG,IAAI,CAmBrC"}
@@ -1,14 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.computeActionForBudgetExceeded = exports.canRegisterUsage = void 0;
4
- const utils_1 = require("@medusajs/utils");
5
- function canRegisterUsage(computedAction) {
6
- return [
7
- utils_1.ComputedActions.ADD_ITEM_ADJUSTMENT,
8
- utils_1.ComputedActions.ADD_SHIPPING_METHOD_ADJUSTMENT,
9
- ].includes(computedAction.action);
10
- }
11
- exports.canRegisterUsage = canRegisterUsage;
3
+ exports.computeActionForBudgetExceeded = computeActionForBudgetExceeded;
4
+ const utils_1 = require("@medusajs/framework/utils");
12
5
  function computeActionForBudgetExceeded(promotion, amount) {
13
6
  const campaignBudget = promotion.campaign?.budget;
14
7
  if (!campaignBudget) {
@@ -16,13 +9,13 @@ function computeActionForBudgetExceeded(promotion, amount) {
16
9
  }
17
10
  const campaignBudgetUsed = campaignBudget.used ?? 0;
18
11
  const totalUsed = campaignBudget.type === utils_1.CampaignBudgetType.SPEND
19
- ? campaignBudgetUsed + amount
20
- : campaignBudgetUsed + 1;
21
- if (campaignBudget.limit && totalUsed > campaignBudget.limit) {
12
+ ? utils_1.MathBN.add(campaignBudgetUsed, amount)
13
+ : utils_1.MathBN.add(campaignBudgetUsed, 1);
14
+ if (campaignBudget.limit && utils_1.MathBN.gt(totalUsed, campaignBudget.limit)) {
22
15
  return {
23
16
  action: utils_1.ComputedActions.CAMPAIGN_BUDGET_EXCEEDED,
24
17
  code: promotion.code,
25
18
  };
26
19
  }
27
20
  }
28
- exports.computeActionForBudgetExceeded = computeActionForBudgetExceeded;
21
+ //# sourceMappingURL=usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usage.js","sourceRoot":"","sources":["../../../src/utils/compute-actions/usage.ts"],"names":[],"mappings":";;AAWA,wEAsBC;AA5BD,qDAIkC;AAElC,SAAgB,8BAA8B,CAC5C,SAAuB,EACvB,MAAsB;IAEtB,MAAM,cAAc,GAAG,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAA;IAEjD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAM;IACR,CAAC;IAED,MAAM,kBAAkB,GAAG,cAAc,CAAC,IAAI,IAAI,CAAC,CAAA;IACnD,MAAM,SAAS,GACb,cAAc,CAAC,IAAI,KAAK,0BAAkB,CAAC,KAAK;QAC9C,CAAC,CAAC,cAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC;QACxC,CAAC,CAAC,cAAM,CAAC,GAAG,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAA;IAEvC,IAAI,cAAc,CAAC,KAAK,IAAI,cAAM,CAAC,EAAE,CAAC,SAAS,EAAE,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QACvE,OAAO;YACL,MAAM,EAAE,uBAAe,CAAC,wBAAwB;YAChD,IAAI,EAAE,SAAS,CAAC,IAAK;SACtB,CAAA;IACH,CAAC;AACH,CAAC"}
@@ -29,3 +29,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.ComputeActionUtils = void 0;
30
30
  exports.ComputeActionUtils = __importStar(require("./compute-actions"));
31
31
  __exportStar(require("./validations"), exports);
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wEAAuD;AACvD,gDAA6B"}
@@ -1 +1 @@
1
- {"version":3,"file":"application-method.d.ts","sourceRoot":"","sources":["../../../src/utils/validations/application-method.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAA;AAE/E,eAAO,MAAM,4BAA4B,EAAE,MAAM,EAGhD,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,MAAM,EAG1C,CAAA;AAED,eAAO,MAAM,4BAA4B,EAAE,MAAM,EAEhD,CAAA;AAED,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,0BAA0B,GAAG,0BAA0B,EAC7D,SAAS,EAAE,SAAS,QA4GrB"}
1
+ {"version":3,"file":"application-method.d.ts","sourceRoot":"","sources":["../../../src/utils/validations/application-method.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AACnC,OAAO,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,MAAM,QAAQ,CAAA;AAE/E,eAAO,MAAM,4BAA4B,EAAE,MAAM,EAGhD,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,MAAM,EAG1C,CAAA;AAED,eAAO,MAAM,4BAA4B,EAAE,MAAM,EAEhD,CAAA;AAED,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,0BAA0B,GAAG,0BAA0B,EAC7D,SAAS,EAAE,SAAS,QA4GrB"}
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateApplicationMethodAttributes = exports.allowedAllocationForQuantity = exports.allowedAllocationTypes = exports.allowedAllocationTargetTypes = void 0;
4
- const utils_1 = require("@medusajs/utils");
3
+ exports.allowedAllocationForQuantity = exports.allowedAllocationTypes = exports.allowedAllocationTargetTypes = void 0;
4
+ exports.validateApplicationMethodAttributes = validateApplicationMethodAttributes;
5
+ const utils_1 = require("@medusajs/framework/utils");
5
6
  exports.allowedAllocationTargetTypes = [
6
7
  utils_1.ApplicationMethodTargetType.SHIPPING_METHODS,
7
8
  utils_1.ApplicationMethodTargetType.ITEMS,
@@ -20,12 +21,12 @@ function validateApplicationMethodAttributes(data, promotion) {
20
21
  const targetType = data.target_type || applicationMethod?.target_type;
21
22
  const type = data.type || applicationMethod?.type;
22
23
  const applicationMethodType = data.type || applicationMethod?.type;
23
- const value = data.value || applicationMethod.value;
24
+ const value = new utils_1.BigNumber(data.value ?? applicationMethod.value ?? 0);
24
25
  const maxQuantity = data.max_quantity || applicationMethod.max_quantity;
25
26
  const allocation = data.allocation || applicationMethod.allocation;
26
27
  const allTargetTypes = Object.values(utils_1.ApplicationMethodTargetType);
27
28
  if (type === utils_1.ApplicationMethodType.PERCENTAGE &&
28
- (typeof value !== "number" || value <= 0 || value > 100)) {
29
+ (utils_1.MathBN.lte(value, 0) || utils_1.MathBN.gt(value, 100))) {
29
30
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Application Method value should be a percentage number between 0 and 100`);
30
31
  }
31
32
  if (promotion?.type === utils_1.PromotionType.BUYGET) {
@@ -61,4 +62,4 @@ function validateApplicationMethodAttributes(data, promotion) {
61
62
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `application_method.max_quantity is required when application_method.allocation is '${exports.allowedAllocationForQuantity.join(" OR ")}'`);
62
63
  }
63
64
  }
64
- exports.validateApplicationMethodAttributes = validateApplicationMethodAttributes;
65
+ //# sourceMappingURL=application-method.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-method.js","sourceRoot":"","sources":["../../../src/utils/validations/application-method.ts"],"names":[],"mappings":";;;AA4BA,kFA8GC;AA1ID,qDAUkC;AAIrB,QAAA,4BAA4B,GAAa;IACpD,mCAA2B,CAAC,gBAAgB;IAC5C,mCAA2B,CAAC,KAAK;CAClC,CAAA;AAEY,QAAA,sBAAsB,GAAa;IAC9C,mCAA2B,CAAC,MAAM;IAClC,mCAA2B,CAAC,IAAI;CACjC,CAAA;AAEY,QAAA,4BAA4B,GAAa;IACpD,mCAA2B,CAAC,IAAI;CACjC,CAAA;AAED,SAAgB,mCAAmC,CACjD,IAA6D,EAC7D,SAAoB;IAEpB,MAAM,iBAAiB,GAAG,SAAS,EAAE,kBAAkB,IAAI,EAAE,CAAA;IAC7D,MAAM,mBAAmB,GACvB,IAAI,CAAC,sBAAsB,IAAI,iBAAiB,EAAE,sBAAsB,CAAA;IAC1E,MAAM,eAAe,GACnB,IAAI,CAAC,iBAAiB,IAAI,iBAAiB,EAAE,iBAAiB,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AAE,CAAC;QAC3D,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,kDAAkD,kBAAkB,CAAC,IAAI,CACvE,IAAI,CACL,EAAE,CACJ,CAAA;IACH,CAAC;IAED,IACE,UAAU;QACV,oCAA4B,CAAC,QAAQ,CAAC,UAAU,CAAC;QACjD,CAAC,IAAA,iBAAS,EAAC,WAAW,CAAC,EACvB,CAAC;QACD,MAAM,IAAI,mBAAW,CACnB,mBAAW,CAAC,KAAK,CAAC,YAAY,EAC9B,sFAAsF,oCAA4B,CAAC,IAAI,CACrH,MAAM,CACP,GAAG,CACL,CAAA;IACH,CAAC;AACH,CAAC"}
@@ -16,3 +16,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./application-method"), exports);
18
18
  __exportStar(require("./promotion-rule"), exports);
19
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/validations/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAoC;AACpC,mDAAgC"}
@@ -1,6 +1,6 @@
1
- import { PromotionRuleDTO } from "@medusajs/types";
1
+ import { ApplicationMethodTargetTypeValues, PromotionRuleDTO } from "@medusajs/framework/types";
2
2
  import { CreatePromotionRuleDTO } from "../../types";
3
3
  export declare function validatePromotionRuleAttributes(promotionRulesData: CreatePromotionRuleDTO[]): void;
4
- export declare function areRulesValidForContext(rules: PromotionRuleDTO[], context: Record<string, any>): boolean;
4
+ export declare function areRulesValidForContext(rules: PromotionRuleDTO[], context: Record<string, any>, contextScope: ApplicationMethodTargetTypeValues): boolean;
5
5
  export declare function evaluateRuleValueCondition(ruleValues: string[], operator: string, ruleValuesToCheck: string[] | string): boolean;
6
6
  //# sourceMappingURL=promotion-rule.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"promotion-rule.d.ts","sourceRoot":"","sources":["../../../src/utils/validations/promotion-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAA+B,MAAM,iBAAiB,CAAA;AAQ/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAE/C,wBAAgB,+BAA+B,CAC7C,kBAAkB,EAAE,sBAAsB,EAAE,QAiC7C;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,gBAAgB,EAAE,EACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC3B,OAAO,CAgBT;AAED,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,MAAM,EAAE,EACpB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,EAAE,GAAG,MAAM,WAiCrC"}
1
+ {"version":3,"file":"promotion-rule.d.ts","sourceRoot":"","sources":["../../../src/utils/validations/promotion-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,gBAAgB,EAEjB,MAAM,2BAA2B,CAAA;AASlC,OAAO,EAAE,sBAAsB,EAAE,MAAM,QAAQ,CAAA;AAE/C,wBAAgB,+BAA+B,CAC7C,kBAAkB,EAAE,sBAAsB,EAAE,QAiC7C;AAED,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,gBAAgB,EAAE,EACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC5B,YAAY,EAAE,iCAAiC,GAC9C,OAAO,CAmBT;AAkCD,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,MAAM,EAAE,EACpB,QAAQ,EAAE,MAAM,EAChB,iBAAiB,EAAE,MAAM,EAAE,GAAG,MAAM,WAiCrC"}
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.evaluateRuleValueCondition = exports.areRulesValidForContext = exports.validatePromotionRuleAttributes = void 0;
4
- const utils_1 = require("@medusajs/utils");
3
+ exports.validatePromotionRuleAttributes = validatePromotionRuleAttributes;
4
+ exports.areRulesValidForContext = areRulesValidForContext;
5
+ exports.evaluateRuleValueCondition = evaluateRuleValueCondition;
6
+ const utils_1 = require("@medusajs/framework/utils");
5
7
  function validatePromotionRuleAttributes(promotionRulesData) {
6
8
  const errors = [];
7
9
  for (const promotionRuleData of promotionRulesData) {
@@ -25,18 +27,36 @@ function validatePromotionRuleAttributes(promotionRulesData) {
25
27
  return;
26
28
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, errors.join(", "));
27
29
  }
28
- exports.validatePromotionRuleAttributes = validatePromotionRuleAttributes;
29
- function areRulesValidForContext(rules, context) {
30
+ function areRulesValidForContext(rules, context, contextScope) {
30
31
  return rules.every((rule) => {
31
32
  const validRuleValues = rule.values?.map((ruleValue) => ruleValue.value);
32
33
  if (!rule.attribute) {
33
34
  return false;
34
35
  }
35
- const valuesToCheck = (0, utils_1.pickValueFromObject)(rule.attribute, context);
36
+ const valuesToCheck = (0, utils_1.pickValueFromObject)(fetchRuleAttributeForContext(rule.attribute, contextScope), context);
36
37
  return evaluateRuleValueCondition(validRuleValues.filter(utils_1.isString), rule.operator, valuesToCheck);
37
38
  });
38
39
  }
39
- exports.areRulesValidForContext = areRulesValidForContext;
40
+ /*
41
+ The context here can either be either:
42
+ - a cart context
43
+ - an item context under a cart
44
+ - a shipping method context under a cart
45
+
46
+ The rule's attributes are set from the perspective of the cart context. For example: items.product.id
47
+
48
+ When the context here is item or shipping_method, we need to drop the "items."" or "shipping_method."
49
+ from the rule attribute string to accurate pick the values from the context.
50
+ */
51
+ function fetchRuleAttributeForContext(ruleAttribute, contextScope) {
52
+ if (contextScope === utils_1.ApplicationMethodTargetType.ITEMS) {
53
+ ruleAttribute = ruleAttribute.replace(`${utils_1.ApplicationMethodTargetType.ITEMS}.`, "");
54
+ }
55
+ if (contextScope === utils_1.ApplicationMethodTargetType.SHIPPING_METHODS) {
56
+ ruleAttribute = ruleAttribute.replace(`${utils_1.ApplicationMethodTargetType.SHIPPING_METHODS}.`, "");
57
+ }
58
+ return ruleAttribute;
59
+ }
40
60
  function evaluateRuleValueCondition(ruleValues, operator, ruleValuesToCheck) {
41
61
  if (!Array.isArray(ruleValuesToCheck)) {
42
62
  ruleValuesToCheck = [ruleValuesToCheck];
@@ -63,4 +83,4 @@ function evaluateRuleValueCondition(ruleValues, operator, ruleValuesToCheck) {
63
83
  return false;
64
84
  });
65
85
  }
66
- exports.evaluateRuleValueCondition = evaluateRuleValueCondition;
86
+ //# sourceMappingURL=promotion-rule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promotion-rule.js","sourceRoot":"","sources":["../../../src/utils/validations/promotion-rule.ts"],"names":[],"mappings":";;AAeA,0EAkCC;AAED,0DAuBC;AAkCD,gEAoCC;AA3ID,qDAOkC;AAGlC,SAAgB,+BAA+B,CAC7C,kBAA4C;IAE5C,MAAM,MAAM,GAAa,EAAE,CAAA;IAE3B,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,EAAE,CAAC;QACnD,IAAI,CAAC,IAAA,iBAAS,EAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAA;QACtD,CAAC;QAED,IAAI,CAAC,IAAA,iBAAS,EAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC3C,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAA;QACrD,CAAC;QAED,IAAI,IAAA,iBAAS,EAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC1C,MAAM,gBAAgB,GAAkC,MAAM,CAAC,MAAM,CACnE,6BAAqB,CACtB,CAAA;YAED,IAAI,CAAC,gBAAgB,CAAC,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;gBAC3D,MAAM,CAAC,IAAI,CACT,qBACE,iBAAiB,CAAC,QACpB,qCAAqC,gBAAgB,CAAC,IAAI,CAA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AAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,IAAI,gBAAgB,CAAC,CAAA;QACtE,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC,CAAC,CAAA;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@medusajs/promotion",
3
- "version": "0.0.6",
3
+ "version": "1.0.0-rc-20241003153304",
4
4
  "description": "Medusa Promotion module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "files": [
8
- "dist"
8
+ "dist",
9
+ "!dist/**/__tests__",
10
+ "!dist/**/__mocks__",
11
+ "!dist/**/__fixtures__"
9
12
  ],
10
13
  "engines": {
11
- "node": ">=16"
12
- },
13
- "bin": {
14
- "medusa-promotion-seed": "dist/scripts/bin/run-seed.js"
14
+ "node": ">=20"
15
15
  },
16
16
  "repository": {
17
17
  "type": "git",
@@ -26,36 +26,35 @@
26
26
  "scripts": {
27
27
  "watch": "tsc --build --watch",
28
28
  "watch:test": "tsc --build tsconfig.spec.json --watch",
29
- "prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json",
30
- "build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json",
29
+ "resolve:aliases": "tsc --showConfig -p tsconfig.json > tsconfig.resolved.json && tsc-alias -p tsconfig.resolved.json && rimraf tsconfig.resolved.json",
30
+ "build": "rimraf dist && tsc --build && npm run resolve:aliases",
31
31
  "test": "jest --runInBand --passWithNoTests --bail --forceExit -- src",
32
32
  "test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
33
- "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate",
34
- "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial",
35
- "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create",
36
- "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:up",
37
- "orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
33
+ "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:generate",
34
+ "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
35
+ "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
36
+ "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
37
+ "orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
38
38
  },
39
39
  "devDependencies": {
40
+ "@medusajs/framework": "1.0.0-rc-20241003153304",
40
41
  "@mikro-orm/cli": "5.9.7",
41
- "cross-env": "^5.2.1",
42
- "jest": "^29.6.3",
43
- "medusa-test-utils": "^1.1.45",
42
+ "@mikro-orm/core": "5.9.7",
43
+ "@mikro-orm/migrations": "5.9.7",
44
+ "@mikro-orm/postgresql": "5.9.7",
45
+ "@swc/core": "^1.7.28",
46
+ "@swc/jest": "^0.2.36",
47
+ "jest": "^29.7.0",
48
+ "medusa-test-utils": "2.0.0-rc-20241003153304",
44
49
  "rimraf": "^3.0.2",
45
- "ts-jest": "^29.1.1",
46
- "ts-node": "^10.9.1",
47
50
  "tsc-alias": "^1.8.6",
48
- "typescript": "^5.1.6"
51
+ "typescript": "^5.6.2"
49
52
  },
50
- "dependencies": {
51
- "@medusajs/modules-sdk": "^1.12.12",
52
- "@medusajs/types": "^1.11.17",
53
- "@medusajs/utils": "1.11.11",
53
+ "peerDependencies": {
54
+ "@medusajs/framework": "1.0.0-rc-20241003153304",
54
55
  "@mikro-orm/core": "5.9.7",
55
56
  "@mikro-orm/migrations": "5.9.7",
56
57
  "@mikro-orm/postgresql": "5.9.7",
57
- "awilix": "^8.0.0",
58
- "dotenv": "^16.4.5",
59
- "knex": "2.4.2"
58
+ "awilix": "^8.0.1"
60
59
  }
61
60
  }
@@ -1,5 +0,0 @@
1
- import { ExternalModuleDeclaration, InternalModuleDeclaration } from "@medusajs/modules-sdk";
2
- import { IPromotionModuleService, ModulesSdkTypes } from "@medusajs/types";
3
- import { InitializeModuleInjectableDependencies } from "../types";
4
- export declare const initialize: (options?: ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions | ExternalModuleDeclaration | InternalModuleDeclaration, injectedDependencies?: InitializeModuleInjectableDependencies) => Promise<IPromotionModuleService>;
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/initialize/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EAI1B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,sCAAsC,EAAE,MAAM,UAAU,CAAA;AAEjE,eAAO,MAAM,UAAU,aAEjB,gBAAgB,8BAA8B,GAC9C,gBAAgB,6CAA6C,GAC7D,yBAAyB,GACzB,yBAAyB,yBACN,sCAAsC,KAC5D,QAAQ,uBAAuB,CAYjC,CAAA"}
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initialize = void 0;
4
- const modules_sdk_1 = require("@medusajs/modules-sdk");
5
- const module_definition_1 = require("../module-definition");
6
- const initialize = async (options, injectedDependencies) => {
7
- const loaded = await modules_sdk_1.MedusaModule.bootstrap({
8
- moduleKey: modules_sdk_1.Modules.PROMOTION,
9
- defaultPath: modules_sdk_1.MODULE_PACKAGE_NAMES[modules_sdk_1.Modules.PROMOTION],
10
- declaration: options,
11
- injectedDependencies,
12
- moduleExports: module_definition_1.moduleDefinition,
13
- });
14
- return loaded[modules_sdk_1.Modules.PROMOTION];
15
- };
16
- exports.initialize = initialize;
@@ -1,5 +0,0 @@
1
- import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk";
2
- import { ModulesSdkTypes } from "@medusajs/types";
3
- declare const _default: ({ options, container, logger, }: LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions>, moduleDeclaration?: InternalModuleDeclaration) => Promise<void>;
4
- export default _default;
5
- //# sourceMappingURL=connection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/loaders/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,aAAa,EAEd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;0DAU5C,cACC,gBAAgB,8BAA8B,GAC9C,gBAAgB,6CAA6C,CAChE,sBACmB,yBAAyB,KAC5C,QAAQ,IAAI,CAAC;AAVhB,wBAuBC"}
@@ -1,41 +0,0 @@
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 __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const modules_sdk_1 = require("@medusajs/modules-sdk");
27
- const utils_1 = require("@medusajs/utils");
28
- const PromotionModels = __importStar(require("../models"));
29
- exports.default = async ({ options, container, logger, }, moduleDeclaration) => {
30
- const entities = Object.values(PromotionModels);
31
- const pathToMigrations = __dirname + "/../migrations";
32
- await utils_1.ModulesSdkUtils.mikroOrmConnectionLoader({
33
- moduleName: modules_sdk_1.Modules.PROMOTION,
34
- entities,
35
- container,
36
- options,
37
- moduleDeclaration,
38
- logger,
39
- pathToMigrations,
40
- });
41
- };
@@ -1,3 +0,0 @@
1
- declare const _default: ({ container, options }: import("@medusajs/types").LoaderOptions) => Promise<void>;
2
- export default _default;
3
- //# sourceMappingURL=container.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/loaders/container.ts"],"names":[],"mappings":";AAKA,wBAIE"}