@unchainedshop/api 4.0.0-rc.13 → 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 (108) 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/system/schemas.d.ts +36 -6
  13. package/lib/mcp/tools/system/schemas.d.ts.map +1 -1
  14. package/lib/mcp/tools/system/schemas.js +4 -6
  15. package/lib/mcp/tools/system/schemas.js.map +1 -1
  16. package/lib/mcp/tools/system/types.d.ts +8 -2
  17. package/lib/mcp/tools/system/types.d.ts.map +1 -1
  18. package/lib/mcp/tools/users/schemas.d.ts +2 -2
  19. package/lib/resolvers/mutations/accounts/verifyWeb3Address.d.ts.map +1 -1
  20. package/lib/resolvers/mutations/accounts/verifyWeb3Address.js +78 -5
  21. package/lib/resolvers/mutations/accounts/verifyWeb3Address.js.map +1 -1
  22. package/lib/resolvers/mutations/index.d.ts +4 -1
  23. package/lib/resolvers/mutations/index.d.ts.map +1 -1
  24. package/lib/resolvers/mutations/index.js +8 -2
  25. package/lib/resolvers/mutations/index.js.map +1 -1
  26. package/lib/resolvers/mutations/orders/updateCart.js +6 -6
  27. package/lib/resolvers/mutations/orders/updateCart.js.map +1 -1
  28. package/lib/resolvers/mutations/orders/updateCartDeliveryPickUp.d.ts +8 -0
  29. package/lib/resolvers/mutations/orders/updateCartDeliveryPickUp.d.ts.map +1 -0
  30. package/lib/resolvers/mutations/orders/updateCartDeliveryPickUp.js +38 -0
  31. package/lib/resolvers/mutations/orders/updateCartDeliveryPickUp.js.map +1 -0
  32. package/lib/resolvers/mutations/orders/updateCartDeliveryShipping.d.ts +8 -0
  33. package/lib/resolvers/mutations/orders/updateCartDeliveryShipping.d.ts.map +1 -0
  34. package/lib/resolvers/mutations/orders/updateCartDeliveryShipping.js +38 -0
  35. package/lib/resolvers/mutations/orders/updateCartDeliveryShipping.js.map +1 -0
  36. package/lib/resolvers/mutations/orders/updateCartPaymentGeneric.d.ts +7 -0
  37. package/lib/resolvers/mutations/orders/updateCartPaymentGeneric.d.ts.map +1 -0
  38. package/lib/resolvers/mutations/orders/updateCartPaymentGeneric.js +37 -0
  39. package/lib/resolvers/mutations/orders/updateCartPaymentGeneric.js.map +1 -0
  40. package/lib/resolvers/mutations/orders/updateCartPaymentInvoice.d.ts +7 -0
  41. package/lib/resolvers/mutations/orders/updateCartPaymentInvoice.d.ts.map +1 -0
  42. package/lib/resolvers/mutations/orders/updateCartPaymentInvoice.js +37 -0
  43. package/lib/resolvers/mutations/orders/updateCartPaymentInvoice.js.map +1 -0
  44. package/lib/resolvers/mutations/products/updateProductCommerce.d.ts.map +1 -1
  45. package/lib/resolvers/mutations/products/updateProductCommerce.js +11 -2
  46. package/lib/resolvers/mutations/products/updateProductCommerce.js.map +1 -1
  47. package/lib/resolvers/queries/orders/orderStatistics.d.ts +3 -1
  48. package/lib/resolvers/queries/orders/orderStatistics.d.ts.map +1 -1
  49. package/lib/resolvers/queries/orders/orderStatistics.js +3 -2
  50. package/lib/resolvers/queries/orders/orderStatistics.js.map +1 -1
  51. package/lib/resolvers/type/index.d.ts +52 -0
  52. package/lib/resolvers/type/index.d.ts.map +1 -1
  53. package/lib/resolvers/type/index.js +2 -0
  54. package/lib/resolvers/type/index.js.map +1 -1
  55. package/lib/resolvers/type/order/order-payment-types.d.ts.map +1 -1
  56. package/lib/resolvers/type/order/order-payment-types.js +0 -1
  57. package/lib/resolvers/type/order/order-payment-types.js.map +1 -1
  58. package/lib/resolvers/type/order/order-statistics-types.d.ts +34 -0
  59. package/lib/resolvers/type/order/order-statistics-types.d.ts.map +1 -0
  60. package/lib/resolvers/type/order/order-statistics-types.js +68 -0
  61. package/lib/resolvers/type/order/order-statistics-types.js.map +1 -0
  62. package/lib/resolvers/type/product/product-bundle-types.d.ts +20 -0
  63. package/lib/resolvers/type/product/product-bundle-types.d.ts.map +1 -1
  64. package/lib/resolvers/type/product/product-bundle-types.js +2 -2
  65. package/lib/resolvers/type/product/product-bundle-types.js.map +1 -1
  66. package/lib/schema/mutation.d.ts.map +1 -1
  67. package/lib/schema/mutation.js +36 -7
  68. package/lib/schema/mutation.js.map +1 -1
  69. package/lib/schema/query.js +2 -2
  70. package/lib/schema/types/events.d.ts.map +1 -1
  71. package/lib/schema/types/events.js +7 -1
  72. package/lib/schema/types/events.js.map +1 -1
  73. package/lib/schema/types/order/order.d.ts.map +1 -1
  74. package/lib/schema/types/order/order.js +9 -1
  75. package/lib/schema/types/order/order.js.map +1 -1
  76. package/lib/schema/types/payment.d.ts.map +1 -1
  77. package/lib/schema/types/payment.js +0 -5
  78. package/lib/schema/types/payment.js.map +1 -1
  79. package/lib/schema/types/product/bundle-product.d.ts.map +1 -1
  80. package/lib/schema/types/product/bundle-product.js +18 -7
  81. package/lib/schema/types/product/bundle-product.js.map +1 -1
  82. package/package.json +17 -12
  83. package/src/express/createERCMetadataMiddleware.ts +11 -9
  84. package/src/fastify/bulkImportHandler.ts +1 -1
  85. package/src/fastify/ercMetadataHandler.ts +1 -1
  86. package/src/fastify/tempUploadHandler.ts +1 -1
  87. package/src/mcp/tools/system/schemas.ts +4 -6
  88. package/src/mcp/tools/system/types.ts +8 -2
  89. package/src/resolvers/mutations/accounts/verifyWeb3Address.ts +100 -7
  90. package/src/resolvers/mutations/index.ts +8 -2
  91. package/src/resolvers/mutations/orders/updateCart.ts +6 -6
  92. package/src/resolvers/mutations/orders/updateCartDeliveryPickUp.ts +51 -0
  93. package/src/resolvers/mutations/orders/updateCartDeliveryShipping.ts +51 -0
  94. package/src/resolvers/mutations/orders/updateCartPaymentGeneric.ts +50 -0
  95. package/src/resolvers/mutations/orders/updateCartPaymentInvoice.ts +50 -0
  96. package/src/resolvers/mutations/products/updateProductCommerce.ts +12 -4
  97. package/src/resolvers/queries/orders/orderStatistics.ts +3 -3
  98. package/src/resolvers/type/index.ts +2 -0
  99. package/src/resolvers/type/order/order-payment-types.ts +0 -1
  100. package/src/resolvers/type/order/order-statistics-types.ts +99 -0
  101. package/src/resolvers/type/product/product-bundle-types.ts +2 -2
  102. package/src/schema/mutation.ts +36 -7
  103. package/src/schema/query.ts +2 -2
  104. package/src/schema/types/events.ts +7 -1
  105. package/src/schema/types/order/order.ts +9 -1
  106. package/src/schema/types/payment.ts +0 -5
  107. package/src/schema/types/product/bundle-product.ts +18 -7
  108. package/src/resolvers/mutations/orders/updateOrderPaymentCard.ts +0 -37
@@ -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
 
@@ -0,0 +1,99 @@
1
+ import { Context } from '../../../context.js';
2
+
3
+ function buildDateMatch(dateField: string, dateRange?: { start?: string; end?: string }) {
4
+ if (!dateRange?.start && !dateRange?.end) return { [dateField]: { $exists: true } };
5
+
6
+ const rangeMatch: Record<string, any> = {};
7
+ if (dateRange?.start) rangeMatch.$gte = new Date(dateRange.start);
8
+ if (dateRange?.end) rangeMatch.$lte = new Date(dateRange.end);
9
+
10
+ return { [dateField]: rangeMatch };
11
+ }
12
+
13
+ async function aggregateOrders(
14
+ modules: Context['modules'],
15
+ dateField: string,
16
+ dateRange?: { start?: string; end?: string },
17
+ options?: { includeAmount?: boolean; includeCarts?: boolean },
18
+ ) {
19
+ const match = buildDateMatch(dateField, dateRange);
20
+
21
+ const pipeline: any[] = [{ $match: match }];
22
+
23
+ if (options?.includeCarts) {
24
+ match.status = null;
25
+ match.orderNumber = null;
26
+ }
27
+
28
+ if (options?.includeAmount) {
29
+ pipeline.push({
30
+ $addFields: {
31
+ orderTotal: {
32
+ $reduce: {
33
+ input: { $ifNull: ['$calculation', []] },
34
+ initialValue: 0,
35
+ in: { $add: ['$$value', { $ifNull: ['$$this.amount', 0] }] },
36
+ },
37
+ },
38
+ },
39
+ });
40
+
41
+ pipeline.push({
42
+ $group: {
43
+ _id: {
44
+ date: { $dateToString: { format: '%Y-%m-%d', date: `$${dateField}` } },
45
+ currency: '$currencyCode',
46
+ },
47
+ totalAmount: { $sum: '$orderTotal' },
48
+ count: { $sum: 1 },
49
+ },
50
+ });
51
+
52
+ pipeline.push({
53
+ $project: {
54
+ _id: 0,
55
+ date: '$_id.date',
56
+ total: { amount: '$totalAmount', currencyCode: '$_id.currency' },
57
+ count: 1,
58
+ },
59
+ });
60
+
61
+ pipeline.push({ $sort: { date: 1 } });
62
+ return modules.orders.aggregateOrders({ pipeline });
63
+ }
64
+ // Just count total orders
65
+ pipeline.push({ $count: 'count' });
66
+ const result = await modules.orders.aggregateOrders({ pipeline });
67
+ return result[0]?.count ?? 0;
68
+ }
69
+ export const OrderStatistics = {
70
+ newCount: async ({ dateRange }, _p, { modules }: Context) =>
71
+ aggregateOrders(modules, 'created', dateRange, { includeCarts: true }),
72
+
73
+ checkoutCount: async ({ dateRange }, _p, { modules }: Context) =>
74
+ aggregateOrders(modules, 'ordered', dateRange),
75
+
76
+ rejectCount: async ({ dateRange }, _p, { modules }: Context) =>
77
+ aggregateOrders(modules, 'rejected', dateRange),
78
+
79
+ confirmCount: async ({ dateRange }, _p, { modules }: Context) =>
80
+ aggregateOrders(modules, 'confirmed', dateRange),
81
+
82
+ fulfillCount: async ({ dateRange }, _p, { modules }: Context) =>
83
+ aggregateOrders(modules, 'fullfilled', dateRange),
84
+
85
+ newRecords: async ({ dateRange }, _p, { modules }: Context) =>
86
+ aggregateOrders(modules, 'created', dateRange, { includeAmount: true, includeCarts: true }),
87
+
88
+ checkoutRecords: async ({ dateRange }, _p, { modules }: Context) =>
89
+ aggregateOrders(modules, 'ordered', dateRange, { includeAmount: true }),
90
+
91
+ rejectRecords: async ({ dateRange }, _p, { modules }: Context) =>
92
+ aggregateOrders(modules, 'rejected', dateRange, { includeAmount: true }),
93
+
94
+ confirmRecords: async ({ dateRange }, _p, { modules }: Context) =>
95
+ aggregateOrders(modules, 'confirmed', dateRange, { includeAmount: true }),
96
+
97
+ fulfilledRecords: async ({ dateRange }, _p, { modules }: Context) =>
98
+ aggregateOrders(modules, 'fullfilled', dateRange, { includeAmount: true }),
99
+ };
@@ -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
@@ -480,14 +480,14 @@ export default [
480
480
  limit: Int = 10
481
481
  offset: Int = 0
482
482
  queryString: String
483
- created: DateTime
483
+ created: DateFilterInput
484
484
  sort: [SortOptionInput!]
485
485
  ): [Event!]!
486
486
 
487
487
  """
488
488
  Get total count of all emitted events
489
489
  """
490
- eventsCount(types: [String!], queryString: String, created: DateTime): Int!
490
+ eventsCount(types: [String!], queryString: String, created: DateFilterInput): Int!
491
491
 
492
492
  """
493
493
  Determines if a token is valid/active for reset password
@@ -11,9 +11,15 @@ export default [
11
11
  created: Timestamp!
12
12
  }
13
13
 
14
+ type EventStatisticReport {
15
+ date: Date!
16
+ count: Int!
17
+ }
18
+
14
19
  type EventStatistics {
15
- type: EventType!
20
+ detail: [EventStatisticReport!]!
16
21
  emitCount: Int!
22
+ type: String
17
23
  }
18
24
  `,
19
25
  ];
@@ -81,13 +81,21 @@ export default [
81
81
  updated: DateTime
82
82
  user: User
83
83
  }
84
-
84
+ type OrderStatisticsRecord {
85
+ date: String!
86
+ total: Price!
87
+ }
85
88
  type OrderStatistics {
86
89
  newCount: Int!
87
90
  checkoutCount: Int!
88
91
  rejectCount: Int!
89
92
  confirmCount: Int!
90
93
  fulfillCount: Int!
94
+ confirmRecords: [OrderStatisticsRecord!]!
95
+ checkoutRecords: [OrderStatisticsRecord!]!
96
+ rejectRecords: [OrderStatisticsRecord!]!
97
+ newRecords: [OrderStatisticsRecord!]!
98
+ fulfilledRecords: [OrderStatisticsRecord!]!
91
99
  }
92
100
  `,
93
101
  ];
@@ -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) {
@@ -1,37 +0,0 @@
1
- import { log } from '@unchainedshop/logger';
2
- import { Context } from '../../../context.js';
3
- import { PaymentProviderType } from '@unchainedshop/core-payment';
4
- import { OrderPaymentNotFoundError, InvalidIdError, OrderPaymentTypeError } from '../../../errors.js';
5
-
6
- export default async function updateOrderPaymentCard(
7
- root: never,
8
- { orderPaymentId, meta }: { orderPaymentId: string; meta?: any },
9
- context: Context,
10
- ) {
11
- const { modules, services, userId } = context;
12
-
13
- log(`mutation updateOrderPaymentCard ${orderPaymentId} ${JSON.stringify(meta)}`, { userId });
14
-
15
- if (!orderPaymentId) throw new InvalidIdError({ orderPaymentId });
16
-
17
- const orderPayment = await modules.orders.payments.findOrderPayment({
18
- orderPaymentId,
19
- });
20
- if (!orderPayment) throw new OrderPaymentNotFoundError({ data: { orderPaymentId } });
21
-
22
- const provider = await modules.payment.paymentProviders.findProvider({
23
- paymentProviderId: orderPayment.paymentProviderId,
24
- });
25
- const providerType = provider?.type;
26
-
27
- if (providerType !== PaymentProviderType.CARD)
28
- throw new OrderPaymentTypeError({
29
- orderPaymentId,
30
- received: providerType,
31
- required: PaymentProviderType.CARD,
32
- });
33
-
34
- await modules.orders.payments.updateContext(orderPayment._id, { meta });
35
- await services.orders.updateCalculation(orderPayment.orderId);
36
- return modules.orders.payments.findOrderPayment({ orderPaymentId });
37
- }