@unchainedshop/api 3.0.0-rc6 → 3.0.0-rc8
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/api-index.d.ts +1 -1
- package/lib/api-index.d.ts.map +1 -1
- package/lib/api-index.js +1 -1
- package/lib/api-index.js.map +1 -1
- package/lib/context.d.ts +0 -1
- package/lib/context.d.ts.map +1 -1
- package/lib/context.js +4 -19
- package/lib/context.js.map +1 -1
- package/lib/express/createBulkImportMiddleware.d.ts +1 -2
- package/lib/express/createBulkImportMiddleware.d.ts.map +1 -1
- package/lib/express/createBulkImportMiddleware.js.map +1 -1
- package/lib/express/createERCMetadataMiddleware.js +1 -1
- package/lib/express/createERCMetadataMiddleware.js.map +1 -1
- package/lib/express/index.d.ts.map +1 -1
- package/lib/express/index.js.map +1 -1
- package/lib/fastify/index.d.ts.map +1 -1
- package/lib/fastify/index.js.map +1 -1
- package/lib/resolvers/mutations/orders/addCartDiscount.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/addCartDiscount.js +8 -3
- package/lib/resolvers/mutations/orders/addCartDiscount.js.map +1 -1
- package/lib/resolvers/mutations/orders/addCartProduct.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/addCartProduct.js +8 -3
- package/lib/resolvers/mutations/orders/addCartProduct.js.map +1 -1
- package/lib/resolvers/mutations/orders/addCartQuotation.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/addCartQuotation.js +8 -3
- package/lib/resolvers/mutations/orders/addCartQuotation.js.map +1 -1
- package/lib/resolvers/mutations/orders/addMultipleCartProducts.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/addMultipleCartProducts.js +8 -3
- package/lib/resolvers/mutations/orders/addMultipleCartProducts.js.map +1 -1
- package/lib/resolvers/mutations/orders/checkoutCart.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/checkoutCart.js +10 -5
- package/lib/resolvers/mutations/orders/checkoutCart.js.map +1 -1
- package/lib/resolvers/mutations/orders/emptyCart.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/emptyCart.js +8 -3
- package/lib/resolvers/mutations/orders/emptyCart.js.map +1 -1
- package/lib/resolvers/mutations/orders/signPaymentProviderForCheckout.js +1 -1
- package/lib/resolvers/mutations/orders/signPaymentProviderForCheckout.js.map +1 -1
- package/lib/resolvers/mutations/orders/updateCart.d.ts.map +1 -1
- package/lib/resolvers/mutations/orders/updateCart.js +8 -3
- package/lib/resolvers/mutations/orders/updateCart.js.map +1 -1
- package/lib/resolvers/type/delivery-provider-types.d.ts +0 -1
- package/lib/resolvers/type/delivery-provider-types.d.ts.map +1 -1
- package/lib/resolvers/type/delivery-provider-types.js +0 -2
- package/lib/resolvers/type/delivery-provider-types.js.map +1 -1
- package/lib/resolvers/type/filter/loaded-filter-types.d.ts.map +1 -1
- package/lib/resolvers/type/filter/loaded-filter-types.js +1 -2
- package/lib/resolvers/type/filter/loaded-filter-types.js.map +1 -1
- package/lib/resolvers/type/index.d.ts +11 -45
- package/lib/resolvers/type/index.d.ts.map +1 -1
- package/lib/resolvers/type/index.js +0 -4
- package/lib/resolvers/type/index.js.map +1 -1
- package/lib/resolvers/type/order/order-delivery-discount-types.d.ts +2 -3
- package/lib/resolvers/type/order/order-delivery-discount-types.d.ts.map +1 -1
- package/lib/resolvers/type/order/order-delivery-discount-types.js +1 -3
- package/lib/resolvers/type/order/order-delivery-discount-types.js.map +1 -1
- package/lib/resolvers/type/order/order-global-discount-types.d.ts +2 -3
- package/lib/resolvers/type/order/order-global-discount-types.d.ts.map +1 -1
- package/lib/resolvers/type/order/order-global-discount-types.js +1 -3
- package/lib/resolvers/type/order/order-global-discount-types.js.map +1 -1
- package/lib/resolvers/type/order/order-item-discount-types.d.ts +2 -3
- package/lib/resolvers/type/order/order-item-discount-types.d.ts.map +1 -1
- package/lib/resolvers/type/order/order-item-discount-types.js +1 -3
- package/lib/resolvers/type/order/order-item-discount-types.js.map +1 -1
- package/lib/resolvers/type/order/order-item-types.d.ts.map +1 -1
- package/lib/resolvers/type/order/order-item-types.js +2 -11
- package/lib/resolvers/type/order/order-item-types.js.map +1 -1
- package/lib/resolvers/type/order/order-payment-discount-types.d.ts +2 -3
- package/lib/resolvers/type/order/order-payment-discount-types.d.ts.map +1 -1
- package/lib/resolvers/type/order/order-payment-discount-types.js +1 -7
- package/lib/resolvers/type/order/order-payment-discount-types.js.map +1 -1
- package/lib/resolvers/type/order/order-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-types.d.ts.map +1 -1
- package/lib/resolvers/type/order/order-types.js +2 -7
- package/lib/resolvers/type/order/order-types.js.map +1 -1
- package/lib/resolvers/type/payment/payment-provider-types.d.ts +0 -1
- package/lib/resolvers/type/payment/payment-provider-types.d.ts.map +1 -1
- package/lib/resolvers/type/payment/payment-provider-types.js +0 -2
- package/lib/resolvers/type/payment/payment-provider-types.js.map +1 -1
- package/lib/resolvers/type/price-types.d.ts +0 -1
- package/lib/resolvers/type/price-types.d.ts.map +1 -1
- package/lib/resolvers/type/price-types.js.map +1 -1
- package/lib/resolvers/type/product/product-configurable-types.d.ts.map +1 -1
- package/lib/resolvers/type/product/product-configurable-types.js +5 -36
- package/lib/resolvers/type/product/product-configurable-types.js.map +1 -1
- package/lib/resolvers/type/product/product-discount.d.ts +2 -3
- package/lib/resolvers/type/product/product-discount.d.ts.map +1 -1
- package/lib/resolvers/type/product/product-discount.js +2 -4
- package/lib/resolvers/type/product/product-discount.js.map +1 -1
- package/lib/resolvers/type/product/product-plan-types.d.ts.map +1 -1
- package/lib/resolvers/type/product/product-plan-types.js +3 -7
- package/lib/resolvers/type/product/product-plan-types.js.map +1 -1
- package/lib/resolvers/type/product/product-simple-types.d.ts +0 -2
- package/lib/resolvers/type/product/product-simple-types.d.ts.map +1 -1
- package/lib/resolvers/type/product/product-simple-types.js +13 -50
- package/lib/resolvers/type/product/product-simple-types.js.map +1 -1
- package/lib/resolvers/type/product/product-tokenized-types.d.ts +0 -1
- package/lib/resolvers/type/product/product-tokenized-types.d.ts.map +1 -1
- package/lib/resolvers/type/product/product-tokenized-types.js +5 -23
- package/lib/resolvers/type/product/product-tokenized-types.js.map +1 -1
- package/lib/resolvers/type/user-types.d.ts.map +1 -1
- package/lib/resolvers/type/user-types.js +2 -2
- package/lib/resolvers/type/user-types.js.map +1 -1
- package/lib/schema/inputTypes.d.ts.map +1 -1
- package/lib/schema/inputTypes.js +0 -1
- package/lib/schema/inputTypes.js.map +1 -1
- package/lib/schema/types/dispatch.d.ts.map +1 -1
- package/lib/schema/types/dispatch.js +0 -1
- package/lib/schema/types/dispatch.js.map +1 -1
- package/lib/schema/types/price.d.ts.map +1 -1
- package/lib/schema/types/price.js +0 -2
- package/lib/schema/types/price.js.map +1 -1
- package/lib/schema/types/stock.d.ts.map +1 -1
- package/lib/schema/types/stock.js +0 -1
- package/lib/schema/types/stock.js.map +1 -1
- package/package.json +10 -7
- package/src/api-index.ts +1 -1
- package/src/context.ts +4 -20
- package/src/express/createBulkImportMiddleware.ts +1 -2
- package/src/express/createERCMetadataMiddleware.ts +1 -1
- package/src/express/index.ts +1 -2
- package/src/fastify/index.ts +2 -3
- package/src/resolvers/mutations/orders/addCartDiscount.ts +7 -2
- package/src/resolvers/mutations/orders/addCartProduct.ts +8 -2
- package/src/resolvers/mutations/orders/addCartQuotation.ts +7 -2
- package/src/resolvers/mutations/orders/addMultipleCartProducts.ts +7 -2
- package/src/resolvers/mutations/orders/checkoutCart.ts +9 -5
- package/src/resolvers/mutations/orders/emptyCart.ts +7 -3
- package/src/resolvers/mutations/orders/signPaymentProviderForCheckout.ts +1 -1
- package/src/resolvers/mutations/orders/updateCart.ts +7 -3
- package/src/resolvers/type/delivery-provider-types.ts +0 -3
- package/src/resolvers/type/filter/loaded-filter-types.ts +1 -2
- package/src/resolvers/type/index.ts +0 -4
- package/src/resolvers/type/order/order-delivery-discount-types.ts +1 -3
- package/src/resolvers/type/order/order-global-discount-types.ts +2 -3
- package/src/resolvers/type/order/order-item-discount-types.ts +1 -3
- package/src/resolvers/type/order/order-item-types.ts +3 -11
- package/src/resolvers/type/order/order-payment-discount-types.ts +2 -9
- package/src/resolvers/type/order/order-types.ts +3 -7
- package/src/resolvers/type/payment/payment-provider-types.ts +0 -2
- package/src/resolvers/type/price-types.ts +0 -1
- package/src/resolvers/type/product/product-configurable-types.ts +5 -49
- package/src/resolvers/type/product/product-discount.ts +2 -4
- package/src/resolvers/type/product/product-plan-types.ts +3 -11
- package/src/resolvers/type/product/product-simple-types.ts +14 -75
- package/src/resolvers/type/product/product-tokenized-types.ts +5 -35
- package/src/resolvers/type/user-types.ts +4 -2
- package/src/schema/inputTypes.ts +0 -1
- package/src/schema/types/dispatch.ts +0 -1
- package/src/schema/types/price.ts +0 -2
- package/src/schema/types/stock.ts +0 -1
- package/tests/api-index.test.ts +4 -4
- package/lib/resolvers/mutations/utils/getOrderCart.d.ts +0 -7
- package/lib/resolvers/mutations/utils/getOrderCart.d.ts.map +0 -1
- package/lib/resolvers/mutations/utils/getOrderCart.js +0 -17
- package/lib/resolvers/mutations/utils/getOrderCart.js.map +0 -1
- package/src/resolvers/mutations/utils/getOrderCart.ts +0 -20
- package/src/resolvers/type/dispatch-types.ts +0 -27
- package/src/resolvers/type/stock-types.ts +0 -25
package/src/api-index.ts
CHANGED
|
@@ -10,8 +10,8 @@ import { UnchainedCore } from '@unchainedshop/core';
|
|
|
10
10
|
export * from './context.js';
|
|
11
11
|
export * from './locale-context.js';
|
|
12
12
|
export * from './loaders/index.js';
|
|
13
|
+
export * from './errors.js';
|
|
13
14
|
export * as acl from './acl.js';
|
|
14
|
-
export * as errors from './errors.js';
|
|
15
15
|
export * as roles from './roles/index.js';
|
|
16
16
|
export { createContextResolver, getCurrentContextResolver, setCurrentContextResolver };
|
|
17
17
|
|
package/src/context.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import path from 'path';
|
|
3
1
|
import { UnchainedCore } from '@unchainedshop/core';
|
|
4
2
|
import instantiateLoaders, { UnchainedLoaders } from './loaders/index.js';
|
|
5
3
|
import { getLocaleContext, UnchainedLocaleContext } from './locale-context.js';
|
|
@@ -58,24 +56,10 @@ export type UnchainedContextResolver = (
|
|
|
58
56
|
},
|
|
59
57
|
) => Promise<Context>;
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
version: process.env.npm_package_version,
|
|
67
|
-
};
|
|
68
|
-
const absolutePath = path.resolve(path.dirname(base), filename);
|
|
69
|
-
const data = JSON.parse(fs.readFileSync(absolutePath, 'utf-8'));
|
|
70
|
-
return data;
|
|
71
|
-
} catch {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const packageJson = loadJSON('../package.json');
|
|
77
|
-
|
|
78
|
-
const { UNCHAINED_API_VERSION = packageJson?.version || '2.x' } = process.env;
|
|
59
|
+
const { default: packageJson } = await import(`${import.meta.dirname}/../package.json`, {
|
|
60
|
+
with: { type: 'json' },
|
|
61
|
+
});
|
|
62
|
+
const { UNCHAINED_API_VERSION = packageJson?.version || '3.x' } = process.env;
|
|
79
63
|
|
|
80
64
|
export const createContextResolver =
|
|
81
65
|
(
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { createLogger } from '@unchainedshop/logger';
|
|
2
2
|
import { checkAction } from '../acl.js';
|
|
3
3
|
import { actions } from '../roles/index.js';
|
|
4
|
-
import { IncomingMessage } from 'http';
|
|
5
4
|
import { Context } from '../context.js';
|
|
6
5
|
|
|
7
6
|
const logger = createLogger('unchained:bulk-import');
|
|
@@ -19,7 +18,7 @@ const methodWrongHandler = (res) => () => {
|
|
|
19
18
|
};
|
|
20
19
|
|
|
21
20
|
export default async function bulkImportMiddleware(
|
|
22
|
-
req:
|
|
21
|
+
req: Request & { query?: any; unchainedContext: Context },
|
|
23
22
|
res,
|
|
24
23
|
) {
|
|
25
24
|
try {
|
package/src/express/index.ts
CHANGED
|
@@ -11,9 +11,8 @@ import { UnchainedCore } from '@unchainedshop/core';
|
|
|
11
11
|
import { emit } from '@unchainedshop/events';
|
|
12
12
|
import { API_EVENTS } from '../events.js';
|
|
13
13
|
import { User } from '@unchainedshop/core-users';
|
|
14
|
-
import { IncomingMessage } from 'http';
|
|
15
14
|
|
|
16
|
-
const resolveUserRemoteAddress = (req:
|
|
15
|
+
const resolveUserRemoteAddress = (req: e.Request) => {
|
|
17
16
|
const remoteAddress =
|
|
18
17
|
(req.headers['x-real-ip'] as string) ||
|
|
19
18
|
(req.headers['x-forwarded-for'] as string) ||
|
package/src/fastify/index.ts
CHANGED
|
@@ -8,12 +8,11 @@ import { UnchainedCore } from '@unchainedshop/core';
|
|
|
8
8
|
import { emit } from '@unchainedshop/events';
|
|
9
9
|
import { API_EVENTS } from '../events.js';
|
|
10
10
|
import { User } from '@unchainedshop/core-users';
|
|
11
|
-
import { IncomingMessage } from 'http';
|
|
12
11
|
import fastifySession from '@fastify/session';
|
|
13
12
|
import fastifyCookie from '@fastify/cookie';
|
|
14
|
-
import { FastifyInstance } from 'fastify';
|
|
13
|
+
import { FastifyInstance, FastifyRequest } from 'fastify';
|
|
15
14
|
|
|
16
|
-
const resolveUserRemoteAddress = (req:
|
|
15
|
+
const resolveUserRemoteAddress = (req: FastifyRequest) => {
|
|
17
16
|
const remoteAddress =
|
|
18
17
|
(req.headers['x-real-ip'] as string) ||
|
|
19
18
|
(req.headers['x-forwarded-for'] as string) ||
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Context } from '../../../context.js';
|
|
2
2
|
import { log } from '@unchainedshop/logger';
|
|
3
|
-
import { getOrderCart } from '../utils/getOrderCart.js';
|
|
4
3
|
import {
|
|
5
4
|
OrderWrongStatusError,
|
|
6
5
|
OrderDiscountCodeAlreadyPresentError,
|
|
7
6
|
OrderDiscountCodeNotValidError,
|
|
7
|
+
OrderNotFoundError,
|
|
8
8
|
} from '../../../errors.js';
|
|
9
9
|
|
|
10
10
|
export default async function addCartDiscount(
|
|
@@ -16,7 +16,12 @@ export default async function addCartDiscount(
|
|
|
16
16
|
|
|
17
17
|
log(`mutation addCartDiscount ${code} ${orderId}`, { userId, orderId });
|
|
18
18
|
|
|
19
|
-
const order = await
|
|
19
|
+
const order = await services.orders.findOrInitCart({
|
|
20
|
+
orderId,
|
|
21
|
+
user,
|
|
22
|
+
countryCode: context.countryContext,
|
|
23
|
+
});
|
|
24
|
+
if (!order) throw new OrderNotFoundError({ orderId });
|
|
20
25
|
|
|
21
26
|
if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
|
|
22
27
|
|
|
@@ -5,8 +5,8 @@ import {
|
|
|
5
5
|
OrderQuantityTooLowError,
|
|
6
6
|
InvalidIdError,
|
|
7
7
|
OrderWrongStatusError,
|
|
8
|
+
OrderNotFoundError,
|
|
8
9
|
} from '../../../errors.js';
|
|
9
|
-
import { getOrderCart } from '../utils/getOrderCart.js';
|
|
10
10
|
import { ordersSettings } from '@unchainedshop/core-orders';
|
|
11
11
|
|
|
12
12
|
export default async function addCartProduct(
|
|
@@ -29,7 +29,13 @@ export default async function addCartProduct(
|
|
|
29
29
|
const originalProduct = await modules.products.findProduct({ productId: originalProductId });
|
|
30
30
|
if (!originalProduct) throw new ProductNotFoundError({ productId: originalProductId });
|
|
31
31
|
|
|
32
|
-
const order = await
|
|
32
|
+
const order = await services.orders.findOrInitCart({
|
|
33
|
+
orderId,
|
|
34
|
+
user,
|
|
35
|
+
countryCode: context.countryContext,
|
|
36
|
+
});
|
|
37
|
+
if (!order) throw new OrderNotFoundError({ orderId });
|
|
38
|
+
|
|
33
39
|
if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
|
|
34
40
|
|
|
35
41
|
const product = await modules.products.resolveOrderableProduct(originalProduct, { configuration });
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
InvalidIdError,
|
|
9
9
|
OrderWrongStatusError,
|
|
10
10
|
ProductNotFoundError,
|
|
11
|
+
OrderNotFoundError,
|
|
11
12
|
} from '../../../errors.js';
|
|
12
|
-
import { getOrderCart } from '../utils/getOrderCart.js';
|
|
13
13
|
import { QuotationDirector } from '@unchainedshop/core';
|
|
14
14
|
|
|
15
15
|
export default async function addCartQuotation(
|
|
@@ -43,7 +43,12 @@ export default async function addCartQuotation(
|
|
|
43
43
|
throw new QuotationWrongStatusError({ status: quotation.status });
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const order = await
|
|
46
|
+
const order = await services.orders.findOrInitCart({
|
|
47
|
+
orderId,
|
|
48
|
+
user,
|
|
49
|
+
countryCode: context.countryContext,
|
|
50
|
+
});
|
|
51
|
+
if (!order) throw new OrderNotFoundError({ orderId });
|
|
47
52
|
if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
|
|
48
53
|
|
|
49
54
|
if (
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
ProductNotFoundError,
|
|
5
5
|
OrderQuantityTooLowError,
|
|
6
6
|
OrderWrongStatusError,
|
|
7
|
+
OrderNotFoundError,
|
|
7
8
|
} from '../../../errors.js';
|
|
8
|
-
import { getOrderCart } from '../utils/getOrderCart.js';
|
|
9
9
|
import { ordersSettings } from '@unchainedshop/core-orders';
|
|
10
10
|
|
|
11
11
|
export default async function addMultipleCartProducts(
|
|
@@ -41,7 +41,12 @@ export default async function addMultipleCartProducts(
|
|
|
41
41
|
}),
|
|
42
42
|
);
|
|
43
43
|
|
|
44
|
-
const order = await
|
|
44
|
+
const order = await services.orders.findOrInitCart({
|
|
45
|
+
orderId,
|
|
46
|
+
user,
|
|
47
|
+
countryCode: context.countryContext,
|
|
48
|
+
});
|
|
49
|
+
if (!order) throw new OrderNotFoundError({ orderId });
|
|
45
50
|
if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
|
|
46
51
|
|
|
47
52
|
// Reduce is used to wait for each product to be added before processing the next (sequential processing)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Context } from '../../../context.js';
|
|
2
|
-
import { OrderCheckoutError } from '../../../errors.js';
|
|
3
|
-
import { getOrderCart } from '../utils/getOrderCart.js';
|
|
2
|
+
import { OrderCheckoutError, OrderNotFoundError } from '../../../errors.js';
|
|
4
3
|
import { createLogger, log } from '@unchainedshop/logger';
|
|
5
4
|
|
|
6
5
|
const logger = createLogger('unchained:api');
|
|
@@ -20,11 +19,16 @@ export default async function checkoutCart(
|
|
|
20
19
|
log('mutation checkoutCart', { orderId: forceOrderId, userId });
|
|
21
20
|
|
|
22
21
|
// Do not check for order status here! The checkout method will act accordingly
|
|
23
|
-
|
|
22
|
+
const order = await services.orders.findOrInitCart({
|
|
23
|
+
orderId: forceOrderId,
|
|
24
|
+
user,
|
|
25
|
+
countryCode: context.countryContext,
|
|
26
|
+
});
|
|
27
|
+
if (!order) throw new OrderNotFoundError({ orderId: forceOrderId });
|
|
24
28
|
|
|
25
29
|
try {
|
|
26
|
-
|
|
27
|
-
return
|
|
30
|
+
const checkedOutOrder = await services.orders.checkoutOrder(order._id, transactionContext);
|
|
31
|
+
return checkedOutOrder;
|
|
28
32
|
} catch (error) {
|
|
29
33
|
logger.error(error.message, { userId, orderId: order._id });
|
|
30
34
|
throw new OrderCheckoutError({
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { log } from '@unchainedshop/logger';
|
|
2
2
|
import { Context } from '../../../context.js';
|
|
3
|
-
import {
|
|
4
|
-
import { OrderWrongStatusError } from '../../../errors.js';
|
|
3
|
+
import { OrderNotFoundError, OrderWrongStatusError } from '../../../errors.js';
|
|
5
4
|
|
|
6
5
|
export default async function emptyCart(
|
|
7
6
|
root: never,
|
|
@@ -12,7 +11,12 @@ export default async function emptyCart(
|
|
|
12
11
|
|
|
13
12
|
log('mutation emptyCart', { userId, orderId });
|
|
14
13
|
|
|
15
|
-
const order = await
|
|
14
|
+
const order = await services.orders.findOrInitCart({
|
|
15
|
+
orderId,
|
|
16
|
+
user,
|
|
17
|
+
countryCode: context.countryContext,
|
|
18
|
+
});
|
|
19
|
+
if (!order) throw new OrderNotFoundError({ orderId });
|
|
16
20
|
if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
|
|
17
21
|
|
|
18
22
|
if (!order) return null;
|
|
@@ -32,7 +32,7 @@ export default async function signPaymentProviderForCheckout(
|
|
|
32
32
|
if (!orderPayment) throw new OrderPaymentNotFoundError({ orderPaymentId });
|
|
33
33
|
} else {
|
|
34
34
|
const order = await modules.orders.cart({
|
|
35
|
-
|
|
35
|
+
countryCode: context.countryContext,
|
|
36
36
|
userId,
|
|
37
37
|
});
|
|
38
38
|
if (!order) throw new UserNoCartError({ userId });
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { log } from '@unchainedshop/logger';
|
|
2
2
|
import { Context } from '../../../context.js';
|
|
3
|
-
import {
|
|
4
|
-
import { OrderWrongStatusError } from '../../../errors.js';
|
|
3
|
+
import { OrderNotFoundError, OrderWrongStatusError } from '../../../errors.js';
|
|
5
4
|
import { Address, Contact } from '@unchainedshop/mongodb';
|
|
6
5
|
|
|
7
6
|
interface UpdateCartParams {
|
|
@@ -20,7 +19,12 @@ export default async function updateCart(root: never, params: UpdateCartParams,
|
|
|
20
19
|
|
|
21
20
|
log('mutation updateCart', { userId });
|
|
22
21
|
|
|
23
|
-
let order = await
|
|
22
|
+
let order = await services.orders.findOrInitCart({
|
|
23
|
+
orderId,
|
|
24
|
+
user,
|
|
25
|
+
countryCode: context.countryContext,
|
|
26
|
+
});
|
|
27
|
+
if (!order) throw new OrderNotFoundError({ orderId });
|
|
24
28
|
if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
|
|
25
29
|
|
|
26
30
|
if (meta) {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Context } from '../../context.js';
|
|
2
2
|
import { DeliveryProvider as DeliveryProviderType } from '@unchainedshop/core-delivery';
|
|
3
3
|
import { DeliveryDirector, DeliveryError, DeliveryPricingDirector } from '@unchainedshop/core';
|
|
4
|
-
import { sha256 } from '@unchainedshop/utils';
|
|
5
4
|
|
|
6
5
|
export type HelperType<P, T> = (provider: DeliveryProviderType, params: P, context: Context) => T;
|
|
7
6
|
|
|
@@ -24,7 +23,6 @@ export interface DeliveryProviderHelperTypes {
|
|
|
24
23
|
context: any;
|
|
25
24
|
},
|
|
26
25
|
Promise<{
|
|
27
|
-
_id: string;
|
|
28
26
|
amount: number;
|
|
29
27
|
currencyCode: string;
|
|
30
28
|
countryCode: string;
|
|
@@ -84,7 +82,6 @@ export const DeliveryProvider: DeliveryProviderHelperTypes = {
|
|
|
84
82
|
};
|
|
85
83
|
|
|
86
84
|
return {
|
|
87
|
-
_id: await sha256([deliveryProvider._id, country, useNetPrice, order ? order._id : ''].join('')),
|
|
88
85
|
amount: orderPrice.amount,
|
|
89
86
|
currencyCode: orderPrice.currency,
|
|
90
87
|
countryCode: country,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Context } from '../../../context.js';
|
|
2
2
|
import { Filter, SearchQuery } from '@unchainedshop/core-filters';
|
|
3
3
|
import { FilterDirector } from '@unchainedshop/core';
|
|
4
|
-
import { intersectSet } from '@unchainedshop/utils';
|
|
5
4
|
|
|
6
5
|
type LoadedFilterData = {
|
|
7
6
|
forceLiveCollection: boolean;
|
|
@@ -26,7 +25,7 @@ export const LoadedFilter = {
|
|
|
26
25
|
) => {
|
|
27
26
|
const filterActions = await FilterDirector.actions({ searchQuery }, context);
|
|
28
27
|
return filterActions.aggregateProductIds({
|
|
29
|
-
productIds: Array.from(
|
|
28
|
+
productIds: Array.from(filteredByOtherFiltersSet.intersection(filteredByThisFilterSet)),
|
|
30
29
|
}).length;
|
|
31
30
|
},
|
|
32
31
|
productsCount: async (
|
|
@@ -12,7 +12,6 @@ import { Country } from './country-types.js';
|
|
|
12
12
|
import { Currency } from './currency-types.js';
|
|
13
13
|
import { DeliveryProvider } from './delivery-provider-types.js';
|
|
14
14
|
import { Dimensions } from './dimensions-types.js';
|
|
15
|
-
import { Dispatch } from './dispatch-types.js';
|
|
16
15
|
import { Enrollment } from './enrollment/enrollment-types.js';
|
|
17
16
|
import { EnrollmentDelivery } from './enrollment/enrollment-delivery-types.js';
|
|
18
17
|
import { EnrollmentPayment } from './enrollment/enrollment-payment-types.js';
|
|
@@ -57,7 +56,6 @@ import { Quotation } from './quotation-types.js';
|
|
|
57
56
|
import { Shop } from './shop-types.js';
|
|
58
57
|
import { SimpleProduct } from './product/product-simple-types.js';
|
|
59
58
|
import { TokenizedProduct } from './product/product-tokenized-types.js';
|
|
60
|
-
import { Stock } from './stock-types.js';
|
|
61
59
|
import { User } from './user-types.js';
|
|
62
60
|
import { WebAuthnCredentials } from './webauthn-credentials-types.js';
|
|
63
61
|
import { WarehousingProvider } from './warehousing-provider-types.js';
|
|
@@ -84,7 +82,6 @@ const types = {
|
|
|
84
82
|
Currency,
|
|
85
83
|
DeliveryProvider,
|
|
86
84
|
Dimensions,
|
|
87
|
-
Dispatch,
|
|
88
85
|
Enrollment,
|
|
89
86
|
EnrollmentDelivery,
|
|
90
87
|
EnrollmentPayment,
|
|
@@ -131,7 +128,6 @@ const types = {
|
|
|
131
128
|
SimpleProduct,
|
|
132
129
|
TokenizedProduct,
|
|
133
130
|
Token,
|
|
134
|
-
Stock,
|
|
135
131
|
User,
|
|
136
132
|
WebAuthnCredentials,
|
|
137
133
|
WarehousingProvider,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Context } from '../../../context.js';
|
|
2
2
|
import { OrderDeliveryDiscount as OrderDeliveryDiscountType } from '@unchainedshop/core-orders';
|
|
3
|
-
import { sha256 } from '@unchainedshop/utils';
|
|
4
3
|
|
|
5
4
|
export const OrderDeliveryDiscount = {
|
|
6
5
|
_id(obj: OrderDeliveryDiscountType) {
|
|
@@ -13,9 +12,8 @@ export const OrderDeliveryDiscount = {
|
|
|
13
12
|
});
|
|
14
13
|
},
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
total(obj: OrderDeliveryDiscountType) {
|
|
17
16
|
return {
|
|
18
|
-
_id: await sha256([`${obj.item._id}:${obj.discountId}`, obj.amount, obj.currency].join('')),
|
|
19
17
|
amount: obj.amount,
|
|
20
18
|
currency: obj.currency,
|
|
21
19
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Order } from '@unchainedshop/core-orders';
|
|
2
2
|
import { Context } from '../../../context.js';
|
|
3
|
-
import { Price
|
|
3
|
+
import { Price } from '@unchainedshop/utils';
|
|
4
4
|
|
|
5
5
|
export const OrderGlobalDiscount = {
|
|
6
6
|
_id(
|
|
@@ -25,14 +25,13 @@ export const OrderGlobalDiscount = {
|
|
|
25
25
|
});
|
|
26
26
|
},
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
total(
|
|
29
29
|
obj: Price & {
|
|
30
30
|
order: Order;
|
|
31
31
|
discountId: string;
|
|
32
32
|
},
|
|
33
33
|
) {
|
|
34
34
|
return {
|
|
35
|
-
_id: await sha256([`${obj.order._id}:${obj.discountId}`, obj.amount, obj.currency].join('')),
|
|
36
35
|
amount: obj.amount,
|
|
37
36
|
currency: obj.currency,
|
|
38
37
|
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { sha256 } from '@unchainedshop/utils';
|
|
2
1
|
import { Context } from '../../../context.js';
|
|
3
2
|
import { OrderPositionDiscount } from '@unchainedshop/core-orders';
|
|
4
3
|
|
|
@@ -13,9 +12,8 @@ export const OrderItemDiscount = {
|
|
|
13
12
|
});
|
|
14
13
|
},
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
total(obj: OrderPositionDiscount) {
|
|
17
16
|
return {
|
|
18
|
-
_id: await sha256([`${obj.item._id}:${obj.discountId}`, obj.amount, obj.currency].join('')),
|
|
19
17
|
amount: obj.amount,
|
|
20
18
|
currency: obj.currency,
|
|
21
19
|
};
|
|
@@ -5,7 +5,7 @@ import { OrderPosition, OrderPositionDiscount } from '@unchainedshop/core-orders
|
|
|
5
5
|
import { Product } from '@unchainedshop/core-products';
|
|
6
6
|
import { Quotation } from '@unchainedshop/core-quotations';
|
|
7
7
|
import { TokenSurrogate, WarehousingProvider } from '@unchainedshop/core-warehousing';
|
|
8
|
-
import { Price
|
|
8
|
+
import { Price } from '@unchainedshop/utils';
|
|
9
9
|
import { ProductPricingSheet } from '@unchainedshop/core';
|
|
10
10
|
|
|
11
11
|
const getPricingSheet = async (orderPosition: OrderPosition, context: Context) => {
|
|
@@ -120,11 +120,7 @@ export const OrderItem = {
|
|
|
120
120
|
const pricing = await getPricingSheet(orderPosition, context);
|
|
121
121
|
|
|
122
122
|
if (pricing.isValid()) {
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
_id: await sha256([orderPosition._id, JSON.stringify(params), JSON.stringify(price)].join('')),
|
|
126
|
-
...price,
|
|
127
|
-
};
|
|
123
|
+
return pricing.total(params);
|
|
128
124
|
}
|
|
129
125
|
return null;
|
|
130
126
|
},
|
|
@@ -137,11 +133,7 @@ export const OrderItem = {
|
|
|
137
133
|
const pricing = await getPricingSheet(orderPosition, context);
|
|
138
134
|
|
|
139
135
|
if (pricing.isValid()) {
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
_id: await sha256([`${orderPosition._id}-unit`, price.amount, pricing.currency].join('')),
|
|
143
|
-
...price,
|
|
144
|
-
};
|
|
136
|
+
return pricing.unitPrice(params);
|
|
145
137
|
}
|
|
146
138
|
return null;
|
|
147
139
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context } from '../../../context.js';
|
|
2
2
|
import { OrderPayment } from '@unchainedshop/core-orders';
|
|
3
|
-
import { Price
|
|
3
|
+
import { Price } from '@unchainedshop/utils';
|
|
4
4
|
|
|
5
5
|
export const OrderPaymentDiscount = {
|
|
6
6
|
_id: (orderDelivery: Price & { discountId: string; item: OrderPayment }) =>
|
|
@@ -15,15 +15,8 @@ export const OrderPaymentDiscount = {
|
|
|
15
15
|
discountId: orderDelivery.discountId,
|
|
16
16
|
}),
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
total(orderDelivery: Price & { discountId: string; item: OrderPayment }) {
|
|
19
19
|
return {
|
|
20
|
-
_id: await sha256(
|
|
21
|
-
[
|
|
22
|
-
`${orderDelivery.item._id}-${orderDelivery.discountId}`,
|
|
23
|
-
orderDelivery.amount,
|
|
24
|
-
orderDelivery.currency,
|
|
25
|
-
].join(''),
|
|
26
|
-
),
|
|
27
20
|
amount: orderDelivery.amount,
|
|
28
21
|
currency: orderDelivery.currency,
|
|
29
22
|
};
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
OrderDelivery,
|
|
12
12
|
} from '@unchainedshop/core-orders';
|
|
13
13
|
import { User } from '@unchainedshop/core-users';
|
|
14
|
-
import { Price
|
|
14
|
+
import { Price } from '@unchainedshop/utils';
|
|
15
15
|
import { OrderPricingSheet } from '@unchainedshop/core';
|
|
16
16
|
|
|
17
17
|
export const Order = {
|
|
@@ -74,18 +74,14 @@ export const Order = {
|
|
|
74
74
|
return order.status;
|
|
75
75
|
},
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
total(order: OrderType, params: { category: string; useNetPrice: boolean }): Price {
|
|
78
78
|
const pricing = OrderPricingSheet({
|
|
79
79
|
calculation: order.calculation,
|
|
80
80
|
currency: order.currency,
|
|
81
81
|
});
|
|
82
82
|
|
|
83
83
|
if (pricing.isValid()) {
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
_id: await sha256([order._id, JSON.stringify(params), JSON.stringify(price)].join('')),
|
|
87
|
-
...price,
|
|
88
|
-
};
|
|
84
|
+
return pricing.total(params);
|
|
89
85
|
}
|
|
90
86
|
return null;
|
|
91
87
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Context } from '../../../context.js';
|
|
2
2
|
import { PaymentProvider as PaymentProviderType } from '@unchainedshop/core-payment';
|
|
3
3
|
import { PaymentDirector, PaymentPricingDirector } from '@unchainedshop/core';
|
|
4
|
-
import { sha256 } from '@unchainedshop/utils';
|
|
5
4
|
|
|
6
5
|
export const PaymentProvider = {
|
|
7
6
|
interface(provider: PaymentProviderType) {
|
|
@@ -53,7 +52,6 @@ export const PaymentProvider = {
|
|
|
53
52
|
};
|
|
54
53
|
|
|
55
54
|
return {
|
|
56
|
-
_id: await sha256([paymentProvider._id, country, useNetPrice, order ? order._id : ''].join('')),
|
|
57
55
|
amount: orderPrice.amount,
|
|
58
56
|
currencyCode: orderPrice.currency,
|
|
59
57
|
countryCode: country,
|
|
@@ -7,8 +7,6 @@ import {
|
|
|
7
7
|
} from '@unchainedshop/core-products';
|
|
8
8
|
import { Context } from '../../../context.js';
|
|
9
9
|
import { Product } from './product-types.js';
|
|
10
|
-
import { sha256 } from '@unchainedshop/utils';
|
|
11
|
-
import { ProductPricingDirector } from '@unchainedshop/core';
|
|
12
10
|
|
|
13
11
|
export const ConfigurableProduct = {
|
|
14
12
|
...Product,
|
|
@@ -105,7 +103,7 @@ export const ConfigurableProduct = {
|
|
|
105
103
|
},
|
|
106
104
|
requestContext: Context,
|
|
107
105
|
): Promise<ProductPriceRange> {
|
|
108
|
-
const { countryContext, modules } = requestContext;
|
|
106
|
+
const { countryContext, modules, services } = requestContext;
|
|
109
107
|
const currency = forcedCurrencyCode || requestContext.currencyContext;
|
|
110
108
|
|
|
111
109
|
const products = await modules.products.proxyProducts(product, vectors, {
|
|
@@ -123,26 +121,11 @@ export const ConfigurableProduct = {
|
|
|
123
121
|
quantity,
|
|
124
122
|
};
|
|
125
123
|
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
requestContext,
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
if (!calculated || !calculated.length) return null;
|
|
132
|
-
|
|
133
|
-
const pricing = ProductPricingDirector.calculationSheet(pricingContext, calculated);
|
|
124
|
+
const pricing = await services.products.simulateProductPricing(pricingContext);
|
|
125
|
+
if (!pricing) return null;
|
|
134
126
|
const unitPrice = pricing.unitPrice({ useNetPrice });
|
|
135
127
|
|
|
136
128
|
return {
|
|
137
|
-
_id: await sha256(
|
|
138
|
-
[
|
|
139
|
-
proxyProduct._id,
|
|
140
|
-
countryContext,
|
|
141
|
-
quantity,
|
|
142
|
-
useNetPrice,
|
|
143
|
-
requestContext.userId || 'ANONYMOUS',
|
|
144
|
-
].join(''),
|
|
145
|
-
),
|
|
146
129
|
...unitPrice,
|
|
147
130
|
isNetPrice: useNetPrice,
|
|
148
131
|
isTaxable: pricing.taxSum() > 0,
|
|
@@ -159,36 +142,9 @@ export const ConfigurableProduct = {
|
|
|
159
142
|
prices: filteredPrices,
|
|
160
143
|
});
|
|
161
144
|
|
|
162
|
-
const minPriceHash = await sha256(
|
|
163
|
-
[
|
|
164
|
-
product._id,
|
|
165
|
-
minPrice?.isTaxable,
|
|
166
|
-
minPrice?.isNetPrice,
|
|
167
|
-
minPrice?.amount,
|
|
168
|
-
minPrice?.currencyCode,
|
|
169
|
-
].join(''),
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
const maxPriceHash = await sha256(
|
|
173
|
-
[
|
|
174
|
-
product._id,
|
|
175
|
-
maxPrice?.isTaxable,
|
|
176
|
-
maxPrice?.isNetPrice,
|
|
177
|
-
maxPrice?.amount,
|
|
178
|
-
maxPrice?.currencyCode,
|
|
179
|
-
].join(''),
|
|
180
|
-
);
|
|
181
|
-
|
|
182
145
|
return {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
_id: minPriceHash,
|
|
186
|
-
...minPrice,
|
|
187
|
-
},
|
|
188
|
-
maxPrice: {
|
|
189
|
-
_id: maxPriceHash,
|
|
190
|
-
...maxPrice,
|
|
191
|
-
},
|
|
146
|
+
minPrice,
|
|
147
|
+
maxPrice,
|
|
192
148
|
};
|
|
193
149
|
},
|
|
194
150
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ProductDiscount as ProductDiscountType } from '@unchainedshop/core-products';
|
|
2
2
|
import { ProductDiscountDirector } from '@unchainedshop/core';
|
|
3
|
-
import { sha256 } from '@unchainedshop/utils';
|
|
4
3
|
|
|
5
4
|
export const ProductDiscount = {
|
|
6
5
|
interface: async (productDiscount: ProductDiscountType) => {
|
|
@@ -15,11 +14,10 @@ export const ProductDiscount = {
|
|
|
15
14
|
};
|
|
16
15
|
},
|
|
17
16
|
|
|
18
|
-
|
|
19
|
-
const { total
|
|
17
|
+
total(productDiscount: ProductDiscountType) {
|
|
18
|
+
const { total } = productDiscount;
|
|
20
19
|
if (productDiscount.total) {
|
|
21
20
|
return {
|
|
22
|
-
_id: await sha256([`${_id}`, total.amount, total.currency].join('')),
|
|
23
21
|
amount: total.amount,
|
|
24
22
|
currency: total.currency,
|
|
25
23
|
};
|