@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,14 @@
1
+ import type { User, UserRegistrationData } 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 interface RegisterUserResult {
11
+ user: User;
12
+ isFirstUser: boolean;
13
+ }
14
+ export declare function registerUserService(this: Modules, params: UserRegistrationData, httpContext: HttpContext): Promise<RegisterUserResult>;
@@ -0,0 +1,44 @@
1
+ import { nextUserCartService } from "./nextUserCart.js";
2
+ import { UsernameOrEmailRequiredError, PasswordOrWebAuthnPublicKeyRequiredError, EmailAlreadyExistsError, UsernameAlreadyExistsError, PasswordInvalidError, WebAuthnVerificationFailedError, AuthOperationFailedError, } from "../errors/index.js";
3
+ export async function registerUserService(params, httpContext) {
4
+ if (!params.username && !params.email) {
5
+ throw new UsernameOrEmailRequiredError();
6
+ }
7
+ if (!params.password && !params.webAuthnPublicKeyCredentials) {
8
+ throw new PasswordOrWebAuthnPublicKeyRequiredError({ username: params.username });
9
+ }
10
+ const usersCountBeforeCreation = await this.users.count({
11
+ includeDeleted: true,
12
+ includeGuests: true,
13
+ });
14
+ const isFirstUser = usersCountBeforeCreation === 0;
15
+ let newUserId;
16
+ try {
17
+ newUserId = await this.users.createUser({
18
+ ...params,
19
+ initialPassword: false,
20
+ roles: isFirstUser ? ['admin'] : [],
21
+ }, {});
22
+ }
23
+ catch (e) {
24
+ if (e.cause === 'EMAIL_INVALID')
25
+ throw new EmailAlreadyExistsError({ email: params.email });
26
+ else if (e.cause === 'USERNAME_INVALID')
27
+ throw new UsernameAlreadyExistsError({ username: params.username });
28
+ else if (e.cause === 'PASSWORD_INVALID')
29
+ throw new PasswordInvalidError({ username: params.username });
30
+ else if (e.cause === 'WEBAUTHN_INVALID')
31
+ throw new WebAuthnVerificationFailedError({ username: params.username });
32
+ else
33
+ throw new AuthOperationFailedError({ username: params.username, email: params.email });
34
+ }
35
+ const user = (await this.users.updateHeartbeat(newUserId, {
36
+ remoteAddress: httpContext.remoteAddress,
37
+ remotePort: httpContext.remotePort,
38
+ userAgent: httpContext.userAgent,
39
+ locale: httpContext.locale,
40
+ countryCode: httpContext.countryCode,
41
+ }));
42
+ await nextUserCartService.bind(this)({ user, countryCode: httpContext.countryCode });
43
+ return { user, isFirstUser };
44
+ }
@@ -0,0 +1,6 @@
1
+ import type { Bookmark } from '@unchainedshop/core-bookmarks';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface RemoveBookmarkParams {
4
+ bookmarkId: string;
5
+ }
6
+ export declare function removeBookmarkService(this: Modules, params: RemoveBookmarkParams): Promise<Bookmark>;
@@ -0,0 +1,10 @@
1
+ import { BookmarkNotFoundError } from "../errors/index.js";
2
+ export async function removeBookmarkService(params) {
3
+ const { bookmarkId } = params;
4
+ const bookmark = await this.bookmarks.findBookmarkById(bookmarkId);
5
+ if (!bookmark) {
6
+ throw new BookmarkNotFoundError({ bookmarkId });
7
+ }
8
+ await this.bookmarks.delete(bookmarkId);
9
+ return bookmark;
10
+ }
@@ -0,0 +1,6 @@
1
+ import type { OrderPosition } from '@unchainedshop/core-orders';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface RemoveCartItemParams {
4
+ itemId: string;
5
+ }
6
+ export declare function removeCartItemService(this: Modules, params: RemoveCartItemParams): Promise<OrderPosition>;
@@ -0,0 +1,19 @@
1
+ import { updateCalculationService } from "./updateCalculation.js";
2
+ import { OrderItemNotFoundError, OrderNotFoundError, OrderWrongStatusError } from "../errors/index.js";
3
+ export async function removeCartItemService(params) {
4
+ const { itemId } = params;
5
+ const orderItem = await this.orders.positions.findOrderPosition({ itemId });
6
+ if (!orderItem) {
7
+ throw new OrderItemNotFoundError({ orderItemId: itemId });
8
+ }
9
+ const order = await this.orders.findOrder({ orderId: orderItem.orderId });
10
+ if (!order) {
11
+ throw new OrderNotFoundError({ orderId: orderItem.orderId });
12
+ }
13
+ if (!this.orders.isCart(order)) {
14
+ throw new OrderWrongStatusError({ status: order.status });
15
+ }
16
+ const removedOrderPosition = await this.orders.positions.delete(itemId);
17
+ await updateCalculationService.bind(this)(order._id);
18
+ return removedOrderPosition;
19
+ }
@@ -0,0 +1,14 @@
1
+ import type { User } from '@unchainedshop/core-users';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface ResetPasswordParams {
4
+ token: string;
5
+ newPassword: string;
6
+ }
7
+ export interface HttpContext {
8
+ remoteAddress?: string;
9
+ remotePort?: number;
10
+ userAgent?: string;
11
+ locale?: string;
12
+ countryCode: string;
13
+ }
14
+ export declare function resetPasswordWithMigrationService(this: Modules, params: ResetPasswordParams, httpContext: HttpContext, currentUserId?: string): Promise<User>;
@@ -0,0 +1,31 @@
1
+ import { migrateUserDataService } from "./migrateUserData.js";
2
+ import { nextUserCartService } from "./nextUserCart.js";
3
+ import { InvalidResetTokenError, PasswordInvalidError } from "../errors/index.js";
4
+ export async function resetPasswordWithMigrationService(params, httpContext, currentUserId) {
5
+ const { token, newPassword } = params;
6
+ let user;
7
+ try {
8
+ user = await this.users.resetPassword(token, newPassword);
9
+ }
10
+ catch (e) {
11
+ if (e && typeof e === 'object' && 'cause' in e && e.cause === 'PASSWORD_INVALID') {
12
+ throw new PasswordInvalidError();
13
+ }
14
+ throw e;
15
+ }
16
+ if (!user) {
17
+ throw new InvalidResetTokenError();
18
+ }
19
+ user = (await this.users.updateHeartbeat(user._id, {
20
+ remoteAddress: httpContext.remoteAddress,
21
+ remotePort: httpContext.remotePort,
22
+ userAgent: httpContext.userAgent,
23
+ locale: httpContext.locale,
24
+ countryCode: httpContext.countryCode,
25
+ }));
26
+ if (currentUserId) {
27
+ await migrateUserDataService.bind(this)(currentUserId, user._id);
28
+ }
29
+ await nextUserCartService.bind(this)({ user, countryCode: httpContext.countryCode });
30
+ return user;
31
+ }
@@ -0,0 +1 @@
1
+ export declare function resolveWorkTypeService(workType: string): string;
@@ -0,0 +1,7 @@
1
+ import { WorkerDirector } from "../directors/WorkerDirector.js";
2
+ export function resolveWorkTypeService(workType) {
3
+ if (WorkerDirector.getActivePluginTypes().includes(workType)) {
4
+ return workType;
5
+ }
6
+ return 'UNKNOWN';
7
+ }
@@ -0,0 +1,19 @@
1
+ import type { Assortment } from '@unchainedshop/core-assortments';
2
+ import type { SearchQuery } from '@unchainedshop/core-filters';
3
+ import type { Modules } from '../modules.ts';
4
+ export interface SearchProductsWithAssortmentParams extends SearchQuery {
5
+ assortmentId?: string;
6
+ assortment?: Assortment;
7
+ ignoreChildAssortments?: boolean;
8
+ }
9
+ export interface SearchProductsOptions {
10
+ locale: Intl.Locale;
11
+ userId?: string;
12
+ forceLiveCollection?: boolean;
13
+ }
14
+ export declare function searchProductsWithAssortmentService(this: Modules, params: SearchProductsWithAssortmentParams, options: SearchProductsOptions): Promise<{
15
+ searchConfiguration: import("../core-index.ts").SearchProductsOptions;
16
+ totalProductIds: string[];
17
+ aggregatedTotalProductIds: string[];
18
+ aggregatedFilteredProductIds: string[];
19
+ }>;
@@ -0,0 +1,17 @@
1
+ import { searchProductsService } from "./searchProducts.js";
2
+ export async function searchProductsWithAssortmentService(params, options) {
3
+ const { assortmentId, assortment: providedAssortment, ignoreChildAssortments, ...searchQuery } = params;
4
+ const assortment = providedAssortment ||
5
+ (assortmentId ? await this.assortments.findAssortment({ assortmentId }) : null);
6
+ if (!assortment) {
7
+ return searchProductsService.call(this, searchQuery, options);
8
+ }
9
+ const [productIds, filterIds] = await Promise.all([
10
+ this.assortments.findProductIds({
11
+ assortment,
12
+ ignoreChildAssortments: ignoreChildAssortments || false,
13
+ }),
14
+ this.assortments.filters.findFilterIds({ assortmentId: assortment._id }),
15
+ ]);
16
+ return searchProductsService.call(this, { ...searchQuery, productIds, filterIds }, options);
17
+ }
@@ -0,0 +1,8 @@
1
+ import type { Bookmark } from '@unchainedshop/core-bookmarks';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface ToggleBookmarkParams {
4
+ productId: string;
5
+ userId: string;
6
+ bookmarked: boolean;
7
+ }
8
+ export declare function toggleBookmarkService(this: Modules, params: ToggleBookmarkParams): Promise<Bookmark>;
@@ -0,0 +1,33 @@
1
+ import { ProductNotFoundError, BookmarkNotFoundError, MultipleBookmarksFoundError, } from "../errors/index.js";
2
+ export async function toggleBookmarkService(params) {
3
+ const { productId, userId, bookmarked } = params;
4
+ if (!(await this.products.productExists({ productId }))) {
5
+ throw new ProductNotFoundError({ productId });
6
+ }
7
+ const foundBookmarks = await this.bookmarks.findBookmarks({
8
+ productId,
9
+ userId,
10
+ });
11
+ if (foundBookmarks.length > 1) {
12
+ throw new MultipleBookmarksFoundError({
13
+ productId,
14
+ userId,
15
+ bookmarkIds: foundBookmarks.map((b) => b._id),
16
+ });
17
+ }
18
+ const foundBookmark = foundBookmarks[0];
19
+ if (bookmarked) {
20
+ if (foundBookmark)
21
+ return foundBookmark;
22
+ const bookmarkId = await this.bookmarks.create({
23
+ productId,
24
+ userId,
25
+ });
26
+ return (await this.bookmarks.findBookmarkById(bookmarkId));
27
+ }
28
+ if (!foundBookmark) {
29
+ throw new BookmarkNotFoundError({ productId, userId });
30
+ }
31
+ await this.bookmarks.delete(foundBookmark._id);
32
+ return foundBookmark;
33
+ }
@@ -0,0 +1,15 @@
1
+ import type { Order } from '@unchainedshop/core-orders';
2
+ import type { User } from '@unchainedshop/core-users';
3
+ import type { Address, Contact } from '@unchainedshop/core-users';
4
+ import type { Modules } from '../modules.ts';
5
+ export interface UpdateCartParams {
6
+ orderId?: string;
7
+ billingAddress?: Address;
8
+ contact?: Contact;
9
+ paymentProviderId?: string;
10
+ deliveryProviderId?: string;
11
+ meta?: any;
12
+ user: User;
13
+ countryCode: string;
14
+ }
15
+ export declare function updateCartService(this: Modules, params: UpdateCartParams): Promise<Order>;
@@ -0,0 +1,27 @@
1
+ import { findOrInitCartService } from "./findOrInitCart.js";
2
+ import { updateCalculationService } from "./updateCalculation.js";
3
+ import { OrderNotFoundError, OrderWrongStatusError } from "../errors/index.js";
4
+ export async function updateCartService(params) {
5
+ const { orderId, billingAddress, contact, paymentProviderId, deliveryProviderId, meta, user, countryCode, } = params;
6
+ const order = await findOrInitCartService.bind(this)({
7
+ orderId,
8
+ user,
9
+ countryCode,
10
+ });
11
+ if (!order) {
12
+ throw new OrderNotFoundError({ orderId });
13
+ }
14
+ if (!this.orders.isCart(order)) {
15
+ throw new OrderWrongStatusError({ status: order.status });
16
+ }
17
+ if (meta || billingAddress || contact) {
18
+ await this.orders.updateCartFields(order._id, { meta, billingAddress, contact });
19
+ }
20
+ if (paymentProviderId) {
21
+ await this.orders.setPaymentProvider(order._id, paymentProviderId);
22
+ }
23
+ if (deliveryProviderId) {
24
+ await this.orders.setDeliveryProvider(order._id, deliveryProviderId);
25
+ }
26
+ return updateCalculationService.bind(this)(order._id);
27
+ }
@@ -0,0 +1,11 @@
1
+ import { type OrderPosition } from '@unchainedshop/core-orders';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface UpdateCartItemParams {
4
+ itemId: string;
5
+ quantity?: number;
6
+ configuration?: {
7
+ key: string;
8
+ value: string;
9
+ }[];
10
+ }
11
+ export declare function updateCartItemService(this: Modules, params: UpdateCartItemParams, context: any): Promise<OrderPosition>;
@@ -0,0 +1,37 @@
1
+ import { ordersSettings } from '@unchainedshop/core-orders';
2
+ import { updateCalculationService } from "./updateCalculation.js";
3
+ import { OrderItemNotFoundError, OrderNotFoundError, OrderWrongStatusError, OrderQuantityTooLowError, ProductNotFoundError, } from "../errors/index.js";
4
+ export async function updateCartItemService(params, context) {
5
+ const { itemId, configuration, quantity = 1 } = params;
6
+ const item = await this.orders.positions.findOrderPosition({ itemId });
7
+ if (!item) {
8
+ throw new OrderItemNotFoundError({ orderItemId: itemId });
9
+ }
10
+ const order = await this.orders.findOrder({ orderId: item.orderId });
11
+ if (!order) {
12
+ throw new OrderNotFoundError({ orderId: item.orderId });
13
+ }
14
+ if (!this.orders.isCart(order)) {
15
+ throw new OrderWrongStatusError({ status: order.status });
16
+ }
17
+ const product = await this.products.findProduct({ productId: item.productId });
18
+ if (!product) {
19
+ throw new ProductNotFoundError({ productId: item.productId });
20
+ }
21
+ if (quantity !== null && quantity < 1) {
22
+ throw new OrderQuantityTooLowError({ quantity });
23
+ }
24
+ await ordersSettings.validateOrderPosition({
25
+ order,
26
+ product,
27
+ configuration,
28
+ quantityDiff: quantity - item.quantity,
29
+ }, context);
30
+ await this.orders.positions.updateProductItem({
31
+ orderPositionId: item._id,
32
+ quantity: quantity || null,
33
+ configuration: configuration || null,
34
+ });
35
+ await updateCalculationService.bind(this)(order._id);
36
+ return (await this.orders.positions.findOrderPosition({ itemId: item._id }));
37
+ }
@@ -0,0 +1,13 @@
1
+ import { type Enrollment, type EnrollmentPlan } from '@unchainedshop/core-enrollments';
2
+ import type { Address, Contact } from '@unchainedshop/core-users';
3
+ import type { Modules } from '../modules.ts';
4
+ export interface UpdateEnrollmentParams {
5
+ enrollmentId: string;
6
+ contact?: Contact;
7
+ plan?: EnrollmentPlan;
8
+ billingAddress?: Address;
9
+ payment?: Enrollment['payment'];
10
+ delivery?: Enrollment['delivery'];
11
+ meta?: any;
12
+ }
13
+ export declare function updateEnrollmentService(this: Modules, params: UpdateEnrollmentParams): Promise<Enrollment>;
@@ -0,0 +1,36 @@
1
+ import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
2
+ import { initializeEnrollmentService } from "./initializeEnrollment.js";
3
+ import { EnrollmentNotFoundError, EnrollmentWrongStatusError, EnrollmentPlanUpdateNotAllowedError, } from "../errors/index.js";
4
+ export async function updateEnrollmentService(params) {
5
+ const { enrollmentId, billingAddress, contact, delivery, meta, payment, plan } = params;
6
+ let enrollment = await this.enrollments.findEnrollment({ enrollmentId });
7
+ if (!enrollment) {
8
+ throw new EnrollmentNotFoundError({ enrollmentId });
9
+ }
10
+ if (enrollment.status === EnrollmentStatus.TERMINATED) {
11
+ throw new EnrollmentWrongStatusError({ status: enrollment.status, enrollmentId: enrollment._id });
12
+ }
13
+ if (meta) {
14
+ enrollment = (await this.enrollments.updateContext(enrollmentId, meta));
15
+ }
16
+ if (billingAddress) {
17
+ enrollment = (await this.enrollments.updateBillingAddress(enrollmentId, billingAddress));
18
+ }
19
+ if (contact) {
20
+ enrollment = (await this.enrollments.updateContact(enrollmentId, contact));
21
+ }
22
+ if (payment) {
23
+ enrollment = (await this.enrollments.updatePayment(enrollmentId, payment));
24
+ }
25
+ if (delivery) {
26
+ enrollment = (await this.enrollments.updateDelivery(enrollmentId, delivery));
27
+ }
28
+ if (plan) {
29
+ if (enrollment.status !== EnrollmentStatus.INITIAL) {
30
+ throw new EnrollmentPlanUpdateNotAllowedError({ status: enrollment.status, enrollmentId });
31
+ }
32
+ enrollment = (await this.enrollments.updatePlan(enrollmentId, plan));
33
+ enrollment = await initializeEnrollmentService.bind(this)(enrollment, { reason: 'updated_plan' });
34
+ }
35
+ return enrollment;
36
+ }
@@ -0,0 +1,15 @@
1
+ import type { User } from '@unchainedshop/core-users';
2
+ import type { Modules } from '../modules.ts';
3
+ export interface VerifyEmailHttpContext {
4
+ remoteAddress?: string;
5
+ remotePort?: number;
6
+ userAgent?: string;
7
+ locale?: string;
8
+ countryCode: string;
9
+ }
10
+ export interface VerifyEmailParams {
11
+ token: string;
12
+ currentUserId?: string;
13
+ httpContext: VerifyEmailHttpContext;
14
+ }
15
+ export declare function verifyEmailWithMigrationService(this: Modules, params: VerifyEmailParams): Promise<User>;
@@ -0,0 +1,23 @@
1
+ import { nextUserCartService } from "./nextUserCart.js";
2
+ import { migrateUserDataService } from "./migrateUserData.js";
3
+ import { InvalidEmailVerificationTokenError } from "../errors/index.js";
4
+ export async function verifyEmailWithMigrationService(params) {
5
+ const { token, currentUserId, httpContext } = params;
6
+ const unverifiedToken = await this.users.findUnverifiedEmailToken(token);
7
+ if (!unverifiedToken) {
8
+ throw new InvalidEmailVerificationTokenError({ token });
9
+ }
10
+ await this.users.verifyEmail(unverifiedToken.userId, unverifiedToken.address);
11
+ const user = (await this.users.updateHeartbeat(unverifiedToken.userId, {
12
+ remoteAddress: httpContext.remoteAddress,
13
+ remotePort: httpContext.remotePort,
14
+ userAgent: httpContext.userAgent,
15
+ locale: httpContext.locale,
16
+ countryCode: httpContext.countryCode,
17
+ }));
18
+ if (currentUserId) {
19
+ await migrateUserDataService.bind(this)(currentUserId, user._id);
20
+ }
21
+ await nextUserCartService.bind(this)({ user, countryCode: httpContext.countryCode });
22
+ return user;
23
+ }
@@ -0,0 +1 @@
1
+ export declare const getFileAdapter: () => import("@unchainedshop/core-files").IFileAdapter<unknown>;
@@ -0,0 +1,7 @@
1
+ import { FileDirector } from "../directors/FileDirector.js";
2
+ export const getFileAdapter = () => {
3
+ const adapters = FileDirector.getAdapters();
4
+ if (adapters.length === 0)
5
+ throw Error('No file adapter found.');
6
+ return adapters[0];
7
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unchainedshop/core",
3
3
  "description": "Core orchestration package for the Unchained Engine with business services and directors",
4
- "version": "4.8.26",
4
+ "version": "4.8.27",
5
5
  "main": "lib/core-index.js",
6
6
  "types": "lib/core-index.d.ts",
7
7
  "type": "module",
@@ -35,28 +35,28 @@
35
35
  },
36
36
  "homepage": "https://github.com/unchainedshop/unchained#readme",
37
37
  "dependencies": {
38
- "@unchainedshop/core-assortments": "^4.8.12",
39
- "@unchainedshop/core-bookmarks": "^4.8.12",
40
- "@unchainedshop/core-countries": "^4.8.12",
41
- "@unchainedshop/core-currencies": "^4.8.12",
42
- "@unchainedshop/core-delivery": "^4.8.12",
43
- "@unchainedshop/core-enrollments": "^4.8.12",
44
- "@unchainedshop/core-events": "^4.8.12",
45
- "@unchainedshop/core-files": "^4.8.12",
46
- "@unchainedshop/core-filters": "^4.8.12",
47
- "@unchainedshop/core-languages": "^4.8.12",
48
- "@unchainedshop/core-orders": "^4.8.12",
49
- "@unchainedshop/core-payment": "^4.8.12",
50
- "@unchainedshop/core-products": "^4.8.12",
51
- "@unchainedshop/core-quotations": "^4.8.12",
52
- "@unchainedshop/core-users": "^4.8.12",
53
- "@unchainedshop/core-warehousing": "^4.8.12",
54
- "@unchainedshop/core-worker": "^4.8.12",
55
- "@unchainedshop/events": "^4.8.12",
56
- "@unchainedshop/file-upload": "^4.8.12",
57
- "@unchainedshop/logger": "^4.8.12",
58
- "@unchainedshop/mongodb": "^4.8.12",
59
- "@unchainedshop/utils": "^4.8.12",
38
+ "@unchainedshop/core-assortments": "^4.8.27",
39
+ "@unchainedshop/core-bookmarks": "^4.8.27",
40
+ "@unchainedshop/core-countries": "^4.8.27",
41
+ "@unchainedshop/core-currencies": "^4.8.27",
42
+ "@unchainedshop/core-delivery": "^4.8.27",
43
+ "@unchainedshop/core-enrollments": "^4.8.27",
44
+ "@unchainedshop/core-events": "^4.8.27",
45
+ "@unchainedshop/core-files": "^4.8.27",
46
+ "@unchainedshop/core-filters": "^4.8.27",
47
+ "@unchainedshop/core-languages": "^4.8.27",
48
+ "@unchainedshop/core-orders": "^4.8.27",
49
+ "@unchainedshop/core-payment": "^4.8.27",
50
+ "@unchainedshop/core-products": "^4.8.27",
51
+ "@unchainedshop/core-quotations": "^4.8.27",
52
+ "@unchainedshop/core-users": "^4.8.27",
53
+ "@unchainedshop/core-warehousing": "^4.8.27",
54
+ "@unchainedshop/core-worker": "^4.8.27",
55
+ "@unchainedshop/events": "^4.8.27",
56
+ "@unchainedshop/file-upload": "^4.8.27",
57
+ "@unchainedshop/logger": "^4.8.27",
58
+ "@unchainedshop/mongodb": "^4.8.27",
59
+ "@unchainedshop/utils": "^4.8.27",
60
60
  "minipass-json-stream": "^1.0.2",
61
61
  "zod": "^4.2.0"
62
62
  },