@unchainedshop/core 4.8.29 → 4.8.30
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.
- package/lib/bulk-importer/handlers/product/upsertVariations.js +5 -3
- package/lib/directors/FileDirector.d.ts +4 -4
- package/lib/directors/FileDirector.js +2 -13
- package/lib/directors/registryDirector.d.ts +2 -0
- package/lib/directors/registryDirector.js +6 -0
- package/lib/factory/registerEnrollment.d.ts +8 -1
- package/lib/factory/registerEnrollment.js +12 -14
- package/lib/factory/registerQuotation.d.ts +2 -1
- package/lib/factory/registerQuotation.js +3 -2
- package/lib/plugins/PluginRegistry.d.ts +2 -1
- package/lib/plugins/PluginRegistry.js +16 -3
- package/lib/services/addCartQuotation.d.ts +9 -13
- package/lib/services/addCartQuotation.js +43 -38
- package/lib/services/reserveOrderDiscountsForCheckout.d.ts +5 -0
- package/lib/services/reserveOrderDiscountsForCheckout.js +34 -0
- package/lib/services/reserveOrderQuotationsForCheckout.d.ts +8 -0
- package/lib/services/reserveOrderQuotationsForCheckout.js +49 -0
- package/lib/services/simulateProductDispatching.d.ts +3 -1
- package/lib/services/simulateProductDispatching.js +3 -3
- package/lib/services/simulateProductInventory.d.ts +3 -1
- package/lib/services/simulateProductInventory.js +3 -3
- package/lib/services/supportedDeliveryProviders.js +9 -0
- package/lib/services/supportedPaymentProviders.js +9 -0
- package/lib/services/supportedWarehousingProviders.js +9 -0
- package/lib/services/suspendEnrollment.d.ts +5 -0
- package/lib/services/suspendEnrollment.js +21 -0
- package/lib/services/updateCartItem.d.ts +7 -7
- package/lib/services/updateCartItem.js +28 -25
- package/lib/services/updateEnrollmentPlan.d.ts +5 -0
- package/lib/services/updateEnrollmentPlan.js +26 -0
- package/package.json +1 -1
- package/lib/errors/common.d.ts +0 -568
- package/lib/errors/common.js +0 -789
- package/lib/errors/index.d.ts +0 -1
- package/lib/errors/index.js +0 -1
- package/lib/services/addCartDiscount.d.ts +0 -10
- package/lib/services/addCartDiscount.js +0 -27
- package/lib/services/addCartItem.d.ts +0 -15
- package/lib/services/addCartItem.js +0 -41
- package/lib/services/addEmail.d.ts +0 -7
- package/lib/services/addEmail.js +0 -17
- package/lib/services/addProductAssignment.d.ts +0 -3
- package/lib/services/addProductAssignment.js +0 -63
- package/lib/services/authenticateWithPassword.d.ts +0 -15
- package/lib/services/authenticateWithPassword.js +0 -34
- package/lib/services/changePassword.d.ts +0 -10
- package/lib/services/changePassword.js +0 -19
- package/lib/services/countOrdersWithFilters.d.ts +0 -3
- package/lib/services/countOrdersWithFilters.js +0 -25
- package/lib/services/createAssortment.d.ts +0 -7
- package/lib/services/createAssortment.js +0 -10
- package/lib/services/createBookmark.d.ts +0 -8
- package/lib/services/createBookmark.js +0 -21
- package/lib/services/createDeliveryProvider.d.ts +0 -6
- package/lib/services/createDeliveryProvider.js +0 -19
- package/lib/services/createEnrollment.d.ts +0 -17
- package/lib/services/createEnrollment.js +0 -33
- package/lib/services/createProduct.d.ts +0 -7
- package/lib/services/createProduct.js +0 -8
- package/lib/services/createProductBundleItem.d.ts +0 -5
- package/lib/services/createProductBundleItem.js +0 -25
- package/lib/services/createProductReview.d.ts +0 -8
- package/lib/services/createProductReview.js +0 -12
- package/lib/services/deleteDeadCarts.d.ts +0 -2
- package/lib/services/deleteDeadCarts.js +0 -17
- package/lib/services/deliverOrder.d.ts +0 -5
- package/lib/services/deliverOrder.js +0 -26
- package/lib/services/findActiveWorkTypes.d.ts +0 -2
- package/lib/services/findActiveWorkTypes.js +0 -6
- package/lib/services/findDeliveryInterfaces.d.ts +0 -7
- package/lib/services/findDeliveryInterfaces.js +0 -13
- package/lib/services/findOrdersWithFilters.d.ts +0 -9
- package/lib/services/findOrdersWithFilters.js +0 -25
- package/lib/services/findPaymentInterfaces.d.ts +0 -7
- package/lib/services/findPaymentInterfaces.js +0 -13
- package/lib/services/findWarehousingInterfaces.d.ts +0 -7
- package/lib/services/findWarehousingInterfaces.js +0 -13
- package/lib/services/getDeliveryDiscounts.d.ts +0 -8
- package/lib/services/getDeliveryDiscounts.js +0 -14
- package/lib/services/getPaymentDiscounts.d.ts +0 -8
- package/lib/services/getPaymentDiscounts.js +0 -14
- package/lib/services/getShopInfo.d.ts +0 -25
- package/lib/services/getShopInfo.js +0 -47
- package/lib/services/impersonateUser.d.ts +0 -8
- package/lib/services/impersonateUser.js +0 -20
- package/lib/services/loginAsGuest.d.ts +0 -10
- package/lib/services/loginAsGuest.js +0 -19
- package/lib/services/obfuscateWorkerData.d.ts +0 -4
- package/lib/services/obfuscateWorkerData.js +0 -4
- package/lib/services/orderPricingAccessors.d.ts +0 -18
- package/lib/services/orderPricingAccessors.js +0 -29
- package/lib/services/payOrder.d.ts +0 -5
- package/lib/services/payOrder.js +0 -25
- package/lib/services/registerUser.d.ts +0 -14
- package/lib/services/registerUser.js +0 -44
- package/lib/services/removeBookmark.d.ts +0 -6
- package/lib/services/removeBookmark.js +0 -10
- package/lib/services/removeCartItem.d.ts +0 -6
- package/lib/services/removeCartItem.js +0 -19
- package/lib/services/resetPasswordWithMigration.d.ts +0 -14
- package/lib/services/resetPasswordWithMigration.js +0 -31
- package/lib/services/resolveWorkType.d.ts +0 -1
- package/lib/services/resolveWorkType.js +0 -7
- package/lib/services/searchProductsWithAssortment.d.ts +0 -19
- package/lib/services/searchProductsWithAssortment.js +0 -17
- package/lib/services/toggleBookmark.d.ts +0 -8
- package/lib/services/toggleBookmark.js +0 -33
- package/lib/services/updateCart.d.ts +0 -15
- package/lib/services/updateCart.js +0 -27
- package/lib/services/updateEnrollment.d.ts +0 -13
- package/lib/services/updateEnrollment.js +0 -36
- package/lib/services/verifyEmailWithMigration.d.ts +0 -15
- package/lib/services/verifyEmailWithMigration.js +0 -23
package/lib/errors/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './common.ts';
|
package/lib/errors/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./common.js";
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { OrderDiscount } from '@unchainedshop/core-orders';
|
|
2
|
-
import type { Modules } from '../modules.ts';
|
|
3
|
-
import type { User } from '@unchainedshop/core-users';
|
|
4
|
-
export interface AddCartDiscountParams {
|
|
5
|
-
orderId?: string;
|
|
6
|
-
code: string;
|
|
7
|
-
user: User;
|
|
8
|
-
countryCode: string;
|
|
9
|
-
}
|
|
10
|
-
export declare function addCartDiscountService(this: Modules, params: AddCartDiscountParams): Promise<OrderDiscount>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { createManualOrderDiscountService } from "./createManualOrderDiscount.js";
|
|
2
|
-
import { updateCalculationService } from "./updateCalculation.js";
|
|
3
|
-
import { findOrInitCartService } from "./findOrInitCart.js";
|
|
4
|
-
import { OrderNotFoundError, OrderWrongStatusError, OrderDiscountCodeAlreadyPresentError, OrderDiscountCodeNotValidError, } from "../errors/index.js";
|
|
5
|
-
export async function addCartDiscountService(params) {
|
|
6
|
-
const { orderId, code, user, countryCode } = params;
|
|
7
|
-
const order = await findOrInitCartService.bind(this)({
|
|
8
|
-
orderId,
|
|
9
|
-
user,
|
|
10
|
-
countryCode,
|
|
11
|
-
});
|
|
12
|
-
if (!order) {
|
|
13
|
-
throw new OrderNotFoundError({ orderId: orderId || null });
|
|
14
|
-
}
|
|
15
|
-
if (!this.orders.isCart(order)) {
|
|
16
|
-
throw new OrderWrongStatusError({ status: order.status });
|
|
17
|
-
}
|
|
18
|
-
if (await this.orders.discounts.isDiscountCodeUsed({ code, orderId: order._id })) {
|
|
19
|
-
throw new OrderDiscountCodeAlreadyPresentError({ orderId: order._id, code });
|
|
20
|
-
}
|
|
21
|
-
const discount = await createManualOrderDiscountService.bind(this)({ order, code });
|
|
22
|
-
if (!discount) {
|
|
23
|
-
throw new OrderDiscountCodeNotValidError({ code });
|
|
24
|
-
}
|
|
25
|
-
await updateCalculationService.bind(this)(order._id);
|
|
26
|
-
return discount;
|
|
27
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type OrderPosition } from '@unchainedshop/core-orders';
|
|
2
|
-
import type { User } from '@unchainedshop/core-users';
|
|
3
|
-
import type { Modules } from '../modules.ts';
|
|
4
|
-
export interface AddCartItemParams {
|
|
5
|
-
orderId?: string;
|
|
6
|
-
productId: string;
|
|
7
|
-
quantity: number;
|
|
8
|
-
configuration?: {
|
|
9
|
-
key: string;
|
|
10
|
-
value: string;
|
|
11
|
-
}[];
|
|
12
|
-
user: User;
|
|
13
|
-
countryCode: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function addCartItemService(this: Modules, params: AddCartItemParams, context: any): Promise<OrderPosition>;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ordersSettings } from '@unchainedshop/core-orders';
|
|
2
|
-
import { findOrInitCartService } from "./findOrInitCart.js";
|
|
3
|
-
import { updateCalculationService } from "./updateCalculation.js";
|
|
4
|
-
import { ProductNotFoundError, OrderNotFoundError, OrderWrongStatusError, OrderQuantityTooLowError, } from "../errors/index.js";
|
|
5
|
-
export async function addCartItemService(params, context) {
|
|
6
|
-
const { orderId, productId: originalProductId, quantity, configuration, user, countryCode } = params;
|
|
7
|
-
if (quantity < 1) {
|
|
8
|
-
throw new OrderQuantityTooLowError({ quantity });
|
|
9
|
-
}
|
|
10
|
-
const originalProduct = await this.products.findProduct({ productId: originalProductId });
|
|
11
|
-
if (!originalProduct) {
|
|
12
|
-
throw new ProductNotFoundError({ productId: originalProductId });
|
|
13
|
-
}
|
|
14
|
-
const order = await findOrInitCartService.bind(this)({
|
|
15
|
-
orderId,
|
|
16
|
-
user,
|
|
17
|
-
countryCode,
|
|
18
|
-
});
|
|
19
|
-
if (!order) {
|
|
20
|
-
throw new OrderNotFoundError({ orderId });
|
|
21
|
-
}
|
|
22
|
-
if (!this.orders.isCart(order)) {
|
|
23
|
-
throw new OrderWrongStatusError({ status: order.status });
|
|
24
|
-
}
|
|
25
|
-
const product = await this.products.resolveOrderableProduct(originalProduct, { configuration });
|
|
26
|
-
await ordersSettings.validateOrderPosition({
|
|
27
|
-
order,
|
|
28
|
-
product,
|
|
29
|
-
configuration,
|
|
30
|
-
quantityDiff: quantity,
|
|
31
|
-
}, context);
|
|
32
|
-
const orderPosition = await this.orders.positions.addProductItem({
|
|
33
|
-
quantity,
|
|
34
|
-
configuration,
|
|
35
|
-
productId: product._id,
|
|
36
|
-
originalProductId,
|
|
37
|
-
orderId: order._id,
|
|
38
|
-
});
|
|
39
|
-
await updateCalculationService.bind(this)(order._id);
|
|
40
|
-
return (await this.orders.positions.findOrderPosition({ itemId: orderPosition._id }));
|
|
41
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { User } from '@unchainedshop/core-users';
|
|
2
|
-
import type { Modules } from '../modules.ts';
|
|
3
|
-
export interface AddEmailParams {
|
|
4
|
-
userId: string;
|
|
5
|
-
email: string;
|
|
6
|
-
}
|
|
7
|
-
export declare function addEmailService(this: Modules, params: AddEmailParams): Promise<User>;
|
package/lib/services/addEmail.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { UserNotFoundError, EmailAlreadyExistsError } from "../errors/index.js";
|
|
2
|
-
export async function addEmailService(params) {
|
|
3
|
-
const { userId, email } = params;
|
|
4
|
-
if (!(await this.users.userExists({ userId }))) {
|
|
5
|
-
throw new UserNotFoundError({ userId });
|
|
6
|
-
}
|
|
7
|
-
try {
|
|
8
|
-
await this.users.addEmail(userId, email);
|
|
9
|
-
}
|
|
10
|
-
catch (e) {
|
|
11
|
-
if (e.cause === 'EMAIL_INVALID') {
|
|
12
|
-
throw new EmailAlreadyExistsError({ email });
|
|
13
|
-
}
|
|
14
|
-
throw e;
|
|
15
|
-
}
|
|
16
|
-
return (await this.users.findUserById(userId));
|
|
17
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type Product, type ProductConfiguration } from '@unchainedshop/core-products';
|
|
2
|
-
import type { Modules } from '../modules.ts';
|
|
3
|
-
export declare function addProductAssignmentService(this: Modules, proxyId: string, productId: string, vectors: ProductConfiguration[]): Promise<Product | null>;
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { ProductType, } from '@unchainedshop/core-products';
|
|
2
|
-
import { ProductNotFoundError, ProductWrongTypeError, ProductVariationInfinityLoopError, ProductVariationVectorInvalidError, ProductVariationVectorAlreadySetError, } from "../errors/index.js";
|
|
3
|
-
const extractVariationMatrix = (variations = []) => {
|
|
4
|
-
const cartesianProduct = (arrays) => {
|
|
5
|
-
return arrays.reduce((acc, array) => acc.flatMap((item) => array.map((value) => [...item, value])), [
|
|
6
|
-
[],
|
|
7
|
-
]);
|
|
8
|
-
};
|
|
9
|
-
const keys = variations.map((item) => item.key);
|
|
10
|
-
const options = variations.map((item) => item.options);
|
|
11
|
-
const combinations = cartesianProduct(options);
|
|
12
|
-
return combinations.map((combination) => combination.reduce((acc, value, index) => {
|
|
13
|
-
acc[keys[index]] = value;
|
|
14
|
-
return acc;
|
|
15
|
-
}, {}));
|
|
16
|
-
};
|
|
17
|
-
const combinationExists = (matrix, combination) => {
|
|
18
|
-
return matrix.some((variation) => {
|
|
19
|
-
return (Object.keys(variation).length === Object.keys(combination).length &&
|
|
20
|
-
Object.entries(combination).every(([key, value]) => variation[key] === value));
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
export async function addProductAssignmentService(proxyId, productId, vectors) {
|
|
24
|
-
if (!(await this.products.productExists({ productId }))) {
|
|
25
|
-
throw new ProductNotFoundError({ productId });
|
|
26
|
-
}
|
|
27
|
-
const proxyProduct = await this.products.findProduct({ productId: proxyId });
|
|
28
|
-
if (!proxyProduct) {
|
|
29
|
-
throw new ProductNotFoundError({ productId: proxyId });
|
|
30
|
-
}
|
|
31
|
-
if (productId === proxyId) {
|
|
32
|
-
throw new ProductVariationInfinityLoopError({ productId });
|
|
33
|
-
}
|
|
34
|
-
if (proxyProduct.type !== ProductType.CONFIGURABLE_PRODUCT) {
|
|
35
|
-
throw new ProductWrongTypeError({
|
|
36
|
-
proxyId,
|
|
37
|
-
received: proxyProduct.type,
|
|
38
|
-
required: ProductType.CONFIGURABLE_PRODUCT,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
const variations = await this.products.variations.findProductVariations({
|
|
42
|
-
productId: proxyId,
|
|
43
|
-
});
|
|
44
|
-
const variationMatrix = extractVariationMatrix(variations);
|
|
45
|
-
const normalizedVectors = vectors?.reduce((prev, { key, value }) => {
|
|
46
|
-
return {
|
|
47
|
-
...prev,
|
|
48
|
-
[key]: value,
|
|
49
|
-
};
|
|
50
|
-
}, {});
|
|
51
|
-
if (!combinationExists(variationMatrix, normalizedVectors)) {
|
|
52
|
-
throw new ProductVariationVectorInvalidError({ proxyId, vectors });
|
|
53
|
-
}
|
|
54
|
-
const added = await this.products.assignments.addProxyAssignment({
|
|
55
|
-
productId,
|
|
56
|
-
proxyId,
|
|
57
|
-
vectors,
|
|
58
|
-
});
|
|
59
|
-
if (!added) {
|
|
60
|
-
throw new ProductVariationVectorAlreadySetError({ proxyId, vectors });
|
|
61
|
-
}
|
|
62
|
-
return this.products.findProduct({ productId: proxyId });
|
|
63
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { User } from '@unchainedshop/core-users';
|
|
2
|
-
import type { Modules } from '../modules.ts';
|
|
3
|
-
export interface AuthenticateWithPasswordParams {
|
|
4
|
-
username?: string;
|
|
5
|
-
email?: string;
|
|
6
|
-
password: string;
|
|
7
|
-
}
|
|
8
|
-
export interface HttpContext {
|
|
9
|
-
remoteAddress?: string;
|
|
10
|
-
remotePort?: number;
|
|
11
|
-
userAgent?: string;
|
|
12
|
-
locale?: string;
|
|
13
|
-
countryCode: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function authenticateWithPasswordService(this: Modules, params: AuthenticateWithPasswordParams, httpContext: HttpContext, currentUserId?: string): Promise<User>;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { migrateUserDataService } from "./migrateUserData.js";
|
|
2
|
-
import { nextUserCartService } from "./nextUserCart.js";
|
|
3
|
-
import { UsernameOrEmailRequiredError, InvalidCredentialsError } from "../errors/index.js";
|
|
4
|
-
export async function authenticateWithPasswordService(params, httpContext, currentUserId) {
|
|
5
|
-
const { username, email, password } = params;
|
|
6
|
-
if (!username && !email) {
|
|
7
|
-
throw new UsernameOrEmailRequiredError();
|
|
8
|
-
}
|
|
9
|
-
let user = username
|
|
10
|
-
? await this.users.findUserByUsername(username)
|
|
11
|
-
: await this.users.findUserByEmail(email);
|
|
12
|
-
if (!user) {
|
|
13
|
-
throw new InvalidCredentialsError({ username, email });
|
|
14
|
-
}
|
|
15
|
-
const verified = user.services?.password && (await this.users.verifyPassword(user.services.password, password));
|
|
16
|
-
if (!verified) {
|
|
17
|
-
throw new InvalidCredentialsError({ username, email });
|
|
18
|
-
}
|
|
19
|
-
if (user.guest) {
|
|
20
|
-
await this.users.updateGuest(user, false);
|
|
21
|
-
}
|
|
22
|
-
user = (await this.users.updateHeartbeat(user._id, {
|
|
23
|
-
remoteAddress: httpContext.remoteAddress,
|
|
24
|
-
remotePort: httpContext.remotePort,
|
|
25
|
-
userAgent: httpContext.userAgent,
|
|
26
|
-
locale: httpContext.locale,
|
|
27
|
-
countryCode: httpContext.countryCode,
|
|
28
|
-
}));
|
|
29
|
-
if (currentUserId) {
|
|
30
|
-
await migrateUserDataService.bind(this)(currentUserId, user._id);
|
|
31
|
-
}
|
|
32
|
-
await nextUserCartService.bind(this)({ user, countryCode: httpContext.countryCode });
|
|
33
|
-
return user;
|
|
34
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Modules } from '../modules.ts';
|
|
2
|
-
export interface ChangePasswordParams {
|
|
3
|
-
userId: string;
|
|
4
|
-
oldPassword: string;
|
|
5
|
-
newPassword: string;
|
|
6
|
-
}
|
|
7
|
-
export interface ChangePasswordResult {
|
|
8
|
-
success: boolean;
|
|
9
|
-
}
|
|
10
|
-
export declare function changePasswordService(this: Modules, params: ChangePasswordParams): Promise<ChangePasswordResult>;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { InvalidCredentialsError, PasswordInvalidError } from "../errors/index.js";
|
|
2
|
-
export async function changePasswordService(params) {
|
|
3
|
-
const { userId, oldPassword, newPassword } = params;
|
|
4
|
-
const user = await this.users.findUserById(userId);
|
|
5
|
-
const isValidCurrentPassword = user?.services?.password && (await this.users.verifyPassword(user.services.password, oldPassword));
|
|
6
|
-
if (!isValidCurrentPassword) {
|
|
7
|
-
throw new InvalidCredentialsError();
|
|
8
|
-
}
|
|
9
|
-
try {
|
|
10
|
-
await this.users.setPassword(user._id, newPassword);
|
|
11
|
-
return { success: true };
|
|
12
|
-
}
|
|
13
|
-
catch (e) {
|
|
14
|
-
if (e.cause === 'PASSWORD_INVALID') {
|
|
15
|
-
throw new PasswordInvalidError({ userId });
|
|
16
|
-
}
|
|
17
|
-
throw e;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export async function countOrdersWithFiltersService(params) {
|
|
2
|
-
const { paymentProviderIds, deliveryProviderIds, ...restParams } = params;
|
|
3
|
-
if (!paymentProviderIds?.length && !deliveryProviderIds?.length) {
|
|
4
|
-
return this.orders.count(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 0;
|
|
17
|
-
}
|
|
18
|
-
const paymentIds = orderPayments.map((p) => p._id);
|
|
19
|
-
const deliveryIds = orderDeliveries.map((d) => d._id);
|
|
20
|
-
return this.orders.count({
|
|
21
|
-
...restParams,
|
|
22
|
-
paymentIds,
|
|
23
|
-
deliveryIds,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Assortment, AssortmentText } from '@unchainedshop/core-assortments';
|
|
2
|
-
import type { Modules } from '../modules.ts';
|
|
3
|
-
export interface CreateAssortmentParams {
|
|
4
|
-
assortment: Partial<Assortment>;
|
|
5
|
-
texts?: AssortmentText[];
|
|
6
|
-
}
|
|
7
|
-
export declare function createAssortmentService(this: Modules, params: CreateAssortmentParams): Promise<Assortment>;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export async function createAssortmentService(params) {
|
|
2
|
-
const { assortment: assortmentData, texts } = params;
|
|
3
|
-
const assortment = await this.assortments.create({
|
|
4
|
-
...assortmentData,
|
|
5
|
-
});
|
|
6
|
-
if (texts) {
|
|
7
|
-
await this.assortments.texts.updateTexts(assortment._id, texts);
|
|
8
|
-
}
|
|
9
|
-
return assortment;
|
|
10
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Bookmark } from '@unchainedshop/core-bookmarks';
|
|
2
|
-
import type { Modules } from '../modules.ts';
|
|
3
|
-
export interface CreateBookmarkParams {
|
|
4
|
-
productId: string;
|
|
5
|
-
userId: string;
|
|
6
|
-
meta?: any;
|
|
7
|
-
}
|
|
8
|
-
export declare function createBookmarkService(this: Modules, params: CreateBookmarkParams): Promise<Bookmark>;
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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>;
|
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
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>;
|
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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>;
|
|
@@ -1,8 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
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>;
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
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>;
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
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,5 +0,0 @@
|
|
|
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>;
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
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[]>;
|
|
@@ -1,13 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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[]>;
|