@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,34 +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 utils_1 = require("@medusajs/utils");
27
- const ModuleModels = __importStar(require("../models"));
28
- const ModuleRepositories = __importStar(require("../repositories"));
29
- const ModuleServices = __importStar(require("../services"));
30
- exports.default = utils_1.ModulesSdkUtils.moduleContainerLoaderFactory({
31
- moduleModels: ModuleModels,
32
- moduleRepositories: ModuleRepositories,
33
- moduleServices: ModuleServices,
34
- });
@@ -1,3 +0,0 @@
1
- export * from "./connection";
2
- export * from "./container";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA"}
@@ -1,18 +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 __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("./connection"), exports);
18
- __exportStar(require("./container"), exports);
@@ -1,5 +0,0 @@
1
- import { ModuleExports } from "@medusajs/types";
2
- export declare const runMigrations: ({ options, logger, }?: Pick<import("@medusajs/modules-sdk").LoaderOptions<import("@medusajs/modules-sdk").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
3
- export declare const revertMigration: ({ options, logger, }?: Pick<import("@medusajs/modules-sdk").LoaderOptions<import("@medusajs/modules-sdk").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
4
- export declare const moduleDefinition: ModuleExports;
5
- //# sourceMappingURL=module-definition.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"module-definition.d.ts","sourceRoot":"","sources":["../src/module-definition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAa/C,eAAO,MAAM,aAAa,iMAEzB,CAAA;AACD,eAAO,MAAM,eAAe,iMAE3B,CAAA;AAKD,eAAO,MAAM,gBAAgB,EAAE,aAK9B,CAAA"}
@@ -1,50 +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
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.moduleDefinition = exports.revertMigration = exports.runMigrations = void 0;
30
- const modules_sdk_1 = require("@medusajs/modules-sdk");
31
- const utils_1 = require("@medusajs/utils");
32
- const Models = __importStar(require("./models"));
33
- const _services_1 = require("./services");
34
- const connection_1 = __importDefault(require("./loaders/connection"));
35
- const container_1 = __importDefault(require("./loaders/container"));
36
- const migrationScriptOptions = {
37
- moduleName: modules_sdk_1.Modules.PROMOTION,
38
- models: Models,
39
- pathToMigrations: __dirname + "/migrations",
40
- };
41
- exports.runMigrations = utils_1.ModulesSdkUtils.buildMigrationScript(migrationScriptOptions);
42
- exports.revertMigration = utils_1.ModulesSdkUtils.buildRevertMigrationScript(migrationScriptOptions);
43
- const service = _services_1.PromotionModuleService;
44
- const loaders = [container_1.default, connection_1.default];
45
- exports.moduleDefinition = {
46
- service,
47
- loaders,
48
- runMigrations: exports.runMigrations,
49
- revertMigration: exports.revertMigration,
50
- };
@@ -1,16 +0,0 @@
1
- import { Context } from "@medusajs/types";
2
- import { DALUtils } from "@medusajs/utils";
3
- import { Campaign } from "../models";
4
- import { CreateCampaignDTO, UpdateCampaignDTO } from "../types";
5
- declare const CampaignRepository_base: new ({ manager }: {
6
- manager: any;
7
- }) => DALUtils.MikroOrmBaseRepository<Campaign>;
8
- export declare class CampaignRepository extends CampaignRepository_base {
9
- create(data: CreateCampaignDTO[], context?: Context): Promise<Campaign[]>;
10
- update(data: {
11
- entity: Campaign;
12
- update: UpdateCampaignDTO;
13
- }[], context?: Context): Promise<Campaign[]>;
14
- }
15
- export {};
16
- //# sourceMappingURL=campaign.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"campaign.d.ts","sourceRoot":"","sources":["../../src/repositories/campaign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAE1C,OAAO,EAAE,QAAQ,EAAa,MAAM,SAAS,CAAA;AAC7C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;;;;AAE7D,qBAAa,kBAAmB,SAAQ,uBAEvC;IACO,MAAM,CACV,IAAI,EAAE,iBAAiB,EAAE,EACzB,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,QAAQ,EAAE,CAAC;IAiDhB,MAAM,CACV,IAAI,EAAE;QAAE,MAAM,EAAE,QAAQ,CAAC;QAAC,MAAM,EAAE,iBAAiB,CAAA;KAAE,EAAE,EACvD,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,QAAQ,EAAE,CAAC;CAoFvB"}
@@ -1,90 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CampaignRepository = void 0;
4
- const utils_1 = require("@medusajs/utils");
5
- const _models_1 = require("../models");
6
- class CampaignRepository extends utils_1.DALUtils.mikroOrmBaseRepositoryFactory(_models_1.Campaign) {
7
- async create(data, context = {}) {
8
- const manager = this.getActiveManager(context);
9
- const promotionIdsToUpsert = [];
10
- const campaignIdentifierPromotionsMap = new Map();
11
- data.forEach((campaignData) => {
12
- const campaignPromotionIds = campaignData.promotions?.map((p) => p.id) || [];
13
- promotionIdsToUpsert.push(...campaignPromotionIds);
14
- campaignIdentifierPromotionsMap.set(campaignData.campaign_identifier, campaignPromotionIds);
15
- delete campaignData.promotions;
16
- });
17
- const existingPromotions = await manager.find(_models_1.Promotion, {
18
- id: promotionIdsToUpsert,
19
- });
20
- const existingPromotionsMap = new Map(existingPromotions.map((promotion) => [promotion.id, promotion]));
21
- const createdCampaigns = await super.create(data, context);
22
- for (const createdCampaign of createdCampaigns) {
23
- const campaignPromotionIds = campaignIdentifierPromotionsMap.get(createdCampaign.campaign_identifier) || [];
24
- for (const campaignPromotionId of campaignPromotionIds) {
25
- const promotion = existingPromotionsMap.get(campaignPromotionId);
26
- if (!promotion) {
27
- continue;
28
- }
29
- createdCampaign.promotions.add(promotion);
30
- }
31
- }
32
- return createdCampaigns;
33
- }
34
- async update(data, context = {}) {
35
- const manager = this.getActiveManager(context);
36
- const promotionIdsToUpsert = [];
37
- const campaignIds = [];
38
- const campaignPromotionIdsMap = new Map();
39
- data.forEach(({ update: campaignData }) => {
40
- const campaignPromotionIds = campaignData.promotions?.map((p) => p.id);
41
- campaignIds.push(campaignData.id);
42
- if (campaignPromotionIds) {
43
- promotionIdsToUpsert.push(...campaignPromotionIds);
44
- campaignPromotionIdsMap.set(campaignData.id, campaignPromotionIds);
45
- }
46
- delete campaignData.promotions;
47
- });
48
- const existingCampaigns = await manager.find(_models_1.Campaign, { id: campaignIds }, { populate: ["promotions"] });
49
- const promotionIds = existingCampaigns
50
- .map((campaign) => campaign.promotions?.map((p) => p.id))
51
- .flat(1)
52
- .concat(promotionIdsToUpsert);
53
- const existingPromotions = await manager.find(_models_1.Promotion, {
54
- id: promotionIds,
55
- });
56
- const existingCampaignsMap = new Map(existingCampaigns.map((campaign) => [campaign.id, campaign]));
57
- const existingPromotionsMap = new Map(existingPromotions.map((promotion) => [promotion.id, promotion]));
58
- const updatedCampaigns = await super.update(data, context);
59
- for (const updatedCampaign of updatedCampaigns) {
60
- const upsertPromotionIds = campaignPromotionIdsMap.get(updatedCampaign.id);
61
- if (!upsertPromotionIds) {
62
- continue;
63
- }
64
- const existingPromotionIds = (existingCampaignsMap.get(updatedCampaign.id)?.promotions || []).map((p) => p.id);
65
- for (const existingPromotionId of existingPromotionIds) {
66
- const promotion = existingPromotionsMap.get(existingPromotionId);
67
- if (!promotion) {
68
- continue;
69
- }
70
- if (!upsertPromotionIds.includes(existingPromotionId)) {
71
- updatedCampaign.promotions.remove(promotion);
72
- }
73
- }
74
- for (const promotionIdToAdd of upsertPromotionIds) {
75
- const promotion = existingPromotionsMap.get(promotionIdToAdd);
76
- if (!promotion) {
77
- continue;
78
- }
79
- if (existingPromotionIds.includes(promotionIdToAdd)) {
80
- continue;
81
- }
82
- else {
83
- updatedCampaign.promotions.add(promotion);
84
- }
85
- }
86
- }
87
- return updatedCampaigns;
88
- }
89
- }
90
- exports.CampaignRepository = CampaignRepository;
@@ -1,3 +0,0 @@
1
- export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils";
2
- export { CampaignRepository } from "./campaign";
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/repositories/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,IAAI,cAAc,EAAE,MAAM,iBAAiB,CAAA;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA"}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CampaignRepository = exports.BaseRepository = void 0;
4
- var utils_1 = require("@medusajs/utils");
5
- Object.defineProperty(exports, "BaseRepository", { enumerable: true, get: function () { return utils_1.MikroOrmBaseRepository; } });
6
- var campaign_1 = require("./campaign");
7
- Object.defineProperty(exports, "CampaignRepository", { enumerable: true, get: function () { return campaign_1.CampaignRepository; } });