@unchainedshop/core 4.6.1 → 4.7.2

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 (171) hide show
  1. package/lib/core-index.d.ts +3 -0
  2. package/lib/core-index.js +6 -2
  3. package/lib/directors/BaseDiscountDirector.js +6 -6
  4. package/lib/directors/BasePricingDirector.js +1 -1
  5. package/lib/directors/DeliveryAdapter.js +1 -0
  6. package/lib/directors/DeliveryDirector.js +11 -2
  7. package/lib/directors/DeliveryPricingAdapter.d.ts +2 -1
  8. package/lib/directors/DeliveryPricingAdapter.js +2 -1
  9. package/lib/directors/DeliveryPricingDirector.d.ts +1 -1
  10. package/lib/directors/DeliveryPricingDirector.js +12 -2
  11. package/lib/directors/DeliveryPricingSheet.d.ts +1 -1
  12. package/lib/directors/DeliveryPricingSheet.js +1 -1
  13. package/lib/directors/EnrollmentAdapter.js +1 -0
  14. package/lib/directors/EnrollmentDirector.js +11 -1
  15. package/lib/directors/FileDirector.d.ts +10 -0
  16. package/lib/directors/FileDirector.js +25 -0
  17. package/lib/directors/FilterAdapter.js +1 -0
  18. package/lib/directors/FilterDirector.js +11 -1
  19. package/lib/directors/OrderDiscountAdapter.d.ts +3 -2
  20. package/lib/directors/OrderDiscountAdapter.js +5 -2
  21. package/lib/directors/OrderDiscountDirector.d.ts +15 -1
  22. package/lib/directors/OrderDiscountDirector.js +14 -1
  23. package/lib/directors/OrderPricingAdapter.d.ts +2 -1
  24. package/lib/directors/OrderPricingAdapter.js +3 -1
  25. package/lib/directors/OrderPricingDirector.d.ts +4 -1
  26. package/lib/directors/OrderPricingDirector.js +12 -1
  27. package/lib/directors/OrderPricingSheet.d.ts +1 -1
  28. package/lib/directors/OrderPricingSheet.js +1 -1
  29. package/lib/directors/PaymentAdapter.js +1 -0
  30. package/lib/directors/PaymentDirector.js +11 -2
  31. package/lib/directors/PaymentPricingAdapter.d.ts +2 -1
  32. package/lib/directors/PaymentPricingAdapter.js +2 -1
  33. package/lib/directors/PaymentPricingDirector.d.ts +2 -1
  34. package/lib/directors/PaymentPricingDirector.js +11 -1
  35. package/lib/directors/PaymentPricingSheet.d.ts +2 -1
  36. package/lib/directors/PaymentPricingSheet.js +2 -1
  37. package/lib/directors/ProductDiscountAdapter.d.ts +3 -2
  38. package/lib/directors/ProductDiscountAdapter.js +5 -2
  39. package/lib/directors/ProductDiscountDirector.d.ts +16 -2
  40. package/lib/directors/ProductDiscountDirector.js +15 -2
  41. package/lib/directors/ProductPricingAdapter.d.ts +2 -1
  42. package/lib/directors/ProductPricingAdapter.js +3 -1
  43. package/lib/directors/ProductPricingDirector.d.ts +3 -1
  44. package/lib/directors/ProductPricingDirector.js +12 -1
  45. package/lib/directors/ProductPricingSheet.d.ts +1 -1
  46. package/lib/directors/ProductPricingSheet.js +1 -1
  47. package/lib/directors/QuotationAdapter.js +1 -0
  48. package/lib/directors/QuotationDirector.js +11 -2
  49. package/lib/directors/WarehousingAdapter.js +1 -0
  50. package/lib/directors/WarehousingDirector.d.ts +1 -1
  51. package/lib/directors/WarehousingDirector.js +12 -2
  52. package/lib/directors/WorkerAdapter.js +1 -0
  53. package/lib/directors/WorkerDirector.d.ts +1 -1
  54. package/lib/directors/WorkerDirector.js +10 -17
  55. package/lib/directors/index.d.ts +2 -0
  56. package/lib/directors/index.js +2 -0
  57. package/lib/errors/common.d.ts +568 -0
  58. package/lib/errors/common.js +789 -0
  59. package/lib/errors/index.d.ts +1 -0
  60. package/lib/errors/index.js +1 -0
  61. package/lib/factory/registerAssortmentSearchFilter.d.ts +2 -1
  62. package/lib/factory/registerAssortmentSearchFilter.js +12 -3
  63. package/lib/factory/registerInvoicePayment.d.ts +2 -2
  64. package/lib/factory/registerInvoicePayment.js +12 -3
  65. package/lib/factory/registerPhysicalWarehousing.d.ts +2 -2
  66. package/lib/factory/registerPhysicalWarehousing.js +12 -3
  67. package/lib/factory/registerPickUpDelivery.d.ts +2 -2
  68. package/lib/factory/registerPickUpDelivery.js +12 -3
  69. package/lib/factory/registerProductDiscoverabilityFilter.d.ts +2 -1
  70. package/lib/factory/registerProductDiscoverabilityFilter.js +12 -3
  71. package/lib/factory/registerProductSearchFilter.d.ts +2 -1
  72. package/lib/factory/registerProductSearchFilter.js +12 -3
  73. package/lib/factory/registerShippingDelivery.d.ts +2 -2
  74. package/lib/factory/registerShippingDelivery.js +12 -3
  75. package/lib/factory/registerVirtualWarehousing.d.ts +2 -2
  76. package/lib/factory/registerVirtualWarehousing.js +12 -3
  77. package/lib/factory/registerWorker.d.ts +2 -1
  78. package/lib/factory/registerWorker.js +12 -3
  79. package/lib/plugins/PluginRegistry.d.ts +42 -0
  80. package/lib/plugins/PluginRegistry.js +113 -0
  81. package/lib/services/addCartDiscount.d.ts +10 -0
  82. package/lib/services/addCartDiscount.js +27 -0
  83. package/lib/services/addCartItem.d.ts +15 -0
  84. package/lib/services/addCartItem.js +41 -0
  85. package/lib/services/addCartQuotation.d.ts +16 -0
  86. package/lib/services/addCartQuotation.js +52 -0
  87. package/lib/services/addEmail.d.ts +7 -0
  88. package/lib/services/addEmail.js +17 -0
  89. package/lib/services/addProductAssignment.d.ts +3 -0
  90. package/lib/services/addProductAssignment.js +63 -0
  91. package/lib/services/authenticateWithPassword.d.ts +15 -0
  92. package/lib/services/authenticateWithPassword.js +34 -0
  93. package/lib/services/changePassword.d.ts +10 -0
  94. package/lib/services/changePassword.js +19 -0
  95. package/lib/services/countOrdersWithFilters.d.ts +3 -0
  96. package/lib/services/countOrdersWithFilters.js +25 -0
  97. package/lib/services/createAssortment.d.ts +7 -0
  98. package/lib/services/createAssortment.js +10 -0
  99. package/lib/services/createBookmark.d.ts +8 -0
  100. package/lib/services/createBookmark.js +21 -0
  101. package/lib/services/createDeliveryProvider.d.ts +6 -0
  102. package/lib/services/createDeliveryProvider.js +19 -0
  103. package/lib/services/createDownloadStream.js +1 -1
  104. package/lib/services/createEnrollment.d.ts +17 -0
  105. package/lib/services/createEnrollment.js +33 -0
  106. package/lib/services/createFileDownloadURL.js +2 -1
  107. package/lib/services/createProduct.d.ts +7 -0
  108. package/lib/services/createProduct.js +8 -0
  109. package/lib/services/createProductBundleItem.d.ts +5 -0
  110. package/lib/services/createProductBundleItem.js +25 -0
  111. package/lib/services/createProductReview.d.ts +8 -0
  112. package/lib/services/createProductReview.js +12 -0
  113. package/lib/services/createSignedURL.js +2 -1
  114. package/lib/services/deliverOrder.d.ts +5 -0
  115. package/lib/services/deliverOrder.js +26 -0
  116. package/lib/services/findActiveWorkTypes.d.ts +2 -0
  117. package/lib/services/findActiveWorkTypes.js +6 -0
  118. package/lib/services/findDeliveryInterfaces.d.ts +7 -0
  119. package/lib/services/findDeliveryInterfaces.js +13 -0
  120. package/lib/services/findOrdersWithFilters.d.ts +9 -0
  121. package/lib/services/findOrdersWithFilters.js +25 -0
  122. package/lib/services/findPaymentInterfaces.d.ts +7 -0
  123. package/lib/services/findPaymentInterfaces.js +13 -0
  124. package/lib/services/findWarehousingInterfaces.d.ts +7 -0
  125. package/lib/services/findWarehousingInterfaces.js +13 -0
  126. package/lib/services/getDeliveryDiscounts.d.ts +8 -0
  127. package/lib/services/getDeliveryDiscounts.js +14 -0
  128. package/lib/services/getPaymentDiscounts.d.ts +8 -0
  129. package/lib/services/getPaymentDiscounts.js +14 -0
  130. package/lib/services/getShopInfo.d.ts +25 -0
  131. package/lib/services/getShopInfo.js +47 -0
  132. package/lib/services/impersonateUser.d.ts +8 -0
  133. package/lib/services/impersonateUser.js +20 -0
  134. package/lib/services/linkFileService.js +1 -1
  135. package/lib/services/loginAsGuest.d.ts +10 -0
  136. package/lib/services/loginAsGuest.js +19 -0
  137. package/lib/services/obfuscateWorkerData.d.ts +4 -0
  138. package/lib/services/obfuscateWorkerData.js +4 -0
  139. package/lib/services/orderPricingAccessors.d.ts +18 -0
  140. package/lib/services/orderPricingAccessors.js +29 -0
  141. package/lib/services/payOrder.d.ts +5 -0
  142. package/lib/services/payOrder.js +25 -0
  143. package/lib/services/registerUser.d.ts +14 -0
  144. package/lib/services/registerUser.js +44 -0
  145. package/lib/services/removeBookmark.d.ts +6 -0
  146. package/lib/services/removeBookmark.js +10 -0
  147. package/lib/services/removeCartItem.d.ts +6 -0
  148. package/lib/services/removeCartItem.js +19 -0
  149. package/lib/services/removeFiles.js +1 -1
  150. package/lib/services/resetPasswordWithMigration.d.ts +14 -0
  151. package/lib/services/resetPasswordWithMigration.js +31 -0
  152. package/lib/services/resolveWorkType.d.ts +1 -0
  153. package/lib/services/resolveWorkType.js +7 -0
  154. package/lib/services/searchProductsWithAssortment.d.ts +19 -0
  155. package/lib/services/searchProductsWithAssortment.js +17 -0
  156. package/lib/services/toggleBookmark.d.ts +8 -0
  157. package/lib/services/toggleBookmark.js +33 -0
  158. package/lib/services/updateCart.d.ts +15 -0
  159. package/lib/services/updateCart.js +27 -0
  160. package/lib/services/updateCartItem.d.ts +11 -0
  161. package/lib/services/updateCartItem.js +37 -0
  162. package/lib/services/updateEnrollment.d.ts +13 -0
  163. package/lib/services/updateEnrollment.js +36 -0
  164. package/lib/services/uploadFileFromStream.js +2 -1
  165. package/lib/services/uploadFileFromURL.js +2 -1
  166. package/lib/services/verifyEmailWithMigration.d.ts +15 -0
  167. package/lib/services/verifyEmailWithMigration.js +23 -0
  168. package/lib/utils/getFileAdapter.d.ts +1 -0
  169. package/lib/utils/getFileAdapter.js +7 -0
  170. package/lib/utils/schedule.js +164 -28
  171. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ export * from './common.ts';
@@ -0,0 +1 @@
1
+ export * from "./common.js";
@@ -1,8 +1,9 @@
1
1
  import type { SearchQuery } from '@unchainedshop/core-filters';
2
+ import { type IPlugin } from '../core-index.ts';
2
3
  export default function registerAssortmentSearchFilter({ orderIndex, search, }: {
3
4
  orderIndex?: number;
4
5
  search: (params: SearchQuery & {
5
6
  queryString: string;
6
7
  locale: Intl.Locale;
7
8
  }) => Promise<string[]>;
8
- }): void;
9
+ }): IPlugin;
@@ -1,6 +1,7 @@
1
- import { FilterAdapter, FilterDirector } from "../core-index.js";
1
+ import { FilterAdapter } from "../core-index.js";
2
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
2
3
  export default function registerAssortmentSearchFilter({ orderIndex = 0, search, }) {
3
- FilterDirector.registerAdapter({
4
+ const adapter = {
4
5
  ...FilterAdapter,
5
6
  key: `shop.unchained.filters.assortment-search-${crypto.randomUUID()}`,
6
7
  label: 'Assortment Search Filter (auto-generated)',
@@ -19,5 +20,13 @@ export default function registerAssortmentSearchFilter({ orderIndex = 0, search,
19
20
  },
20
21
  };
21
22
  },
22
- });
23
+ };
24
+ const plugin = {
25
+ key: adapter.key,
26
+ label: adapter.label,
27
+ version: adapter.version,
28
+ adapters: [adapter],
29
+ };
30
+ pluginRegistry.register(plugin);
31
+ return plugin;
23
32
  }
@@ -1,8 +1,8 @@
1
1
  import type { PaymentConfiguration } from '@unchainedshop/core-payment';
2
- import { type PaymentContext, type PaymentChargeActionResult } from '../core-index.ts';
2
+ import { type PaymentContext, type PaymentChargeActionResult, type IPlugin } from '../core-index.ts';
3
3
  export default function registerInvoicePayment({ adapterId, active, payLaterAllowed, charge, }: {
4
4
  adapterId: string;
5
5
  active?: boolean;
6
6
  payLaterAllowed?: boolean;
7
7
  charge: false | ((configuration: PaymentConfiguration, context: PaymentContext) => Promise<PaymentChargeActionResult | false>);
8
- }): void;
8
+ }): IPlugin;
@@ -1,7 +1,8 @@
1
- import { PaymentAdapter, PaymentDirector, } from "../core-index.js";
1
+ import { PaymentAdapter, } from "../core-index.js";
2
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
2
3
  import { PaymentProviderType } from '@unchainedshop/core-payment';
3
4
  export default function registerInvoicePayment({ adapterId, active, payLaterAllowed, charge, }) {
4
- PaymentDirector.registerAdapter({
5
+ const adapter = {
5
6
  ...PaymentAdapter,
6
7
  key: `shop.unchained.payment.invoice-${adapterId}`,
7
8
  label: 'Invoice Payment: ' + adapterId,
@@ -27,5 +28,13 @@ export default function registerInvoicePayment({ adapterId, active, payLaterAllo
27
28
  },
28
29
  };
29
30
  },
30
- });
31
+ };
32
+ const plugin = {
33
+ key: adapter.key,
34
+ label: adapter.label,
35
+ version: adapter.version,
36
+ adapters: [adapter],
37
+ };
38
+ pluginRegistry.register(plugin);
39
+ return plugin;
31
40
  }
@@ -1,9 +1,9 @@
1
1
  import type { WarehousingConfiguration } from '@unchainedshop/core-warehousing';
2
- import { type WarehousingContext } from '../core-index.ts';
2
+ import { type WarehousingContext, type IPlugin } from '../core-index.ts';
3
3
  export default function registerPhysicalWarehousing({ adapterId, orderIndex, stock, productionTime, commissioningTime, }: {
4
4
  adapterId: string;
5
5
  orderIndex?: number;
6
6
  stock?: number | ((referenceDate: Date, configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<number>);
7
7
  productionTime?: number | ((quantityToProduct: number, configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<number>);
8
8
  commissioningTime?: number | ((quantity: number, configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<number>);
9
- }): void;
9
+ }): IPlugin;
@@ -1,7 +1,8 @@
1
1
  import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
2
- import { WarehousingAdapter, WarehousingDirector } from "../core-index.js";
2
+ import { WarehousingAdapter, } from "../core-index.js";
3
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
4
  export default function registerPhysicalWarehousing({ adapterId, orderIndex = 0, stock, productionTime, commissioningTime, }) {
4
- WarehousingDirector.registerAdapter({
5
+ const adapter = {
5
6
  ...WarehousingAdapter,
6
7
  key: 'shop.unchained.warehousing.physical.' + adapterId,
7
8
  label: 'Physical Warehousing: ' + adapterId,
@@ -49,5 +50,13 @@ export default function registerPhysicalWarehousing({ adapterId, orderIndex = 0,
49
50
  },
50
51
  };
51
52
  },
52
- });
53
+ };
54
+ const plugin = {
55
+ key: adapter.key,
56
+ label: adapter.label,
57
+ version: adapter.version,
58
+ adapters: [adapter],
59
+ };
60
+ pluginRegistry.register(plugin);
61
+ return plugin;
53
62
  }
@@ -1,5 +1,5 @@
1
1
  import { type DeliveryConfiguration, type DeliveryLocation } from '@unchainedshop/core-delivery';
2
- import { type DeliveryContext } from '../core-index.ts';
2
+ import { type DeliveryContext, type IPlugin } from '../core-index.ts';
3
3
  import type { Work } from '@unchainedshop/core-worker';
4
4
  export default function registerPickUpDelivery({ adapterId, locations, active, autoReleaseAllowed, estimatedDeliveryThroughput, send, }: {
5
5
  adapterId: string;
@@ -8,4 +8,4 @@ export default function registerPickUpDelivery({ adapterId, locations, active, a
8
8
  estimatedDeliveryThroughput?: (warehousingThroughputTime: number, context: DeliveryContext) => Promise<number | null>;
9
9
  send: boolean | ((configuration: DeliveryConfiguration, context: DeliveryContext) => Promise<boolean | Work>);
10
10
  locations: DeliveryLocation[] | ((context: DeliveryContext) => Promise<DeliveryLocation[]>);
11
- }): void;
11
+ }): IPlugin;
@@ -1,7 +1,8 @@
1
1
  import { DeliveryProviderType, } from '@unchainedshop/core-delivery';
2
- import { DeliveryAdapter, DeliveryDirector } from "../core-index.js";
2
+ import { DeliveryAdapter, } from "../core-index.js";
3
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
4
  export default function registerPickUpDelivery({ adapterId, locations, active, autoReleaseAllowed, estimatedDeliveryThroughput, send, }) {
4
- DeliveryDirector.registerAdapter({
5
+ const adapter = {
5
6
  ...DeliveryAdapter,
6
7
  key: `shop.unchained.delivery.pickup-${adapterId}`,
7
8
  label: 'PickUp Delivery: ' + adapterId,
@@ -41,5 +42,13 @@ export default function registerPickUpDelivery({ adapterId, locations, active, a
41
42
  },
42
43
  };
43
44
  },
44
- });
45
+ };
46
+ const plugin = {
47
+ key: adapter.key,
48
+ label: adapter.label,
49
+ version: adapter.version,
50
+ adapters: [adapter],
51
+ };
52
+ pluginRegistry.register(plugin);
53
+ return plugin;
45
54
  }
@@ -1,4 +1,5 @@
1
+ import { type IPlugin } from '../core-index.ts';
1
2
  export default function registerProductDiscoverabilityFilter({ orderIndex, hiddenTagValue, }: {
2
3
  orderIndex?: number;
3
4
  hiddenTagValue?: string;
4
- }): void;
5
+ }): IPlugin;
@@ -1,6 +1,7 @@
1
- import { FilterAdapter, FilterDirector } from "../core-index.js";
1
+ import { FilterAdapter } from "../core-index.js";
2
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
2
3
  export default function registerProductDiscoverabilityFilter({ orderIndex = 0, hiddenTagValue = 'hidden', }) {
3
- FilterDirector.registerAdapter({
4
+ const adapter = {
4
5
  ...FilterAdapter,
5
6
  key: `shop.unchained.filters.product-discoverability-${crypto.randomUUID()}`,
6
7
  label: 'Product Discoverability Filter (auto-generated)',
@@ -22,5 +23,13 @@ export default function registerProductDiscoverabilityFilter({ orderIndex = 0, h
22
23
  },
23
24
  };
24
25
  },
25
- });
26
+ };
27
+ const plugin = {
28
+ key: adapter.key,
29
+ label: adapter.label,
30
+ version: adapter.version,
31
+ adapters: [adapter],
32
+ };
33
+ pluginRegistry.register(plugin);
34
+ return plugin;
26
35
  }
@@ -1,8 +1,9 @@
1
1
  import type { SearchQuery } from '@unchainedshop/core-filters';
2
+ import { type IPlugin } from '../core-index.ts';
2
3
  export default function registerProductSearchFilter({ orderIndex, search, }: {
3
4
  orderIndex?: number;
4
5
  search: (params: SearchQuery & {
5
6
  queryString: string;
6
7
  locale: Intl.Locale;
7
8
  }) => Promise<string[]>;
8
- }): void;
9
+ }): IPlugin;
@@ -1,6 +1,7 @@
1
- import { FilterAdapter, FilterDirector } from "../core-index.js";
1
+ import { FilterAdapter } from "../core-index.js";
2
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
2
3
  export default function registerProductSearchFilter({ orderIndex = 0, search, }) {
3
- FilterDirector.registerAdapter({
4
+ const adapter = {
4
5
  ...FilterAdapter,
5
6
  key: `shop.unchained.filters.product-search-${crypto.randomUUID()}`,
6
7
  label: 'Product Search Filter (auto-generated)',
@@ -19,5 +20,13 @@ export default function registerProductSearchFilter({ orderIndex = 0, search, })
19
20
  },
20
21
  };
21
22
  },
22
- });
23
+ };
24
+ const plugin = {
25
+ key: adapter.key,
26
+ label: adapter.label,
27
+ version: adapter.version,
28
+ adapters: [adapter],
29
+ };
30
+ pluginRegistry.register(plugin);
31
+ return plugin;
23
32
  }
@@ -1,5 +1,5 @@
1
1
  import type { DeliveryConfiguration } from '@unchainedshop/core-delivery';
2
- import { type DeliveryContext } from '../core-index.ts';
2
+ import { type DeliveryContext, type IPlugin } from '../core-index.ts';
3
3
  import type { Work } from '@unchainedshop/core-worker';
4
4
  export default function registerShippingDelivery({ adapterId, active, autoReleaseAllowed, estimatedDeliveryThroughput, send, }: {
5
5
  adapterId: string;
@@ -7,4 +7,4 @@ export default function registerShippingDelivery({ adapterId, active, autoReleas
7
7
  autoReleaseAllowed?: boolean;
8
8
  estimatedDeliveryThroughput?: (warehousingThroughputTime: number, context: DeliveryContext) => Promise<number | null>;
9
9
  send: boolean | ((configuration: DeliveryConfiguration, context: DeliveryContext) => Promise<boolean | Work>);
10
- }): void;
10
+ }): IPlugin;
@@ -1,7 +1,8 @@
1
1
  import { DeliveryProviderType } from '@unchainedshop/core-delivery';
2
- import { DeliveryAdapter, DeliveryDirector } from "../core-index.js";
2
+ import { DeliveryAdapter, } from "../core-index.js";
3
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
4
  export default function registerShippingDelivery({ adapterId, active, autoReleaseAllowed, estimatedDeliveryThroughput, send, }) {
4
- DeliveryDirector.registerAdapter({
5
+ const adapter = {
5
6
  ...DeliveryAdapter,
6
7
  key: `shop.unchained.delivery.shipping-${adapterId}`,
7
8
  label: 'Shipping Delivery: ' + adapterId,
@@ -33,5 +34,13 @@ export default function registerShippingDelivery({ adapterId, active, autoReleas
33
34
  },
34
35
  };
35
36
  },
36
- });
37
+ };
38
+ const plugin = {
39
+ key: adapter.key,
40
+ label: adapter.label,
41
+ version: adapter.version,
42
+ adapters: [adapter],
43
+ };
44
+ pluginRegistry.register(plugin);
45
+ return plugin;
37
46
  }
@@ -1,5 +1,5 @@
1
1
  import { type TokenSurrogate, type WarehousingConfiguration } from '@unchainedshop/core-warehousing';
2
- import { type WarehousingContext } from '../core-index.ts';
2
+ import { type WarehousingContext, type IPlugin } from '../core-index.ts';
3
3
  export default function registerVirtualWarehousing<Metadata = Record<string, any>>({ adapterId, orderIndex, stock, tokenize, tokenMetadata, isInvalidateable, }: {
4
4
  adapterId: string;
5
5
  orderIndex?: number;
@@ -7,4 +7,4 @@ export default function registerVirtualWarehousing<Metadata = Record<string, any
7
7
  tokenize: (configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<Omit<TokenSurrogate, 'userId' | 'productId' | 'orderPositionId'>[]>;
8
8
  tokenMetadata?: (serialNumber: string, referenceDate: Date, configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<Metadata>;
9
9
  isInvalidateable?: (serialNumber: string, referenceDate: Date, configuration: WarehousingConfiguration, context: WarehousingContext) => Promise<boolean>;
10
- }): void;
10
+ }): IPlugin;
@@ -1,7 +1,8 @@
1
1
  import { WarehousingProviderType, } from '@unchainedshop/core-warehousing';
2
- import { WarehousingAdapter, WarehousingDirector } from "../core-index.js";
2
+ import { WarehousingAdapter, } from "../core-index.js";
3
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
4
  export default function registerVirtualWarehousing({ adapterId, orderIndex = 0, stock, tokenize, tokenMetadata, isInvalidateable, }) {
4
- WarehousingDirector.registerAdapter({
5
+ const adapter = {
5
6
  ...WarehousingAdapter,
6
7
  key: 'shop.unchained.warehousing.virtual.' + adapterId,
7
8
  label: 'Virtual Wareshousing: ' + adapterId,
@@ -46,5 +47,13 @@ export default function registerVirtualWarehousing({ adapterId, orderIndex = 0,
46
47
  },
47
48
  };
48
49
  },
49
- });
50
+ };
51
+ const plugin = {
52
+ key: adapter.key,
53
+ label: adapter.label,
54
+ version: adapter.version,
55
+ adapters: [adapter],
56
+ };
57
+ pluginRegistry.register(plugin);
58
+ return plugin;
50
59
  }
@@ -1,6 +1,7 @@
1
+ import { type IPlugin } from '../core-index.ts';
1
2
  export default function registerWorker<Input = any, Result = any>({ type, external, maxParallelAllocations, process, }: {
2
3
  type: string;
3
4
  external?: boolean;
4
5
  maxParallelAllocations?: number;
5
6
  process?: (input: Input, workId: string) => Promise<Result>;
6
- }): void;
7
+ }): IPlugin;
@@ -1,6 +1,7 @@
1
- import { WorkerAdapter, WorkerDirector } from "../core-index.js";
1
+ import { WorkerAdapter } from "../core-index.js";
2
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
2
3
  export default function registerWorker({ type, external, maxParallelAllocations, process, }) {
3
- WorkerDirector.registerAdapter({
4
+ const adapter = {
4
5
  ...WorkerAdapter,
5
6
  key: 'shop.unchained.worker.' + type.toLowerCase(),
6
7
  label: 'Worker: ' + type,
@@ -30,5 +31,13 @@ export default function registerWorker({ type, external, maxParallelAllocations,
30
31
  };
31
32
  }
32
33
  },
33
- });
34
+ };
35
+ const plugin = {
36
+ key: adapter.key,
37
+ label: adapter.label,
38
+ version: adapter.version,
39
+ adapters: [adapter],
40
+ };
41
+ pluginRegistry.register(plugin);
42
+ return plugin;
34
43
  }
@@ -0,0 +1,42 @@
1
+ import type { UnchainedCore } from '../core-index.ts';
2
+ import type { IBaseAdapter } from '@unchainedshop/utils';
3
+ import type { mongodb } from '@unchainedshop/mongodb';
4
+ export interface PluginHttpRoute {
5
+ path: string;
6
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'OPTIONS' | 'ALL';
7
+ handler: (request: Request, context: UnchainedCore & {
8
+ params: Record<string, string>;
9
+ userId?: string;
10
+ impersonatorId?: string;
11
+ }) => Response | Promise<Response>;
12
+ }
13
+ export type PluginModuleFactory = (options: {
14
+ db: mongodb.Db;
15
+ }) => Record<string, any>;
16
+ export interface IPlugin {
17
+ key: string;
18
+ label: string;
19
+ version: string;
20
+ adapters?: IBaseAdapter[];
21
+ module?: PluginModuleFactory;
22
+ routes?: PluginHttpRoute[];
23
+ onRegister?: (unchainedAPI: UnchainedCore) => void | boolean | Promise<void | boolean>;
24
+ onShutdown?: (unchainedAPI: UnchainedCore) => void | Promise<void>;
25
+ }
26
+ declare class PluginRegistry {
27
+ private plugins;
28
+ private moduleFactories;
29
+ private skippedPlugins;
30
+ register(plugin: IPlugin): void;
31
+ initialize(unchainedAPI: UnchainedCore): Promise<void>;
32
+ getModuleFactories(): PluginModuleFactory[];
33
+ getRoutes(): PluginHttpRoute[];
34
+ shutdown(unchainedAPI: UnchainedCore): Promise<void>;
35
+ getPlugin(key: string): IPlugin | undefined;
36
+ getAllPlugins(): IPlugin[];
37
+ getAdapters(adapterType: symbol): IBaseAdapter[];
38
+ hasPlugin(key: string): boolean;
39
+ clear(): void;
40
+ }
41
+ export declare const pluginRegistry: PluginRegistry;
42
+ export {};
@@ -0,0 +1,113 @@
1
+ import { createLogger } from '@unchainedshop/logger';
2
+ const logger = createLogger('unchained:core');
3
+ class PluginRegistry {
4
+ plugins = new Map();
5
+ moduleFactories = [];
6
+ skippedPlugins = new Set();
7
+ register(plugin) {
8
+ if (this.plugins.has(plugin.key)) {
9
+ logger.warn(`Plugin ${plugin.key} already registered, skipping`, {
10
+ label: plugin.label,
11
+ });
12
+ return;
13
+ }
14
+ logger.info(`Registering plugin: ${plugin.label} (${plugin.key})`, {
15
+ version: plugin.version,
16
+ });
17
+ this.plugins.set(plugin.key, plugin);
18
+ if (plugin.module) {
19
+ this.moduleFactories.push(plugin.module);
20
+ }
21
+ }
22
+ async initialize(unchainedAPI) {
23
+ logger.info(`Initializing ${this.plugins.size} plugins`);
24
+ const skippedPlugins = new Set();
25
+ for (const plugin of this.plugins.values()) {
26
+ if (plugin.onRegister) {
27
+ try {
28
+ const result = await plugin.onRegister(unchainedAPI);
29
+ if (result === false) {
30
+ skippedPlugins.add(plugin.key);
31
+ logger.warn(`Plugin ${plugin.key} skipped adapter registration`, {
32
+ label: plugin.label,
33
+ });
34
+ }
35
+ else {
36
+ logger.debug(`Plugin ${plugin.key} initialized`, {
37
+ label: plugin.label,
38
+ });
39
+ }
40
+ }
41
+ catch (error) {
42
+ skippedPlugins.add(plugin.key);
43
+ const reason = error instanceof Error ? error.message : String(error);
44
+ logger.warn(`Plugin ${plugin.key} skipped adapter registration - ${reason}`, {
45
+ label: plugin.label,
46
+ });
47
+ }
48
+ }
49
+ }
50
+ this.skippedPlugins = skippedPlugins;
51
+ }
52
+ getModuleFactories() {
53
+ return this.moduleFactories;
54
+ }
55
+ getRoutes() {
56
+ const routes = [];
57
+ for (const plugin of this.plugins.values()) {
58
+ if (this.skippedPlugins.has(plugin.key)) {
59
+ continue;
60
+ }
61
+ if (plugin.routes) {
62
+ routes.push(...plugin.routes);
63
+ }
64
+ }
65
+ return routes;
66
+ }
67
+ async shutdown(unchainedAPI) {
68
+ logger.info('Shutting down plugins');
69
+ for (const plugin of this.plugins.values()) {
70
+ if (plugin.onShutdown) {
71
+ try {
72
+ await plugin.onShutdown(unchainedAPI);
73
+ logger.debug(`Plugin ${plugin.key} shutdown complete`, {
74
+ label: plugin.label,
75
+ });
76
+ }
77
+ catch (error) {
78
+ logger.error(`Error shutting down plugin ${plugin.key}`, {
79
+ error: error instanceof Error ? error.message : String(error),
80
+ });
81
+ }
82
+ }
83
+ }
84
+ }
85
+ getPlugin(key) {
86
+ return this.plugins.get(key);
87
+ }
88
+ getAllPlugins() {
89
+ return Array.from(this.plugins.values());
90
+ }
91
+ getAdapters(adapterType) {
92
+ const result = [];
93
+ for (const plugin of this.plugins.values()) {
94
+ if (!plugin.adapters)
95
+ continue;
96
+ for (const adapter of plugin.adapters) {
97
+ if (adapter.adapterType === adapterType) {
98
+ result.push(adapter);
99
+ }
100
+ }
101
+ }
102
+ return result;
103
+ }
104
+ hasPlugin(key) {
105
+ return this.plugins.has(key);
106
+ }
107
+ clear() {
108
+ this.plugins.clear();
109
+ this.moduleFactories = [];
110
+ this.skippedPlugins.clear();
111
+ }
112
+ }
113
+ export const pluginRegistry = new PluginRegistry();
@@ -0,0 +1,10 @@
1
+ import type { OrderDiscount } from '@unchainedshop/core-orders';
2
+ import type { Modules } from '../modules.ts';
3
+ import type { User } from '@unchainedshop/core-users';
4
+ export interface AddCartDiscountParams {
5
+ orderId?: string;
6
+ code: string;
7
+ user: User;
8
+ countryCode: string;
9
+ }
10
+ export declare function addCartDiscountService(this: Modules, params: AddCartDiscountParams): Promise<OrderDiscount>;
@@ -0,0 +1,27 @@
1
+ import { createManualOrderDiscountService } from "./createManualOrderDiscount.js";
2
+ import { updateCalculationService } from "./updateCalculation.js";
3
+ import { findOrInitCartService } from "./findOrInitCart.js";
4
+ import { OrderNotFoundError, OrderWrongStatusError, OrderDiscountCodeAlreadyPresentError, OrderDiscountCodeNotValidError, } from "../errors/index.js";
5
+ export async function addCartDiscountService(params) {
6
+ const { orderId, code, user, countryCode } = params;
7
+ const order = await findOrInitCartService.bind(this)({
8
+ orderId,
9
+ user,
10
+ countryCode,
11
+ });
12
+ if (!order) {
13
+ throw new OrderNotFoundError({ orderId: orderId || null });
14
+ }
15
+ if (!this.orders.isCart(order)) {
16
+ throw new OrderWrongStatusError({ status: order.status });
17
+ }
18
+ if (await this.orders.discounts.isDiscountCodeUsed({ code, orderId: order._id })) {
19
+ throw new OrderDiscountCodeAlreadyPresentError({ orderId: order._id, code });
20
+ }
21
+ const discount = await createManualOrderDiscountService.bind(this)({ order, code });
22
+ if (!discount) {
23
+ throw new OrderDiscountCodeNotValidError({ code });
24
+ }
25
+ await updateCalculationService.bind(this)(order._id);
26
+ return discount;
27
+ }
@@ -0,0 +1,15 @@
1
+ import { type OrderPosition } from '@unchainedshop/core-orders';
2
+ import type { User } from '@unchainedshop/core-users';
3
+ import type { Modules } from '../modules.ts';
4
+ export interface AddCartItemParams {
5
+ orderId?: string;
6
+ productId: string;
7
+ quantity: number;
8
+ configuration?: {
9
+ key: string;
10
+ value: string;
11
+ }[];
12
+ user: User;
13
+ countryCode: string;
14
+ }
15
+ export declare function addCartItemService(this: Modules, params: AddCartItemParams, context: any): Promise<OrderPosition>;
@@ -0,0 +1,41 @@
1
+ import { ordersSettings } from '@unchainedshop/core-orders';
2
+ import { findOrInitCartService } from "./findOrInitCart.js";
3
+ import { updateCalculationService } from "./updateCalculation.js";
4
+ import { ProductNotFoundError, OrderNotFoundError, OrderWrongStatusError, OrderQuantityTooLowError, } from "../errors/index.js";
5
+ export async function addCartItemService(params, context) {
6
+ const { orderId, productId: originalProductId, quantity, configuration, user, countryCode } = params;
7
+ if (quantity < 1) {
8
+ throw new OrderQuantityTooLowError({ quantity });
9
+ }
10
+ const originalProduct = await this.products.findProduct({ productId: originalProductId });
11
+ if (!originalProduct) {
12
+ throw new ProductNotFoundError({ productId: originalProductId });
13
+ }
14
+ const order = await findOrInitCartService.bind(this)({
15
+ orderId,
16
+ user,
17
+ countryCode,
18
+ });
19
+ if (!order) {
20
+ throw new OrderNotFoundError({ orderId });
21
+ }
22
+ if (!this.orders.isCart(order)) {
23
+ throw new OrderWrongStatusError({ status: order.status });
24
+ }
25
+ const product = await this.products.resolveOrderableProduct(originalProduct, { configuration });
26
+ await ordersSettings.validateOrderPosition({
27
+ order,
28
+ product,
29
+ configuration,
30
+ quantityDiff: quantity,
31
+ }, context);
32
+ const orderPosition = await this.orders.positions.addProductItem({
33
+ quantity,
34
+ configuration,
35
+ productId: product._id,
36
+ originalProductId,
37
+ orderId: order._id,
38
+ });
39
+ await updateCalculationService.bind(this)(order._id);
40
+ return (await this.orders.positions.findOrderPosition({ itemId: orderPosition._id }));
41
+ }
@@ -0,0 +1,16 @@
1
+ import type { OrderPosition } from '@unchainedshop/core-orders';
2
+ import type { User } from '@unchainedshop/core-users';
3
+ import type { Modules } from '../modules.ts';
4
+ export interface AddCartQuotationParams {
5
+ orderId?: string;
6
+ quotationId: string;
7
+ quantity: number;
8
+ configuration: {
9
+ key: string;
10
+ value: string;
11
+ }[];
12
+ user: User;
13
+ countryCode: string;
14
+ context: unknown;
15
+ }
16
+ export declare function addCartQuotationService(this: Modules, params: AddCartQuotationParams): Promise<OrderPosition>;