@unchainedshop/api 1.2.40 → 2.0.0-beta2

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 (238) hide show
  1. package/lib/api-index.d.ts +1 -0
  2. package/lib/api-index.js +3 -0
  3. package/lib/api-index.js.map +1 -1
  4. package/lib/context.js +3 -3
  5. package/lib/context.js.map +1 -1
  6. package/lib/createBulkImportServer.js +1 -1
  7. package/lib/createBulkImportServer.js.map +1 -1
  8. package/lib/createERCMetadataServer.d.ts +2 -0
  9. package/lib/createERCMetadataServer.js +53 -0
  10. package/lib/createERCMetadataServer.js.map +1 -0
  11. package/lib/errors.d.ts +4 -0
  12. package/lib/errors.js +4 -0
  13. package/lib/errors.js.map +1 -1
  14. package/lib/loaders/index.d.ts +2 -2
  15. package/lib/loaders/index.js +1 -1
  16. package/lib/loaders/index.js.map +1 -1
  17. package/lib/locale-context.d.ts +2 -2
  18. package/lib/locale-context.js +1 -1
  19. package/lib/locale-context.js.map +1 -1
  20. package/lib/resolvers/index.js +2 -0
  21. package/lib/resolvers/index.js.map +1 -1
  22. package/lib/resolvers/mutations/accounts/addWeb3Address.d.ts +4 -0
  23. package/lib/resolvers/mutations/accounts/addWeb3Address.js +21 -0
  24. package/lib/resolvers/mutations/accounts/addWeb3Address.js.map +1 -0
  25. package/lib/resolvers/mutations/accounts/addWebAuthnCredentials.d.ts +4 -0
  26. package/lib/resolvers/mutations/accounts/addWebAuthnCredentials.js +14 -0
  27. package/lib/resolvers/mutations/accounts/addWebAuthnCredentials.js.map +1 -0
  28. package/lib/resolvers/mutations/accounts/createUser.js +18 -6
  29. package/lib/resolvers/mutations/accounts/createUser.js.map +1 -1
  30. package/lib/resolvers/mutations/accounts/createWebAuthnCredentialCreationOptions.d.ts +5 -0
  31. package/lib/resolvers/mutations/accounts/createWebAuthnCredentialCreationOptions.js +9 -0
  32. package/lib/resolvers/mutations/accounts/createWebAuthnCredentialCreationOptions.js.map +1 -0
  33. package/lib/resolvers/mutations/accounts/createWebAuthnCredentialRequestOptions.d.ts +5 -0
  34. package/lib/resolvers/mutations/accounts/createWebAuthnCredentialRequestOptions.js +16 -0
  35. package/lib/resolvers/mutations/accounts/createWebAuthnCredentialRequestOptions.js.map +1 -0
  36. package/lib/resolvers/mutations/accounts/loginWithWebAuthn.d.ts +8 -0
  37. package/lib/resolvers/mutations/accounts/loginWithWebAuthn.js +7 -0
  38. package/lib/resolvers/mutations/accounts/loginWithWebAuthn.js.map +1 -0
  39. package/lib/resolvers/mutations/accounts/logout.js +6 -2
  40. package/lib/resolvers/mutations/accounts/logout.js.map +1 -1
  41. package/lib/resolvers/mutations/accounts/logoutAllSessions.js +6 -2
  42. package/lib/resolvers/mutations/accounts/logoutAllSessions.js.map +1 -1
  43. package/lib/resolvers/mutations/accounts/removeWeb3Address.d.ts +4 -0
  44. package/lib/resolvers/mutations/accounts/removeWeb3Address.js +18 -0
  45. package/lib/resolvers/mutations/accounts/removeWeb3Address.js.map +1 -0
  46. package/lib/resolvers/mutations/accounts/removeWebAuthnCredentials.d.ts +4 -0
  47. package/lib/resolvers/mutations/accounts/removeWebAuthnCredentials.js +18 -0
  48. package/lib/resolvers/mutations/accounts/removeWebAuthnCredentials.js.map +1 -0
  49. package/lib/resolvers/mutations/accounts/verifyWeb3Address.d.ts +5 -0
  50. package/lib/resolvers/mutations/accounts/verifyWeb3Address.js +40 -0
  51. package/lib/resolvers/mutations/accounts/verifyWeb3Address.js.map +1 -0
  52. package/lib/resolvers/mutations/index.d.ts +174 -157
  53. package/lib/resolvers/mutations/index.js +20 -0
  54. package/lib/resolvers/mutations/index.js.map +1 -1
  55. package/lib/resolvers/mutations/orders/signPaymentProviderForCheckout.js +7 -1
  56. package/lib/resolvers/mutations/orders/signPaymentProviderForCheckout.js.map +1 -1
  57. package/lib/resolvers/mutations/pageView.d.ts +2 -2
  58. package/lib/resolvers/mutations/pageView.js.map +1 -1
  59. package/lib/resolvers/mutations/products/updateProductTokenization.d.ts +6 -0
  60. package/lib/resolvers/mutations/products/updateProductTokenization.js +19 -0
  61. package/lib/resolvers/mutations/products/updateProductTokenization.js.map +1 -0
  62. package/lib/resolvers/mutations/warehousing/exportToken.d.ts +6 -0
  63. package/lib/resolvers/mutations/warehousing/exportToken.js +21 -0
  64. package/lib/resolvers/mutations/warehousing/exportToken.js.map +1 -0
  65. package/lib/resolvers/queries/index.d.ts +67 -66
  66. package/lib/resolvers/queries/index.js +2 -0
  67. package/lib/resolvers/queries/index.js.map +1 -1
  68. package/lib/resolvers/queries/warehousing/token.d.ts +4 -0
  69. package/lib/resolvers/queries/warehousing/token.js +11 -0
  70. package/lib/resolvers/queries/warehousing/token.js.map +1 -0
  71. package/lib/resolvers/scalars/LowerCaseString.d.ts +3 -0
  72. package/lib/resolvers/scalars/LowerCaseString.js +17 -0
  73. package/lib/resolvers/scalars/LowerCaseString.js.map +1 -0
  74. package/lib/resolvers/scalars/index.d.ts +4 -0
  75. package/lib/resolvers/scalars/index.js +5 -0
  76. package/lib/resolvers/scalars/index.js.map +1 -0
  77. package/lib/resolvers/type/assortment/assortment-filter-types.d.ts +1 -1
  78. package/lib/resolvers/type/assortment/assortment-link-types.d.ts +1 -1
  79. package/lib/resolvers/type/assortment/assortment-product-types.d.ts +1 -1
  80. package/lib/resolvers/type/currency-types.d.ts +3 -0
  81. package/lib/resolvers/type/currency-types.js +6 -0
  82. package/lib/resolvers/type/currency-types.js.map +1 -0
  83. package/lib/resolvers/type/index.d.ts +246 -130
  84. package/lib/resolvers/type/index.js +8 -0
  85. package/lib/resolvers/type/index.js.map +1 -1
  86. package/lib/resolvers/type/login-method-response-types.d.ts +4 -0
  87. package/lib/resolvers/type/login-method-response-types.js +4 -0
  88. package/lib/resolvers/type/login-method-response-types.js.map +1 -1
  89. package/lib/resolvers/type/order/order-delivery-discount-types.d.ts +1 -1
  90. package/lib/resolvers/type/order/order-delivery-shipping-types.d.ts +1 -1
  91. package/lib/resolvers/type/order/order-discount-types.d.ts +1 -1
  92. package/lib/resolvers/type/order/order-discountable-types.d.ts +6 -0
  93. package/lib/resolvers/type/order/order-discountable-types.js +1 -1
  94. package/lib/resolvers/type/order/order-discountable-types.js.map +1 -1
  95. package/lib/resolvers/type/order/order-global-discount-types.d.ts +1 -1
  96. package/lib/resolvers/type/order/order-item-discount-types.d.ts +1 -1
  97. package/lib/resolvers/type/order/order-item-types.d.ts +1 -1
  98. package/lib/resolvers/type/order/order-payment-card-types.d.ts +1 -1
  99. package/lib/resolvers/type/order/order-payment-discount-types.d.ts +1 -1
  100. package/lib/resolvers/type/order/order-payment-generic-types.d.ts +1 -1
  101. package/lib/resolvers/type/order/order-payment-invoice-types.d.ts +1 -1
  102. package/lib/resolvers/type/order/order-types.d.ts +2 -6
  103. package/lib/resolvers/type/order/order-types.js +0 -1
  104. package/lib/resolvers/type/order/order-types.js.map +1 -1
  105. package/lib/resolvers/type/product/product-tokenized-types.d.ts +2 -0
  106. package/lib/resolvers/type/product/product-tokenized-types.js +28 -0
  107. package/lib/resolvers/type/product/product-tokenized-types.js.map +1 -0
  108. package/lib/resolvers/type/quotation-types.d.ts +0 -4
  109. package/lib/resolvers/type/quotation-types.js +0 -10
  110. package/lib/resolvers/type/quotation-types.js.map +1 -1
  111. package/lib/resolvers/type/shop-types.d.ts +1 -1
  112. package/lib/resolvers/type/token-types.d.ts +17 -0
  113. package/lib/resolvers/type/token-types.js +30 -0
  114. package/lib/resolvers/type/token-types.js.map +1 -0
  115. package/lib/resolvers/type/user-types.d.ts +5 -1
  116. package/lib/resolvers/type/user-types.js +12 -0
  117. package/lib/resolvers/type/user-types.js.map +1 -1
  118. package/lib/resolvers/type/webauthn-credentials-types.d.ts +10 -0
  119. package/lib/resolvers/type/webauthn-credentials-types.js +13 -0
  120. package/lib/resolvers/type/webauthn-credentials-types.js.map +1 -0
  121. package/lib/roles/admin.js +3 -0
  122. package/lib/roles/admin.js.map +1 -1
  123. package/lib/roles/all.js +3 -0
  124. package/lib/roles/all.js.map +1 -1
  125. package/lib/roles/index.d.ts +1 -1
  126. package/lib/roles/index.js +3 -0
  127. package/lib/roles/index.js.map +1 -1
  128. package/lib/roles/loggedIn.js +9 -0
  129. package/lib/roles/loggedIn.js.map +1 -1
  130. package/lib/schema/inputTypes.js +6 -4
  131. package/lib/schema/inputTypes.js.map +1 -1
  132. package/lib/schema/mutation.js +57 -4
  133. package/lib/schema/mutation.js.map +1 -1
  134. package/lib/schema/query.js +9 -4
  135. package/lib/schema/query.js.map +1 -1
  136. package/lib/schema/scalars.js +1 -0
  137. package/lib/schema/scalars.js.map +1 -1
  138. package/lib/schema/types/assortment.js +6 -6
  139. package/lib/schema/types/currency.js +1 -0
  140. package/lib/schema/types/currency.js.map +1 -1
  141. package/lib/schema/types/order/order.js +0 -33
  142. package/lib/schema/types/order/order.js.map +1 -1
  143. package/lib/schema/types/payment.js +1 -1
  144. package/lib/schema/types/product/bundle-product.js +2 -2
  145. package/lib/schema/types/product/configurable-product.js +2 -2
  146. package/lib/schema/types/product/index.js +9 -1
  147. package/lib/schema/types/product/index.js.map +1 -1
  148. package/lib/schema/types/product/plan-product.js +2 -2
  149. package/lib/schema/types/product/product.js +4 -4
  150. package/lib/schema/types/product/simple-product.js +2 -2
  151. package/lib/schema/types/product/tokenized-product.d.ts +2 -0
  152. package/lib/schema/types/product/tokenized-product.js +57 -0
  153. package/lib/schema/types/product/tokenized-product.js.map +1 -0
  154. package/lib/schema/types/quotation.js +0 -1
  155. package/lib/schema/types/quotation.js.map +1 -1
  156. package/lib/schema/types/user.js +39 -1
  157. package/lib/schema/types/user.js.map +1 -1
  158. package/lib/schema/types/warehousing.js +23 -1
  159. package/lib/schema/types/warehousing.js.map +1 -1
  160. package/lib/user-context.d.ts +2 -2
  161. package/lib/user-context.js +20 -9
  162. package/lib/user-context.js.map +1 -1
  163. package/package.json +11 -9
  164. package/src/api-index.ts +4 -0
  165. package/src/context.ts +3 -3
  166. package/src/createBulkImportServer.ts +1 -1
  167. package/src/createERCMetadataServer.ts +71 -0
  168. package/src/errors.ts +20 -0
  169. package/src/loaders/index.ts +2 -1
  170. package/src/locale-context.ts +2 -1
  171. package/src/resolvers/index.ts +2 -0
  172. package/src/resolvers/mutations/accounts/addWeb3Address.ts +33 -0
  173. package/src/resolvers/mutations/accounts/addWebAuthnCredentials.ts +29 -0
  174. package/src/resolvers/mutations/accounts/createUser.ts +28 -6
  175. package/src/resolvers/mutations/accounts/createWebAuthnCredentialCreationOptions.ts +20 -0
  176. package/src/resolvers/mutations/accounts/createWebAuthnCredentialRequestOptions.ts +28 -0
  177. package/src/resolvers/mutations/accounts/loginWithWebAuthn.ts +16 -0
  178. package/src/resolvers/mutations/accounts/logout.ts +5 -2
  179. package/src/resolvers/mutations/accounts/logoutAllSessions.ts +5 -2
  180. package/src/resolvers/mutations/accounts/removeWeb3Address.ts +32 -0
  181. package/src/resolvers/mutations/accounts/removeWebAuthnCredentials.ts +30 -0
  182. package/src/resolvers/mutations/accounts/verifyWeb3Address.ts +60 -0
  183. package/src/resolvers/mutations/{index.js → index.ts} +20 -0
  184. package/src/resolvers/mutations/orders/signPaymentProviderForCheckout.ts +8 -1
  185. package/src/resolvers/mutations/{pageView.js → pageView.ts} +0 -0
  186. package/src/resolvers/mutations/products/updateProductTokenization.ts +28 -0
  187. package/src/resolvers/mutations/warehousing/exportToken.ts +33 -0
  188. package/src/resolvers/queries/{index.js → index.ts} +2 -0
  189. package/src/resolvers/queries/warehousing/token.ts +17 -0
  190. package/src/resolvers/scalars/LowerCaseString.ts +19 -0
  191. package/src/resolvers/scalars/index.ts +5 -0
  192. package/src/resolvers/type/assortment/assortment-filter-types.ts +1 -1
  193. package/src/resolvers/type/assortment/assortment-link-types.ts +1 -1
  194. package/src/resolvers/type/assortment/assortment-product-types.ts +1 -1
  195. package/src/resolvers/type/currency-types.ts +5 -0
  196. package/src/resolvers/type/{index.js → index.ts} +8 -0
  197. package/src/resolvers/type/login-method-response-types.ts +4 -0
  198. package/src/resolvers/type/order/order-delivery-discount-types.ts +1 -1
  199. package/src/resolvers/type/order/order-delivery-shipping-types.ts +1 -1
  200. package/src/resolvers/type/order/order-discount-types.ts +1 -1
  201. package/src/resolvers/type/order/order-discountable-types.ts +1 -1
  202. package/src/resolvers/type/order/order-global-discount-types.ts +1 -1
  203. package/src/resolvers/type/order/order-item-discount-types.ts +1 -1
  204. package/src/resolvers/type/order/order-item-types.ts +1 -1
  205. package/src/resolvers/type/order/order-payment-card-types.ts +1 -1
  206. package/src/resolvers/type/order/order-payment-discount-types.ts +1 -1
  207. package/src/resolvers/type/order/order-payment-generic-types.ts +1 -1
  208. package/src/resolvers/type/order/order-payment-invoice-types.ts +1 -1
  209. package/src/resolvers/type/order/order-types.ts +2 -10
  210. package/src/resolvers/type/product/product-tokenized-types.ts +34 -0
  211. package/src/resolvers/type/quotation-types.ts +0 -17
  212. package/src/resolvers/type/shop-types.ts +1 -1
  213. package/src/resolvers/type/token-types.ts +43 -0
  214. package/src/resolvers/type/user-types.ts +26 -1
  215. package/src/resolvers/type/webauthn-credentials-types.ts +27 -0
  216. package/src/roles/admin.ts +3 -0
  217. package/src/roles/all.ts +3 -0
  218. package/src/roles/index.ts +4 -1
  219. package/src/roles/loggedIn.ts +13 -0
  220. package/src/schema/inputTypes.js +6 -4
  221. package/src/schema/mutation.js +57 -4
  222. package/src/schema/query.js +9 -4
  223. package/src/schema/scalars.js +1 -0
  224. package/src/schema/types/assortment.js +6 -6
  225. package/src/schema/types/currency.js +1 -0
  226. package/src/schema/types/order/order.js +0 -33
  227. package/src/schema/types/payment.js +1 -1
  228. package/src/schema/types/product/bundle-product.js +2 -2
  229. package/src/schema/types/product/configurable-product.js +2 -2
  230. package/src/schema/types/product/index.js +9 -1
  231. package/src/schema/types/product/plan-product.js +2 -2
  232. package/src/schema/types/product/product.js +4 -4
  233. package/src/schema/types/product/simple-product.js +2 -2
  234. package/src/schema/types/product/tokenized-product.js +56 -0
  235. package/src/schema/types/quotation.js +0 -1
  236. package/src/schema/types/user.js +39 -1
  237. package/src/schema/types/warehousing.js +23 -1
  238. package/src/user-context.ts +23 -9
@@ -1,6 +1,7 @@
1
1
  import { actions } from '../../roles';
2
2
  import { checkResolver as acl } from '../../acl';
3
3
  import loginWithPassword from './accounts/loginWithPassword';
4
+ import loginWithWebAuthn from './accounts/loginWithWebAuthn';
4
5
  import impersonate from './accounts/impersonate';
5
6
  import loginAsGuest from './accounts/loginAsGuest';
6
7
  import logout from './accounts/logout';
@@ -18,6 +19,13 @@ import forgotPassword from './accounts/forgotPassword';
18
19
  import resetPassword from './accounts/resetPassword';
19
20
  import addEmail from './accounts/addEmail';
20
21
  import removeEmail from './accounts/removeEmail';
22
+ import createWebAuthnCredentialCreationOptions from './accounts/createWebAuthnCredentialCreationOptions';
23
+ import createWebAuthnCredentialRequestOptions from './accounts/createWebAuthnCredentialRequestOptions';
24
+ import addWebAuthnCredentials from './accounts/addWebAuthnCredentials';
25
+ import removeWebAuthnCredentials from './accounts/removeWebAuthnCredentials';
26
+ import addWeb3Address from './accounts/addWeb3Address';
27
+ import removeWeb3Address from './accounts/removeWeb3Address';
28
+ import verifyWeb3Address from './accounts/verifyWeb3Address';
21
29
  import updateUserAvatar from './users/updateUserAvatar';
22
30
  import updateUserProfile from './users/updateUserProfile';
23
31
  import setUserTags from './users/setUserTags';
@@ -36,6 +44,7 @@ import removeProduct from './products/removeProduct';
36
44
  import unpublishProduct from './products/unpublishProduct';
37
45
  import updateProduct from './products/updateProduct';
38
46
  import updateProductTexts from './products/updateProductTexts';
47
+ import updateProductTokenization from './products/updateProductTokenization';
39
48
  import updateProductMediaTexts from './products/updateProductMediaTexts';
40
49
  import createProductVariation from './products/createProductVariation';
41
50
  import createProductBundleItem from './products/createProductBundleItem';
@@ -79,6 +88,7 @@ import removeDeliveryProvider from './delivery/removeDeliveryProvider';
79
88
  import createWarehousingProvider from './warehousing/createWarehousingProvider';
80
89
  import updateWarehousingProvider from './warehousing/updateWarehousingProvider';
81
90
  import removeWarehousingProvider from './warehousing/removeWarehousingProvider';
91
+ import exportToken from './warehousing/exportToken';
82
92
  import setPassword from './accounts/setPassword';
83
93
  import setRoles from './users/setRoles';
84
94
  import setUsername from './accounts/setUsername';
@@ -149,8 +159,16 @@ export default {
149
159
  logout,
150
160
  logoutAllSessions,
151
161
  loginAsGuest,
162
+ createWebAuthnCredentialCreationOptions,
163
+ createWebAuthnCredentialRequestOptions,
164
+ addWebAuthnCredentials: acl(actions.updateUser)(addWebAuthnCredentials),
165
+ removeWebAuthnCredentials: acl(actions.updateUser)(removeWebAuthnCredentials),
166
+ addWeb3Address: acl(actions.updateUser)(addWeb3Address),
167
+ removeWeb3Address: acl(actions.updateUser)(removeWeb3Address),
168
+ verifyWeb3Address: acl(actions.updateUser)(verifyWeb3Address),
152
169
  verifyEmail,
153
170
  loginWithPassword,
171
+ loginWithWebAuthn,
154
172
  impersonate: acl(actions.impersonate)(impersonate),
155
173
  buildSecretTOTPAuthURL: acl(actions.authTwoFactor)(buildSecretTOTPAuthURL),
156
174
  enableTOTP: acl(actions.authTwoFactor)(enableTOTP),
@@ -203,6 +221,7 @@ export default {
203
221
  updateProductWarehousing: acl(actions.manageProducts)(updateProductWarehousing),
204
222
  updateProductSupply: acl(actions.manageProducts)(updateProductSupply),
205
223
  updateProductPlan: acl(actions.manageProducts)(updateProductPlan),
224
+ updateProductTokenization: acl(actions.manageProducts)(updateProductTokenization),
206
225
  removeProductVariation: acl(actions.manageProducts)(removeProductVariation),
207
226
  updateProductVariationTexts: acl(actions.manageProducts)(updateProductVariationTexts),
208
227
  removeProductVariationOption: acl(actions.manageProducts)(removeProductVariationOption),
@@ -257,6 +276,7 @@ export default {
257
276
  createWarehousingProvider: acl(actions.manageWarehousingProviders)(createWarehousingProvider),
258
277
  updateWarehousingProvider: acl(actions.manageWarehousingProviders)(updateWarehousingProvider),
259
278
  removeWarehousingProvider: acl(actions.manageWarehousingProviders)(removeWarehousingProvider),
279
+ exportToken: acl(actions.updateToken)(exportToken),
260
280
 
261
281
  createFilter: acl(actions.manageFilters)(createFilter),
262
282
  updateFilter: acl(actions.manageFilters)(updateFilter),
@@ -1,12 +1,13 @@
1
1
  import { log } from '@unchainedshop/logger';
2
2
  import { Context, Root } from '@unchainedshop/types/api';
3
3
  import { PaymentProviderType } from '@unchainedshop/core-payment';
4
-
4
+ import { OrderPaymentStatus } from '@unchainedshop/types/orders.payments';
5
5
  import {
6
6
  InvalidIdError,
7
7
  OrderPaymentConfigurationError,
8
8
  OrderPaymentNotFoundError,
9
9
  OrderPaymentTypeError,
10
+ OrderWrongPaymentStatusError,
10
11
  } from '../../../errors';
11
12
 
12
13
  export default async function signPaymentProviderForCheckout(
@@ -40,6 +41,12 @@ export default async function signPaymentProviderForCheckout(
40
41
  required: PaymentProviderType.GENERIC,
41
42
  });
42
43
 
44
+ if (modules.orders.payments.normalizedStatus(orderPayment) !== OrderPaymentStatus.OPEN) {
45
+ throw new OrderWrongPaymentStatusError({
46
+ status: orderPayment.status,
47
+ });
48
+ }
49
+
43
50
  try {
44
51
  const sign = await modules.payment.paymentProviders.sign(
45
52
  provider._id,
@@ -0,0 +1,28 @@
1
+ import { log } from '@unchainedshop/logger';
2
+ import { ProductTypes } from '@unchainedshop/core-products';
3
+ import { Context, Root } from '@unchainedshop/types/api';
4
+ import { ProductTokenization } from '@unchainedshop/types/products';
5
+ import { ProductNotFoundError, InvalidIdError, ProductWrongStatusError } from '../../../errors';
6
+
7
+ export default async function updateProductTokenization(
8
+ root: Root,
9
+ { tokenization, productId }: { tokenization: ProductTokenization; productId: string },
10
+ { modules, userId }: Context,
11
+ ) {
12
+ log(`mutation updateProductTokenization ${productId}`, { userId });
13
+
14
+ if (!productId) throw new InvalidIdError({ productId });
15
+
16
+ const product = await modules.products.findProduct({ productId });
17
+ if (!product) throw new ProductNotFoundError({ productId });
18
+
19
+ if (product?.type !== ProductTypes.TokenizedProduct)
20
+ throw new ProductWrongStatusError({
21
+ received: product?.type,
22
+ required: ProductTypes.TokenizedProduct,
23
+ });
24
+
25
+ await modules.products.update(productId, { tokenization }, userId);
26
+
27
+ return modules.products.findProduct({ productId });
28
+ }
@@ -0,0 +1,33 @@
1
+ import { Context, Root } from '@unchainedshop/types/api';
2
+ import { log } from '@unchainedshop/logger';
3
+ import { InvalidIdError } from '../../../errors';
4
+
5
+ export default async function exportToken(
6
+ root: Root,
7
+ {
8
+ tokenId,
9
+ quantity,
10
+ recipientWalletAddress,
11
+ }: { tokenId: string; quantity: number; recipientWalletAddress: string },
12
+ { modules, userId }: Context,
13
+ ) {
14
+ log(`mutation exportToken ${tokenId}`, {
15
+ userId,
16
+ });
17
+
18
+ if (!tokenId) throw new InvalidIdError({ tokenId });
19
+
20
+ const token = await modules.warehousing.findToken({ tokenId });
21
+
22
+ await modules.worker.addWork({
23
+ type: 'EXPORT_TOKEN',
24
+ retries: 5,
25
+ input: {
26
+ token,
27
+ quantity,
28
+ recipientWalletAddress,
29
+ },
30
+ });
31
+
32
+ return modules.warehousing.findToken({ tokenId });
33
+ }
@@ -61,6 +61,7 @@ import warehousingInterfaces from './warehousing/warehousingInterfaces';
61
61
  import warehousingProvider from './warehousing/warehousingProvider';
62
62
  import warehousingProviders from './warehousing/warehousingProviders';
63
63
  import warehousingProvidersCount from './warehousing/warehousingProvidersCount';
64
+ import token from './warehousing/token';
64
65
  import work from './worker/work';
65
66
  import workQueue from './worker/workQueue';
66
67
  import workQueueCount from './worker/workQueueCount';
@@ -95,6 +96,7 @@ export default {
95
96
  warehousingProviders: acl(actions.viewWarehousingProviders)(warehousingProviders),
96
97
  warehousingProvider: acl(actions.viewWarehousingProvider)(warehousingProvider),
97
98
  warehousingInterfaces: acl(actions.viewWarehousingInterfaces)(warehousingInterfaces),
99
+ token: acl(actions.viewToken)(token),
98
100
  translatedProductTexts: acl(actions.viewTranslations)(translatedProductTexts),
99
101
  translatedProductMediaTexts: acl(actions.viewTranslations)(translatedProductMediaTexts),
100
102
  translatedProductVariationTexts: acl(actions.viewTranslations)(translatedProductVariationTexts),
@@ -0,0 +1,17 @@
1
+ import { log } from '@unchainedshop/logger';
2
+ import { Context, Root } from '@unchainedshop/types/api';
3
+ import { InvalidIdError } from '../../../errors';
4
+
5
+ export default async function token(
6
+ root: Root,
7
+ { tokenId }: { tokenId: string },
8
+ { modules, userId }: Context,
9
+ ) {
10
+ log(`query token ${tokenId}`, { userId });
11
+
12
+ if (!tokenId) throw new InvalidIdError({ tokenId });
13
+
14
+ return modules.warehousing.findToken({
15
+ tokenId,
16
+ });
17
+ }
@@ -0,0 +1,19 @@
1
+ import { GraphQLScalarType, Kind } from 'graphql';
2
+
3
+ const LowerCaseString = new GraphQLScalarType({
4
+ name: 'LowerCaseString',
5
+ description: 'Lowercased string',
6
+ serialize: (value: any) => value?.toLowerCase(),
7
+ parseValue(value) {
8
+ return String(value)?.toLowerCase();
9
+ },
10
+ parseLiteral(ast) {
11
+ if (ast.kind === Kind.STRING) {
12
+ return ast.value?.toLowerCase();
13
+ }
14
+
15
+ return null;
16
+ },
17
+ });
18
+
19
+ export default LowerCaseString;
@@ -0,0 +1,5 @@
1
+ import LowerCaseString from './LowerCaseString';
2
+
3
+ export default {
4
+ LowerCaseString,
5
+ };
@@ -4,7 +4,7 @@ import { Filter } from '@unchainedshop/types/filters';
4
4
 
5
5
  type HelperType<T> = (assortmentFilter: AssortmentFilterType, _: never, context: Context) => T;
6
6
 
7
- type AssortmentFilterHelperTypes = {
7
+ export type AssortmentFilterHelperTypes = {
8
8
  assortment: HelperType<Promise<Assortment>>;
9
9
  filter: HelperType<Promise<Filter>>;
10
10
  };
@@ -3,7 +3,7 @@ import { Assortment, AssortmentLink as AssortmentLinkType } from '@unchainedshop
3
3
 
4
4
  type HelperType<T> = (assortmentLink: AssortmentLinkType, _: never, context: Context) => T;
5
5
 
6
- type AssortmentLinkHelperTypes = {
6
+ export type AssortmentLinkHelperTypes = {
7
7
  child: HelperType<Promise<Assortment>>;
8
8
  parent: HelperType<Promise<Assortment>>;
9
9
  };
@@ -7,7 +7,7 @@ import { Product } from '@unchainedshop/types/products';
7
7
 
8
8
  type HelperType<T> = (assortmentProduct: AssortmentProductType, _: never, context: Context) => T;
9
9
 
10
- type AssortmentProductHelperTypes = {
10
+ export type AssortmentProductHelperTypes = {
11
11
  assortment: HelperType<Promise<Assortment>>;
12
12
  product: HelperType<Promise<Product>>;
13
13
  };
@@ -0,0 +1,5 @@
1
+ export const Currency = {
2
+ decimals: (currency) => {
3
+ return currency.decimals ?? 2;
4
+ },
5
+ };
@@ -9,6 +9,7 @@ import { BundleProduct } from './product/product-bundle-types';
9
9
  import { Color } from './color-types';
10
10
  import { ConfigurableProduct } from './product/product-configurable-types';
11
11
  import { Country } from './country-types';
12
+ import { Currency } from './currency-types';
12
13
  import { DeliveryProvider } from './delivery-provider-types';
13
14
  import { Dimensions } from './dimensions-types';
14
15
  import { Dispatch } from './dispatch-types';
@@ -56,12 +57,15 @@ import { ProductVariationOption } from './product/product-variation-option-types
56
57
  import { Quotation } from './quotation-types';
57
58
  import { Shop } from './shop-types';
58
59
  import { SimpleProduct } from './product/product-simple-types';
60
+ import { TokenizedProduct } from './product/product-tokenized-types';
59
61
  import { Stock } from './stock-types';
60
62
  import { User } from './user-types';
63
+ import { WebAuthnCredentials } from './webauthn-credentials-types';
61
64
  import { WarehousingProvider } from './warehousing-provider-types';
62
65
  import { Work } from './work-types';
63
66
  import { Event } from './event-types';
64
67
  import { Media } from './media-types';
68
+ import { Token } from './token-types';
65
69
 
66
70
  const types = {
67
71
  Assortment,
@@ -75,6 +79,7 @@ const types = {
75
79
  Color,
76
80
  ConfigurableProduct,
77
81
  Country,
82
+ Currency,
78
83
  DeliveryProvider,
79
84
  Dimensions,
80
85
  Dispatch,
@@ -122,8 +127,11 @@ const types = {
122
127
  Quotation,
123
128
  Shop,
124
129
  SimpleProduct,
130
+ TokenizedProduct,
131
+ Token,
125
132
  Stock,
126
133
  User,
134
+ WebAuthnCredentials,
127
135
  WarehousingProvider,
128
136
  Work,
129
137
  Event,
@@ -10,4 +10,8 @@ export const LoginMethodResponse = {
10
10
 
11
11
  return user;
12
12
  },
13
+ token({ token, tokenExpires }, _, { setLoginToken }: Context) {
14
+ setLoginToken(token, tokenExpires);
15
+ return token;
16
+ },
13
17
  };
@@ -6,7 +6,7 @@ import crypto from 'crypto';
6
6
 
7
7
  type HelperType<P, T> = (orderDelivery: OrderDeliveryDiscountType, params: P, context: Context) => T;
8
8
 
9
- interface OrderDeliveryDiscountHelperTypes {
9
+ export interface OrderDeliveryDiscountHelperTypes {
10
10
  _id: HelperType<never, string>;
11
11
  orderDiscount: HelperType<never, Promise<OrderDiscount>>;
12
12
  total: HelperType<never, OrderPrice>;
@@ -5,7 +5,7 @@ import { OrderDelivery, OrderDeliveryDiscount } from '@unchainedshop/types/order
5
5
 
6
6
  type HelperType<T> = (orderDelivery: OrderDelivery, _: never, context: Context) => T;
7
7
 
8
- interface OrderDeliveryShippingHelperTypes {
8
+ export interface OrderDeliveryShippingHelperTypes {
9
9
  address: HelperType<Address>;
10
10
  discounts: HelperType<Promise<Array<OrderDeliveryDiscount>>>;
11
11
  provider: HelperType<Promise<DeliveryProvider>>;
@@ -6,7 +6,7 @@ import { OrderDiscountDirector } from '@unchainedshop/core-orders';
6
6
 
7
7
  type HelperType<P, T> = (orderDiscount: OrderDiscountType, params: P, context: Context) => T;
8
8
 
9
- interface OrderDiscountHelperTypes {
9
+ export interface OrderDiscountHelperTypes {
10
10
  interface: HelperType<
11
11
  never,
12
12
  Promise<{
@@ -5,7 +5,7 @@ import { OrderPayment } from '@unchainedshop/types/orders.payments';
5
5
  import { OrderPosition } from '@unchainedshop/types/orders.positions';
6
6
  import { OrderPrice } from '@unchainedshop/types/orders.pricing';
7
7
 
8
- const OrderDiscountableType = {
8
+ export const OrderDiscountableType = {
9
9
  OrderItemDiscount: 'OrderItemDiscount',
10
10
  OrderPaymentDiscount: 'OrderPaymentDiscount',
11
11
  OrderDeliveryDiscount: 'OrderDeliveryDiscount',
@@ -13,7 +13,7 @@ type HelperType<P, T> = (
13
13
  context: Context,
14
14
  ) => T;
15
15
 
16
- interface OrderGlobalDiscountHelperTypes {
16
+ export interface OrderGlobalDiscountHelperTypes {
17
17
  _id: HelperType<never, string>;
18
18
  orderDiscount: HelperType<never, Promise<OrderDiscount>>;
19
19
  total: HelperType<never, OrderPrice>;
@@ -6,7 +6,7 @@ import crypto from 'crypto';
6
6
 
7
7
  type HelperType<P, T> = (orderPositionDiscount: OrderPositionDiscount, params: P, context: Context) => T;
8
8
 
9
- interface OrderItemDiscountHelperTypes {
9
+ export interface OrderItemDiscountHelperTypes {
10
10
  _id: HelperType<never, string>;
11
11
  orderDiscount: HelperType<never, Promise<OrderDiscount>>;
12
12
  total: HelperType<never, OrderPrice>;
@@ -10,7 +10,7 @@ import crypto from 'crypto';
10
10
 
11
11
  type HelperType<P, T> = (orderPosition: OrderPosition, params: P, context: Context) => T;
12
12
 
13
- interface OrderItemHelperTypes {
13
+ export interface OrderItemHelperTypes {
14
14
  discounts: HelperType<never, Promise<Array<OrderPositionDiscount>>>;
15
15
  dispatches: HelperType<
16
16
  never,
@@ -4,7 +4,7 @@ import { PaymentProvider } from '@unchainedshop/types/payments';
4
4
 
5
5
  type HelperType<T> = (orderPayment: OrderPayment, _: never, context: Context) => T;
6
6
 
7
- interface OrderPaymentCardHelperTypes {
7
+ export interface OrderPaymentCardHelperTypes {
8
8
  discounts: HelperType<Promise<Array<OrderPaymentDiscount>>>;
9
9
  provider: HelperType<Promise<PaymentProvider>>;
10
10
  status: HelperType<string>;
@@ -10,7 +10,7 @@ type HelperType<P, T> = (
10
10
  context: Context,
11
11
  ) => T;
12
12
 
13
- interface OrderPaymentDiscountHelperTypes {
13
+ export interface OrderPaymentDiscountHelperTypes {
14
14
  _id: HelperType<never, string>;
15
15
  orderDiscount: HelperType<never, Promise<OrderDiscount>>;
16
16
  total: HelperType<never, OrderPrice>;
@@ -4,7 +4,7 @@ import { PaymentProvider } from '@unchainedshop/types/payments';
4
4
 
5
5
  type HelperType<P, T> = (orderPayment: OrderPayment, params: P, context: Context) => T;
6
6
 
7
- interface OrderPaymentGenericHelperTypes {
7
+ export interface OrderPaymentGenericHelperTypes {
8
8
  discounts: HelperType<never, Promise<Array<OrderPaymentDiscount>>>;
9
9
  provider: HelperType<never, Promise<PaymentProvider>>;
10
10
  status: HelperType<never, string>;
@@ -4,7 +4,7 @@ import { PaymentProvider } from '@unchainedshop/types/payments';
4
4
 
5
5
  type HelperType<T> = (orderPayment: OrderPayment, _: never, context: Context) => T;
6
6
 
7
- interface OrderPaymentInvoiceHelperTypes {
7
+ export interface OrderPaymentInvoiceHelperTypes {
8
8
  discounts: HelperType<Promise<Array<OrderPaymentDiscount>>>;
9
9
  provider: HelperType<Promise<PaymentProvider>>;
10
10
  status: HelperType<string>;
@@ -3,8 +3,7 @@ import { Country } from '@unchainedshop/types/countries';
3
3
  import { Currency } from '@unchainedshop/types/currencies';
4
4
  import { DeliveryProvider } from '@unchainedshop/types/delivery';
5
5
  import { Enrollment } from '@unchainedshop/types/enrollments';
6
- import { File } from '@unchainedshop/types/files';
7
- import { Order as OrderType, OrderDocumentType } from '@unchainedshop/types/orders';
6
+ import { Order as OrderType } from '@unchainedshop/types/orders';
8
7
  import { OrderDelivery } from '@unchainedshop/types/orders.deliveries';
9
8
  import { OrderDiscount } from '@unchainedshop/types/orders.discounts';
10
9
  import { OrderPayment } from '@unchainedshop/types/orders.payments';
@@ -16,14 +15,13 @@ import crypto from 'crypto';
16
15
 
17
16
  type HelperType<P, T> = (order: OrderType, params: P, context: Context) => T;
18
17
 
19
- interface OrderHelperTypes {
18
+ export interface OrderHelperTypes {
20
19
  supportedDeliveryProviders: HelperType<never, Promise<Array<DeliveryProvider>>>;
21
20
  supportedPaymentProviders: HelperType<never, Promise<Array<PaymentProvider>>>;
22
21
  currency: HelperType<never, Promise<Currency>>;
23
22
  country: HelperType<never, Promise<Country>>;
24
23
  discounts: HelperType<never, Promise<Array<OrderDiscount>>>;
25
24
  delivery: HelperType<never, Promise<OrderDelivery>>;
26
- documents: HelperType<{ type: OrderDocumentType }, Promise<Array<File>>>;
27
25
  enrollment: HelperType<never, Promise<Enrollment>>;
28
26
  payment: HelperType<never, Promise<OrderPayment>>;
29
27
  items: HelperType<never, Promise<Array<OrderPosition>>>;
@@ -55,12 +53,6 @@ export const Order: OrderHelperTypes = {
55
53
  discounts: async (obj, _, { modules }) =>
56
54
  modules.orders.discounts.findOrderDiscounts({ orderId: obj._id }),
57
55
 
58
- documents: async (obj, { type }, { modules }) =>
59
- modules.files.findFilesByMetaData(
60
- { meta: { orderId: obj._id, type } },
61
- { sort: { 'meta.data': -1 } },
62
- ),
63
-
64
56
  delivery: async (obj, _, { modules }) =>
65
57
  modules.orders.deliveries.findDelivery({
66
58
  orderDeliveryId: obj.deliveryId,
@@ -0,0 +1,34 @@
1
+ import { TokenizedProductHelperTypes } from '@unchainedshop/types/products';
2
+ import localePkg from 'locale';
3
+ import { PlanProduct } from './product-plan-types';
4
+
5
+ const { Locale } = localePkg;
6
+
7
+ export const TokenizedProduct: TokenizedProductHelperTypes = {
8
+ ...PlanProduct,
9
+
10
+ contractAddress(product) {
11
+ return product.tokenization?.contractAddress;
12
+ },
13
+
14
+ contractConfiguration(product) {
15
+ if (!product.tokenization) return null;
16
+ return {
17
+ supply: product.tokenization.supply,
18
+ tokenId: product.tokenization.tokenId,
19
+ };
20
+ },
21
+
22
+ contractStandard(product) {
23
+ return product.tokenization?.contractStandard;
24
+ },
25
+
26
+ async ercMetadata(product, { forceLocale }, context) {
27
+ const locale = forceLocale ? new Locale(forceLocale) : context.localeContext;
28
+ return context.services.products.ercMetadata({ product, locale }, context);
29
+ },
30
+ };
31
+
32
+ delete TokenizedProduct.salesUnit;
33
+ delete TokenizedProduct.salesQuantityPerUnit;
34
+ delete TokenizedProduct.defaultOrderQuantity;
@@ -4,14 +4,12 @@ import { User } from '@unchainedshop/types/user';
4
4
  import { Product } from '@unchainedshop/types/products';
5
5
  import { Country } from '@unchainedshop/types/countries';
6
6
  import { Currency } from '@unchainedshop/types/currencies';
7
- import { File } from '@unchainedshop/types/files';
8
7
 
9
8
  type HelperType<P, T> = (quotation: QuotationType, params: P, context: Context) => T;
10
9
 
11
10
  type QuotationHelperTypes = {
12
11
  country: HelperType<never, Promise<Country>>;
13
12
  currency: HelperType<never, Promise<Currency>>;
14
- documents: HelperType<{ type: string }, Promise<Array<File>>>;
15
13
  isExpired: HelperType<{ referenceDate: Date }, boolean>;
16
14
  status: HelperType<never, string>;
17
15
  product: HelperType<never, Promise<Product>>;
@@ -23,21 +21,6 @@ export const Quotation: QuotationHelperTypes = {
23
21
 
24
22
  currency: async (obj, _, { modules }) => modules.currencies.findCurrency({ isoCode: obj.currency }),
25
23
 
26
- documents: (obj, { type }, { modules }) =>
27
- modules.files.findFilesByMetaData(
28
- {
29
- meta: {
30
- quotationId: obj._id,
31
- type,
32
- },
33
- },
34
- {
35
- sort: {
36
- 'meta.date': -1,
37
- },
38
- },
39
- ),
40
-
41
24
  isExpired: (obj, { referenceDate }, { modules }) =>
42
25
  modules.quotations.isExpired(obj, { referenceDate }),
43
26
 
@@ -6,7 +6,7 @@ import { allRoles, actions } from '../../roles';
6
6
 
7
7
  type HelperType<T> = (root: never, params: never, context: Context) => Promise<T>;
8
8
 
9
- interface ShopHelperTypes {
9
+ export interface ShopHelperTypes {
10
10
  _id: () => string;
11
11
  country: HelperType<Country>;
12
12
  language: HelperType<Language>;
@@ -0,0 +1,43 @@
1
+ import { Context } from '@unchainedshop/types/api';
2
+ import { Product } from '@unchainedshop/types/products';
3
+ import { User } from '@unchainedshop/types/user';
4
+ import { TokenSurrogate } from '@unchainedshop/types/warehousing';
5
+ import { WorkStatus } from '@unchainedshop/types/worker';
6
+
7
+ type HelperType<T> = (root: TokenSurrogate, params: never, context: Context) => Promise<T>;
8
+
9
+ export enum TokenExportStatus {
10
+ CENTRALIZED = 'CENTRALIZED',
11
+ EXPORTING = 'EXPORTING',
12
+ DECENTRALIZED = 'DECENTRALIZED',
13
+ }
14
+
15
+ export interface TokenHelperTypes {
16
+ product: HelperType<Product>;
17
+ status: HelperType<TokenExportStatus>;
18
+ user: HelperType<User>;
19
+ }
20
+
21
+ export const Token: TokenHelperTypes = {
22
+ product: async (token, _params, { modules }) => {
23
+ return modules.products.findProduct({ productId: token.productId });
24
+ },
25
+
26
+ user: async (token, _params, { modules }) => {
27
+ if (!token.userId) return null;
28
+ return modules.users.findUserById(token.userId);
29
+ },
30
+
31
+ status: async (token, _params, { modules }) => {
32
+ if (token.walletAddress && !token.userId) {
33
+ return TokenExportStatus.DECENTRALIZED;
34
+ }
35
+ const workItems = await modules.worker.findWorkQueue({
36
+ types: ['EXPORT_TOKEN'],
37
+ status: [WorkStatus.NEW, WorkStatus.ALLOCATED],
38
+ });
39
+ if (workItems.find((item) => item.input?.token?._id === token._id))
40
+ return TokenExportStatus.EXPORTING;
41
+ return TokenExportStatus.CENTRALIZED;
42
+ },
43
+ };
@@ -8,9 +8,16 @@ import { Language } from '@unchainedshop/types/languages';
8
8
  import { Order } from '@unchainedshop/types/orders';
9
9
  import { PaymentCredentials } from '@unchainedshop/types/payments';
10
10
  import { Quotation } from '@unchainedshop/types/quotations';
11
- import { Email, User as UserType, UserProfile } from '@unchainedshop/types/user';
11
+ import {
12
+ Email,
13
+ User as UserType,
14
+ UserProfile,
15
+ Web3Address,
16
+ WebAuthnCredentials,
17
+ } from '@unchainedshop/types/user';
12
18
  import type { Locale } from 'locale';
13
19
  import { log, LogLevel } from '@unchainedshop/logger';
20
+ import { TokenSurrogate } from '@unchainedshop/types/warehousing';
14
21
  import { checkAction, checkTypeResolver } from '../../acl';
15
22
  import { actions } from '../../roles';
16
23
 
@@ -41,6 +48,9 @@ export interface UserHelperTypes {
41
48
  Array<Order>
42
49
  >;
43
50
  paymentCredentials: HelperType<any, Array<PaymentCredentials>>;
51
+ tokens: HelperType<any, Array<TokenSurrogate>>;
52
+ webAuthnCredentials: HelperType<any, Array<WebAuthnCredentials>>;
53
+ web3Addresses: HelperType<any, Array<Web3Address>>;
44
54
  primaryEmail: HelperType<any, Email>;
45
55
  profile: HelperType<any, UserProfile>;
46
56
  quotations: HelperType<{ sort?: Array<SortOption>; queryString?: string }, Array<Quotation>>;
@@ -132,6 +142,11 @@ export const User: UserHelperTypes = {
132
142
  return modules.orders.cart({ countryContext, orderNumber: params.orderNumber }, user);
133
143
  },
134
144
 
145
+ async tokens(user, params, context) {
146
+ await checkAction(context, viewUserPrivateInfos, [user, params]);
147
+ return context.modules.warehousing.findTokensForUser(user);
148
+ },
149
+
135
150
  country: async (user, params, context) => {
136
151
  await checkAction(context, viewUserPrivateInfos, [user, params]);
137
152
  return context.services.users.getUserCountry(user, params, context);
@@ -181,6 +196,16 @@ export const User: UserHelperTypes = {
181
196
  );
182
197
  },
183
198
 
199
+ webAuthnCredentials: async (user, params, context) => {
200
+ await checkAction(context, viewUserPrivateInfos, [user, params]);
201
+ return user.services.webAuthn || [];
202
+ },
203
+
204
+ web3Addresses: async (user, params, context) => {
205
+ await checkAction(context, viewUserPrivateInfos, [user, params]);
206
+ return user.services.web3 || [];
207
+ },
208
+
184
209
  quotations: async (user, params, context) => {
185
210
  await checkAction(context, viewUserQuotations, [user, params]);
186
211
  return context.modules.quotations.findQuotations({