@medusajs/product 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 (83) hide show
  1. package/dist/index.d.ts +8 -0
  2. package/dist/index.js +24 -0
  3. package/dist/initialize/index.d.ts +4 -0
  4. package/dist/initialize/index.js +11 -0
  5. package/dist/loaders/connection.d.ts +4 -0
  6. package/dist/loaders/connection.js +56 -0
  7. package/dist/loaders/container.d.ts +4 -0
  8. package/dist/loaders/container.js +76 -0
  9. package/dist/loaders/index.d.ts +2 -0
  10. package/dist/loaders/index.js +18 -0
  11. package/dist/migrations/Migration20230609132805.d.ts +4 -0
  12. package/dist/migrations/Migration20230609132805.js +42 -0
  13. package/dist/models/index.d.ts +6 -0
  14. package/dist/models/index.js +18 -0
  15. package/dist/models/product-category.d.ts +20 -0
  16. package/dist/models/product-category.js +123 -0
  17. package/dist/models/product-collection.d.ts +9 -0
  18. package/dist/models/product-collection.js +55 -0
  19. package/dist/models/product-option-value.d.ts +12 -0
  20. package/dist/models/product-option-value.js +59 -0
  21. package/dist/models/product-option.d.ts +14 -0
  22. package/dist/models/product-option.js +68 -0
  23. package/dist/models/product-tag.d.ts +11 -0
  24. package/dist/models/product-tag.js +55 -0
  25. package/dist/models/product-type.d.ts +8 -0
  26. package/dist/models/product-type.js +44 -0
  27. package/dist/models/product-variant.d.ts +34 -0
  28. package/dist/models/product-variant.js +162 -0
  29. package/dist/models/product.d.ts +43 -0
  30. package/dist/models/product.js +177 -0
  31. package/dist/module-definition.d.ts +2 -0
  32. package/dist/module-definition.js +44 -0
  33. package/dist/repositories/index.d.ts +5 -0
  34. package/dist/repositories/index.js +13 -0
  35. package/dist/repositories/product-category.d.ts +16 -0
  36. package/dist/repositories/product-category.js +86 -0
  37. package/dist/repositories/product-collection.d.ts +15 -0
  38. package/dist/repositories/product-collection.js +46 -0
  39. package/dist/repositories/product-tag.d.ts +15 -0
  40. package/dist/repositories/product-tag.js +46 -0
  41. package/dist/repositories/product-variant.d.ts +15 -0
  42. package/dist/repositories/product-variant.js +46 -0
  43. package/dist/repositories/product.d.ts +21 -0
  44. package/dist/repositories/product.js +72 -0
  45. package/dist/scripts/bin/run-migration-down.d.ts +2 -0
  46. package/dist/scripts/bin/run-migration-down.js +31 -0
  47. package/dist/scripts/bin/run-migration-up.d.ts +2 -0
  48. package/dist/scripts/bin/run-migration-up.js +31 -0
  49. package/dist/scripts/bin/run-seed.d.ts +2 -0
  50. package/dist/scripts/bin/run-seed.js +37 -0
  51. package/dist/scripts/index.d.ts +2 -0
  52. package/dist/scripts/index.js +18 -0
  53. package/dist/scripts/migration-down.d.ts +10 -0
  54. package/dist/scripts/migration-down.js +51 -0
  55. package/dist/scripts/migration-up.d.ts +10 -0
  56. package/dist/scripts/migration-up.js +51 -0
  57. package/dist/scripts/seed.d.ts +5 -0
  58. package/dist/scripts/seed.js +87 -0
  59. package/dist/services/index.d.ts +6 -0
  60. package/dist/services/index.js +18 -0
  61. package/dist/services/product-category.d.ts +11 -0
  62. package/dist/services/product-category.js +18 -0
  63. package/dist/services/product-collection.d.ts +11 -0
  64. package/dist/services/product-collection.js +17 -0
  65. package/dist/services/product-module-service.d.ts +25 -0
  66. package/dist/services/product-module-service.js +36 -0
  67. package/dist/services/product-tag.d.ts +11 -0
  68. package/dist/services/product-tag.js +16 -0
  69. package/dist/services/product-variant.d.ts +11 -0
  70. package/dist/services/product-variant.js +13 -0
  71. package/dist/services/product.d.ts +15 -0
  72. package/dist/services/product.js +43 -0
  73. package/dist/types/index.d.ts +17 -0
  74. package/dist/types/index.js +2 -0
  75. package/dist/utils/create-connection.d.ts +3 -0
  76. package/dist/utils/create-connection.js +35 -0
  77. package/dist/utils/index.d.ts +3 -0
  78. package/dist/utils/index.js +19 -0
  79. package/dist/utils/load-database-config.d.ts +7 -0
  80. package/dist/utils/load-database-config.js +59 -0
  81. package/dist/utils/query/index.d.ts +6 -0
  82. package/dist/utils/query/index.js +35 -0
  83. package/package.json +62 -0
@@ -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 } from "@medusajs/modules-sdk";
2
+ import { IProductModuleService } from "@medusajs/types";
3
+ import { InitializeModuleInjectableDependencies, ProductServiceInitializeCustomDataLayerOptions, ProductServiceInitializeOptions } from "../types";
4
+ export declare const initialize: (options?: ProductServiceInitializeOptions | ProductServiceInitializeCustomDataLayerOptions | ExternalModuleDeclaration, injectedDependencies?: InitializeModuleInjectableDependencies) => Promise<IProductModuleService>;
@@ -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.PRODUCT;
8
+ const loaded = await modules_sdk_1.MedusaModule.bootstrap(serviceKey, modules_sdk_1.MODULE_PACKAGE_NAMES[modules_sdk_1.Modules.PRODUCT], options, module_definition_1.moduleDefinition, injectedDependencies);
9
+ return loaded[serviceKey];
10
+ };
11
+ exports.initialize = initialize;
@@ -0,0 +1,4 @@
1
+ import { InternalModuleDeclaration, LoaderOptions } from "@medusajs/modules-sdk";
2
+ import { ProductServiceInitializeCustomDataLayerOptions, ProductServiceInitializeOptions } from "../types";
3
+ declare const _default: ({ options, container, }: LoaderOptions<ProductServiceInitializeOptions | ProductServiceInitializeCustomDataLayerOptions>, moduleDeclaration?: InternalModuleDeclaration) => Promise<void>;
4
+ export default _default;
@@ -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
+ const awilix_1 = require("awilix");
27
+ const modules_sdk_1 = require("@medusajs/modules-sdk");
28
+ const utils_1 = require("@medusajs/utils");
29
+ const ProductModels = __importStar(require("../models"));
30
+ const utils_2 = require("../utils");
31
+ exports.default = async ({ options, container, }, moduleDeclaration) => {
32
+ if (moduleDeclaration?.scope === modules_sdk_1.MODULE_SCOPE.INTERNAL &&
33
+ moduleDeclaration.resources === modules_sdk_1.MODULE_RESOURCE_TYPE.SHARED) {
34
+ return;
35
+ }
36
+ const customManager = options?.manager;
37
+ if (!customManager) {
38
+ const dbData = (0, utils_2.loadDatabaseConfig)(options);
39
+ await loadDefault({ database: dbData, container });
40
+ }
41
+ else {
42
+ container.register({
43
+ manager: (0, awilix_1.asValue)(customManager),
44
+ });
45
+ }
46
+ };
47
+ async function loadDefault({ database, container }) {
48
+ if (!database) {
49
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_ARGUMENT, `Database config is not present at module config "options.database"`);
50
+ }
51
+ const entities = Object.values(ProductModels);
52
+ const orm = await (0, utils_2.createConnection)(database, entities);
53
+ container.register({
54
+ manager: (0, awilix_1.asValue)(orm.em.fork()),
55
+ });
56
+ }
@@ -0,0 +1,4 @@
1
+ import { LoaderOptions } from "@medusajs/modules-sdk";
2
+ import { ProductServiceInitializeCustomDataLayerOptions, ProductServiceInitializeOptions } from "../types";
3
+ declare const _default: ({ container, options, }: LoaderOptions<ProductServiceInitializeOptions | ProductServiceInitializeCustomDataLayerOptions>) => Promise<void>;
4
+ export default _default;
@@ -0,0 +1,76 @@
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 awilix_1 = require("awilix");
27
+ const _services_1 = require("../services");
28
+ const DefaultRepositories = __importStar(require("../repositories"));
29
+ const _repositories_1 = require("../repositories");
30
+ const utils_1 = require("@medusajs/utils");
31
+ exports.default = async ({ container, options, }) => {
32
+ const customRepositories = options?.repositories;
33
+ container.register({
34
+ productModuleService: (0, awilix_1.asClass)(_services_1.ProductModuleService).singleton(),
35
+ productService: (0, awilix_1.asClass)(_services_1.ProductService).singleton(),
36
+ productCategoryService: (0, awilix_1.asClass)(_services_1.ProductCategoryService).singleton(),
37
+ productVariantService: (0, awilix_1.asClass)(_services_1.ProductVariantService).singleton(),
38
+ productTagService: (0, awilix_1.asClass)(_services_1.ProductTagService).singleton(),
39
+ productCollectionService: (0, awilix_1.asClass)(_services_1.ProductCollectionService).singleton(),
40
+ });
41
+ if (customRepositories) {
42
+ await loadCustomRepositories({ customRepositories, container });
43
+ }
44
+ else {
45
+ await loadDefaultRepositories({ container });
46
+ }
47
+ };
48
+ function loadDefaultRepositories({ container }) {
49
+ container.register({
50
+ productRepository: (0, awilix_1.asClass)(_repositories_1.ProductRepository).singleton(),
51
+ productVariantRepository: (0, awilix_1.asClass)(_repositories_1.ProductVariantRepository).singleton(),
52
+ productTagRepository: (0, awilix_1.asClass)(_repositories_1.ProductTagRepository).singleton(),
53
+ productCategoryRepository: (0, awilix_1.asClass)(_repositories_1.ProductCategoryRepository).singleton(),
54
+ productCollectionRepository: (0, awilix_1.asClass)(_repositories_1.ProductCollectionRepository).singleton(),
55
+ });
56
+ }
57
+ /**
58
+ * Load the repositories from the custom repositories object. If a repository is not
59
+ * present in the custom repositories object, the default repository will be used.
60
+ *
61
+ * @param customRepositories
62
+ * @param container
63
+ */
64
+ function loadCustomRepositories({ customRepositories, container }) {
65
+ const customRepositoriesMap = new Map(Object.entries(customRepositories));
66
+ Object.entries(DefaultRepositories).forEach(([key, DefaultRepository]) => {
67
+ let finalRepository = customRepositoriesMap.get(key);
68
+ if (!finalRepository ||
69
+ !finalRepository.prototype.find) {
70
+ finalRepository = DefaultRepository;
71
+ }
72
+ container.register({
73
+ [(0, utils_1.lowerCaseFirst)(key)]: (0, awilix_1.asClass)(finalRepository).singleton(),
74
+ });
75
+ });
76
+ }
@@ -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 Migration20230609132805 extends Migration {
3
+ up(): Promise<void>;
4
+ }
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Migration20230609132805 = void 0;
4
+ const migrations_1 = require("@mikro-orm/migrations");
5
+ class Migration20230609132805 extends migrations_1.Migration {
6
+ async up() {
7
+ this.addSql('create table "product_category" ("id" text not null, "name" text not null, "description" text not null default \'\', "handle" text not null, "mpath" text not null, "is_active" boolean not null default false, "is_internal" boolean not null default false, "rank" numeric not null default 0, "parent_category_id" text null, "created_at" timestamptz not null, "updated_at" timestamptz not null, constraint "product_category_pkey" primary key ("id"));');
8
+ this.addSql('create index "IDX_product_category_path" on "product_category" ("mpath");');
9
+ this.addSql('alter table "product_category" add constraint "IDX_product_category_handle" unique ("handle");');
10
+ this.addSql('create table "product_collection" ("id" text not null, "title" text not null, "handle" text not null, "metadata" jsonb null, "deleted_at" timestamptz null, constraint "product_collection_pkey" primary key ("id"));');
11
+ this.addSql('alter table "product_collection" add constraint "IDX_product_collection_handle_unique" unique ("handle");');
12
+ this.addSql('create table "product_tag" ("id" text not null, "value" text not null, "metadata" jsonb null, "deleted_at" timestamptz null, constraint "product_tag_pkey" primary key ("id"));');
13
+ this.addSql('create table "product_type" ("id" text not null, "value" text not null, "metadata" json null, "deleted_at" timestamptz null, constraint "product_type_pkey" primary key ("id"));');
14
+ this.addSql('create table "product" ("id" text not null, "title" text not null, "handle" text not null, "subtitle" text null, "description" text null, "is_giftcard" boolean not null default false, "status" text check ("status" in (\'draft\', \'proposed\', \'published\', \'rejected\')) not null, "thumbnail" text null, "weight" text null, "length" text null, "height" text null, "width" text null, "origin_country" text null, "hs_code" text null, "mid_code" text null, "material" text null, "collection_id" text null, "type_id" text null, "discountable" boolean not null default true, "external_id" text null, "created_at" timestamptz not null, "updated_at" timestamptz not null, "deleted_at" timestamptz null, "metadata" jsonb null, constraint "product_pkey" primary key ("id"));');
15
+ this.addSql('create index "IDX_product_type_id" on "product" ("type_id");');
16
+ this.addSql('alter table "product" add constraint "IDX_product_handle_unique" unique ("handle");');
17
+ this.addSql('create table "product_option" ("id" text not null, "title" text not null, "product_id" text not null, "metadata" jsonb null, "deleted_at" timestamptz null, constraint "product_option_pkey" primary key ("id"));');
18
+ this.addSql('create index "IDX_product_option_product_id" on "product_option" ("product_id");');
19
+ this.addSql('create table "product_tags" ("product_id" text not null, "product_tag_id" text not null, constraint "product_tags_pkey" primary key ("product_id", "product_tag_id"));');
20
+ this.addSql('create table "product_category_product" ("product_id" text not null, "product_category_id" text not null, constraint "product_category_product_pkey" primary key ("product_id", "product_category_id"));');
21
+ this.addSql('create table "product_variant" ("id" text not null, "title" text not null, "sku" text null, "barcode" text null, "ean" text null, "upc" text null, "inventory_quantity" numeric not null, "allow_backorder" boolean not null default false, "manage_inventory" boolean not null default true, "hs_code" text null, "origin_country" text null, "mid_code" text null, "material" text null, "weight" numeric null, "length" numeric null, "height" numeric null, "width" numeric null, "metadata" jsonb null, "variant_rank" numeric null, "created_at" timestamptz not null, "updated_at" timestamptz not null, "deleted_at" timestamptz null, "product_id" text not null, constraint "product_variant_pkey" primary key ("id"));');
22
+ this.addSql('create index "IDX_product_variant_product_id_index" on "product_variant" ("product_id");');
23
+ this.addSql('alter table "product_variant" add constraint "IDX_product_variant_sku_unique" unique ("sku");');
24
+ this.addSql('alter table "product_variant" add constraint "IDX_product_variant_barcode_unique" unique ("barcode");');
25
+ this.addSql('alter table "product_variant" add constraint "IDX_product_variant_ean_unique" unique ("ean");');
26
+ this.addSql('alter table "product_variant" add constraint "IDX_product_variant_upc_unique" unique ("upc");');
27
+ this.addSql('create table "product_option_value" ("id" text not null, "value" text not null, "option_id" text not null, "variant_id" text not null, "metadata" jsonb null, "deleted_at" timestamptz null, constraint "product_option_value_pkey" primary key ("id"));');
28
+ this.addSql('create index "IDX_product_option_value_product_option" on "product_option_value" ("option_id");');
29
+ this.addSql('alter table "product_category" add constraint "product_category_parent_category_id_foreign" foreign key ("parent_category_id") references "product_category" ("id") on update cascade on delete set null;');
30
+ this.addSql('alter table "product" add constraint "product_collection_id_foreign" foreign key ("collection_id") references "product_collection" ("id") on update cascade on delete set null;');
31
+ this.addSql('alter table "product" add constraint "product_type_id_foreign" foreign key ("type_id") references "product_type" ("id") on update cascade on delete set null;');
32
+ this.addSql('alter table "product_option" add constraint "product_option_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade;');
33
+ this.addSql('alter table "product_tags" add constraint "product_tags_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
34
+ this.addSql('alter table "product_tags" add constraint "product_tags_product_tag_id_foreign" foreign key ("product_tag_id") references "product_tag" ("id") on update cascade on delete cascade;');
35
+ this.addSql('alter table "product_category_product" add constraint "product_category_product_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
36
+ this.addSql('alter table "product_category_product" add constraint "product_category_product_product_category_id_foreign" foreign key ("product_category_id") references "product_category" ("id") on update cascade on delete cascade;');
37
+ this.addSql('alter table "product_variant" add constraint "product_variant_product_id_foreign" foreign key ("product_id") references "product" ("id") on update cascade on delete cascade;');
38
+ this.addSql('alter table "product_option_value" add constraint "product_option_value_option_id_foreign" foreign key ("option_id") references "product_option" ("id") on update cascade;');
39
+ this.addSql('alter table "product_option_value" add constraint "product_option_value_variant_id_foreign" foreign key ("variant_id") references "product_variant" ("id") on update cascade on delete cascade;');
40
+ }
41
+ }
42
+ exports.Migration20230609132805 = Migration20230609132805;
@@ -0,0 +1,6 @@
1
+ export { default as Product } from "./product";
2
+ export { default as ProductCategory } from "./product-category";
3
+ export { default as ProductCollection } from "./product-collection";
4
+ export { default as ProductTag } from "./product-tag";
5
+ export { default as ProductType } from "./product-type";
6
+ export { default as ProductVariant } from "./product-variant";
@@ -0,0 +1,18 @@
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.ProductVariant = exports.ProductType = exports.ProductTag = exports.ProductCollection = exports.ProductCategory = exports.Product = void 0;
7
+ var product_1 = require("./product");
8
+ Object.defineProperty(exports, "Product", { enumerable: true, get: function () { return __importDefault(product_1).default; } });
9
+ var product_category_1 = require("./product-category");
10
+ Object.defineProperty(exports, "ProductCategory", { enumerable: true, get: function () { return __importDefault(product_category_1).default; } });
11
+ var product_collection_1 = require("./product-collection");
12
+ Object.defineProperty(exports, "ProductCollection", { enumerable: true, get: function () { return __importDefault(product_collection_1).default; } });
13
+ var product_tag_1 = require("./product-tag");
14
+ Object.defineProperty(exports, "ProductTag", { enumerable: true, get: function () { return __importDefault(product_tag_1).default; } });
15
+ var product_type_1 = require("./product-type");
16
+ Object.defineProperty(exports, "ProductType", { enumerable: true, get: function () { return __importDefault(product_type_1).default; } });
17
+ var product_variant_1 = require("./product-variant");
18
+ Object.defineProperty(exports, "ProductVariant", { enumerable: true, get: function () { return __importDefault(product_variant_1).default; } });
@@ -0,0 +1,20 @@
1
+ import { Collection, EventArgs } from "@mikro-orm/core";
2
+ import Product from "./product";
3
+ declare class ProductCategory {
4
+ id: string;
5
+ name: string;
6
+ description?: string;
7
+ handle?: string;
8
+ mpath?: string;
9
+ is_active?: boolean;
10
+ is_internal?: boolean;
11
+ rank?: number;
12
+ parent_category_id?: string;
13
+ parent_category: ProductCategory;
14
+ category_children: Collection<ProductCategory, object>;
15
+ created_at: Date;
16
+ updated_at: Date;
17
+ products: Collection<Product, object>;
18
+ onCreate(args: EventArgs<ProductCategory>): Promise<void>;
19
+ }
20
+ export default ProductCategory;
@@ -0,0 +1,123 @@
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
+ var ProductCategory_1;
15
+ Object.defineProperty(exports, "__esModule", { value: true });
16
+ const utils_1 = require("@medusajs/utils");
17
+ const core_1 = require("@mikro-orm/core");
18
+ const product_1 = __importDefault(require("./product"));
19
+ let ProductCategory = ProductCategory_1 = class ProductCategory {
20
+ constructor() {
21
+ this.category_children = new core_1.Collection(this);
22
+ this.products = new core_1.Collection(this);
23
+ }
24
+ async onCreate(args) {
25
+ this.id = (0, utils_1.generateEntityId)(this.id, "pcat");
26
+ if (!this.handle) {
27
+ this.handle = (0, utils_1.kebabCase)(this.name);
28
+ }
29
+ const { em } = args;
30
+ const parentCategoryId = args.changeSet?.entity?.parent_category?.id;
31
+ let parentCategory = null;
32
+ if (parentCategoryId) {
33
+ parentCategory = await em.findOne(ProductCategory_1, parentCategoryId);
34
+ }
35
+ if (parentCategory) {
36
+ this.mpath = `${parentCategory?.mpath}${this.id}.`;
37
+ }
38
+ else {
39
+ this.mpath = `${this.id}.`;
40
+ }
41
+ }
42
+ };
43
+ __decorate([
44
+ (0, core_1.PrimaryKey)({ columnType: "text" }),
45
+ __metadata("design:type", String)
46
+ ], ProductCategory.prototype, "id", void 0);
47
+ __decorate([
48
+ (0, core_1.Property)({ columnType: "text", nullable: false }),
49
+ __metadata("design:type", String)
50
+ ], ProductCategory.prototype, "name", void 0);
51
+ __decorate([
52
+ (0, core_1.Property)({ columnType: "text", default: "", nullable: false }),
53
+ __metadata("design:type", String)
54
+ ], ProductCategory.prototype, "description", void 0);
55
+ __decorate([
56
+ (0, core_1.Unique)({
57
+ name: "IDX_product_category_handle",
58
+ properties: ["handle"],
59
+ }),
60
+ (0, core_1.Property)({ columnType: "text", nullable: false }),
61
+ __metadata("design:type", String)
62
+ ], ProductCategory.prototype, "handle", void 0);
63
+ __decorate([
64
+ (0, core_1.Index)({
65
+ name: "IDX_product_category_path",
66
+ properties: ["mpath"],
67
+ }),
68
+ (0, core_1.Property)({ columnType: "text", nullable: false }),
69
+ __metadata("design:type", String)
70
+ ], ProductCategory.prototype, "mpath", void 0);
71
+ __decorate([
72
+ (0, core_1.Property)({ columnType: "boolean", default: false }),
73
+ __metadata("design:type", Boolean)
74
+ ], ProductCategory.prototype, "is_active", void 0);
75
+ __decorate([
76
+ (0, core_1.Property)({ columnType: "boolean", default: false }),
77
+ __metadata("design:type", Boolean)
78
+ ], ProductCategory.prototype, "is_internal", void 0);
79
+ __decorate([
80
+ (0, core_1.Property)({ columnType: "numeric", nullable: false, default: 0 }),
81
+ __metadata("design:type", Number)
82
+ ], ProductCategory.prototype, "rank", void 0);
83
+ __decorate([
84
+ (0, core_1.Property)({ columnType: "text", nullable: true }),
85
+ __metadata("design:type", String)
86
+ ], ProductCategory.prototype, "parent_category_id", void 0);
87
+ __decorate([
88
+ (0, core_1.ManyToOne)(() => ProductCategory_1, { nullable: true }),
89
+ __metadata("design:type", ProductCategory)
90
+ ], ProductCategory.prototype, "parent_category", void 0);
91
+ __decorate([
92
+ (0, core_1.OneToMany)({
93
+ entity: () => ProductCategory_1,
94
+ mappedBy: (productCategory) => productCategory.parent_category,
95
+ }),
96
+ __metadata("design:type", Object)
97
+ ], ProductCategory.prototype, "category_children", void 0);
98
+ __decorate([
99
+ (0, core_1.Property)({ onCreate: () => new Date(), columnType: "timestamptz" }),
100
+ __metadata("design:type", Date)
101
+ ], ProductCategory.prototype, "created_at", void 0);
102
+ __decorate([
103
+ (0, core_1.Property)({
104
+ onCreate: () => new Date(),
105
+ onUpdate: () => new Date(),
106
+ columnType: "timestamptz",
107
+ }),
108
+ __metadata("design:type", Date)
109
+ ], ProductCategory.prototype, "updated_at", void 0);
110
+ __decorate([
111
+ (0, core_1.ManyToMany)(() => product_1.default, (product) => product.categories),
112
+ __metadata("design:type", Object)
113
+ ], ProductCategory.prototype, "products", void 0);
114
+ __decorate([
115
+ (0, core_1.BeforeCreate)(),
116
+ __metadata("design:type", Function),
117
+ __metadata("design:paramtypes", [Object]),
118
+ __metadata("design:returntype", Promise)
119
+ ], ProductCategory.prototype, "onCreate", null);
120
+ ProductCategory = ProductCategory_1 = __decorate([
121
+ (0, core_1.Entity)({ tableName: "product_category" })
122
+ ], ProductCategory);
123
+ exports.default = ProductCategory;
@@ -0,0 +1,9 @@
1
+ declare class ProductCollection {
2
+ id: string;
3
+ title: string;
4
+ handle: string;
5
+ metadata?: Record<string, unknown> | null;
6
+ deleted_at: Date;
7
+ onCreate(): void;
8
+ }
9
+ export default ProductCollection;
@@ -0,0 +1,55 @@
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
+ const utils_1 = require("@medusajs/utils");
14
+ let ProductCollection = class ProductCollection {
15
+ onCreate() {
16
+ this.id = (0, utils_1.generateEntityId)(this.id, "pcol");
17
+ if (!this.handle) {
18
+ this.handle = (0, utils_1.kebabCase)(this.title);
19
+ }
20
+ }
21
+ };
22
+ __decorate([
23
+ (0, core_1.PrimaryKey)({ columnType: "text" }),
24
+ __metadata("design:type", String)
25
+ ], ProductCollection.prototype, "id", void 0);
26
+ __decorate([
27
+ (0, core_1.Property)({ columnType: "text" }),
28
+ __metadata("design:type", String)
29
+ ], ProductCollection.prototype, "title", void 0);
30
+ __decorate([
31
+ (0, core_1.Property)({ columnType: "text" }),
32
+ (0, core_1.Unique)({
33
+ name: "IDX_product_collection_handle_unique",
34
+ properties: ["handle"],
35
+ }),
36
+ __metadata("design:type", String)
37
+ ], ProductCollection.prototype, "handle", void 0);
38
+ __decorate([
39
+ (0, core_1.Property)({ columnType: "jsonb", nullable: true }),
40
+ __metadata("design:type", Object)
41
+ ], ProductCollection.prototype, "metadata", void 0);
42
+ __decorate([
43
+ (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
44
+ __metadata("design:type", Date)
45
+ ], ProductCollection.prototype, "deleted_at", void 0);
46
+ __decorate([
47
+ (0, core_1.BeforeCreate)(),
48
+ __metadata("design:type", Function),
49
+ __metadata("design:paramtypes", []),
50
+ __metadata("design:returntype", void 0)
51
+ ], ProductCollection.prototype, "onCreate", null);
52
+ ProductCollection = __decorate([
53
+ (0, core_1.Entity)({ tableName: "product_collection" })
54
+ ], ProductCollection);
55
+ exports.default = ProductCollection;
@@ -0,0 +1,12 @@
1
+ import ProductOption from "./product-option";
2
+ import { ProductVariant } from "./index";
3
+ declare class ProductOptionValue {
4
+ id: string;
5
+ value: string;
6
+ option: ProductOption;
7
+ variant: ProductVariant;
8
+ metadata?: Record<string, unknown> | null;
9
+ deleted_at: Date;
10
+ beforeCreate(): void;
11
+ }
12
+ export default ProductOptionValue;
@@ -0,0 +1,59 @@
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 core_1 = require("@mikro-orm/core");
16
+ const utils_1 = require("@medusajs/utils");
17
+ const product_option_1 = __importDefault(require("./product-option"));
18
+ const index_1 = require("./index");
19
+ let ProductOptionValue = class ProductOptionValue {
20
+ beforeCreate() {
21
+ this.id = (0, utils_1.generateEntityId)(this.id, "optval");
22
+ }
23
+ };
24
+ __decorate([
25
+ (0, core_1.PrimaryKey)({ columnType: "text" }),
26
+ __metadata("design:type", String)
27
+ ], ProductOptionValue.prototype, "id", void 0);
28
+ __decorate([
29
+ (0, core_1.Property)({ columnType: "text" }),
30
+ __metadata("design:type", String)
31
+ ], ProductOptionValue.prototype, "value", void 0);
32
+ __decorate([
33
+ (0, core_1.ManyToOne)(() => product_option_1.default, {
34
+ index: "IDX_product_option_value_product_option",
35
+ }),
36
+ __metadata("design:type", product_option_1.default)
37
+ ], ProductOptionValue.prototype, "option", void 0);
38
+ __decorate([
39
+ (0, core_1.ManyToOne)(() => index_1.ProductVariant, { onDelete: "cascade" }),
40
+ __metadata("design:type", index_1.ProductVariant)
41
+ ], ProductOptionValue.prototype, "variant", void 0);
42
+ __decorate([
43
+ (0, core_1.Property)({ columnType: "jsonb", nullable: true }),
44
+ __metadata("design:type", Object)
45
+ ], ProductOptionValue.prototype, "metadata", void 0);
46
+ __decorate([
47
+ (0, core_1.Property)({ columnType: "timestamptz", nullable: true }),
48
+ __metadata("design:type", Date)
49
+ ], ProductOptionValue.prototype, "deleted_at", void 0);
50
+ __decorate([
51
+ (0, core_1.BeforeCreate)(),
52
+ __metadata("design:type", Function),
53
+ __metadata("design:paramtypes", []),
54
+ __metadata("design:returntype", void 0)
55
+ ], ProductOptionValue.prototype, "beforeCreate", null);
56
+ ProductOptionValue = __decorate([
57
+ (0, core_1.Entity)({ tableName: "product_option_value" })
58
+ ], ProductOptionValue);
59
+ exports.default = ProductOptionValue;
@@ -0,0 +1,14 @@
1
+ import { Collection } from "@mikro-orm/core";
2
+ import { Product } from "./index";
3
+ import ProductOptionValue from "./product-option-value";
4
+ declare class ProductOption {
5
+ id: string;
6
+ title: string;
7
+ product_id: number;
8
+ product: Product;
9
+ values: Collection<ProductOptionValue, object>;
10
+ metadata?: Record<string, unknown> | null;
11
+ deleted_at: Date;
12
+ beforeCreate(): void;
13
+ }
14
+ export default ProductOption;