@unchainedshop/core 5.0.0-alpha.1 → 5.0.0-alpha.11
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/README.md +92 -546
- package/lib/bulk-exporter/createBulkExporter.js +1 -1
- package/lib/bulk-exporter/handlers/exportProductsHandler.js +2 -2
- package/lib/bulk-exporter/handlers/exportUsersHandler.js +1 -0
- package/lib/bulk-importer/handlers/assortment/create.js +1 -3
- package/lib/bulk-importer/handlers/assortment/update.js +1 -1
- package/lib/bulk-importer/handlers/product/create.d.ts +150 -35
- package/lib/bulk-importer/handlers/product/create.js +35 -16
- package/lib/bulk-importer/handlers/product/update.d.ts +78 -36
- package/lib/bulk-importer/handlers/product/update.js +8 -48
- package/lib/core-index.d.ts +1 -2
- package/lib/core-index.js +2 -18
- package/lib/directors/BaseDiscountAdapter.d.ts +3 -0
- package/lib/directors/BaseDiscountDirector.d.ts +2 -2
- package/lib/directors/BaseDiscountDirector.js +7 -9
- package/lib/directors/BasePricingDirector.d.ts +2 -2
- package/lib/directors/BasePricingDirector.js +3 -6
- package/lib/directors/BasePricingSheet.d.ts +2 -0
- package/lib/directors/BaseWorker.js +3 -2
- package/lib/directors/DeliveryDirector.d.ts +1 -1
- package/lib/directors/DeliveryDirector.js +2 -12
- package/lib/directors/DeliveryPricingDirector.js +1 -10
- package/lib/directors/DeliveryPricingSheet.js +9 -4
- package/lib/directors/EnrollmentAdapter.d.ts +11 -1
- package/lib/directors/EnrollmentAdapter.js +7 -2
- package/lib/directors/EnrollmentDirector.d.ts +3 -2
- package/lib/directors/EnrollmentDirector.js +9 -19
- package/lib/directors/FileDirector.d.ts +4 -4
- package/lib/directors/FileDirector.js +2 -13
- package/lib/directors/FilterDirector.d.ts +1 -1
- package/lib/directors/FilterDirector.js +25 -32
- package/lib/directors/OrderDiscountDirector.d.ts +1 -15
- package/lib/directors/OrderDiscountDirector.js +1 -13
- package/lib/directors/OrderPricingDirector.js +1 -10
- package/lib/directors/OrderPricingSheet.d.ts +1 -0
- package/lib/directors/OrderPricingSheet.js +16 -17
- package/lib/directors/PaymentDirector.d.ts +1 -1
- package/lib/directors/PaymentDirector.js +2 -12
- package/lib/directors/PaymentPricingDirector.js +1 -10
- package/lib/directors/PaymentPricingSheet.js +9 -4
- package/lib/directors/ProductDiscountDirector.d.ts +1 -15
- package/lib/directors/ProductDiscountDirector.js +1 -13
- package/lib/directors/ProductPricingAdapter.d.ts +1 -0
- package/lib/directors/ProductPricingDirector.js +2 -10
- package/lib/directors/ProductPricingSheet.js +7 -4
- package/lib/directors/QuotationAdapter.js +5 -2
- package/lib/directors/QuotationDirector.d.ts +1 -1
- package/lib/directors/QuotationDirector.js +2 -14
- package/lib/directors/WarehousingDirector.js +16 -34
- package/lib/directors/WorkerDirector.d.ts +7 -1
- package/lib/directors/WorkerDirector.js +29 -29
- package/lib/directors/registryDirector.d.ts +2 -0
- package/lib/directors/registryDirector.js +6 -0
- package/lib/errors.d.ts +1 -0
- package/lib/errors.js +5 -0
- package/lib/factory/index.d.ts +12 -1
- package/lib/factory/index.js +12 -1
- package/lib/factory/registerAssortmentSearchFilter.d.ts +2 -1
- package/lib/factory/registerAssortmentSearchFilter.js +6 -3
- package/lib/factory/registerDeliveryPricing.d.ts +7 -0
- package/lib/factory/registerDeliveryPricing.js +30 -0
- package/lib/factory/registerDeliveryProvider.d.ts +12 -0
- package/lib/factory/registerDeliveryProvider.js +46 -0
- package/lib/factory/registerEnrollment.d.ts +25 -0
- package/lib/factory/registerEnrollment.js +41 -0
- package/lib/factory/registerFileAdapter.d.ts +17 -0
- package/lib/factory/registerFileAdapter.js +24 -0
- package/lib/factory/registerOrderDiscount.d.ts +13 -0
- package/lib/factory/registerOrderDiscount.js +39 -0
- package/lib/factory/registerOrderPricing.d.ts +7 -0
- package/lib/factory/registerOrderPricing.js +30 -0
- package/lib/factory/registerPaymentPricing.d.ts +7 -0
- package/lib/factory/registerPaymentPricing.js +30 -0
- package/lib/factory/registerPaymentProvider.d.ts +15 -0
- package/lib/factory/registerPaymentProvider.js +53 -0
- package/lib/factory/registerProductDiscount.d.ts +20 -0
- package/lib/factory/registerProductDiscount.js +47 -0
- package/lib/factory/registerProductDiscoverabilityFilter.d.ts +2 -1
- package/lib/factory/registerProductDiscoverabilityFilter.js +6 -3
- package/lib/factory/registerProductPricing.d.ts +7 -0
- package/lib/factory/registerProductPricing.js +30 -0
- package/lib/factory/registerProductSearchFilter.d.ts +2 -1
- package/lib/factory/registerProductSearchFilter.js +4 -3
- package/lib/factory/registerQuotation.d.ts +13 -0
- package/lib/factory/registerQuotation.js +53 -0
- package/lib/factory/registerVirtualWarehousing.js +1 -1
- package/lib/factory/registerWorker.js +1 -1
- package/lib/plugins/PluginRegistry.d.ts +2 -1
- package/lib/plugins/PluginRegistry.js +19 -4
- package/lib/services/addCartQuotation.d.ts +9 -13
- package/lib/services/addCartQuotation.js +43 -38
- package/lib/services/addMultipleCartProducts.js +3 -2
- package/lib/services/bulkAssignProductsToAssortment.d.ts +8 -0
- package/lib/services/bulkAssignProductsToAssortment.js +11 -0
- package/lib/services/bulkDeleteUsers.d.ts +7 -0
- package/lib/services/bulkDeleteUsers.js +11 -0
- package/lib/services/bulkRemoveFilters.d.ts +7 -0
- package/lib/services/bulkRemoveFilters.js +10 -0
- package/lib/services/bulkRemoveProducts.d.ts +7 -0
- package/lib/services/bulkRemoveProducts.js +23 -0
- package/lib/services/bulkSetFilterActive.d.ts +8 -0
- package/lib/services/bulkSetFilterActive.js +12 -0
- package/lib/services/calculateDiscountTotal.d.ts +5 -1
- package/lib/services/calculateDiscountTotal.js +36 -28
- package/lib/services/checkoutOrder.js +8 -0
- package/lib/services/createFilter.d.ts +3 -0
- package/lib/services/createFilter.js +6 -0
- package/lib/services/createFilterOption.d.ts +5 -0
- package/lib/services/createFilterOption.js +8 -0
- package/lib/services/createSignedURL.js +2 -1
- package/lib/services/deleteCart.d.ts +2 -0
- package/lib/services/deleteCart.js +7 -0
- package/lib/services/deleteUser.js +2 -5
- package/lib/services/index.d.ts +32 -1
- package/lib/services/index.js +32 -1
- package/lib/services/initCartProviders.js +1 -0
- package/lib/services/initializeEnrollment.d.ts +1 -1
- package/lib/services/initializeEnrollment.js +11 -0
- package/lib/services/isTokenInvalidateable.d.ts +3 -1
- package/lib/services/isTokenInvalidateable.js +2 -2
- package/lib/services/loadFilterOptions.js +3 -3
- package/lib/services/migrateOrderCart.js +2 -2
- package/lib/services/migrateUserData.js +3 -0
- package/lib/services/processEnrollment.js +8 -4
- package/lib/services/processOrder.js +7 -6
- package/lib/services/processQuotation.js +11 -13
- package/lib/services/proposeQuotation.js +3 -0
- package/lib/services/removeFilterOption.d.ts +6 -0
- package/lib/services/removeFilterOption.js +8 -0
- package/lib/services/removeProduct.js +2 -1
- 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/simulateConfigurablePriceRange.js +1 -1
- package/lib/services/simulateDeliveryPricing.js +1 -1
- package/lib/services/simulatePaymentPricing.js +1 -1
- 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/terminateEnrollment.d.ts +6 -2
- package/lib/services/terminateEnrollment.js +27 -7
- package/lib/services/updateCalculation.js +2 -1
- 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/lib/services/updateFilter.d.ts +3 -0
- package/lib/services/updateFilter.js +8 -0
- package/lib/services/uploadFileFromStream.js +2 -1
- package/lib/services/validateOrder.js +13 -9
- package/package.json +29 -23
- 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/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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { supportedWarehousingProvidersService } from "./supportedWarehousingProviders.js";
|
|
2
2
|
import { WarehousingDirector } from "../directors/WarehousingDirector.js";
|
|
3
|
-
export async function simulateProductDispatchingService({ product, quantity, referenceDate, }) {
|
|
4
|
-
const deliveryProviders = await this.delivery.allProviders();
|
|
3
|
+
export async function simulateProductDispatchingService({ product, quantity, referenceDate, deliveryProviderType, }) {
|
|
4
|
+
const deliveryProviders = (await this.delivery.allProviders()).filter(({ type }) => !deliveryProviderType || type === deliveryProviderType);
|
|
5
5
|
return deliveryProviders.reduce(async (oldResult, deliveryProvider) => {
|
|
6
6
|
const result = await oldResult;
|
|
7
7
|
const warehousingProviders = await supportedWarehousingProvidersService.bind(this)({
|
|
@@ -25,6 +25,6 @@ export async function simulateProductDispatchingService({ product, quantity, ref
|
|
|
25
25
|
...dispatch,
|
|
26
26
|
};
|
|
27
27
|
}));
|
|
28
|
-
return result.concat(
|
|
28
|
+
return result.concat(mappedWarehousingProviders);
|
|
29
29
|
}, Promise.resolve([]));
|
|
30
30
|
}
|
|
@@ -2,9 +2,11 @@ import type { Modules } from '../modules.ts';
|
|
|
2
2
|
import type { Product } from '@unchainedshop/core-products';
|
|
3
3
|
import type { WarehousingContext } from '../directors/WarehousingAdapter.ts';
|
|
4
4
|
import type { WarehousingProvider } from '@unchainedshop/core-warehousing';
|
|
5
|
-
|
|
5
|
+
import type { DeliveryProviderType } from '@unchainedshop/core-delivery';
|
|
6
|
+
export declare function simulateProductInventoryService(this: Modules, { product, referenceDate, deliveryProviderType, }: {
|
|
6
7
|
product: Product;
|
|
7
8
|
referenceDate?: Date;
|
|
9
|
+
deliveryProviderType?: DeliveryProviderType | null;
|
|
8
10
|
}): Promise<(WarehousingContext & {
|
|
9
11
|
quantity?: number;
|
|
10
12
|
} & {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { supportedWarehousingProvidersService } from "./supportedWarehousingProviders.js";
|
|
2
2
|
import { WarehousingDirector } from "../directors/WarehousingDirector.js";
|
|
3
|
-
export async function simulateProductInventoryService({ product, referenceDate, }) {
|
|
4
|
-
const deliveryProviders = await this.delivery.allProviders();
|
|
3
|
+
export async function simulateProductInventoryService({ product, referenceDate, deliveryProviderType, }) {
|
|
4
|
+
const deliveryProviders = (await this.delivery.allProviders()).filter(({ type }) => !deliveryProviderType || type === deliveryProviderType);
|
|
5
5
|
return deliveryProviders.reduce(async (oldResult, deliveryProvider) => {
|
|
6
6
|
const result = await oldResult;
|
|
7
7
|
const warehousingProviders = await supportedWarehousingProvidersService.bind(this)({
|
|
@@ -24,6 +24,6 @@ export async function simulateProductInventoryService({ product, referenceDate,
|
|
|
24
24
|
...stock,
|
|
25
25
|
};
|
|
26
26
|
}));
|
|
27
|
-
return result.concat(
|
|
27
|
+
return result.concat(mappedWarehousingProviders);
|
|
28
28
|
}, Promise.resolve([]));
|
|
29
29
|
}
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { deliverySettings } from '@unchainedshop/core-delivery';
|
|
2
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
3
|
import { DeliveryDirector } from "../directors/index.js";
|
|
4
|
+
const logger = createLogger('unchained:core');
|
|
3
5
|
export async function supportedDeliveryProvidersService(params) {
|
|
4
6
|
const allProviders = await this.delivery.allProviders();
|
|
5
7
|
const providers = (await Promise.all(allProviders.map(async (provider) => {
|
|
8
|
+
if (!DeliveryDirector.getAdapter(provider.adapterKey)) {
|
|
9
|
+
logger.warn('Delivery provider skipped, its adapter is not registered', {
|
|
10
|
+
deliveryProviderId: provider._id,
|
|
11
|
+
adapterKey: provider.adapterKey,
|
|
12
|
+
});
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
6
15
|
const adapter = await DeliveryDirector.actions(provider, params, { modules: this });
|
|
7
16
|
return adapter.isActive() ? [provider] : [];
|
|
8
17
|
}))).flat();
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import { paymentSettings } from '@unchainedshop/core-payment';
|
|
2
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
3
|
import { PaymentDirector } from "../directors/PaymentDirector.js";
|
|
4
|
+
const logger = createLogger('unchained:core');
|
|
3
5
|
export async function supportedPaymentProvidersService(params) {
|
|
4
6
|
const allProviders = await this.payment.paymentProviders.allProviders();
|
|
5
7
|
const providers = (await Promise.all(allProviders.map(async (provider) => {
|
|
8
|
+
if (!PaymentDirector.getAdapter(provider.adapterKey)) {
|
|
9
|
+
logger.warn('Payment provider skipped, its adapter is not registered', {
|
|
10
|
+
paymentProviderId: provider._id,
|
|
11
|
+
adapterKey: provider.adapterKey,
|
|
12
|
+
});
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
6
15
|
const adapter = await PaymentDirector.actions(provider, params, { modules: this });
|
|
7
16
|
return adapter.isActive() ? [provider] : [];
|
|
8
17
|
}))).flat();
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
1
2
|
import { WarehousingDirector } from "../directors/index.js";
|
|
3
|
+
const logger = createLogger('unchained:core');
|
|
2
4
|
export async function supportedWarehousingProvidersService(params) {
|
|
3
5
|
const allProviders = await this.warehousing.allProviders();
|
|
4
6
|
const providers = (await Promise.all(allProviders.map(async (provider) => {
|
|
7
|
+
if (!WarehousingDirector.getAdapter(provider.adapterKey)) {
|
|
8
|
+
logger.warn('Warehousing provider skipped, its adapter is not registered', {
|
|
9
|
+
warehousingProviderId: provider._id,
|
|
10
|
+
adapterKey: provider.adapterKey,
|
|
11
|
+
});
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
5
14
|
const adapter = await WarehousingDirector.actions(provider, params, { modules: this });
|
|
6
15
|
return adapter.isActive() ? [provider] : [];
|
|
7
16
|
}))).flat();
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
|
|
2
|
+
import { addMessageService } from "./addMessage.js";
|
|
3
|
+
export async function suspendEnrollmentService(enrollment, { resumeAt } = {}) {
|
|
4
|
+
if (enrollment.status === EnrollmentStatus.TERMINATED)
|
|
5
|
+
return enrollment;
|
|
6
|
+
let updatedEnrollment = (await this.enrollments.updateStatus(enrollment._id, {
|
|
7
|
+
status: EnrollmentStatus.SUSPENDED,
|
|
8
|
+
info: 'suspended manually',
|
|
9
|
+
}));
|
|
10
|
+
if (resumeAt) {
|
|
11
|
+
updatedEnrollment = (await this.enrollments.updateResumeAt(enrollment._id, resumeAt));
|
|
12
|
+
}
|
|
13
|
+
const user = await this.users.findUserById(enrollment.userId);
|
|
14
|
+
const locale = this.users.userLocale(user);
|
|
15
|
+
await addMessageService.bind(this)('ENROLLMENT_STATUS', {
|
|
16
|
+
reason: 'status_change',
|
|
17
|
+
locale: locale.baseName,
|
|
18
|
+
enrollmentId: updatedEnrollment._id,
|
|
19
|
+
});
|
|
20
|
+
return updatedEnrollment;
|
|
21
|
+
}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
import { type Enrollment } from '@unchainedshop/core-enrollments';
|
|
2
|
-
|
|
1
|
+
import { type Enrollment, type EnrollmentTerminationReason } from '@unchainedshop/core-enrollments';
|
|
2
|
+
import type { Modules } from '../modules.ts';
|
|
3
|
+
export declare function terminateEnrollmentService(this: Modules, enrollment: Enrollment, { reason, comment }?: {
|
|
4
|
+
reason?: EnrollmentTerminationReason;
|
|
5
|
+
comment?: string;
|
|
6
|
+
}): Promise<Enrollment>;
|
|
@@ -1,14 +1,34 @@
|
|
|
1
|
-
import { EnrollmentStatus } from '@unchainedshop/core-enrollments';
|
|
1
|
+
import { EnrollmentStatus, } from '@unchainedshop/core-enrollments';
|
|
2
2
|
import { processEnrollmentService } from "./processEnrollment.js";
|
|
3
3
|
import { addMessageService } from "./addMessage.js";
|
|
4
|
-
|
|
4
|
+
import { EnrollmentDirector } from "../core-index.js";
|
|
5
|
+
import { createServiceError } from "../errors.js";
|
|
6
|
+
export async function terminateEnrollmentService(enrollment, { reason, comment } = {}) {
|
|
5
7
|
if (enrollment.status === EnrollmentStatus.TERMINATED)
|
|
6
8
|
return enrollment;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
|
|
9
|
+
const product = await this.products.findProduct({ productId: enrollment.productId });
|
|
10
|
+
if (!product)
|
|
11
|
+
throw createServiceError('ProductNotFoundError', 'Product not found for enrollment');
|
|
12
|
+
const director = await EnrollmentDirector.actions({ enrollment, product }, { modules: this });
|
|
13
|
+
const terminationDate = await director.terminationDate({ referenceDate: new Date() });
|
|
14
|
+
if (!terminationDate) {
|
|
15
|
+
throw createServiceError('EnrollmentTerminationNotAllowedError', 'Enrollment termination is not allowed at this time');
|
|
16
|
+
}
|
|
17
|
+
const expires = new Date(Math.min(Math.max(terminationDate.getTime(), enrollment.minimumCommitmentEnd?.getTime() ?? 0), enrollment.expires?.getTime() ?? Infinity));
|
|
18
|
+
if (reason || comment) {
|
|
19
|
+
await this.enrollments.updateCancellation(enrollment._id, { reason, comment });
|
|
20
|
+
}
|
|
21
|
+
let updatedEnrollment;
|
|
22
|
+
if (expires.getTime() > Date.now()) {
|
|
23
|
+
updatedEnrollment = (await this.enrollments.updateExpiry(enrollment._id, expires));
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
updatedEnrollment = (await this.enrollments.updateStatus(enrollment._id, {
|
|
27
|
+
status: EnrollmentStatus.TERMINATED,
|
|
28
|
+
info: 'terminated manually',
|
|
29
|
+
}));
|
|
30
|
+
updatedEnrollment = await processEnrollmentService.bind(this)(updatedEnrollment);
|
|
31
|
+
}
|
|
12
32
|
const user = await this.users.findUserById(enrollment.userId);
|
|
13
33
|
const locale = this.users.userLocale(user);
|
|
14
34
|
await addMessageService.bind(this)('ENROLLMENT_STATUS', {
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { OrderDiscountTrigger, } from '@unchainedshop/core-orders';
|
|
2
2
|
import { initCartProvidersService } from "./initCartProviders.js";
|
|
3
3
|
import { updateSchedulingService } from "./updateScheduling.js";
|
|
4
|
+
import { createServiceError } from "../errors.js";
|
|
4
5
|
import { OrderDiscountDirector, OrderPricingDirector, DeliveryPricingDirector, ProductPricingDirector, PaymentPricingDirector, } from "../directors/index.js";
|
|
5
6
|
export async function updateCalculationService(orderId) {
|
|
6
7
|
let order = await this.orders.findOrder({ orderId });
|
|
7
8
|
if (!order)
|
|
8
|
-
throw
|
|
9
|
+
throw createServiceError('OrderNotFoundError', 'Order not found');
|
|
9
10
|
if (order.status !== null)
|
|
10
11
|
return order;
|
|
11
12
|
const discounts = await this.orders.discounts.findOrderDiscounts({
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { type OrderPosition } from '@unchainedshop/core-orders';
|
|
1
|
+
import { type Order, type OrderPosition } from '@unchainedshop/core-orders';
|
|
2
2
|
import type { Modules } from '../modules.ts';
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare function updateCartItemService(this: Modules, { order, item, quantity, configuration, }: {
|
|
4
|
+
order: Order;
|
|
5
|
+
item: OrderPosition;
|
|
6
|
+
quantity?: number | null;
|
|
6
7
|
configuration?: {
|
|
7
8
|
key: string;
|
|
8
9
|
value: string;
|
|
9
|
-
}[];
|
|
10
|
-
}
|
|
11
|
-
export declare function updateCartItemService(this: Modules, params: UpdateCartItemParams, context: any): Promise<OrderPosition>;
|
|
10
|
+
}[] | null;
|
|
11
|
+
}, unchainedAPI?: Record<string, any>): Promise<OrderPosition | null>;
|
|
@@ -1,37 +1,40 @@
|
|
|
1
1
|
import { ordersSettings } from '@unchainedshop/core-orders';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export async function updateCartItemService(
|
|
5
|
-
const {
|
|
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
|
-
}
|
|
2
|
+
import { QuotationDirector } from "../directors/QuotationDirector.js";
|
|
3
|
+
import { createServiceError } from "../errors.js";
|
|
4
|
+
export async function updateCartItemService({ order, item, quantity, configuration, }, unchainedAPI = {}) {
|
|
5
|
+
const context = { ...unchainedAPI, modules: this };
|
|
17
6
|
const product = await this.products.findProduct({ productId: item.productId });
|
|
18
7
|
if (!product) {
|
|
19
|
-
throw
|
|
8
|
+
throw createServiceError('ProductNotFoundError', `Product not found: ${item.productId}`);
|
|
20
9
|
}
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
let itemQuantity = quantity === undefined ? 1 : quantity;
|
|
11
|
+
let itemConfiguration = configuration;
|
|
12
|
+
if (item.quotationId) {
|
|
13
|
+
const quotation = await this.quotations.findQuotation({ quotationId: item.quotationId });
|
|
14
|
+
if (!quotation) {
|
|
15
|
+
throw createServiceError('QuotationNotFoundError', `Quotation not found: ${item.quotationId}`);
|
|
16
|
+
}
|
|
17
|
+
const director = await QuotationDirector.actions({ quotation }, context);
|
|
18
|
+
const requestedQuantity = quantity || item.quantity;
|
|
19
|
+
const quotationConfiguration = await director.transformItemConfiguration({
|
|
20
|
+
quantity: requestedQuantity,
|
|
21
|
+
configuration: configuration || item.configuration || [],
|
|
22
|
+
});
|
|
23
|
+
if (!quotationConfiguration) {
|
|
24
|
+
throw createServiceError('QuotationItemConfigurationError', `Quotation ${quotation._id} does not take quantity ${requestedQuantity}`);
|
|
25
|
+
}
|
|
26
|
+
itemQuantity = quotationConfiguration.quantity || requestedQuantity;
|
|
27
|
+
itemConfiguration = quotationConfiguration.configuration;
|
|
23
28
|
}
|
|
24
29
|
await ordersSettings.validateOrderPosition({
|
|
25
30
|
order,
|
|
26
31
|
product,
|
|
27
|
-
configuration,
|
|
28
|
-
quantityDiff:
|
|
32
|
+
configuration: itemConfiguration,
|
|
33
|
+
quantityDiff: itemQuantity - item.quantity,
|
|
29
34
|
}, context);
|
|
30
|
-
|
|
35
|
+
return this.orders.positions.updateProductItem({
|
|
31
36
|
orderPositionId: item._id,
|
|
32
|
-
quantity:
|
|
33
|
-
configuration:
|
|
37
|
+
quantity: itemQuantity || null,
|
|
38
|
+
configuration: itemConfiguration || null,
|
|
34
39
|
});
|
|
35
|
-
await updateCalculationService.bind(this)(order._id);
|
|
36
|
-
return (await this.orders.positions.findOrderPosition({ itemId: item._id }));
|
|
37
40
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Enrollment, EnrollmentPlan } from '@unchainedshop/core-enrollments';
|
|
2
|
+
import type { Modules } from '../modules.ts';
|
|
3
|
+
export declare function updateEnrollmentPlanService(this: Modules, enrollment: Enrollment, { plan }: {
|
|
4
|
+
plan: EnrollmentPlan;
|
|
5
|
+
}): Promise<Enrollment>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { emit } from '@unchainedshop/events';
|
|
2
|
+
import { EnrollmentDirector } from "../core-index.js";
|
|
3
|
+
import { processEnrollmentService } from "./processEnrollment.js";
|
|
4
|
+
import { addMessageService } from "./addMessage.js";
|
|
5
|
+
import { createServiceError } from "../errors.js";
|
|
6
|
+
export async function updateEnrollmentPlanService(enrollment, { plan }) {
|
|
7
|
+
const product = await this.products.findProduct({ productId: enrollment.productId });
|
|
8
|
+
if (!product)
|
|
9
|
+
throw createServiceError('ProductNotFoundError', 'Product not found for enrollment');
|
|
10
|
+
const director = await EnrollmentDirector.actions({ enrollment, product }, { modules: this });
|
|
11
|
+
const newPlan = await director.transformPlanToNewPlan({ plan });
|
|
12
|
+
if (!newPlan) {
|
|
13
|
+
throw createServiceError('EnrollmentPlanChangeNotSupportedError', 'Plan change is not supported for this enrollment');
|
|
14
|
+
}
|
|
15
|
+
let updatedEnrollment = (await this.enrollments.updatePlan(enrollment._id, newPlan));
|
|
16
|
+
updatedEnrollment = await processEnrollmentService.bind(this)(updatedEnrollment);
|
|
17
|
+
await emit('ENROLLMENT_PLAN_CHANGE', { enrollment: updatedEnrollment });
|
|
18
|
+
const user = await this.users.findUserById(enrollment.userId);
|
|
19
|
+
const locale = this.users.userLocale(user);
|
|
20
|
+
await addMessageService.bind(this)('ENROLLMENT_STATUS', {
|
|
21
|
+
reason: 'plan_change',
|
|
22
|
+
locale: locale.baseName,
|
|
23
|
+
enrollmentId: updatedEnrollment._id,
|
|
24
|
+
});
|
|
25
|
+
return updatedEnrollment;
|
|
26
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FilterDirector } from "../core-index.js";
|
|
2
|
+
export async function updateFilterService(filterId, doc) {
|
|
3
|
+
const updatedFilter = await this.filters.update(filterId, doc);
|
|
4
|
+
if (updatedFilter) {
|
|
5
|
+
await FilterDirector.invalidateProductIdCache(updatedFilter, { modules: this });
|
|
6
|
+
}
|
|
7
|
+
return updatedFilter;
|
|
8
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getFileFromFileData } from '@unchainedshop/core-files';
|
|
2
2
|
import { getFileAdapter } from "../utils/getFileAdapter.js";
|
|
3
|
+
import { createServiceError } from "../errors.js";
|
|
3
4
|
export async function uploadFileFromStreamService({ directoryName, rawFile, meta, ...options }) {
|
|
4
5
|
const fileUploadAdapter = getFileAdapter();
|
|
5
6
|
const uploadFileData = await fileUploadAdapter.uploadFileFromStream(directoryName, rawFile, {
|
|
@@ -9,6 +10,6 @@ export async function uploadFileFromStreamService({ directoryName, rawFile, meta
|
|
|
9
10
|
const fileId = await this.files.create(fileData);
|
|
10
11
|
const file = await this.files.findFile({ fileId });
|
|
11
12
|
if (!file)
|
|
12
|
-
throw
|
|
13
|
+
throw createServiceError('FileNotFoundError', 'File not found after upload');
|
|
13
14
|
return file;
|
|
14
15
|
}
|
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
import { ordersSettings } from '@unchainedshop/core-orders';
|
|
2
|
+
import { createServiceError } from "../errors.js";
|
|
2
3
|
export async function validateOrderService(order) {
|
|
3
4
|
if (!order.contact)
|
|
4
|
-
throw
|
|
5
|
+
throw createServiceError('ContactMissingError', 'Contact data not provided');
|
|
5
6
|
if (!order.billingAddress)
|
|
6
|
-
throw
|
|
7
|
+
throw createServiceError('BillingAddressMissingError', 'Billing address not provided');
|
|
7
8
|
if (!order.deliveryId ||
|
|
8
9
|
!(await this.orders.deliveries.findDelivery({ orderDeliveryId: order.deliveryId })))
|
|
9
|
-
throw
|
|
10
|
+
throw createServiceError('NoDeliveryProviderError', 'No delivery provider selected');
|
|
10
11
|
if (!order.paymentId ||
|
|
11
12
|
!(await this.orders.payments.findOrderPayment({ orderPaymentId: order.paymentId })))
|
|
12
|
-
throw
|
|
13
|
+
throw createServiceError('NoPaymentProviderError', 'No payment provider selected');
|
|
13
14
|
const orderPositions = await this.orders.positions.findOrderPositions({ orderId: order._id });
|
|
14
15
|
if (orderPositions.length === 0) {
|
|
15
|
-
|
|
16
|
-
NoItemsError.name = 'NoItemsError';
|
|
17
|
-
throw NoItemsError;
|
|
16
|
+
throw createServiceError('NoItemsError', 'No items to checkout');
|
|
18
17
|
}
|
|
19
18
|
for (const orderPosition of orderPositions) {
|
|
20
19
|
const product = await this.products.findProduct({
|
|
@@ -30,8 +29,13 @@ export async function validateOrderService(order) {
|
|
|
30
29
|
(await this.quotations.findQuotation({
|
|
31
30
|
quotationId: orderPosition.quotationId,
|
|
32
31
|
}));
|
|
33
|
-
if (quotation &&
|
|
34
|
-
|
|
32
|
+
if (quotation &&
|
|
33
|
+
!this.quotations.isProposalValidFor(quotation, {
|
|
34
|
+
userId: order.userId,
|
|
35
|
+
productId: orderPosition.productId,
|
|
36
|
+
currencyCode: order.currencyCode,
|
|
37
|
+
})) {
|
|
38
|
+
throw createServiceError('QuotationInvalidError', 'Quotation expired, fulfilled or not valid for this order, please request a new offer');
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unchainedshop/core",
|
|
3
3
|
"description": "Core orchestration package for the Unchained Engine with business services and directors",
|
|
4
|
-
"version": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.11",
|
|
5
|
+
"files": [
|
|
6
|
+
"lib"
|
|
7
|
+
],
|
|
5
8
|
"main": "lib/core-index.js",
|
|
6
9
|
"types": "lib/core-index.d.ts",
|
|
7
10
|
"type": "module",
|
|
@@ -35,29 +38,32 @@
|
|
|
35
38
|
},
|
|
36
39
|
"homepage": "https://github.com/unchainedshop/unchained#readme",
|
|
37
40
|
"dependencies": {
|
|
38
|
-
"@unchainedshop/core-assortments": "^5.0.0-alpha.
|
|
39
|
-
"@unchainedshop/core-bookmarks": "^5.0.0-alpha.
|
|
40
|
-
"@unchainedshop/core-countries": "^5.0.0-alpha.
|
|
41
|
-
"@unchainedshop/core-currencies": "^5.0.0-alpha.
|
|
42
|
-
"@unchainedshop/core-delivery": "^5.0.0-alpha.
|
|
43
|
-
"@unchainedshop/core-enrollments": "^5.0.0-alpha.
|
|
44
|
-
"@unchainedshop/core-events": "^5.0.0-alpha.
|
|
45
|
-
"@unchainedshop/core-files": "^5.0.0-alpha.
|
|
46
|
-
"@unchainedshop/core-filters": "^5.0.0-alpha.
|
|
47
|
-
"@unchainedshop/core-languages": "^5.0.0-alpha.
|
|
48
|
-
"@unchainedshop/core-orders": "^5.0.0-alpha.
|
|
49
|
-
"@unchainedshop/core-payment": "^5.0.0-alpha.
|
|
50
|
-
"@unchainedshop/core-products": "^5.0.0-alpha.
|
|
51
|
-
"@unchainedshop/core-quotations": "^5.0.0-alpha.
|
|
52
|
-
"@unchainedshop/core-users": "^5.0.0-alpha.
|
|
53
|
-
"@unchainedshop/core-warehousing": "^5.0.0-alpha.
|
|
54
|
-
"@unchainedshop/core-worker": "^5.0.0-alpha.
|
|
55
|
-
"@unchainedshop/
|
|
56
|
-
"@unchainedshop/
|
|
57
|
-
"
|
|
41
|
+
"@unchainedshop/core-assortments": "^5.0.0-alpha.11",
|
|
42
|
+
"@unchainedshop/core-bookmarks": "^5.0.0-alpha.11",
|
|
43
|
+
"@unchainedshop/core-countries": "^5.0.0-alpha.11",
|
|
44
|
+
"@unchainedshop/core-currencies": "^5.0.0-alpha.11",
|
|
45
|
+
"@unchainedshop/core-delivery": "^5.0.0-alpha.11",
|
|
46
|
+
"@unchainedshop/core-enrollments": "^5.0.0-alpha.11",
|
|
47
|
+
"@unchainedshop/core-events": "^5.0.0-alpha.11",
|
|
48
|
+
"@unchainedshop/core-files": "^5.0.0-alpha.11",
|
|
49
|
+
"@unchainedshop/core-filters": "^5.0.0-alpha.11",
|
|
50
|
+
"@unchainedshop/core-languages": "^5.0.0-alpha.11",
|
|
51
|
+
"@unchainedshop/core-orders": "^5.0.0-alpha.11",
|
|
52
|
+
"@unchainedshop/core-payment": "^5.0.0-alpha.11",
|
|
53
|
+
"@unchainedshop/core-products": "^5.0.0-alpha.11",
|
|
54
|
+
"@unchainedshop/core-quotations": "^5.0.0-alpha.11",
|
|
55
|
+
"@unchainedshop/core-users": "^5.0.0-alpha.11",
|
|
56
|
+
"@unchainedshop/core-warehousing": "^5.0.0-alpha.11",
|
|
57
|
+
"@unchainedshop/core-worker": "^5.0.0-alpha.11",
|
|
58
|
+
"@unchainedshop/events": "^5.0.0-alpha.11",
|
|
59
|
+
"@unchainedshop/logger": "^5.0.0-alpha.11",
|
|
60
|
+
"@unchainedshop/mongodb": "^5.0.0-alpha.11",
|
|
61
|
+
"@unchainedshop/utils": "^5.0.0-alpha.11",
|
|
62
|
+
"minipass-json-stream": "^1.0.2",
|
|
63
|
+
"zod": "^4.2.0"
|
|
58
64
|
},
|
|
59
65
|
"devDependencies": {
|
|
60
|
-
"@types/node": "^
|
|
61
|
-
"typescript": "^
|
|
66
|
+
"@types/node": "^26.2.0",
|
|
67
|
+
"typescript": "^6.0.3"
|
|
62
68
|
}
|
|
63
69
|
}
|