@unchainedshop/api 2.8.18 → 2.9.1

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 (82) hide show
  1. package/jest.config.js +2 -2
  2. package/lib/errors.d.ts +1 -0
  3. package/lib/errors.js +1 -0
  4. package/lib/errors.js.map +1 -1
  5. package/lib/resolvers/mutations/index.d.ts +1 -0
  6. package/lib/resolvers/mutations/index.js +2 -0
  7. package/lib/resolvers/mutations/index.js.map +1 -1
  8. package/lib/resolvers/mutations/warehousing/invalidateToken.d.ts +4 -0
  9. package/lib/resolvers/mutations/warehousing/invalidateToken.js +26 -0
  10. package/lib/resolvers/mutations/warehousing/invalidateToken.js.map +1 -0
  11. package/lib/resolvers/queries/index.d.ts +1 -0
  12. package/lib/resolvers/queries/index.js +2 -0
  13. package/lib/resolvers/queries/index.js.map +1 -1
  14. package/lib/resolvers/queries/warehousing/tokens.d.ts +5 -0
  15. package/lib/resolvers/queries/warehousing/tokens.js +6 -0
  16. package/lib/resolvers/queries/warehousing/tokens.js.map +1 -0
  17. package/lib/resolvers/type/index.d.ts +367 -9
  18. package/lib/resolvers/type/order/order-item-types.d.ts +15 -17
  19. package/lib/resolvers/type/order/order-item-types.js +28 -23
  20. package/lib/resolvers/type/order/order-item-types.js.map +1 -1
  21. package/lib/resolvers/type/order/order-types.d.ts +15 -19
  22. package/lib/resolvers/type/order/order-types.js +48 -28
  23. package/lib/resolvers/type/order/order-types.js.map +1 -1
  24. package/lib/resolvers/type/product/product-bundle-types.d.ts +34 -2
  25. package/lib/resolvers/type/product/product-bundle-types.js.map +1 -1
  26. package/lib/resolvers/type/product/product-configurable-types.d.ts +62 -2
  27. package/lib/resolvers/type/product/product-configurable-types.js +10 -10
  28. package/lib/resolvers/type/product/product-configurable-types.js.map +1 -1
  29. package/lib/resolvers/type/product/product-plan-types.d.ts +53 -2
  30. package/lib/resolvers/type/product/product-plan-types.js +9 -9
  31. package/lib/resolvers/type/product/product-plan-types.js.map +1 -1
  32. package/lib/resolvers/type/product/product-simple-types.d.ts +85 -2
  33. package/lib/resolvers/type/product/product-simple-types.js +7 -7
  34. package/lib/resolvers/type/product/product-simple-types.js.map +1 -1
  35. package/lib/resolvers/type/product/product-tokenized-types.d.ts +67 -2
  36. package/lib/resolvers/type/product/product-tokenized-types.js +19 -10
  37. package/lib/resolvers/type/product/product-tokenized-types.js.map +1 -1
  38. package/lib/resolvers/type/product/product-types.d.ts +38 -2
  39. package/lib/resolvers/type/product/product-types.js +15 -15
  40. package/lib/resolvers/type/product/product-types.js.map +1 -1
  41. package/lib/resolvers/type/token-types.d.ts +9 -12
  42. package/lib/resolvers/type/token-types.js +22 -3
  43. package/lib/resolvers/type/token-types.js.map +1 -1
  44. package/lib/roles/all.js +38 -17
  45. package/lib/roles/all.js.map +1 -1
  46. package/lib/roles/index.js +1 -0
  47. package/lib/roles/index.js.map +1 -1
  48. package/lib/roles/loggedIn.js +9 -14
  49. package/lib/roles/loggedIn.js.map +1 -1
  50. package/lib/schema/mutation.js +5 -1
  51. package/lib/schema/mutation.js.map +1 -1
  52. package/lib/schema/query.js +5 -0
  53. package/lib/schema/query.js.map +1 -1
  54. package/lib/schema/types/order/item.js +1 -0
  55. package/lib/schema/types/order/item.js.map +1 -1
  56. package/lib/schema/types/product/tokenized-product.js +2 -0
  57. package/lib/schema/types/product/tokenized-product.js.map +1 -1
  58. package/lib/schema/types/warehousing.js +9 -2
  59. package/lib/schema/types/warehousing.js.map +1 -1
  60. package/package.json +8 -8
  61. package/src/errors.ts +2 -0
  62. package/src/resolvers/mutations/index.ts +2 -0
  63. package/src/resolvers/mutations/warehousing/invalidateToken.ts +42 -0
  64. package/src/resolvers/queries/index.ts +2 -1
  65. package/src/resolvers/queries/warehousing/tokens.ts +18 -0
  66. package/src/resolvers/type/order/order-item-types.ts +59 -49
  67. package/src/resolvers/type/order/order-types.ts +58 -54
  68. package/src/resolvers/type/product/product-bundle-types.ts +3 -3
  69. package/src/resolvers/type/product/product-configurable-types.ts +79 -19
  70. package/src/resolvers/type/product/product-plan-types.ts +34 -15
  71. package/src/resolvers/type/product/product-simple-types.ts +41 -10
  72. package/src/resolvers/type/product/product-tokenized-types.ts +43 -13
  73. package/src/resolvers/type/product/product-types.ts +77 -18
  74. package/src/resolvers/type/token-types.ts +35 -20
  75. package/src/roles/all.ts +46 -17
  76. package/src/roles/index.ts +1 -0
  77. package/src/roles/loggedIn.ts +10 -24
  78. package/src/schema/mutation.ts +5 -1
  79. package/src/schema/query.ts +5 -0
  80. package/src/schema/types/order/item.ts +1 -0
  81. package/src/schema/types/product/tokenized-product.ts +2 -0
  82. package/src/schema/types/warehousing.ts +9 -2
@@ -205,6 +205,11 @@ export default [
205
205
  """
206
206
  token(tokenId: ID!): Token
207
207
 
208
+ """
209
+ Get all tokens
210
+ """
211
+ tokens(limit: Int = 10, offset: Int = 0): [Token!]!
212
+
208
213
  """
209
214
  Returns total number of payment providers, optionally filtered by type
210
215
  """
@@ -1 +1 @@
1
- {"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/schema/query.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAudb;CACF,CAAC"}
1
+ {"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/schema/query.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4db;CACF,CAAC"}
@@ -29,6 +29,7 @@ export default [
29
29
  discounts: [OrderItemDiscount!]
30
30
  dispatches: [Dispatch!]
31
31
  configuration: [ProductConfigurationParameter!]
32
+ tokens: [Token!]!
32
33
  }
33
34
  `,
34
35
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"item.js","sourceRoot":"","sources":["../../../../src/schema/types/order/item.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+Bb;CACF,CAAC"}
1
+ {"version":3,"file":"item.js","sourceRoot":"","sources":["../../../../src/schema/types/order/item.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCb;CACF,CAAC"}
@@ -54,6 +54,8 @@ export default [
54
54
  contractAddress: String
55
55
  contractStandard: SmartContractStandard
56
56
  contractConfiguration: ContractConfiguration
57
+ tokens: [Token!]!
58
+ tokensCount: Int!
57
59
  }
58
60
  `,
59
61
  ];
@@ -1 +1 @@
1
- {"version":3,"file":"tokenized-product.js","sourceRoot":"","sources":["../../../../src/schema/types/product/tokenized-product.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwDb;CACF,CAAC"}
1
+ {"version":3,"file":"tokenized-product.js","sourceRoot":"","sources":["../../../../src/schema/types/product/tokenized-product.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0Db;CACF,CAAC"}
@@ -44,12 +44,19 @@ export default [
44
44
 
45
45
  type Token @cacheControl(maxAge: 0, scope: PRIVATE) {
46
46
  _id: ID!
47
- user: User
48
- walletAddress: String
49
47
  product: TokenizedProduct!
50
48
  status: TokenExportStatus!
51
49
  quantity: Int!
50
+ isInvalidateable: Boolean!
51
+ """
52
+ Get an access key that you can pass along the HTTP Header "x-token-accesskey" to access the token anonymously.
53
+ """
54
+ accessKey: String!
55
+ invalidatedDate: DateTime
56
+ user: User
57
+ expiryDate: DateTime
52
58
  contractAddress: String
59
+ walletAddress: String
53
60
  chainId: String
54
61
  chainTokenId: String
55
62
  ercMetadata(forceLocale: String): JSON
@@ -1 +1 @@
1
- {"version":3,"file":"warehousing.js","sourceRoot":"","sources":["../../../src/schema/types/warehousing.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuDb;CACF,CAAC"}
1
+ {"version":3,"file":"warehousing.js","sourceRoot":"","sources":["../../../src/schema/types/warehousing.ts"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8Db;CACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/api",
3
- "version": "2.8.18",
3
+ "version": "2.9.1",
4
4
  "main": "lib/api-index.js",
5
5
  "exports": {
6
6
  ".": "./lib/api-index.js",
@@ -48,11 +48,11 @@
48
48
  },
49
49
  "dependencies": {
50
50
  "@metamask/eth-sig-util": "^7.0.2",
51
- "@unchainedshop/core": "^2.8.18",
52
- "@unchainedshop/events": "^2.8.18",
53
- "@unchainedshop/logger": "^2.8.18",
54
- "@unchainedshop/roles": "^2.8.18",
55
- "@unchainedshop/utils": "^2.8.18",
51
+ "@unchainedshop/core": "^2.9.1",
52
+ "@unchainedshop/events": "^2.9.1",
53
+ "@unchainedshop/logger": "^2.9.1",
54
+ "@unchainedshop/roles": "^2.9.1",
55
+ "@unchainedshop/utils": "^2.9.1",
56
56
  "accounting": "0.4.1",
57
57
  "dataloader": "^2.2.2",
58
58
  "graphql-scalars": "^1.23.0",
@@ -65,10 +65,10 @@
65
65
  "@types/graphql-upload": "^16.0.7",
66
66
  "@types/locale": "^0.1.4",
67
67
  "@types/node": "^20.12.12",
68
- "@unchainedshop/types": "^2.8.18",
68
+ "@unchainedshop/types": "^2.9.1",
69
69
  "express": "^4.19.2",
70
70
  "jest": "^29.7.0",
71
- "ts-jest": "^29.1.2",
71
+ "ts-jest": "^29.1.3",
72
72
  "typescript": "^5.4.5"
73
73
  }
74
74
  }
package/src/errors.ts CHANGED
@@ -208,6 +208,8 @@ export const TokenWrongStatusError = createError(
208
208
  'The current status of the token does not allow this operation',
209
209
  );
210
210
 
211
+ export const TokenNotFoundError = createError('TokenNotFoundError', 'Token not found');
212
+
211
213
  export const CyclicAssortmentLinkNotSupportedError = createError(
212
214
  'CyclicAssortmentLinkNotSupported',
213
215
  'Cyclic assortment link detected, make sure child assortment is not assigned as a parent on the assortment graph',
@@ -91,6 +91,7 @@ import createWarehousingProvider from './warehousing/createWarehousingProvider.j
91
91
  import updateWarehousingProvider from './warehousing/updateWarehousingProvider.js';
92
92
  import removeWarehousingProvider from './warehousing/removeWarehousingProvider.js';
93
93
  import exportToken from './warehousing/exportToken.js';
94
+ import invalidateToken from './warehousing/invalidateToken.js';
94
95
  import setPassword from './accounts/setPassword.js';
95
96
  import setRoles from './users/setRoles.js';
96
97
  import setUsername from './accounts/setUsername.js';
@@ -286,6 +287,7 @@ export default {
286
287
  updateWarehousingProvider: acl(actions.manageWarehousingProviders)(updateWarehousingProvider),
287
288
  removeWarehousingProvider: acl(actions.manageWarehousingProviders)(removeWarehousingProvider),
288
289
  exportToken: acl(actions.updateToken)(exportToken),
290
+ invalidateToken: acl(actions.updateToken)(invalidateToken),
289
291
  createFilter: acl(actions.manageFilters)(createFilter),
290
292
  updateFilter: acl(actions.manageFilters)(updateFilter),
291
293
  removeFilter: acl(actions.manageFilters)(removeFilter),
@@ -0,0 +1,42 @@
1
+ import { Context, Root } from '@unchainedshop/types/api.js';
2
+ import { log } from '@unchainedshop/logger';
3
+ import {
4
+ InvalidIdError,
5
+ TokenNotFoundError,
6
+ ProductNotFoundError,
7
+ TokenWrongStatusError,
8
+ } from '../../../errors.js';
9
+
10
+ export default async function invalidateToken(
11
+ root: Root,
12
+ { tokenId }: { tokenId: string },
13
+ context: Context,
14
+ ) {
15
+ const { modules, userId } = context;
16
+ log(`mutation invalidateToken ${tokenId}`, {
17
+ userId,
18
+ });
19
+
20
+ if (!tokenId) throw new InvalidIdError({ tokenId });
21
+
22
+ const token = await modules.warehousing.findToken({ tokenId });
23
+ if (!token) throw new TokenNotFoundError({ tokenId });
24
+
25
+ const product = await modules.products.findProduct({ productId: token.productId });
26
+ if (!product) throw new ProductNotFoundError({ productId: token.productId });
27
+
28
+ const isInvalidateable = await modules.warehousing.isInvalidateable(
29
+ token.chainTokenId,
30
+ {
31
+ token,
32
+ product,
33
+ referenceDate: new Date(),
34
+ },
35
+ context,
36
+ );
37
+
38
+ if (!isInvalidateable) throw new TokenWrongStatusError({ tokenId });
39
+
40
+ await modules.warehousing.invalidateToken(tokenId);
41
+ return modules.warehousing.findToken({ tokenId });
42
+ }
@@ -62,6 +62,7 @@ import warehousingProvider from './warehousing/warehousingProvider.js';
62
62
  import warehousingProviders from './warehousing/warehousingProviders.js';
63
63
  import warehousingProvidersCount from './warehousing/warehousingProvidersCount.js';
64
64
  import token from './warehousing/token.js';
65
+ import tokens from './warehousing/tokens.js';
65
66
  import work from './worker/work.js';
66
67
  import workQueue from './worker/workQueue.js';
67
68
  import workQueueCount from './worker/workQueueCount.js';
@@ -101,6 +102,7 @@ export default {
101
102
  warehousingProvider: acl(actions.viewWarehousingProvider)(warehousingProvider),
102
103
  warehousingInterfaces: acl(actions.viewWarehousingInterfaces)(warehousingInterfaces),
103
104
  token: acl(actions.viewToken)(token),
105
+ tokens: acl(actions.viewTokens)(tokens),
104
106
  translatedProductTexts: acl(actions.viewTranslations)(translatedProductTexts),
105
107
  translatedProductMediaTexts: acl(actions.viewTranslations)(translatedProductMediaTexts),
106
108
  translatedProductVariationTexts: acl(actions.viewTranslations)(translatedProductVariationTexts),
@@ -131,7 +133,6 @@ export default {
131
133
  enrollment: acl(actions.viewEnrollment)(enrollment),
132
134
  enrollments: acl(actions.viewEnrollments)(enrollments),
133
135
  enrollmentsCount: acl(actions.viewEnrollments)(enrollmentsCount),
134
-
135
136
  work: acl(actions.manageWorker)(work),
136
137
  event: acl(actions.viewEvent)(event),
137
138
  events: acl(actions.viewEvents)(events),
@@ -0,0 +1,18 @@
1
+ import { log } from '@unchainedshop/logger';
2
+ import { Context, Root } from '@unchainedshop/types/api.js';
3
+
4
+ export default async function tokens(
5
+ root: Root,
6
+ {
7
+ limit = 10,
8
+ offset = 0,
9
+ }: {
10
+ limit: number;
11
+ offset: number;
12
+ },
13
+ { modules, userId }: Context,
14
+ ) {
15
+ log(`query tokens`, { userId });
16
+
17
+ return modules.warehousing.findTokens({}, { limit, skip: offset });
18
+ }
@@ -6,31 +6,7 @@ import { OrderPosition, OrderPositionDiscount } from '@unchainedshop/types/order
6
6
  import { OrderPrice } from '@unchainedshop/types/orders.pricing.js';
7
7
  import { Product } from '@unchainedshop/types/products.js';
8
8
  import { Quotation } from '@unchainedshop/types/quotations.js';
9
- import { WarehousingProvider } from '@unchainedshop/types/warehousing.js';
10
-
11
- type HelperType<P, T> = (orderPosition: OrderPosition, params: P, context: Context) => T;
12
-
13
- export interface OrderItemHelperTypes {
14
- discounts: HelperType<never, Promise<Array<OrderPositionDiscount>>>;
15
- dispatches: HelperType<
16
- never,
17
- Promise<
18
- Array<{
19
- _id: string;
20
- deliveryProvider: DeliveryProvider;
21
- warehousingProvider: WarehousingProvider;
22
- shipping: Date;
23
- earliestDelivery: Date;
24
- }>
25
- >
26
- >;
27
- order: HelperType<never, Promise<Order>>;
28
- originalProduct: HelperType<never, Promise<Product>>;
29
- product: HelperType<never, Promise<Product>>;
30
- quotation: HelperType<never, Promise<Quotation>>;
31
- total: HelperType<{ category: string; useNetPrice: boolean }, Promise<OrderPrice>>;
32
- unitPrice: HelperType<{ useNetPrice: boolean }, Promise<OrderPrice>>;
33
- }
9
+ import { TokenSurrogate, WarehousingProvider } from '@unchainedshop/types/warehousing.js';
34
10
 
35
11
  const getPricingSheet = async (orderPosition: OrderPosition, context: Context) => {
36
12
  const { modules } = context;
@@ -43,23 +19,39 @@ const getPricingSheet = async (orderPosition: OrderPosition, context: Context) =
43
19
  return pricingSheet;
44
20
  };
45
21
 
46
- export const OrderItem: OrderItemHelperTypes = {
47
- discounts: async (obj, _, context) => {
48
- const pricingSheet = await getPricingSheet(obj, context);
22
+ export const OrderItem = {
23
+ async discounts(
24
+ orderPosition: OrderPosition,
25
+ _,
26
+ context: Context,
27
+ ): Promise<Array<OrderPositionDiscount>> {
28
+ const pricingSheet = await getPricingSheet(orderPosition, context);
49
29
 
50
30
  if (pricingSheet.isValid()) {
51
31
  // IMPORTANT: Do not send any parameter to obj.discounts!
52
32
  return pricingSheet.discountPrices().map((discount) => ({
53
- item: obj,
33
+ item: orderPosition,
54
34
  ...discount,
55
35
  }));
56
36
  }
57
37
  return [];
58
38
  },
59
39
 
60
- dispatches: async (obj, _, { modules, loaders }) => {
61
- const scheduling = obj.scheduling || [];
62
- const order = await modules.orders.findOrder({ orderId: obj.orderId });
40
+ async dispatches(
41
+ orderPosition: OrderPosition,
42
+ _,
43
+ { modules, loaders }: Context,
44
+ ): Promise<
45
+ Array<{
46
+ _id: string;
47
+ deliveryProvider: DeliveryProvider;
48
+ warehousingProvider: WarehousingProvider;
49
+ shipping: Date;
50
+ earliestDelivery: Date;
51
+ }>
52
+ > {
53
+ const scheduling = orderPosition.scheduling || [];
54
+ const order = await modules.orders.findOrder({ orderId: orderPosition.orderId });
63
55
  const { countryCode, userId } = order;
64
56
 
65
57
  const orderDelivery = await modules.orders.deliveries.findDelivery({
@@ -69,7 +61,7 @@ export const OrderItem: OrderItemHelperTypes = {
69
61
  deliveryProviderId: orderDelivery.deliveryProviderId,
70
62
  });
71
63
  const product = await loaders.productLoader.load({
72
- productId: obj.productId,
64
+ productId: orderPosition.productId,
73
65
  });
74
66
 
75
67
  return Promise.all(
@@ -82,7 +74,7 @@ export const OrderItem: OrderItemHelperTypes = {
82
74
  warehousingProvider,
83
75
  deliveryProvider,
84
76
  product,
85
- quantity: obj.quantity,
77
+ quantity: orderPosition.quantity,
86
78
  country: countryCode,
87
79
  userId,
88
80
  // referenceDate,
@@ -95,38 +87,42 @@ export const OrderItem: OrderItemHelperTypes = {
95
87
  );
96
88
  },
97
89
 
98
- order: async (obj, _, { modules }) => {
99
- return modules.orders.findOrder({ orderId: obj.orderId });
90
+ async order(orderPosition: OrderPosition, _, { modules }: Context): Promise<Order> {
91
+ return modules.orders.findOrder({ orderId: orderPosition.orderId });
100
92
  },
101
93
 
102
- originalProduct: async (obj, _, { loaders }) => {
94
+ async originalProduct(orderPosition: OrderPosition, _, { loaders }: Context): Promise<Product> {
103
95
  const product = await loaders.productLoader.load({
104
- productId: obj.originalProductId,
96
+ productId: orderPosition.originalProductId,
105
97
  });
106
98
  return product;
107
99
  },
108
100
 
109
- product: async (obj, _, { loaders }) => {
101
+ async product(orderPosition: OrderPosition, _, { loaders }: Context): Promise<Product> {
110
102
  const product = await loaders.productLoader.load({
111
- productId: obj.productId,
103
+ productId: orderPosition.productId,
112
104
  });
113
105
  return product;
114
106
  },
115
107
 
116
- quotation: async (obj, _, { modules }) => {
117
- if (!obj.quotationId) return null;
118
- return modules.quotations.findQuotation({ quotationId: obj.quotationId });
108
+ async quotation(orderPosition: OrderPosition, _, { modules }: Context): Promise<Quotation> {
109
+ if (!orderPosition.quotationId) return null;
110
+ return modules.quotations.findQuotation({ quotationId: orderPosition.quotationId });
119
111
  },
120
112
 
121
- total: async (obj, params, context) => {
122
- const pricingSheet = await getPricingSheet(obj, context);
113
+ async total(
114
+ orderPosition: OrderPosition,
115
+ params: { category: string; useNetPrice: boolean },
116
+ context: Context,
117
+ ): Promise<OrderPrice> {
118
+ const pricingSheet = await getPricingSheet(orderPosition, context);
123
119
 
124
120
  if (pricingSheet.isValid()) {
125
121
  const price = pricingSheet.total(params);
126
122
  return {
127
123
  _id: crypto
128
124
  .createHash('sha256')
129
- .update([obj._id, JSON.stringify(params), JSON.stringify(price)].join(''))
125
+ .update([orderPosition._id, JSON.stringify(params), JSON.stringify(price)].join(''))
130
126
  .digest('hex'),
131
127
  ...price,
132
128
  };
@@ -134,19 +130,33 @@ export const OrderItem: OrderItemHelperTypes = {
134
130
  return null;
135
131
  },
136
132
 
137
- unitPrice: async (obj, params, context) => {
138
- const pricingSheet = await getPricingSheet(obj, context);
133
+ async unitPrice(
134
+ orderPosition: OrderPosition,
135
+ params: { useNetPrice: boolean },
136
+ context: Context,
137
+ ): Promise<OrderPrice> {
138
+ const pricingSheet = await getPricingSheet(orderPosition, context);
139
139
 
140
140
  if (pricingSheet.isValid()) {
141
141
  const price = pricingSheet.unitPrice(params);
142
142
  return {
143
143
  _id: crypto
144
144
  .createHash('sha256')
145
- .update([`${obj._id}-unit`, price.amount, pricingSheet.currency].join(''))
145
+ .update([`${orderPosition._id}-unit`, price.amount, pricingSheet.currency].join(''))
146
146
  .digest('hex'),
147
147
  ...price,
148
148
  };
149
149
  }
150
150
  return null;
151
151
  },
152
+
153
+ async tokens(
154
+ orderPosition: OrderPosition,
155
+ params: never,
156
+ { modules }: Context,
157
+ ): Promise<Array<TokenSurrogate>> {
158
+ return modules.warehousing.findTokens({
159
+ orderPositionId: orderPosition._id,
160
+ });
161
+ },
152
162
  };
@@ -10,85 +10,87 @@ import { OrderDiscount } from '@unchainedshop/types/orders.discounts.js';
10
10
  import { OrderPayment } from '@unchainedshop/types/orders.payments.js';
11
11
  import { OrderPosition } from '@unchainedshop/types/orders.positions.js';
12
12
  import { OrderPrice } from '@unchainedshop/types/orders.pricing.js';
13
- import { PaymentProvider } from '@unchainedshop/types/payments.js';
14
13
  import { User } from '@unchainedshop/types/user.js';
15
14
 
16
- type HelperType<P, T> = (order: OrderType, params: P, context: Context) => T;
17
-
18
- export interface OrderHelperTypes {
19
- supportedDeliveryProviders: HelperType<never, Promise<Array<DeliveryProvider>>>;
20
- supportedPaymentProviders: HelperType<never, Promise<Array<PaymentProvider>>>;
21
- currency: HelperType<never, Promise<Currency>>;
22
- country: HelperType<never, Promise<Country>>;
23
- discounts: HelperType<never, Promise<Array<OrderDiscount>>>;
24
- delivery: HelperType<never, Promise<OrderDelivery>>;
25
- enrollment: HelperType<never, Promise<Enrollment>>;
26
- payment: HelperType<never, Promise<OrderPayment>>;
27
- items: HelperType<never, Promise<Array<OrderPosition>>>;
28
- status: HelperType<never, string>;
29
- total: HelperType<{ category: string; useNetPrice: boolean }, Promise<OrderPrice>>;
30
- user: HelperType<never, Promise<User>>;
31
- }
32
-
33
- export const Order: OrderHelperTypes = {
34
- supportedDeliveryProviders: async (obj, _, context) =>
35
- context.modules.delivery.findSupported(
15
+ export const Order = {
16
+ async supportedDeliveryProviders(
17
+ order: OrderType,
18
+ _,
19
+ context: Context,
20
+ ): Promise<Array<DeliveryProvider>> {
21
+ return context.modules.delivery.findSupported(
36
22
  {
37
- order: obj,
23
+ order,
38
24
  },
39
25
  context,
40
- ),
26
+ );
27
+ },
41
28
 
42
- supportedPaymentProviders: async (obj, _, context) =>
43
- context.modules.payment.paymentProviders.findSupported(
29
+ async supportedPaymentProviders(order: OrderType, _, context: Context) {
30
+ return context.modules.payment.paymentProviders.findSupported(
44
31
  {
45
- order: obj,
32
+ order,
46
33
  },
47
34
  context,
48
- ),
35
+ );
36
+ },
49
37
 
50
- currency: async (obj, _, { modules }) => modules.currencies.findCurrency({ isoCode: obj.currency }),
51
- country: async (obj, _, { modules }) => modules.countries.findCountry({ isoCode: obj.countryCode }),
38
+ async currency(order: OrderType, _, { modules }: Context): Promise<Currency> {
39
+ return modules.currencies.findCurrency({ isoCode: order.currency });
40
+ },
52
41
 
53
- discounts: async (obj, _, { modules }) =>
54
- modules.orders.discounts.findOrderDiscounts({ orderId: obj._id }),
42
+ async country(order: OrderType, _, { modules }: Context): Promise<Country> {
43
+ return modules.countries.findCountry({ isoCode: order.countryCode });
44
+ },
55
45
 
56
- delivery: async (obj, _, { modules }) =>
57
- modules.orders.deliveries.findDelivery({
58
- orderDeliveryId: obj.deliveryId,
59
- }),
46
+ async discounts(order: OrderType, _, { modules }: Context): Promise<Array<OrderDiscount>> {
47
+ return modules.orders.discounts.findOrderDiscounts({ orderId: order._id });
48
+ },
60
49
 
61
- enrollment: async (obj, _, { modules }) =>
62
- modules.enrollments.findEnrollment({
63
- orderId: obj._id,
64
- }),
50
+ async delivery(order: OrderType, _, { modules }: Context): Promise<OrderDelivery> {
51
+ return modules.orders.deliveries.findDelivery({
52
+ orderDeliveryId: order.deliveryId,
53
+ });
54
+ },
55
+
56
+ async enrollment(order: OrderType, _, { modules }: Context): Promise<Enrollment> {
57
+ return modules.enrollments.findEnrollment({
58
+ orderId: order._id,
59
+ });
60
+ },
65
61
 
66
- items: async (obj, _, { modules }) =>
67
- modules.orders.positions.findOrderPositions({
68
- orderId: obj._id,
69
- }),
62
+ async items(order: OrderType, _, { modules }: Context): Promise<Array<OrderPosition>> {
63
+ return modules.orders.positions.findOrderPositions({
64
+ orderId: order._id,
65
+ });
66
+ },
70
67
 
71
- payment: async (obj, _, { modules }) =>
72
- modules.orders.payments.findOrderPayment({
73
- orderPaymentId: obj.paymentId,
74
- }),
68
+ async payment(order: OrderType, _, { modules }: Context): Promise<OrderPayment> {
69
+ return modules.orders.payments.findOrderPayment({
70
+ orderPaymentId: order.paymentId,
71
+ });
72
+ },
75
73
 
76
- status: (obj) => {
77
- if (obj.status === null) {
74
+ status(order: OrderType): string {
75
+ if (order.status === null) {
78
76
  return 'OPEN';
79
77
  }
80
- return obj.status;
78
+ return order.status;
81
79
  },
82
80
 
83
- total: async (obj, params, { modules }) => {
84
- const pricingSheet = modules.orders.pricingSheet(obj);
81
+ async total(
82
+ order: OrderType,
83
+ params: { category: string; useNetPrice: boolean },
84
+ { modules }: Context,
85
+ ): Promise<OrderPrice> {
86
+ const pricingSheet = modules.orders.pricingSheet(order);
85
87
 
86
88
  if (pricingSheet.isValid()) {
87
89
  const price = pricingSheet.total(params);
88
90
  return {
89
91
  _id: crypto
90
92
  .createHash('sha256')
91
- .update([obj._id, JSON.stringify(params), JSON.stringify(price)].join(''))
93
+ .update([order._id, JSON.stringify(params), JSON.stringify(price)].join(''))
92
94
  .digest('hex'),
93
95
  ...price,
94
96
  };
@@ -96,5 +98,7 @@ export const Order: OrderHelperTypes = {
96
98
  return null;
97
99
  },
98
100
 
99
- user: async (obj, _, { modules }) => modules.users.findUserById(obj.userId),
101
+ async user(order: OrderType, _, { modules }: Context): Promise<User> {
102
+ return modules.users.findUserById(order.userId);
103
+ },
100
104
  };
@@ -1,10 +1,10 @@
1
- import { BundleProductHelperTypes } from '@unchainedshop/types/products.js';
1
+ import { ProductBundleItem } from '@unchainedshop/types/products.js';
2
2
  import { Product } from './product-types.js';
3
3
 
4
- export const BundleProduct: BundleProductHelperTypes = {
4
+ export const BundleProduct = {
5
5
  ...Product,
6
6
 
7
- bundleItems(product) {
7
+ bundleItems(product): Array<ProductBundleItem> {
8
8
  return product.bundleItems ? product.bundleItems : [];
9
9
  },
10
10
  };