@unchainedshop/core 4.0.0-rc.14 → 4.0.0-rc.16

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 (193) hide show
  1. package/lib/bulk-importer/createBulkImporter.d.ts +61 -0
  2. package/lib/bulk-importer/createBulkImporter.d.ts.map +1 -0
  3. package/lib/bulk-importer/createBulkImporter.js +135 -0
  4. package/lib/bulk-importer/createBulkImporter.js.map +1 -0
  5. package/lib/bulk-importer/handlers/assortment/create.d.ts +15 -0
  6. package/lib/bulk-importer/handlers/assortment/create.d.ts.map +1 -0
  7. package/lib/bulk-importer/handlers/assortment/create.js +62 -0
  8. package/lib/bulk-importer/handlers/assortment/create.js.map +1 -0
  9. package/lib/bulk-importer/handlers/assortment/index.d.ts +4 -0
  10. package/lib/bulk-importer/handlers/assortment/index.d.ts.map +1 -0
  11. package/lib/bulk-importer/handlers/assortment/index.js +4 -0
  12. package/lib/bulk-importer/handlers/assortment/index.js.map +1 -0
  13. package/lib/bulk-importer/handlers/assortment/remove.d.ts +12 -0
  14. package/lib/bulk-importer/handlers/assortment/remove.d.ts.map +1 -0
  15. package/lib/bulk-importer/handlers/assortment/remove.js +13 -0
  16. package/lib/bulk-importer/handlers/assortment/remove.js.map +1 -0
  17. package/lib/bulk-importer/handlers/assortment/update.d.ts +16 -0
  18. package/lib/bulk-importer/handlers/assortment/update.d.ts.map +1 -0
  19. package/lib/bulk-importer/handlers/assortment/update.js +62 -0
  20. package/lib/bulk-importer/handlers/assortment/update.js.map +1 -0
  21. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.d.ts +9 -0
  22. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.d.ts.map +1 -0
  23. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js +37 -0
  24. package/lib/bulk-importer/handlers/assortment/upsertAssortmentChildren.js.map +1 -0
  25. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.d.ts +9 -0
  26. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.d.ts.map +1 -0
  27. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js +32 -0
  28. package/lib/bulk-importer/handlers/assortment/upsertAssortmentFilters.js.map +1 -0
  29. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.d.ts +9 -0
  30. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.d.ts.map +1 -0
  31. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js +37 -0
  32. package/lib/bulk-importer/handlers/assortment/upsertAssortmentProducts.js.map +1 -0
  33. package/lib/bulk-importer/handlers/assortment/upsertMedia.d.ts +11 -0
  34. package/lib/bulk-importer/handlers/assortment/upsertMedia.d.ts.map +1 -0
  35. package/lib/bulk-importer/handlers/assortment/upsertMedia.js +39 -0
  36. package/lib/bulk-importer/handlers/assortment/upsertMedia.js.map +1 -0
  37. package/lib/bulk-importer/handlers/filter/create.d.ts +13 -0
  38. package/lib/bulk-importer/handlers/filter/create.d.ts.map +1 -0
  39. package/lib/bulk-importer/handlers/filter/create.js +58 -0
  40. package/lib/bulk-importer/handlers/filter/create.js.map +1 -0
  41. package/lib/bulk-importer/handlers/filter/index.d.ts +4 -0
  42. package/lib/bulk-importer/handlers/filter/index.d.ts.map +1 -0
  43. package/lib/bulk-importer/handlers/filter/index.js +4 -0
  44. package/lib/bulk-importer/handlers/filter/index.js.map +1 -0
  45. package/lib/bulk-importer/handlers/filter/remove.d.ts +12 -0
  46. package/lib/bulk-importer/handlers/filter/remove.d.ts.map +1 -0
  47. package/lib/bulk-importer/handlers/filter/remove.js +14 -0
  48. package/lib/bulk-importer/handlers/filter/remove.js.map +1 -0
  49. package/lib/bulk-importer/handlers/filter/update.d.ts +13 -0
  50. package/lib/bulk-importer/handlers/filter/update.d.ts.map +1 -0
  51. package/lib/bulk-importer/handlers/filter/update.js +48 -0
  52. package/lib/bulk-importer/handlers/filter/update.js.map +1 -0
  53. package/lib/bulk-importer/handlers/product/create.d.ts +15 -0
  54. package/lib/bulk-importer/handlers/product/create.d.ts.map +1 -0
  55. package/lib/bulk-importer/handlers/product/create.js +53 -0
  56. package/lib/bulk-importer/handlers/product/create.js.map +1 -0
  57. package/lib/bulk-importer/handlers/product/index.d.ts +4 -0
  58. package/lib/bulk-importer/handlers/product/index.d.ts.map +1 -0
  59. package/lib/bulk-importer/handlers/product/index.js +4 -0
  60. package/lib/bulk-importer/handlers/product/index.js.map +1 -0
  61. package/lib/bulk-importer/handlers/product/remove.d.ts +14 -0
  62. package/lib/bulk-importer/handlers/product/remove.d.ts.map +1 -0
  63. package/lib/bulk-importer/handlers/product/remove.js +13 -0
  64. package/lib/bulk-importer/handlers/product/remove.js.map +1 -0
  65. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.d.ts +3 -0
  66. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.d.ts.map +1 -0
  67. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.js +16 -0
  68. package/lib/bulk-importer/handlers/product/transformSpecificationToProductStructure.js.map +1 -0
  69. package/lib/bulk-importer/handlers/product/update.d.ts +15 -0
  70. package/lib/bulk-importer/handlers/product/update.d.ts.map +1 -0
  71. package/lib/bulk-importer/handlers/product/update.js +48 -0
  72. package/lib/bulk-importer/handlers/product/update.js.map +1 -0
  73. package/lib/bulk-importer/handlers/product/upsertMedia.d.ts +10 -0
  74. package/lib/bulk-importer/handlers/product/upsertMedia.d.ts.map +1 -0
  75. package/lib/bulk-importer/handlers/product/upsertMedia.js +45 -0
  76. package/lib/bulk-importer/handlers/product/upsertMedia.js.map +1 -0
  77. package/lib/bulk-importer/handlers/product/upsertVariations.d.ts +8 -0
  78. package/lib/bulk-importer/handlers/product/upsertVariations.d.ts.map +1 -0
  79. package/lib/bulk-importer/handlers/product/upsertVariations.js +48 -0
  80. package/lib/bulk-importer/handlers/product/upsertVariations.js.map +1 -0
  81. package/lib/bulk-importer/handlers/utils/convertTagsToLowerCase.d.ts +3 -0
  82. package/lib/bulk-importer/handlers/utils/convertTagsToLowerCase.d.ts.map +1 -0
  83. package/lib/bulk-importer/handlers/utils/convertTagsToLowerCase.js +6 -0
  84. package/lib/bulk-importer/handlers/utils/convertTagsToLowerCase.js.map +1 -0
  85. package/lib/bulk-importer/upsertAsset.d.ts +12 -0
  86. package/lib/bulk-importer/upsertAsset.d.ts.map +1 -0
  87. package/lib/bulk-importer/upsertAsset.js +33 -0
  88. package/lib/bulk-importer/upsertAsset.js.map +1 -0
  89. package/lib/core-index.d.ts +7 -5
  90. package/lib/core-index.d.ts.map +1 -1
  91. package/lib/core-index.js +5 -1
  92. package/lib/core-index.js.map +1 -1
  93. package/lib/directors/FilterAdapter.d.ts +1 -1
  94. package/lib/directors/FilterAdapter.d.ts.map +1 -1
  95. package/lib/directors/FilterDirector.d.ts.map +1 -1
  96. package/lib/directors/FilterDirector.js +6 -7
  97. package/lib/directors/FilterDirector.js.map +1 -1
  98. package/lib/directors/PaymentDirector.js +2 -2
  99. package/lib/directors/PaymentDirector.js.map +1 -1
  100. package/lib/directors/WorkerAdapter.d.ts +3 -2
  101. package/lib/directors/WorkerAdapter.d.ts.map +1 -1
  102. package/lib/directors/WorkerAdapter.js.map +1 -1
  103. package/lib/factory/index.d.ts +3 -0
  104. package/lib/factory/index.d.ts.map +1 -0
  105. package/lib/factory/index.js +3 -0
  106. package/lib/factory/index.js.map +1 -0
  107. package/lib/factory/registerProductDiscoverabilityFilter copy.d.ts +5 -0
  108. package/lib/factory/registerProductDiscoverabilityFilter copy.d.ts.map +1 -0
  109. package/lib/factory/registerProductDiscoverabilityFilter copy.js +28 -0
  110. package/lib/factory/registerProductDiscoverabilityFilter copy.js.map +1 -0
  111. package/lib/factory/registerProductDiscoverabilityFilter.d.ts +5 -0
  112. package/lib/factory/registerProductDiscoverabilityFilter.d.ts.map +1 -0
  113. package/lib/factory/registerProductDiscoverabilityFilter.js +27 -0
  114. package/lib/factory/registerProductDiscoverabilityFilter.js.map +1 -0
  115. package/lib/modules.d.ts.map +1 -1
  116. package/lib/modules.js +1 -0
  117. package/lib/modules.js.map +1 -1
  118. package/lib/services/activateEnrollment.d.ts.map +1 -1
  119. package/lib/services/activateEnrollment.js +5 -9
  120. package/lib/services/activateEnrollment.js.map +1 -1
  121. package/lib/services/addMessage.d.ts +4 -0
  122. package/lib/services/addMessage.d.ts.map +1 -0
  123. package/lib/services/addMessage.js +15 -0
  124. package/lib/services/addMessage.js.map +1 -0
  125. package/lib/services/index.d.ts +4 -0
  126. package/lib/services/index.d.ts.map +1 -1
  127. package/lib/services/index.js +4 -0
  128. package/lib/services/index.js.map +1 -1
  129. package/lib/services/initCartProviders.d.ts.map +1 -1
  130. package/lib/services/initCartProviders.js +6 -2
  131. package/lib/services/initCartProviders.js.map +1 -1
  132. package/lib/services/initializeEnrollment.d.ts.map +1 -1
  133. package/lib/services/initializeEnrollment.js +5 -9
  134. package/lib/services/initializeEnrollment.js.map +1 -1
  135. package/lib/services/processQuotation.d.ts.map +1 -1
  136. package/lib/services/processQuotation.js +4 -8
  137. package/lib/services/processQuotation.js.map +1 -1
  138. package/lib/services/removeFiles.js +2 -2
  139. package/lib/services/removeFiles.js.map +1 -1
  140. package/lib/services/searchAssortments.d.ts.map +1 -1
  141. package/lib/services/searchAssortments.js +2 -1
  142. package/lib/services/searchAssortments.js.map +1 -1
  143. package/lib/services/searchProducts.d.ts.map +1 -1
  144. package/lib/services/searchProducts.js +2 -1
  145. package/lib/services/searchProducts.js.map +1 -1
  146. package/lib/services/terminateEnrollment.d.ts.map +1 -1
  147. package/lib/services/terminateEnrollment.js +5 -9
  148. package/lib/services/terminateEnrollment.js.map +1 -1
  149. package/lib/services/updateCalculation.d.ts.map +1 -1
  150. package/lib/services/updateCalculation.js +5 -3
  151. package/lib/services/updateCalculation.js.map +1 -1
  152. package/package.json +21 -20
  153. package/src/bulk-importer/createBulkImporter.ts +193 -0
  154. package/src/bulk-importer/handlers/assortment/create.ts +87 -0
  155. package/src/bulk-importer/handlers/assortment/index.ts +3 -0
  156. package/src/bulk-importer/handlers/assortment/remove.ts +15 -0
  157. package/src/bulk-importer/handlers/assortment/update.ts +89 -0
  158. package/src/bulk-importer/handlers/assortment/upsertAssortmentChildren.ts +52 -0
  159. package/src/bulk-importer/handlers/assortment/upsertAssortmentFilters.ts +42 -0
  160. package/src/bulk-importer/handlers/assortment/upsertAssortmentProducts.ts +50 -0
  161. package/src/bulk-importer/handlers/assortment/upsertMedia.ts +58 -0
  162. package/src/bulk-importer/handlers/filter/create.ts +76 -0
  163. package/src/bulk-importer/handlers/filter/index.ts +3 -0
  164. package/src/bulk-importer/handlers/filter/remove.ts +20 -0
  165. package/src/bulk-importer/handlers/filter/update.ts +67 -0
  166. package/src/bulk-importer/handlers/product/create.ts +70 -0
  167. package/src/bulk-importer/handlers/product/index.ts +3 -0
  168. package/src/bulk-importer/handlers/product/remove.ts +21 -0
  169. package/src/bulk-importer/handlers/product/transformSpecificationToProductStructure.ts +22 -0
  170. package/src/bulk-importer/handlers/product/update.ts +66 -0
  171. package/src/bulk-importer/handlers/product/upsertMedia.ts +64 -0
  172. package/src/bulk-importer/handlers/product/upsertVariations.ts +71 -0
  173. package/src/bulk-importer/handlers/utils/convertTagsToLowerCase.ts +4 -0
  174. package/src/bulk-importer/upsertAsset.ts +42 -0
  175. package/src/core-index.ts +11 -6
  176. package/src/directors/FilterAdapter.ts +1 -1
  177. package/src/directors/FilterDirector.ts +6 -7
  178. package/src/directors/PaymentDirector.ts +2 -2
  179. package/src/directors/WorkerAdapter.ts +8 -3
  180. package/src/factory/index.ts +3 -0
  181. package/src/factory/registerProductDiscoverabilityFilter.ts +36 -0
  182. package/src/modules.ts +1 -0
  183. package/src/services/activateEnrollment.ts +5 -9
  184. package/src/services/addMessage.ts +20 -0
  185. package/src/services/index.ts +4 -0
  186. package/src/services/initCartProviders.ts +6 -8
  187. package/src/services/initializeEnrollment.ts +5 -9
  188. package/src/services/processQuotation.ts +4 -8
  189. package/src/services/removeFiles.ts +2 -2
  190. package/src/services/searchAssortments.ts +2 -1
  191. package/src/services/searchProducts.ts +3 -1
  192. package/src/services/terminateEnrollment.ts +5 -9
  193. package/src/services/updateCalculation.ts +5 -3
@@ -0,0 +1,20 @@
1
+ import { Work } from '@unchainedshop/core-worker';
2
+ import { MessagingDirector } from '../core-index.js';
3
+ import { Modules } from '../modules.js';
4
+
5
+ export async function addMessageService<T = Record<string, any>>(
6
+ this: Modules,
7
+ template: string,
8
+ input: T,
9
+ ): Promise<Work | null> {
10
+ const templateResolver = MessagingDirector.getTemplate(template); // Validate template exists
11
+ if (!templateResolver) return null;
12
+ return this.worker.addWork({
13
+ type: 'MESSAGE',
14
+ input: {
15
+ template,
16
+ ...input,
17
+ },
18
+ retries: 0,
19
+ });
20
+ }
@@ -44,6 +44,7 @@ import { simulateProductPricingService } from './simulateProductPricing.js';
44
44
  import { simulateProductDispatchingService } from './simulateProductDispatching.js';
45
45
  import { simulateProductInventoryService } from './simulateProductInventory.js';
46
46
  import { findOrInitCartService } from './findOrInitCart.js';
47
+ import { addMessageService } from './addMessage.js';
47
48
 
48
49
  // Auto-Inject Unchained API as last parameter
49
50
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
@@ -156,6 +157,9 @@ export default function initServices(modules: Modules, customServices: CustomSer
156
157
  warehousing: {
157
158
  ercMetadata: ercMetadataService as Bound<typeof ercMetadataService>,
158
159
  },
160
+ worker: {
161
+ addMessage: addMessageService as Bound<typeof addMessageService>,
162
+ },
159
163
  };
160
164
 
161
165
  // This Proxy Binds all services to the Modules Object
@@ -33,10 +33,9 @@ export async function initCartProvidersService(this: Modules, order: Order) {
33
33
  { modules: this },
34
34
  );
35
35
  if (defaultOrderDeliveryProvider) {
36
- updatedOrder = await this.orders.setDeliveryProvider(
37
- updatedOrder._id,
38
- defaultOrderDeliveryProvider._id,
39
- );
36
+ updatedOrder =
37
+ (await this.orders.setDeliveryProvider(updatedOrder._id, defaultOrderDeliveryProvider._id)) ||
38
+ updatedOrder;
40
39
  }
41
40
  }
42
41
 
@@ -76,10 +75,9 @@ export async function initCartProvidersService(this: Modules, order: Order) {
76
75
  );
77
76
 
78
77
  if (defaultOrderPaymentProvider) {
79
- updatedOrder = await this.orders.setPaymentProvider(
80
- updatedOrder._id,
81
- defaultOrderPaymentProvider._id,
82
- );
78
+ updatedOrder =
79
+ (await this.orders.setPaymentProvider(updatedOrder._id, defaultOrderPaymentProvider._id)) ||
80
+ updatedOrder;
83
81
  }
84
82
  }
85
83
  return updatedOrder;
@@ -2,6 +2,7 @@ import { Enrollment } from '@unchainedshop/core-enrollments';
2
2
  import { EnrollmentDirector } from '../core-index.js';
3
3
  import { processEnrollmentService } from './processEnrollment.js';
4
4
  import { Modules } from '../modules.js';
5
+ import { addMessageService } from './addMessage.js';
5
6
 
6
7
  export async function initializeEnrollmentService(
7
8
  this: Modules,
@@ -23,15 +24,10 @@ export async function initializeEnrollmentService(
23
24
  const user = await this.users.findUserById(enrollment.userId);
24
25
  const locale = this.users.userLocale(user);
25
26
 
26
- await this.worker.addWork({
27
- type: 'MESSAGE',
28
- retries: 0,
29
- input: {
30
- reason: params.reason || 'status_change',
31
- locale: locale.baseName,
32
- template: 'ENROLLMENT_STATUS',
33
- enrollmentId: processedEnrollment._id,
34
- },
27
+ await addMessageService.bind(this)('ENROLLMENT_STATUS', {
28
+ reason: 'status_change',
29
+ locale: locale.baseName,
30
+ enrollmentId: processedEnrollment._id,
35
31
  });
36
32
 
37
33
  return processedEnrollment;
@@ -1,6 +1,7 @@
1
1
  import { Quotation, QuotationStatus } from '@unchainedshop/core-quotations';
2
2
  import { Modules } from '../modules.js';
3
3
  import { QuotationDirector } from '../core-index.js';
4
+ import { addMessageService } from './addMessage.js';
4
5
 
5
6
  const findNextStatus = async (quotation: Quotation, modules: Modules): Promise<QuotationStatus> => {
6
7
  let status = quotation.status as QuotationStatus;
@@ -61,14 +62,9 @@ export async function processQuotationService(
61
62
  const user = await this.users.findUserById(updatedQuotation.userId);
62
63
  const locale = this.users.userLocale(user);
63
64
 
64
- await this.worker.addWork({
65
- type: 'MESSAGE',
66
- retries: 0,
67
- input: {
68
- locale: locale.baseName,
69
- template: 'QUOTATION_STATUS',
70
- quotationId: updatedQuotation._id,
71
- },
65
+ await addMessageService.bind(this)('QUOTATION_STATUS', {
66
+ locale: locale.baseName,
67
+ quotationId: updatedQuotation._id,
72
68
  });
73
69
 
74
70
  return updatedQuotation;
@@ -13,8 +13,8 @@ export async function removeFilesService(this: Modules, { fileIds }: { fileIds:
13
13
 
14
14
  try {
15
15
  await fileUploadAdapter.removeFiles(fileObjects, { modules: this });
16
- } catch (e) {
17
- console.warn(e);
16
+ } catch {
17
+ /**/
18
18
  }
19
19
 
20
20
  const fileIdsToDelete = fileObjects.map((f) => f._id).filter(Boolean);
@@ -36,7 +36,8 @@ export async function searchAssortmentsService(
36
36
  const assortmentIds = await searchQuery.assortmentIds;
37
37
 
38
38
  const totalAssortmentIds =
39
- (await filterActions.searchAssortments({ assortmentIds }, searchConfiguration)) || [];
39
+ (await filterActions.searchAssortments({ assortmentIds }, searchConfiguration)) ||
40
+ (await this.assortments.findAssortmentIds({ includeInactive: searchQuery.includeInactive }));
40
41
 
41
42
  return {
42
43
  searchConfiguration,
@@ -47,7 +47,9 @@ export async function searchProductsService(
47
47
  };
48
48
  }
49
49
 
50
- const totalProductIds = (await filterActions.searchProducts(searchQuery, searchConfiguration)) || [];
50
+ const totalProductIds =
51
+ (await filterActions.searchProducts(searchQuery, searchConfiguration)) ||
52
+ (await this.products.findProductIds({ includeDrafts: searchQuery.includeInactive }));
51
53
 
52
54
  const filteredProductIds = await FilterDirector.productFacetedSearch(
53
55
  totalProductIds,
@@ -1,5 +1,6 @@
1
1
  import { Enrollment, EnrollmentStatus } from '@unchainedshop/core-enrollments';
2
2
  import { processEnrollmentService } from './processEnrollment.js';
3
+ import { addMessageService } from './addMessage.js';
3
4
 
4
5
  export async function terminateEnrollmentService(enrollment: Enrollment) {
5
6
  if (enrollment.status === EnrollmentStatus.TERMINATED) return enrollment;
@@ -14,15 +15,10 @@ export async function terminateEnrollmentService(enrollment: Enrollment) {
14
15
  const user = await this.users.findUserById(enrollment.userId);
15
16
  const locale = this.users.userLocale(user);
16
17
 
17
- await this.worker.addWork({
18
- type: 'MESSAGE',
19
- retries: 0,
20
- input: {
21
- reason: 'status_change',
22
- locale: locale.baseName,
23
- template: 'ENROLLMENT_STATUS',
24
- enrollmentId: updatedEnrollment._id,
25
- },
18
+ await addMessageService.bind(this)('ENROLLMENT_STATUS', {
19
+ reason: 'status_change',
20
+ locale: locale.baseName,
21
+ enrollmentId: updatedEnrollment._id,
26
22
  });
27
23
 
28
24
  return updatedEnrollment;
@@ -11,7 +11,7 @@ import {
11
11
  } from '../directors/index.js';
12
12
 
13
13
  export async function updateCalculationService(this: Modules, orderId: string) {
14
- const order = await this.orders.findOrder({ orderId });
14
+ let order = await this.orders.findOrder({ orderId });
15
15
 
16
16
  // Don't recalculate orders, only carts
17
17
  if (order.status !== null) return order;
@@ -124,7 +124,9 @@ export async function updateCalculationService(this: Modules, orderId: string) {
124
124
  { modules: this },
125
125
  );
126
126
 
127
- const updatedOrder = await this.orders.updateCalculationSheet(orderId, calculation);
127
+ if (JSON.stringify(order.calculation) !== JSON.stringify(calculation)) {
128
+ order = await this.orders.updateCalculationSheet(orderId, calculation);
129
+ }
128
130
 
129
131
  /*
130
132
  // We have to do initCartProviders after calculation, only then filterSupportedProviders will work correctly and has access to recent pricing
@@ -138,5 +140,5 @@ export async function updateCalculationService(this: Modules, orderId: string) {
138
140
  // 6. update calculation -> order pricing updated to items 0, delivery 0, payment 0
139
141
  // 7. initCartProviders with updated order -> all providers are valid -> return order
140
142
  */
141
- return initCartProvidersService.bind(this)(updatedOrder);
143
+ return initCartProvidersService.bind(this)(order);
142
144
  }