@medusajs/pricing 0.0.2-canary-20230831100806

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +3 -0
  2. package/dist/index.d.ts +8 -0
  3. package/dist/index.js +24 -0
  4. package/dist/initialize/index.d.ts +4 -0
  5. package/dist/initialize/index.js +11 -0
  6. package/dist/joiner-config.d.ts +8 -0
  7. package/dist/joiner-config.js +37 -0
  8. package/dist/loaders/connection.d.ts +4 -0
  9. package/dist/loaders/connection.js +39 -0
  10. package/dist/loaders/container.d.ts +4 -0
  11. package/dist/loaders/container.js +52 -0
  12. package/dist/loaders/index.d.ts +2 -0
  13. package/dist/loaders/index.js +18 -0
  14. package/dist/migrations/Migration20230828182018.d.ts +4 -0
  15. package/dist/migrations/Migration20230828182018.js +10 -0
  16. package/dist/models/currency.d.ts +7 -0
  17. package/dist/models/currency.js +34 -0
  18. package/dist/models/index.d.ts +1 -0
  19. package/dist/models/index.js +8 -0
  20. package/dist/module-definition.d.ts +2 -0
  21. package/dist/module-definition.js +15 -0
  22. package/dist/repositories/currency.d.ts +15 -0
  23. package/dist/repositories/currency.js +69 -0
  24. package/dist/repositories/index.d.ts +2 -0
  25. package/dist/repositories/index.js +7 -0
  26. package/dist/scripts/bin/run-migration-down.d.ts +3 -0
  27. package/dist/scripts/bin/run-migration-down.js +32 -0
  28. package/dist/scripts/bin/run-migration-up.d.ts +3 -0
  29. package/dist/scripts/bin/run-migration-up.js +32 -0
  30. package/dist/scripts/bin/run-seed.d.ts +3 -0
  31. package/dist/scripts/bin/run-seed.js +38 -0
  32. package/dist/scripts/index.d.ts +2 -0
  33. package/dist/scripts/index.js +18 -0
  34. package/dist/scripts/migration-down.d.ts +9 -0
  35. package/dist/scripts/migration-down.js +52 -0
  36. package/dist/scripts/migration-up.d.ts +9 -0
  37. package/dist/scripts/migration-up.js +56 -0
  38. package/dist/scripts/seed.d.ts +4 -0
  39. package/dist/scripts/seed.js +59 -0
  40. package/dist/services/currency.d.ts +17 -0
  41. package/dist/services/currency.js +98 -0
  42. package/dist/services/index.d.ts +2 -0
  43. package/dist/services/index.js +10 -0
  44. package/dist/services/pricing-module.d.ts +21 -0
  45. package/dist/services/pricing-module.js +107 -0
  46. package/dist/types/index.d.ts +4 -0
  47. package/dist/types/index.js +2 -0
  48. package/package.json +60 -0
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Pricing Module
2
+
3
+ The Pricing Module gives you access MoneyAmounts, Currency and PriceList through a standalone package that can be installed and run in Next.js functions and other Node.js compatible runtimes.
@@ -0,0 +1,8 @@
1
+ import { moduleDefinition } from "./module-definition";
2
+ export default moduleDefinition;
3
+ export * from "./scripts";
4
+ export * from "./initialize";
5
+ export * from "./types";
6
+ export * from "./loaders";
7
+ export * from "./models";
8
+ export * from "./services";
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
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
+ const module_definition_1 = require("./module-definition");
18
+ exports.default = module_definition_1.moduleDefinition;
19
+ __exportStar(require("./scripts"), exports);
20
+ __exportStar(require("./initialize"), exports);
21
+ __exportStar(require("./types"), exports);
22
+ __exportStar(require("./loaders"), exports);
23
+ __exportStar(require("./models"), exports);
24
+ __exportStar(require("./services"), exports);
@@ -0,0 +1,4 @@
1
+ import { ExternalModuleDeclaration, InternalModuleDeclaration } from "@medusajs/modules-sdk";
2
+ import { IPricingModuleService, ModulesSdkTypes } from "@medusajs/types";
3
+ import { InitializeModuleInjectableDependencies } from "../types";
4
+ export declare const initialize: (options?: ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions | ExternalModuleDeclaration | InternalModuleDeclaration, injectedDependencies?: InitializeModuleInjectableDependencies) => Promise<IPricingModuleService>;
@@ -0,0 +1,11 @@
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 serviceKey = modules_sdk_1.Modules.PRICING;
8
+ const loaded = await modules_sdk_1.MedusaModule.bootstrap(serviceKey, modules_sdk_1.MODULE_PACKAGE_NAMES[modules_sdk_1.Modules.PRICING], options, module_definition_1.moduleDefinition, injectedDependencies);
9
+ return loaded[serviceKey];
10
+ };
11
+ exports.initialize = initialize;
@@ -0,0 +1,8 @@
1
+ import { JoinerServiceConfig } from "@medusajs/types";
2
+ import { MapToConfig } from "@medusajs/utils";
3
+ export declare enum LinkableKeys {
4
+ MONEY_AMOUNT_ID = "money_amount_id",
5
+ CURRENCY_CODE = "code"
6
+ }
7
+ export declare const entityNameToLinkableKeysMap: MapToConfig;
8
+ export declare const joinerConfig: JoinerServiceConfig;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.joinerConfig = exports.entityNameToLinkableKeysMap = exports.LinkableKeys = void 0;
4
+ const modules_sdk_1 = require("@medusajs/modules-sdk");
5
+ const _models_1 = require("./models");
6
+ var LinkableKeys;
7
+ (function (LinkableKeys) {
8
+ LinkableKeys["MONEY_AMOUNT_ID"] = "money_amount_id";
9
+ LinkableKeys["CURRENCY_CODE"] = "code";
10
+ })(LinkableKeys || (exports.LinkableKeys = LinkableKeys = {}));
11
+ exports.entityNameToLinkableKeysMap = {
12
+ [_models_1.Currency.name]: [{ mapTo: LinkableKeys.CURRENCY_CODE, valueFrom: "code" }],
13
+ };
14
+ exports.joinerConfig = {
15
+ serviceName: modules_sdk_1.Modules.PRICING,
16
+ primaryKeys: ["code"],
17
+ alias: [
18
+ // {
19
+ // name: "money_amount",
20
+ // },
21
+ // {
22
+ // name: "money_amounts",
23
+ // },
24
+ {
25
+ name: "currency",
26
+ args: {
27
+ methodSuffix: "Currencies",
28
+ },
29
+ },
30
+ {
31
+ name: "currencies",
32
+ args: {
33
+ methodSuffix: "Currencies",
34
+ },
35
+ },
36
+ ],
37
+ };
@@ -0,0 +1,4 @@
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;
@@ -0,0 +1,39 @@
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 PricingModels = __importStar(require("../models"));
28
+ exports.default = async ({ options, container, logger, }, moduleDeclaration) => {
29
+ const entities = Object.values(PricingModels);
30
+ const pathToMigrations = __dirname + "/../migrations";
31
+ await utils_1.ModulesSdkUtils.mikroOrmConnectionLoader({
32
+ entities,
33
+ container,
34
+ options,
35
+ moduleDeclaration,
36
+ logger,
37
+ pathToMigrations,
38
+ });
39
+ };
@@ -0,0 +1,4 @@
1
+ import { ModulesSdkTypes } from "@medusajs/types";
2
+ import { LoaderOptions } from "@medusajs/modules-sdk";
3
+ declare const _default: ({ container, options, }: LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions>) => Promise<void>;
4
+ export default _default;
@@ -0,0 +1,52 @@
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 defaultRepositories = __importStar(require("../repositories"));
27
+ const _repositories_1 = require("../repositories");
28
+ const _services_1 = require("../services");
29
+ const utils_1 = require("@medusajs/utils");
30
+ const awilix_1 = require("awilix");
31
+ exports.default = async ({ container, options, }) => {
32
+ const customRepositories = options?.repositories;
33
+ container.register({
34
+ currencyService: (0, awilix_1.asClass)(_services_1.CurrencyService).singleton(),
35
+ });
36
+ if (customRepositories) {
37
+ (0, utils_1.loadCustomRepositories)({
38
+ defaultRepositories,
39
+ customRepositories,
40
+ container,
41
+ });
42
+ }
43
+ else {
44
+ loadDefaultRepositories({ container });
45
+ }
46
+ };
47
+ function loadDefaultRepositories({ container }) {
48
+ container.register({
49
+ baseRepository: (0, awilix_1.asClass)(_repositories_1.BaseRepository).singleton(),
50
+ currencyRepository: (0, awilix_1.asClass)(_repositories_1.CurrencyRepository).singleton(),
51
+ });
52
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./connection";
2
+ export * from "./container";
@@ -0,0 +1,18 @@
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);
@@ -0,0 +1,4 @@
1
+ import { Migration } from '@mikro-orm/migrations';
2
+ export declare class Migration20230828182018 extends Migration {
3
+ up(): Promise<void>;
4
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20230828182018 = void 0;
4
+ const migrations_1 = require("@mikro-orm/migrations");
5
+ class Migration20230828182018 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql('create table "currency" ("code" text not null, "symbol" text not null, "symbol_native" text not null, "name" text not null, constraint "currency_pkey" primary key ("code"));');
8
+ }
9
+ }
10
+ exports.Migration20230828182018 = Migration20230828182018;
@@ -0,0 +1,7 @@
1
+ declare class Currency {
2
+ code: string;
3
+ symbol: string;
4
+ symbol_native: string;
5
+ name: string;
6
+ }
7
+ export default Currency;
@@ -0,0 +1,34 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const core_1 = require("@mikro-orm/core");
13
+ let Currency = class Currency {
14
+ };
15
+ __decorate([
16
+ (0, core_1.PrimaryKey)({ columnType: "text" }),
17
+ __metadata("design:type", String)
18
+ ], Currency.prototype, "code", void 0);
19
+ __decorate([
20
+ (0, core_1.Property)({ columnType: "text" }),
21
+ __metadata("design:type", String)
22
+ ], Currency.prototype, "symbol", void 0);
23
+ __decorate([
24
+ (0, core_1.Property)({ columnType: "text" }),
25
+ __metadata("design:type", String)
26
+ ], Currency.prototype, "symbol_native", void 0);
27
+ __decorate([
28
+ (0, core_1.Property)({ columnType: "text" }),
29
+ __metadata("design:type", String)
30
+ ], Currency.prototype, "name", void 0);
31
+ Currency = __decorate([
32
+ (0, core_1.Entity)({ tableName: "currency" })
33
+ ], Currency);
34
+ exports.default = Currency;
@@ -0,0 +1 @@
1
+ export { default as Currency } from "./currency";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Currency = void 0;
7
+ var currency_1 = require("./currency");
8
+ Object.defineProperty(exports, "Currency", { enumerable: true, get: function () { return __importDefault(currency_1).default; } });
@@ -0,0 +1,2 @@
1
+ import { ModuleExports } from "@medusajs/types";
2
+ export declare const moduleDefinition: ModuleExports;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.moduleDefinition = void 0;
7
+ const _services_1 = require("./services");
8
+ const connection_1 = __importDefault(require("./loaders/connection"));
9
+ const container_1 = __importDefault(require("./loaders/container"));
10
+ const service = _services_1.PricingModuleService;
11
+ const loaders = [container_1.default, connection_1.default];
12
+ exports.moduleDefinition = {
13
+ service,
14
+ loaders,
15
+ };
@@ -0,0 +1,15 @@
1
+ import { Context, CreateCurrencyDTO, DAL, UpdateCurrencyDTO } from "@medusajs/types";
2
+ import { DALUtils } from "@medusajs/utils";
3
+ import { SqlEntityManager } from "@mikro-orm/postgresql";
4
+ import { Currency } from "../models";
5
+ export declare class CurrencyRepository extends DALUtils.MikroOrmBaseRepository {
6
+ protected readonly manager_: SqlEntityManager;
7
+ constructor({ manager }: {
8
+ manager: SqlEntityManager;
9
+ });
10
+ find(findOptions?: DAL.FindOptions<Currency>, context?: Context): Promise<Currency[]>;
11
+ findAndCount(findOptions?: DAL.FindOptions<Currency>, context?: Context): Promise<[Currency[], number]>;
12
+ delete(codes: string[], context?: Context): Promise<void>;
13
+ create(data: CreateCurrencyDTO[], context?: Context): Promise<Currency[]>;
14
+ update(data: UpdateCurrencyDTO[], context?: Context): Promise<Currency[]>;
15
+ }
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CurrencyRepository = void 0;
4
+ const utils_1 = require("@medusajs/utils");
5
+ const core_1 = require("@mikro-orm/core");
6
+ const _models_1 = require("../models");
7
+ class CurrencyRepository extends utils_1.DALUtils.MikroOrmBaseRepository {
8
+ constructor({ manager }) {
9
+ // @ts-ignore
10
+ // eslint-disable-next-line prefer-rest-params
11
+ super(...arguments);
12
+ this.manager_ = manager;
13
+ }
14
+ async find(findOptions = { where: {} }, context = {}) {
15
+ const manager = this.getActiveManager(context);
16
+ const findOptions_ = { ...findOptions };
17
+ findOptions_.options ?? (findOptions_.options = {});
18
+ Object.assign(findOptions_.options, {
19
+ strategy: core_1.LoadStrategy.SELECT_IN,
20
+ });
21
+ return await manager.find(_models_1.Currency, findOptions_.where, findOptions_.options);
22
+ }
23
+ async findAndCount(findOptions = { where: {} }, context = {}) {
24
+ const manager = this.getActiveManager(context);
25
+ const findOptions_ = { ...findOptions };
26
+ findOptions_.options ?? (findOptions_.options = {});
27
+ Object.assign(findOptions_.options, {
28
+ strategy: core_1.LoadStrategy.SELECT_IN,
29
+ });
30
+ return await manager.findAndCount(_models_1.Currency, findOptions_.where, findOptions_.options);
31
+ }
32
+ async delete(codes, context = {}) {
33
+ const manager = this.getActiveManager(context);
34
+ await manager.nativeDelete(_models_1.Currency, { code: { $in: codes } }, {});
35
+ }
36
+ async create(data, context = {}) {
37
+ const manager = this.getActiveManager(context);
38
+ const currencies = data.map((currencyData) => {
39
+ return manager.create(_models_1.Currency, currencyData);
40
+ });
41
+ manager.persist(currencies);
42
+ return currencies;
43
+ }
44
+ async update(data, context = {}) {
45
+ const manager = this.getActiveManager(context);
46
+ const currencyCodes = data.map((currencyData) => currencyData.code);
47
+ const existingCurrencies = await this.find({
48
+ where: {
49
+ code: {
50
+ $in: currencyCodes,
51
+ },
52
+ },
53
+ }, context);
54
+ const existingCurrencyMap = new Map(existingCurrencies.map((currency) => [
55
+ currency.code,
56
+ currency,
57
+ ]));
58
+ const currencies = data.map((currencyData) => {
59
+ const existingCurrency = existingCurrencyMap.get(currencyData.code);
60
+ if (!existingCurrency) {
61
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.NOT_FOUND, `Currency with code "${currencyData.code}" not found`);
62
+ }
63
+ return manager.assign(existingCurrency, currencyData);
64
+ });
65
+ manager.persist(currencies);
66
+ return currencies;
67
+ }
68
+ }
69
+ exports.CurrencyRepository = CurrencyRepository;
@@ -0,0 +1,2 @@
1
+ export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils";
2
+ export { CurrencyRepository } from "./currency";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CurrencyRepository = 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 currency_1 = require("./currency");
7
+ Object.defineProperty(exports, "CurrencyRepository", { enumerable: true, get: function () { return currency_1.CurrencyRepository; } });
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ declare const _default: Promise<void>;
3
+ export default _default;
@@ -0,0 +1,32 @@
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
+ exports.default = (async () => {
28
+ const { revertMigration } = await Promise.resolve().then(() => __importStar(require("../migration-down")));
29
+ const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
30
+ config();
31
+ await revertMigration();
32
+ })();
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ declare const _default: Promise<void>;
3
+ export default _default;
@@ -0,0 +1,32 @@
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
+ exports.default = (async () => {
28
+ const { runMigrations } = await Promise.resolve().then(() => __importStar(require("../migration-up")));
29
+ const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
30
+ config();
31
+ await runMigrations();
32
+ })();
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ declare const _default: Promise<void>;
3
+ export default _default;
@@ -0,0 +1,38 @@
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
+ })();
@@ -0,0 +1,2 @@
1
+ export * from "./migration-up";
2
+ export * from "./migration-down";
@@ -0,0 +1,18 @@
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("./migration-up"), exports);
18
+ __exportStar(require("./migration-down"), exports);
@@ -0,0 +1,9 @@
1
+ import { LoaderOptions, ModulesSdkTypes } from "@medusajs/types";
2
+ /**
3
+ * This script is only valid for mikro orm managers. If a user provide a custom manager
4
+ * he is in charge of reverting the migrations.
5
+ * @param options
6
+ * @param logger
7
+ * @param moduleDeclaration
8
+ */
9
+ export declare function revertMigration({ options, logger, }?: Pick<LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>, "options" | "logger">): Promise<void>;
@@ -0,0 +1,52 @@
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.revertMigration = void 0;
27
+ const PricingModels = __importStar(require("../models"));
28
+ const utils_1 = require("@medusajs/utils");
29
+ /**
30
+ * This script is only valid for mikro orm managers. If a user provide a custom manager
31
+ * he is in charge of reverting the migrations.
32
+ * @param options
33
+ * @param logger
34
+ * @param moduleDeclaration
35
+ */
36
+ async function revertMigration({ options, logger, } = {}) {
37
+ logger ?? (logger = console);
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
+ try {
43
+ const migrator = orm.getMigrator();
44
+ await migrator.down();
45
+ logger?.info("Pricing module migration executed");
46
+ }
47
+ catch (error) {
48
+ logger?.error(`Pricing module migration failed to run - Error: ${error}`);
49
+ }
50
+ await orm.close();
51
+ }
52
+ exports.revertMigration = revertMigration;
@@ -0,0 +1,9 @@
1
+ import { LoaderOptions, ModulesSdkTypes } from "@medusajs/types";
2
+ /**
3
+ * This script is only valid for mikro orm managers. If a user provide a custom manager
4
+ * he is in charge of running the migrations.
5
+ * @param options
6
+ * @param logger
7
+ * @param moduleDeclaration
8
+ */
9
+ export declare function runMigrations({ options, logger, }?: Pick<LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>, "options" | "logger">): Promise<void>;
@@ -0,0 +1,56 @@
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.runMigrations = void 0;
27
+ const utils_1 = require("@medusajs/utils");
28
+ const PricingModels = __importStar(require("../models"));
29
+ /**
30
+ * This script is only valid for mikro orm managers. If a user provide a custom manager
31
+ * he is in charge of running the migrations.
32
+ * @param options
33
+ * @param logger
34
+ * @param moduleDeclaration
35
+ */
36
+ async function runMigrations({ options, logger, } = {}) {
37
+ logger ?? (logger = console);
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
+ try {
43
+ const migrator = orm.getMigrator();
44
+ const pendingMigrations = await migrator.getPendingMigrations();
45
+ logger.info(`Running pending migrations: ${pendingMigrations}`);
46
+ await migrator.up({
47
+ migrations: pendingMigrations.map((m) => m.name),
48
+ });
49
+ logger.info("Pricing module migration executed");
50
+ }
51
+ catch (error) {
52
+ logger.error(`Pricing module migration failed to run - Error: ${error}`);
53
+ }
54
+ await orm.close();
55
+ }
56
+ exports.runMigrations = runMigrations;
@@ -0,0 +1,4 @@
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>;
@@ -0,0 +1,59 @@
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 { currenciesData } = 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 currenciesData.${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 currencies");
45
+ await createCurrencies(manager, currenciesData);
46
+ }
47
+ catch (e) {
48
+ logger.error(`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${os_1.EOL}${e}`);
49
+ }
50
+ await orm.close(true);
51
+ }
52
+ exports.run = run;
53
+ async function createCurrencies(manager, data) {
54
+ const currencies = data.map((currencyData) => {
55
+ return manager.create(PricingModels.Currency, currencyData);
56
+ });
57
+ await manager.persistAndFlush(currencies);
58
+ return currencies;
59
+ }
@@ -0,0 +1,17 @@
1
+ import { Context, DAL, FindConfig, PricingTypes } from "@medusajs/types";
2
+ import { Currency } from "../models";
3
+ type InjectedDependencies = {
4
+ currencyRepository: DAL.RepositoryService;
5
+ };
6
+ export default class CurrencyService<TEntity extends Currency = Currency> {
7
+ protected readonly currencyRepository_: DAL.RepositoryService;
8
+ constructor({ currencyRepository }: InjectedDependencies);
9
+ retrieve(currencyCode: string, config?: FindConfig<PricingTypes.CurrencyDTO>, sharedContext?: Context): Promise<TEntity>;
10
+ list(filters?: PricingTypes.FilterableCurrencyProps, config?: FindConfig<PricingTypes.CurrencyDTO>, sharedContext?: Context): Promise<TEntity[]>;
11
+ listAndCount(filters?: PricingTypes.FilterableCurrencyProps, config?: FindConfig<PricingTypes.CurrencyDTO>, sharedContext?: Context): Promise<[TEntity[], number]>;
12
+ private buildQueryForList;
13
+ create(data: PricingTypes.CreateCurrencyDTO[], sharedContext?: Context): Promise<TEntity[]>;
14
+ update(data: PricingTypes.UpdateCurrencyDTO[], sharedContext?: Context): Promise<TEntity[]>;
15
+ delete(ids: string[], sharedContext?: Context): Promise<void>;
16
+ }
17
+ export {};
@@ -0,0 +1,98 @@
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 types_1 = require("@medusajs/types");
16
+ const utils_1 = require("@medusajs/utils");
17
+ const _models_1 = require("../models");
18
+ const utils_2 = require("@medusajs/utils");
19
+ class CurrencyService {
20
+ constructor({ currencyRepository }) {
21
+ this.currencyRepository_ = currencyRepository;
22
+ }
23
+ async retrieve(currencyCode, config = {}, sharedContext = {}) {
24
+ return (await (0, utils_1.retrieveEntity)({
25
+ id: currencyCode,
26
+ identifierColumn: "code",
27
+ entityName: _models_1.Currency.name,
28
+ repository: this.currencyRepository_,
29
+ config,
30
+ sharedContext,
31
+ }));
32
+ }
33
+ async list(filters = {}, config = {}, sharedContext = {}) {
34
+ return (await this.currencyRepository_.find(this.buildQueryForList(filters, config), sharedContext));
35
+ }
36
+ async listAndCount(filters = {}, config = {}, sharedContext = {}) {
37
+ return (await this.currencyRepository_.findAndCount(this.buildQueryForList(filters, config), sharedContext));
38
+ }
39
+ buildQueryForList(filters = {}, config = {}) {
40
+ const queryOptions = utils_1.ModulesSdkUtils.buildQuery(filters, config);
41
+ if (filters.code) {
42
+ queryOptions.where["code"] = { $in: filters.code };
43
+ }
44
+ return queryOptions;
45
+ }
46
+ async create(data, sharedContext = {}) {
47
+ return (await this.currencyRepository_.create(data, sharedContext));
48
+ }
49
+ async update(data, sharedContext = {}) {
50
+ return (await this.currencyRepository_.update(data, sharedContext));
51
+ }
52
+ async delete(ids, sharedContext = {}) {
53
+ await this.currencyRepository_.delete(ids, sharedContext);
54
+ }
55
+ }
56
+ exports.default = CurrencyService;
57
+ __decorate([
58
+ (0, utils_1.InjectManager)("currencyRepository_"),
59
+ __param(2, (0, utils_1.MedusaContext)()),
60
+ __metadata("design:type", Function),
61
+ __metadata("design:paramtypes", [String, Object, Object]),
62
+ __metadata("design:returntype", Promise)
63
+ ], CurrencyService.prototype, "retrieve", null);
64
+ __decorate([
65
+ (0, utils_1.InjectManager)("currencyRepository_"),
66
+ __param(2, (0, utils_1.MedusaContext)()),
67
+ __metadata("design:type", Function),
68
+ __metadata("design:paramtypes", [Object, Object, Object]),
69
+ __metadata("design:returntype", Promise)
70
+ ], CurrencyService.prototype, "list", null);
71
+ __decorate([
72
+ (0, utils_1.InjectManager)("currencyRepository_"),
73
+ __param(2, (0, utils_1.MedusaContext)()),
74
+ __metadata("design:type", Function),
75
+ __metadata("design:paramtypes", [Object, Object, Object]),
76
+ __metadata("design:returntype", Promise)
77
+ ], CurrencyService.prototype, "listAndCount", null);
78
+ __decorate([
79
+ (0, utils_1.InjectTransactionManager)(utils_2.shouldForceTransaction, "currencyRepository_"),
80
+ __param(1, (0, utils_1.MedusaContext)()),
81
+ __metadata("design:type", Function),
82
+ __metadata("design:paramtypes", [Array, Object]),
83
+ __metadata("design:returntype", Promise)
84
+ ], CurrencyService.prototype, "create", null);
85
+ __decorate([
86
+ (0, utils_1.InjectTransactionManager)(utils_2.shouldForceTransaction, "currencyRepository_"),
87
+ __param(1, (0, utils_1.MedusaContext)()),
88
+ __metadata("design:type", Function),
89
+ __metadata("design:paramtypes", [Array, Object]),
90
+ __metadata("design:returntype", Promise)
91
+ ], CurrencyService.prototype, "update", null);
92
+ __decorate([
93
+ (0, utils_1.InjectTransactionManager)(utils_2.doNotForceTransaction, "currencyRepository_"),
94
+ __param(1, (0, utils_1.MedusaContext)()),
95
+ __metadata("design:type", Function),
96
+ __metadata("design:paramtypes", [Array, Object]),
97
+ __metadata("design:returntype", Promise)
98
+ ], CurrencyService.prototype, "delete", null);
@@ -0,0 +1,2 @@
1
+ export { default as CurrencyService } from "./currency";
2
+ export { default as PricingModuleService } from "./pricing-module";
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.PricingModuleService = exports.CurrencyService = void 0;
7
+ var currency_1 = require("./currency");
8
+ Object.defineProperty(exports, "CurrencyService", { enumerable: true, get: function () { return __importDefault(currency_1).default; } });
9
+ var pricing_module_1 = require("./pricing-module");
10
+ Object.defineProperty(exports, "PricingModuleService", { enumerable: true, get: function () { return __importDefault(pricing_module_1).default; } });
@@ -0,0 +1,21 @@
1
+ import { Context, DAL, FindConfig, InternalModuleDeclaration, JoinerServiceConfig, PricingTypes } from "@medusajs/types";
2
+ import { Currency } from "../models";
3
+ import { CurrencyService } from ".";
4
+ type InjectedDependencies = {
5
+ baseRepository: DAL.RepositoryService;
6
+ currencyService: CurrencyService<any>;
7
+ };
8
+ export default class PricingModuleService<TCurrency extends Currency = Currency> implements PricingTypes.IPricingModuleService {
9
+ protected readonly moduleDeclaration: InternalModuleDeclaration;
10
+ protected baseRepository_: DAL.RepositoryService;
11
+ protected readonly currencyService_: CurrencyService<TCurrency>;
12
+ constructor({ baseRepository, currencyService }: InjectedDependencies, moduleDeclaration: InternalModuleDeclaration);
13
+ __joinerConfig(): JoinerServiceConfig;
14
+ retrieveCurrency(code: string, config?: FindConfig<PricingTypes.CurrencyDTO>, sharedContext?: Context): Promise<PricingTypes.CurrencyDTO>;
15
+ listCurrencies(filters?: PricingTypes.FilterableCurrencyProps, config?: FindConfig<PricingTypes.CurrencyDTO>, sharedContext?: Context): Promise<PricingTypes.CurrencyDTO[]>;
16
+ listAndCountCurrencies(filters?: PricingTypes.FilterableCurrencyProps, config?: FindConfig<PricingTypes.CurrencyDTO>, sharedContext?: Context): Promise<[PricingTypes.CurrencyDTO[], number]>;
17
+ createCurrencies(data: PricingTypes.CreateCurrencyDTO[], sharedContext?: Context): Promise<PricingTypes.CurrencyDTO[]>;
18
+ updateCurrencies(data: PricingTypes.UpdateCurrencyDTO[], sharedContext?: Context): Promise<PricingTypes.CurrencyDTO[]>;
19
+ deleteCurrencies(currencyCodes: string[], sharedContext?: Context): Promise<void>;
20
+ }
21
+ export {};
@@ -0,0 +1,107 @@
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 types_1 = require("@medusajs/types");
16
+ const utils_1 = require("@medusajs/utils");
17
+ const utils_2 = require("@medusajs/utils");
18
+ const joiner_config_1 = require("../joiner-config");
19
+ class PricingModuleService {
20
+ constructor({ baseRepository, currencyService }, moduleDeclaration) {
21
+ this.moduleDeclaration = moduleDeclaration;
22
+ this.baseRepository_ = baseRepository;
23
+ this.currencyService_ = currencyService;
24
+ }
25
+ __joinerConfig() {
26
+ return joiner_config_1.joinerConfig;
27
+ }
28
+ async retrieveCurrency(code, config = {}, sharedContext = {}) {
29
+ const currency = await this.currencyService_.retrieve(code, config, sharedContext);
30
+ return this.baseRepository_.serialize(currency, {
31
+ populate: true,
32
+ });
33
+ }
34
+ async listCurrencies(filters = {}, config = {}, sharedContext = {}) {
35
+ const currencies = await this.currencyService_.list(filters, config, sharedContext);
36
+ return this.baseRepository_.serialize(currencies, {
37
+ populate: true,
38
+ });
39
+ }
40
+ async listAndCountCurrencies(filters = {}, config = {}, sharedContext = {}) {
41
+ const [currencies, count] = await this.currencyService_.listAndCount(filters, config, sharedContext);
42
+ return [
43
+ await this.baseRepository_.serialize(currencies, {
44
+ populate: true,
45
+ }),
46
+ count,
47
+ ];
48
+ }
49
+ async createCurrencies(data, sharedContext = {}) {
50
+ const currencies = await this.currencyService_.create(data, sharedContext);
51
+ return this.baseRepository_.serialize(currencies, {
52
+ populate: true,
53
+ });
54
+ }
55
+ async updateCurrencies(data, sharedContext = {}) {
56
+ const currencies = await this.currencyService_.update(data, sharedContext);
57
+ return this.baseRepository_.serialize(currencies, {
58
+ populate: true,
59
+ });
60
+ }
61
+ async deleteCurrencies(currencyCodes, sharedContext = {}) {
62
+ await this.currencyService_.delete(currencyCodes, sharedContext);
63
+ }
64
+ }
65
+ exports.default = PricingModuleService;
66
+ __decorate([
67
+ (0, utils_1.InjectManager)("baseRepository_"),
68
+ __param(2, (0, utils_1.MedusaContext)()),
69
+ __metadata("design:type", Function),
70
+ __metadata("design:paramtypes", [String, Object, Object]),
71
+ __metadata("design:returntype", Promise)
72
+ ], PricingModuleService.prototype, "retrieveCurrency", null);
73
+ __decorate([
74
+ (0, utils_1.InjectManager)("baseRepository_"),
75
+ __param(2, (0, utils_1.MedusaContext)()),
76
+ __metadata("design:type", Function),
77
+ __metadata("design:paramtypes", [Object, Object, Object]),
78
+ __metadata("design:returntype", Promise)
79
+ ], PricingModuleService.prototype, "listCurrencies", null);
80
+ __decorate([
81
+ (0, utils_1.InjectManager)("baseRepository_"),
82
+ __param(2, (0, utils_1.MedusaContext)()),
83
+ __metadata("design:type", Function),
84
+ __metadata("design:paramtypes", [Object, Object, Object]),
85
+ __metadata("design:returntype", Promise)
86
+ ], PricingModuleService.prototype, "listAndCountCurrencies", null);
87
+ __decorate([
88
+ (0, utils_1.InjectTransactionManager)(utils_2.shouldForceTransaction, "baseRepository_"),
89
+ __param(1, (0, utils_1.MedusaContext)()),
90
+ __metadata("design:type", Function),
91
+ __metadata("design:paramtypes", [Array, Object]),
92
+ __metadata("design:returntype", Promise)
93
+ ], PricingModuleService.prototype, "createCurrencies", null);
94
+ __decorate([
95
+ (0, utils_1.InjectTransactionManager)(utils_2.shouldForceTransaction, "baseRepository_"),
96
+ __param(1, (0, utils_1.MedusaContext)()),
97
+ __metadata("design:type", Function),
98
+ __metadata("design:paramtypes", [Array, Object]),
99
+ __metadata("design:returntype", Promise)
100
+ ], PricingModuleService.prototype, "updateCurrencies", null);
101
+ __decorate([
102
+ (0, utils_1.InjectTransactionManager)(utils_2.shouldForceTransaction, "baseRepository_"),
103
+ __param(1, (0, utils_1.MedusaContext)()),
104
+ __metadata("design:type", Function),
105
+ __metadata("design:paramtypes", [Array, Object]),
106
+ __metadata("design:returntype", Promise)
107
+ ], PricingModuleService.prototype, "deleteCurrencies", null);
@@ -0,0 +1,4 @@
1
+ import { Logger } from "@medusajs/types";
2
+ export type InitializeModuleInjectableDependencies = {
3
+ logger?: Logger;
4
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "@medusajs/pricing",
3
+ "version": "0.0.2-canary-20230831100806",
4
+ "description": "Medusa Pricing module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "bin": {
11
+ "medusa-pricing-migrations-down": "dist/scripts/bin/run-migration-down.js",
12
+ "medusa-pricing-migrations-up": "dist/scripts/bin/run-migration-up.js",
13
+ "medusa-pricing-seed": "dist/scripts/bin/run-seed.js"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/medusajs/medusa",
18
+ "directory": "packages/pricing"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "author": "Medusa",
24
+ "license": "MIT",
25
+ "scripts": {
26
+ "watch": "tsc --build --watch",
27
+ "watch:test": "tsc --build tsconfig.spec.json --watch",
28
+ "prepublishOnly": "cross-env NODE_ENV=production tsc --build && tsc-alias -p tsconfig.json",
29
+ "build": "rimraf dist && tsc --build && tsc-alias -p tsconfig.json",
30
+ "test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts",
31
+ "test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.ts",
32
+ "migration:generate": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:generate",
33
+ "migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create --initial",
34
+ "migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:create",
35
+ "migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm migration:up",
36
+ "orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts mikro-orm cache:clear"
37
+ },
38
+ "devDependencies": {
39
+ "@mikro-orm/cli": "5.7.12",
40
+ "cross-env": "^5.2.1",
41
+ "jest": "^29.6.3",
42
+ "medusa-test-utils": "^1.1.40",
43
+ "rimraf": "^3.0.2",
44
+ "ts-jest": "^29.1.1",
45
+ "ts-node": "^10.9.1",
46
+ "tsc-alias": "^1.8.6",
47
+ "typescript": "^5.1.6"
48
+ },
49
+ "dependencies": {
50
+ "@medusajs/modules-sdk": "1.10.0-canary-20230831100806",
51
+ "@medusajs/types": "1.11.0-canary-20230831100806",
52
+ "@medusajs/utils": "1.10.0-canary-20230831100806",
53
+ "@mikro-orm/core": "5.7.12",
54
+ "@mikro-orm/migrations": "5.7.12",
55
+ "@mikro-orm/postgresql": "5.7.12",
56
+ "awilix": "^8.0.0",
57
+ "dotenv": "^16.1.4",
58
+ "knex": "2.4.2"
59
+ }
60
+ }