@unchainedshop/core 4.8.26 → 4.8.27

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 (129) hide show
  1. package/lib/bulk-importer/handlers/product/create.d.ts +3 -3
  2. package/lib/bulk-importer/handlers/product/create.js +1 -1
  3. package/lib/bulk-importer/handlers/product/update.d.ts +3 -3
  4. package/lib/bulk-importer/handlers/product/update.js +1 -1
  5. package/lib/directors/FileDirector.d.ts +10 -0
  6. package/lib/directors/FileDirector.js +25 -0
  7. package/lib/errors/common.d.ts +568 -0
  8. package/lib/errors/common.js +789 -0
  9. package/lib/errors/index.d.ts +1 -0
  10. package/lib/errors/index.js +1 -0
  11. package/lib/factory/registerDeliveryPricing.d.ts +7 -0
  12. package/lib/factory/registerDeliveryPricing.js +30 -0
  13. package/lib/factory/registerDeliveryProvider.d.ts +12 -0
  14. package/lib/factory/registerDeliveryProvider.js +46 -0
  15. package/lib/factory/registerEnrollment.d.ts +18 -0
  16. package/lib/factory/registerEnrollment.js +43 -0
  17. package/lib/factory/registerFileAdapter.d.ts +17 -0
  18. package/lib/factory/registerFileAdapter.js +24 -0
  19. package/lib/factory/registerOrderDiscount.d.ts +13 -0
  20. package/lib/factory/registerOrderDiscount.js +39 -0
  21. package/lib/factory/registerOrderPricing.d.ts +7 -0
  22. package/lib/factory/registerOrderPricing.js +30 -0
  23. package/lib/factory/registerPaymentPricing.d.ts +7 -0
  24. package/lib/factory/registerPaymentPricing.js +30 -0
  25. package/lib/factory/registerPaymentProvider.d.ts +15 -0
  26. package/lib/factory/registerPaymentProvider.js +53 -0
  27. package/lib/factory/registerProductDiscount.d.ts +20 -0
  28. package/lib/factory/registerProductDiscount.js +47 -0
  29. package/lib/factory/registerProductPricing.d.ts +7 -0
  30. package/lib/factory/registerProductPricing.js +30 -0
  31. package/lib/factory/registerQuotation.d.ts +12 -0
  32. package/lib/factory/registerQuotation.js +52 -0
  33. package/lib/plugins/PluginRegistry.d.ts +42 -0
  34. package/lib/plugins/PluginRegistry.js +115 -0
  35. package/lib/services/addCartDiscount.d.ts +10 -0
  36. package/lib/services/addCartDiscount.js +27 -0
  37. package/lib/services/addCartItem.d.ts +15 -0
  38. package/lib/services/addCartItem.js +41 -0
  39. package/lib/services/addCartQuotation.d.ts +16 -0
  40. package/lib/services/addCartQuotation.js +52 -0
  41. package/lib/services/addEmail.d.ts +7 -0
  42. package/lib/services/addEmail.js +17 -0
  43. package/lib/services/addProductAssignment.d.ts +3 -0
  44. package/lib/services/addProductAssignment.js +63 -0
  45. package/lib/services/authenticateWithPassword.d.ts +15 -0
  46. package/lib/services/authenticateWithPassword.js +34 -0
  47. package/lib/services/bulkAssignProductsToAssortment.d.ts +8 -0
  48. package/lib/services/bulkAssignProductsToAssortment.js +11 -0
  49. package/lib/services/bulkDeleteUsers.d.ts +7 -0
  50. package/lib/services/bulkDeleteUsers.js +11 -0
  51. package/lib/services/bulkRemoveFilters.d.ts +7 -0
  52. package/lib/services/bulkRemoveFilters.js +10 -0
  53. package/lib/services/bulkRemoveProducts.d.ts +7 -0
  54. package/lib/services/bulkRemoveProducts.js +23 -0
  55. package/lib/services/bulkSetFilterActive.d.ts +8 -0
  56. package/lib/services/bulkSetFilterActive.js +12 -0
  57. package/lib/services/changePassword.d.ts +10 -0
  58. package/lib/services/changePassword.js +19 -0
  59. package/lib/services/countOrdersWithFilters.d.ts +3 -0
  60. package/lib/services/countOrdersWithFilters.js +25 -0
  61. package/lib/services/createAssortment.d.ts +7 -0
  62. package/lib/services/createAssortment.js +10 -0
  63. package/lib/services/createBookmark.d.ts +8 -0
  64. package/lib/services/createBookmark.js +21 -0
  65. package/lib/services/createDeliveryProvider.d.ts +6 -0
  66. package/lib/services/createDeliveryProvider.js +19 -0
  67. package/lib/services/createEnrollment.d.ts +17 -0
  68. package/lib/services/createEnrollment.js +33 -0
  69. package/lib/services/createProduct.d.ts +7 -0
  70. package/lib/services/createProduct.js +8 -0
  71. package/lib/services/createProductBundleItem.d.ts +5 -0
  72. package/lib/services/createProductBundleItem.js +25 -0
  73. package/lib/services/createProductReview.d.ts +8 -0
  74. package/lib/services/createProductReview.js +12 -0
  75. package/lib/services/deleteDeadCarts.d.ts +2 -0
  76. package/lib/services/deleteDeadCarts.js +17 -0
  77. package/lib/services/deliverOrder.d.ts +5 -0
  78. package/lib/services/deliverOrder.js +26 -0
  79. package/lib/services/findActiveWorkTypes.d.ts +2 -0
  80. package/lib/services/findActiveWorkTypes.js +6 -0
  81. package/lib/services/findDeliveryInterfaces.d.ts +7 -0
  82. package/lib/services/findDeliveryInterfaces.js +13 -0
  83. package/lib/services/findOrdersWithFilters.d.ts +9 -0
  84. package/lib/services/findOrdersWithFilters.js +25 -0
  85. package/lib/services/findPaymentInterfaces.d.ts +7 -0
  86. package/lib/services/findPaymentInterfaces.js +13 -0
  87. package/lib/services/findWarehousingInterfaces.d.ts +7 -0
  88. package/lib/services/findWarehousingInterfaces.js +13 -0
  89. package/lib/services/getDeliveryDiscounts.d.ts +8 -0
  90. package/lib/services/getDeliveryDiscounts.js +14 -0
  91. package/lib/services/getPaymentDiscounts.d.ts +8 -0
  92. package/lib/services/getPaymentDiscounts.js +14 -0
  93. package/lib/services/getShopInfo.d.ts +25 -0
  94. package/lib/services/getShopInfo.js +47 -0
  95. package/lib/services/impersonateUser.d.ts +8 -0
  96. package/lib/services/impersonateUser.js +20 -0
  97. package/lib/services/loginAsGuest.d.ts +10 -0
  98. package/lib/services/loginAsGuest.js +19 -0
  99. package/lib/services/obfuscateWorkerData.d.ts +4 -0
  100. package/lib/services/obfuscateWorkerData.js +4 -0
  101. package/lib/services/orderPricingAccessors.d.ts +18 -0
  102. package/lib/services/orderPricingAccessors.js +29 -0
  103. package/lib/services/payOrder.d.ts +5 -0
  104. package/lib/services/payOrder.js +25 -0
  105. package/lib/services/registerUser.d.ts +14 -0
  106. package/lib/services/registerUser.js +44 -0
  107. package/lib/services/removeBookmark.d.ts +6 -0
  108. package/lib/services/removeBookmark.js +10 -0
  109. package/lib/services/removeCartItem.d.ts +6 -0
  110. package/lib/services/removeCartItem.js +19 -0
  111. package/lib/services/resetPasswordWithMigration.d.ts +14 -0
  112. package/lib/services/resetPasswordWithMigration.js +31 -0
  113. package/lib/services/resolveWorkType.d.ts +1 -0
  114. package/lib/services/resolveWorkType.js +7 -0
  115. package/lib/services/searchProductsWithAssortment.d.ts +19 -0
  116. package/lib/services/searchProductsWithAssortment.js +17 -0
  117. package/lib/services/toggleBookmark.d.ts +8 -0
  118. package/lib/services/toggleBookmark.js +33 -0
  119. package/lib/services/updateCart.d.ts +15 -0
  120. package/lib/services/updateCart.js +27 -0
  121. package/lib/services/updateCartItem.d.ts +11 -0
  122. package/lib/services/updateCartItem.js +37 -0
  123. package/lib/services/updateEnrollment.d.ts +13 -0
  124. package/lib/services/updateEnrollment.js +36 -0
  125. package/lib/services/verifyEmailWithMigration.d.ts +15 -0
  126. package/lib/services/verifyEmailWithMigration.js +23 -0
  127. package/lib/utils/getFileAdapter.d.ts +1 -0
  128. package/lib/utils/getFileAdapter.js +7 -0
  129. package/package.json +23 -23
@@ -0,0 +1,21 @@
1
+ import { ProductNotFoundError, BookmarkAlreadyExistsError } from "../errors/index.js";
2
+ export async function createBookmarkService(params) {
3
+ const { productId, userId, meta } = params;
4
+ if (!(await this.products.productExists({ productId }))) {
5
+ throw new ProductNotFoundError({ productId });
6
+ }
7
+ const [existingBookmark] = await this.bookmarks.findBookmarks({
8
+ productId,
9
+ userId,
10
+ meta,
11
+ });
12
+ if (existingBookmark) {
13
+ throw new BookmarkAlreadyExistsError({ bookmarkId: existingBookmark._id });
14
+ }
15
+ const bookmarkId = await this.bookmarks.create({
16
+ userId,
17
+ productId,
18
+ meta,
19
+ });
20
+ return (await this.bookmarks.findBookmarkById(bookmarkId));
21
+ }
@@ -0,0 +1,6 @@
1
+ import type { DeliveryProvider } from '@unchainedshop/core-delivery';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface CreateDeliveryProviderParams {
4
+ deliveryProvider: Pick<DeliveryProvider, 'type' | 'adapterKey'>;
5
+ }
6
+ export declare function createDeliveryProviderService(this: Modules, params: CreateDeliveryProviderParams): Promise<DeliveryProvider | null>;
@@ -0,0 +1,19 @@
1
+ import { DeliveryDirector } from "../directors/DeliveryDirector.js";
2
+ import { ProviderConfigurationInvalidError } from "../errors/index.js";
3
+ export async function createDeliveryProviderService(params) {
4
+ const { deliveryProvider } = params;
5
+ const Adapter = DeliveryDirector.getAdapter(deliveryProvider.adapterKey);
6
+ if (!Adapter)
7
+ return null;
8
+ const provider = await this.delivery.create({
9
+ configuration: Adapter.initialConfiguration,
10
+ ...deliveryProvider,
11
+ });
12
+ if (!provider) {
13
+ throw new ProviderConfigurationInvalidError({
14
+ adapterKey: deliveryProvider.adapterKey,
15
+ type: deliveryProvider.type,
16
+ });
17
+ }
18
+ return provider;
19
+ }
@@ -0,0 +1,17 @@
1
+ import type { Enrollment, EnrollmentPlan } from '@unchainedshop/core-enrollments';
2
+ import type { Address, Contact } from '@unchainedshop/core-users';
3
+ import type { Modules } from '../modules.ts';
4
+ export interface CreateEnrollmentParams {
5
+ productId: string;
6
+ quantity?: number;
7
+ configuration?: EnrollmentPlan['configuration'];
8
+ billingAddress?: Address;
9
+ contact?: Contact;
10
+ payment?: Enrollment['payment'];
11
+ delivery?: Enrollment['delivery'];
12
+ meta?: any;
13
+ countryCode: string;
14
+ currencyCode: string;
15
+ userId: string;
16
+ }
17
+ export declare function createEnrollmentService(this: Modules, params: CreateEnrollmentParams): Promise<Enrollment>;
@@ -0,0 +1,33 @@
1
+ import { ProductStatus, ProductType } from '@unchainedshop/core-products';
2
+ import { initializeEnrollmentService } from "./initializeEnrollment.js";
3
+ import { ProductNotFoundError, ProductWrongStatusError, ProductWrongTypeError, } from "../errors/index.js";
4
+ export async function createEnrollmentService(params) {
5
+ const { productId, quantity, configuration, billingAddress, contact, payment, delivery, meta, countryCode, currencyCode, userId, } = params;
6
+ const product = await this.products.findProduct({ productId });
7
+ if (!product) {
8
+ throw new ProductNotFoundError({ productId });
9
+ }
10
+ if (product.status !== ProductStatus.ACTIVE) {
11
+ throw new ProductWrongStatusError({ status: product.status });
12
+ }
13
+ if (product.type !== ProductType.PLAN_PRODUCT) {
14
+ throw new ProductWrongTypeError({ type: product.type });
15
+ }
16
+ const enrollment = await this.enrollments.create({
17
+ billingAddress: billingAddress,
18
+ configuration: configuration ?? null,
19
+ contact: contact,
20
+ countryCode,
21
+ currencyCode,
22
+ delivery: delivery,
23
+ meta,
24
+ payment,
25
+ productId,
26
+ quantity: quantity ?? 1,
27
+ userId,
28
+ });
29
+ return initializeEnrollmentService.bind(this)(enrollment, {
30
+ orderIdForFirstPeriod: enrollment.orderIdForFirstPeriod,
31
+ reason: 'new_enrollment',
32
+ });
33
+ }
@@ -0,0 +1,7 @@
1
+ import type { Product, ProductText } from '@unchainedshop/core-products';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface CreateProductParams {
4
+ product: Partial<Product>;
5
+ texts?: ProductText[];
6
+ }
7
+ export declare function createProductService(this: Modules, params: CreateProductParams): Promise<Product>;
@@ -0,0 +1,8 @@
1
+ export async function createProductService(params) {
2
+ const { product: productData, texts } = params;
3
+ const newProduct = await this.products.create(productData);
4
+ if (texts) {
5
+ await this.products.texts.updateTexts(newProduct._id, texts);
6
+ }
7
+ return newProduct;
8
+ }
@@ -0,0 +1,5 @@
1
+ import { type Product, type ProductBundleItem } from '@unchainedshop/core-products';
2
+ import type { Modules } from '../modules.ts';
3
+ import { ProductNotFoundError, ProductWrongTypeError, CyclicProductBundlingNotSupportedError } from '../errors/index.ts';
4
+ export { ProductNotFoundError, ProductWrongTypeError, CyclicProductBundlingNotSupportedError };
5
+ export declare function createProductBundleItemService(this: Modules, productId: string, item: ProductBundleItem): Promise<Product | null>;
@@ -0,0 +1,25 @@
1
+ import { ProductType } from '@unchainedshop/core-products';
2
+ import { ProductNotFoundError, ProductWrongTypeError, CyclicProductBundlingNotSupportedError, } from "../errors/index.js";
3
+ export { ProductNotFoundError, ProductWrongTypeError, CyclicProductBundlingNotSupportedError };
4
+ export async function createProductBundleItemService(productId, item) {
5
+ const product = await this.products.findProduct({ productId });
6
+ if (!product) {
7
+ throw new ProductNotFoundError({ productId });
8
+ }
9
+ if (product.type !== ProductType.BUNDLE_PRODUCT) {
10
+ throw new ProductWrongTypeError({
11
+ productId,
12
+ received: product.type,
13
+ required: ProductType.BUNDLE_PRODUCT,
14
+ });
15
+ }
16
+ const itemProduct = await this.products.findProduct({ productId: item.productId });
17
+ if (!itemProduct) {
18
+ throw new ProductNotFoundError({ productId: item.productId });
19
+ }
20
+ if (itemProduct._id === product._id) {
21
+ throw new CyclicProductBundlingNotSupportedError({ productId: itemProduct._id });
22
+ }
23
+ await this.products.bundleItems.addBundleItem(productId, item);
24
+ return this.products.findProduct({ productId });
25
+ }
@@ -0,0 +1,8 @@
1
+ import type { ProductReview } from '@unchainedshop/core-products';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface CreateProductReviewParams {
4
+ productId: string;
5
+ authorId: string;
6
+ productReview: Pick<ProductReview, 'title' | 'rating' | 'meta'>;
7
+ }
8
+ export declare function createProductReviewService(this: Modules, params: CreateProductReviewParams): Promise<ProductReview>;
@@ -0,0 +1,12 @@
1
+ import { ProductNotFoundError } from "../errors/index.js";
2
+ export async function createProductReviewService(params) {
3
+ const { productId, authorId, productReview } = params;
4
+ if (!(await this.products.productExists({ productId }))) {
5
+ throw new ProductNotFoundError({ productId });
6
+ }
7
+ return this.products.reviews.create({
8
+ ...productReview,
9
+ productId,
10
+ authorId,
11
+ });
12
+ }
@@ -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
+ }
@@ -0,0 +1,5 @@
1
+ import { type Order } from '@unchainedshop/core-orders';
2
+ import type { Modules } from '../modules.ts';
3
+ import { OrderDeliveryNotFoundError, OrderWrongDeliveryStatusError } from '../errors/index.ts';
4
+ export { OrderDeliveryNotFoundError, OrderWrongDeliveryStatusError };
5
+ export declare function deliverOrderService(this: Modules, orderId: string): Promise<Order>;
@@ -0,0 +1,26 @@
1
+ import { OrderDeliveryStatus } from '@unchainedshop/core-orders';
2
+ import { processOrderService } from "./processOrder.js";
3
+ import { OrderNotFoundError, OrderWrongStatusError, OrderDeliveryNotFoundError, OrderWrongDeliveryStatusError, } from "../errors/index.js";
4
+ export { OrderDeliveryNotFoundError, OrderWrongDeliveryStatusError };
5
+ export async function deliverOrderService(orderId) {
6
+ const order = await this.orders.findOrder({ orderId });
7
+ if (!order) {
8
+ throw new OrderNotFoundError({ orderId });
9
+ }
10
+ if (this.orders.isCart(order)) {
11
+ throw new OrderWrongStatusError({ status: order.status });
12
+ }
13
+ const orderDelivery = order.deliveryId &&
14
+ (await this.orders.deliveries.findDelivery({
15
+ orderDeliveryId: order.deliveryId,
16
+ }));
17
+ if (!orderDelivery) {
18
+ throw new OrderDeliveryNotFoundError({ orderDeliveryId: order.deliveryId });
19
+ }
20
+ if (this.orders.deliveries.normalizedStatus(orderDelivery) !== OrderDeliveryStatus.OPEN &&
21
+ order.confirmed) {
22
+ throw new OrderWrongDeliveryStatusError({ status: orderDelivery.status });
23
+ }
24
+ await this.orders.deliveries.markAsDelivered(orderDelivery);
25
+ return processOrderService.bind(this)(order, {});
26
+ }
@@ -0,0 +1,2 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export declare function findActiveWorkTypesService(this: Modules): Promise<string[]>;
@@ -0,0 +1,6 @@
1
+ import { WorkerDirector } from "../directors/index.js";
2
+ export async function findActiveWorkTypesService() {
3
+ const typeList = await this.worker.activeWorkTypes();
4
+ const pluginTypes = WorkerDirector.getActivePluginTypes();
5
+ return typeList.filter((type) => pluginTypes.includes(type));
6
+ }
@@ -0,0 +1,7 @@
1
+ import { DeliveryProviderType } from '@unchainedshop/core-delivery';
2
+ export interface DeliveryInterface {
3
+ _id: string;
4
+ label: string;
5
+ version: string;
6
+ }
7
+ export declare function findDeliveryInterfacesService(type?: DeliveryProviderType): Promise<DeliveryInterface[]>;
@@ -0,0 +1,13 @@
1
+ import { DeliveryProviderType } from '@unchainedshop/core-delivery';
2
+ import { DeliveryDirector } from "../directors/index.js";
3
+ export async function findDeliveryInterfacesService(type) {
4
+ const allAdapters = await DeliveryDirector.getAdapters();
5
+ const filteredAdapters = type
6
+ ? allAdapters.filter((Adapter) => Adapter.typeSupported(type))
7
+ : allAdapters;
8
+ return filteredAdapters.map((Adapter) => ({
9
+ _id: Adapter.key,
10
+ label: Adapter.label,
11
+ version: Adapter.version,
12
+ }));
13
+ }
@@ -0,0 +1,9 @@
1
+ import type { Order, OrderQuery } from '@unchainedshop/core-orders';
2
+ import type { SortOption } from '@unchainedshop/utils';
3
+ import type { Modules } from '../modules.ts';
4
+ export interface FindOrdersWithFiltersParams extends OrderQuery {
5
+ limit?: number;
6
+ offset?: number;
7
+ sort?: SortOption[];
8
+ }
9
+ export declare function findOrdersWithFiltersService(this: Modules, params: FindOrdersWithFiltersParams): Promise<Order[]>;
@@ -0,0 +1,25 @@
1
+ export async function findOrdersWithFiltersService(params) {
2
+ const { paymentProviderIds, deliveryProviderIds, ...restParams } = params;
3
+ if (!paymentProviderIds?.length && !deliveryProviderIds?.length) {
4
+ return this.orders.findOrders(restParams);
5
+ }
6
+ const [orderPayments, orderDeliveries] = await Promise.all([
7
+ paymentProviderIds?.length
8
+ ? this.orders.payments.findOrderPaymentsByProviderIds({ paymentProviderIds })
9
+ : [],
10
+ deliveryProviderIds?.length
11
+ ? this.orders.deliveries.findDeliveryByProvidersId({ deliveryProviderIds })
12
+ : [],
13
+ ]);
14
+ if ((paymentProviderIds?.length && !orderPayments.length) ||
15
+ (deliveryProviderIds?.length && !orderDeliveries.length)) {
16
+ return [];
17
+ }
18
+ const paymentIds = orderPayments.map((p) => p._id);
19
+ const deliveryIds = orderDeliveries.map((d) => d._id);
20
+ return this.orders.findOrders({
21
+ ...restParams,
22
+ paymentIds,
23
+ deliveryIds,
24
+ });
25
+ }
@@ -0,0 +1,7 @@
1
+ import { PaymentProviderType } from '@unchainedshop/core-payment';
2
+ export interface PaymentInterface {
3
+ _id: string;
4
+ label: string;
5
+ version: string;
6
+ }
7
+ export declare function findPaymentInterfacesService(type?: PaymentProviderType): Promise<PaymentInterface[]>;
@@ -0,0 +1,13 @@
1
+ import { PaymentProviderType } from '@unchainedshop/core-payment';
2
+ import { PaymentDirector } from "../directors/index.js";
3
+ export async function findPaymentInterfacesService(type) {
4
+ const allAdapters = await PaymentDirector.getAdapters();
5
+ const filteredAdapters = type
6
+ ? allAdapters.filter((Adapter) => Adapter.typeSupported(type))
7
+ : allAdapters;
8
+ return filteredAdapters.map((Adapter) => ({
9
+ _id: Adapter.key,
10
+ label: Adapter.label,
11
+ version: Adapter.version,
12
+ }));
13
+ }
@@ -0,0 +1,7 @@
1
+ import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
2
+ export interface WarehousingInterface {
3
+ _id: string;
4
+ label: string;
5
+ version: string;
6
+ }
7
+ export declare function findWarehousingInterfacesService(type?: WarehousingProviderType): Promise<WarehousingInterface[]>;
@@ -0,0 +1,13 @@
1
+ import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
2
+ import { WarehousingDirector } from "../directors/index.js";
3
+ export async function findWarehousingInterfacesService(type) {
4
+ const allAdapters = await WarehousingDirector.getAdapters();
5
+ const filteredAdapters = type
6
+ ? allAdapters.filter((Adapter) => Adapter.typeSupported(type))
7
+ : allAdapters;
8
+ return filteredAdapters.map((Adapter) => ({
9
+ _id: Adapter.key,
10
+ label: Adapter.label,
11
+ version: Adapter.version,
12
+ }));
13
+ }
@@ -0,0 +1,8 @@
1
+ import type { OrderDelivery } from '@unchainedshop/core-orders';
2
+ export interface DeliveryDiscountPrice {
3
+ item: OrderDelivery;
4
+ amount: number;
5
+ currencyCode: string;
6
+ discountId: string;
7
+ }
8
+ export declare function getDeliveryDiscountsService(orderDelivery: OrderDelivery, currencyCode: string): DeliveryDiscountPrice[];
@@ -0,0 +1,14 @@
1
+ import { DeliveryPricingSheet } from "../directors/index.js";
2
+ export function getDeliveryDiscountsService(orderDelivery, currencyCode) {
3
+ const pricing = DeliveryPricingSheet({
4
+ calculation: orderDelivery.calculation,
5
+ currencyCode,
6
+ });
7
+ if (pricing.isValid()) {
8
+ return pricing.discountPrices().map((discount) => ({
9
+ item: orderDelivery,
10
+ ...discount,
11
+ }));
12
+ }
13
+ return [];
14
+ }
@@ -0,0 +1,8 @@
1
+ import type { OrderPayment } from '@unchainedshop/core-orders';
2
+ export interface PaymentDiscountPrice {
3
+ item: OrderPayment;
4
+ amount: number;
5
+ currencyCode: string;
6
+ discountId: string;
7
+ }
8
+ export declare function getPaymentDiscountsService(orderPayment: OrderPayment, currencyCode: string): PaymentDiscountPrice[];
@@ -0,0 +1,14 @@
1
+ import { PaymentPricingSheet } from "../directors/index.js";
2
+ export function getPaymentDiscountsService(orderPayment, currencyCode) {
3
+ const pricing = PaymentPricingSheet({
4
+ calculation: orderPayment.calculation,
5
+ currencyCode,
6
+ });
7
+ if (pricing.isValid()) {
8
+ return pricing.discountPrices().map((discount) => ({
9
+ item: orderPayment,
10
+ ...discount,
11
+ }));
12
+ }
13
+ return [];
14
+ }
@@ -0,0 +1,25 @@
1
+ import type { Modules } from '../modules.ts';
2
+ export interface AdminUIConfig {
3
+ customProperties?: unknown[];
4
+ singleSignOnURL?: string;
5
+ externalLinks?: unknown[];
6
+ defaultProductTags?: string[];
7
+ defaultAssortmentTags?: string[];
8
+ defaultUserTags?: string[];
9
+ }
10
+ export interface ShopInfoResult {
11
+ version?: string;
12
+ adminUiConfig: {
13
+ customProperties: () => Promise<unknown[]>;
14
+ singleSignOnURL?: string;
15
+ externalLinks: () => unknown[];
16
+ productTags: () => Promise<string[]>;
17
+ assortmentTags: () => Promise<string[]>;
18
+ userTags: () => Promise<string[]>;
19
+ };
20
+ vapidPublicKey?: string;
21
+ }
22
+ export declare function getShopInfoService(this: Modules, params: {
23
+ version?: string;
24
+ adminUiConfig?: AdminUIConfig;
25
+ }): ShopInfoResult;
@@ -0,0 +1,47 @@
1
+ import { readFile } from 'fs/promises';
2
+ async function loadCustomProperties(adminUiConfig) {
3
+ try {
4
+ if (!process.env.UNCHAINED_ADMIN_UI_CUSTOM_PROPERTIES) {
5
+ return adminUiConfig?.customProperties ?? [];
6
+ }
7
+ const raw = await readFile(process.env.UNCHAINED_ADMIN_UI_CUSTOM_PROPERTIES, 'utf-8');
8
+ return JSON.parse(raw);
9
+ }
10
+ catch {
11
+ return adminUiConfig?.customProperties ?? [];
12
+ }
13
+ }
14
+ function loadExternalLinks() {
15
+ try {
16
+ if (!process.env.EXTERNAL_LINKS)
17
+ return [];
18
+ return JSON.parse(process.env.EXTERNAL_LINKS);
19
+ }
20
+ catch {
21
+ return [];
22
+ }
23
+ }
24
+ async function getConfiguredTags(existingTagsFn, envVar, configDefault) {
25
+ const existingTags = await existingTagsFn();
26
+ const envTags = (process.env[envVar] || '')
27
+ .split(',')
28
+ .map((t) => t.trim())
29
+ .filter(Boolean);
30
+ const normalizedDefaultTags = envTags?.length ? envTags : (configDefault || []).filter(Boolean);
31
+ return Array.from(new Set(normalizedDefaultTags.concat(existingTags)));
32
+ }
33
+ export function getShopInfoService(params) {
34
+ const { version, adminUiConfig } = params;
35
+ return {
36
+ version,
37
+ adminUiConfig: {
38
+ customProperties: () => loadCustomProperties(adminUiConfig),
39
+ singleSignOnURL: process.env.UNCHAINED_ADMIN_UI_SINGLE_SIGN_ON_URL || adminUiConfig?.singleSignOnURL,
40
+ externalLinks: loadExternalLinks,
41
+ productTags: () => getConfiguredTags(() => this.products.existingTags(), 'UNCHAINED_ADMIN_UI_DEFAULT_PRODUCT_TAGS', adminUiConfig?.defaultProductTags),
42
+ assortmentTags: () => getConfiguredTags(() => this.assortments.existingTags(), 'UNCHAINED_ADMIN_UI_DEFAULT_ASSORTMENT_TAGS', adminUiConfig?.defaultAssortmentTags),
43
+ userTags: () => getConfiguredTags(() => this.users.existingTags(), 'UNCHAINED_ADMIN_UI_DEFAULT_USER_TAGS', adminUiConfig?.defaultUserTags),
44
+ },
45
+ vapidPublicKey: process.env?.PUSH_NOTIFICATION_PUBLIC_KEY,
46
+ };
47
+ }
@@ -0,0 +1,8 @@
1
+ import type { User } from '@unchainedshop/core-users';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface ImpersonateUserParams {
4
+ userIdToImpersonate: string;
5
+ currentUserId?: string;
6
+ countryCode: string;
7
+ }
8
+ export declare function impersonateUserService(this: Modules, params: ImpersonateUserParams): Promise<User>;
@@ -0,0 +1,20 @@
1
+ import { nextUserCartService } from "./nextUserCart.js";
2
+ import { UserNotFoundError, ImpersonatingAdminUserError } from "../errors/index.js";
3
+ export async function impersonateUserService(params) {
4
+ const { userIdToImpersonate, currentUserId, countryCode } = params;
5
+ const userToImpersonate = await this.users.findUserById(userIdToImpersonate);
6
+ if (!userToImpersonate) {
7
+ throw new UserNotFoundError({ userId: userIdToImpersonate });
8
+ }
9
+ if ((userToImpersonate.roles || []).includes('admin')) {
10
+ throw new ImpersonatingAdminUserError({
11
+ impersonatedUserId: userIdToImpersonate,
12
+ userId: currentUserId,
13
+ });
14
+ }
15
+ await nextUserCartService.bind(this)({
16
+ user: userToImpersonate,
17
+ countryCode,
18
+ });
19
+ return userToImpersonate;
20
+ }
@@ -0,0 +1,10 @@
1
+ import type { User } from '@unchainedshop/core-users';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface HttpContext {
4
+ remoteAddress?: string;
5
+ remotePort?: number;
6
+ userAgent?: string;
7
+ locale?: string;
8
+ countryCode: string;
9
+ }
10
+ export declare function loginAsGuestService(this: Modules, httpContext: HttpContext): Promise<User>;
@@ -0,0 +1,19 @@
1
+ import { nextUserCartService } from "./nextUserCart.js";
2
+ export async function loginAsGuestService(httpContext) {
3
+ const guestname = `guest-${crypto.randomUUID()}`;
4
+ const guestUserId = await this.users.createUser({
5
+ email: `${guestname}@unchained.local`,
6
+ guest: true,
7
+ password: null,
8
+ initialPassword: true,
9
+ }, { skipMessaging: true });
10
+ const user = (await this.users.updateHeartbeat(guestUserId, {
11
+ remoteAddress: httpContext.remoteAddress,
12
+ remotePort: httpContext.remotePort,
13
+ userAgent: httpContext.userAgent,
14
+ locale: httpContext.locale,
15
+ countryCode: httpContext.countryCode,
16
+ }));
17
+ await nextUserCartService.bind(this)({ user, countryCode: httpContext.countryCode });
18
+ return user;
19
+ }
@@ -0,0 +1,4 @@
1
+ export interface WorkerObfuscationOptions {
2
+ blacklistedVariables?: string[];
3
+ }
4
+ export declare function obfuscateWorkerDataService<T>(data: T, options?: WorkerObfuscationOptions): T;
@@ -0,0 +1,4 @@
1
+ import { buildObfuscatedFieldsFilter } from '@unchainedshop/utils';
2
+ export function obfuscateWorkerDataService(data, options) {
3
+ return buildObfuscatedFieldsFilter(options?.blacklistedVariables)(data);
4
+ }
@@ -0,0 +1,18 @@
1
+ import type { Order, OrderPosition } from '@unchainedshop/core-orders';
2
+ import type { Price } from '@unchainedshop/utils';
3
+ import type { Modules } from '../modules.ts';
4
+ import { type IOrderPricingSheet } from '../directors/OrderPricingSheet.ts';
5
+ import { type IProductPricingSheet } from '../directors/ProductPricingSheet.ts';
6
+ export declare function getOrderPricingSheetService(this: Modules, order: Order): IOrderPricingSheet | null;
7
+ export declare function getOrderTotalService(this: Modules, order: Order, params?: {
8
+ category?: string;
9
+ useNetPrice?: boolean;
10
+ }): Price | null;
11
+ export declare function getPositionPricingSheetService(this: Modules, position: OrderPosition, currencyCode: string): IProductPricingSheet | null;
12
+ export declare function getPositionTotalService(this: Modules, position: OrderPosition, currencyCode: string, params?: {
13
+ category?: string;
14
+ useNetPrice?: boolean;
15
+ }): Price | null;
16
+ export declare function getPositionUnitPriceService(this: Modules, position: OrderPosition, currencyCode: string, params?: {
17
+ useNetPrice?: boolean;
18
+ }): Price | null;
@@ -0,0 +1,29 @@
1
+ import { OrderPricingSheet } from "../directors/OrderPricingSheet.js";
2
+ import { ProductPricingSheet } from "../directors/ProductPricingSheet.js";
3
+ export function getOrderPricingSheetService(order) {
4
+ const pricing = OrderPricingSheet({
5
+ calculation: order.calculation,
6
+ currencyCode: order.currencyCode,
7
+ });
8
+ return pricing.isValid() ? pricing : null;
9
+ }
10
+ export function getOrderTotalService(order, params = {}) {
11
+ const pricing = getOrderPricingSheetService.call(this, order);
12
+ return pricing?.total(params) ?? null;
13
+ }
14
+ export function getPositionPricingSheetService(position, currencyCode) {
15
+ const pricing = ProductPricingSheet({
16
+ calculation: position.calculation,
17
+ currencyCode,
18
+ quantity: position.quantity,
19
+ });
20
+ return pricing.isValid() ? pricing : null;
21
+ }
22
+ export function getPositionTotalService(position, currencyCode, params = {}) {
23
+ const pricing = getPositionPricingSheetService.call(this, position, currencyCode);
24
+ return pricing?.total(params) ?? null;
25
+ }
26
+ export function getPositionUnitPriceService(position, currencyCode, params = {}) {
27
+ const pricing = getPositionPricingSheetService.call(this, position, currencyCode);
28
+ return pricing?.unitPrice(params) ?? null;
29
+ }
@@ -0,0 +1,5 @@
1
+ import { type Order } from '@unchainedshop/core-orders';
2
+ import type { Modules } from '../modules.ts';
3
+ import { OrderNotFoundError, OrderWrongStatusError, OrderPaymentNotFoundError, OrderWrongPaymentStatusError } from '../errors/index.ts';
4
+ export { OrderNotFoundError, OrderWrongStatusError, OrderPaymentNotFoundError, OrderWrongPaymentStatusError, };
5
+ export declare function payOrderService(this: Modules, orderId: string): Promise<Order>;
@@ -0,0 +1,25 @@
1
+ import { OrderPaymentStatus } from '@unchainedshop/core-orders';
2
+ import { processOrderService } from "./processOrder.js";
3
+ import { OrderNotFoundError, OrderWrongStatusError, OrderPaymentNotFoundError, OrderWrongPaymentStatusError, } from "../errors/index.js";
4
+ export { OrderNotFoundError, OrderWrongStatusError, OrderPaymentNotFoundError, OrderWrongPaymentStatusError, };
5
+ export async function payOrderService(orderId) {
6
+ const order = await this.orders.findOrder({ orderId });
7
+ if (!order) {
8
+ throw new OrderNotFoundError({ orderId });
9
+ }
10
+ if (this.orders.isCart(order)) {
11
+ throw new OrderWrongStatusError({ status: order.status });
12
+ }
13
+ const payment = order.paymentId &&
14
+ (await this.orders.payments.findOrderPayment({
15
+ orderPaymentId: order.paymentId,
16
+ }));
17
+ if (!payment) {
18
+ throw new OrderPaymentNotFoundError({ orderPaymentId: order.paymentId });
19
+ }
20
+ if (this.orders.payments.normalizedStatus(payment) !== OrderPaymentStatus.OPEN) {
21
+ throw new OrderWrongPaymentStatusError({ status: payment.status });
22
+ }
23
+ await this.orders.payments.markAsPaid(payment, null);
24
+ return processOrderService.bind(this)(order, {});
25
+ }