@unchainedshop/api 4.0.0-rc.14 → 4.0.0-rc.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/lib/express/createERCMetadataMiddleware.d.ts.map +1 -1
  2. package/lib/express/createERCMetadataMiddleware.js +10 -9
  3. package/lib/express/createERCMetadataMiddleware.js.map +1 -1
  4. package/lib/fastify/bulkImportHandler.js +1 -1
  5. package/lib/fastify/bulkImportHandler.js.map +1 -1
  6. package/lib/fastify/ercMetadataHandler.js +1 -1
  7. package/lib/fastify/ercMetadataHandler.js.map +1 -1
  8. package/lib/fastify/tempUploadHandler.js +1 -1
  9. package/lib/fastify/tempUploadHandler.js.map +1 -1
  10. package/lib/mcp/tools/order/schemas.d.ts +2 -2
  11. package/lib/mcp/tools/product/schemas.d.ts +62 -62
  12. package/lib/mcp/tools/users/schemas.d.ts +2 -2
  13. package/lib/resolvers/mutations/index.d.ts +4 -1
  14. package/lib/resolvers/mutations/index.d.ts.map +1 -1
  15. package/lib/resolvers/mutations/index.js +8 -2
  16. package/lib/resolvers/mutations/index.js.map +1 -1
  17. package/lib/resolvers/mutations/orders/updateCart.js +6 -6
  18. package/lib/resolvers/mutations/orders/updateCart.js.map +1 -1
  19. package/lib/resolvers/mutations/orders/updateCartDeliveryPickUp.d.ts +8 -0
  20. package/lib/resolvers/mutations/orders/updateCartDeliveryPickUp.d.ts.map +1 -0
  21. package/lib/resolvers/mutations/orders/updateCartDeliveryPickUp.js +38 -0
  22. package/lib/resolvers/mutations/orders/updateCartDeliveryPickUp.js.map +1 -0
  23. package/lib/resolvers/mutations/orders/updateCartDeliveryShipping.d.ts +8 -0
  24. package/lib/resolvers/mutations/orders/updateCartDeliveryShipping.d.ts.map +1 -0
  25. package/lib/resolvers/mutations/orders/updateCartDeliveryShipping.js +38 -0
  26. package/lib/resolvers/mutations/orders/updateCartDeliveryShipping.js.map +1 -0
  27. package/lib/resolvers/mutations/orders/updateCartPaymentGeneric.d.ts +7 -0
  28. package/lib/resolvers/mutations/orders/updateCartPaymentGeneric.d.ts.map +1 -0
  29. package/lib/resolvers/mutations/orders/updateCartPaymentGeneric.js +37 -0
  30. package/lib/resolvers/mutations/orders/updateCartPaymentGeneric.js.map +1 -0
  31. package/lib/resolvers/mutations/orders/updateCartPaymentInvoice.d.ts +7 -0
  32. package/lib/resolvers/mutations/orders/updateCartPaymentInvoice.d.ts.map +1 -0
  33. package/lib/resolvers/mutations/orders/updateCartPaymentInvoice.js +37 -0
  34. package/lib/resolvers/mutations/orders/updateCartPaymentInvoice.js.map +1 -0
  35. package/lib/resolvers/mutations/products/updateProductCommerce.d.ts.map +1 -1
  36. package/lib/resolvers/mutations/products/updateProductCommerce.js +11 -2
  37. package/lib/resolvers/mutations/products/updateProductCommerce.js.map +1 -1
  38. package/lib/resolvers/type/index.d.ts +20 -0
  39. package/lib/resolvers/type/index.d.ts.map +1 -1
  40. package/lib/resolvers/type/order/order-payment-types.d.ts.map +1 -1
  41. package/lib/resolvers/type/order/order-payment-types.js +0 -1
  42. package/lib/resolvers/type/order/order-payment-types.js.map +1 -1
  43. package/lib/resolvers/type/product/product-bundle-types.d.ts +20 -0
  44. package/lib/resolvers/type/product/product-bundle-types.d.ts.map +1 -1
  45. package/lib/resolvers/type/product/product-bundle-types.js +2 -2
  46. package/lib/resolvers/type/product/product-bundle-types.js.map +1 -1
  47. package/lib/schema/mutation.d.ts.map +1 -1
  48. package/lib/schema/mutation.js +36 -7
  49. package/lib/schema/mutation.js.map +1 -1
  50. package/lib/schema/types/payment.d.ts.map +1 -1
  51. package/lib/schema/types/payment.js +0 -5
  52. package/lib/schema/types/payment.js.map +1 -1
  53. package/lib/schema/types/product/bundle-product.d.ts.map +1 -1
  54. package/lib/schema/types/product/bundle-product.js +18 -7
  55. package/lib/schema/types/product/bundle-product.js.map +1 -1
  56. package/package.json +6 -6
  57. package/src/express/createERCMetadataMiddleware.ts +11 -9
  58. package/src/fastify/bulkImportHandler.ts +1 -1
  59. package/src/fastify/ercMetadataHandler.ts +1 -1
  60. package/src/fastify/tempUploadHandler.ts +1 -1
  61. package/src/resolvers/mutations/index.ts +8 -2
  62. package/src/resolvers/mutations/orders/updateCart.ts +6 -6
  63. package/src/resolvers/mutations/orders/updateCartDeliveryPickUp.ts +51 -0
  64. package/src/resolvers/mutations/orders/updateCartDeliveryShipping.ts +51 -0
  65. package/src/resolvers/mutations/orders/updateCartPaymentGeneric.ts +50 -0
  66. package/src/resolvers/mutations/orders/updateCartPaymentInvoice.ts +50 -0
  67. package/src/resolvers/mutations/products/updateProductCommerce.ts +12 -4
  68. package/src/resolvers/type/order/order-payment-types.ts +0 -1
  69. package/src/resolvers/type/product/product-bundle-types.ts +2 -2
  70. package/src/schema/mutation.ts +36 -7
  71. package/src/schema/types/payment.ts +0 -5
  72. package/src/schema/types/product/bundle-product.ts +18 -7
  73. package/src/resolvers/mutations/orders/updateOrderPaymentCard.ts +0 -37
@@ -7,11 +7,6 @@ export default [
7
7
  }
8
8
 
9
9
  enum PaymentProviderType {
10
- """
11
- Card
12
- """
13
- CARD
14
-
15
10
  """
16
11
  Invoice
17
12
  """
@@ -1 +1 @@
1
- {"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../src/schema/types/payment.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0Db;CACF,CAAC"}
1
+ {"version":3,"file":"payment.js","sourceRoot":"","sources":["../../../src/schema/types/payment.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDb;CACF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"bundle-product.d.ts","sourceRoot":"","sources":["../../../../src/schema/types/product/bundle-product.ts"],"names":[],"mappings":";AAAA,wBAuCE"}
1
+ {"version":3,"file":"bundle-product.d.ts","sourceRoot":"","sources":["../../../../src/schema/types/product/bundle-product.ts"],"names":[],"mappings":";AAAA,wBAkDE"}
@@ -13,14 +13,18 @@ export default [
13
13
  published: DateTime
14
14
  media(limit: Int = 10, offset: Int = 0, tags: [LowerCaseString!]): [ProductMedia!]!
15
15
  texts(forceLocale: Locale): ProductTexts
16
+ catalogPrice(quantity: Int = 1, currencyCode: String): Price
17
+ leveledCatalogPrices(currencyCode: String): [PriceLevel!]!
18
+ simulatedPrice(
19
+ currencyCode: String
20
+ useNetPrice: Boolean = false
21
+ quantity: Int = 1
22
+ configuration: [ProductConfigurationParameterInput!]
23
+ ): Price @cacheControl(scope: PRIVATE, maxAge: 10)
24
+ salesUnit: String
25
+ salesQuantityPerUnit: String
26
+ defaultOrderQuantity: Int
16
27
  bundleItems: [ProductBundleItem!]
17
- reviews(
18
- limit: Int = 10
19
- offset: Int = 0
20
- sort: [SortOptionInput!]
21
- queryString: String
22
- ): [ProductReview!]!
23
- reviewsCount(queryString: String): Int!
24
28
  assortmentPaths: [ProductAssortmentPath!]!
25
29
  proxies: [ConfigurableOrBundleProduct!]!
26
30
  siblings(
@@ -29,6 +33,13 @@ export default [
29
33
  offset: Int = 0
30
34
  includeInactive: Boolean = false
31
35
  ): [Product!]!
36
+ reviews(
37
+ limit: Int = 10
38
+ offset: Int = 0
39
+ sort: [SortOptionInput!]
40
+ queryString: String
41
+ ): [ProductReview!]!
42
+ reviewsCount(queryString: String): Int!
32
43
  }
33
44
 
34
45
  type ProductBundleItem @cacheControl(maxAge: 180) {
@@ -1 +1 @@
1
- {"version":3,"file":"bundle-product.js","sourceRoot":"","sources":["../../../../src/schema/types/product/bundle-product.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCb;CACF,CAAC"}
1
+ {"version":3,"file":"bundle-product.js","sourceRoot":"","sources":["../../../../src/schema/types/product/bundle-product.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDb;CACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/api",
3
- "version": "4.0.0-rc.14",
3
+ "version": "4.0.0-rc.15",
4
4
  "main": "lib/api-index.js",
5
5
  "types": "lib/api-index.d.ts",
6
6
  "type": "module",
@@ -87,11 +87,11 @@
87
87
  }
88
88
  },
89
89
  "dependencies": {
90
- "@unchainedshop/core": "^4.0.0-rc.14",
91
- "@unchainedshop/events": "^4.0.0-rc.14",
92
- "@unchainedshop/logger": "^4.0.0-rc.14",
93
- "@unchainedshop/roles": "^4.0.0-rc.14",
94
- "@unchainedshop/utils": "^4.0.0-rc.14",
90
+ "@unchainedshop/core": "^4.0.0-rc.15",
91
+ "@unchainedshop/events": "^4.0.0-rc.15",
92
+ "@unchainedshop/logger": "^4.0.0-rc.15",
93
+ "@unchainedshop/roles": "^4.0.0-rc.15",
94
+ "@unchainedshop/utils": "^4.0.0-rc.15",
95
95
  "accounting": "0.4.1",
96
96
  "dataloader": "^2.2.3",
97
97
  "expiry-map": "^2.0.0",
@@ -1,4 +1,3 @@
1
- import path from 'node:path';
2
1
  import { createLogger } from '@unchainedshop/logger';
3
2
  import { Context } from '../context.js';
4
3
  import { Request, RequestHandler } from 'express';
@@ -25,16 +24,20 @@ const ercMetadataMiddleware: RequestHandler = async (
25
24
 
26
25
  const { services, modules, loaders, locale } = req.unchainedContext;
27
26
  const url = new URL(req.url, ROOT_URL);
28
- const parsedPath = path.parse(url.pathname);
29
27
 
30
- if (parsedPath.ext !== '.json') throw new Error('Invalid ERC Metadata URI');
28
+ // Replace path.parse with URL/string methods
29
+ const pathname = url.pathname;
30
+ if (!pathname.toLowerCase().endsWith('.json')) throw new Error('Invalid ERC Metadata URI');
31
+
32
+ const fileName = pathname.split('/').pop();
33
+ const chainTokenId = fileName.slice(0, fileName.lastIndexOf('.'));
31
34
 
32
35
  const [, productId, localeOrTokenFilename, tokenFileName] = url.pathname.split('/');
33
36
 
34
37
  const product = await loaders.productLoader.load({ productId });
35
38
 
36
39
  const [token] = await modules.warehousing.findTokens({
37
- chainTokenId: parsedPath.name,
40
+ chainTokenId,
38
41
  contractAddress: product?.tokenization?.contractAddress,
39
42
  });
40
43
 
@@ -49,11 +52,10 @@ const ercMetadataMiddleware: RequestHandler = async (
49
52
  }
50
53
 
51
54
  const body = JSON.stringify(ercMetadata);
52
- res.writeHead(200, {
53
- 'Content-Length': Buffer.byteLength(body),
54
- 'Content-Type': 'text/plain',
55
- });
56
- res.end(body);
55
+ res.status(200);
56
+ res.setHeader('Content-Type', 'application/json');
57
+ res.setHeader('Content-Length', new TextEncoder().encode(body).length);
58
+ return res.send(body);
57
59
  } catch (e) {
58
60
  logger.error(e.message);
59
61
  res.writeHead(503);
@@ -46,7 +46,7 @@ const bulkImportHandler: RouteHandlerMethod = async (
46
46
 
47
47
  const body = JSON.stringify(work);
48
48
  res.status(200);
49
- res.header('Content-Length', Buffer.byteLength(body));
49
+ res.header('Content-Length', new TextEncoder().encode(body).length);
50
50
  res.header('Content-Type', 'application/json');
51
51
  return res.send(body);
52
52
  } catch (e) {
@@ -41,7 +41,7 @@ const ercMetadataHandler: RouteHandlerMethod = async (
41
41
 
42
42
  const body = JSON.stringify(ercMetadata);
43
43
  res.status(200);
44
- res.header('Content-Length', Buffer.byteLength(body));
44
+ res.header('Content-Length', new TextEncoder().encode(body).length);
45
45
  res.header('Content-Type', 'application/json');
46
46
  return res.send(body);
47
47
  } catch (e) {
@@ -39,7 +39,7 @@ const tempUploadHandler: RouteHandlerMethod = async (
39
39
  const url = context.modules.files.normalizeUrl(rawUrl, {});
40
40
  const body = JSON.stringify({ fileId: file._id, url, expires: expires.toISOString() });
41
41
  res.status(200);
42
- res.header('Content-Length', Buffer.byteLength(body));
42
+ res.header('Content-Length', new TextEncoder().encode(body).length);
43
43
  res.header('Content-Type', 'application/json');
44
44
  return res.send(body);
45
45
  } catch (e) {
@@ -138,7 +138,6 @@ import removePaymentCredentials from './payment/removePaymentCredentials.js';
138
138
  import updateOrderDeliveryShipping from './orders/updateOrderDeliveryShipping.js';
139
139
  import updateOrderDeliveryPickUp from './orders/updateOrderDeliveryPickUp.js';
140
140
  import updateOrderPaymentGeneric from './orders/updateOrderPaymentGeneric.js';
141
- import updateOrderPaymentCard from './orders/updateOrderPaymentCard.js';
142
141
  import updateOrderPaymentInvoice from './orders/updateOrderPaymentInvoice.js';
143
142
  import signPaymentProviderForCredentialRegistration from './payment/signPaymentProviderForCredentialRegistration.js';
144
143
  import signPaymentProviderForCheckout from './orders/signPaymentProviderForCheckout.js';
@@ -153,6 +152,10 @@ import rejectOrder from './orders/rejectOrder.js';
153
152
  import removePushSubscription from './users/removePushSubscription.js';
154
153
  import addPushSubscription from './users/addPushSubscription.js';
155
154
  import removeUserProductReviews from './users/removeUserProductReviews.js';
155
+ import updateCartDeliveryPickUp from './orders/updateCartDeliveryPickUp.js';
156
+ import updateCartDeliveryShipping from './orders/updateCartDeliveryShipping.js';
157
+ import updateCartPaymentGeneric from './orders/updateCartPaymentGeneric.js';
158
+ import updateCartPaymentInvoice from './orders/updateCartPaymentInvoice.js';
156
159
 
157
160
  export default {
158
161
  logout: acl(actions.logout)(logout),
@@ -244,12 +247,15 @@ export default {
244
247
  updateCartItem: acl(actions.updateOrderItem)(updateCartItem),
245
248
  removeCartItem: acl(actions.updateOrderItem)(removeCartItem),
246
249
  removeCartDiscount: acl(actions.updateOrderDiscount)(removeCartDiscount),
250
+ updateCartDeliveryPickUp: acl(actions.updateCart)(updateCartDeliveryPickUp),
251
+ updateCartDeliveryShipping: acl(actions.updateCart)(updateCartDeliveryShipping),
252
+ updateCartPaymentGeneric: acl(actions.updateCart)(updateCartPaymentGeneric),
253
+ updateCartPaymentInvoice: acl(actions.updateCart)(updateCartPaymentInvoice),
247
254
  setOrderPaymentProvider: acl(actions.updateOrder)(setOrderPaymentProvider),
248
255
  setOrderDeliveryProvider: acl(actions.updateOrder)(setOrderDeliveryProvider),
249
256
  updateOrderDeliveryShipping: acl(actions.updateOrderDelivery)(updateOrderDeliveryShipping),
250
257
  updateOrderDeliveryPickUp: acl(actions.updateOrderDelivery)(updateOrderDeliveryPickUp),
251
258
  updateOrderPaymentGeneric: acl(actions.updateOrderPayment)(updateOrderPaymentGeneric),
252
- updateOrderPaymentCard: acl(actions.updateOrderPayment)(updateOrderPaymentCard),
253
259
  updateOrderPaymentInvoice: acl(actions.updateOrderPayment)(updateOrderPaymentInvoice),
254
260
  removeOrder: acl(actions.updateOrder)(removeOrder),
255
261
  confirmOrder: acl(actions.markOrderConfirmed)(confirmOrder),
@@ -19,7 +19,7 @@ export default async function updateCart(root: never, params: UpdateCartParams,
19
19
 
20
20
  log('mutation updateCart', { userId });
21
21
 
22
- let order = await services.orders.findOrInitCart({
22
+ const order = await services.orders.findOrInitCart({
23
23
  orderId,
24
24
  user,
25
25
  countryCode: context.countryCode,
@@ -28,23 +28,23 @@ export default async function updateCart(root: never, params: UpdateCartParams,
28
28
  if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
29
29
 
30
30
  if (meta) {
31
- order = await modules.orders.updateContext(order._id, meta);
31
+ await modules.orders.updateContext(order._id, meta);
32
32
  }
33
33
 
34
34
  if (billingAddress) {
35
- order = await modules.orders.updateBillingAddress(order._id, billingAddress);
35
+ await modules.orders.updateBillingAddress(order._id, billingAddress);
36
36
  }
37
37
 
38
38
  if (contact) {
39
- order = await modules.orders.updateContact(order._id, contact);
39
+ await modules.orders.updateContact(order._id, contact);
40
40
  }
41
41
 
42
42
  if (paymentProviderId) {
43
- order = await modules.orders.setPaymentProvider(order._id, paymentProviderId);
43
+ await modules.orders.setPaymentProvider(order._id, paymentProviderId);
44
44
  }
45
45
 
46
46
  if (deliveryProviderId) {
47
- order = await modules.orders.setDeliveryProvider(order._id, deliveryProviderId);
47
+ await modules.orders.setDeliveryProvider(order._id, deliveryProviderId);
48
48
  }
49
49
 
50
50
  // Recalculate, then return
@@ -0,0 +1,51 @@
1
+ import { Context } from '../../../context.js';
2
+ import { DeliveryProviderType } from '@unchainedshop/core-delivery';
3
+ import { log } from '@unchainedshop/logger';
4
+ import {
5
+ InvalidIdError,
6
+ OrderDeliveryTypeError,
7
+ OrderNotFoundError,
8
+ OrderWrongStatusError,
9
+ } from '../../../errors.js';
10
+
11
+ export default async function updateCartDeliveryPickUp(
12
+ root: never,
13
+ params: { orderId: string; deliveryProviderId: string; orderPickUpLocationId: string; meta: any },
14
+ context: Context,
15
+ ) {
16
+ const { modules, services, userId, user } = context;
17
+ const { orderId, deliveryProviderId, orderPickUpLocationId, meta } = params;
18
+ log(`mutation updateCartDeliveryPickUp provider ${deliveryProviderId}`, {
19
+ userId,
20
+ });
21
+
22
+ if (!deliveryProviderId) throw new InvalidIdError({ deliveryProviderId });
23
+
24
+ let order = await services.orders.findOrInitCart({
25
+ orderId,
26
+ user,
27
+ countryCode: context.countryCode,
28
+ });
29
+ if (!order) throw new OrderNotFoundError({ orderId });
30
+ if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
31
+
32
+ const provider = await modules.delivery.findProvider({
33
+ deliveryProviderId,
34
+ });
35
+ const deliveryProviderType = provider?.type;
36
+
37
+ if (deliveryProviderType !== DeliveryProviderType.PICKUP)
38
+ throw new OrderDeliveryTypeError({
39
+ orderId: order._id,
40
+ received: deliveryProviderType,
41
+ required: DeliveryProviderType.PICKUP,
42
+ });
43
+
44
+ order = (await modules.orders.setDeliveryProvider(order._id, deliveryProviderId)) || order;
45
+
46
+ await modules.orders.deliveries.updateContext(order.deliveryId, {
47
+ orderPickUpLocationId,
48
+ meta,
49
+ });
50
+ return services.orders.updateCalculation(order._id);
51
+ }
@@ -0,0 +1,51 @@
1
+ import { Context } from '../../../context.js';
2
+ import { DeliveryProviderType } from '@unchainedshop/core-delivery';
3
+ import { log } from '@unchainedshop/logger';
4
+ import {
5
+ InvalidIdError,
6
+ OrderDeliveryTypeError,
7
+ OrderNotFoundError,
8
+ OrderWrongStatusError,
9
+ } from '../../../errors.js';
10
+
11
+ export default async function updateCartDeliveryShipping(
12
+ root: never,
13
+ params: { orderId: string; deliveryProviderId: string; address: any; meta: any },
14
+ context: Context,
15
+ ) {
16
+ const { modules, services, userId, user } = context;
17
+ const { orderId, deliveryProviderId, address, meta } = params;
18
+ log(`mutation updateCartDeliveryShipping provider ${deliveryProviderId}`, {
19
+ userId,
20
+ });
21
+
22
+ if (!deliveryProviderId) throw new InvalidIdError({ deliveryProviderId });
23
+
24
+ let order = await services.orders.findOrInitCart({
25
+ orderId,
26
+ user,
27
+ countryCode: context.countryCode,
28
+ });
29
+ if (!order) throw new OrderNotFoundError({ orderId });
30
+ if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
31
+
32
+ const provider = await modules.delivery.findProvider({
33
+ deliveryProviderId,
34
+ });
35
+ const deliveryProviderType = provider?.type;
36
+
37
+ if (deliveryProviderType !== DeliveryProviderType.SHIPPING)
38
+ throw new OrderDeliveryTypeError({
39
+ orderId: order._id,
40
+ received: deliveryProviderType,
41
+ required: DeliveryProviderType.SHIPPING,
42
+ });
43
+
44
+ order = (await modules.orders.setDeliveryProvider(order._id, deliveryProviderId)) || order;
45
+
46
+ await modules.orders.deliveries.updateContext(order.deliveryId, {
47
+ address,
48
+ meta,
49
+ });
50
+ return services.orders.updateCalculation(order._id);
51
+ }
@@ -0,0 +1,50 @@
1
+ import { Context } from '../../../context.js';
2
+ import { PaymentProviderType } from '@unchainedshop/core-payment';
3
+ import { log } from '@unchainedshop/logger';
4
+ import {
5
+ InvalidIdError,
6
+ OrderNotFoundError,
7
+ OrderPaymentTypeError,
8
+ OrderWrongStatusError,
9
+ } from '../../../errors.js';
10
+
11
+ export default async function updateCartPaymentGeneric(
12
+ root: never,
13
+ params: { orderId: string; paymentProviderId: string; meta?: any },
14
+ context: Context,
15
+ ) {
16
+ const { modules, services, userId, user } = context;
17
+ const { orderId, paymentProviderId, meta } = params;
18
+ log(`mutation updateCartPaymentGeneric provider ${paymentProviderId}`, {
19
+ userId,
20
+ });
21
+
22
+ if (!paymentProviderId) throw new InvalidIdError({ paymentProviderId });
23
+
24
+ let order = await services.orders.findOrInitCart({
25
+ orderId,
26
+ user,
27
+ countryCode: context.countryCode,
28
+ });
29
+ if (!order) throw new OrderNotFoundError({ orderId });
30
+ if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
31
+
32
+ const provider = await modules.payment.paymentProviders.findProvider({
33
+ paymentProviderId,
34
+ });
35
+ const paymentProviderType = provider?.type;
36
+
37
+ if (paymentProviderType !== PaymentProviderType.GENERIC)
38
+ throw new OrderPaymentTypeError({
39
+ orderId: order._id,
40
+ received: paymentProviderType,
41
+ required: PaymentProviderType.GENERIC,
42
+ });
43
+
44
+ order = (await modules.orders.setPaymentProvider(order._id, paymentProviderId)) || order;
45
+
46
+ await modules.orders.payments.updateContext(order.paymentId, {
47
+ meta,
48
+ });
49
+ return services.orders.updateCalculation(order._id);
50
+ }
@@ -0,0 +1,50 @@
1
+ import { Context } from '../../../context.js';
2
+ import { PaymentProviderType } from '@unchainedshop/core-payment';
3
+ import { log } from '@unchainedshop/logger';
4
+ import {
5
+ InvalidIdError,
6
+ OrderNotFoundError,
7
+ OrderPaymentTypeError,
8
+ OrderWrongStatusError,
9
+ } from '../../../errors.js';
10
+
11
+ export default async function updateCartPaymentInvoice(
12
+ root: never,
13
+ params: { orderId: string; paymentProviderId: string; meta?: any },
14
+ context: Context,
15
+ ) {
16
+ const { modules, services, userId, user } = context;
17
+ const { orderId, paymentProviderId, meta } = params;
18
+ log(`mutation updateCartPaymentInvoice provider ${paymentProviderId}`, {
19
+ userId,
20
+ });
21
+
22
+ if (!paymentProviderId) throw new InvalidIdError({ paymentProviderId });
23
+
24
+ let order = await services.orders.findOrInitCart({
25
+ orderId,
26
+ user,
27
+ countryCode: context.countryCode,
28
+ });
29
+ if (!order) throw new OrderNotFoundError({ orderId });
30
+ if (!modules.orders.isCart(order)) throw new OrderWrongStatusError({ status: order.status });
31
+
32
+ const provider = await modules.payment.paymentProviders.findProvider({
33
+ paymentProviderId,
34
+ });
35
+ const paymentProviderType = provider?.type;
36
+
37
+ if (paymentProviderType !== PaymentProviderType.INVOICE)
38
+ throw new OrderPaymentTypeError({
39
+ orderId: order._id,
40
+ received: paymentProviderType,
41
+ required: PaymentProviderType.INVOICE,
42
+ });
43
+
44
+ order = (await modules.orders.setPaymentProvider(order._id, paymentProviderId)) || order;
45
+
46
+ await modules.orders.payments.updateContext(order.paymentId, {
47
+ meta,
48
+ });
49
+ return services.orders.updateCalculation(order._id);
50
+ }
@@ -1,6 +1,6 @@
1
1
  import { log } from '@unchainedshop/logger';
2
- import { ProductCommerce } from '@unchainedshop/core-products';
3
- import { ProductNotFoundError, InvalidIdError } from '../../../errors.js';
2
+ import { ProductCommerce, ProductTypes } from '@unchainedshop/core-products';
3
+ import { ProductNotFoundError, InvalidIdError, ProductWrongTypeError } from '../../../errors.js';
4
4
  import { Context } from '../../../context.js';
5
5
 
6
6
  export default async function updateProductCommerce(
@@ -12,8 +12,16 @@ export default async function updateProductCommerce(
12
12
 
13
13
  if (!productId) throw new InvalidIdError({ productId });
14
14
 
15
- if (!(await modules.products.productExists({ productId })))
16
- throw new ProductNotFoundError({ productId });
15
+ const product = await modules.products.findProduct({ productId });
16
+ if (!product) throw new ProductNotFoundError({ productId });
17
+
18
+ if (product.type === ProductTypes.ConfigurableProduct) {
19
+ throw new ProductWrongTypeError({
20
+ productId: productId,
21
+ received: product.type,
22
+ required: { not: ProductTypes.ConfigurableProduct },
23
+ });
24
+ }
17
25
 
18
26
  await modules.products.update(productId, { commerce });
19
27
 
@@ -5,7 +5,6 @@ import { objectInvert } from '@unchainedshop/utils';
5
5
 
6
6
  const OrderPaymentMap = {
7
7
  OrderPaymentGeneric: PaymentProviderType.GENERIC,
8
- OrderPaymentCard: PaymentProviderType.CARD,
9
8
  OrderPaymentInvoice: PaymentProviderType.INVOICE,
10
9
  };
11
10
 
@@ -1,8 +1,8 @@
1
1
  import { ProductBundleItem } from '@unchainedshop/core-products';
2
- import { Product } from './product-types.js';
2
+ import { PlanProduct } from './product-plan-types.js';
3
3
 
4
4
  export const BundleProduct = {
5
- ...Product,
5
+ ...PlanProduct,
6
6
 
7
7
  bundleItems(product): ProductBundleItem[] {
8
8
  return product.bundleItems ? product.bundleItems : [];
@@ -226,12 +226,44 @@ export default [
226
226
  doesn’t exists new delivery provider will be created with the provided ID.
227
227
  """
228
228
  setOrderDeliveryProvider(orderId: ID!, deliveryProviderId: ID!): Order!
229
+ @deprecated(reason: "Use updateCart or updateCartDelivery* mutations instead")
229
230
 
230
231
  """
231
232
  Change the payment method/provider to an order. If the payment provider
232
233
  doesn’t exists new payment provider will be created with the provided ID.
233
234
  """
234
235
  setOrderPaymentProvider(orderId: ID!, paymentProviderId: ID!): Order!
236
+ @deprecated(reason: "Use updateCart or updateCartPayment* mutations instead")
237
+
238
+ """
239
+ Update the cart by changing the delivery provider and using a shipping specific configuration
240
+ """
241
+ updateCartDeliveryShipping(
242
+ orderId: ID
243
+ deliveryProviderId: ID!
244
+ address: AddressInput
245
+ meta: JSON
246
+ ): Order!
247
+
248
+ """
249
+ Update the cart by changing the delivery provider and using a pick up specific configuration
250
+ """
251
+ updateCartDeliveryPickUp(
252
+ orderId: ID
253
+ deliveryProviderId: ID!
254
+ orderPickUpLocationId: ID!
255
+ meta: JSON
256
+ ): Order!
257
+
258
+ """
259
+ Update the cart by changing the payment provider and using an invoice-type specific configuration
260
+ """
261
+ updateCartPaymentInvoice(orderId: ID, paymentProviderId: ID!, meta: JSON): Order!
262
+
263
+ """
264
+ Update the cart by changing the payment provider and using a generic specific configuration
265
+ """
266
+ updateCartPaymentGeneric(orderId: ID, paymentProviderId: ID!, meta: JSON): Order!
235
267
 
236
268
  """
237
269
  Update a Shipping Delivery Provider's specific configuration
@@ -240,7 +272,7 @@ export default [
240
272
  orderDeliveryId: ID!
241
273
  address: AddressInput
242
274
  meta: JSON
243
- ): OrderDeliveryShipping!
275
+ ): OrderDeliveryShipping! @deprecated(reason: "Use updateCartDeliveryShipping instead")
244
276
 
245
277
  """
246
278
  Update a Pick Up Delivery Provider's specific configuration
@@ -249,22 +281,19 @@ export default [
249
281
  orderDeliveryId: ID!
250
282
  orderPickUpLocationId: ID!
251
283
  meta: JSON
252
- ): OrderDeliveryPickUp!
253
-
254
- """
255
- Update a Card Payment Provider's specific configuration
256
- """
257
- updateOrderPaymentCard(orderPaymentId: ID!, meta: JSON): OrderPaymentCard!
284
+ ): OrderDeliveryPickUp! @deprecated(reason: "Use updateCartDeliveryPickUp instead")
258
285
 
259
286
  """
260
287
  Update an Invoice Payment Provider's specific configuration
261
288
  """
262
289
  updateOrderPaymentInvoice(orderPaymentId: ID!, meta: JSON): OrderPaymentInvoice!
290
+ @deprecated(reason: "Use updateCartPaymentInvoice instead")
263
291
 
264
292
  """
265
293
  Update a Generic Payment Provider's specific configuration
266
294
  """
267
295
  updateOrderPaymentGeneric(orderPaymentId: ID!, meta: JSON): OrderPaymentGeneric!
296
+ @deprecated(reason: "Use updateCartPaymentGeneric instead")
268
297
 
269
298
  """
270
299
  Remove an order while it's still open
@@ -7,11 +7,6 @@ export default [
7
7
  }
8
8
 
9
9
  enum PaymentProviderType {
10
- """
11
- Card
12
- """
13
- CARD
14
-
15
10
  """
16
11
  Invoice
17
12
  """
@@ -13,14 +13,18 @@ export default [
13
13
  published: DateTime
14
14
  media(limit: Int = 10, offset: Int = 0, tags: [LowerCaseString!]): [ProductMedia!]!
15
15
  texts(forceLocale: Locale): ProductTexts
16
+ catalogPrice(quantity: Int = 1, currencyCode: String): Price
17
+ leveledCatalogPrices(currencyCode: String): [PriceLevel!]!
18
+ simulatedPrice(
19
+ currencyCode: String
20
+ useNetPrice: Boolean = false
21
+ quantity: Int = 1
22
+ configuration: [ProductConfigurationParameterInput!]
23
+ ): Price @cacheControl(scope: PRIVATE, maxAge: 10)
24
+ salesUnit: String
25
+ salesQuantityPerUnit: String
26
+ defaultOrderQuantity: Int
16
27
  bundleItems: [ProductBundleItem!]
17
- reviews(
18
- limit: Int = 10
19
- offset: Int = 0
20
- sort: [SortOptionInput!]
21
- queryString: String
22
- ): [ProductReview!]!
23
- reviewsCount(queryString: String): Int!
24
28
  assortmentPaths: [ProductAssortmentPath!]!
25
29
  proxies: [ConfigurableOrBundleProduct!]!
26
30
  siblings(
@@ -29,6 +33,13 @@ export default [
29
33
  offset: Int = 0
30
34
  includeInactive: Boolean = false
31
35
  ): [Product!]!
36
+ reviews(
37
+ limit: Int = 10
38
+ offset: Int = 0
39
+ sort: [SortOptionInput!]
40
+ queryString: String
41
+ ): [ProductReview!]!
42
+ reviewsCount(queryString: String): Int!
32
43
  }
33
44
 
34
45
  type ProductBundleItem @cacheControl(maxAge: 180) {