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

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 +21 -24
  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
@@ -12,21 +12,23 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
12
  return function (target, key) { decorator(target, key, paramIndex); }
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const types_1 = require("@medusajs/types");
15
+ const types_1 = require("@medusajs/framework/types");
16
16
  const _models_1 = require("../models");
17
- const utils_1 = require("@medusajs/utils");
17
+ const utils_1 = require("@medusajs/framework/utils");
18
18
  const types_2 = require("../types");
19
+ const utils_2 = require("../utils");
19
20
  const joiner_config_1 = require("./../joiner-config");
20
- const generateMethodForModels = [
21
- { model: _models_1.ProductCategory, singular: "Category", plural: "Categories" },
22
- { model: _models_1.ProductCollection, singular: "Collection", plural: "Collections" },
23
- { model: _models_1.ProductOption, singular: "Option", plural: "Options" },
24
- { model: _models_1.ProductTag, singular: "Tag", plural: "Tags" },
25
- { model: _models_1.ProductType, singular: "Type", plural: "Types" },
26
- { model: _models_1.ProductVariant, singular: "Variant", plural: "Variants" },
27
- ];
28
- class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleServiceFactory(_models_1.Product, generateMethodForModels, joiner_config_1.entityNameToLinkableKeysMap) {
29
- constructor({ baseRepository, productService, productVariantService, productTagService, productCategoryService, productCollectionService, productImageService, productTypeService, productOptionService, productOptionValueService, eventBusModuleService, }, moduleDeclaration) {
21
+ class ProductModuleService extends (0, utils_1.MedusaService)({
22
+ Product: _models_1.Product,
23
+ ProductCategory: _models_1.ProductCategory,
24
+ ProductCollection: _models_1.ProductCollection,
25
+ ProductOption: _models_1.ProductOption,
26
+ ProductOptionValue: _models_1.ProductOptionValue,
27
+ ProductTag: _models_1.ProductTag,
28
+ ProductType: _models_1.ProductType,
29
+ ProductVariant: _models_1.ProductVariant,
30
+ }) {
31
+ constructor({ baseRepository, productService, productVariantService, productTagService, productCategoryService, productCollectionService, productImageService, productTypeService, productOptionService, productOptionValueService, [utils_1.Modules.EVENT_BUS]: eventBusModuleService, }, moduleDeclaration) {
30
32
  // @ts-ignore
31
33
  // eslint-disable-next-line prefer-rest-params
32
34
  super(...arguments);
@@ -46,7 +48,7 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
46
48
  __joinerConfig() {
47
49
  return joiner_config_1.joinerConfig;
48
50
  }
49
- async createVariants(data, sharedContext = {}) {
51
+ async createProductVariants(data, sharedContext = {}) {
50
52
  const input = Array.isArray(data) ? data : [data];
51
53
  const variants = await this.createVariants_(input, sharedContext);
52
54
  const createdVariants = await this.baseRepository_.serialize(variants);
@@ -54,18 +56,22 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
54
56
  }
55
57
  async createVariants_(data, sharedContext = {}) {
56
58
  if (data.some((v) => !v.product_id)) {
57
- throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Tried to create variants without specifying a product_id");
59
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Unable to create variants without specifying a product_id");
58
60
  }
59
61
  const productOptions = await this.productOptionService_.list({
60
62
  product_id: [...new Set(data.map((v) => v.product_id))],
61
63
  }, {
62
- take: null,
63
64
  relations: ["values"],
64
65
  }, sharedContext);
65
66
  const productVariantsWithOptions = ProductModuleService.assignOptionsToVariants(data, productOptions);
66
- return await this.productVariantService_.create(productVariantsWithOptions, sharedContext);
67
+ const createdVariants = await this.productVariantService_.create(productVariantsWithOptions, sharedContext);
68
+ utils_2.eventBuilders.createdProductVariant({
69
+ data: createdVariants,
70
+ sharedContext,
71
+ });
72
+ return createdVariants;
67
73
  }
68
- async upsertVariants(data, sharedContext = {}) {
74
+ async upsertProductVariants(data, sharedContext = {}) {
69
75
  const input = Array.isArray(data) ? data : [data];
70
76
  const forUpdate = input.filter((variant) => !!variant.id);
71
77
  const forCreate = input.filter((variant) => !variant.id);
@@ -81,7 +87,7 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
81
87
  const allVariants = await this.baseRepository_.serialize(result);
82
88
  return Array.isArray(data) ? allVariants : allVariants[0];
83
89
  }
84
- async updateVariants(idOrSelector, data, sharedContext = {}) {
90
+ async updateProductVariants(idOrSelector, data, sharedContext = {}) {
85
91
  let normalizedInput = [];
86
92
  if ((0, utils_1.isString)(idOrSelector)) {
87
93
  normalizedInput = [{ id: idOrSelector, ...data }];
@@ -100,7 +106,7 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
100
106
  async updateVariants_(data, sharedContext = {}) {
101
107
  // Validation step
102
108
  const variantIdsToUpdate = data.map(({ id }) => id);
103
- const variants = await this.productVariantService_.list({ id: variantIdsToUpdate }, { take: null }, sharedContext);
109
+ const variants = await this.productVariantService_.list({ id: variantIdsToUpdate }, {}, sharedContext);
104
110
  if (variants.length !== data.length) {
105
111
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Cannot update non-existing variants with ids: ${(0, utils_1.arrayDifference)(variantIdsToUpdate, variants.map(({ id }) => id)).join(", ")}`);
106
112
  }
@@ -112,26 +118,87 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
112
118
  }));
113
119
  const productOptions = await this.productOptionService_.list({
114
120
  product_id: Array.from(new Set(variantsWithProductId.map((v) => v.product_id))),
115
- }, { take: null, relations: ["values"] }, sharedContext);
116
- return this.productVariantService_.upsertWithReplace(ProductModuleService.assignOptionsToVariants(variantsWithProductId, productOptions), {
121
+ }, { relations: ["values"] }, sharedContext);
122
+ const { entities: productVariants, performedActions } = await this.productVariantService_.upsertWithReplace(ProductModuleService.assignOptionsToVariants(variantsWithProductId, productOptions), {
117
123
  relations: ["options"],
118
124
  }, sharedContext);
125
+ utils_2.eventBuilders.createdProductVariant({
126
+ data: performedActions.created[_models_1.ProductVariant.name] ?? [],
127
+ sharedContext,
128
+ });
129
+ utils_2.eventBuilders.updatedProductVariant({
130
+ data: performedActions.updated[_models_1.ProductVariant.name] ?? [],
131
+ sharedContext,
132
+ });
133
+ utils_2.eventBuilders.deletedProductVariant({
134
+ data: performedActions.deleted[_models_1.ProductVariant.name] ?? [],
135
+ sharedContext,
136
+ });
137
+ return productVariants;
119
138
  }
120
- async createTags(data, sharedContext = {}) {
121
- const productTags = await this.productTagService_.create(data, sharedContext);
122
- return await this.baseRepository_.serialize(productTags);
139
+ async createProductTags(data, sharedContext = {}) {
140
+ const input = Array.isArray(data) ? data : [data];
141
+ const tags = await this.productTagService_.create(input, sharedContext);
142
+ const createdTags = await this.baseRepository_.serialize(tags);
143
+ utils_2.eventBuilders.createdProductTag({
144
+ data: createdTags,
145
+ sharedContext,
146
+ });
147
+ return Array.isArray(data) ? createdTags : createdTags[0];
123
148
  }
124
- async updateTags(data, sharedContext = {}) {
125
- const productTags = await this.productTagService_.update(data, sharedContext);
126
- return await this.baseRepository_.serialize(productTags);
149
+ async upsertProductTags(data, sharedContext = {}) {
150
+ const input = Array.isArray(data) ? data : [data];
151
+ const forUpdate = input.filter((tag) => !!tag.id);
152
+ const forCreate = input.filter((tag) => !tag.id);
153
+ let created = [];
154
+ let updated = [];
155
+ if (forCreate.length) {
156
+ created = await this.productTagService_.create(forCreate, sharedContext);
157
+ utils_2.eventBuilders.createdProductTag({
158
+ data: created,
159
+ sharedContext,
160
+ });
161
+ }
162
+ if (forUpdate.length) {
163
+ updated = await this.productTagService_.update(forUpdate, sharedContext);
164
+ utils_2.eventBuilders.updatedProductTag({
165
+ data: updated,
166
+ sharedContext,
167
+ });
168
+ }
169
+ const result = [...created, ...updated];
170
+ const allTags = await this.baseRepository_.serialize(result);
171
+ return Array.isArray(data) ? allTags : allTags[0];
127
172
  }
128
- async createTypes(data, sharedContext = {}) {
173
+ async updateProductTags(idOrSelector, data, sharedContext = {}) {
174
+ let normalizedInput = [];
175
+ if ((0, utils_1.isString)(idOrSelector)) {
176
+ // Check if the tag exists in the first place
177
+ await this.productTagService_.retrieve(idOrSelector, {}, sharedContext);
178
+ normalizedInput = [{ id: idOrSelector, ...data }];
179
+ }
180
+ else {
181
+ const tags = await this.productTagService_.list(idOrSelector, {}, sharedContext);
182
+ normalizedInput = tags.map((tag) => ({
183
+ id: tag.id,
184
+ ...data,
185
+ }));
186
+ }
187
+ const tags = await this.productTagService_.update(normalizedInput, sharedContext);
188
+ const updatedTags = await this.baseRepository_.serialize(tags);
189
+ utils_2.eventBuilders.updatedProductTag({
190
+ data: updatedTags,
191
+ sharedContext,
192
+ });
193
+ return (0, utils_1.isString)(idOrSelector) ? updatedTags[0] : updatedTags;
194
+ }
195
+ async createProductTypes(data, sharedContext = {}) {
129
196
  const input = Array.isArray(data) ? data : [data];
130
197
  const types = await this.productTypeService_.create(input, sharedContext);
131
198
  const createdTypes = await this.baseRepository_.serialize(types);
132
199
  return Array.isArray(data) ? createdTypes : createdTypes[0];
133
200
  }
134
- async upsertTypes(data, sharedContext = {}) {
201
+ async upsertProductTypes(data, sharedContext = {}) {
135
202
  const input = Array.isArray(data) ? data : [data];
136
203
  const forUpdate = input.filter((type) => !!type.id);
137
204
  const forCreate = input.filter((type) => !type.id);
@@ -147,7 +214,7 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
147
214
  const allTypes = await this.baseRepository_.serialize(result);
148
215
  return Array.isArray(data) ? allTypes : allTypes[0];
149
216
  }
150
- async updateTypes(idOrSelector, data, sharedContext = {}) {
217
+ async updateProductTypes(idOrSelector, data, sharedContext = {}) {
151
218
  let normalizedInput = [];
152
219
  if ((0, utils_1.isString)(idOrSelector)) {
153
220
  // Check if the type exists in the first place
@@ -165,7 +232,7 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
165
232
  const updatedTypes = await this.baseRepository_.serialize(types);
166
233
  return (0, utils_1.isString)(idOrSelector) ? updatedTypes[0] : updatedTypes;
167
234
  }
168
- async createOptions(data, sharedContext = {}) {
235
+ async createProductOptions(data, sharedContext = {}) {
169
236
  const input = Array.isArray(data) ? data : [data];
170
237
  const options = await this.createOptions_(input, sharedContext);
171
238
  const createdOptions = await this.baseRepository_.serialize(options);
@@ -185,7 +252,7 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
185
252
  });
186
253
  return await this.productOptionService_.create(normalizedInput, sharedContext);
187
254
  }
188
- async upsertOptions(data, sharedContext = {}) {
255
+ async upsertProductOptions(data, sharedContext = {}) {
189
256
  const input = Array.isArray(data) ? data : [data];
190
257
  const forUpdate = input.filter((option) => !!option.id);
191
258
  const forCreate = input.filter((option) => !option.id);
@@ -201,7 +268,7 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
201
268
  const allOptions = await this.baseRepository_.serialize(result);
202
269
  return Array.isArray(data) ? allOptions : allOptions[0];
203
270
  }
204
- async updateOptions(idOrSelector, data, sharedContext = {}) {
271
+ async updateProductOptions(idOrSelector, data, sharedContext = {}) {
205
272
  let normalizedInput = [];
206
273
  if ((0, utils_1.isString)(idOrSelector)) {
207
274
  await this.productOptionService_.retrieve(idOrSelector, {}, sharedContext);
@@ -223,7 +290,7 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
223
290
  if (data.some((option) => !option.id)) {
224
291
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, "Tried to update options without specifying an ID");
225
292
  }
226
- const dbOptions = await this.productOptionService_.list({ id: data.map(({ id }) => id) }, { take: null, relations: ["values"] }, sharedContext);
293
+ const dbOptions = await this.productOptionService_.list({ id: data.map(({ id }) => id) }, { relations: ["values"] }, sharedContext);
227
294
  if (dbOptions.length !== data.length) {
228
295
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Cannot update non-existing options with ids: ${(0, utils_1.arrayDifference)(data.map(({ id }) => id), dbOptions.map(({ id }) => id)).join(", ")}`);
229
296
  }
@@ -255,25 +322,29 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
255
322
  : {}),
256
323
  };
257
324
  });
258
- return await this.productOptionService_.upsertWithReplace(normalizedInput, { relations: ["values"] }, sharedContext);
325
+ const { entities: productOptions } = await this.productOptionService_.upsertWithReplace(normalizedInput, { relations: ["values"] }, sharedContext);
326
+ return productOptions;
259
327
  }
260
- async createCollections(data, sharedContext = {}) {
328
+ async createProductCollections(data, sharedContext = {}) {
261
329
  const input = Array.isArray(data) ? data : [data];
262
330
  const collections = await this.createCollections_(input, sharedContext);
263
331
  const createdCollections = await this.baseRepository_.serialize(collections);
264
332
  await this.eventBusModuleService_?.emit(collections.map(({ id }) => ({
265
- eventName: types_2.ProductCollectionEvents.COLLECTION_CREATED,
333
+ name: types_2.ProductCollectionEvents.COLLECTION_CREATED,
266
334
  data: { id },
267
- })));
335
+ })), {
336
+ internal: true,
337
+ });
268
338
  return Array.isArray(data) ? createdCollections : createdCollections[0];
269
339
  }
270
340
  async createCollections_(data, sharedContext = {}) {
271
341
  const normalizedInput = data.map(ProductModuleService.normalizeCreateProductCollectionInput);
272
342
  // It's safe to use upsertWithReplace here since we only have product IDs and the only operation to do is update the product
273
343
  // with the collection ID
274
- return await this.productCollectionService_.upsertWithReplace(normalizedInput, { relations: ["products"] }, sharedContext);
344
+ const { entities: productCollections } = await this.productCollectionService_.upsertWithReplace(normalizedInput, { relations: ["products"] }, sharedContext);
345
+ return productCollections;
275
346
  }
276
- async upsertCollections(data, sharedContext = {}) {
347
+ async upsertProductCollections(data, sharedContext = {}) {
277
348
  const input = Array.isArray(data) ? data : [data];
278
349
  const forUpdate = input.filter((collection) => !!collection.id);
279
350
  const forCreate = input.filter((collection) => !collection.id);
@@ -289,19 +360,23 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
289
360
  const allCollections = await this.baseRepository_.serialize(result);
290
361
  if (created.length) {
291
362
  await this.eventBusModuleService_?.emit(created.map(({ id }) => ({
292
- eventName: types_2.ProductCollectionEvents.COLLECTION_CREATED,
363
+ name: types_2.ProductCollectionEvents.COLLECTION_CREATED,
293
364
  data: { id },
294
- })));
365
+ })), {
366
+ internal: true,
367
+ });
295
368
  }
296
369
  if (updated.length) {
297
370
  await this.eventBusModuleService_?.emit(updated.map(({ id }) => ({
298
- eventName: types_2.ProductCollectionEvents.COLLECTION_UPDATED,
371
+ name: types_2.ProductCollectionEvents.COLLECTION_UPDATED,
299
372
  data: { id },
300
- })));
373
+ })), {
374
+ internal: true,
375
+ });
301
376
  }
302
377
  return Array.isArray(data) ? allCollections : allCollections[0];
303
378
  }
304
- async updateCollections(idOrSelector, data, sharedContext = {}) {
379
+ async updateProductCollections(idOrSelector, data, sharedContext = {}) {
305
380
  let normalizedInput = [];
306
381
  if ((0, utils_1.isString)(idOrSelector)) {
307
382
  await this.productCollectionService_.retrieve(idOrSelector, {}, sharedContext);
@@ -317,9 +392,11 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
317
392
  const collections = await this.updateCollections_(normalizedInput, sharedContext);
318
393
  const updatedCollections = await this.baseRepository_.serialize(collections);
319
394
  await this.eventBusModuleService_?.emit(updatedCollections.map(({ id }) => ({
320
- eventName: types_2.ProductCollectionEvents.COLLECTION_UPDATED,
395
+ name: types_2.ProductCollectionEvents.COLLECTION_UPDATED,
321
396
  data: { id },
322
- })));
397
+ })), {
398
+ internal: true,
399
+ });
323
400
  return (0, utils_1.isString)(idOrSelector) ? updatedCollections[0] : updatedCollections;
324
401
  }
325
402
  async updateCollections_(data, sharedContext = {}) {
@@ -327,85 +404,146 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
327
404
  // TODO: Maybe we can update upsertWithReplace to not remove oneToMany entities, but just disassociate them? With that we can remove the code below.
328
405
  // Another alternative is to not allow passing product_ids to a collection, and instead set the collection_id through the product update call.
329
406
  const updatedCollections = await this.productCollectionService_.update(normalizedInput.map((c) => (0, utils_1.removeUndefined)({ ...c, products: undefined })), sharedContext);
330
- const collectionWithProducts = await (0, utils_1.promiseAll)(updatedCollections.map(async (collection, i) => {
331
- const input = normalizedInput.find((c) => c.id === collection.id);
407
+ const collections = [];
408
+ const updateSelectorAndData = updatedCollections.flatMap((collectionData) => {
409
+ const input = normalizedInput.find((c) => c.id === collectionData.id);
332
410
  const productsToUpdate = input?.products;
333
- if (!productsToUpdate) {
334
- return { ...collection, products: [] };
411
+ const dissociateSelector = {
412
+ collection_id: collectionData.id,
413
+ };
414
+ const associateSelector = {};
415
+ if (!!productsToUpdate?.length) {
416
+ const productIds = productsToUpdate.map((p) => p.id);
417
+ dissociateSelector["id"] = { $nin: productIds };
418
+ associateSelector["id"] = { $in: productIds };
335
419
  }
336
- await this.productService_.update({
337
- selector: { collection_id: collection.id },
338
- data: { collection_id: null },
339
- }, sharedContext);
340
- if (productsToUpdate.length > 0) {
341
- await this.productService_.update(productsToUpdate.map((p) => ({
342
- id: p.id,
343
- collection_id: collection.id,
344
- })), sharedContext);
420
+ const result = [
421
+ {
422
+ selector: dissociateSelector,
423
+ data: {
424
+ collection_id: null,
425
+ },
426
+ },
427
+ ];
428
+ if ((0, utils_1.isPresent)(associateSelector)) {
429
+ result.push({
430
+ selector: associateSelector,
431
+ data: {
432
+ collection_id: collectionData.id,
433
+ },
434
+ });
345
435
  }
346
- return { ...collection, products: productsToUpdate };
347
- }));
348
- return collectionWithProducts;
349
- }
350
- async createCategory(data, sharedContext = {}) {
351
- const result = await this.createCategory_(data, sharedContext);
352
- return await this.baseRepository_.serialize(result);
353
- }
354
- async createCategory_(data, sharedContext = {}) {
355
- const productCategory = await this.productCategoryService_.create(data, sharedContext);
356
- await this.eventBusModuleService_?.emit(types_2.ProductCategoryEvents.CATEGORY_CREATED, { id: productCategory.id });
357
- return productCategory;
358
- }
359
- async updateCategory(categoryId, data, sharedContext = {}) {
360
- const productCategory = await this.productCategoryService_.update(categoryId, data, sharedContext);
361
- await this.eventBusModuleService_?.emit(types_2.ProductCategoryEvents.CATEGORY_UPDATED, { id: productCategory.id });
362
- return await this.baseRepository_.serialize(productCategory, {
363
- populate: true,
436
+ collections.push({
437
+ ...collectionData,
438
+ products: productsToUpdate ?? [],
439
+ });
440
+ return result;
441
+ });
442
+ await this.productService_.update(updateSelectorAndData, sharedContext);
443
+ return collections;
444
+ }
445
+ async createProductCategories(data, sharedContext = {}) {
446
+ const input = Array.isArray(data) ? data : [data];
447
+ const categories = await this.productCategoryService_.create(input, sharedContext);
448
+ const createdCategories = await this.baseRepository_.serialize(categories);
449
+ utils_2.eventBuilders.createdProductCategory({
450
+ data: createdCategories,
451
+ sharedContext,
452
+ });
453
+ return Array.isArray(data) ? createdCategories : createdCategories[0];
454
+ }
455
+ async upsertProductCategories(data, sharedContext = {}) {
456
+ const input = Array.isArray(data) ? data : [data];
457
+ const forUpdate = input.filter((category) => !!category.id);
458
+ const forCreate = input.filter((category) => !category.id);
459
+ let created = [];
460
+ let updated = [];
461
+ if (forCreate.length) {
462
+ created = await this.productCategoryService_.create(forCreate, sharedContext);
463
+ }
464
+ if (forUpdate.length) {
465
+ updated = await this.productCategoryService_.update(forUpdate, sharedContext);
466
+ }
467
+ const createdCategories = await this.baseRepository_.serialize(created);
468
+ const updatedCategories = await this.baseRepository_.serialize(updated);
469
+ utils_2.eventBuilders.createdProductCategory({
470
+ data: createdCategories,
471
+ sharedContext,
364
472
  });
473
+ utils_2.eventBuilders.updatedProductCategory({
474
+ data: updatedCategories,
475
+ sharedContext,
476
+ });
477
+ const result = [...createdCategories, ...updatedCategories];
478
+ return Array.isArray(data) ? result : result[0];
365
479
  }
366
- async deleteCategory(categoryId, sharedContext = {}) {
367
- await this.productCategoryService_.delete(categoryId, sharedContext);
368
- await this.eventBusModuleService_?.emit(types_2.ProductCategoryEvents.CATEGORY_DELETED, { id: categoryId });
480
+ async updateProductCategories(idOrSelector, data, sharedContext = {}) {
481
+ let normalizedInput = [];
482
+ if ((0, utils_1.isString)(idOrSelector)) {
483
+ // Check if the type exists in the first place
484
+ await this.productCategoryService_.retrieve(idOrSelector, {}, sharedContext);
485
+ normalizedInput = [{ id: idOrSelector, ...data }];
486
+ }
487
+ else {
488
+ const categories = await this.productCategoryService_.list(idOrSelector, {}, sharedContext);
489
+ normalizedInput = categories.map((type) => ({
490
+ id: type.id,
491
+ ...data,
492
+ }));
493
+ }
494
+ const categories = await this.productCategoryService_.update(normalizedInput, sharedContext);
495
+ const updatedCategories = await this.baseRepository_.serialize(categories);
496
+ utils_2.eventBuilders.updatedProductCategory({
497
+ data: updatedCategories,
498
+ sharedContext,
499
+ });
500
+ return (0, utils_1.isString)(idOrSelector) ? updatedCategories[0] : updatedCategories;
369
501
  }
370
- async create(data, sharedContext = {}) {
502
+ async createProducts(data, sharedContext = {}) {
371
503
  const input = Array.isArray(data) ? data : [data];
372
- const products = await this.create_(input, sharedContext);
504
+ const products = await this.createProducts_(input, sharedContext);
373
505
  const createdProducts = await this.baseRepository_.serialize(products);
374
506
  await this.eventBusModuleService_?.emit(createdProducts.map(({ id }) => ({
375
- eventName: types_2.ProductEvents.PRODUCT_CREATED,
507
+ name: types_2.ProductEvents.PRODUCT_CREATED,
376
508
  data: { id },
377
- })));
509
+ })), {
510
+ internal: true,
511
+ });
378
512
  return Array.isArray(data) ? createdProducts : createdProducts[0];
379
513
  }
380
- async upsert(data, sharedContext = {}) {
514
+ async upsertProducts(data, sharedContext = {}) {
381
515
  const input = Array.isArray(data) ? data : [data];
382
516
  const forUpdate = input.filter((product) => !!product.id);
383
517
  const forCreate = input.filter((product) => !product.id);
384
518
  let created = [];
385
519
  let updated = [];
386
520
  if (forCreate.length) {
387
- created = await this.create_(forCreate, sharedContext);
521
+ created = await this.createProducts_(forCreate, sharedContext);
388
522
  }
389
523
  if (forUpdate.length) {
390
- updated = await this.update_(forUpdate, sharedContext);
524
+ updated = await this.updateProducts_(forUpdate, sharedContext);
391
525
  }
392
526
  const result = [...created, ...updated];
393
527
  const allProducts = await this.baseRepository_.serialize(result);
394
528
  if (created.length) {
395
529
  await this.eventBusModuleService_?.emit(created.map(({ id }) => ({
396
- eventName: types_2.ProductEvents.PRODUCT_CREATED,
530
+ name: types_2.ProductEvents.PRODUCT_CREATED,
397
531
  data: { id },
398
- })));
532
+ })), {
533
+ internal: true,
534
+ });
399
535
  }
400
536
  if (updated.length) {
401
537
  await this.eventBusModuleService_?.emit(updated.map(({ id }) => ({
402
- eventName: types_2.ProductEvents.PRODUCT_UPDATED,
538
+ name: types_2.ProductEvents.PRODUCT_UPDATED,
403
539
  data: { id },
404
- })));
540
+ })), {
541
+ internal: true,
542
+ });
405
543
  }
406
544
  return Array.isArray(data) ? allProducts : allProducts[0];
407
545
  }
408
- async update(idOrSelector, data, sharedContext = {}) {
546
+ async updateProducts(idOrSelector, data, sharedContext = {}) {
409
547
  let normalizedInput = [];
410
548
  if ((0, utils_1.isString)(idOrSelector)) {
411
549
  // This will throw if the product does not exist
@@ -419,17 +557,23 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
419
557
  ...data,
420
558
  }));
421
559
  }
422
- const products = await this.update_(normalizedInput, sharedContext);
560
+ const products = await this.updateProducts_(normalizedInput, sharedContext);
423
561
  const updatedProducts = await this.baseRepository_.serialize(products);
424
562
  await this.eventBusModuleService_?.emit(updatedProducts.map(({ id }) => ({
425
- eventName: types_2.ProductEvents.PRODUCT_UPDATED,
563
+ name: types_2.ProductEvents.PRODUCT_UPDATED,
426
564
  data: { id },
427
- })));
565
+ })), {
566
+ internal: true,
567
+ });
428
568
  return (0, utils_1.isString)(idOrSelector) ? updatedProducts[0] : updatedProducts;
429
569
  }
430
- async create_(data, sharedContext = {}) {
431
- const normalizedInput = await (0, utils_1.promiseAll)(data.map(async (d) => await this.normalizeCreateProductInput(d, sharedContext)));
432
- const productData = await this.productService_.upsertWithReplace(normalizedInput, {
570
+ async createProducts_(data, sharedContext = {}) {
571
+ const normalizedInput = await (0, utils_1.promiseAll)(data.map(async (d) => {
572
+ const normalized = await this.normalizeCreateProductInput(d, sharedContext);
573
+ this.validateProductPayload(normalized);
574
+ return normalized;
575
+ }));
576
+ const { entities: productData } = await this.productService_.upsertWithReplace(normalizedInput, {
433
577
  relations: ["images", "tags", "categories"],
434
578
  }, sharedContext);
435
579
  await (0, utils_1.promiseAll)(
@@ -439,25 +583,29 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
439
583
  upsertedProduct.options = [];
440
584
  upsertedProduct.variants = [];
441
585
  if (product.options?.length) {
442
- upsertedProduct.options =
443
- await this.productOptionService_.upsertWithReplace(product.options?.map((option) => ({
444
- ...option,
445
- product_id: upsertedProduct.id,
446
- })) ?? [], { relations: ["values"] }, sharedContext);
586
+ const { entities: productOptions } = await this.productOptionService_.upsertWithReplace(product.options?.map((option) => ({
587
+ ...option,
588
+ product_id: upsertedProduct.id,
589
+ })) ?? [], { relations: ["values"] }, sharedContext);
590
+ upsertedProduct.options = productOptions;
447
591
  }
448
592
  if (product.variants?.length) {
449
- upsertedProduct.variants =
450
- await this.productVariantService_.upsertWithReplace(ProductModuleService.assignOptionsToVariants(product.variants?.map((v) => ({
451
- ...v,
452
- product_id: upsertedProduct.id,
453
- })) ?? [], upsertedProduct.options), { relations: ["options"] }, sharedContext);
593
+ const { entities: productVariants } = await this.productVariantService_.upsertWithReplace(ProductModuleService.assignOptionsToVariants(product.variants?.map((v) => ({
594
+ ...v,
595
+ product_id: upsertedProduct.id,
596
+ })) ?? [], upsertedProduct.options), { relations: ["options"] }, sharedContext);
597
+ upsertedProduct.variants = productVariants;
454
598
  }
455
599
  }));
456
600
  return productData;
457
601
  }
458
- async update_(data, sharedContext = {}) {
459
- const normalizedInput = await (0, utils_1.promiseAll)(data.map(async (d) => await this.normalizeUpdateProductInput(d, sharedContext)));
460
- const productData = await this.productService_.upsertWithReplace(normalizedInput, {
602
+ async updateProducts_(data, sharedContext = {}) {
603
+ const normalizedInput = await (0, utils_1.promiseAll)(data.map(async (d) => {
604
+ const normalized = await this.normalizeUpdateProductInput(d, sharedContext);
605
+ this.validateProductPayload(normalized);
606
+ return normalized;
607
+ }));
608
+ const { entities: productData } = await this.productService_.upsertWithReplace(normalizedInput, {
461
609
  relations: ["images", "tags", "categories"],
462
610
  }, sharedContext);
463
611
  // There is more than 1-level depth of relations here, so we need to handle the options and variants manually
@@ -467,11 +615,11 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
467
615
  const upsertedProduct = productData[i];
468
616
  let allOptions = [];
469
617
  if (product.options?.length) {
470
- upsertedProduct.options =
471
- await this.productOptionService_.upsertWithReplace(product.options?.map((option) => ({
472
- ...option,
473
- product_id: upsertedProduct.id,
474
- })) ?? [], { relations: ["values"] }, sharedContext);
618
+ const { entities: productOptions } = await this.productOptionService_.upsertWithReplace(product.options?.map((option) => ({
619
+ ...option,
620
+ product_id: upsertedProduct.id,
621
+ })) ?? [], { relations: ["values"] }, sharedContext);
622
+ upsertedProduct.options = productOptions;
475
623
  // Since we handle the options and variants outside of the product upsert, we need to clean up manually
476
624
  await this.productOptionService_.delete({
477
625
  product_id: upsertedProduct.id,
@@ -484,15 +632,15 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
484
632
  else {
485
633
  // If the options weren't affected, but the user is changing the variants, make sure we have all options available locally
486
634
  if (product.variants?.length) {
487
- allOptions = await this.productOptionService_.list({ product_id: upsertedProduct.id }, { take: null, relations: ["values"] }, sharedContext);
635
+ allOptions = await this.productOptionService_.list({ product_id: upsertedProduct.id }, { relations: ["values"] }, sharedContext);
488
636
  }
489
637
  }
490
638
  if (product.variants?.length) {
491
- upsertedProduct.variants =
492
- await this.productVariantService_.upsertWithReplace(ProductModuleService.assignOptionsToVariants(product.variants?.map((v) => ({
493
- ...v,
494
- product_id: upsertedProduct.id,
495
- })) ?? [], allOptions), { relations: ["options"] }, sharedContext);
639
+ const { entities: productVariants } = await this.productVariantService_.upsertWithReplace(ProductModuleService.assignOptionsToVariants(product.variants?.map((v) => ({
640
+ ...v,
641
+ product_id: upsertedProduct.id,
642
+ })) ?? [], allOptions), { relations: ["options"] }, sharedContext);
643
+ upsertedProduct.variants = productVariants;
496
644
  await this.productVariantService_.delete({
497
645
  product_id: upsertedProduct.id,
498
646
  id: {
@@ -503,10 +651,19 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
503
651
  }));
504
652
  return productData;
505
653
  }
654
+ /**
655
+ * Validates the manually provided handle value of the product
656
+ * to be URL-safe
657
+ */
658
+ validateProductPayload(productData) {
659
+ if (productData.handle && !(0, utils_1.isValidHandle)(productData.handle)) {
660
+ throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Invalid product handle '${productData.handle}'. It must contain URL safe characters`);
661
+ }
662
+ }
506
663
  async normalizeCreateProductInput(product, sharedContext = {}) {
507
664
  const productData = (await this.normalizeUpdateProductInput(product, sharedContext));
508
665
  if (!productData.handle && productData.title) {
509
- productData.handle = (0, utils_1.kebabCase)(productData.title);
666
+ productData.handle = (0, utils_1.toHandle)(productData.title);
510
667
  }
511
668
  if (!productData.status) {
512
669
  productData.status = utils_1.ProductStatus.DRAFT;
@@ -521,33 +678,30 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
521
678
  if (productData.is_giftcard) {
522
679
  productData.discountable = false;
523
680
  }
524
- if (productData.tags?.length && productData.tags.some((t) => !t.id)) {
525
- const dbTags = await this.productTagService_.list({
526
- value: productData.tags
527
- .map((t) => t.value)
528
- .filter((v) => !!v),
529
- }, { take: null }, sharedContext);
530
- productData.tags = productData.tags.map((tag) => {
531
- const dbTag = dbTags.find((t) => t.value === tag.value);
532
- return {
533
- ...tag,
534
- ...(dbTag ? { id: dbTag.id } : {}),
535
- };
536
- });
537
- }
538
681
  if (productData.options?.length) {
539
- ;
682
+ const dbOptions = await this.productOptionService_.list({ product_id: productData.id }, { relations: ["values"] }, sharedContext);
540
683
  productData.options = productData.options?.map((option) => {
684
+ const dbOption = dbOptions.find((o) => o.title === option.title);
541
685
  return {
542
686
  title: option.title,
543
687
  values: option.values?.map((value) => {
688
+ const dbValue = dbOption?.values?.find((val) => val.value === value);
544
689
  return {
545
690
  value: value,
691
+ ...(dbValue ? { id: dbValue.id } : {}),
546
692
  };
547
693
  }),
694
+ ...(dbOption ? { id: dbOption.id } : {}),
548
695
  };
549
696
  });
550
697
  }
698
+ if (productData.tag_ids) {
699
+ ;
700
+ productData.tags = productData.tag_ids.map((cid) => ({
701
+ id: cid,
702
+ }));
703
+ delete productData.tag_ids;
704
+ }
551
705
  if (productData.category_ids) {
552
706
  ;
553
707
  productData.categories = productData.category_ids.map((cid) => ({
@@ -581,7 +735,7 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
581
735
  }
582
736
  const variantsWithOptions = variants.map((variant) => {
583
737
  const variantOptions = Object.entries(variant.options ?? {}).map(([key, val]) => {
584
- const option = options.find((o) => o.title === key);
738
+ const option = options.find((o) => o.title === key && o.product_id === variant.product_id);
585
739
  const optionValue = option?.values?.find((v) => (v.value?.value ?? v.value) === val);
586
740
  if (!optionValue) {
587
741
  throw new utils_1.MedusaError(utils_1.MedusaError.Types.INVALID_DATA, `Option value ${val} does not exist for option ${key}`);
@@ -603,208 +757,217 @@ class ProductModuleService extends utils_1.ModulesSdkUtils.abstractModuleService
603
757
  }
604
758
  exports.default = ProductModuleService;
605
759
  __decorate([
606
- (0, utils_1.InjectManager)("baseRepository_"),
760
+ (0, utils_1.InjectManager)(),
761
+ (0, utils_1.EmitEvents)(),
607
762
  __param(1, (0, utils_1.MedusaContext)()),
608
763
  __metadata("design:type", Function),
609
764
  __metadata("design:paramtypes", [Object, Object]),
610
765
  __metadata("design:returntype", Promise)
611
- ], ProductModuleService.prototype, "createVariants", null);
766
+ ], ProductModuleService.prototype, "createProductVariants", null);
612
767
  __decorate([
613
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
768
+ (0, utils_1.InjectTransactionManager)(),
614
769
  __param(1, (0, utils_1.MedusaContext)()),
615
770
  __metadata("design:type", Function),
616
771
  __metadata("design:paramtypes", [Array, Object]),
617
772
  __metadata("design:returntype", Promise)
618
773
  ], ProductModuleService.prototype, "createVariants_", null);
619
774
  __decorate([
620
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
775
+ (0, utils_1.InjectTransactionManager)(),
776
+ (0, utils_1.EmitEvents)(),
621
777
  __param(1, (0, utils_1.MedusaContext)()),
622
778
  __metadata("design:type", Function),
623
779
  __metadata("design:paramtypes", [Object, Object]),
624
780
  __metadata("design:returntype", Promise)
625
- ], ProductModuleService.prototype, "upsertVariants", null);
781
+ ], ProductModuleService.prototype, "upsertProductVariants", null);
626
782
  __decorate([
627
- (0, utils_1.InjectManager)("baseRepository_"),
783
+ (0, utils_1.InjectManager)(),
784
+ (0, utils_1.EmitEvents)(),
628
785
  __param(2, (0, utils_1.MedusaContext)()),
629
786
  __metadata("design:type", Function),
630
787
  __metadata("design:paramtypes", [Object, Object, Object]),
631
788
  __metadata("design:returntype", Promise)
632
- ], ProductModuleService.prototype, "updateVariants", null);
789
+ ], ProductModuleService.prototype, "updateProductVariants", null);
633
790
  __decorate([
634
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
791
+ (0, utils_1.InjectTransactionManager)(),
635
792
  __param(1, (0, utils_1.MedusaContext)()),
636
793
  __metadata("design:type", Function),
637
794
  __metadata("design:paramtypes", [Array, Object]),
638
795
  __metadata("design:returntype", Promise)
639
796
  ], ProductModuleService.prototype, "updateVariants_", null);
640
797
  __decorate([
641
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
798
+ (0, utils_1.InjectManager)(),
799
+ (0, utils_1.EmitEvents)(),
642
800
  __param(1, (0, utils_1.MedusaContext)()),
643
801
  __metadata("design:type", Function),
644
- __metadata("design:paramtypes", [Array, Object]),
802
+ __metadata("design:paramtypes", [Object, Object]),
645
803
  __metadata("design:returntype", Promise)
646
- ], ProductModuleService.prototype, "createTags", null);
804
+ ], ProductModuleService.prototype, "createProductTags", null);
647
805
  __decorate([
648
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
806
+ (0, utils_1.InjectTransactionManager)(),
807
+ (0, utils_1.EmitEvents)(),
649
808
  __param(1, (0, utils_1.MedusaContext)()),
650
809
  __metadata("design:type", Function),
651
- __metadata("design:paramtypes", [Array, Object]),
810
+ __metadata("design:paramtypes", [Object, Object]),
811
+ __metadata("design:returntype", Promise)
812
+ ], ProductModuleService.prototype, "upsertProductTags", null);
813
+ __decorate([
814
+ (0, utils_1.InjectManager)(),
815
+ (0, utils_1.EmitEvents)(),
816
+ __param(2, (0, utils_1.MedusaContext)()),
817
+ __metadata("design:type", Function),
818
+ __metadata("design:paramtypes", [Object, Object, Object]),
652
819
  __metadata("design:returntype", Promise)
653
- ], ProductModuleService.prototype, "updateTags", null);
820
+ ], ProductModuleService.prototype, "updateProductTags", null);
654
821
  __decorate([
655
- (0, utils_1.InjectManager)("baseRepository_"),
822
+ (0, utils_1.InjectManager)(),
656
823
  __param(1, (0, utils_1.MedusaContext)()),
657
824
  __metadata("design:type", Function),
658
825
  __metadata("design:paramtypes", [Object, Object]),
659
826
  __metadata("design:returntype", Promise)
660
- ], ProductModuleService.prototype, "createTypes", null);
827
+ ], ProductModuleService.prototype, "createProductTypes", null);
661
828
  __decorate([
662
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
829
+ (0, utils_1.InjectTransactionManager)(),
663
830
  __param(1, (0, utils_1.MedusaContext)()),
664
831
  __metadata("design:type", Function),
665
832
  __metadata("design:paramtypes", [Object, Object]),
666
833
  __metadata("design:returntype", Promise)
667
- ], ProductModuleService.prototype, "upsertTypes", null);
834
+ ], ProductModuleService.prototype, "upsertProductTypes", null);
668
835
  __decorate([
669
- (0, utils_1.InjectManager)("baseRepository_"),
836
+ (0, utils_1.InjectManager)(),
670
837
  __param(2, (0, utils_1.MedusaContext)()),
671
838
  __metadata("design:type", Function),
672
839
  __metadata("design:paramtypes", [Object, Object, Object]),
673
840
  __metadata("design:returntype", Promise)
674
- ], ProductModuleService.prototype, "updateTypes", null);
841
+ ], ProductModuleService.prototype, "updateProductTypes", null);
675
842
  __decorate([
676
- (0, utils_1.InjectManager)("baseRepository_"),
843
+ (0, utils_1.InjectManager)(),
677
844
  __param(1, (0, utils_1.MedusaContext)()),
678
845
  __metadata("design:type", Function),
679
846
  __metadata("design:paramtypes", [Object, Object]),
680
847
  __metadata("design:returntype", Promise)
681
- ], ProductModuleService.prototype, "createOptions", null);
848
+ ], ProductModuleService.prototype, "createProductOptions", null);
682
849
  __decorate([
683
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
850
+ (0, utils_1.InjectTransactionManager)(),
684
851
  __param(1, (0, utils_1.MedusaContext)()),
685
852
  __metadata("design:type", Function),
686
853
  __metadata("design:paramtypes", [Array, Object]),
687
854
  __metadata("design:returntype", Promise)
688
855
  ], ProductModuleService.prototype, "createOptions_", null);
689
856
  __decorate([
690
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
857
+ (0, utils_1.InjectTransactionManager)(),
691
858
  __param(1, (0, utils_1.MedusaContext)()),
692
859
  __metadata("design:type", Function),
693
860
  __metadata("design:paramtypes", [Object, Object]),
694
861
  __metadata("design:returntype", Promise)
695
- ], ProductModuleService.prototype, "upsertOptions", null);
862
+ ], ProductModuleService.prototype, "upsertProductOptions", null);
696
863
  __decorate([
697
- (0, utils_1.InjectManager)("baseRepository_"),
864
+ (0, utils_1.InjectManager)(),
698
865
  __param(2, (0, utils_1.MedusaContext)()),
699
866
  __metadata("design:type", Function),
700
867
  __metadata("design:paramtypes", [Object, Object, Object]),
701
868
  __metadata("design:returntype", Promise)
702
- ], ProductModuleService.prototype, "updateOptions", null);
869
+ ], ProductModuleService.prototype, "updateProductOptions", null);
703
870
  __decorate([
704
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
871
+ (0, utils_1.InjectTransactionManager)(),
705
872
  __param(1, (0, utils_1.MedusaContext)()),
706
873
  __metadata("design:type", Function),
707
874
  __metadata("design:paramtypes", [Array, Object]),
708
875
  __metadata("design:returntype", Promise)
709
876
  ], ProductModuleService.prototype, "updateOptions_", null);
710
877
  __decorate([
711
- (0, utils_1.InjectManager)("baseRepository_"),
878
+ (0, utils_1.InjectManager)(),
712
879
  __param(1, (0, utils_1.MedusaContext)()),
713
880
  __metadata("design:type", Function),
714
881
  __metadata("design:paramtypes", [Object, Object]),
715
882
  __metadata("design:returntype", Promise)
716
- ], ProductModuleService.prototype, "createCollections", null);
883
+ ], ProductModuleService.prototype, "createProductCollections", null);
717
884
  __decorate([
718
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
885
+ (0, utils_1.InjectTransactionManager)(),
719
886
  __param(1, (0, utils_1.MedusaContext)()),
720
887
  __metadata("design:type", Function),
721
888
  __metadata("design:paramtypes", [Array, Object]),
722
889
  __metadata("design:returntype", Promise)
723
890
  ], ProductModuleService.prototype, "createCollections_", null);
724
891
  __decorate([
725
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
892
+ (0, utils_1.InjectTransactionManager)(),
726
893
  __param(1, (0, utils_1.MedusaContext)()),
727
894
  __metadata("design:type", Function),
728
895
  __metadata("design:paramtypes", [Object, Object]),
729
896
  __metadata("design:returntype", Promise)
730
- ], ProductModuleService.prototype, "upsertCollections", null);
897
+ ], ProductModuleService.prototype, "upsertProductCollections", null);
731
898
  __decorate([
732
- (0, utils_1.InjectManager)("baseRepository_"),
899
+ (0, utils_1.InjectManager)(),
733
900
  __param(2, (0, utils_1.MedusaContext)()),
734
901
  __metadata("design:type", Function),
735
902
  __metadata("design:paramtypes", [Object, Object, Object]),
736
903
  __metadata("design:returntype", Promise)
737
- ], ProductModuleService.prototype, "updateCollections", null);
904
+ ], ProductModuleService.prototype, "updateProductCollections", null);
738
905
  __decorate([
739
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
906
+ (0, utils_1.InjectTransactionManager)(),
740
907
  __param(1, (0, utils_1.MedusaContext)()),
741
908
  __metadata("design:type", Function),
742
909
  __metadata("design:paramtypes", [Array, Object]),
743
910
  __metadata("design:returntype", Promise)
744
911
  ], ProductModuleService.prototype, "updateCollections_", null);
745
912
  __decorate([
746
- (0, utils_1.InjectManager)("baseRepository_"),
913
+ (0, utils_1.InjectManager)(),
914
+ (0, utils_1.EmitEvents)(),
747
915
  __param(1, (0, utils_1.MedusaContext)()),
748
916
  __metadata("design:type", Function),
749
917
  __metadata("design:paramtypes", [Object, Object]),
750
918
  __metadata("design:returntype", Promise)
751
- ], ProductModuleService.prototype, "createCategory", null);
919
+ ], ProductModuleService.prototype, "createProductCategories", null);
752
920
  __decorate([
753
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
921
+ (0, utils_1.InjectTransactionManager)(),
922
+ (0, utils_1.EmitEvents)(),
754
923
  __param(1, (0, utils_1.MedusaContext)()),
755
924
  __metadata("design:type", Function),
756
925
  __metadata("design:paramtypes", [Object, Object]),
757
926
  __metadata("design:returntype", Promise)
758
- ], ProductModuleService.prototype, "createCategory_", null);
927
+ ], ProductModuleService.prototype, "upsertProductCategories", null);
759
928
  __decorate([
760
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
929
+ (0, utils_1.InjectManager)(),
930
+ (0, utils_1.EmitEvents)(),
761
931
  __param(2, (0, utils_1.MedusaContext)()),
762
932
  __metadata("design:type", Function),
763
- __metadata("design:paramtypes", [String, Object, Object]),
764
- __metadata("design:returntype", Promise)
765
- ], ProductModuleService.prototype, "updateCategory", null);
766
- __decorate([
767
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
768
- __param(1, (0, utils_1.MedusaContext)()),
769
- __metadata("design:type", Function),
770
- __metadata("design:paramtypes", [String, Object]),
933
+ __metadata("design:paramtypes", [Object, Object, Object]),
771
934
  __metadata("design:returntype", Promise)
772
- ], ProductModuleService.prototype, "deleteCategory", null);
935
+ ], ProductModuleService.prototype, "updateProductCategories", null);
773
936
  __decorate([
774
- (0, utils_1.InjectManager)("baseRepository_"),
937
+ (0, utils_1.InjectManager)(),
775
938
  __param(1, (0, utils_1.MedusaContext)()),
776
939
  __metadata("design:type", Function),
777
940
  __metadata("design:paramtypes", [Object, Object]),
778
941
  __metadata("design:returntype", Promise)
779
- ], ProductModuleService.prototype, "create", null);
942
+ ], ProductModuleService.prototype, "createProducts", null);
780
943
  __decorate([
781
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
944
+ (0, utils_1.InjectTransactionManager)(),
782
945
  __param(1, (0, utils_1.MedusaContext)()),
783
946
  __metadata("design:type", Function),
784
947
  __metadata("design:paramtypes", [Object, Object]),
785
948
  __metadata("design:returntype", Promise)
786
- ], ProductModuleService.prototype, "upsert", null);
949
+ ], ProductModuleService.prototype, "upsertProducts", null);
787
950
  __decorate([
788
- (0, utils_1.InjectManager)("baseRepository_"),
951
+ (0, utils_1.InjectManager)(),
789
952
  __param(2, (0, utils_1.MedusaContext)()),
790
953
  __metadata("design:type", Function),
791
954
  __metadata("design:paramtypes", [Object, Object, Object]),
792
955
  __metadata("design:returntype", Promise)
793
- ], ProductModuleService.prototype, "update", null);
956
+ ], ProductModuleService.prototype, "updateProducts", null);
794
957
  __decorate([
795
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
958
+ (0, utils_1.InjectTransactionManager)(),
796
959
  __param(1, (0, utils_1.MedusaContext)()),
797
960
  __metadata("design:type", Function),
798
961
  __metadata("design:paramtypes", [Array, Object]),
799
962
  __metadata("design:returntype", Promise)
800
- ], ProductModuleService.prototype, "create_", null);
963
+ ], ProductModuleService.prototype, "createProducts_", null);
801
964
  __decorate([
802
- (0, utils_1.InjectTransactionManager)("baseRepository_"),
965
+ (0, utils_1.InjectTransactionManager)(),
803
966
  __param(1, (0, utils_1.MedusaContext)()),
804
967
  __metadata("design:type", Function),
805
968
  __metadata("design:paramtypes", [Array, Object]),
806
969
  __metadata("design:returntype", Promise)
807
- ], ProductModuleService.prototype, "update_", null);
970
+ ], ProductModuleService.prototype, "updateProducts_", null);
808
971
  __decorate([
809
972
  __param(1, (0, utils_1.MedusaContext)()),
810
973
  __metadata("design:type", Function),
@@ -817,3 +980,4 @@ __decorate([
817
980
  __metadata("design:paramtypes", [Object, Object]),
818
981
  __metadata("design:returntype", Promise)
819
982
  ], ProductModuleService.prototype, "normalizeUpdateProductInput", null);
983
+ //# sourceMappingURL=product-module-service.js.map