@medusajs/pricing 0.1.13-snapshot-20240718083016 → 0.1.13-snapshot-20240719080828

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. package/dist/index.d.ts +6 -6
  2. package/dist/index.d.ts.map +1 -0
  3. package/dist/index.js +5 -9
  4. package/dist/joiner-config.d.ts +2 -10
  5. package/dist/joiner-config.d.ts.map +1 -0
  6. package/dist/joiner-config.js +4 -52
  7. package/dist/migrations/Migration20230929122253.d.ts +1 -0
  8. package/dist/migrations/Migration20230929122253.d.ts.map +1 -0
  9. package/dist/migrations/Migration20240322094407.d.ts +1 -0
  10. package/dist/migrations/Migration20240322094407.d.ts.map +1 -0
  11. package/dist/migrations/Migration20240322113359.d.ts +1 -0
  12. package/dist/migrations/Migration20240322113359.d.ts.map +1 -0
  13. package/dist/migrations/Migration20240322120125.d.ts +1 -0
  14. package/dist/migrations/Migration20240322120125.d.ts.map +1 -0
  15. package/dist/migrations/Migration20240626133555.d.ts +5 -0
  16. package/dist/migrations/Migration20240626133555.d.ts.map +1 -0
  17. package/dist/migrations/Migration20240626133555.js +33 -0
  18. package/dist/migrations/Migration20240704094505.d.ts +6 -0
  19. package/dist/migrations/Migration20240704094505.d.ts.map +1 -0
  20. package/dist/migrations/Migration20240704094505.js +15 -0
  21. package/dist/models/index.d.ts +2 -3
  22. package/dist/models/index.d.ts.map +1 -0
  23. package/dist/models/index.js +3 -7
  24. package/dist/models/price-list-rule.d.ts +6 -8
  25. package/dist/models/price-list-rule.d.ts.map +1 -0
  26. package/dist/models/price-list-rule.js +8 -29
  27. package/dist/models/price-list.d.ts +2 -3
  28. package/dist/models/price-list.d.ts.map +1 -0
  29. package/dist/models/price-list.js +0 -9
  30. package/dist/models/price-preference.d.ts +13 -0
  31. package/dist/models/price-preference.d.ts.map +1 -0
  32. package/dist/models/{rule-type.js → price-preference.js} +35 -40
  33. package/dist/models/price-rule.d.ts +5 -9
  34. package/dist/models/price-rule.d.ts.map +1 -0
  35. package/dist/models/price-rule.js +6 -45
  36. package/dist/models/price-set.d.ts +1 -4
  37. package/dist/models/price-set.d.ts.map +1 -0
  38. package/dist/models/price-set.js +0 -19
  39. package/dist/models/price.d.ts +5 -4
  40. package/dist/models/price.d.ts.map +1 -0
  41. package/dist/models/price.js +5 -5
  42. package/dist/repositories/index.d.ts +1 -0
  43. package/dist/repositories/index.d.ts.map +1 -0
  44. package/dist/repositories/pricing.d.ts +1 -0
  45. package/dist/repositories/pricing.d.ts.map +1 -0
  46. package/dist/repositories/pricing.js +29 -36
  47. package/dist/schema/index.d.ts +1 -0
  48. package/dist/schema/index.d.ts.map +1 -0
  49. package/dist/services/index.d.ts +1 -2
  50. package/dist/services/index.d.ts.map +1 -0
  51. package/dist/services/index.js +1 -5
  52. package/dist/services/pricing-module.d.ts +66 -53
  53. package/dist/services/pricing-module.d.ts.map +1 -0
  54. package/dist/services/pricing-module.js +594 -605
  55. package/dist/types/index.d.ts +1 -0
  56. package/dist/types/index.d.ts.map +1 -0
  57. package/dist/types/services/index.d.ts +30 -2
  58. package/dist/types/services/index.d.ts.map +1 -0
  59. package/dist/types/services/index.js +0 -16
  60. package/dist/utils/events.d.ts +63 -0
  61. package/dist/utils/events.d.ts.map +1 -0
  62. package/dist/utils/events.js +66 -0
  63. package/dist/utils/index.d.ts +2 -0
  64. package/dist/utils/index.d.ts.map +1 -0
  65. package/dist/utils/index.js +1 -0
  66. package/dist/utils/validate-price-list-dates.d.ts +1 -0
  67. package/dist/utils/validate-price-list-dates.d.ts.map +1 -0
  68. package/package.json +8 -13
  69. package/dist/initialize/index.d.ts +0 -4
  70. package/dist/initialize/index.js +0 -17
  71. package/dist/loaders/connection.d.ts +0 -4
  72. package/dist/loaders/connection.js +0 -40
  73. package/dist/loaders/container.d.ts +0 -2
  74. package/dist/loaders/container.js +0 -34
  75. package/dist/loaders/index.d.ts +0 -2
  76. package/dist/loaders/index.js +0 -18
  77. package/dist/models/price-list-rule-value.d.ts +0 -17
  78. package/dist/models/price-list-rule-value.js +0 -102
  79. package/dist/models/price-set-rule-type.d.ts +0 -10
  80. package/dist/models/price-set-rule-type.js +0 -108
  81. package/dist/models/rule-type.d.ts +0 -17
  82. package/dist/module-definition.d.ts +0 -4
  83. package/dist/module-definition.js +0 -50
  84. package/dist/scripts/bin/run-seed.d.ts +0 -3
  85. package/dist/scripts/bin/run-seed.js +0 -38
  86. package/dist/scripts/seed.d.ts +0 -4
  87. package/dist/scripts/seed.js +0 -67
  88. package/dist/services/price-list.d.ts +0 -16
  89. package/dist/services/price-list.js +0 -34
  90. package/dist/services/rule-type.d.ts +0 -15
  91. package/dist/services/rule-type.js +0 -53
  92. package/dist/types/services/price-list.d.ts +0 -18
  93. package/dist/types/services/price-list.js +0 -2
  94. package/dist/types/services/price-set.d.ts +0 -4
  95. package/dist/types/services/price-set.js +0 -2
@@ -1,17 +0,0 @@
1
- import { Collection, OptionalProps } from "@mikro-orm/core";
2
- import PriceSet from "./price-set";
3
- type OptionalFields = "default_priority";
4
- declare class RuleType {
5
- [OptionalProps]?: OptionalFields;
6
- id: string;
7
- name: string;
8
- rule_attribute: string;
9
- default_priority: number;
10
- price_sets: Collection<PriceSet, object>;
11
- created_at: Date;
12
- updated_at: Date;
13
- deleted_at: Date | null;
14
- onCreate(): void;
15
- onInit(): void;
16
- }
17
- export default RuleType;
@@ -1,4 +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;
@@ -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.PRICING,
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.PricingModuleService;
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,3 +0,0 @@
1
- #!/usr/bin/env node
2
- declare const _default: Promise<void>;
3
- export default _default;
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- const os_1 = require("os");
28
- const seed_1 = require("../seed");
29
- const args = process.argv;
30
- const path = args.pop();
31
- exports.default = (async () => {
32
- const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
33
- config();
34
- if (!path) {
35
- throw new Error(`filePath is required.${os_1.EOL}Example: medusa-pricing-seed <filePath>`);
36
- }
37
- await (0, seed_1.run)({ path });
38
- })();
@@ -1,4 +0,0 @@
1
- import { LoaderOptions, ModulesSdkTypes } from "@medusajs/types";
2
- export declare function run({ options, logger, path, }: Partial<Pick<LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>, "options" | "logger">> & {
3
- path: string;
4
- }): Promise<void>;
@@ -1,67 +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
- exports.run = void 0;
27
- const utils_1 = require("@medusajs/utils");
28
- const PricingModels = __importStar(require("../models"));
29
- const os_1 = require("os");
30
- const path_1 = require("path");
31
- async function run({ options, logger, path, }) {
32
- logger ?? (logger = console);
33
- logger.info(`Loading seed data from ${path}...`);
34
- const { priceSetsData, pricesData } = await Promise.resolve(`${(0, path_1.resolve)(process.cwd(), path)}`).then(s => __importStar(require(s))).catch((e) => {
35
- logger?.error(`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: priceSetsData and pricesData.${os_1.EOL}${e}`);
36
- throw e;
37
- });
38
- const dbData = utils_1.ModulesSdkUtils.loadDatabaseConfig("pricing", options);
39
- const entities = Object.values(PricingModels);
40
- const pathToMigrations = __dirname + "/../migrations";
41
- const orm = await utils_1.DALUtils.mikroOrmCreateConnection(dbData, entities, pathToMigrations);
42
- const manager = orm.em.fork();
43
- try {
44
- logger.info("Inserting price_sets & prices");
45
- await createPriceSets(manager, priceSetsData);
46
- await createPrices(manager, pricesData);
47
- }
48
- catch (e) {
49
- logger.error(`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${os_1.EOL}${e}`);
50
- }
51
- await orm.close(true);
52
- }
53
- exports.run = run;
54
- async function createPriceSets(manager, data) {
55
- const priceSets = data.map((priceSetData) => {
56
- return manager.create(PricingModels.PriceSet, priceSetData);
57
- });
58
- await manager.persistAndFlush(priceSets);
59
- return priceSets;
60
- }
61
- async function createPrices(manager, data) {
62
- const prices = data.map((priceData) => {
63
- return manager.create(PricingModels.Price, priceData);
64
- });
65
- await manager.persistAndFlush(prices);
66
- return prices;
67
- }
@@ -1,16 +0,0 @@
1
- import { Context, DAL } from "@medusajs/types";
2
- import { PriceList } from "../models";
3
- import { ServiceTypes } from "../types";
4
- type InjectedDependencies = {
5
- priceListRepository: DAL.RepositoryService;
6
- };
7
- declare const PriceListService_base: new <TEntity_1 extends object = any>(container: InjectedDependencies) => import("@medusajs/types").InternalModuleService<TEntity_1, InjectedDependencies>;
8
- export default class PriceListService<TEntity extends PriceList = PriceList> extends PriceListService_base<TEntity> {
9
- constructor(container: InjectedDependencies);
10
- create(data: ServiceTypes.CreatePriceListDTO[], sharedContext?: Context): Promise<TEntity[]>;
11
- create(data: ServiceTypes.CreatePriceListDTO, sharedContext?: Context): Promise<TEntity>;
12
- update(data: any[], sharedContext?: Context): Promise<TEntity[]>;
13
- update(data: any, sharedContext?: Context): Promise<TEntity>;
14
- protected normalizePriceListDate(data: (ServiceTypes.UpdatePriceListDTO | ServiceTypes.CreatePriceListDTO)[]): any[];
15
- }
16
- export {};
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const utils_1 = require("@medusajs/utils");
4
- const _models_1 = require("../models");
5
- class PriceListService extends utils_1.ModulesSdkUtils.internalModuleServiceFactory(_models_1.PriceList) {
6
- constructor(container) {
7
- // @ts-ignore
8
- super(...arguments);
9
- }
10
- async create(data, sharedContext) {
11
- const data_ = Array.isArray(data) ? data : [data];
12
- const priceLists = this.normalizePriceListDate(data_);
13
- return await super.create(priceLists, sharedContext);
14
- }
15
- // TODO: Add support for selector? and then rm ts ignore
16
- // @ts-ignore
17
- async update(data, sharedContext) {
18
- const data_ = Array.isArray(data) ? data : [data];
19
- const priceLists = this.normalizePriceListDate(data_);
20
- return await super.update(priceLists, sharedContext);
21
- }
22
- normalizePriceListDate(data) {
23
- return data.map((priceListData) => {
24
- if (!!priceListData.starts_at) {
25
- priceListData.starts_at = (0, utils_1.GetIsoStringFromDate)(priceListData.starts_at);
26
- }
27
- if (!!priceListData.ends_at) {
28
- priceListData.ends_at = (0, utils_1.GetIsoStringFromDate)(priceListData.ends_at);
29
- }
30
- return priceListData;
31
- });
32
- }
33
- }
34
- exports.default = PriceListService;
@@ -1,15 +0,0 @@
1
- import { Context, DAL, PricingTypes } from "@medusajs/types";
2
- import { RuleType } from "../models";
3
- type InjectedDependencies = {
4
- ruleTypeRepository: DAL.RepositoryService;
5
- };
6
- declare const RuleTypeService_base: new <TEntity_1 extends object = any>(container: InjectedDependencies) => import("@medusajs/types").InternalModuleService<TEntity_1, InjectedDependencies>;
7
- export default class RuleTypeService<TEntity extends RuleType = RuleType> extends RuleTypeService_base<TEntity> {
8
- protected readonly ruleTypeRepository_: DAL.RepositoryService<TEntity>;
9
- constructor({ ruleTypeRepository }: InjectedDependencies);
10
- create(data: PricingTypes.CreateRuleTypeDTO, sharedContext: Context): Promise<TEntity>;
11
- create(data: PricingTypes.CreateRuleTypeDTO[], sharedContext: Context): Promise<TEntity[]>;
12
- update(data: PricingTypes.UpdateRuleTypeDTO[], sharedContext: Context): Promise<TEntity[]>;
13
- update(data: PricingTypes.UpdateRuleTypeDTO, sharedContext: Context): Promise<TEntity>;
14
- }
15
- export {};
@@ -1,53 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const utils_1 = require("@medusajs/utils");
16
- const _models_1 = require("../models");
17
- class RuleTypeService extends utils_1.ModulesSdkUtils.internalModuleServiceFactory(_models_1.RuleType) {
18
- constructor({ ruleTypeRepository }) {
19
- // @ts-ignore
20
- super(...arguments);
21
- this.ruleTypeRepository_ = ruleTypeRepository;
22
- }
23
- async create(data, sharedContext = {}) {
24
- const data_ = Array.isArray(data) ? data : [data];
25
- (0, utils_1.validateRuleAttributes)(data_.map((d) => d.rule_attribute));
26
- return await super.create(data, sharedContext);
27
- }
28
- // TODO: add support for selector? and then rm ts ignore
29
- // @ts-ignore
30
- async update(data, sharedContext = {}) {
31
- const data_ = Array.isArray(data) ? data : [data];
32
- (0, utils_1.validateRuleAttributes)(data_.map((d) => d.rule_attribute));
33
- return await super.update(data, sharedContext);
34
- }
35
- }
36
- exports.default = RuleTypeService;
37
- __decorate([
38
- (0, utils_1.InjectTransactionManager)("ruleTypeRepository_"),
39
- __param(1, (0, utils_1.MedusaContext)()),
40
- __metadata("design:type", Function),
41
- __metadata("design:paramtypes", [Object, Object]),
42
- __metadata("design:returntype", Promise)
43
- ], RuleTypeService.prototype, "create", null);
44
- __decorate([
45
- (0, utils_1.InjectTransactionManager)("ruleTypeRepository_")
46
- // TODO: add support for selector? and then rm ts ignore
47
- // @ts-ignore
48
- ,
49
- __param(1, (0, utils_1.MedusaContext)()),
50
- __metadata("design:type", Function),
51
- __metadata("design:paramtypes", [Object, Object]),
52
- __metadata("design:returntype", Promise)
53
- ], RuleTypeService.prototype, "update", null);
@@ -1,18 +0,0 @@
1
- import { PriceListStatus, PriceListType } from "@medusajs/utils";
2
- export interface CreatePriceListDTO {
3
- title: string;
4
- description: string;
5
- starts_at?: string | null;
6
- ends_at?: string | null;
7
- status?: PriceListStatus;
8
- type?: PriceListType;
9
- number_rules?: number;
10
- }
11
- export interface UpdatePriceListDTO {
12
- id: string;
13
- title?: string;
14
- starts_at?: string | null;
15
- ends_at?: string | null;
16
- status?: PriceListStatus;
17
- number_rules?: number;
18
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +0,0 @@
1
- import { UpdatePriceSetDTO } from "@medusajs/types";
2
- export interface UpdatePriceSetInput extends UpdatePriceSetDTO {
3
- id: string;
4
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });