@medusajs/promotion 0.0.5-snapshot-20240904104726 → 0.0.5-snapshot-20240905140403
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/services/promotion-module.d.ts +1 -0
- package/dist/services/promotion-module.d.ts.map +1 -1
- package/dist/services/promotion-module.js +77 -9
- package/dist/utils/compute-actions/usage.d.ts +1 -2
- package/dist/utils/compute-actions/usage.d.ts.map +1 -1
- package/dist/utils/compute-actions/usage.js +1 -8
- package/package.json +4 -4
@@ -42,6 +42,7 @@ export default class PromotionModuleService extends PromotionModuleService_base
|
|
42
42
|
constructor({ baseRepository, promotionService, applicationMethodService, promotionRuleService, promotionRuleValueService, campaignService, campaignBudgetService, }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
|
43
43
|
__joinerConfig(): ModuleJoinerConfig;
|
44
44
|
registerUsage(computedActions: PromotionTypes.UsageComputedActions[], sharedContext?: Context): Promise<void>;
|
45
|
+
revertUsage(computedActions: PromotionTypes.UsageComputedActions[], sharedContext?: Context): Promise<void>;
|
45
46
|
computeActions(promotionCodes: string[], applicationContext: PromotionTypes.ComputeActionContext, options?: PromotionTypes.ComputeActionOptions, sharedContext?: Context): Promise<PromotionTypes.ComputeActions[]>;
|
46
47
|
createPromotions(data: PromotionTypes.CreatePromotionDTO, sharedContext?: Context): Promise<PromotionTypes.PromotionDTO>;
|
47
48
|
createPromotions(data: PromotionTypes.CreatePromotionDTO[], sharedContext?: Context): Promise<PromotionTypes.PromotionDTO[]>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"promotion-module.d.ts","sourceRoot":"","sources":["../../src/services/promotion-module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,OAAO,EACP,GAAG,EACH,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACf,MAAM,iBAAiB,CAAA;AAoBxB,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,cAAc,EACd,SAAS,EACT,aAAa,EACb,kBAAkB,EACnB,MAAM,SAA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Ae,CAAC,sBAAsB,CAAC,aAAa,CAAC,CAAA;IACtF,SAAS,CAAC,0BAA0B,EAAE,eAAe,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAA;IAChG,SAAS,CAAC,gBAAgB,EAAE,eAAe,CAAC,sBAAsB,CAAC,QAAQ,CAAC,CAAA;IAC5E,SAAS,CAAC,sBAAsB,EAAE,eAAe,CAAC,sBAAsB,CAAC,cAAc,CAAC,CAAA;gBAGtF,EACE,cAAc,EACd,gBAAgB,EAChB,wBAAwB,EACxB,oBAAoB,EACpB,yBAAyB,EACzB,eAAe,EACf,qBAAqB,GACtB,EAAE,oBAAoB,EACJ,iBAAiB,EAAE,yBAAyB;IAcjE,cAAc,IAAI,kBAAkB;IAK9B,aAAa,CACjB,eAAe,EAAE,cAAc,CAAC,oBAAoB,EAAE,EACrC,aAAa,GAAE,OAAY,GAC3C,OAAO,CAAC,IAAI,CAAC;
|
1
|
+
{"version":3,"file":"promotion-module.d.ts","sourceRoot":"","sources":["../../src/services/promotion-module.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,OAAO,EACP,GAAG,EACH,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,EACf,cAAc,EACf,MAAM,iBAAiB,CAAA;AAoBxB,OAAO,EACL,iBAAiB,EACjB,QAAQ,EACR,cAAc,EACd,SAAS,EACT,aAAa,EACb,kBAAkB,EACnB,MAAM,SAAS,CAAA;AAChB,OAAO,EACL,0BAA0B,EAU3B,MAAM,QAAQ,CAAA;AAWf,KAAK,oBAAoB,GAAG;IAC1B,cAAc,EAAE,GAAG,CAAC,iBAAiB,CAAA;IACrC,gBAAgB,EAAE,eAAe,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAA;IAC7D,wBAAwB,EAAE,eAAe,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAA;IACrE,oBAAoB,EAAE,eAAe,CAAC,sBAAsB,CAAC,GAAG,CAAC,CAAA;IACjE,yBAAyB,EAAE,eAA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3B,IAAI,EAAE,cAAc,CAAC,0BAA0B,EAC/C,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;cAWb,wBAAwB,CACtC,IAAI,EAAE,cAAc,CAAC,0BAA0B,EAC9B,aAAa,GAAE,OAAY;IAmDxC,4BAA4B,CAChC,IAAI,EAAE,cAAc,CAAC,0BAA0B,EAC/C,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;cAOb,6BAA6B,CAC3C,IAAI,EAAE,cAAc,CAAC,0BAA0B,EAC9B,aAAa,GAAE,OAAY;CAiC/C"}
|
@@ -45,14 +45,19 @@ class PromotionModuleService extends (0, utils_1.MedusaService)({
|
|
45
45
|
const promotionCodes = computedActions
|
46
46
|
.map((computedAction) => computedAction.code)
|
47
47
|
.filter(Boolean);
|
48
|
-
const
|
48
|
+
const campaignBudgetMap = new Map();
|
49
49
|
const promotionCodeUsageMap = new Map();
|
50
|
-
const existingPromotions = await this.listPromotions({ code: promotionCodes }, {
|
50
|
+
const existingPromotions = await this.listPromotions({ code: promotionCodes }, {
|
51
|
+
relations: ["campaign", "campaign.budget"],
|
52
|
+
take: null,
|
53
|
+
}, sharedContext);
|
54
|
+
for (const promotion of existingPromotions) {
|
55
|
+
if (promotion.campaign?.budget) {
|
56
|
+
campaignBudgetMap.set(promotion.campaign?.budget.id, promotion.campaign?.budget);
|
57
|
+
}
|
58
|
+
}
|
51
59
|
const existingPromotionsMap = new Map(existingPromotions.map((promotion) => [promotion.code, promotion]));
|
52
60
|
for (let computedAction of computedActions) {
|
53
|
-
if (!_utils_1.ComputeActionUtils.canRegisterUsage(computedAction)) {
|
54
|
-
continue;
|
55
|
-
}
|
56
61
|
const promotion = existingPromotionsMap.get(computedAction.code);
|
57
62
|
if (!promotion) {
|
58
63
|
continue;
|
@@ -62,13 +67,16 @@ class PromotionModuleService extends (0, utils_1.MedusaService)({
|
|
62
67
|
continue;
|
63
68
|
}
|
64
69
|
if (campaignBudget.type === utils_1.CampaignBudgetType.SPEND) {
|
65
|
-
const campaignBudgetData =
|
70
|
+
const campaignBudgetData = campaignBudgetMap.get(campaignBudget.id);
|
71
|
+
if (!campaignBudgetData) {
|
72
|
+
continue;
|
73
|
+
}
|
66
74
|
campaignBudgetData.used = utils_1.MathBN.add(campaignBudgetData.used ?? 0, computedAction.amount);
|
67
75
|
if (campaignBudget.limit &&
|
68
76
|
utils_1.MathBN.gt(campaignBudgetData.used, campaignBudget.limit)) {
|
69
77
|
continue;
|
70
78
|
}
|
71
|
-
|
79
|
+
campaignBudgetMap.set(campaignBudget.id, campaignBudgetData);
|
72
80
|
}
|
73
81
|
if (campaignBudget.type === utils_1.CampaignBudgetType.USAGE) {
|
74
82
|
const promotionAlreadyUsed = promotionCodeUsageMap.get(promotion.code) || false;
|
@@ -83,11 +91,63 @@ class PromotionModuleService extends (0, utils_1.MedusaService)({
|
|
83
91
|
utils_1.MathBN.gt(campaignBudgetData.used, campaignBudget.limit)) {
|
84
92
|
continue;
|
85
93
|
}
|
86
|
-
|
94
|
+
campaignBudgetMap.set(campaignBudget.id, campaignBudgetData);
|
95
|
+
promotionCodeUsageMap.set(promotion.code, true);
|
96
|
+
}
|
97
|
+
const campaignBudgetsData = [];
|
98
|
+
for (const [_, campaignBudgetData] of campaignBudgetMap) {
|
99
|
+
campaignBudgetsData.push(campaignBudgetData);
|
100
|
+
}
|
101
|
+
await this.campaignBudgetService_.update(campaignBudgetsData, sharedContext);
|
102
|
+
}
|
103
|
+
}
|
104
|
+
async revertUsage(computedActions, sharedContext = {}) {
|
105
|
+
const promotionCodeUsageMap = new Map();
|
106
|
+
const campaignBudgetMap = new Map();
|
107
|
+
const existingPromotions = await this.listPromotions({
|
108
|
+
code: computedActions
|
109
|
+
.map((computedAction) => computedAction.code)
|
110
|
+
.filter(Boolean),
|
111
|
+
}, {
|
112
|
+
relations: ["campaign", "campaign.budget"],
|
113
|
+
take: null,
|
114
|
+
}, sharedContext);
|
115
|
+
for (const promotion of existingPromotions) {
|
116
|
+
if (promotion.campaign?.budget) {
|
117
|
+
campaignBudgetMap.set(promotion.campaign?.budget.id, promotion.campaign?.budget);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
const existingPromotionsMap = new Map(existingPromotions.map((promotion) => [promotion.code, promotion]));
|
121
|
+
for (let computedAction of computedActions) {
|
122
|
+
const promotion = existingPromotionsMap.get(computedAction.code);
|
123
|
+
if (!promotion) {
|
124
|
+
continue;
|
125
|
+
}
|
126
|
+
const campaignBudget = promotion.campaign?.budget;
|
127
|
+
if (!campaignBudget) {
|
128
|
+
continue;
|
129
|
+
}
|
130
|
+
if (campaignBudget.type === utils_1.CampaignBudgetType.SPEND) {
|
131
|
+
const campaignBudgetData = campaignBudgetMap.get(campaignBudget.id);
|
132
|
+
if (!campaignBudgetData) {
|
133
|
+
continue;
|
134
|
+
}
|
135
|
+
campaignBudgetData.used = utils_1.MathBN.sub(campaignBudgetData.used ?? 0, computedAction.amount);
|
136
|
+
campaignBudgetMap.set(campaignBudget.id, campaignBudgetData);
|
137
|
+
}
|
138
|
+
if (campaignBudget.type === utils_1.CampaignBudgetType.USAGE) {
|
139
|
+
const promotionAlreadyUsed = promotionCodeUsageMap.get(promotion.code) || false;
|
140
|
+
if (promotionAlreadyUsed) {
|
141
|
+
continue;
|
142
|
+
}
|
143
|
+
campaignBudgetMap.set(campaignBudget.id, {
|
144
|
+
id: campaignBudget.id,
|
145
|
+
used: utils_1.MathBN.sub(campaignBudget.used ?? 0, 1),
|
146
|
+
});
|
87
147
|
promotionCodeUsageMap.set(promotion.code, true);
|
88
148
|
}
|
89
149
|
const campaignBudgetsData = [];
|
90
|
-
for (const [_, campaignBudgetData] of
|
150
|
+
for (const [_, campaignBudgetData] of campaignBudgetMap) {
|
91
151
|
campaignBudgetsData.push(campaignBudgetData);
|
92
152
|
}
|
93
153
|
await this.campaignBudgetService_.update(campaignBudgetsData, sharedContext);
|
@@ -655,10 +715,18 @@ exports.default = PromotionModuleService;
|
|
655
715
|
__decorate([
|
656
716
|
(0, utils_1.InjectManager)("baseRepository_"),
|
657
717
|
__param(1, (0, utils_1.MedusaContext)()),
|
718
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
658
719
|
__metadata("design:type", Function),
|
659
720
|
__metadata("design:paramtypes", [Array, Object]),
|
660
721
|
__metadata("design:returntype", Promise)
|
661
722
|
], PromotionModuleService.prototype, "registerUsage", null);
|
723
|
+
__decorate([
|
724
|
+
(0, utils_1.InjectManager)("baseRepository_"),
|
725
|
+
__param(1, (0, utils_1.MedusaContext)()),
|
726
|
+
__metadata("design:type", Function),
|
727
|
+
__metadata("design:paramtypes", [Array, Object]),
|
728
|
+
__metadata("design:returntype", Promise)
|
729
|
+
], PromotionModuleService.prototype, "revertUsage", null);
|
662
730
|
__decorate([
|
663
731
|
(0, utils_1.InjectManager)("baseRepository_"),
|
664
732
|
__param(3, (0, utils_1.MedusaContext)()),
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import { BigNumberInput, CampaignBudgetExceededAction,
|
2
|
-
export declare function canRegisterUsage(computedAction: ComputeActions): boolean;
|
1
|
+
import { BigNumberInput, CampaignBudgetExceededAction, PromotionDTO } from "@medusajs/types";
|
3
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,cAAc,EACd,4BAA4B,EAC5B,
|
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,iBAAiB,CAAA;AAGxB,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 =
|
3
|
+
exports.computeActionForBudgetExceeded = void 0;
|
4
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;
|
12
5
|
function computeActionForBudgetExceeded(promotion, amount) {
|
13
6
|
const campaignBudget = promotion.campaign?.budget;
|
14
7
|
if (!campaignBudget) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@medusajs/promotion",
|
3
|
-
"version": "0.0.5-snapshot-
|
3
|
+
"version": "0.0.5-snapshot-20240905140403",
|
4
4
|
"description": "Medusa Promotion module",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -33,11 +33,11 @@
|
|
33
33
|
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
|
34
34
|
},
|
35
35
|
"devDependencies": {
|
36
|
-
"@medusajs/types": "1.12.0-snapshot-
|
36
|
+
"@medusajs/types": "1.12.0-snapshot-20240905140403",
|
37
37
|
"@mikro-orm/cli": "5.9.7",
|
38
38
|
"cross-env": "^5.2.1",
|
39
39
|
"jest": "^29.7.0",
|
40
|
-
"medusa-test-utils": "1.1.45-snapshot-
|
40
|
+
"medusa-test-utils": "1.1.45-snapshot-20240905140403",
|
41
41
|
"rimraf": "^3.0.2",
|
42
42
|
"ts-jest": "^29.1.1",
|
43
43
|
"ts-node": "^10.9.1",
|
@@ -45,7 +45,7 @@
|
|
45
45
|
"typescript": "^5.1.6"
|
46
46
|
},
|
47
47
|
"dependencies": {
|
48
|
-
"@medusajs/utils": "1.12.0-snapshot-
|
48
|
+
"@medusajs/utils": "1.12.0-snapshot-20240905140403"
|
49
49
|
},
|
50
50
|
"peerDependencies": {
|
51
51
|
"@mikro-orm/core": "5.9.7",
|