@unchainedshop/core 5.0.0-alpha.2 → 5.0.0-alpha.3

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 (67) hide show
  1. package/lib/bulk-exporter/handlers/exportProductsHandler.js +2 -2
  2. package/lib/bulk-importer/handlers/product/create.d.ts +18 -6
  3. package/lib/bulk-importer/handlers/product/create.js +5 -3
  4. package/lib/bulk-importer/handlers/product/update.d.ts +18 -6
  5. package/lib/bulk-importer/handlers/product/update.js +5 -2
  6. package/lib/directors/FilterDirector.js +23 -18
  7. package/lib/directors/WorkerDirector.js +1 -1
  8. package/lib/errors.d.ts +1 -0
  9. package/lib/errors.js +5 -0
  10. package/lib/factory/index.d.ts +12 -1
  11. package/lib/factory/index.js +12 -1
  12. package/lib/factory/registerAssortmentSearchFilter.d.ts +2 -1
  13. package/lib/factory/registerAssortmentSearchFilter.js +6 -3
  14. package/lib/factory/registerDeliveryPricing.d.ts +7 -0
  15. package/lib/factory/registerDeliveryPricing.js +30 -0
  16. package/lib/factory/registerDeliveryProvider.d.ts +12 -0
  17. package/lib/factory/registerDeliveryProvider.js +46 -0
  18. package/lib/factory/registerEnrollment.d.ts +18 -0
  19. package/lib/factory/registerEnrollment.js +43 -0
  20. package/lib/factory/registerFileAdapter.d.ts +17 -0
  21. package/lib/factory/registerFileAdapter.js +24 -0
  22. package/lib/factory/registerOrderDiscount.d.ts +13 -0
  23. package/lib/factory/registerOrderDiscount.js +39 -0
  24. package/lib/factory/registerOrderPricing.d.ts +7 -0
  25. package/lib/factory/registerOrderPricing.js +30 -0
  26. package/lib/factory/registerPaymentPricing.d.ts +7 -0
  27. package/lib/factory/registerPaymentPricing.js +30 -0
  28. package/lib/factory/registerPaymentProvider.d.ts +15 -0
  29. package/lib/factory/registerPaymentProvider.js +53 -0
  30. package/lib/factory/registerProductDiscount.d.ts +20 -0
  31. package/lib/factory/registerProductDiscount.js +47 -0
  32. package/lib/factory/registerProductDiscoverabilityFilter.d.ts +2 -1
  33. package/lib/factory/registerProductDiscoverabilityFilter.js +6 -3
  34. package/lib/factory/registerProductPricing.d.ts +7 -0
  35. package/lib/factory/registerProductPricing.js +30 -0
  36. package/lib/factory/registerProductSearchFilter.d.ts +2 -1
  37. package/lib/factory/registerProductSearchFilter.js +4 -3
  38. package/lib/factory/registerQuotation.d.ts +12 -0
  39. package/lib/factory/registerQuotation.js +52 -0
  40. package/lib/factory/registerWorker.js +1 -1
  41. package/lib/services/addMultipleCartProducts.js +3 -2
  42. package/lib/services/createFilter.d.ts +3 -0
  43. package/lib/services/createFilter.js +6 -0
  44. package/lib/services/createFilterOption.d.ts +5 -0
  45. package/lib/services/createFilterOption.js +8 -0
  46. package/lib/services/createSignedURL.js +2 -1
  47. package/lib/services/deleteCart.d.ts +2 -0
  48. package/lib/services/deleteCart.js +7 -0
  49. package/lib/services/deleteDeadCarts.d.ts +2 -0
  50. package/lib/services/deleteDeadCarts.js +17 -0
  51. package/lib/services/deleteUser.js +2 -5
  52. package/lib/services/index.d.ts +10 -0
  53. package/lib/services/index.js +10 -0
  54. package/lib/services/loadFilterOptions.js +3 -3
  55. package/lib/services/processEnrollment.js +2 -1
  56. package/lib/services/processOrder.js +3 -2
  57. package/lib/services/processQuotation.js +11 -13
  58. package/lib/services/proposeQuotation.js +3 -0
  59. package/lib/services/removeFilterOption.d.ts +6 -0
  60. package/lib/services/removeFilterOption.js +8 -0
  61. package/lib/services/removeProduct.js +2 -1
  62. package/lib/services/updateCalculation.js +2 -1
  63. package/lib/services/updateFilter.d.ts +3 -0
  64. package/lib/services/updateFilter.js +8 -0
  65. package/lib/services/uploadFileFromStream.js +2 -1
  66. package/lib/services/validateOrder.js +7 -8
  67. package/package.json +6 -3
@@ -0,0 +1,30 @@
1
+ import { OrderPricingAdapter, } from "../core-index.js";
2
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
+ export default function registerOrderPricing({ adapterId, orderIndex, isActivatedFor, calculate, }) {
4
+ const adapter = {
5
+ ...OrderPricingAdapter,
6
+ key: `shop.unchained.pricing.order-${adapterId}`,
7
+ label: 'Order Pricing: ' + adapterId,
8
+ version: '1.0.0',
9
+ orderIndex: orderIndex ?? 0,
10
+ isActivatedFor: (context) => (isActivatedFor ? isActivatedFor(context) : true),
11
+ actions: (params) => {
12
+ const pricingAdapter = OrderPricingAdapter.actions(params);
13
+ return {
14
+ ...pricingAdapter,
15
+ calculate: async () => {
16
+ await calculate(pricingAdapter.resultSheet(), params.context);
17
+ return pricingAdapter.calculate();
18
+ },
19
+ };
20
+ },
21
+ };
22
+ const plugin = {
23
+ key: adapter.key,
24
+ label: adapter.label,
25
+ version: adapter.version,
26
+ adapters: [adapter],
27
+ };
28
+ pluginRegistry.register(plugin);
29
+ return plugin;
30
+ }
@@ -0,0 +1,7 @@
1
+ import { type IPlugin, type IPaymentPricingSheet, type PaymentPricingAdapterContext } from '../core-index.ts';
2
+ export default function registerPaymentPricing({ adapterId, orderIndex, isActivatedFor, calculate, }: {
3
+ adapterId: string;
4
+ orderIndex?: number;
5
+ isActivatedFor?: (context: PaymentPricingAdapterContext) => boolean;
6
+ calculate: (sheet: IPaymentPricingSheet, context: PaymentPricingAdapterContext) => Promise<void>;
7
+ }): IPlugin;
@@ -0,0 +1,30 @@
1
+ import { PaymentPricingAdapter, } from "../core-index.js";
2
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
+ export default function registerPaymentPricing({ adapterId, orderIndex, isActivatedFor, calculate, }) {
4
+ const adapter = {
5
+ ...PaymentPricingAdapter,
6
+ key: `shop.unchained.pricing.payment-${adapterId}`,
7
+ label: 'Payment Pricing: ' + adapterId,
8
+ version: '1.0.0',
9
+ orderIndex: orderIndex ?? 0,
10
+ isActivatedFor: (context) => (isActivatedFor ? isActivatedFor(context) : true),
11
+ actions: (params) => {
12
+ const pricingAdapter = PaymentPricingAdapter.actions(params);
13
+ return {
14
+ ...pricingAdapter,
15
+ calculate: async () => {
16
+ await calculate(pricingAdapter.resultSheet(), params.context);
17
+ return pricingAdapter.calculate();
18
+ },
19
+ };
20
+ },
21
+ };
22
+ const plugin = {
23
+ key: adapter.key,
24
+ label: adapter.label,
25
+ version: adapter.version,
26
+ adapters: [adapter],
27
+ };
28
+ pluginRegistry.register(plugin);
29
+ return plugin;
30
+ }
@@ -0,0 +1,15 @@
1
+ import type { PaymentConfiguration } from '@unchainedshop/core-payment';
2
+ import { PaymentProviderType } from '@unchainedshop/core-payment';
3
+ import { type PaymentContext, type PaymentChargeActionResult, type PaymentError, type IPlugin } from '../core-index.ts';
4
+ export default function registerPaymentProvider({ adapterId, type, charge, sign, validate, isActive, isPayLaterAllowed, configurationError, cancel, confirm, }: {
5
+ adapterId: string;
6
+ type?: PaymentProviderType;
7
+ charge: false | ((configuration: PaymentConfiguration, context: PaymentContext) => Promise<PaymentChargeActionResult | false>);
8
+ sign?: (configuration: PaymentConfiguration, context: PaymentContext) => Promise<string | null>;
9
+ validate?: (configuration: PaymentConfiguration, context: PaymentContext) => Promise<boolean>;
10
+ isActive?: boolean;
11
+ isPayLaterAllowed?: boolean;
12
+ configurationError?: PaymentError | null;
13
+ cancel?: (configuration: PaymentConfiguration, context: PaymentContext) => Promise<boolean>;
14
+ confirm?: (configuration: PaymentConfiguration, context: PaymentContext) => Promise<boolean>;
15
+ }): IPlugin;
@@ -0,0 +1,53 @@
1
+ import { PaymentProviderType } from '@unchainedshop/core-payment';
2
+ import { PaymentAdapter, } from "../core-index.js";
3
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
4
+ export default function registerPaymentProvider({ adapterId, type, charge, sign, validate, isActive, isPayLaterAllowed, configurationError, cancel, confirm, }) {
5
+ const providerType = type ?? PaymentProviderType.GENERIC;
6
+ const adapter = {
7
+ ...PaymentAdapter,
8
+ key: `shop.unchained.payment.${adapterId}`,
9
+ label: 'Payment: ' + adapterId,
10
+ version: '1.0.0',
11
+ initialConfiguration: [],
12
+ typeSupported: (t) => {
13
+ return t === providerType;
14
+ },
15
+ actions: (config, context) => {
16
+ return {
17
+ ...PaymentAdapter.actions(config, context),
18
+ isActive: () => {
19
+ return isActive ?? true;
20
+ },
21
+ isPayLaterAllowed: () => {
22
+ return isPayLaterAllowed ?? false;
23
+ },
24
+ configurationError: () => {
25
+ return configurationError ?? null;
26
+ },
27
+ sign: async () => {
28
+ return sign ? sign(config, context) : null;
29
+ },
30
+ validate: async () => {
31
+ return validate ? validate(config, context) : false;
32
+ },
33
+ cancel: async () => {
34
+ return cancel ? cancel(config, context) : false;
35
+ },
36
+ confirm: async () => {
37
+ return confirm ? confirm(config, context) : false;
38
+ },
39
+ charge: async () => {
40
+ return typeof charge === 'function' ? await charge(config, context) : charge;
41
+ },
42
+ };
43
+ },
44
+ };
45
+ const plugin = {
46
+ key: adapter.key,
47
+ label: adapter.label,
48
+ version: adapter.version,
49
+ adapters: [adapter],
50
+ };
51
+ pluginRegistry.register(plugin);
52
+ return plugin;
53
+ }
@@ -0,0 +1,20 @@
1
+ import { type IPlugin, type IPricingSheet, type ProductDiscountConfiguration } from '../core-index.ts';
2
+ import type { PricingCalculation } from '@unchainedshop/utils';
3
+ export default function registerProductDiscount({ adapterId, orderIndex, isManualAdditionAllowed, isManualRemovalAllowed, isValidForSystemTriggering, isValidForCodeTriggering, discountForPricingAdapterKey, reserve, release, }: {
4
+ adapterId: string;
5
+ orderIndex?: number;
6
+ isManualAdditionAllowed?: (code?: string) => Promise<boolean>;
7
+ isManualRemovalAllowed?: () => Promise<boolean>;
8
+ isValidForSystemTriggering?: () => Promise<boolean>;
9
+ isValidForCodeTriggering?: (params: {
10
+ code: string;
11
+ }) => Promise<boolean>;
12
+ discountForPricingAdapterKey: (params: {
13
+ pricingAdapterKey: string;
14
+ calculationSheet: IPricingSheet<PricingCalculation>;
15
+ }) => ProductDiscountConfiguration | null;
16
+ reserve?: (params: {
17
+ code?: string;
18
+ }) => Promise<any>;
19
+ release?: () => Promise<void>;
20
+ }): IPlugin;
@@ -0,0 +1,47 @@
1
+ import { ProductDiscountAdapter, } from "../core-index.js";
2
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
+ export default function registerProductDiscount({ adapterId, orderIndex, isManualAdditionAllowed, isManualRemovalAllowed, isValidForSystemTriggering, isValidForCodeTriggering, discountForPricingAdapterKey, reserve, release, }) {
4
+ const adapter = {
5
+ ...ProductDiscountAdapter,
6
+ key: `shop.unchained.discount.product-${adapterId}`,
7
+ label: 'Product Discount: ' + adapterId,
8
+ version: '1.0.0',
9
+ orderIndex: orderIndex ?? 0,
10
+ isManualAdditionAllowed: async (code) => {
11
+ return isManualAdditionAllowed
12
+ ? isManualAdditionAllowed(code)
13
+ : ProductDiscountAdapter.isManualAdditionAllowed(code);
14
+ },
15
+ isManualRemovalAllowed: async () => {
16
+ return isManualRemovalAllowed
17
+ ? isManualRemovalAllowed()
18
+ : ProductDiscountAdapter.isManualRemovalAllowed();
19
+ },
20
+ actions: async (params) => {
21
+ return {
22
+ ...(await ProductDiscountAdapter.actions(params)),
23
+ isValidForSystemTriggering: async () => {
24
+ return isValidForSystemTriggering ? isValidForSystemTriggering() : false;
25
+ },
26
+ isValidForCodeTriggering: async ({ code }) => {
27
+ return isValidForCodeTriggering ? isValidForCodeTriggering({ code }) : false;
28
+ },
29
+ discountForPricingAdapterKey,
30
+ reserve: async ({ code }) => {
31
+ return reserve ? reserve({ code }) : {};
32
+ },
33
+ release: async () => {
34
+ return release ? release() : undefined;
35
+ },
36
+ };
37
+ },
38
+ };
39
+ const plugin = {
40
+ key: adapter.key,
41
+ label: adapter.label,
42
+ version: adapter.version,
43
+ adapters: [adapter],
44
+ };
45
+ pluginRegistry.register(plugin);
46
+ return plugin;
47
+ }
@@ -1,5 +1,6 @@
1
1
  import { type IPlugin } from '../core-index.ts';
2
- export default function registerProductDiscoverabilityFilter({ orderIndex, hiddenTagValue, }: {
2
+ export default function registerProductDiscoverabilityFilter({ adapterId, orderIndex, hiddenTagValue, }: {
3
+ adapterId?: string;
3
4
  orderIndex?: number;
4
5
  hiddenTagValue?: string;
5
6
  }): IPlugin;
@@ -1,10 +1,13 @@
1
1
  import { FilterAdapter } from "../core-index.js";
2
2
  import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
- export default function registerProductDiscoverabilityFilter({ orderIndex = 0, hiddenTagValue = 'hidden', }) {
3
+ export default function registerProductDiscoverabilityFilter({ adapterId, orderIndex = 0, hiddenTagValue = 'hidden', }) {
4
+ const id = adapterId ?? crypto.randomUUID();
4
5
  const adapter = {
5
6
  ...FilterAdapter,
6
- key: `shop.unchained.filters.product-discoverability-${crypto.randomUUID()}`,
7
- label: 'Product Discoverability Filter (auto-generated)',
7
+ key: `shop.unchained.filters.product-discoverability-${id}`,
8
+ label: adapterId
9
+ ? `Product Discoverability Filter: ${adapterId}`
10
+ : 'Product Discoverability Filter (auto-generated)',
8
11
  version: '1.0.0',
9
12
  orderIndex,
10
13
  actions: (params) => {
@@ -0,0 +1,7 @@
1
+ import { type IPlugin, type IProductPricingSheet, type ProductPricingAdapterContext } from '../core-index.ts';
2
+ export default function registerProductPricing({ adapterId, orderIndex, isActivatedFor, calculate, }: {
3
+ adapterId: string;
4
+ orderIndex?: number;
5
+ isActivatedFor?: (context: ProductPricingAdapterContext) => boolean;
6
+ calculate: (sheet: IProductPricingSheet, context: ProductPricingAdapterContext) => Promise<void>;
7
+ }): IPlugin;
@@ -0,0 +1,30 @@
1
+ import { ProductPricingAdapter, } from "../core-index.js";
2
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
+ export default function registerProductPricing({ adapterId, orderIndex, isActivatedFor, calculate, }) {
4
+ const adapter = {
5
+ ...ProductPricingAdapter,
6
+ key: `shop.unchained.pricing.product-${adapterId}`,
7
+ label: 'Product Pricing: ' + adapterId,
8
+ version: '1.0.0',
9
+ orderIndex: orderIndex ?? 0,
10
+ isActivatedFor: (context) => (isActivatedFor ? isActivatedFor(context) : true),
11
+ actions: (params) => {
12
+ const pricingAdapter = ProductPricingAdapter.actions(params);
13
+ return {
14
+ ...pricingAdapter,
15
+ calculate: async () => {
16
+ await calculate(pricingAdapter.resultSheet(), params.context);
17
+ return pricingAdapter.calculate();
18
+ },
19
+ };
20
+ },
21
+ };
22
+ const plugin = {
23
+ key: adapter.key,
24
+ label: adapter.label,
25
+ version: adapter.version,
26
+ adapters: [adapter],
27
+ };
28
+ pluginRegistry.register(plugin);
29
+ return plugin;
30
+ }
@@ -1,6 +1,7 @@
1
1
  import type { SearchQuery } from '@unchainedshop/core-filters';
2
2
  import { type IPlugin } from '../core-index.ts';
3
- export default function registerProductSearchFilter({ orderIndex, search, }: {
3
+ export default function registerProductSearchFilter({ adapterId, orderIndex, search, }: {
4
+ adapterId?: string;
4
5
  orderIndex?: number;
5
6
  search: (params: SearchQuery & {
6
7
  queryString: string;
@@ -1,10 +1,11 @@
1
1
  import { FilterAdapter } from "../core-index.js";
2
2
  import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
- export default function registerProductSearchFilter({ orderIndex = 0, search, }) {
3
+ export default function registerProductSearchFilter({ adapterId, orderIndex = 0, search, }) {
4
+ const id = adapterId ?? crypto.randomUUID();
4
5
  const adapter = {
5
6
  ...FilterAdapter,
6
- key: `shop.unchained.filters.product-search-${crypto.randomUUID()}`,
7
- label: 'Product Search Filter (auto-generated)',
7
+ key: `shop.unchained.filters.product-search-${id}`,
8
+ label: adapterId ? `Product Search Filter: ${adapterId}` : 'Product Search Filter (auto-generated)',
8
9
  version: '1.0.0',
9
10
  orderIndex,
10
11
  actions: (params) => {
@@ -0,0 +1,12 @@
1
+ import type { QuotationItemConfiguration, QuotationProposal } from '@unchainedshop/core-quotations';
2
+ import { type QuotationContext, type IPlugin } from '../core-index.ts';
3
+ export default function registerQuotation({ adapterId, isManualRequestVerificationRequired, isManualProposalRequired, quote, submitRequest, verifyRequest, rejectRequest, transformItemConfiguration, }: {
4
+ adapterId: string;
5
+ isManualRequestVerificationRequired?: boolean;
6
+ isManualProposalRequired?: boolean;
7
+ quote?: (context: QuotationContext) => Promise<QuotationProposal>;
8
+ submitRequest?: (context: QuotationContext) => Promise<boolean>;
9
+ verifyRequest?: (context: QuotationContext) => Promise<boolean>;
10
+ rejectRequest?: (context: QuotationContext) => Promise<boolean>;
11
+ transformItemConfiguration?: (params: QuotationItemConfiguration, context: QuotationContext) => Promise<QuotationItemConfiguration | null>;
12
+ }): IPlugin;
@@ -0,0 +1,52 @@
1
+ import { QuotationAdapter, } from "../core-index.js";
2
+ import { pluginRegistry } from "../plugins/PluginRegistry.js";
3
+ export default function registerQuotation({ adapterId, isManualRequestVerificationRequired, isManualProposalRequired, quote, submitRequest, verifyRequest, rejectRequest, transformItemConfiguration, }) {
4
+ const adapter = {
5
+ ...QuotationAdapter,
6
+ key: `shop.unchained.quotation.${adapterId}`,
7
+ label: 'Quotation: ' + adapterId,
8
+ version: '1.0.0',
9
+ isActivatedFor: () => {
10
+ return true;
11
+ },
12
+ actions: (context) => {
13
+ return {
14
+ ...QuotationAdapter.actions(context),
15
+ configurationError: () => {
16
+ return null;
17
+ },
18
+ isManualRequestVerificationRequired: async () => {
19
+ return isManualRequestVerificationRequired ?? true;
20
+ },
21
+ isManualProposalRequired: async () => {
22
+ return isManualProposalRequired ?? true;
23
+ },
24
+ quote: async () => {
25
+ return quote ? quote(context) : {};
26
+ },
27
+ submitRequest: async () => {
28
+ return submitRequest ? submitRequest(context) : true;
29
+ },
30
+ verifyRequest: async () => {
31
+ return verifyRequest ? verifyRequest(context) : true;
32
+ },
33
+ rejectRequest: async () => {
34
+ return rejectRequest ? rejectRequest(context) : true;
35
+ },
36
+ transformItemConfiguration: async (params) => {
37
+ return transformItemConfiguration
38
+ ? transformItemConfiguration(params, context)
39
+ : { quantity: params.quantity, configuration: params.configuration };
40
+ },
41
+ };
42
+ },
43
+ };
44
+ const plugin = {
45
+ key: adapter.key,
46
+ label: adapter.label,
47
+ version: adapter.version,
48
+ adapters: [adapter],
49
+ };
50
+ pluginRegistry.register(plugin);
51
+ return plugin;
52
+ }
@@ -5,7 +5,7 @@ export default function registerWorker({ type, external, maxParallelAllocations,
5
5
  ...WorkerAdapter,
6
6
  key: 'shop.unchained.worker.' + type.toLowerCase(),
7
7
  label: 'Worker: ' + type,
8
- version: '1.0',
8
+ version: '1.0.0',
9
9
  external: external ?? false,
10
10
  maxParallelAllocations,
11
11
  type,
@@ -1,4 +1,5 @@
1
1
  import { ordersSettings } from '@unchainedshop/core-orders';
2
+ import { createServiceError } from "../errors.js";
2
3
  export async function addMultipleCartProductsService({ orderId, items, context, }) {
3
4
  const order = await this.orders.findOrder({ orderId });
4
5
  if (!order)
@@ -6,10 +7,10 @@ export async function addMultipleCartProductsService({ orderId, items, context,
6
7
  for (const { productId, quantity, configuration } of items) {
7
8
  const originalProduct = await this.products.findProduct({ productId });
8
9
  if (!originalProduct) {
9
- throw new Error(`Product not found: ${productId}`);
10
+ throw createServiceError('ProductNotFoundError', `Product not found: ${productId}`);
10
11
  }
11
12
  if (quantity < 1) {
12
- throw new Error(`Invalid quantity for product: ${productId}`);
13
+ throw createServiceError('InvalidQuantityError', `Invalid quantity for product: ${productId}`);
13
14
  }
14
15
  const product = await this.products.resolveOrderableProduct(originalProduct, { configuration });
15
16
  await ordersSettings.validateOrderPosition({ order, product, configuration, quantityDiff: quantity }, { modules: this, ...context });
@@ -0,0 +1,3 @@
1
+ import type { Filter } from '@unchainedshop/core-filters';
2
+ import type { Modules } from '../modules.ts';
3
+ export declare function createFilterService(this: Modules, filter: Parameters<Modules['filters']['create']>[0]): Promise<Filter>;
@@ -0,0 +1,6 @@
1
+ import { FilterDirector } from "../core-index.js";
2
+ export async function createFilterService(filter) {
3
+ const newFilter = await this.filters.create(filter);
4
+ await FilterDirector.invalidateProductIdCache(newFilter, { modules: this });
5
+ return newFilter;
6
+ }
@@ -0,0 +1,5 @@
1
+ import type { Filter } from '@unchainedshop/core-filters';
2
+ import type { Modules } from '../modules.ts';
3
+ export declare function createFilterOptionService(this: Modules, filterId: string, { value }: {
4
+ value: string;
5
+ }): Promise<Filter | null>;
@@ -0,0 +1,8 @@
1
+ import { FilterDirector } from "../core-index.js";
2
+ export async function createFilterOptionService(filterId, { value }) {
3
+ const filter = await this.filters.createFilterOption(filterId, { value });
4
+ if (filter) {
5
+ await FilterDirector.invalidateProductIdCache(filter, { modules: this });
6
+ }
7
+ return filter;
8
+ }
@@ -1,12 +1,13 @@
1
1
  import { getFileFromFileData } from '@unchainedshop/core-files';
2
2
  import { getFileAdapter } from "../utils/getFileAdapter.js";
3
+ import { createServiceError } from "../errors.js";
3
4
  export async function createSignedURLService({ directoryName, fileName, meta }) {
4
5
  const fileUploadAdapter = getFileAdapter();
5
6
  const preparedFileData = await fileUploadAdapter.createSignedURL(directoryName, fileName, {
6
7
  modules: this,
7
8
  });
8
9
  if (!preparedFileData)
9
- throw new Error('Could not prepare signed URL');
10
+ throw createServiceError('SignedURLPreparationError', 'Could not prepare signed URL');
10
11
  const fileData = getFileFromFileData(preparedFileData, meta);
11
12
  const fileId = await this.files.create(fileData);
12
13
  const file = await this.files.findFile({ fileId });
@@ -0,0 +1,2 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export declare function deleteCartService(this: Modules, orderId: string): Promise<number>;
@@ -0,0 +1,7 @@
1
+ export async function deleteCartService(orderId) {
2
+ await this.orders.positions.deleteOrderPositions(orderId);
3
+ await this.orders.payments.deleteOrderPayments(orderId);
4
+ await this.orders.deliveries.deleteOrderDeliveries(orderId);
5
+ await this.orders.discounts.deleteOrderDiscounts(orderId);
6
+ return this.orders.delete(orderId);
7
+ }
@@ -0,0 +1,2 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export declare function deleteDeadCartsService(this: Modules): Promise<number>;
@@ -0,0 +1,17 @@
1
+ import { deleteCartService } from "./deleteCart.js";
2
+ export async function deleteDeadCartsService() {
3
+ const cartUserIds = (await this.orders.findCartUserIds()).filter(Boolean);
4
+ if (!cartUserIds.length)
5
+ return 0;
6
+ const existingUserIds = new Set(await this.users.findExistingUserIds({ userIds: cartUserIds }));
7
+ const deadUserIds = cartUserIds.filter((userId) => !existingUserIds.has(userId));
8
+ if (!deadUserIds.length)
9
+ return 0;
10
+ const deadCarts = await this.orders.findCarts({ userIds: deadUserIds }, { projection: { _id: 1 } });
11
+ let deletedCount = 0;
12
+ await Array.fromAsync(deadCarts, async (cart) => {
13
+ await deleteCartService.bind(this)(cart._id);
14
+ deletedCount += 1;
15
+ });
16
+ return deletedCount;
17
+ }
@@ -1,3 +1,4 @@
1
+ import { deleteCartService } from "./deleteCart.js";
1
2
  export async function deleteUserService({ userId }) {
2
3
  const user = await this.users.markDeleted(userId);
3
4
  if (!user)
@@ -11,11 +12,7 @@ export async function deleteUserService({ userId }) {
11
12
  }
12
13
  const carts = (await this.orders.findOrders({ userId, includeCarts: true })).filter((c) => c.status === null);
13
14
  await Array.fromAsync(carts, async (userCart) => {
14
- await this.orders.positions.deleteOrderPositions(userCart?._id);
15
- await this.orders.payments.deleteOrderPayments(userCart?._id);
16
- await this.orders.deliveries.deleteOrderDeliveries(userCart?._id);
17
- await this.orders.discounts.deleteOrderDiscounts(userCart?._id);
18
- await this.orders.delete(userCart?._id);
15
+ await deleteCartService.bind(this)(userCart._id);
19
16
  });
20
17
  const ordersCount = await this.orders.count({ userId, includeCarts: true });
21
18
  const quotationsCount = await this.quotations.count({ userId });
@@ -15,6 +15,7 @@ import { initCartProvidersService } from './initCartProviders.ts';
15
15
  import { updateCalculationService } from './updateCalculation.ts';
16
16
  import { supportedDeliveryProvidersService } from './supportedDeliveryProviders.ts';
17
17
  import { deleteUserService } from './deleteUser.ts';
18
+ import { deleteCartService } from './deleteCart.ts';
18
19
  import { supportedPaymentProvidersService } from './supportedPaymentProviders.ts';
19
20
  import { supportedWarehousingProvidersService } from './supportedWarehousingProviders.ts';
20
21
  import { createEnrollmentFromCheckoutService } from './createEnrollmentFromCheckout.ts';
@@ -40,6 +41,10 @@ import { verifyQuotationService } from './verifyQuotation.ts';
40
41
  import { loadFiltersService } from './loadFilters.ts';
41
42
  import { loadFilterOptionsService } from './loadFilterOptions.ts';
42
43
  import { removeFilterService } from './removeFilter.ts';
44
+ import { createFilterService } from './createFilter.ts';
45
+ import { updateFilterService } from './updateFilter.ts';
46
+ import { createFilterOptionService } from './createFilterOption.ts';
47
+ import { removeFilterOptionService } from './removeFilterOption.ts';
43
48
  import { removeCartDiscountService } from './removeCartDiscount.ts';
44
49
  import { addMultipleCartProductsService } from './addMultipleCartProducts.ts';
45
50
  import { ercMetadataService } from './ercMetadata.ts';
@@ -77,6 +82,7 @@ export default function initServices(modules: Modules, customServices?: CustomSe
77
82
  registerPaymentCredentials: Bound<typeof registerPaymentCredentialsService>;
78
83
  calculateDiscountTotal: Bound<typeof calculateDiscountTotalService>;
79
84
  migrateOrderCarts: Bound<typeof migrateOrderCartsService>;
85
+ deleteCart: Bound<typeof deleteCartService>;
80
86
  nextUserCart: Bound<typeof nextUserCartService>;
81
87
  findOrInitCart: Bound<typeof findOrInitCartService>;
82
88
  initCartProviders: Bound<typeof initCartProvidersService>;
@@ -129,6 +135,10 @@ export default function initServices(modules: Modules, customServices?: CustomSe
129
135
  loadFilters: Bound<typeof loadFiltersService>;
130
136
  loadFilterOptions: Bound<typeof loadFilterOptionsService>;
131
137
  removeFilter: Bound<typeof removeFilterService>;
138
+ createFilter: Bound<typeof createFilterService>;
139
+ updateFilter: Bound<typeof updateFilterService>;
140
+ createFilterOption: Bound<typeof createFilterOptionService>;
141
+ removeFilterOption: Bound<typeof removeFilterOptionService>;
132
142
  };
133
143
  warehousing: {
134
144
  ercMetadata: Bound<typeof ercMetadataService>;
@@ -14,6 +14,7 @@ import { initCartProvidersService } from "./initCartProviders.js";
14
14
  import { updateCalculationService } from "./updateCalculation.js";
15
15
  import { supportedDeliveryProvidersService } from "./supportedDeliveryProviders.js";
16
16
  import { deleteUserService } from "./deleteUser.js";
17
+ import { deleteCartService } from "./deleteCart.js";
17
18
  import { supportedPaymentProvidersService } from "./supportedPaymentProviders.js";
18
19
  import { supportedWarehousingProvidersService } from "./supportedWarehousingProviders.js";
19
20
  import { createEnrollmentFromCheckoutService } from "./createEnrollmentFromCheckout.js";
@@ -39,6 +40,10 @@ import { verifyQuotationService } from "./verifyQuotation.js";
39
40
  import { loadFiltersService } from "./loadFilters.js";
40
41
  import { loadFilterOptionsService } from "./loadFilterOptions.js";
41
42
  import { removeFilterService } from "./removeFilter.js";
43
+ import { createFilterService } from "./createFilter.js";
44
+ import { updateFilterService } from "./updateFilter.js";
45
+ import { createFilterOptionService } from "./createFilterOption.js";
46
+ import { removeFilterOptionService } from "./removeFilterOption.js";
42
47
  import { removeCartDiscountService } from "./removeCartDiscount.js";
43
48
  import { addMultipleCartProductsService } from "./addMultipleCartProducts.js";
44
49
  import { ercMetadataService } from "./ercMetadata.js";
@@ -88,6 +93,7 @@ export default function initServices(modules, customServices = {}) {
88
93
  registerPaymentCredentials: registerPaymentCredentialsService,
89
94
  calculateDiscountTotal: calculateDiscountTotalService,
90
95
  migrateOrderCarts: migrateOrderCartsService,
96
+ deleteCart: deleteCartService,
91
97
  nextUserCart: nextUserCartService,
92
98
  findOrInitCart: findOrInitCartService,
93
99
  initCartProviders: initCartProvidersService,
@@ -140,6 +146,10 @@ export default function initServices(modules, customServices = {}) {
140
146
  loadFilters: loadFiltersService,
141
147
  loadFilterOptions: loadFilterOptionsService,
142
148
  removeFilter: removeFilterService,
149
+ createFilter: createFilterService,
150
+ updateFilter: updateFilterService,
151
+ createFilterOption: createFilterOptionService,
152
+ removeFilterOption: removeFilterOptionService,
143
153
  },
144
154
  warehousing: {
145
155
  ercMetadata: ercMetadataService,
@@ -1,10 +1,10 @@
1
- import { FilterType } from '@unchainedshop/core-filters';
1
+ import { filterOptionValues } from '@unchainedshop/core-filters';
2
2
  import { FilterDirector, parseQueryArray } from "../directors/FilterDirector.js";
3
3
  export async function loadFilterOptionsService(filter, params) {
4
4
  const { forceLiveCollection, productIdSet, searchQuery } = params;
5
5
  const filterQueryParsed = parseQueryArray(searchQuery?.filterQuery);
6
6
  const values = filterQueryParsed[filter.key];
7
- const allOptions = (filter.type === FilterType.SWITCH && ['true', 'false']) || filter.options || [];
7
+ const allOptions = filterOptionValues(filter);
8
8
  const mappedOptions = await Promise.all(allOptions.map(async (value) => {
9
9
  const filterOptionProductIds = await FilterDirector.filterProductIds(filter, {
10
10
  values: [value],
@@ -12,7 +12,7 @@ export async function loadFilterOptionsService(filter, params) {
12
12
  }, { modules: this });
13
13
  const filteredProductIdSet = productIdSet.intersection(filterOptionProductIds);
14
14
  const normalizedValues = values && this.filters.parse(filter, values, [value]);
15
- const isSelected = normalizedValues && normalizedValues.indexOf(value) !== -1;
15
+ const isSelected = Boolean(normalizedValues && normalizedValues.indexOf(value) !== -1);
16
16
  if (!filteredProductIdSet.size && !isSelected) {
17
17
  return null;
18
18
  }
@@ -1,12 +1,13 @@
1
1
  import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
2
2
  import { EnrollmentDirector } from "../core-index.js";
3
+ import { createServiceError } from "../errors.js";
3
4
  const findNextStatus = async (enrollment, modules) => {
4
5
  let status = enrollment.status;
5
6
  const product = await modules.products.findProduct({
6
7
  productId: enrollment.productId,
7
8
  });
8
9
  if (!product)
9
- throw new Error('Product not found for enrollment');
10
+ throw createServiceError('ProductNotFoundError', 'Product not found for enrollment');
10
11
  const director = await EnrollmentDirector.actions({ enrollment, product }, { modules });
11
12
  if (status === EnrollmentStatus.INITIAL || status === EnrollmentStatus.PAUSED) {
12
13
  if (await director.isValidForActivation()) {