@medusajs/product 0.4.0-snapshot-20240429113131 → 1.0.0-rc-20241003153304

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. package/README.md +2 -4
  2. package/dist/index.d.ts +6 -7
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +6 -24
  5. package/dist/index.js.map +1 -0
  6. package/dist/joiner-config.d.ts +2 -16
  7. package/dist/joiner-config.d.ts.map +1 -0
  8. package/dist/joiner-config.js +23 -77
  9. package/dist/joiner-config.js.map +1 -0
  10. package/dist/migrations/InitialSetup20240401153642.d.ts +2 -1
  11. package/dist/migrations/InitialSetup20240401153642.d.ts.map +1 -0
  12. package/dist/migrations/InitialSetup20240401153642.js +3 -2
  13. package/dist/migrations/InitialSetup20240401153642.js.map +1 -0
  14. package/dist/migrations/Migration20240601111544.d.ts +6 -0
  15. package/dist/migrations/Migration20240601111544.d.ts.map +1 -0
  16. package/dist/migrations/Migration20240601111544.js +16 -0
  17. package/dist/migrations/Migration20240601111544.js.map +1 -0
  18. package/dist/migrations/Migration202408271511.d.ts +6 -0
  19. package/dist/migrations/Migration202408271511.d.ts.map +1 -0
  20. package/dist/migrations/Migration202408271511.js +14 -0
  21. package/dist/migrations/Migration202408271511.js.map +1 -0
  22. package/dist/models/index.d.ts +1 -0
  23. package/dist/models/index.d.ts.map +1 -0
  24. package/dist/models/index.js +1 -0
  25. package/dist/models/index.js.map +1 -0
  26. package/dist/models/product-category.d.ts +3 -1
  27. package/dist/models/product-category.d.ts.map +1 -0
  28. package/dist/models/product-category.js +18 -18
  29. package/dist/models/product-category.js.map +1 -0
  30. package/dist/models/product-collection.d.ts +1 -0
  31. package/dist/models/product-collection.d.ts.map +1 -0
  32. package/dist/models/product-collection.js +2 -1
  33. package/dist/models/product-collection.js.map +1 -0
  34. package/dist/models/product-image.d.ts +1 -0
  35. package/dist/models/product-image.d.ts.map +1 -0
  36. package/dist/models/product-image.js +2 -1
  37. package/dist/models/product-image.js.map +1 -0
  38. package/dist/models/product-option-value.d.ts +1 -0
  39. package/dist/models/product-option-value.d.ts.map +1 -0
  40. package/dist/models/product-option-value.js +3 -2
  41. package/dist/models/product-option-value.js.map +1 -0
  42. package/dist/models/product-option.d.ts +1 -0
  43. package/dist/models/product-option.d.ts.map +1 -0
  44. package/dist/models/product-option.js +3 -2
  45. package/dist/models/product-option.js.map +1 -0
  46. package/dist/models/product-tag.d.ts +1 -0
  47. package/dist/models/product-tag.d.ts.map +1 -0
  48. package/dist/models/product-tag.js +2 -1
  49. package/dist/models/product-tag.js.map +1 -0
  50. package/dist/models/product-type.d.ts +1 -0
  51. package/dist/models/product-type.d.ts.map +1 -0
  52. package/dist/models/product-type.js +2 -1
  53. package/dist/models/product-type.js.map +1 -0
  54. package/dist/models/product-variant.d.ts +1 -1
  55. package/dist/models/product-variant.d.ts.map +1 -0
  56. package/dist/models/product-variant.js +4 -17
  57. package/dist/models/product-variant.js.map +1 -0
  58. package/dist/models/product.d.ts +2 -1
  59. package/dist/models/product.d.ts.map +1 -0
  60. package/dist/models/product.js +5 -4
  61. package/dist/models/product.js.map +1 -0
  62. package/dist/repositories/index.d.ts +1 -1
  63. package/dist/repositories/index.d.ts.map +1 -0
  64. package/dist/repositories/index.js +2 -3
  65. package/dist/repositories/index.js.map +1 -0
  66. package/dist/repositories/product-category.d.ts +602 -20
  67. package/dist/repositories/product-category.d.ts.map +1 -0
  68. package/dist/repositories/product-category.js +273 -210
  69. package/dist/repositories/product-category.js.map +1 -0
  70. package/dist/repositories/product.d.ts +3 -2
  71. package/dist/repositories/product.d.ts.map +1 -0
  72. package/dist/repositories/product.js +2 -1
  73. package/dist/repositories/product.js.map +1 -0
  74. package/dist/schema/index.d.ts +3 -0
  75. package/dist/schema/index.d.ts.map +1 -0
  76. package/dist/schema/index.js +151 -0
  77. package/dist/schema/index.js.map +1 -0
  78. package/dist/services/index.d.ts +1 -1
  79. package/dist/services/index.d.ts.map +1 -0
  80. package/dist/services/index.js +2 -3
  81. package/dist/services/index.js.map +1 -0
  82. package/dist/services/product-category.d.ts +12 -8
  83. package/dist/services/product-category.d.ts.map +1 -0
  84. package/dist/services/product-category.js +38 -14
  85. package/dist/services/product-category.js.map +1 -0
  86. package/dist/services/product-module-service.d.ts +85 -79
  87. package/dist/services/product-module-service.d.ts.map +1 -0
  88. package/dist/services/product-module-service.js +364 -200
  89. package/dist/services/product-module-service.js.map +1 -0
  90. package/dist/tsconfig.tsbuildinfo +1 -0
  91. package/dist/types/index.d.ts +9 -2
  92. package/dist/types/index.d.ts.map +1 -0
  93. package/dist/types/index.js +1 -0
  94. package/dist/types/index.js.map +1 -0
  95. package/dist/utils/events.d.ts +147 -0
  96. package/dist/utils/events.d.ts.map +1 -0
  97. package/dist/utils/events.js +115 -0
  98. package/dist/utils/events.js.map +1 -0
  99. package/dist/utils/index.d.ts +2 -2
  100. package/dist/utils/index.d.ts.map +1 -0
  101. package/dist/utils/index.js +16 -9
  102. package/dist/utils/index.js.map +1 -0
  103. package/package.json +26 -29
  104. package/dist/initialize/index.d.ts +0 -4
  105. package/dist/initialize/index.js +0 -17
  106. package/dist/loaders/connection.d.ts +0 -4
  107. package/dist/loaders/connection.js +0 -40
  108. package/dist/loaders/container.d.ts +0 -2
  109. package/dist/loaders/container.js +0 -34
  110. package/dist/loaders/index.d.ts +0 -2
  111. package/dist/loaders/index.js +0 -18
  112. package/dist/module-definition.d.ts +0 -4
  113. package/dist/module-definition.js +0 -50
  114. package/dist/scripts/bin/run-seed.d.ts +0 -3
  115. package/dist/scripts/bin/run-seed.js +0 -52
  116. package/dist/scripts/seed-utils.d.ts +0 -5
  117. package/dist/scripts/seed-utils.js +0 -40
  118. package/dist/services/product.d.ts +0 -21
  119. package/dist/services/product.js +0 -63
@@ -1,2 +0,0 @@
1
- export * from "./connection";
2
- export * from "./container";
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./connection"), exports);
18
- __exportStar(require("./container"), exports);
@@ -1,4 +0,0 @@
1
- import { ModuleExports } from "@medusajs/types";
2
- export declare const runMigrations: ({ options, logger, }?: Pick<import("@medusajs/types").LoaderOptions<import("@medusajs/types").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
3
- export declare const revertMigration: ({ options, logger, }?: Pick<import("@medusajs/types").LoaderOptions<import("@medusajs/types").ModuleServiceInitializeOptions>, "options" | "logger"> | undefined) => Promise<void>;
4
- export declare const moduleDefinition: ModuleExports;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.moduleDefinition = exports.revertMigration = exports.runMigrations = void 0;
30
- const _services_1 = require("./services");
31
- const connection_1 = __importDefault(require("./loaders/connection"));
32
- const container_1 = __importDefault(require("./loaders/container"));
33
- const modules_sdk_1 = require("@medusajs/modules-sdk");
34
- const utils_1 = require("@medusajs/utils");
35
- const ProductModels = __importStar(require("./models"));
36
- const migrationScriptOptions = {
37
- moduleName: modules_sdk_1.Modules.PRODUCT,
38
- models: ProductModels,
39
- pathToMigrations: __dirname + "/migrations",
40
- };
41
- exports.runMigrations = utils_1.ModulesSdkUtils.buildMigrationScript(migrationScriptOptions);
42
- exports.revertMigration = utils_1.ModulesSdkUtils.buildRevertMigrationScript(migrationScriptOptions);
43
- const service = _services_1.ProductModuleService;
44
- const loaders = [container_1.default, connection_1.default];
45
- exports.moduleDefinition = {
46
- service,
47
- loaders,
48
- runMigrations: exports.runMigrations,
49
- revertMigration: exports.revertMigration,
50
- };
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- declare const _default: Promise<void>;
3
- export default _default;
@@ -1,52 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
- if (k2 === undefined) k2 = k;
5
- var desc = Object.getOwnPropertyDescriptor(m, k);
6
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
- desc = { enumerable: true, get: function() { return m[k]; } };
8
- }
9
- Object.defineProperty(o, k2, desc);
10
- }) : (function(o, m, k, k2) {
11
- if (k2 === undefined) k2 = k;
12
- o[k2] = m[k];
13
- }));
14
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
- Object.defineProperty(o, "default", { enumerable: true, value: v });
16
- }) : function(o, v) {
17
- o["default"] = v;
18
- });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- const utils_1 = require("@medusajs/utils");
28
- const modules_sdk_1 = require("@medusajs/modules-sdk");
29
- const ProductModels = __importStar(require("../../models"));
30
- const seed_utils_1 = require("../seed-utils");
31
- const os_1 = require("os");
32
- const args = process.argv;
33
- const path = args.pop();
34
- exports.default = (async () => {
35
- const { config } = await Promise.resolve().then(() => __importStar(require("dotenv")));
36
- config();
37
- if (!path) {
38
- throw new Error(`filePath is required.${os_1.EOL}Example: medusa-product-seed <filePath>`);
39
- }
40
- const run = utils_1.ModulesSdkUtils.buildSeedScript({
41
- moduleName: modules_sdk_1.Modules.PRODUCT,
42
- models: ProductModels,
43
- pathToMigrations: __dirname + "/../../migrations",
44
- seedHandler: async ({ manager, data }) => {
45
- const { productCategoriesData, productsData, variantsData } = data;
46
- await (0, seed_utils_1.createProductCategories)(manager, productCategoriesData);
47
- await (0, seed_utils_1.createProducts)(manager, productsData);
48
- await (0, seed_utils_1.createProductVariants)(manager, variantsData);
49
- },
50
- });
51
- await run({ path });
52
- })();
@@ -1,5 +0,0 @@
1
- import { SqlEntityManager } from "@mikro-orm/postgresql";
2
- import { ProductCategory } from "../models";
3
- export declare function createProductCategories(manager: SqlEntityManager, categoriesData: any[]): Promise<ProductCategory[]>;
4
- export declare function createProducts(manager: SqlEntityManager, data: any[]): Promise<any[]>;
5
- export declare function createProductVariants(manager: SqlEntityManager, data: any[]): Promise<any[]>;
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createProductVariants = exports.createProducts = exports.createProductCategories = void 0;
4
- const _models_1 = require("../models");
5
- async function createProductCategories(manager, categoriesData) {
6
- const categories = [];
7
- for (let categoryData of categoriesData) {
8
- let categoryDataClone = { ...categoryData };
9
- let parentCategory = null;
10
- const parentCategoryId = categoryDataClone.parent_category_id;
11
- delete categoryDataClone.parent_category_id;
12
- if (parentCategoryId) {
13
- parentCategory = await manager.findOne(_models_1.ProductCategory, parentCategoryId);
14
- }
15
- const category = manager.create(_models_1.ProductCategory, {
16
- ...categoryDataClone,
17
- parent_category: parentCategory,
18
- });
19
- categories.push(category);
20
- }
21
- await manager.persistAndFlush(categories);
22
- return categories;
23
- }
24
- exports.createProductCategories = createProductCategories;
25
- async function createProducts(manager, data) {
26
- const products = data.map((productData) => {
27
- return manager.create(_models_1.Product, productData);
28
- });
29
- await manager.persistAndFlush(products);
30
- return products;
31
- }
32
- exports.createProducts = createProducts;
33
- async function createProductVariants(manager, data) {
34
- const variants = data.map((variantsData) => {
35
- return manager.create(_models_1.ProductVariant, variantsData);
36
- });
37
- await manager.persistAndFlush(variants);
38
- return variants;
39
- }
40
- exports.createProductVariants = createProductVariants;
@@ -1,21 +0,0 @@
1
- import { Context, DAL, FindConfig, ProductTypes, FilterableProductProps } from "@medusajs/types";
2
- import { Product } from "../models";
3
- type InjectedDependencies = {
4
- productRepository: DAL.RepositoryService;
5
- };
6
- type NormalizedFilterableProductProps = ProductTypes.FilterableProductProps & {
7
- categories?: {
8
- id: string | {
9
- $in: string[];
10
- };
11
- };
12
- };
13
- declare const ProductService_base: new <TEntity_1 extends object = any>(container: InjectedDependencies) => import("@medusajs/types").InternalModuleService<TEntity_1, InjectedDependencies>;
14
- export default class ProductService<TEntity extends Product = Product> extends ProductService_base<TEntity> {
15
- protected readonly productRepository_: DAL.RepositoryService<TEntity>;
16
- constructor({ productRepository }: InjectedDependencies);
17
- list(filters?: ProductTypes.FilterableProductProps, config?: FindConfig<TEntity>, sharedContext?: Context): Promise<TEntity[]>;
18
- listAndCount(filters?: ProductTypes.FilterableProductProps, config?: FindConfig<any>, sharedContext?: Context): Promise<[TEntity[], number]>;
19
- protected static normalizeFilters(filters?: FilterableProductProps): NormalizedFilterableProductProps;
20
- }
21
- export {};
@@ -1,63 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- var __param = (this && this.__param) || function (paramIndex, decorator) {
12
- return function (target, key) { decorator(target, key, paramIndex); }
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- const types_1 = require("@medusajs/types");
16
- const utils_1 = require("@medusajs/utils");
17
- const _models_1 = require("../models");
18
- class ProductService extends utils_1.ModulesSdkUtils.internalModuleServiceFactory(_models_1.Product) {
19
- constructor({ productRepository }) {
20
- // @ts-ignore
21
- // eslint-disable-next-line prefer-rest-params
22
- super(...arguments);
23
- this.productRepository_ = productRepository;
24
- }
25
- async list(filters = {}, config = {}, sharedContext = {}) {
26
- return await super.list(ProductService.normalizeFilters(filters), config, sharedContext);
27
- }
28
- async listAndCount(filters = {}, config = {}, sharedContext = {}) {
29
- return await super.listAndCount(ProductService.normalizeFilters(filters), config, sharedContext);
30
- }
31
- static normalizeFilters(filters = {}) {
32
- const normalized = filters;
33
- if (normalized.category_id) {
34
- if (Array.isArray(normalized.category_id)) {
35
- normalized.categories = {
36
- id: { $in: normalized.category_id },
37
- };
38
- }
39
- else {
40
- normalized.categories = {
41
- id: normalized.category_id,
42
- };
43
- }
44
- delete normalized.category_id;
45
- }
46
- return normalized;
47
- }
48
- }
49
- exports.default = ProductService;
50
- __decorate([
51
- (0, utils_1.InjectManager)("productRepository_"),
52
- __param(2, (0, utils_1.MedusaContext)()),
53
- __metadata("design:type", Function),
54
- __metadata("design:paramtypes", [Object, Object, Object]),
55
- __metadata("design:returntype", Promise)
56
- ], ProductService.prototype, "list", null);
57
- __decorate([
58
- (0, utils_1.InjectManager)("productRepository_"),
59
- __param(2, (0, utils_1.MedusaContext)()),
60
- __metadata("design:type", Function),
61
- __metadata("design:paramtypes", [Object, Object, Object]),
62
- __metadata("design:returntype", Promise)
63
- ], ProductService.prototype, "listAndCount", null);