@medusajs/promotion 0.0.5-snapshot-20240717160031 → 0.0.5-snapshot-20240718083016

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. package/dist/index.d.ts +4 -5
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +20 -5
  4. package/dist/initialize/index.d.ts +5 -0
  5. package/dist/initialize/index.d.ts.map +1 -0
  6. package/dist/initialize/index.js +16 -0
  7. package/dist/joiner-config.d.ts +8 -1
  8. package/dist/joiner-config.d.ts.map +1 -1
  9. package/dist/joiner-config.js +35 -4
  10. package/dist/loaders/connection.d.ts +5 -0
  11. package/dist/loaders/connection.d.ts.map +1 -0
  12. package/dist/loaders/connection.js +41 -0
  13. package/dist/loaders/container.d.ts +3 -0
  14. package/dist/loaders/container.d.ts.map +1 -0
  15. package/dist/loaders/container.js +34 -0
  16. package/dist/loaders/index.d.ts +3 -0
  17. package/dist/loaders/index.d.ts.map +1 -0
  18. package/dist/loaders/index.js +18 -0
  19. package/dist/migrations/Migration20240227120221.d.ts.map +1 -1
  20. package/dist/migrations/Migration20240227120221.js +2 -10
  21. package/dist/models/application-method.d.ts +6 -4
  22. package/dist/models/application-method.d.ts.map +1 -1
  23. package/dist/models/application-method.js +6 -16
  24. package/dist/models/campaign-budget.d.ts +5 -6
  25. package/dist/models/campaign-budget.d.ts.map +1 -1
  26. package/dist/models/campaign-budget.js +4 -8
  27. package/dist/models/campaign.d.ts +4 -3
  28. package/dist/models/campaign.d.ts.map +1 -1
  29. package/dist/models/campaign.js +13 -10
  30. package/dist/models/promotion-rule-value.d.ts +1 -2
  31. package/dist/models/promotion-rule-value.d.ts.map +1 -1
  32. package/dist/models/promotion-rule-value.js +1 -1
  33. package/dist/models/promotion-rule.d.ts +1 -1
  34. package/dist/models/promotion-rule.d.ts.map +1 -1
  35. package/dist/models/promotion.d.ts +4 -5
  36. package/dist/models/promotion.d.ts.map +1 -1
  37. package/dist/models/promotion.js +4 -8
  38. package/dist/module-definition.d.ts +5 -0
  39. package/dist/module-definition.d.ts.map +1 -0
  40. package/dist/module-definition.js +50 -0
  41. package/dist/repositories/campaign.d.ts +16 -0
  42. package/dist/repositories/campaign.d.ts.map +1 -0
  43. package/dist/repositories/campaign.js +90 -0
  44. package/dist/repositories/index.d.ts +3 -0
  45. package/dist/repositories/index.d.ts.map +1 -0
  46. package/dist/repositories/index.js +7 -0
  47. package/dist/services/promotion-module.d.ts +26 -40
  48. package/dist/services/promotion-module.d.ts.map +1 -1
  49. package/dist/services/promotion-module.js +62 -189
  50. package/dist/types/application-method.d.ts +10 -12
  51. package/dist/types/application-method.d.ts.map +1 -1
  52. package/dist/types/campaign-budget.d.ts +6 -8
  53. package/dist/types/campaign-budget.d.ts.map +1 -1
  54. package/dist/types/campaign.d.ts +8 -6
  55. package/dist/types/campaign.d.ts.map +1 -1
  56. package/dist/types/promotion.d.ts +2 -2
  57. package/dist/types/promotion.d.ts.map +1 -1
  58. package/dist/utils/compute-actions/buy-get.d.ts +2 -2
  59. package/dist/utils/compute-actions/buy-get.d.ts.map +1 -1
  60. package/dist/utils/compute-actions/buy-get.js +12 -12
  61. package/dist/utils/compute-actions/line-items.d.ts.map +1 -1
  62. package/dist/utils/compute-actions/line-items.js +4 -4
  63. package/dist/utils/compute-actions/shipping-methods.d.ts +2 -2
  64. package/dist/utils/compute-actions/shipping-methods.d.ts.map +1 -1
  65. package/dist/utils/compute-actions/shipping-methods.js +17 -14
  66. package/dist/utils/compute-actions/usage.d.ts +2 -2
  67. package/dist/utils/compute-actions/usage.d.ts.map +1 -1
  68. package/dist/utils/compute-actions/usage.js +3 -3
  69. package/dist/utils/validations/application-method.d.ts.map +1 -1
  70. package/dist/utils/validations/application-method.js +2 -2
  71. package/package.json +13 -8
  72. package/dist/migrations/Migration20240617102917.d.ts +0 -6
  73. package/dist/migrations/Migration20240617102917.d.ts.map +0 -1
  74. package/dist/migrations/Migration20240617102917.js +0 -15
  75. package/dist/migrations/Migration20240624153824.d.ts +0 -6
  76. package/dist/migrations/Migration20240624153824.d.ts.map +0 -1
  77. package/dist/migrations/Migration20240624153824.js +0 -15
@@ -17,29 +17,29 @@ function getComputedActionsForBuyGet(promotion, itemsContext, methodIdPromoValue
17
17
  if (!Array.isArray(buyRules) || !Array.isArray(targetRules)) {
18
18
  return [];
19
19
  }
20
- const validQuantity = utils_1.MathBN.sum(...itemsContext
20
+ const validQuantity = itemsContext
21
21
  .filter((item) => (0, validations_1.areRulesValidForContext)(buyRules, item))
22
- .map((item) => item.quantity));
22
+ .reduce((acc, next) => acc + next.quantity, 0);
23
23
  if (!buyRulesMinQuantity ||
24
24
  !applyToQuantity ||
25
- utils_1.MathBN.gt(buyRulesMinQuantity, validQuantity)) {
25
+ buyRulesMinQuantity > validQuantity) {
26
26
  return [];
27
27
  }
28
28
  const validItemsForTargetRules = itemsContext
29
29
  .filter((item) => (0, validations_1.areRulesValidForContext)(targetRules, item))
30
30
  .filter((item) => (0, utils_1.isPresent)(item.subtotal) && (0, utils_1.isPresent)(item.quantity))
31
31
  .sort((a, b) => {
32
- const aPrice = utils_1.MathBN.div(a.subtotal, a.quantity);
33
- const bPrice = utils_1.MathBN.div(b.subtotal, b.quantity);
34
- return utils_1.MathBN.lt(bPrice, aPrice) ? -1 : 1;
32
+ const aPrice = a.subtotal / a.quantity;
33
+ const bPrice = b.subtotal / b.quantity;
34
+ return bPrice - aPrice;
35
35
  });
36
- let remainingQtyToApply = utils_1.MathBN.convert(applyToQuantity);
36
+ let remainingQtyToApply = applyToQuantity;
37
37
  for (const method of validItemsForTargetRules) {
38
38
  const appliedPromoValue = methodIdPromoValueMap.get(method.id) ?? 0;
39
- const multiplier = utils_1.MathBN.min(method.quantity, remainingQtyToApply);
40
- const amount = utils_1.MathBN.mult(utils_1.MathBN.div(method.subtotal, method.quantity), multiplier);
41
- const newRemainingQtyToApply = utils_1.MathBN.sub(remainingQtyToApply, multiplier);
42
- if (utils_1.MathBN.lt(newRemainingQtyToApply, 0) || utils_1.MathBN.lte(amount, 0)) {
39
+ const multiplier = Math.min(method.quantity, remainingQtyToApply);
40
+ const amount = (method.subtotal / method.quantity) * multiplier;
41
+ const newRemainingQtyToApply = remainingQtyToApply - multiplier;
42
+ if (newRemainingQtyToApply < 0 || amount <= 0) {
43
43
  break;
44
44
  }
45
45
  else {
@@ -50,7 +50,7 @@ function getComputedActionsForBuyGet(promotion, itemsContext, methodIdPromoValue
50
50
  computedActions.push(budgetExceededAction);
51
51
  continue;
52
52
  }
53
- methodIdPromoValueMap.set(method.id, utils_1.MathBN.add(appliedPromoValue, amount));
53
+ methodIdPromoValueMap.set(method.id, appliedPromoValue + amount);
54
54
  computedActions.push({
55
55
  action: utils_1.ComputedActions.ADD_ITEM_ADJUSTMENT,
56
56
  item_id: method.id,
@@ -1 +1 @@
1
- {"version":3,"file":"line-items.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/line-items.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EAEjC,cAAc,EACf,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAKL,2BAA2B,IAAI,UAAU,EAE1C,MAAM,iBAAiB,CAAA;AAgBxB,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,KAAK,EAAE,cAAc,CAAC,oBAAoB,CAAC,UAAU,CAAC,KAAK,CAAC,EAC5D,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,kBAAkB,CAAC,EAAE,iCAAiC,GACrD,cAAc,CAAC,cAAc,EAAE,CASjC;AAED,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,eAAe,EAAE,cAAc,CAAC,oBAAoB,CAAC,UAAU,CAAC,gBAAgB,CAAC,EACjF,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,cAAc,CAAC,cAAc,EAAE,CAIjC;AAED,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,sBAAsB,EAAE,cAAc,CAAC,oBAAoB,EAC3D,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,cAAc,EAAE,CAOjC"}
1
+ {"version":3,"file":"line-items.d.ts","sourceRoot":"","sources":["../../../src/utils/compute-actions/line-items.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iCAAiC,EACjC,cAAc,EACf,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAIL,2BAA2B,IAAI,UAAU,EAE1C,MAAM,iBAAiB,CAAA;AAgBxB,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,KAAK,EAAE,cAAc,CAAC,oBAAoB,CAAC,UAAU,CAAC,KAAK,CAAC,EAC5D,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACzC,kBAAkB,CAAC,EAAE,iCAAiC,GACrD,cAAc,CAAC,cAAc,EAAE,CASjC;AAED,wBAAgB,oCAAoC,CAClD,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,eAAe,EAAE,cAAc,CAAC,oBAAoB,CAAC,UAAU,CAAC,gBAAgB,CAAC,EACjF,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACxC,cAAc,CAAC,cAAc,EAAE,CAIjC;AAED,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,cAAc,CAAC,YAAY,EACtC,sBAAsB,EAAE,cAAc,CAAC,oBAAoB,EAC3D,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,cAAc,EAAE,CAOjC"}
@@ -32,9 +32,9 @@ function applyPromotionToItems(promotion, items, appliedPromotionsMap, allocatio
32
32
  const isTargetShippingMethod = target === utils_1.ApplicationMethodTargetType.SHIPPING_METHODS;
33
33
  const isTargetLineItems = target === utils_1.ApplicationMethodTargetType.ITEMS;
34
34
  const isTargetOrder = target === utils_1.ApplicationMethodTargetType.ORDER;
35
- let lineItemsTotal = utils_1.MathBN.convert(0);
35
+ let lineItemsTotal = 0;
36
36
  if (allocation === utils_1.ApplicationMethodAllocation.ACROSS) {
37
- 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));
37
+ lineItemsTotal = applicableItems.reduce((acc, item) => acc + item.subtotal - (appliedPromotionsMap.get(item.id) ?? 0), 0);
38
38
  }
39
39
  for (const item of applicableItems) {
40
40
  const appliedPromoValue = appliedPromotionsMap.get(item.id) ?? 0;
@@ -51,7 +51,7 @@ function applyPromotionToItems(promotion, items, appliedPromotionsMap, allocatio
51
51
  type: applicationMethod?.type,
52
52
  allocation,
53
53
  }, lineItemsTotal);
54
- if (utils_1.MathBN.lte(amount, 0)) {
54
+ if (amount <= 0) {
55
55
  continue;
56
56
  }
57
57
  const budgetExceededAction = (0, usage_1.computeActionForBudgetExceeded)(promotion, amount);
@@ -59,7 +59,7 @@ function applyPromotionToItems(promotion, items, appliedPromotionsMap, allocatio
59
59
  computedActions.push(budgetExceededAction);
60
60
  continue;
61
61
  }
62
- appliedPromotionsMap.set(item.id, utils_1.MathBN.add(appliedPromoValue, amount));
62
+ appliedPromotionsMap.set(item.id, appliedPromoValue + amount);
63
63
  if (isTargetLineItems || isTargetOrder) {
64
64
  computedActions.push({
65
65
  action: utils_1.ComputedActions.ADD_ITEM_ADJUSTMENT,
@@ -1,5 +1,5 @@
1
- import { BigNumberInput, PromotionTypes } from "@medusajs/types";
1
+ import { PromotionTypes } from "@medusajs/types";
2
2
  import { ApplicationMethodTargetType } from "@medusajs/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, BigNumberInput>): PromotionTypes.ComputeActions[];
4
+ export declare function applyPromotionToShippingMethods(promotion: PromotionTypes.PromotionDTO, shippingMethods: PromotionTypes.ComputeActionContext[ApplicationMethodTargetType.SHIPPING_METHODS], methodIdPromoValueMap: Map<string, number>): 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,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAChE,OAAO,EAEL,2BAA2B,EAK5B,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,cAAc,CAAC,GACjD,cAAc,CAAC,cAAc,EAAE,CA2HjC"}
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"}
@@ -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 = utils_1.MathBN.convert(applicationMethod?.value ?? 0);
33
- const applicableTotal = utils_1.MathBN.sub(method.subtotal, appliedPromoValue);
32
+ let promotionValue = applicationMethod?.value ?? 0;
33
+ const applicableTotal = method.subtotal - appliedPromoValue;
34
34
  if (applicationMethod?.type === utils_1.ApplicationMethodType.PERCENTAGE) {
35
- promotionValue = utils_1.MathBN.mult(utils_1.MathBN.div(promotionValue, 100), applicableTotal);
35
+ promotionValue = (promotionValue / 100) * applicableTotal;
36
36
  }
37
- const amount = utils_1.MathBN.min(promotionValue, applicableTotal);
38
- if (utils_1.MathBN.lte(amount, 0)) {
37
+ const amount = Math.min(promotionValue, applicableTotal);
38
+ if (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, utils_1.MathBN.add(appliedPromoValue, amount));
46
+ methodIdPromoValueMap.set(method.id, 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 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)) {
58
+ return acc + (method.subtotal ?? 0) - appliedPromoValue;
59
+ }, 0);
60
+ if (totalApplicableValue <= 0) {
61
61
  return computedActions;
62
62
  }
63
63
  for (const method of shippingMethods) {
@@ -67,12 +67,15 @@ 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
- let applicablePromotionValue = utils_1.MathBN.sub(utils_1.MathBN.mult(utils_1.MathBN.div(applicableTotal, totalApplicableValue), promotionValue), appliedPromoValue);
70
+ // TODO: should we worry about precision here?
71
+ let applicablePromotionValue = (applicableTotal / totalApplicableValue) * promotionValue -
72
+ appliedPromoValue;
71
73
  if (applicationMethod?.type === utils_1.ApplicationMethodType.PERCENTAGE) {
72
- applicablePromotionValue = utils_1.MathBN.sub(utils_1.MathBN.mult(utils_1.MathBN.div(promotionValue, 100), applicableTotal), appliedPromoValue);
74
+ applicablePromotionValue =
75
+ (promotionValue / 100) * (applicableTotal - appliedPromoValue);
73
76
  }
74
- const amount = utils_1.MathBN.min(applicablePromotionValue, applicableTotal);
75
- if (utils_1.MathBN.lte(amount, 0)) {
77
+ const amount = Math.min(applicablePromotionValue, applicableTotal);
78
+ if (amount <= 0) {
76
79
  continue;
77
80
  }
78
81
  const budgetExceededAction = (0, usage_1.computeActionForBudgetExceeded)(promotion, amount);
@@ -80,7 +83,7 @@ function applyPromotionToShippingMethods(promotion, shippingMethods, methodIdPro
80
83
  computedActions.push(budgetExceededAction);
81
84
  continue;
82
85
  }
83
- methodIdPromoValueMap.set(method.id, utils_1.MathBN.add(appliedPromoValue, amount));
86
+ methodIdPromoValueMap.set(method.id, appliedPromoValue + amount);
84
87
  computedActions.push({
85
88
  action: utils_1.ComputedActions.ADD_SHIPPING_METHOD_ADJUSTMENT,
86
89
  shipping_method_id: method.id,
@@ -1,4 +1,4 @@
1
- import { BigNumberInput, CampaignBudgetExceededAction, ComputeActions, PromotionDTO } from "@medusajs/types";
1
+ import { CampaignBudgetExceededAction, ComputeActions, PromotionDTO } from "@medusajs/types";
2
2
  export declare function canRegisterUsage(computedAction: ComputeActions): boolean;
3
- export declare function computeActionForBudgetExceeded(promotion: PromotionDTO, amount: BigNumberInput): CampaignBudgetExceededAction | void;
3
+ export declare function computeActionForBudgetExceeded(promotion: PromotionDTO, amount: number): CampaignBudgetExceededAction | void;
4
4
  //# 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,cAAc,EACd,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,cAAc,GACrB,4BAA4B,GAAG,IAAI,CAmBrC"}
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"}
@@ -16,9 +16,9 @@ function computeActionForBudgetExceeded(promotion, amount) {
16
16
  }
17
17
  const campaignBudgetUsed = campaignBudget.used ?? 0;
18
18
  const totalUsed = campaignBudget.type === utils_1.CampaignBudgetType.SPEND
19
- ? utils_1.MathBN.add(campaignBudgetUsed, amount)
20
- : utils_1.MathBN.add(campaignBudgetUsed, 1);
21
- if (campaignBudget.limit && utils_1.MathBN.gt(totalUsed, campaignBudget.limit)) {
19
+ ? campaignBudgetUsed + amount
20
+ : campaignBudgetUsed + 1;
21
+ if (campaignBudget.limit && totalUsed > campaignBudget.limit) {
22
22
  return {
23
23
  action: utils_1.ComputedActions.CAMPAIGN_BUDGET_EXCEEDED,
24
24
  code: promotion.code,
@@ -1 +1 @@
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
+ {"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"}
@@ -20,12 +20,12 @@ function validateApplicationMethodAttributes(data, promotion) {
20
20
  const targetType = data.target_type || applicationMethod?.target_type;
21
21
  const type = data.type || applicationMethod?.type;
22
22
  const applicationMethodType = data.type || applicationMethod?.type;
23
- const value = new utils_1.BigNumber(data.value ?? applicationMethod.value ?? 0);
23
+ const value = data.value || applicationMethod.value;
24
24
  const maxQuantity = data.max_quantity || applicationMethod.max_quantity;
25
25
  const allocation = data.allocation || applicationMethod.allocation;
26
26
  const allTargetTypes = Object.values(utils_1.ApplicationMethodTargetType);
27
27
  if (type === utils_1.ApplicationMethodType.PERCENTAGE &&
28
- (utils_1.MathBN.lte(value, 0) || utils_1.MathBN.gt(value, 100))) {
28
+ (typeof value !== "number" || value <= 0 || value > 100)) {
29
29
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Application Method value should be a percentage number between 0 and 100`);
30
30
  }
31
31
  if (promotion?.type === utils_1.PromotionType.BUYGET) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@medusajs/promotion",
3
- "version": "0.0.5-snapshot-20240717160031",
3
+ "version": "0.0.5-snapshot-20240718083016",
4
4
  "description": "Medusa Promotion module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -8,7 +8,10 @@
8
8
  "dist"
9
9
  ],
10
10
  "engines": {
11
- "node": ">=20"
11
+ "node": ">=16"
12
+ },
13
+ "bin": {
14
+ "medusa-promotion-seed": "dist/scripts/bin/run-seed.js"
12
15
  },
13
16
  "repository": {
14
17
  "type": "git",
@@ -34,12 +37,10 @@
34
37
  "orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
35
38
  },
36
39
  "devDependencies": {
37
- "@medusajs/modules-sdk": "1.13.0-snapshot-20240717160031",
38
- "@medusajs/types": "1.12.0-snapshot-20240717160031",
39
40
  "@mikro-orm/cli": "5.9.7",
40
41
  "cross-env": "^5.2.1",
41
- "jest": "^29.7.0",
42
- "medusa-test-utils": "1.1.45-snapshot-20240717160031",
42
+ "jest": "^29.6.3",
43
+ "medusa-test-utils": "1.1.45-snapshot-20240718083016",
43
44
  "rimraf": "^3.0.2",
44
45
  "ts-jest": "^29.1.1",
45
46
  "ts-node": "^10.9.1",
@@ -47,10 +48,14 @@
47
48
  "typescript": "^5.1.6"
48
49
  },
49
50
  "dependencies": {
50
- "@medusajs/utils": "1.12.0-snapshot-20240717160031",
51
+ "@medusajs/modules-sdk": "1.12.12-snapshot-20240718083016",
52
+ "@medusajs/types": "1.11.17-snapshot-20240718083016",
53
+ "@medusajs/utils": "1.11.10-snapshot-20240718083016",
51
54
  "@mikro-orm/core": "5.9.7",
52
55
  "@mikro-orm/migrations": "5.9.7",
53
56
  "@mikro-orm/postgresql": "5.9.7",
54
- "awilix": "^8.0.0"
57
+ "awilix": "^8.0.0",
58
+ "dotenv": "^16.4.5",
59
+ "knex": "2.4.2"
55
60
  }
56
61
  }
@@ -1,6 +0,0 @@
1
- import { Migration } from "@mikro-orm/migrations";
2
- export declare class Migration20240617102917 extends Migration {
3
- up(): Promise<void>;
4
- down(): Promise<void>;
5
- }
6
- //# sourceMappingURL=Migration20240617102917.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Migration20240617102917.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20240617102917.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,qBAAa,uBAAwB,SAAQ,SAAS;IAC9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IAUnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ5B"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Migration20240617102917 = void 0;
4
- const migrations_1 = require("@mikro-orm/migrations");
5
- class Migration20240617102917 extends migrations_1.Migration {
6
- async up() {
7
- this.addSql('alter table "promotion_application_method" alter column "currency_code" type text using ("currency_code"::text);');
8
- this.addSql('alter table "promotion_application_method" alter column "currency_code" drop not null;');
9
- }
10
- async down() {
11
- this.addSql('alter table "promotion_application_method" alter column "currency_code" type text using ("currency_code"::text);');
12
- this.addSql('alter table "promotion_application_method" alter column "currency_code" set not null;');
13
- }
14
- }
15
- exports.Migration20240617102917 = Migration20240617102917;
@@ -1,6 +0,0 @@
1
- import { Migration } from "@mikro-orm/migrations";
2
- export declare class Migration20240624153824 extends Migration {
3
- up(): Promise<void>;
4
- down(): Promise<void>;
5
- }
6
- //# sourceMappingURL=Migration20240624153824.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Migration20240624153824.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20240624153824.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,qBAAa,uBAAwB,SAAQ,SAAS;IAC9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;IASnB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ5B"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Migration20240624153824 = void 0;
4
- const migrations_1 = require("@mikro-orm/migrations");
5
- class Migration20240624153824 extends migrations_1.Migration {
6
- async up() {
7
- this.addSql('alter table if exists "promotion_campaign" drop constraint if exists "IDX_campaign_identifier_unique";');
8
- this.addSql('CREATE UNIQUE INDEX IF NOT EXISTS "IDX_promotion_campaign_campaign_identifier_unique" ON "promotion_campaign" (campaign_identifier) WHERE deleted_at IS NULL;');
9
- }
10
- async down() {
11
- this.addSql('drop index if exists "IDX_promotion_campaign_campaign_identifier_unique";');
12
- this.addSql('alter table if exists "promotion_campaign" add constraint "IDX_campaign_identifier_unique" unique ("campaign_identifier");');
13
- }
14
- }
15
- exports.Migration20240624153824 = Migration20240624153824;