@medusajs/promotion 0.0.1

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 (95) hide show
  1. package/README.md +3 -0
  2. package/dist/index.d.ts +6 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +21 -0
  5. package/dist/initialize/index.d.ts +5 -0
  6. package/dist/initialize/index.d.ts.map +1 -0
  7. package/dist/initialize/index.js +16 -0
  8. package/dist/joiner-config.d.ts +8 -0
  9. package/dist/joiner-config.d.ts.map +1 -0
  10. package/dist/joiner-config.js +28 -0
  11. package/dist/loaders/connection.d.ts +5 -0
  12. package/dist/loaders/connection.d.ts.map +1 -0
  13. package/dist/loaders/connection.js +41 -0
  14. package/dist/loaders/container.d.ts +5 -0
  15. package/dist/loaders/container.d.ts.map +1 -0
  16. package/dist/loaders/container.js +53 -0
  17. package/dist/loaders/index.d.ts +3 -0
  18. package/dist/loaders/index.d.ts.map +1 -0
  19. package/dist/loaders/index.js +18 -0
  20. package/dist/migrations/Migration20231221104256.d.ts +5 -0
  21. package/dist/migrations/Migration20231221104256.d.ts.map +1 -0
  22. package/dist/migrations/Migration20231221104256.js +19 -0
  23. package/dist/models/application-method.d.ts +21 -0
  24. package/dist/models/application-method.d.ts.map +1 -0
  25. package/dist/models/application-method.js +98 -0
  26. package/dist/models/index.d.ts +3 -0
  27. package/dist/models/index.d.ts.map +1 -0
  28. package/dist/models/index.js +10 -0
  29. package/dist/models/promotion.d.ts +20 -0
  30. package/dist/models/promotion.d.ts.map +1 -0
  31. package/dist/models/promotion.js +94 -0
  32. package/dist/module-definition.d.ts +3 -0
  33. package/dist/module-definition.d.ts.map +1 -0
  34. package/dist/module-definition.js +15 -0
  35. package/dist/repositories/application-method.d.ts +17 -0
  36. package/dist/repositories/application-method.d.ts.map +1 -0
  37. package/dist/repositories/application-method.js +59 -0
  38. package/dist/repositories/index.d.ts +4 -0
  39. package/dist/repositories/index.d.ts.map +1 -0
  40. package/dist/repositories/index.js +9 -0
  41. package/dist/repositories/promotion.d.ts +17 -0
  42. package/dist/repositories/promotion.d.ts.map +1 -0
  43. package/dist/repositories/promotion.js +69 -0
  44. package/dist/scripts/bin/run-migration-down.d.ts +4 -0
  45. package/dist/scripts/bin/run-migration-down.d.ts.map +1 -0
  46. package/dist/scripts/bin/run-migration-down.js +32 -0
  47. package/dist/scripts/bin/run-migration-up.d.ts +4 -0
  48. package/dist/scripts/bin/run-migration-up.d.ts.map +1 -0
  49. package/dist/scripts/bin/run-migration-up.js +32 -0
  50. package/dist/scripts/bin/run-seed.d.ts +4 -0
  51. package/dist/scripts/bin/run-seed.d.ts.map +1 -0
  52. package/dist/scripts/bin/run-seed.js +38 -0
  53. package/dist/scripts/index.d.ts +3 -0
  54. package/dist/scripts/index.d.ts.map +1 -0
  55. package/dist/scripts/index.js +18 -0
  56. package/dist/scripts/migration-down.d.ts +10 -0
  57. package/dist/scripts/migration-down.d.ts.map +1 -0
  58. package/dist/scripts/migration-down.js +53 -0
  59. package/dist/scripts/migration-up.d.ts +10 -0
  60. package/dist/scripts/migration-up.d.ts.map +1 -0
  61. package/dist/scripts/migration-up.js +57 -0
  62. package/dist/scripts/seed.d.ts +5 -0
  63. package/dist/scripts/seed.d.ts.map +1 -0
  64. package/dist/scripts/seed.js +54 -0
  65. package/dist/services/application-method.d.ts +18 -0
  66. package/dist/services/application-method.d.ts.map +1 -0
  67. package/dist/services/application-method.js +91 -0
  68. package/dist/services/index.d.ts +4 -0
  69. package/dist/services/index.d.ts.map +1 -0
  70. package/dist/services/index.js +12 -0
  71. package/dist/services/promotion-module.d.ts +21 -0
  72. package/dist/services/promotion-module.d.ts.map +1 -0
  73. package/dist/services/promotion-module.js +88 -0
  74. package/dist/services/promotion.d.ts +18 -0
  75. package/dist/services/promotion.d.ts.map +1 -0
  76. package/dist/services/promotion.js +91 -0
  77. package/dist/types/application-method.d.ts +13 -0
  78. package/dist/types/application-method.d.ts.map +1 -0
  79. package/dist/types/application-method.js +2 -0
  80. package/dist/types/index.d.ts +7 -0
  81. package/dist/types/index.d.ts.map +1 -0
  82. package/dist/types/index.js +18 -0
  83. package/dist/types/promotion.d.ts +10 -0
  84. package/dist/types/promotion.d.ts.map +1 -0
  85. package/dist/types/promotion.js +2 -0
  86. package/dist/utils/index.d.ts +2 -0
  87. package/dist/utils/index.d.ts.map +1 -0
  88. package/dist/utils/index.js +17 -0
  89. package/dist/utils/validations/application-method.d.ts +3 -0
  90. package/dist/utils/validations/application-method.d.ts.map +1 -0
  91. package/dist/utils/validations/application-method.js +26 -0
  92. package/dist/utils/validations/index.d.ts +2 -0
  93. package/dist/utils/validations/index.d.ts.map +1 -0
  94. package/dist/utils/validations/index.js +17 -0
  95. package/package.json +63 -0
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # Promotion Module
2
+
3
+ The PromotionModule is Medusa’s promotion engine. It offers functionality to discount carts through coupon codes with a given set of rules governing when and how the code should be applied.
@@ -0,0 +1,6 @@
1
+ import { moduleDefinition } from "./module-definition";
2
+ export default moduleDefinition;
3
+ export * from "./initialize";
4
+ export * from "./loaders";
5
+ export * from "./scripts";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEtD,eAAe,gBAAgB,CAAA;AAE/B,cAAc,cAAc,CAAA;AAC5B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
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("./initialize"), exports);
20
+ __exportStar(require("./loaders"), exports);
21
+ __exportStar(require("./scripts"), exports);
@@ -0,0 +1,5 @@
1
+ import { ExternalModuleDeclaration, InternalModuleDeclaration } from "@medusajs/modules-sdk";
2
+ import { IPromotionModuleService, ModulesSdkTypes } from "@medusajs/types";
3
+ import { InitializeModuleInjectableDependencies } from "../types";
4
+ export declare const initialize: (options?: ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions | ExternalModuleDeclaration | InternalModuleDeclaration, injectedDependencies?: InitializeModuleInjectableDependencies) => Promise<IPromotionModuleService>;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/initialize/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,yBAAyB,EAI1B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAE1E,OAAO,EAAE,sCAAsC,EAAE,MAAM,UAAU,CAAA;AAEjE,eAAO,MAAM,UAAU,aAEjB,gBAAgB,8BAA8B,GAC9C,gBAAgB,6CAA6C,GAC7D,yBAAyB,GACzB,yBAAyB,yBACN,sCAAsC,KAC5D,QAAQ,uBAAuB,CAYjC,CAAA"}
@@ -0,0 +1,16 @@
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 loaded = await modules_sdk_1.MedusaModule.bootstrap({
8
+ moduleKey: modules_sdk_1.Modules.PROMOTION,
9
+ defaultPath: modules_sdk_1.MODULE_PACKAGE_NAMES[modules_sdk_1.Modules.PROMOTION],
10
+ declaration: options,
11
+ injectedDependencies,
12
+ moduleExports: module_definition_1.moduleDefinition,
13
+ });
14
+ return loaded[modules_sdk_1.Modules.PROMOTION];
15
+ };
16
+ exports.initialize = initialize;
@@ -0,0 +1,8 @@
1
+ import { ModuleJoinerConfig } from "@medusajs/types";
2
+ import { MapToConfig } from "@medusajs/utils";
3
+ export declare const LinkableKeys: {
4
+ promotion_id: string;
5
+ };
6
+ export declare const entityNameToLinkableKeysMap: MapToConfig;
7
+ export declare const joinerConfig: ModuleJoinerConfig;
8
+ //# sourceMappingURL=joiner-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"joiner-config.d.ts","sourceRoot":"","sources":["../src/joiner-config.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAG7C,eAAO,MAAM,YAAY;;CAExB,CAAA;AAWD,eAAO,MAAM,2BAA2B,EAAE,WAAmC,CAAA;AAE7E,eAAO,MAAM,YAAY,EAAE,kBAU1B,CAAA"}
@@ -0,0 +1,28 @@
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
+ exports.LinkableKeys = {
7
+ promotion_id: _models_1.Promotion.name,
8
+ };
9
+ const entityLinkableKeysMap = {};
10
+ Object.entries(exports.LinkableKeys).forEach(([key, value]) => {
11
+ entityLinkableKeysMap[value] ?? (entityLinkableKeysMap[value] = []);
12
+ entityLinkableKeysMap[value].push({
13
+ mapTo: key,
14
+ valueFrom: key.split("_").pop(),
15
+ });
16
+ });
17
+ exports.entityNameToLinkableKeysMap = entityLinkableKeysMap;
18
+ exports.joinerConfig = {
19
+ serviceName: modules_sdk_1.Modules.PROMOTION,
20
+ primaryKeys: ["id"],
21
+ linkableKeys: exports.LinkableKeys,
22
+ alias: {
23
+ name: ["promotion", "promotions"],
24
+ args: {
25
+ entity: _models_1.Promotion.name,
26
+ },
27
+ },
28
+ };
@@ -0,0 +1,5 @@
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;
5
+ //# sourceMappingURL=connection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../src/loaders/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,aAAa,EAEd,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;0DAU5C,cACC,gBAAgB,8BAA8B,GAC9C,gBAAgB,6CAA6C,CAChE,sBACmB,yBAAyB,KAC5C,QAAQ,IAAI,CAAC;AAVhB,wBAuBC"}
@@ -0,0 +1,41 @@
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 modules_sdk_1 = require("@medusajs/modules-sdk");
27
+ const utils_1 = require("@medusajs/utils");
28
+ const PromotionModels = __importStar(require("../models"));
29
+ exports.default = async ({ options, container, logger, }, moduleDeclaration) => {
30
+ const entities = Object.values(PromotionModels);
31
+ const pathToMigrations = __dirname + "/../migrations";
32
+ await utils_1.ModulesSdkUtils.mikroOrmConnectionLoader({
33
+ moduleName: modules_sdk_1.Modules.PROMOTION,
34
+ entities,
35
+ container,
36
+ options,
37
+ moduleDeclaration,
38
+ logger,
39
+ pathToMigrations,
40
+ });
41
+ };
@@ -0,0 +1,5 @@
1
+ import { LoaderOptions } from "@medusajs/modules-sdk";
2
+ import { ModulesSdkTypes } from "@medusajs/types";
3
+ declare const _default: ({ container, options, }: LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions | ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions>) => Promise<void>;
4
+ export default _default;
5
+ //# sourceMappingURL=container.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"container.d.ts","sourceRoot":"","sources":["../../src/loaders/container.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;kDAQ9C,cACC,gBAAgB,8BAA8B,GAC9C,gBAAgB,6CAA6C,CAChE,KAAG,QAAQ,IAAI,CAAC;AANjB,wBA2BC"}
@@ -0,0 +1,53 @@
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 utils_1 = require("@medusajs/utils");
28
+ const defaultServices = __importStar(require("../services"));
29
+ const awilix_1 = require("awilix");
30
+ exports.default = async ({ container, options, }) => {
31
+ const customRepositories = options?.repositories;
32
+ container.register({
33
+ promotionService: (0, awilix_1.asClass)(defaultServices.PromotionService).singleton(),
34
+ applicationMethodService: (0, awilix_1.asClass)(defaultServices.ApplicationMethodService).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)(defaultRepositories.BaseRepository).singleton(),
50
+ applicationMethodRepository: (0, awilix_1.asClass)(defaultRepositories.ApplicationMethodRepository).singleton(),
51
+ promotionRepository: (0, awilix_1.asClass)(defaultRepositories.PromotionRepository).singleton(),
52
+ });
53
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./connection";
2
+ export * from "./container";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/loaders/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA"}
@@ -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,5 @@
1
+ import { Migration } from "@mikro-orm/migrations";
2
+ export declare class Migration20231221104256 extends Migration {
3
+ up(): Promise<void>;
4
+ }
5
+ //# sourceMappingURL=Migration20231221104256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Migration20231221104256.d.ts","sourceRoot":"","sources":["../../src/migrations/Migration20231221104256.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,qBAAa,uBAAwB,SAAQ,SAAS;IAC9C,EAAE,IAAI,OAAO,CAAC,IAAI,CAAC;CA8B1B"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20231221104256 = void 0;
4
+ const migrations_1 = require("@mikro-orm/migrations");
5
+ class Migration20231221104256 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql('create table "promotion" ("id" text not null, "code" text not null, "is_automatic" boolean not null default false, "type" text check ("type" in (\'standard\', \'buyget\')) not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "promotion_pkey" primary key ("id"));');
8
+ this.addSql('create index "IDX_promotion_code" on "promotion" ("code");');
9
+ this.addSql('create index "IDX_promotion_type" on "promotion" ("type");');
10
+ this.addSql('alter table "promotion" add constraint "IDX_promotion_code_unique" unique ("code");');
11
+ this.addSql('create table "application_method" ("id" text not null, "value" numeric null, "max_quantity" numeric null, "type" text check ("type" in (\'fixed\', \'percentage\')) not null, "target_type" text check ("target_type" in (\'order\', \'shipping\', \'item\')) not null, "allocation" text check ("allocation" in (\'each\', \'across\')) null, "promotion_id" text not null, "created_at" timestamptz not null default now(), "updated_at" timestamptz not null default now(), "deleted_at" timestamptz null, constraint "application_method_pkey" primary key ("id"));');
12
+ this.addSql('create index "IDX_application_method_type" on "application_method" ("type");');
13
+ this.addSql('create index "IDX_application_method_target_type" on "application_method" ("target_type");');
14
+ this.addSql('create index "IDX_application_method_allocation" on "application_method" ("allocation");');
15
+ this.addSql('alter table "application_method" add constraint "application_method_promotion_id_unique" unique ("promotion_id");');
16
+ this.addSql('alter table "application_method" add constraint "application_method_promotion_id_foreign" foreign key ("promotion_id") references "promotion" ("id") on update cascade;');
17
+ }
18
+ }
19
+ exports.Migration20231221104256 = Migration20231221104256;
@@ -0,0 +1,21 @@
1
+ import { ApplicationMethodAllocation, ApplicationMethodTargetType, ApplicationMethodType } from "@medusajs/types";
2
+ import { OptionalProps } from "@mikro-orm/core";
3
+ import Promotion from "./promotion";
4
+ type OptionalFields = "value" | "max_quantity" | "allocation";
5
+ export default class ApplicationMethod {
6
+ [OptionalProps]?: OptionalFields;
7
+ id: string;
8
+ value?: number;
9
+ max_quantity?: number;
10
+ type: ApplicationMethodType;
11
+ target_type: ApplicationMethodTargetType;
12
+ allocation?: ApplicationMethodAllocation;
13
+ promotion: Promotion;
14
+ created_at?: Date;
15
+ updated_at?: Date;
16
+ deleted_at?: Date;
17
+ onCreate(): void;
18
+ onInit(): void;
19
+ }
20
+ export {};
21
+ //# sourceMappingURL=application-method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-method.d.ts","sourceRoot":"","sources":["../../src/models/application-method.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,EAC3B,qBAAqB,EACtB,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAOL,aAAa,EAGd,MAAM,iBAAiB,CAAA;AACxB,OAAO,SAAS,MAAM,aAAa,CAAA;AAEnC,KAAK,cAAc,GAAG,OAAO,GAAG,cAAc,GAAG,YAAY,CAAA;AAE7D,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,CAAC,aAAa,CAAC,CAAC,EAAE,cAAc,CAAA;IAGhC,EAAE,EAAG,MAAM,CAAA;IAGX,KAAK,CAAC,EAAE,MAAM,CAAA;IAGd,YAAY,CAAC,EAAE,MAAM,CAAA;IAIrB,IAAI,EAAE,qBAAqB,CAAA;IAI3B,WAAW,EAAE,2BAA2B,CAAA;IAOxC,UAAU,CAAC,EAAE,2BAA2B,CAAA;IAKxC,SAAS,EAAE,SAAS,CAAA;IAOpB,UAAU,CAAC,EAAE,IAAI,CAAA;IAQjB,UAAU,CAAC,EAAE,IAAI,CAAA;IAGjB,UAAU,CAAC,EAAE,IAAI,CAAA;IAGjB,QAAQ;IAKR,MAAM;CAGP"}
@@ -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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const utils_1 = require("@medusajs/utils");
16
+ const core_1 = require("@mikro-orm/core");
17
+ const promotion_1 = __importDefault(require("./promotion"));
18
+ let ApplicationMethod = class ApplicationMethod {
19
+ onCreate() {
20
+ this.id = (0, utils_1.generateEntityId)(this.id, "app_method");
21
+ }
22
+ onInit() {
23
+ this.id = (0, utils_1.generateEntityId)(this.id, "promo");
24
+ }
25
+ };
26
+ __decorate([
27
+ (0, core_1.PrimaryKey)({ columnType: "text" }),
28
+ __metadata("design:type", String)
29
+ ], ApplicationMethod.prototype, "id", void 0);
30
+ __decorate([
31
+ (0, core_1.Property)({ columnType: "numeric", nullable: true, serializer: Number }),
32
+ __metadata("design:type", Number)
33
+ ], ApplicationMethod.prototype, "value", void 0);
34
+ __decorate([
35
+ (0, core_1.Property)({ columnType: "numeric", nullable: true, serializer: Number }),
36
+ __metadata("design:type", Number)
37
+ ], ApplicationMethod.prototype, "max_quantity", void 0);
38
+ __decorate([
39
+ (0, core_1.Index)({ name: "IDX_application_method_type" }),
40
+ (0, core_1.Enum)(() => utils_1.PromotionUtils.ApplicationMethodType),
41
+ __metadata("design:type", String)
42
+ ], ApplicationMethod.prototype, "type", void 0);
43
+ __decorate([
44
+ (0, core_1.Index)({ name: "IDX_application_method_target_type" }),
45
+ (0, core_1.Enum)(() => utils_1.PromotionUtils.ApplicationMethodTargetType),
46
+ __metadata("design:type", String)
47
+ ], ApplicationMethod.prototype, "target_type", void 0);
48
+ __decorate([
49
+ (0, core_1.Index)({ name: "IDX_application_method_allocation" }),
50
+ (0, core_1.Enum)({
51
+ items: () => utils_1.PromotionUtils.ApplicationMethodAllocation,
52
+ nullable: true,
53
+ }),
54
+ __metadata("design:type", String)
55
+ ], ApplicationMethod.prototype, "allocation", void 0);
56
+ __decorate([
57
+ (0, core_1.OneToOne)({
58
+ entity: () => promotion_1.default,
59
+ }),
60
+ __metadata("design:type", promotion_1.default)
61
+ ], ApplicationMethod.prototype, "promotion", void 0);
62
+ __decorate([
63
+ (0, core_1.Property)({
64
+ onCreate: () => new Date(),
65
+ columnType: "timestamptz",
66
+ defaultRaw: "now()",
67
+ }),
68
+ __metadata("design:type", Date)
69
+ ], ApplicationMethod.prototype, "created_at", void 0);
70
+ __decorate([
71
+ (0, core_1.Property)({
72
+ onCreate: () => new Date(),
73
+ onUpdate: () => new Date(),
74
+ columnType: "timestamptz",
75
+ defaultRaw: "now()",
76
+ }),
77
+ __metadata("design:type", Date)
78
+ ], ApplicationMethod.prototype, "updated_at", void 0);
79
+ __decorate([
80
+ (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
81
+ __metadata("design:type", Date)
82
+ ], ApplicationMethod.prototype, "deleted_at", void 0);
83
+ __decorate([
84
+ (0, core_1.BeforeCreate)(),
85
+ __metadata("design:type", Function),
86
+ __metadata("design:paramtypes", []),
87
+ __metadata("design:returntype", void 0)
88
+ ], ApplicationMethod.prototype, "onCreate", null);
89
+ __decorate([
90
+ (0, core_1.OnInit)(),
91
+ __metadata("design:type", Function),
92
+ __metadata("design:paramtypes", []),
93
+ __metadata("design:returntype", void 0)
94
+ ], ApplicationMethod.prototype, "onInit", null);
95
+ ApplicationMethod = __decorate([
96
+ (0, core_1.Entity)()
97
+ ], ApplicationMethod);
98
+ exports.default = ApplicationMethod;
@@ -0,0 +1,3 @@
1
+ export { default as ApplicationMethod } from "./application-method";
2
+ export { default as Promotion } from "./promotion";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AACnE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,aAAa,CAAA"}
@@ -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.Promotion = exports.ApplicationMethod = void 0;
7
+ var application_method_1 = require("./application-method");
8
+ Object.defineProperty(exports, "ApplicationMethod", { enumerable: true, get: function () { return __importDefault(application_method_1).default; } });
9
+ var promotion_1 = require("./promotion");
10
+ Object.defineProperty(exports, "Promotion", { enumerable: true, get: function () { return __importDefault(promotion_1).default; } });
@@ -0,0 +1,20 @@
1
+ import { PromotionType } from "@medusajs/types";
2
+ import { OptionalProps } from "@mikro-orm/core";
3
+ import ApplicationMethod from "./application-method";
4
+ type OptionalFields = "is_automatic";
5
+ type OptionalRelations = "application_method";
6
+ export default class Promotion {
7
+ [OptionalProps]?: OptionalFields | OptionalRelations;
8
+ id: string;
9
+ code: string;
10
+ is_automatic?: boolean;
11
+ type: PromotionType;
12
+ application_method: ApplicationMethod;
13
+ created_at?: Date;
14
+ updated_at?: Date;
15
+ deleted_at?: Date;
16
+ onCreate(): void;
17
+ onInit(): void;
18
+ }
19
+ export {};
20
+ //# sourceMappingURL=promotion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promotion.d.ts","sourceRoot":"","sources":["../../src/models/promotion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE/C,OAAO,EAOL,aAAa,EAId,MAAM,iBAAiB,CAAA;AACxB,OAAO,iBAAiB,MAAM,sBAAsB,CAAA;AAEpD,KAAK,cAAc,GAAG,cAAc,CAAA;AACpC,KAAK,iBAAiB,GAAG,oBAAoB,CAAA;AAE7C,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,CAAC,aAAa,CAAC,CAAC,EAAE,cAAc,GAAG,iBAAiB,CAAA;IAGpD,EAAE,EAAG,MAAM,CAAA;IAQX,IAAI,EAAE,MAAM,CAAA;IAGZ,YAAY,CAAC,EAAE,OAAO,CAAQ;IAI9B,IAAI,EAAE,aAAa,CAAA;IAMnB,kBAAkB,EAAE,iBAAiB,CAAA;IAOrC,UAAU,CAAC,EAAE,IAAI,CAAA;IAQjB,UAAU,CAAC,EAAE,IAAI,CAAA;IAGjB,UAAU,CAAC,EAAE,IAAI,CAAA;IAGjB,QAAQ;IAKR,MAAM;CAGP"}
@@ -0,0 +1,94 @@
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 __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const utils_1 = require("@medusajs/utils");
16
+ const core_1 = require("@mikro-orm/core");
17
+ const application_method_1 = __importDefault(require("./application-method"));
18
+ let Promotion = class Promotion {
19
+ constructor() {
20
+ this.is_automatic = false;
21
+ }
22
+ onCreate() {
23
+ this.id = (0, utils_1.generateEntityId)(this.id, "promo");
24
+ }
25
+ onInit() {
26
+ this.id = (0, utils_1.generateEntityId)(this.id, "promo");
27
+ }
28
+ };
29
+ __decorate([
30
+ (0, core_1.PrimaryKey)({ columnType: "text" }),
31
+ __metadata("design:type", String)
32
+ ], Promotion.prototype, "id", void 0);
33
+ __decorate([
34
+ (0, core_1.Property)({ columnType: "text" }),
35
+ (0, core_1.Index)({ name: "IDX_promotion_code" }),
36
+ (0, core_1.Unique)({
37
+ name: "IDX_promotion_code_unique",
38
+ properties: ["code"],
39
+ }),
40
+ __metadata("design:type", String)
41
+ ], Promotion.prototype, "code", void 0);
42
+ __decorate([
43
+ (0, core_1.Property)({ columnType: "boolean", default: false }),
44
+ __metadata("design:type", Boolean)
45
+ ], Promotion.prototype, "is_automatic", void 0);
46
+ __decorate([
47
+ (0, core_1.Index)({ name: "IDX_promotion_type" }),
48
+ (0, core_1.Enum)(() => utils_1.PromotionUtils.PromotionType),
49
+ __metadata("design:type", String)
50
+ ], Promotion.prototype, "type", void 0);
51
+ __decorate([
52
+ (0, core_1.OneToOne)({
53
+ entity: () => application_method_1.default,
54
+ mappedBy: (am) => am.promotion,
55
+ }),
56
+ __metadata("design:type", application_method_1.default)
57
+ ], Promotion.prototype, "application_method", void 0);
58
+ __decorate([
59
+ (0, core_1.Property)({
60
+ onCreate: () => new Date(),
61
+ columnType: "timestamptz",
62
+ defaultRaw: "now()",
63
+ }),
64
+ __metadata("design:type", Date)
65
+ ], Promotion.prototype, "created_at", void 0);
66
+ __decorate([
67
+ (0, core_1.Property)({
68
+ onCreate: () => new Date(),
69
+ onUpdate: () => new Date(),
70
+ columnType: "timestamptz",
71
+ defaultRaw: "now()",
72
+ }),
73
+ __metadata("design:type", Date)
74
+ ], Promotion.prototype, "updated_at", void 0);
75
+ __decorate([
76
+ (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
77
+ __metadata("design:type", Date)
78
+ ], Promotion.prototype, "deleted_at", void 0);
79
+ __decorate([
80
+ (0, core_1.BeforeCreate)(),
81
+ __metadata("design:type", Function),
82
+ __metadata("design:paramtypes", []),
83
+ __metadata("design:returntype", void 0)
84
+ ], Promotion.prototype, "onCreate", null);
85
+ __decorate([
86
+ (0, core_1.OnInit)(),
87
+ __metadata("design:type", Function),
88
+ __metadata("design:paramtypes", []),
89
+ __metadata("design:returntype", void 0)
90
+ ], Promotion.prototype, "onInit", null);
91
+ Promotion = __decorate([
92
+ (0, core_1.Entity)()
93
+ ], Promotion);
94
+ exports.default = Promotion;
@@ -0,0 +1,3 @@
1
+ import { ModuleExports } from "@medusajs/types";
2
+ export declare const moduleDefinition: ModuleExports;
3
+ //# sourceMappingURL=module-definition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module-definition.d.ts","sourceRoot":"","sources":["../src/module-definition.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAQ/C,eAAO,MAAM,gBAAgB,EAAE,aAG9B,CAAA"}
@@ -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.PromotionModuleService;
11
+ const loaders = [container_1.default, connection_1.default];
12
+ exports.moduleDefinition = {
13
+ service,
14
+ loaders,
15
+ };
@@ -0,0 +1,17 @@
1
+ import { Context, DAL } from "@medusajs/types";
2
+ import { DALUtils } from "@medusajs/utils";
3
+ import { SqlEntityManager } from "@mikro-orm/postgresql";
4
+ import { ApplicationMethod } from "../models";
5
+ import { CreateApplicationMethodDTO, UpdateApplicationMethodDTO } from "../types";
6
+ export declare class ApplicationMethodRepository extends DALUtils.MikroOrmBaseRepository {
7
+ protected readonly manager_: SqlEntityManager;
8
+ constructor({ manager }: {
9
+ manager: SqlEntityManager;
10
+ });
11
+ find(findOptions?: DAL.FindOptions<ApplicationMethod>, context?: Context): Promise<ApplicationMethod[]>;
12
+ findAndCount(findOptions?: DAL.FindOptions<ApplicationMethod>, context?: Context): Promise<[ApplicationMethod[], number]>;
13
+ delete(ids: string[], context?: Context): Promise<void>;
14
+ create(data: CreateApplicationMethodDTO[], context?: Context): Promise<ApplicationMethod[]>;
15
+ update(data: UpdateApplicationMethodDTO[], context?: Context): Promise<ApplicationMethod[]>;
16
+ }
17
+ //# sourceMappingURL=application-method.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application-method.d.ts","sourceRoot":"","sources":["../../src/repositories/application-method.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AAC9C,OAAO,EAAE,QAAQ,EAAe,MAAM,iBAAiB,CAAA;AAKvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC3B,MAAM,UAAU,CAAA;AAEjB,qBAAa,2BAA4B,SAAQ,QAAQ,CAAC,sBAAsB;IAC9E,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAA;gBAEjC,EAAE,OAAO,EAAE,EAAE;QAAE,OAAO,EAAE,gBAAgB,CAAA;KAAE;IAOhD,IAAI,CACR,WAAW,GAAE,GAAG,CAAC,WAAW,CAAC,iBAAiB,CAAiB,EAC/D,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAazB,YAAY,CAChB,WAAW,GAAE,GAAG,CAAC,WAAW,CAAC,iBAAiB,CAAiB,EAC/D,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,CAAC,iBAAiB,EAAE,EAAE,MAAM,CAAC,CAAC;IAanC,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,OAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IAM3D,MAAM,CACV,IAAI,EAAE,0BAA0B,EAAE,EAClC,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAYzB,MAAM,CACV,IAAI,EAAE,0BAA0B,EAAE,EAClC,OAAO,GAAE,OAAY,GACpB,OAAO,CAAC,iBAAiB,EAAE,CAAC;CAyChC"}