@unchainedshop/api 2.0.0-beta8 → 2.0.0-beta9

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 (433) hide show
  1. package/jest.config.js +9 -0
  2. package/lib/acl.d.ts +2 -0
  3. package/lib/acl.js +2 -2
  4. package/lib/acl.js.map +1 -1
  5. package/lib/api-index.d.ts +1 -0
  6. package/lib/api-index.js +1 -1
  7. package/lib/api-index.js.map +1 -1
  8. package/lib/createGraphQLServer.js +11 -17
  9. package/lib/createGraphQLServer.js.map +1 -1
  10. package/lib/errors.d.ts +20 -0
  11. package/lib/errors.js +20 -0
  12. package/lib/errors.js.map +1 -1
  13. package/lib/express/createBulkImportMiddleware.js +1 -1
  14. package/lib/express/createBulkImportMiddleware.js.map +1 -1
  15. package/lib/express/createERCMetadataMiddleware.js +2 -1
  16. package/lib/express/createERCMetadataMiddleware.js.map +1 -1
  17. package/lib/express/createSingleSignOnMiddleware.js.map +1 -1
  18. package/lib/loaders/index.js +5 -9
  19. package/lib/loaders/index.js.map +1 -1
  20. package/lib/resolvers/mutations/accounts/changePassword.js +12 -1
  21. package/lib/resolvers/mutations/accounts/changePassword.js.map +1 -1
  22. package/lib/resolvers/mutations/accounts/createUser.js +17 -3
  23. package/lib/resolvers/mutations/accounts/createUser.js.map +1 -1
  24. package/lib/resolvers/mutations/accounts/disableTOTP.js +15 -2
  25. package/lib/resolvers/mutations/accounts/disableTOTP.js.map +1 -1
  26. package/lib/resolvers/mutations/accounts/enableTOTP.js +12 -1
  27. package/lib/resolvers/mutations/accounts/enableTOTP.js.map +1 -1
  28. package/lib/resolvers/mutations/accounts/enrollUser.js +17 -4
  29. package/lib/resolvers/mutations/accounts/enrollUser.js.map +1 -1
  30. package/lib/resolvers/mutations/accounts/forgotPassword.js +11 -1
  31. package/lib/resolvers/mutations/accounts/forgotPassword.js.map +1 -1
  32. package/lib/resolvers/mutations/accounts/impersonate.js +1 -1
  33. package/lib/resolvers/mutations/accounts/impersonate.js.map +1 -1
  34. package/lib/resolvers/mutations/accounts/loginWithPassword.js +19 -1
  35. package/lib/resolvers/mutations/accounts/loginWithPassword.js.map +1 -1
  36. package/lib/resolvers/mutations/accounts/loginWithWebAuthn.js +13 -1
  37. package/lib/resolvers/mutations/accounts/loginWithWebAuthn.js.map +1 -1
  38. package/lib/resolvers/mutations/accounts/logout.d.ts +1 -1
  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 +4 -1
  42. package/lib/resolvers/mutations/accounts/logoutAllSessions.js.map +1 -1
  43. package/lib/resolvers/mutations/accounts/resetPassword.js +17 -2
  44. package/lib/resolvers/mutations/accounts/resetPassword.js.map +1 -1
  45. package/lib/resolvers/mutations/assortments/addAssortmentFilter.js +1 -2
  46. package/lib/resolvers/mutations/assortments/addAssortmentFilter.js.map +1 -1
  47. package/lib/resolvers/mutations/assortments/addAssortmentLink.js +16 -9
  48. package/lib/resolvers/mutations/assortments/addAssortmentLink.js.map +1 -1
  49. package/lib/resolvers/mutations/assortments/addAssortmentMedia.js +2 -3
  50. package/lib/resolvers/mutations/assortments/addAssortmentMedia.js.map +1 -1
  51. package/lib/resolvers/mutations/assortments/addAssortmentProduct.js +1 -2
  52. package/lib/resolvers/mutations/assortments/addAssortmentProduct.js.map +1 -1
  53. package/lib/resolvers/mutations/assortments/createAssortment.js +1 -2
  54. package/lib/resolvers/mutations/assortments/createAssortment.js.map +1 -1
  55. package/lib/resolvers/mutations/assortments/prepareAssortmentMediaUpload.js +0 -1
  56. package/lib/resolvers/mutations/assortments/prepareAssortmentMediaUpload.js.map +1 -1
  57. package/lib/resolvers/mutations/assortments/removeAssortmentMedia.js +2 -2
  58. package/lib/resolvers/mutations/assortments/removeAssortmentMedia.js.map +1 -1
  59. package/lib/resolvers/mutations/assortments/reorderAssortmentFilters.js +1 -1
  60. package/lib/resolvers/mutations/assortments/reorderAssortmentFilters.js.map +1 -1
  61. package/lib/resolvers/mutations/assortments/reorderAssortmentLinks.js +1 -1
  62. package/lib/resolvers/mutations/assortments/reorderAssortmentLinks.js.map +1 -1
  63. package/lib/resolvers/mutations/assortments/reorderAssortmentMedia.js +1 -1
  64. package/lib/resolvers/mutations/assortments/reorderAssortmentMedia.js.map +1 -1
  65. package/lib/resolvers/mutations/assortments/reorderAssortmentProducts.js +1 -1
  66. package/lib/resolvers/mutations/assortments/reorderAssortmentProducts.js.map +1 -1
  67. package/lib/resolvers/mutations/assortments/setBaseAssortment.js +1 -1
  68. package/lib/resolvers/mutations/assortments/setBaseAssortment.js.map +1 -1
  69. package/lib/resolvers/mutations/assortments/updateAssortment.js +1 -1
  70. package/lib/resolvers/mutations/assortments/updateAssortment.js.map +1 -1
  71. package/lib/resolvers/mutations/assortments/updateAssortmentMediaTexts.js +1 -1
  72. package/lib/resolvers/mutations/assortments/updateAssortmentMediaTexts.js.map +1 -1
  73. package/lib/resolvers/mutations/assortments/updateAssortmentTexts.js +1 -1
  74. package/lib/resolvers/mutations/assortments/updateAssortmentTexts.js.map +1 -1
  75. package/lib/resolvers/mutations/bookmarks/bookmark.js +2 -2
  76. package/lib/resolvers/mutations/bookmarks/bookmark.js.map +1 -1
  77. package/lib/resolvers/mutations/bookmarks/createBookmark.js +1 -1
  78. package/lib/resolvers/mutations/bookmarks/createBookmark.js.map +1 -1
  79. package/lib/resolvers/mutations/countries/createCountry.js +1 -2
  80. package/lib/resolvers/mutations/countries/createCountry.js.map +1 -1
  81. package/lib/resolvers/mutations/countries/removeCountry.js +1 -1
  82. package/lib/resolvers/mutations/countries/removeCountry.js.map +1 -1
  83. package/lib/resolvers/mutations/countries/updateCountry.js +1 -1
  84. package/lib/resolvers/mutations/countries/updateCountry.js.map +1 -1
  85. package/lib/resolvers/mutations/currencies/createCurrency.js +1 -2
  86. package/lib/resolvers/mutations/currencies/createCurrency.js.map +1 -1
  87. package/lib/resolvers/mutations/currencies/removeCurrency.js +1 -1
  88. package/lib/resolvers/mutations/currencies/removeCurrency.js.map +1 -1
  89. package/lib/resolvers/mutations/currencies/updateCurrency.js +1 -1
  90. package/lib/resolvers/mutations/currencies/updateCurrency.js.map +1 -1
  91. package/lib/resolvers/mutations/delivery/createDeliveryProvider.js +1 -2
  92. package/lib/resolvers/mutations/delivery/createDeliveryProvider.js.map +1 -1
  93. package/lib/resolvers/mutations/delivery/removeDeliveryProvider.js +1 -1
  94. package/lib/resolvers/mutations/delivery/removeDeliveryProvider.js.map +1 -1
  95. package/lib/resolvers/mutations/delivery/updateDeliveryProvider.js +1 -1
  96. package/lib/resolvers/mutations/delivery/updateDeliveryProvider.js.map +1 -1
  97. package/lib/resolvers/mutations/enrollments/activateEnrollment.js +1 -1
  98. package/lib/resolvers/mutations/enrollments/activateEnrollment.js.map +1 -1
  99. package/lib/resolvers/mutations/enrollments/terminateEnrollment.js +1 -1
  100. package/lib/resolvers/mutations/enrollments/terminateEnrollment.js.map +1 -1
  101. package/lib/resolvers/mutations/enrollments/updateEnrollment.js +5 -5
  102. package/lib/resolvers/mutations/enrollments/updateEnrollment.js.map +1 -1
  103. package/lib/resolvers/mutations/filters/createFilter.js +1 -2
  104. package/lib/resolvers/mutations/filters/createFilter.js.map +1 -1
  105. package/lib/resolvers/mutations/filters/createFilterOption.js +1 -1
  106. package/lib/resolvers/mutations/filters/createFilterOption.js.map +1 -1
  107. package/lib/resolvers/mutations/filters/removeFilter.d.ts +1 -1
  108. package/lib/resolvers/mutations/filters/removeFilter.js +3 -3
  109. package/lib/resolvers/mutations/filters/removeFilter.js.map +1 -1
  110. package/lib/resolvers/mutations/filters/updateFilter.js +1 -1
  111. package/lib/resolvers/mutations/filters/updateFilter.js.map +1 -1
  112. package/lib/resolvers/mutations/filters/updateFilterTexts.js +1 -1
  113. package/lib/resolvers/mutations/filters/updateFilterTexts.js.map +1 -1
  114. package/lib/resolvers/mutations/index.d.ts +1 -0
  115. package/lib/resolvers/mutations/index.js +2 -0
  116. package/lib/resolvers/mutations/index.js.map +1 -1
  117. package/lib/resolvers/mutations/languages/createLanguage.js +1 -2
  118. package/lib/resolvers/mutations/languages/createLanguage.js.map +1 -1
  119. package/lib/resolvers/mutations/languages/removeLanguage.js +1 -1
  120. package/lib/resolvers/mutations/languages/removeLanguage.js.map +1 -1
  121. package/lib/resolvers/mutations/languages/updateLanguage.js +1 -1
  122. package/lib/resolvers/mutations/languages/updateLanguage.js.map +1 -1
  123. package/lib/resolvers/mutations/orders/createCart.js +1 -1
  124. package/lib/resolvers/mutations/orders/createCart.js.map +1 -1
  125. package/lib/resolvers/mutations/orders/payOrder.js +1 -1
  126. package/lib/resolvers/mutations/orders/payOrder.js.map +1 -1
  127. package/lib/resolvers/mutations/orders/removeOrder.js +1 -1
  128. package/lib/resolvers/mutations/orders/removeOrder.js.map +1 -1
  129. package/lib/resolvers/mutations/payment/createPaymentProvider.js +1 -2
  130. package/lib/resolvers/mutations/payment/createPaymentProvider.js.map +1 -1
  131. package/lib/resolvers/mutations/payment/registerPaymentCredentials.js +2 -2
  132. package/lib/resolvers/mutations/payment/registerPaymentCredentials.js.map +1 -1
  133. package/lib/resolvers/mutations/payment/removePaymentProvider.js +1 -1
  134. package/lib/resolvers/mutations/payment/removePaymentProvider.js.map +1 -1
  135. package/lib/resolvers/mutations/payment/updatePaymentProvider.js +1 -1
  136. package/lib/resolvers/mutations/payment/updatePaymentProvider.js.map +1 -1
  137. package/lib/resolvers/mutations/products/addProductAssignment.js +1 -1
  138. package/lib/resolvers/mutations/products/addProductAssignment.js.map +1 -1
  139. package/lib/resolvers/mutations/products/addProductMedia.js +1 -2
  140. package/lib/resolvers/mutations/products/addProductMedia.js.map +1 -1
  141. package/lib/resolvers/mutations/products/addProductReviewVote.js +1 -1
  142. package/lib/resolvers/mutations/products/addProductReviewVote.js.map +1 -1
  143. package/lib/resolvers/mutations/products/createProduct.js +1 -2
  144. package/lib/resolvers/mutations/products/createProduct.js.map +1 -1
  145. package/lib/resolvers/mutations/products/createProductBundleItem.js +1 -1
  146. package/lib/resolvers/mutations/products/createProductBundleItem.js.map +1 -1
  147. package/lib/resolvers/mutations/products/createProductReview.js +1 -1
  148. package/lib/resolvers/mutations/products/createProductReview.js.map +1 -1
  149. package/lib/resolvers/mutations/products/createProductVariation.js +1 -2
  150. package/lib/resolvers/mutations/products/createProductVariation.js.map +1 -1
  151. package/lib/resolvers/mutations/products/createProductVariationOption.js +4 -1
  152. package/lib/resolvers/mutations/products/createProductVariationOption.js.map +1 -1
  153. package/lib/resolvers/mutations/products/prepareProductMediaUpload.js +0 -1
  154. package/lib/resolvers/mutations/products/prepareProductMediaUpload.js.map +1 -1
  155. package/lib/resolvers/mutations/products/publishProduct.js +1 -1
  156. package/lib/resolvers/mutations/products/publishProduct.js.map +1 -1
  157. package/lib/resolvers/mutations/products/removeBundleItem.js +2 -2
  158. package/lib/resolvers/mutations/products/removeBundleItem.js.map +1 -1
  159. package/lib/resolvers/mutations/products/removeProduct.js +14 -2
  160. package/lib/resolvers/mutations/products/removeProduct.js.map +1 -1
  161. package/lib/resolvers/mutations/products/removeProductAssignment.js +1 -1
  162. package/lib/resolvers/mutations/products/removeProductAssignment.js.map +1 -1
  163. package/lib/resolvers/mutations/products/removeProductMedia.js +2 -2
  164. package/lib/resolvers/mutations/products/removeProductMedia.js.map +1 -1
  165. package/lib/resolvers/mutations/products/removeProductReview.js +1 -1
  166. package/lib/resolvers/mutations/products/removeProductReview.js.map +1 -1
  167. package/lib/resolvers/mutations/products/removeProductReviewVote.js +1 -1
  168. package/lib/resolvers/mutations/products/removeProductReviewVote.js.map +1 -1
  169. package/lib/resolvers/mutations/products/removeProductVariation.js +1 -1
  170. package/lib/resolvers/mutations/products/removeProductVariation.js.map +1 -1
  171. package/lib/resolvers/mutations/products/removeProductVariationOption.js +1 -1
  172. package/lib/resolvers/mutations/products/removeProductVariationOption.js.map +1 -1
  173. package/lib/resolvers/mutations/products/reorderProductMedia.js +1 -1
  174. package/lib/resolvers/mutations/products/reorderProductMedia.js.map +1 -1
  175. package/lib/resolvers/mutations/products/unpublishProduct.js +1 -1
  176. package/lib/resolvers/mutations/products/unpublishProduct.js.map +1 -1
  177. package/lib/resolvers/mutations/products/updateProduct.js +1 -1
  178. package/lib/resolvers/mutations/products/updateProduct.js.map +1 -1
  179. package/lib/resolvers/mutations/products/updateProductCommerce.js +1 -1
  180. package/lib/resolvers/mutations/products/updateProductCommerce.js.map +1 -1
  181. package/lib/resolvers/mutations/products/updateProductMediaTexts.js +1 -1
  182. package/lib/resolvers/mutations/products/updateProductMediaTexts.js.map +1 -1
  183. package/lib/resolvers/mutations/products/updateProductPlan.js +1 -1
  184. package/lib/resolvers/mutations/products/updateProductPlan.js.map +1 -1
  185. package/lib/resolvers/mutations/products/updateProductReview.js +1 -1
  186. package/lib/resolvers/mutations/products/updateProductReview.js.map +1 -1
  187. package/lib/resolvers/mutations/products/updateProductSupply.js +1 -1
  188. package/lib/resolvers/mutations/products/updateProductSupply.js.map +1 -1
  189. package/lib/resolvers/mutations/products/updateProductTexts.js +1 -1
  190. package/lib/resolvers/mutations/products/updateProductTexts.js.map +1 -1
  191. package/lib/resolvers/mutations/products/updateProductTokenization.js +1 -1
  192. package/lib/resolvers/mutations/products/updateProductTokenization.js.map +1 -1
  193. package/lib/resolvers/mutations/products/updateProductVariationTexts.js +1 -1
  194. package/lib/resolvers/mutations/products/updateProductVariationTexts.js.map +1 -1
  195. package/lib/resolvers/mutations/products/updateProductWarehousing.js +1 -1
  196. package/lib/resolvers/mutations/products/updateProductWarehousing.js.map +1 -1
  197. package/lib/resolvers/mutations/users/prepareUserAvatarUpload.js +0 -1
  198. package/lib/resolvers/mutations/users/prepareUserAvatarUpload.js.map +1 -1
  199. package/lib/resolvers/mutations/users/removeUser.d.ts +4 -0
  200. package/lib/resolvers/mutations/users/removeUser.js +11 -0
  201. package/lib/resolvers/mutations/users/removeUser.js.map +1 -0
  202. package/lib/resolvers/mutations/users/setRoles.js +1 -1
  203. package/lib/resolvers/mutations/users/setRoles.js.map +1 -1
  204. package/lib/resolvers/mutations/users/setUserTags.js +1 -1
  205. package/lib/resolvers/mutations/users/setUserTags.js.map +1 -1
  206. package/lib/resolvers/mutations/users/updateUserAvatar.js +1 -2
  207. package/lib/resolvers/mutations/users/updateUserAvatar.js.map +1 -1
  208. package/lib/resolvers/mutations/users/updateUserProfile.js +1 -1
  209. package/lib/resolvers/mutations/users/updateUserProfile.js.map +1 -1
  210. package/lib/resolvers/mutations/utils/getOrderCart.js +1 -1
  211. package/lib/resolvers/mutations/utils/getOrderCart.js.map +1 -1
  212. package/lib/resolvers/mutations/warehousing/createWarehousingProvider.js +1 -2
  213. package/lib/resolvers/mutations/warehousing/createWarehousingProvider.js.map +1 -1
  214. package/lib/resolvers/mutations/warehousing/removeWarehousingProvider.js +1 -1
  215. package/lib/resolvers/mutations/warehousing/removeWarehousingProvider.js.map +1 -1
  216. package/lib/resolvers/mutations/warehousing/updateWarehousingProvider.js +1 -1
  217. package/lib/resolvers/mutations/warehousing/updateWarehousingProvider.js.map +1 -1
  218. package/lib/resolvers/mutations/worker/addWork.js +1 -1
  219. package/lib/resolvers/mutations/worker/addWork.js.map +1 -1
  220. package/lib/resolvers/mutations/worker/finishWork.js +1 -1
  221. package/lib/resolvers/mutations/worker/finishWork.js.map +1 -1
  222. package/lib/resolvers/mutations/worker/removeWork.js +1 -1
  223. package/lib/resolvers/mutations/worker/removeWork.js.map +1 -1
  224. package/lib/resolvers/queries/products/productCatalogPrices.js +0 -1
  225. package/lib/resolvers/queries/products/productCatalogPrices.js.map +1 -1
  226. package/lib/resolvers/queries/users/users.d.ts +2 -1
  227. package/lib/resolvers/queries/users/users.js.map +1 -1
  228. package/lib/resolvers/queries/worker/workQueue.d.ts +1 -1
  229. package/lib/resolvers/queries/worker/workQueue.js +1 -1
  230. package/lib/resolvers/queries/worker/workQueue.js.map +1 -1
  231. package/lib/resolvers/type/assortment/assortment-filter-types.js +0 -1
  232. package/lib/resolvers/type/assortment/assortment-filter-types.js.map +1 -1
  233. package/lib/resolvers/type/assortment/assortment-link-types.js +0 -2
  234. package/lib/resolvers/type/assortment/assortment-link-types.js.map +1 -1
  235. package/lib/resolvers/type/assortment/assortment-media-types.js +2 -0
  236. package/lib/resolvers/type/assortment/assortment-media-types.js.map +1 -1
  237. package/lib/resolvers/type/assortment/assortment-path-link-types.js +1 -0
  238. package/lib/resolvers/type/assortment/assortment-path-link-types.js.map +1 -1
  239. package/lib/resolvers/type/assortment/assortment-product-types.js +0 -2
  240. package/lib/resolvers/type/assortment/assortment-product-types.js.map +1 -1
  241. package/lib/resolvers/type/assortment/assortment-types.js +8 -4
  242. package/lib/resolvers/type/assortment/assortment-types.js.map +1 -1
  243. package/lib/resolvers/type/bookmark-types.js +0 -1
  244. package/lib/resolvers/type/bookmark-types.js.map +1 -1
  245. package/lib/resolvers/type/enrollment/enrollment-plan-tyes.js +0 -1
  246. package/lib/resolvers/type/enrollment/enrollment-plan-tyes.js.map +1 -1
  247. package/lib/resolvers/type/index.d.ts +1 -0
  248. package/lib/resolvers/type/login-method-response-types.d.ts +1 -0
  249. package/lib/resolvers/type/order/order-item-types.js +0 -3
  250. package/lib/resolvers/type/order/order-item-types.js.map +1 -1
  251. package/lib/resolvers/type/product/product-assortment-path-types.js +1 -0
  252. package/lib/resolvers/type/product/product-assortment-path-types.js.map +1 -1
  253. package/lib/resolvers/type/product/product-bundle-item-types.js +0 -1
  254. package/lib/resolvers/type/product/product-bundle-item-types.js.map +1 -1
  255. package/lib/resolvers/type/product/product-configurable-types.js +1 -0
  256. package/lib/resolvers/type/product/product-configurable-types.js.map +1 -1
  257. package/lib/resolvers/type/product/product-media-types.js +2 -0
  258. package/lib/resolvers/type/product/product-media-types.js.map +1 -1
  259. package/lib/resolvers/type/product/product-plan-types.js +1 -12
  260. package/lib/resolvers/type/product/product-plan-types.js.map +1 -1
  261. package/lib/resolvers/type/product/product-review-types.js +0 -1
  262. package/lib/resolvers/type/product/product-review-types.js.map +1 -1
  263. package/lib/resolvers/type/product/product-variation-assignment-types.js +0 -1
  264. package/lib/resolvers/type/product/product-variation-assignment-types.js.map +1 -1
  265. package/lib/resolvers/type/quotation-types.js +0 -1
  266. package/lib/resolvers/type/quotation-types.js.map +1 -1
  267. package/lib/resolvers/type/token-types.js +2 -1
  268. package/lib/resolvers/type/token-types.js.map +1 -1
  269. package/lib/resolvers/type/user-types.d.ts +3 -0
  270. package/lib/resolvers/type/user-types.js +10 -9
  271. package/lib/resolvers/type/user-types.js.map +1 -1
  272. package/lib/roles/admin.js +3 -72
  273. package/lib/roles/admin.js.map +1 -1
  274. package/lib/schema/mutation.js +20 -15
  275. package/lib/schema/mutation.js.map +1 -1
  276. package/lib/schema/query.js +14 -12
  277. package/lib/schema/query.js.map +1 -1
  278. package/lib/schema/types/assortment.js +1 -0
  279. package/lib/schema/types/assortment.js.map +1 -1
  280. package/lib/schema/types/dispatch.js +0 -1
  281. package/lib/schema/types/dispatch.js.map +1 -1
  282. package/lib/schema/types/product/plan-product.js +0 -1
  283. package/lib/schema/types/product/plan-product.js.map +1 -1
  284. package/lib/schema/types/product/simple-product.js +0 -1
  285. package/lib/schema/types/product/simple-product.js.map +1 -1
  286. package/lib/schema/types/product/tokenized-product.js +0 -1
  287. package/lib/schema/types/product/tokenized-product.js.map +1 -1
  288. package/lib/schema/types/stock.js +0 -1
  289. package/lib/schema/types/stock.js.map +1 -1
  290. package/lib/schema/types/user.js +3 -0
  291. package/lib/schema/types/user.js.map +1 -1
  292. package/package.json +12 -11
  293. package/src/acl.ts +2 -2
  294. package/src/api-index.ts +1 -1
  295. package/src/createGraphQLServer.ts +13 -24
  296. package/src/errors.ts +85 -0
  297. package/src/express/createBulkImportMiddleware.ts +6 -9
  298. package/src/express/createERCMetadataMiddleware.ts +2 -1
  299. package/src/express/createSingleSignOnMiddleware.ts +3 -2
  300. package/src/loaders/index.ts +27 -35
  301. package/src/resolvers/mutations/accounts/changePassword.ts +9 -2
  302. package/src/resolvers/mutations/accounts/createUser.ts +19 -4
  303. package/src/resolvers/mutations/accounts/disableTOTP.ts +13 -3
  304. package/src/resolvers/mutations/accounts/enableTOTP.ts +9 -2
  305. package/src/resolvers/mutations/accounts/enrollUser.ts +19 -4
  306. package/src/resolvers/mutations/accounts/forgotPassword.ts +8 -1
  307. package/src/resolvers/mutations/accounts/impersonate.ts +1 -1
  308. package/src/resolvers/mutations/accounts/loginWithPassword.ts +24 -1
  309. package/src/resolvers/mutations/accounts/loginWithWebAuthn.ts +13 -2
  310. package/src/resolvers/mutations/accounts/logout.ts +9 -2
  311. package/src/resolvers/mutations/accounts/logoutAllSessions.ts +7 -1
  312. package/src/resolvers/mutations/accounts/resetPassword.ts +19 -3
  313. package/src/resolvers/mutations/assortments/addAssortmentFilter.ts +5 -9
  314. package/src/resolvers/mutations/assortments/addAssortmentLink.ts +22 -14
  315. package/src/resolvers/mutations/assortments/addAssortmentMedia.ts +2 -6
  316. package/src/resolvers/mutations/assortments/addAssortmentProduct.ts +0 -2
  317. package/src/resolvers/mutations/assortments/createAssortment.ts +4 -8
  318. package/src/resolvers/mutations/assortments/prepareAssortmentMediaUpload.ts +0 -1
  319. package/src/resolvers/mutations/assortments/removeAssortmentMedia.ts +2 -2
  320. package/src/resolvers/mutations/assortments/reorderAssortmentFilters.ts +3 -6
  321. package/src/resolvers/mutations/assortments/reorderAssortmentLinks.ts +0 -1
  322. package/src/resolvers/mutations/assortments/reorderAssortmentMedia.ts +3 -6
  323. package/src/resolvers/mutations/assortments/reorderAssortmentProducts.ts +0 -1
  324. package/src/resolvers/mutations/assortments/setBaseAssortment.ts +1 -1
  325. package/src/resolvers/mutations/assortments/updateAssortment.ts +1 -1
  326. package/src/resolvers/mutations/assortments/updateAssortmentMediaTexts.ts +1 -1
  327. package/src/resolvers/mutations/assortments/updateAssortmentTexts.ts +1 -1
  328. package/src/resolvers/mutations/bookmarks/bookmark.ts +4 -7
  329. package/src/resolvers/mutations/bookmarks/createBookmark.ts +4 -7
  330. package/src/resolvers/mutations/countries/createCountry.ts +3 -7
  331. package/src/resolvers/mutations/countries/removeCountry.ts +1 -1
  332. package/src/resolvers/mutations/countries/updateCountry.ts +1 -1
  333. package/src/resolvers/mutations/currencies/createCurrency.ts +3 -7
  334. package/src/resolvers/mutations/currencies/removeCurrency.ts +1 -1
  335. package/src/resolvers/mutations/currencies/updateCurrency.ts +1 -1
  336. package/src/resolvers/mutations/delivery/createDeliveryProvider.ts +3 -7
  337. package/src/resolvers/mutations/delivery/removeDeliveryProvider.ts +1 -1
  338. package/src/resolvers/mutations/delivery/updateDeliveryProvider.ts +1 -1
  339. package/src/resolvers/mutations/enrollments/activateEnrollment.ts +1 -1
  340. package/src/resolvers/mutations/enrollments/terminateEnrollment.ts +1 -1
  341. package/src/resolvers/mutations/enrollments/updateEnrollment.ts +5 -5
  342. package/src/resolvers/mutations/filters/createFilter.ts +0 -2
  343. package/src/resolvers/mutations/filters/createFilterOption.ts +5 -1
  344. package/src/resolvers/mutations/filters/removeFilter.ts +3 -3
  345. package/src/resolvers/mutations/filters/updateFilter.ts +1 -1
  346. package/src/resolvers/mutations/filters/updateFilterTexts.ts +1 -1
  347. package/src/resolvers/mutations/index.ts +2 -0
  348. package/src/resolvers/mutations/languages/createLanguage.ts +3 -7
  349. package/src/resolvers/mutations/languages/removeLanguage.ts +1 -1
  350. package/src/resolvers/mutations/languages/updateLanguage.ts +1 -1
  351. package/src/resolvers/mutations/orders/createCart.ts +4 -1
  352. package/src/resolvers/mutations/orders/payOrder.ts +1 -1
  353. package/src/resolvers/mutations/orders/removeOrder.ts +1 -1
  354. package/src/resolvers/mutations/payment/createPaymentProvider.ts +3 -7
  355. package/src/resolvers/mutations/payment/registerPaymentCredentials.ts +6 -2
  356. package/src/resolvers/mutations/payment/removePaymentProvider.ts +1 -1
  357. package/src/resolvers/mutations/payment/updatePaymentProvider.ts +1 -1
  358. package/src/resolvers/mutations/products/addProductAssignment.ts +4 -8
  359. package/src/resolvers/mutations/products/addProductMedia.ts +1 -2
  360. package/src/resolvers/mutations/products/addProductReviewVote.ts +1 -1
  361. package/src/resolvers/mutations/products/createProduct.ts +4 -8
  362. package/src/resolvers/mutations/products/createProductBundleItem.ts +1 -1
  363. package/src/resolvers/mutations/products/createProductReview.ts +5 -8
  364. package/src/resolvers/mutations/products/createProductVariation.ts +6 -10
  365. package/src/resolvers/mutations/products/createProductVariationOption.ts +4 -5
  366. package/src/resolvers/mutations/products/prepareProductMediaUpload.ts +0 -1
  367. package/src/resolvers/mutations/products/publishProduct.ts +1 -1
  368. package/src/resolvers/mutations/products/removeBundleItem.ts +2 -2
  369. package/src/resolvers/mutations/products/removeProduct.ts +23 -2
  370. package/src/resolvers/mutations/products/removeProductAssignment.ts +1 -1
  371. package/src/resolvers/mutations/products/removeProductMedia.ts +2 -2
  372. package/src/resolvers/mutations/products/removeProductReview.ts +1 -1
  373. package/src/resolvers/mutations/products/removeProductReviewVote.ts +1 -1
  374. package/src/resolvers/mutations/products/removeProductVariation.ts +1 -1
  375. package/src/resolvers/mutations/products/removeProductVariationOption.ts +0 -1
  376. package/src/resolvers/mutations/products/reorderProductMedia.ts +1 -1
  377. package/src/resolvers/mutations/products/unpublishProduct.ts +1 -1
  378. package/src/resolvers/mutations/products/updateProduct.ts +1 -1
  379. package/src/resolvers/mutations/products/updateProductCommerce.ts +1 -1
  380. package/src/resolvers/mutations/products/updateProductMediaTexts.ts +1 -1
  381. package/src/resolvers/mutations/products/updateProductPlan.ts +1 -1
  382. package/src/resolvers/mutations/products/updateProductReview.ts +1 -1
  383. package/src/resolvers/mutations/products/updateProductSupply.ts +1 -1
  384. package/src/resolvers/mutations/products/updateProductTexts.ts +1 -1
  385. package/src/resolvers/mutations/products/updateProductTokenization.ts +1 -1
  386. package/src/resolvers/mutations/products/updateProductVariationTexts.ts +0 -1
  387. package/src/resolvers/mutations/products/updateProductWarehousing.ts +1 -1
  388. package/src/resolvers/mutations/users/prepareUserAvatarUpload.ts +0 -1
  389. package/src/resolvers/mutations/users/removeUser.ts +19 -0
  390. package/src/resolvers/mutations/users/setRoles.ts +1 -1
  391. package/src/resolvers/mutations/users/setUserTags.ts +1 -1
  392. package/src/resolvers/mutations/users/updateUserAvatar.ts +1 -2
  393. package/src/resolvers/mutations/users/updateUserProfile.ts +1 -1
  394. package/src/resolvers/mutations/utils/getOrderCart.ts +1 -1
  395. package/src/resolvers/mutations/warehousing/createWarehousingProvider.ts +3 -7
  396. package/src/resolvers/mutations/warehousing/removeWarehousingProvider.ts +1 -1
  397. package/src/resolvers/mutations/warehousing/updateWarehousingProvider.ts +1 -1
  398. package/src/resolvers/mutations/worker/addWork.ts +1 -1
  399. package/src/resolvers/mutations/worker/finishWork.ts +8 -12
  400. package/src/resolvers/mutations/worker/removeWork.ts +1 -1
  401. package/src/resolvers/queries/products/productCatalogPrices.ts +0 -1
  402. package/src/resolvers/queries/users/users.ts +2 -1
  403. package/src/resolvers/queries/worker/workQueue.ts +1 -1
  404. package/src/resolvers/type/assortment/assortment-filter-types.ts +0 -1
  405. package/src/resolvers/type/assortment/assortment-link-types.ts +0 -2
  406. package/src/resolvers/type/assortment/assortment-media-types.ts +2 -0
  407. package/src/resolvers/type/assortment/assortment-path-link-types.ts +1 -0
  408. package/src/resolvers/type/assortment/assortment-product-types.ts +0 -2
  409. package/src/resolvers/type/assortment/assortment-types.ts +9 -4
  410. package/src/resolvers/type/bookmark-types.ts +0 -1
  411. package/src/resolvers/type/enrollment/enrollment-plan-tyes.ts +0 -1
  412. package/src/resolvers/type/order/order-item-types.ts +0 -3
  413. package/src/resolvers/type/product/product-assortment-path-types.ts +1 -0
  414. package/src/resolvers/type/product/product-bundle-item-types.ts +0 -1
  415. package/src/resolvers/type/product/product-configurable-types.ts +1 -0
  416. package/src/resolvers/type/product/product-media-types.ts +2 -0
  417. package/src/resolvers/type/product/product-plan-types.ts +2 -18
  418. package/src/resolvers/type/product/product-review-types.ts +0 -1
  419. package/src/resolvers/type/product/product-variation-assignment-types.ts +0 -1
  420. package/src/resolvers/type/quotation-types.ts +0 -1
  421. package/src/resolvers/type/token-types.ts +2 -1
  422. package/src/resolvers/type/user-types.ts +14 -10
  423. package/src/roles/admin.ts +3 -72
  424. package/src/schema/mutation.js +20 -15
  425. package/src/schema/query.js +14 -12
  426. package/src/schema/types/assortment.js +1 -0
  427. package/src/schema/types/dispatch.js +0 -1
  428. package/src/schema/types/product/plan-product.js +0 -1
  429. package/src/schema/types/product/simple-product.js +0 -1
  430. package/src/schema/types/product/tokenized-product.js +0 -1
  431. package/src/schema/types/stock.js +0 -1
  432. package/src/schema/types/user.js +3 -0
  433. package/tests/api-index.test.ts +78 -0
@@ -86,6 +86,9 @@ export default [
86
86
 
87
87
  type User {
88
88
  _id: ID!
89
+ created: DateTime!
90
+ updated: DateTime
91
+ deleted: DateTime
89
92
  username: String
90
93
  isGuest: Boolean!
91
94
  isTwoFactorEnabled: Boolean!
@@ -1 +1 @@
1
- {"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/schema/types/user.js"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkHb;CACF,CAAC"}
1
+ {"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/schema/types/user.js"],"names":[],"mappings":"AAAA,eAAe;IACb,aAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqHb;CACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/api",
3
- "version": "2.0.0-beta8",
3
+ "version": "2.0.0-beta9",
4
4
  "main": "lib/api-index.js",
5
5
  "exports": {
6
6
  ".": "./lib/api-index.js",
@@ -21,7 +21,8 @@
21
21
  "clean": "rm -rf lib",
22
22
  "build": "npm run clean && tsc",
23
23
  "watch": "tsc -w",
24
- "test": "jest --watch"
24
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --forceExit",
25
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --detectOpenHandles --forceExit"
25
26
  },
26
27
  "repository": {
27
28
  "type": "git",
@@ -39,7 +40,7 @@
39
40
  },
40
41
  "homepage": "https://github.com/unchainedshop/unchained#readme",
41
42
  "peerDependencies": {
42
- "@apollo/server": "^4.2.1",
43
+ "@apollo/server": "^4.2.2",
43
44
  "cookie": "^0.5.0",
44
45
  "graphql": "^16.6.0"
45
46
  },
@@ -48,11 +49,11 @@
48
49
  },
49
50
  "dependencies": {
50
51
  "@metamask/eth-sig-util": "^5.0.2",
51
- "@unchainedshop/core": "^2.0.0-beta8",
52
- "@unchainedshop/events": "^2.0.0-beta8",
53
- "@unchainedshop/logger": "^2.0.0-beta8",
54
- "@unchainedshop/roles": "^2.0.0-beta8",
55
- "@unchainedshop/utils": "^2.0.0-beta8",
52
+ "@unchainedshop/core": "^2.0.0-beta9",
53
+ "@unchainedshop/events": "^2.0.0-beta9",
54
+ "@unchainedshop/logger": "^2.0.0-beta9",
55
+ "@unchainedshop/roles": "^2.0.0-beta9",
56
+ "@unchainedshop/utils": "^2.0.0-beta9",
56
57
  "accounting": "0.4.1",
57
58
  "dataloader": "^2.1.0",
58
59
  "graphql-scalars": "^1.20.1",
@@ -64,12 +65,12 @@
64
65
  "devDependencies": {
65
66
  "@types/graphql-upload": "^8.0.12",
66
67
  "@types/locale": "^0.1.1",
67
- "@types/node": "^18.11.9",
68
- "@unchainedshop/types": "^2.0.0-beta8",
68
+ "@types/node": "^18.11.12",
69
+ "@unchainedshop/types": "^2.0.0-beta9",
69
70
  "express": "^4.18.2",
70
71
  "graphql": "^16.6.0",
71
72
  "jest": "^29.3.1",
72
73
  "ts-jest": "^29.0.3",
73
- "typescript": "^4.9.3"
74
+ "typescript": "^4.9.4"
74
75
  }
75
76
  }
package/src/acl.ts CHANGED
@@ -10,13 +10,13 @@ const defaultOptions = {
10
10
  const emptyObject = {};
11
11
  const emptyArray: CheckPermissionArgs = [];
12
12
 
13
- const ensureActionExists = (action, userOptions) => {
13
+ export const ensureActionExists = (action, userOptions) => {
14
14
  if (!action) {
15
15
  throw new PermissionSystemError({ userOptions });
16
16
  }
17
17
  };
18
18
 
19
- const ensureIsFunction = (fn, action, options, key) => {
19
+ export const ensureIsFunction = (fn, action, options, key) => {
20
20
  if (typeof fn !== 'function') {
21
21
  throw new PermissionSystemError({
22
22
  action,
package/src/api-index.ts CHANGED
@@ -13,7 +13,7 @@ export { hashPassword } from './hashPassword';
13
13
  export * as roles from './roles';
14
14
  export { createContextResolver, getCurrentContextResolver, setCurrentContextResolver };
15
15
 
16
- const loadJSON = (filename) => {
16
+ export const loadJSON = (filename) => {
17
17
  try {
18
18
  const base = typeof __filename !== 'undefined' && __filename;
19
19
  if (!base)
@@ -1,27 +1,30 @@
1
1
  import { ApolloServer } from '@apollo/server';
2
- import { GraphQLError } from 'graphql';
3
2
  import { log, LogLevel } from '@unchainedshop/logger';
3
+ import { GraphQLFormattedError } from 'graphql';
4
4
  import typeDefs from './schema';
5
5
  import resolvers from './resolvers';
6
6
 
7
7
  const { APOLLO_ENGINE_KEY } = process.env;
8
8
 
9
- const logGraphQLServerError = (error) => {
9
+ const logGraphQLServerError = (error: GraphQLFormattedError) => {
10
10
  try {
11
11
  const {
12
12
  message,
13
- extensions: {
14
- exception: { stacktrace, ...parameters },
15
- ...extensions
16
- },
13
+ extensions: { stacktrace, ...parameters },
17
14
  ...rest
18
15
  } = error;
19
- log(`${message} ${extensions && extensions.code}`, {
16
+ log(`${message} ${parameters && parameters.code}`, {
20
17
  level: LogLevel.Error,
21
- ...extensions,
18
+ ...parameters,
22
19
  ...rest,
23
20
  });
24
- console.error(stacktrace, parameters); // eslint-disable-line
21
+ if (stacktrace && process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
22
+ const nativeError = new Error(message);
23
+ nativeError.stack = (stacktrace as string[]).join('\n');
24
+ nativeError.name = parameters.code as string;
25
+ // eslint-disable-next-line
26
+ console.error(nativeError);
27
+ }
25
28
  } catch (e) {} // eslint-disable-line
26
29
  };
27
30
 
@@ -38,21 +41,7 @@ export default async (options) => {
38
41
  resolvers: [resolvers, ...additionalResolvers],
39
42
  formatError: (error) => {
40
43
  logGraphQLServerError(error);
41
- const {
42
- message,
43
- path,
44
- extensions: { exception, code, ...extensions }, // eslint-disable-line
45
- } = error;
46
- const apolloError = new GraphQLError(message, {
47
- extensions: {
48
- code,
49
- ...extensions,
50
- },
51
- });
52
- // eslint-disable-next-line
53
- // @ts-ignore
54
- apolloError.path = path;
55
- return apolloError;
44
+ return error;
56
45
  },
57
46
  apollo: APOLLO_ENGINE_KEY
58
47
  ? {
package/src/errors.ts CHANGED
@@ -202,3 +202,88 @@ export const TokenWrongStatusError = createError(
202
202
  'TokenWrongStatusError',
203
203
  'The current status of the token does not allow this operation',
204
204
  );
205
+
206
+ export const CyclicAssortmentLinkNotSupportedError = createError(
207
+ 'CyclicAssortmentLinkNotSupported',
208
+ 'Cyclic assortment link detected, make sure child assortment is not assigned as a parent on the assortment graph',
209
+ );
210
+
211
+ export const EmailAlreadyExistsError = createError(
212
+ 'EmailAlreadyExists',
213
+ 'Email already exist in the database',
214
+ );
215
+
216
+ export const UsernameAlreadyExistsError = createError(
217
+ 'UsernameAlreadyExists',
218
+ 'Username already exist in the database',
219
+ );
220
+
221
+ export const UsernameOrEmailRequiredError = createError(
222
+ 'UsernameOrEmailRequired',
223
+ 'No username or email is provided.',
224
+ );
225
+
226
+ export const TwoFactorCodeDidNotMatchError = createError(
227
+ 'TwoFactorCodeDidNotMatch',
228
+ "2FA code didn't match",
229
+ );
230
+
231
+ export const TwoFactorCodeRequiredError = createError('TwoFactorCodeRequired', '2FA code required');
232
+
233
+ export const TwoFactorAlreadySetError = createError('TwoFactorAlreadySet', '2FA already set for user');
234
+
235
+ export const TwoFactorNotSetError = createError('TwoFactorNotSet', '2FA not set for user');
236
+
237
+ export const InvalidCredentialsError = createError(
238
+ 'InvalidCredentials',
239
+ 'Incorrect credential provided',
240
+ );
241
+
242
+ export const InvalidResetTokenError = createError('InvalidResetTokenError', 'Token validation failed');
243
+
244
+ export const NoEmailSetError = createError('NoEmailSet', 'User has no email set');
245
+
246
+ export const ResetPasswordLinkExpiredError = createError(
247
+ 'ResetPasswordLinkExpired',
248
+ 'Token does not exist or is expired',
249
+ );
250
+
251
+ export const ResetPasswordLinkUnknownAddressError = createError(
252
+ 'ResetPasswordLinkUnknownAddress',
253
+ 'Valid token but no email address found for the entry',
254
+ );
255
+
256
+ export const AuthenticationFailedError = createError(
257
+ 'AuthenticationFailed',
258
+ 'Failed to authenticate the user',
259
+ );
260
+
261
+ export const UserDeactivatedError = createError(
262
+ 'UserDeactivatedError',
263
+ 'User is deactivated, so not allowed to login',
264
+ );
265
+
266
+ export const AuthOperationFailedError = createError(
267
+ 'AuthOperationFailed',
268
+ 'Operation failed, please make sure you have provided all required parameters',
269
+ );
270
+
271
+ export const ProductLinkedToActiveVariationError = createError(
272
+ 'ProductLinkedToActiveVariation',
273
+ 'Product is part of a active variation, remove it from any active/draft variation before deleting',
274
+ );
275
+
276
+ export const ProductLinkedToActiveBundleError = createError(
277
+ 'ProductLinkedToActiveBundle',
278
+ 'Product is part of a active/draft bundle item, remove it from any active/draft bundle item before deleting',
279
+ );
280
+
281
+ export const ProductLinkedToEnrollmentError = createError(
282
+ 'ProductLinkedToEnrollment',
283
+ 'Product is part of a active/paused subscriptions item, remove it from any active/paused subscriptions item before deleting',
284
+ );
285
+
286
+ export const ProductLinkedToQuotationError = createError(
287
+ 'ProductLinkedToQuotation',
288
+ 'Product is part of a requested/proposed quotations item, remove it from any requested/proposed quotations item before deleting',
289
+ );
@@ -68,15 +68,12 @@ export default function bulkImportMiddleware(contextResolver: UnchainedContextRe
68
68
  input.payloadId = file._id;
69
69
  input.payloadSize = file.length;
70
70
  }
71
- const work = await context.modules.worker.addWork(
72
- {
73
- type: 'BULK_IMPORT',
74
- input: Object.fromEntries(Object.entries(input).filter(([, value]) => Boolean(value))),
75
- retries: 0,
76
- priority: 10,
77
- },
78
- context.userId,
79
- );
71
+ const work = await context.modules.worker.addWork({
72
+ type: 'BULK_IMPORT',
73
+ input: Object.fromEntries(Object.entries(input).filter(([, value]) => Boolean(value))),
74
+ retries: 0,
75
+ priority: 10,
76
+ });
80
77
  res.writeHead(200);
81
78
  res.end(JSON.stringify(work));
82
79
  } catch (e) {
@@ -54,9 +54,10 @@ export default function ercMetadataMiddleware(contextResolver: UnchainedContextR
54
54
  {
55
55
  token,
56
56
  product,
57
+ locale: new Locale(locale),
57
58
  referenceDate: new Date(),
58
59
  },
59
- { ...context, localeContext: new Locale(locale) },
60
+ context,
60
61
  );
61
62
 
62
63
  const body = JSON.stringify(ercMetadata);
@@ -1,14 +1,15 @@
1
1
  /// <reference lib="dom" />
2
2
  import { createLogger } from '@unchainedshop/logger';
3
- import { Context, UnchainedContextResolver } from '@unchainedshop/types/api';
3
+ import { UnchainedContextResolver } from '@unchainedshop/types/api';
4
4
  import { IncomingMessage } from 'http';
5
5
  import cookie from 'cookie';
6
+ import { UnchainedCore } from '@unchainedshop/types/core';
6
7
 
7
8
  const { ROOT_URL, NODE_ENV, UNCHAINED_CLOUD_ENDPOINT } = process.env;
8
9
 
9
10
  const logger = createLogger('unchained:unchained-cloud-sso');
10
11
 
11
- const loginWithSingleSignOn = async (remoteToken, context: Context) => {
12
+ const loginWithSingleSignOn = async (remoteToken, context: UnchainedCore) => {
12
13
  const domain = process.env.UNCHAINED_COOKIE_DOMAIN || new URL(ROOT_URL).hostname || 'localhost';
13
14
  const result = await fetch(UNCHAINED_CLOUD_ENDPOINT, {
14
15
  method: 'POST',
@@ -17,27 +17,22 @@ export default async (
17
17
  unchainedAPI: UnchainedCore,
18
18
  ): Promise<UnchainedLoaders['loaders']> => {
19
19
  return {
20
- assortmentLoader: new DataLoader<{ assortmentId: string; includeInactive: boolean }, Assortment>(
21
- async (queries) => {
22
- const assortmentIds = [...new Set(queries.map((q) => q.assortmentId).filter(Boolean))];
20
+ assortmentLoader: new DataLoader<{ assortmentId: string }, Assortment>(async (queries) => {
21
+ const assortmentIds = [...new Set(queries.map((q) => q.assortmentId).filter(Boolean))];
23
22
 
24
- const assortments = await unchainedAPI.modules.assortments.findAssortments({
25
- assortmentIds,
26
- includeInactive: true,
27
- includeLeaves: true,
28
- });
23
+ const assortments = await unchainedAPI.modules.assortments.findAssortments({
24
+ assortmentIds,
25
+ includeInactive: true,
26
+ includeLeaves: true,
27
+ });
29
28
 
30
- return queries.map(({ assortmentId, includeInactive }) => {
31
- return assortments.find((assortment) => {
32
- if (assortment._id !== assortmentId) return false;
33
- if (!includeInactive) {
34
- return assortment.isActive === true;
35
- }
36
- return true;
37
- });
29
+ return queries.map(({ assortmentId }) => {
30
+ return assortments.find((assortment) => {
31
+ if (assortment._id !== assortmentId) return false;
32
+ return true;
38
33
  });
39
- },
40
- ),
34
+ });
35
+ }),
41
36
 
42
37
  assortmentTextLoader: new DataLoader<{ assortmentId: string; locale: string }, AssortmentText>(
43
38
  async (queries) => {
@@ -118,26 +113,23 @@ export default async (
118
113
  });
119
114
  }),
120
115
 
121
- productLoader: new DataLoader<{ productId: string; includeDrafts: boolean }, Product>(
122
- async (queries) => {
123
- const productIds = [...new Set(queries.map((q) => q.productId).filter(Boolean))];
116
+ productLoader: new DataLoader<{ productId: string }, Product>(async (queries) => {
117
+ const productIds = [...new Set(queries.map((q) => q.productId).filter(Boolean))];
124
118
 
125
- const products = await unchainedAPI.modules.products.findProducts({
126
- productIds,
127
- includeDrafts: true,
128
- });
119
+ const products = await unchainedAPI.modules.products.findProducts({
120
+ productIds,
121
+ productSelector: {
122
+ status: { $in: [null, ProductStatus.ACTIVE, ProductStatus.DELETED] },
123
+ },
124
+ });
129
125
 
130
- return queries.map(({ productId, includeDrafts }) => {
131
- return products.find((product) => {
132
- if (product._id !== productId) return false;
133
- if (!includeDrafts) {
134
- return product.status === ProductStatus.ACTIVE;
135
- }
136
- return true;
137
- });
126
+ return queries.map(({ productId }) => {
127
+ return products.find((product) => {
128
+ if (product._id !== productId) return false;
129
+ return true;
138
130
  });
139
- },
140
- ),
131
+ });
132
+ }),
141
133
 
142
134
  productTextLoader: new DataLoader<{ productId: string; locale: string }, ProductText>(
143
135
  async (queries) => {
@@ -1,5 +1,6 @@
1
1
  import { log } from '@unchainedshop/logger';
2
2
  import { Context, Root } from '@unchainedshop/types/api';
3
+ import { AuthOperationFailedError, InvalidCredentialsError } from '../../../errors';
3
4
 
4
5
  export default async function changePassword(
5
6
  root: Root,
@@ -17,8 +18,14 @@ export default async function changePassword(
17
18
  if (!params.oldPlainPassword) {
18
19
  throw new Error('Old password is required');
19
20
  }
20
-
21
- const success = await modules.accounts.changePassword(userId, params);
21
+ let success = false;
22
+ try {
23
+ success = await modules.accounts.changePassword(userId, params);
24
+ } catch (e) {
25
+ success = false;
26
+ if (e.code === 'InvalidCredentials') throw new InvalidCredentialsError({});
27
+ else throw new AuthOperationFailedError({});
28
+ }
22
29
 
23
30
  return { success };
24
31
  }
@@ -2,6 +2,12 @@ import { UserData } from '@unchainedshop/types/accounts';
2
2
  import { Context, Root } from '@unchainedshop/types/api';
3
3
  import { log } from '@unchainedshop/logger';
4
4
  import { hashPassword } from '../../../hashPassword';
5
+ import {
6
+ AuthOperationFailedError,
7
+ EmailAlreadyExistsError,
8
+ UsernameAlreadyExistsError,
9
+ UsernameOrEmailRequiredError,
10
+ } from '../../../errors';
5
11
 
6
12
  export default async function createUser(root: Root, params: UserData, context: Context) {
7
13
  const { modules, userId } = context;
@@ -25,10 +31,19 @@ export default async function createUser(root: Root, params: UserData, context:
25
31
  params.username,
26
32
  params.webAuthnPublicKeyCredentials,
27
33
  ));
28
-
29
- const newUserId = await modules.accounts.createUser(mappedUser, {
30
- skipPasswordEnrollment: !!webAuthnService,
31
- });
34
+ let newUserId;
35
+ try {
36
+ newUserId = await modules.accounts.createUser(mappedUser, {
37
+ skipPasswordEnrollment: !!webAuthnService,
38
+ });
39
+ } catch (e) {
40
+ if (e.code === 'EmailAlreadyExists') throw new EmailAlreadyExistsError({ email: params?.email });
41
+ else if (e.code === 'UsernameAlreadyExists')
42
+ throw new UsernameAlreadyExistsError({ username: params?.username });
43
+ else if (e.code === 'UsernameOrEmailRequired')
44
+ throw new UsernameOrEmailRequiredError({ username: params?.username });
45
+ else throw new AuthOperationFailedError({ username: params?.username, email: params.email });
46
+ }
32
47
 
33
48
  if (newUserId && webAuthnService) {
34
49
  await modules.users.updateUser(
@@ -1,6 +1,6 @@
1
1
  import { log } from '@unchainedshop/logger';
2
2
  import { Context, Root } from '@unchainedshop/types/api';
3
- import { UserNotFoundError } from '../../../errors';
3
+ import { TwoFactorCodeDidNotMatchError, TwoFactorNotSetError, UserNotFoundError } from '../../../errors';
4
4
 
5
5
  export default async function disableTOTP(
6
6
  root: Root,
@@ -15,8 +15,18 @@ export default async function disableTOTP(
15
15
 
16
16
  const user = await modules.users.findUserById(normalizedUserId);
17
17
  if (!user) throw new UserNotFoundError({ userId: normalizedUserId });
18
-
19
- await modules.accounts.disableTOTP(normalizedUserId, params.code);
18
+ try {
19
+ await modules.accounts.disableTOTP(normalizedUserId, params.code);
20
+ } catch (e) {
21
+ if (e?.message?.includes("2FA code didn't match"))
22
+ throw new TwoFactorCodeDidNotMatchError({
23
+ submittedCode: params.code,
24
+ userId: params?.userId || userId,
25
+ });
26
+ else if (e?.message?.includes('2FA not set'))
27
+ throw new TwoFactorNotSetError({ userId: params?.userId || userId });
28
+ else throw e;
29
+ }
20
30
 
21
31
  return user;
22
32
  }
@@ -1,5 +1,6 @@
1
1
  import { log } from '@unchainedshop/logger';
2
2
  import { Context, Root } from '@unchainedshop/types/api';
3
+ import { TwoFactorAlreadySetError, TwoFactorCodeDidNotMatchError } from '../../../errors';
3
4
 
4
5
  export default async function enableTOTP(
5
6
  root: Root,
@@ -9,8 +10,14 @@ export default async function enableTOTP(
9
10
  log(`mutation enableTOTP ${params.code}`, {
10
11
  userId,
11
12
  });
12
-
13
- await modules.accounts.enableTOTP(userId, params.secretBase32, params.code);
13
+ try {
14
+ await modules.accounts.enableTOTP(userId, params.secretBase32, params.code);
15
+ } catch (e) {
16
+ if (e?.message?.includes("2FA code didn't match"))
17
+ throw new TwoFactorCodeDidNotMatchError({ submittedCode: params.code, userId });
18
+ else if (e?.message?.includes('2FA already set')) throw new TwoFactorAlreadySetError({ userId });
19
+ else throw e;
20
+ }
14
21
 
15
22
  return modules.users.findUserById(userId);
16
23
  }
@@ -2,6 +2,12 @@ import { log } from '@unchainedshop/logger';
2
2
  import { Context, Root } from '@unchainedshop/types/api';
3
3
  import { UserData } from '@unchainedshop/types/accounts';
4
4
  import { hashPassword } from '../../../hashPassword';
5
+ import {
6
+ AuthOperationFailedError,
7
+ EmailAlreadyExistsError,
8
+ UsernameAlreadyExistsError,
9
+ UsernameOrEmailRequiredError,
10
+ } from '../../../errors';
5
11
 
6
12
  export default async function enrollUser(root: Root, params: UserData, context: Context) {
7
13
  const { modules } = context;
@@ -17,9 +23,18 @@ export default async function enrollUser(root: Root, params: UserData, context:
17
23
 
18
24
  // Skip Messaging when password is set so we
19
25
  // don't send a verification e-mail after enrollment
20
- const userId = await modules.accounts.createUser(mappedUserData, {
21
- skipMessaging: !!mappedUserData.password,
22
- });
26
+ try {
27
+ const userId = await modules.accounts.createUser(mappedUserData, {
28
+ skipMessaging: !!mappedUserData.password,
29
+ });
23
30
 
24
- return modules.users.findUserById(userId);
31
+ return modules.users.findUserById(userId);
32
+ } catch (e) {
33
+ if (e.code === 'EmailAlreadyExists') throw new EmailAlreadyExistsError({ email: params?.email });
34
+ else if (e.code === 'UsernameAlreadyExists')
35
+ throw new UsernameAlreadyExistsError({ username: params?.username, email: params.email });
36
+ else if (e.code === 'UsernameOrEmailRequired')
37
+ throw new UsernameOrEmailRequiredError({ username: params?.username, email: params.email });
38
+ else throw new AuthOperationFailedError({ username: params?.username, email: params.email });
39
+ }
25
40
  }
@@ -1,5 +1,6 @@
1
1
  import { log } from '@unchainedshop/logger';
2
2
  import { Context, Root } from '@unchainedshop/types/api';
3
+ import { AuthOperationFailedError, UserNotFoundError } from '../../../errors';
3
4
 
4
5
  export default async function forgotPassword(
5
6
  root: Root,
@@ -8,7 +9,13 @@ export default async function forgotPassword(
8
9
  ) {
9
10
  log('mutation forgotPassword', { email, userId });
10
11
 
11
- const success = await modules.accounts.sendResetPasswordEmail(email);
12
+ let success = false;
13
+ try {
14
+ success = await modules.accounts.sendResetPasswordEmail(email);
15
+ } catch (e) {
16
+ if (e.code === 'UserNotFound') throw new UserNotFoundError({ email });
17
+ else throw new AuthOperationFailedError({ email });
18
+ }
12
19
 
13
20
  return { success };
14
21
  }
@@ -8,7 +8,7 @@ const impersonate = async (root, { userId }, context: Context) => {
8
8
  const userToImpersonate = await context.modules.users.findUserById(userId);
9
9
 
10
10
  if (!userToImpersonate) {
11
- throw new UserNotFoundError(`No user with id ${userId}`);
11
+ throw new UserNotFoundError({ userId });
12
12
  }
13
13
 
14
14
  if ((userToImpersonate.roles || []).includes('admin')) {
@@ -1,5 +1,13 @@
1
1
  import { log } from '@unchainedshop/logger';
2
2
  import { Context, Root } from '@unchainedshop/types/api';
3
+ import {
4
+ AuthenticationFailedError,
5
+ AuthOperationFailedError,
6
+ InvalidCredentialsError,
7
+ TwoFactorCodeDidNotMatchError,
8
+ TwoFactorCodeRequiredError,
9
+ UserDeactivatedError,
10
+ } from '../../../errors';
3
11
  import { hashPassword } from '../../../hashPassword';
4
12
 
5
13
  export default async function loginWithPassword(
@@ -27,5 +35,20 @@ export default async function loginWithPassword(
27
35
  code: totpCode,
28
36
  };
29
37
 
30
- return modules.accounts.loginWithService({ service: 'password', ...mappedUserLoginParams }, context);
38
+ try {
39
+ const result = await modules.accounts.loginWithService(
40
+ { service: 'password', ...mappedUserLoginParams },
41
+ context,
42
+ );
43
+ return result;
44
+ } catch (e) {
45
+ if (e.code === 'AuthenticationFailed') throw new AuthenticationFailedError({ username, email });
46
+ else if (e.code === 'UserDeactivated') throw new UserDeactivatedError({ username, email });
47
+ else if (e.code === 'InvalidCredentials') throw new InvalidCredentialsError({ username, email });
48
+ else if (e?.message?.includes('2FA code required'))
49
+ throw new TwoFactorCodeRequiredError({ username, email });
50
+ else if (e?.message?.includes("2FA code didn't match"))
51
+ throw new TwoFactorCodeDidNotMatchError({ submittedCode: params.totpCode, username, email });
52
+ else throw new AuthOperationFailedError({ submittedCode: params.totpCode, username, email });
53
+ }
31
54
  }
@@ -1,5 +1,10 @@
1
1
  import { log } from '@unchainedshop/logger';
2
2
  import { Context, Root } from '@unchainedshop/types/api';
3
+ import {
4
+ AuthenticationFailedError,
5
+ AuthOperationFailedError,
6
+ UserDeactivatedError,
7
+ } from '../../../errors';
3
8
 
4
9
  export default async function loginWithWebAuthn(
5
10
  root: Root,
@@ -11,6 +16,12 @@ export default async function loginWithWebAuthn(
11
16
  const { modules } = context;
12
17
 
13
18
  log('mutation loginWithWebAuthn');
14
-
15
- return modules.accounts.loginWithService({ service: 'webAuthn', ...params }, context);
19
+ try {
20
+ const result = await modules.accounts.loginWithService({ service: 'webAuthn', ...params }, context);
21
+ return result;
22
+ } catch (e) {
23
+ if (e.code === 'AuthenticationFailed') throw new AuthenticationFailedError({});
24
+ else if (e.code === 'UserDeactivated') throw new UserDeactivatedError({});
25
+ else throw new AuthOperationFailedError({});
26
+ }
16
27
  }
@@ -1,12 +1,19 @@
1
1
  import { Context, Root } from '@unchainedshop/types/api';
2
2
  import { log, LogLevel } from '@unchainedshop/logger';
3
3
 
4
- export default async function logout(root: Root, params: { token: string }, context: Context) {
4
+ export default async function logout(root: Root, { token }: { token: string }, context: Context) {
5
5
  const { modules, userId, setLoginToken } = context;
6
6
 
7
7
  log('mutation logout', { userId });
8
8
 
9
- const loggedOut = await modules.accounts.logout(params, context);
9
+ const loggedOut = await modules.accounts.logout(
10
+ {
11
+ token,
12
+ loginToken: context.loginToken,
13
+ userId: context.userId,
14
+ },
15
+ context,
16
+ );
10
17
 
11
18
  if (loggedOut.error) {
12
19
  log('Error while logging out', {