@unchainedshop/core 5.0.0-alpha.2 → 5.0.0-alpha.3
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-exporter/handlers/exportProductsHandler.js +2 -2
- package/lib/bulk-importer/handlers/product/create.d.ts +18 -6
- package/lib/bulk-importer/handlers/product/create.js +5 -3
- package/lib/bulk-importer/handlers/product/update.d.ts +18 -6
- package/lib/bulk-importer/handlers/product/update.js +5 -2
- package/lib/directors/FilterDirector.js +23 -18
- package/lib/directors/WorkerDirector.js +1 -1
- 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 +18 -0
- package/lib/factory/registerEnrollment.js +43 -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 +12 -0
- package/lib/factory/registerQuotation.js +52 -0
- package/lib/factory/registerWorker.js +1 -1
- package/lib/services/addMultipleCartProducts.js +3 -2
- 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/deleteDeadCarts.d.ts +2 -0
- package/lib/services/deleteDeadCarts.js +17 -0
- package/lib/services/deleteUser.js +2 -5
- package/lib/services/index.d.ts +10 -0
- package/lib/services/index.js +10 -0
- package/lib/services/loadFilterOptions.js +3 -3
- package/lib/services/processEnrollment.js +2 -1
- package/lib/services/processOrder.js +3 -2
- 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/updateCalculation.js +2 -1
- 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 +7 -8
- package/package.json +6 -3
|
@@ -5,6 +5,7 @@ import { WarehousingProviderType } from '@unchainedshop/core-warehousing';
|
|
|
5
5
|
import { WarehousingDirector, DeliveryDirector, PaymentDirector } from "../directors/index.js";
|
|
6
6
|
import { fulfillQuotationService } from "./fulfillQuotation.js";
|
|
7
7
|
import { createLogger } from '@unchainedshop/logger';
|
|
8
|
+
import { createServiceError } from "../errors.js";
|
|
8
9
|
const logger = createLogger('unchained:core:processOrder');
|
|
9
10
|
const isAutoConfirmationEnabled = async ({ orderPayment, orderDelivery, }, modules) => {
|
|
10
11
|
if (orderPayment.status !== OrderPaymentStatus.PAID) {
|
|
@@ -12,7 +13,7 @@ const isAutoConfirmationEnabled = async ({ orderPayment, orderDelivery, }, modul
|
|
|
12
13
|
paymentProviderId: orderPayment.paymentProviderId,
|
|
13
14
|
});
|
|
14
15
|
if (!paymentProvider)
|
|
15
|
-
throw
|
|
16
|
+
throw createServiceError('PaymentProviderNotFoundError', `Payment provider not found: ${orderPayment.paymentProviderId}`);
|
|
16
17
|
const actions = await PaymentDirector.actions(paymentProvider, {}, { modules });
|
|
17
18
|
if (!actions.isPayLaterAllowed())
|
|
18
19
|
return false;
|
|
@@ -22,7 +23,7 @@ const isAutoConfirmationEnabled = async ({ orderPayment, orderDelivery, }, modul
|
|
|
22
23
|
deliveryProviderId: orderDelivery.deliveryProviderId,
|
|
23
24
|
});
|
|
24
25
|
if (!deliveryProvider)
|
|
25
|
-
throw
|
|
26
|
+
throw createServiceError('DeliveryProviderNotFoundError', `Delivery provider not found: ${orderDelivery.deliveryProviderId}`);
|
|
26
27
|
const director = await DeliveryDirector.actions(deliveryProvider, {}, { modules });
|
|
27
28
|
if (!director.isAutoReleaseAllowed())
|
|
28
29
|
return false;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { QuotationStatus } from '@unchainedshop/core-quotations';
|
|
2
2
|
import { QuotationDirector } from "../core-index.js";
|
|
3
3
|
import { addMessageService } from "./addMessage.js";
|
|
4
|
-
const findNextStatus = async (
|
|
4
|
+
const findNextStatus = async (director, quotation) => {
|
|
5
5
|
let status = quotation.status;
|
|
6
|
-
const director = await QuotationDirector.actions({ quotation }, { modules });
|
|
7
6
|
if (status === QuotationStatus.REQUESTED) {
|
|
8
7
|
if (!(await director.isManualRequestVerificationRequired())) {
|
|
9
8
|
status = QuotationStatus.PROCESSING;
|
|
@@ -19,27 +18,26 @@ const findNextStatus = async (quotation, modules) => {
|
|
|
19
18
|
export async function processQuotationService(initialQuotation, params) {
|
|
20
19
|
const quotationId = initialQuotation._id;
|
|
21
20
|
let quotation = initialQuotation;
|
|
22
|
-
let nextStatus = await findNextStatus(quotation, this);
|
|
23
21
|
const director = await QuotationDirector.actions({ quotation }, { modules: this });
|
|
22
|
+
const runHook = async (hook) => {
|
|
23
|
+
await hook(params.quotationContext);
|
|
24
|
+
quotation = (await this.quotations.findQuotation({ quotationId }));
|
|
25
|
+
return findNextStatus(director, quotation);
|
|
26
|
+
};
|
|
27
|
+
let nextStatus = await findNextStatus(director, quotation);
|
|
24
28
|
if (quotation.status === QuotationStatus.REQUESTED && nextStatus !== QuotationStatus.REQUESTED) {
|
|
25
|
-
await director.submitRequest
|
|
29
|
+
nextStatus = await runHook(director.submitRequest);
|
|
26
30
|
}
|
|
27
|
-
quotation = (await this.quotations.findQuotation({ quotationId }));
|
|
28
|
-
nextStatus = await findNextStatus(quotation, this);
|
|
29
31
|
if (nextStatus !== QuotationStatus.PROCESSING) {
|
|
30
|
-
await director.verifyRequest
|
|
32
|
+
nextStatus = await runHook(director.verifyRequest);
|
|
31
33
|
}
|
|
32
|
-
quotation = (await this.quotations.findQuotation({ quotationId }));
|
|
33
|
-
nextStatus = await findNextStatus(quotation, this);
|
|
34
34
|
if (nextStatus === QuotationStatus.REJECTED) {
|
|
35
|
-
await director.rejectRequest
|
|
35
|
+
nextStatus = await runHook(director.rejectRequest);
|
|
36
36
|
}
|
|
37
|
-
quotation = (await this.quotations.findQuotation({ quotationId }));
|
|
38
|
-
nextStatus = await findNextStatus(quotation, this);
|
|
39
37
|
if (nextStatus === QuotationStatus.PROPOSED) {
|
|
40
38
|
const proposal = await director.quote();
|
|
41
39
|
quotation = (await this.quotations.updateProposal(quotation._id, proposal));
|
|
42
|
-
nextStatus = await findNextStatus(
|
|
40
|
+
nextStatus = await findNextStatus(director, quotation);
|
|
43
41
|
}
|
|
44
42
|
const updatedQuotation = (await this.quotations.updateStatus(quotation._id, {
|
|
45
43
|
status: nextStatus,
|
|
@@ -3,6 +3,9 @@ import { processQuotationService } from "./processQuotation.js";
|
|
|
3
3
|
export async function proposeQuotationService(quotation, { quotationContext }) {
|
|
4
4
|
if (quotation.status !== QuotationStatus.PROCESSING)
|
|
5
5
|
return quotation;
|
|
6
|
+
if (quotationContext) {
|
|
7
|
+
await this.quotations.updateContext(quotation._id, { context: quotationContext });
|
|
8
|
+
}
|
|
6
9
|
const updatedQuotation = (await this.quotations.updateStatus(quotation._id, {
|
|
7
10
|
status: QuotationStatus.PROPOSED,
|
|
8
11
|
info: 'proposed manually',
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Filter } from '@unchainedshop/core-filters';
|
|
2
|
+
import type { Modules } from '../modules.ts';
|
|
3
|
+
export declare function removeFilterOptionService(this: Modules, { filterId, filterOptionValue }: {
|
|
4
|
+
filterId: string;
|
|
5
|
+
filterOptionValue: string;
|
|
6
|
+
}): Promise<Filter | null>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { FilterDirector } from "../core-index.js";
|
|
2
|
+
export async function removeFilterOptionService({ filterId, filterOptionValue }) {
|
|
3
|
+
const filter = await this.filters.removeFilterOption({ filterId, filterOptionValue });
|
|
4
|
+
if (filter) {
|
|
5
|
+
await FilterDirector.invalidateProductIdCache(filter, { modules: this });
|
|
6
|
+
}
|
|
7
|
+
return filter;
|
|
8
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ProductStatus } from '@unchainedshop/core-products';
|
|
2
2
|
import { updateCalculationService } from "./updateCalculation.js";
|
|
3
|
+
import { createServiceError } from "../errors.js";
|
|
3
4
|
export async function removeProductService({ productId }) {
|
|
4
5
|
const product = await this.products.findProduct({ productId });
|
|
5
6
|
switch (product?.status) {
|
|
@@ -21,7 +22,7 @@ export async function removeProductService({ productId }) {
|
|
|
21
22
|
case ProductStatus.DELETED:
|
|
22
23
|
return false;
|
|
23
24
|
default:
|
|
24
|
-
throw
|
|
25
|
+
throw createServiceError('ProductWrongStatusError', `Invalid status: ${product?.status}`);
|
|
25
26
|
}
|
|
26
27
|
return true;
|
|
27
28
|
}
|
|
@@ -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({
|
|
@@ -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({
|
|
@@ -31,7 +30,7 @@ export async function validateOrderService(order) {
|
|
|
31
30
|
quotationId: orderPosition.quotationId,
|
|
32
31
|
}));
|
|
33
32
|
if (quotation && !this.quotations.isProposalValid(quotation)) {
|
|
34
|
-
throw
|
|
33
|
+
throw createServiceError('QuotationInvalidError', 'Quotation expired or fulfilled, please request a new offer');
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
}
|
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": "5.0.0-alpha.
|
|
4
|
+
"version": "5.0.0-alpha.3",
|
|
5
5
|
"main": "lib/core-index.js",
|
|
6
6
|
"types": "lib/core-index.d.ts",
|
|
7
7
|
"type": "module",
|
|
@@ -52,12 +52,15 @@
|
|
|
52
52
|
"@unchainedshop/core-users": "^5.0.0-alpha.1",
|
|
53
53
|
"@unchainedshop/core-warehousing": "^5.0.0-alpha.1",
|
|
54
54
|
"@unchainedshop/core-worker": "^5.0.0-alpha.1",
|
|
55
|
+
"@unchainedshop/events": "^5.0.0-alpha.1",
|
|
55
56
|
"@unchainedshop/logger": "^5.0.0-alpha.1",
|
|
57
|
+
"@unchainedshop/mongodb": "^5.0.0-alpha.1",
|
|
56
58
|
"@unchainedshop/utils": "^5.0.0-alpha.1",
|
|
57
|
-
"minipass-json-stream": "^1.0.2"
|
|
59
|
+
"minipass-json-stream": "^1.0.2",
|
|
60
|
+
"zod": "^4.2.0"
|
|
58
61
|
},
|
|
59
62
|
"devDependencies": {
|
|
60
|
-
"@types/node": "^
|
|
63
|
+
"@types/node": "^26.2.0",
|
|
61
64
|
"typescript": "^5.8.3"
|
|
62
65
|
}
|
|
63
66
|
}
|