@unchainedshop/core 4.6.0 → 4.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/lib/bulk-exporter/createBulkExporter.d.ts +33 -0
  2. package/lib/bulk-exporter/createBulkExporter.js +46 -0
  3. package/lib/bulk-exporter/handlers/exportAssortmentsHandler.d.ts +38 -0
  4. package/lib/bulk-exporter/handlers/exportAssortmentsHandler.js +137 -0
  5. package/lib/bulk-exporter/handlers/exportFiltersHandler.d.ts +26 -0
  6. package/lib/bulk-exporter/handlers/exportFiltersHandler.js +88 -0
  7. package/lib/bulk-exporter/handlers/exportProductsHandler.d.ts +40 -0
  8. package/lib/bulk-exporter/handlers/exportProductsHandler.js +238 -0
  9. package/lib/bulk-exporter/handlers/exportUsersHandler.d.ts +40 -0
  10. package/lib/bulk-exporter/handlers/exportUsersHandler.js +340 -0
  11. package/lib/bulk-exporter/handlers/generateCSVFileAndUrl.d.ts +13 -0
  12. package/lib/bulk-exporter/handlers/generateCSVFileAndUrl.js +21 -0
  13. package/lib/bulk-exporter/handlers/toCSV.d.ts +2 -0
  14. package/lib/bulk-exporter/handlers/toCSV.js +5 -0
  15. package/lib/bulk-exporter/index.d.ts +3 -0
  16. package/lib/bulk-exporter/index.js +3 -0
  17. package/lib/core-index.d.ts +7 -1
  18. package/lib/core-index.js +5 -1
  19. package/lib/directors/FileDirector.d.ts +10 -0
  20. package/lib/directors/FileDirector.js +25 -0
  21. package/lib/directors/WorkerAdapter.d.ts +2 -0
  22. package/lib/errors/common.d.ts +568 -0
  23. package/lib/errors/common.js +789 -0
  24. package/lib/errors/index.d.ts +1 -0
  25. package/lib/errors/index.js +1 -0
  26. package/lib/plugins/PluginRegistry.d.ts +42 -0
  27. package/lib/plugins/PluginRegistry.js +113 -0
  28. package/lib/services/addCartDiscount.d.ts +10 -0
  29. package/lib/services/addCartDiscount.js +27 -0
  30. package/lib/services/addCartItem.d.ts +15 -0
  31. package/lib/services/addCartItem.js +41 -0
  32. package/lib/services/addCartQuotation.d.ts +16 -0
  33. package/lib/services/addCartQuotation.js +52 -0
  34. package/lib/services/addEmail.d.ts +7 -0
  35. package/lib/services/addEmail.js +17 -0
  36. package/lib/services/addProductAssignment.d.ts +3 -0
  37. package/lib/services/addProductAssignment.js +63 -0
  38. package/lib/services/authenticateWithPassword.d.ts +15 -0
  39. package/lib/services/authenticateWithPassword.js +34 -0
  40. package/lib/services/changePassword.d.ts +10 -0
  41. package/lib/services/changePassword.js +19 -0
  42. package/lib/services/countOrdersWithFilters.d.ts +3 -0
  43. package/lib/services/countOrdersWithFilters.js +25 -0
  44. package/lib/services/createAssortment.d.ts +7 -0
  45. package/lib/services/createAssortment.js +10 -0
  46. package/lib/services/createBookmark.d.ts +8 -0
  47. package/lib/services/createBookmark.js +21 -0
  48. package/lib/services/createDeliveryProvider.d.ts +6 -0
  49. package/lib/services/createDeliveryProvider.js +19 -0
  50. package/lib/services/createEnrollment.d.ts +17 -0
  51. package/lib/services/createEnrollment.js +33 -0
  52. package/lib/services/createProduct.d.ts +7 -0
  53. package/lib/services/createProduct.js +8 -0
  54. package/lib/services/createProductBundleItem.d.ts +5 -0
  55. package/lib/services/createProductBundleItem.js +25 -0
  56. package/lib/services/createProductReview.d.ts +8 -0
  57. package/lib/services/createProductReview.js +12 -0
  58. package/lib/services/deliverOrder.d.ts +5 -0
  59. package/lib/services/deliverOrder.js +26 -0
  60. package/lib/services/findActiveWorkTypes.d.ts +2 -0
  61. package/lib/services/findActiveWorkTypes.js +6 -0
  62. package/lib/services/findDeliveryInterfaces.d.ts +7 -0
  63. package/lib/services/findDeliveryInterfaces.js +13 -0
  64. package/lib/services/findOrdersWithFilters.d.ts +9 -0
  65. package/lib/services/findOrdersWithFilters.js +25 -0
  66. package/lib/services/findPaymentInterfaces.d.ts +7 -0
  67. package/lib/services/findPaymentInterfaces.js +13 -0
  68. package/lib/services/findWarehousingInterfaces.d.ts +7 -0
  69. package/lib/services/findWarehousingInterfaces.js +13 -0
  70. package/lib/services/getDeliveryDiscounts.d.ts +8 -0
  71. package/lib/services/getDeliveryDiscounts.js +14 -0
  72. package/lib/services/getPaymentDiscounts.d.ts +8 -0
  73. package/lib/services/getPaymentDiscounts.js +14 -0
  74. package/lib/services/getShopInfo.d.ts +25 -0
  75. package/lib/services/getShopInfo.js +47 -0
  76. package/lib/services/impersonateUser.d.ts +8 -0
  77. package/lib/services/impersonateUser.js +20 -0
  78. package/lib/services/loginAsGuest.d.ts +10 -0
  79. package/lib/services/loginAsGuest.js +19 -0
  80. package/lib/services/obfuscateWorkerData.d.ts +4 -0
  81. package/lib/services/obfuscateWorkerData.js +4 -0
  82. package/lib/services/orderPricingAccessors.d.ts +18 -0
  83. package/lib/services/orderPricingAccessors.js +29 -0
  84. package/lib/services/payOrder.d.ts +5 -0
  85. package/lib/services/payOrder.js +25 -0
  86. package/lib/services/registerUser.d.ts +14 -0
  87. package/lib/services/registerUser.js +44 -0
  88. package/lib/services/removeBookmark.d.ts +6 -0
  89. package/lib/services/removeBookmark.js +10 -0
  90. package/lib/services/removeCartItem.d.ts +6 -0
  91. package/lib/services/removeCartItem.js +19 -0
  92. package/lib/services/resetPasswordWithMigration.d.ts +14 -0
  93. package/lib/services/resetPasswordWithMigration.js +31 -0
  94. package/lib/services/resolveWorkType.d.ts +1 -0
  95. package/lib/services/resolveWorkType.js +7 -0
  96. package/lib/services/searchProductsWithAssortment.d.ts +19 -0
  97. package/lib/services/searchProductsWithAssortment.js +17 -0
  98. package/lib/services/toggleBookmark.d.ts +8 -0
  99. package/lib/services/toggleBookmark.js +33 -0
  100. package/lib/services/updateCart.d.ts +15 -0
  101. package/lib/services/updateCart.js +27 -0
  102. package/lib/services/updateCartItem.d.ts +11 -0
  103. package/lib/services/updateCartItem.js +37 -0
  104. package/lib/services/updateEnrollment.d.ts +13 -0
  105. package/lib/services/updateEnrollment.js +36 -0
  106. package/lib/services/verifyEmailWithMigration.d.ts +15 -0
  107. package/lib/services/verifyEmailWithMigration.js +23 -0
  108. package/lib/utils/getFileAdapter.d.ts +1 -0
  109. package/lib/utils/getFileAdapter.js +7 -0
  110. package/package.json +1 -1
@@ -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.6.0",
4
+ "version": "4.6.2",
5
5
  "main": "lib/core-index.js",
6
6
  "types": "lib/core-index.d.ts",
7
7
  "type": "module",