@unchainedshop/api 2.0.0-beta7 → 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.
- package/jest.config.js +9 -0
- package/lib/acl.d.ts +2 -0
- package/lib/acl.js +2 -2
- package/lib/acl.js.map +1 -1
- package/lib/api-index.d.ts +4 -6
- package/lib/api-index.js +5 -13
- package/lib/api-index.js.map +1 -1
- package/lib/context.d.ts +0 -1
- package/lib/context.js +0 -12
- package/lib/context.js.map +1 -1
- package/lib/createGraphQLServer.d.ts +1 -1
- package/lib/createGraphQLServer.js +13 -50
- package/lib/createGraphQLServer.js.map +1 -1
- package/lib/errors.d.ts +20 -0
- package/lib/errors.js +20 -0
- package/lib/errors.js.map +1 -1
- package/lib/express/createApolloMiddleware.d.ts +4 -0
- package/lib/express/createApolloMiddleware.js +34 -0
- package/lib/express/createApolloMiddleware.js.map +1 -0
- package/lib/express/createBulkImportMiddleware.d.ts +2 -0
- package/lib/express/createBulkImportMiddleware.js +79 -0
- package/lib/express/createBulkImportMiddleware.js.map +1 -0
- package/lib/express/createERCMetadataMiddleware.d.ts +3 -0
- package/lib/express/createERCMetadataMiddleware.js +57 -0
- package/lib/express/createERCMetadataMiddleware.js.map +1 -0
- package/lib/express/createSingleSignOnMiddleware.d.ts +6 -0
- package/lib/express/createSingleSignOnMiddleware.js +71 -0
- package/lib/express/createSingleSignOnMiddleware.js.map +1 -0
- package/lib/express/index.d.ts +6 -0
- package/lib/express/index.js +27 -0
- package/lib/express/index.js.map +1 -0
- package/lib/loaders/index.js +5 -9
- package/lib/loaders/index.js.map +1 -1
- package/lib/resolvers/mutations/accounts/changePassword.d.ts +0 -2
- package/lib/resolvers/mutations/accounts/changePassword.js +14 -3
- package/lib/resolvers/mutations/accounts/changePassword.js.map +1 -1
- package/lib/resolvers/mutations/accounts/createUser.js +19 -5
- package/lib/resolvers/mutations/accounts/createUser.js.map +1 -1
- package/lib/resolvers/mutations/accounts/disableTOTP.js +15 -2
- package/lib/resolvers/mutations/accounts/disableTOTP.js.map +1 -1
- package/lib/resolvers/mutations/accounts/enableTOTP.js +12 -1
- package/lib/resolvers/mutations/accounts/enableTOTP.js.map +1 -1
- package/lib/resolvers/mutations/accounts/enrollUser.js +18 -5
- package/lib/resolvers/mutations/accounts/enrollUser.js.map +1 -1
- package/lib/resolvers/mutations/accounts/forgotPassword.js +11 -1
- package/lib/resolvers/mutations/accounts/forgotPassword.js.map +1 -1
- package/lib/resolvers/mutations/accounts/impersonate.js +1 -1
- package/lib/resolvers/mutations/accounts/impersonate.js.map +1 -1
- package/lib/resolvers/mutations/accounts/loginWithPassword.d.ts +0 -1
- package/lib/resolvers/mutations/accounts/loginWithPassword.js +22 -4
- package/lib/resolvers/mutations/accounts/loginWithPassword.js.map +1 -1
- package/lib/resolvers/mutations/accounts/loginWithWebAuthn.js +13 -1
- package/lib/resolvers/mutations/accounts/loginWithWebAuthn.js.map +1 -1
- package/lib/resolvers/mutations/accounts/logout.d.ts +1 -1
- package/lib/resolvers/mutations/accounts/logout.js +6 -2
- package/lib/resolvers/mutations/accounts/logout.js.map +1 -1
- package/lib/resolvers/mutations/accounts/logoutAllSessions.js +4 -1
- package/lib/resolvers/mutations/accounts/logoutAllSessions.js.map +1 -1
- package/lib/resolvers/mutations/accounts/resetPassword.d.ts +0 -1
- package/lib/resolvers/mutations/accounts/resetPassword.js +18 -3
- package/lib/resolvers/mutations/accounts/resetPassword.js.map +1 -1
- package/lib/resolvers/mutations/accounts/setPassword.d.ts +0 -1
- package/lib/resolvers/mutations/accounts/setPassword.js +1 -1
- package/lib/resolvers/mutations/accounts/setPassword.js.map +1 -1
- package/lib/resolvers/mutations/assortments/addAssortmentFilter.js +1 -2
- package/lib/resolvers/mutations/assortments/addAssortmentFilter.js.map +1 -1
- package/lib/resolvers/mutations/assortments/addAssortmentLink.js +16 -9
- package/lib/resolvers/mutations/assortments/addAssortmentLink.js.map +1 -1
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.js +2 -3
- package/lib/resolvers/mutations/assortments/addAssortmentMedia.js.map +1 -1
- package/lib/resolvers/mutations/assortments/addAssortmentProduct.js +1 -2
- package/lib/resolvers/mutations/assortments/addAssortmentProduct.js.map +1 -1
- package/lib/resolvers/mutations/assortments/createAssortment.js +1 -2
- package/lib/resolvers/mutations/assortments/createAssortment.js.map +1 -1
- package/lib/resolvers/mutations/assortments/prepareAssortmentMediaUpload.js +0 -1
- package/lib/resolvers/mutations/assortments/prepareAssortmentMediaUpload.js.map +1 -1
- package/lib/resolvers/mutations/assortments/removeAssortment.js +1 -1
- package/lib/resolvers/mutations/assortments/removeAssortment.js.map +1 -1
- package/lib/resolvers/mutations/assortments/removeAssortmentFilter.js +1 -1
- package/lib/resolvers/mutations/assortments/removeAssortmentFilter.js.map +1 -1
- package/lib/resolvers/mutations/assortments/removeAssortmentLink.js +1 -1
- package/lib/resolvers/mutations/assortments/removeAssortmentLink.js.map +1 -1
- package/lib/resolvers/mutations/assortments/removeAssortmentMedia.js +2 -2
- package/lib/resolvers/mutations/assortments/removeAssortmentMedia.js.map +1 -1
- package/lib/resolvers/mutations/assortments/removeAssortmentProduct.js +1 -1
- package/lib/resolvers/mutations/assortments/removeAssortmentProduct.js.map +1 -1
- package/lib/resolvers/mutations/assortments/reorderAssortmentFilters.js +1 -1
- package/lib/resolvers/mutations/assortments/reorderAssortmentFilters.js.map +1 -1
- package/lib/resolvers/mutations/assortments/reorderAssortmentLinks.js +1 -1
- package/lib/resolvers/mutations/assortments/reorderAssortmentLinks.js.map +1 -1
- package/lib/resolvers/mutations/assortments/reorderAssortmentMedia.js +1 -1
- package/lib/resolvers/mutations/assortments/reorderAssortmentMedia.js.map +1 -1
- package/lib/resolvers/mutations/assortments/reorderAssortmentProducts.js +1 -1
- package/lib/resolvers/mutations/assortments/reorderAssortmentProducts.js.map +1 -1
- package/lib/resolvers/mutations/assortments/setBaseAssortment.js +1 -1
- package/lib/resolvers/mutations/assortments/setBaseAssortment.js.map +1 -1
- package/lib/resolvers/mutations/assortments/updateAssortment.js +1 -1
- package/lib/resolvers/mutations/assortments/updateAssortment.js.map +1 -1
- package/lib/resolvers/mutations/assortments/updateAssortmentMediaTexts.js +1 -1
- package/lib/resolvers/mutations/assortments/updateAssortmentMediaTexts.js.map +1 -1
- package/lib/resolvers/mutations/assortments/updateAssortmentTexts.js +1 -1
- package/lib/resolvers/mutations/assortments/updateAssortmentTexts.js.map +1 -1
- package/lib/resolvers/mutations/bookmarks/bookmark.js +2 -2
- package/lib/resolvers/mutations/bookmarks/bookmark.js.map +1 -1
- package/lib/resolvers/mutations/bookmarks/createBookmark.js +1 -1
- package/lib/resolvers/mutations/bookmarks/createBookmark.js.map +1 -1
- package/lib/resolvers/mutations/countries/createCountry.js +1 -2
- package/lib/resolvers/mutations/countries/createCountry.js.map +1 -1
- package/lib/resolvers/mutations/countries/removeCountry.js +1 -1
- package/lib/resolvers/mutations/countries/removeCountry.js.map +1 -1
- package/lib/resolvers/mutations/countries/updateCountry.js +1 -1
- package/lib/resolvers/mutations/countries/updateCountry.js.map +1 -1
- package/lib/resolvers/mutations/currencies/createCurrency.js +1 -2
- package/lib/resolvers/mutations/currencies/createCurrency.js.map +1 -1
- package/lib/resolvers/mutations/currencies/removeCurrency.js +1 -1
- package/lib/resolvers/mutations/currencies/removeCurrency.js.map +1 -1
- package/lib/resolvers/mutations/currencies/updateCurrency.js +1 -1
- package/lib/resolvers/mutations/currencies/updateCurrency.js.map +1 -1
- package/lib/resolvers/mutations/delivery/createDeliveryProvider.js +1 -2
- package/lib/resolvers/mutations/delivery/createDeliveryProvider.js.map +1 -1
- package/lib/resolvers/mutations/delivery/removeDeliveryProvider.js +1 -1
- package/lib/resolvers/mutations/delivery/removeDeliveryProvider.js.map +1 -1
- package/lib/resolvers/mutations/delivery/updateDeliveryProvider.js +1 -1
- package/lib/resolvers/mutations/delivery/updateDeliveryProvider.js.map +1 -1
- package/lib/resolvers/mutations/enrollments/activateEnrollment.js +1 -1
- package/lib/resolvers/mutations/enrollments/activateEnrollment.js.map +1 -1
- package/lib/resolvers/mutations/enrollments/terminateEnrollment.js +1 -1
- package/lib/resolvers/mutations/enrollments/terminateEnrollment.js.map +1 -1
- package/lib/resolvers/mutations/enrollments/updateEnrollment.d.ts +1 -1
- package/lib/resolvers/mutations/enrollments/updateEnrollment.js +5 -5
- package/lib/resolvers/mutations/enrollments/updateEnrollment.js.map +1 -1
- package/lib/resolvers/mutations/filters/createFilter.js +1 -2
- package/lib/resolvers/mutations/filters/createFilter.js.map +1 -1
- package/lib/resolvers/mutations/filters/createFilterOption.js +1 -1
- package/lib/resolvers/mutations/filters/createFilterOption.js.map +1 -1
- package/lib/resolvers/mutations/filters/removeFilter.d.ts +1 -1
- package/lib/resolvers/mutations/filters/removeFilter.js +4 -4
- package/lib/resolvers/mutations/filters/removeFilter.js.map +1 -1
- package/lib/resolvers/mutations/filters/updateFilter.js +1 -1
- package/lib/resolvers/mutations/filters/updateFilter.js.map +1 -1
- package/lib/resolvers/mutations/filters/updateFilterTexts.js +1 -1
- package/lib/resolvers/mutations/filters/updateFilterTexts.js.map +1 -1
- package/lib/resolvers/mutations/index.d.ts +2 -1
- package/lib/resolvers/mutations/index.js +2 -0
- package/lib/resolvers/mutations/index.js.map +1 -1
- package/lib/resolvers/mutations/languages/createLanguage.js +1 -2
- package/lib/resolvers/mutations/languages/createLanguage.js.map +1 -1
- package/lib/resolvers/mutations/languages/removeLanguage.js +1 -1
- package/lib/resolvers/mutations/languages/removeLanguage.js.map +1 -1
- package/lib/resolvers/mutations/languages/updateLanguage.js +1 -1
- package/lib/resolvers/mutations/languages/updateLanguage.js.map +1 -1
- package/lib/resolvers/mutations/orders/createCart.js +1 -1
- package/lib/resolvers/mutations/orders/createCart.js.map +1 -1
- package/lib/resolvers/mutations/orders/payOrder.js +1 -1
- package/lib/resolvers/mutations/orders/payOrder.js.map +1 -1
- package/lib/resolvers/mutations/orders/removeOrder.js +1 -1
- package/lib/resolvers/mutations/orders/removeOrder.js.map +1 -1
- package/lib/resolvers/mutations/pageView.d.ts +1 -1
- package/lib/resolvers/mutations/pageView.js +2 -2
- package/lib/resolvers/mutations/pageView.js.map +1 -1
- package/lib/resolvers/mutations/payment/createPaymentProvider.js +1 -2
- package/lib/resolvers/mutations/payment/createPaymentProvider.js.map +1 -1
- package/lib/resolvers/mutations/payment/registerPaymentCredentials.js +2 -2
- package/lib/resolvers/mutations/payment/registerPaymentCredentials.js.map +1 -1
- package/lib/resolvers/mutations/payment/removePaymentProvider.js +1 -1
- package/lib/resolvers/mutations/payment/removePaymentProvider.js.map +1 -1
- package/lib/resolvers/mutations/payment/updatePaymentProvider.js +1 -1
- package/lib/resolvers/mutations/payment/updatePaymentProvider.js.map +1 -1
- package/lib/resolvers/mutations/products/addProductAssignment.js +1 -1
- package/lib/resolvers/mutations/products/addProductAssignment.js.map +1 -1
- package/lib/resolvers/mutations/products/addProductMedia.js +1 -2
- package/lib/resolvers/mutations/products/addProductMedia.js.map +1 -1
- package/lib/resolvers/mutations/products/addProductReviewVote.js +1 -1
- package/lib/resolvers/mutations/products/addProductReviewVote.js.map +1 -1
- package/lib/resolvers/mutations/products/createProduct.js +1 -2
- package/lib/resolvers/mutations/products/createProduct.js.map +1 -1
- package/lib/resolvers/mutations/products/createProductBundleItem.js +1 -1
- package/lib/resolvers/mutations/products/createProductBundleItem.js.map +1 -1
- package/lib/resolvers/mutations/products/createProductReview.js +1 -1
- package/lib/resolvers/mutations/products/createProductReview.js.map +1 -1
- package/lib/resolvers/mutations/products/createProductVariation.js +1 -2
- package/lib/resolvers/mutations/products/createProductVariation.js.map +1 -1
- package/lib/resolvers/mutations/products/createProductVariationOption.js +4 -1
- package/lib/resolvers/mutations/products/createProductVariationOption.js.map +1 -1
- package/lib/resolvers/mutations/products/prepareProductMediaUpload.js +0 -1
- package/lib/resolvers/mutations/products/prepareProductMediaUpload.js.map +1 -1
- package/lib/resolvers/mutations/products/publishProduct.js +1 -1
- package/lib/resolvers/mutations/products/publishProduct.js.map +1 -1
- package/lib/resolvers/mutations/products/removeBundleItem.js +2 -2
- package/lib/resolvers/mutations/products/removeBundleItem.js.map +1 -1
- package/lib/resolvers/mutations/products/removeProduct.d.ts +1 -1
- package/lib/resolvers/mutations/products/removeProduct.js +17 -8
- package/lib/resolvers/mutations/products/removeProduct.js.map +1 -1
- package/lib/resolvers/mutations/products/removeProductAssignment.js +1 -1
- package/lib/resolvers/mutations/products/removeProductAssignment.js.map +1 -1
- package/lib/resolvers/mutations/products/removeProductMedia.js +2 -2
- package/lib/resolvers/mutations/products/removeProductMedia.js.map +1 -1
- package/lib/resolvers/mutations/products/removeProductReview.js +1 -1
- package/lib/resolvers/mutations/products/removeProductReview.js.map +1 -1
- package/lib/resolvers/mutations/products/removeProductReviewVote.js +1 -1
- package/lib/resolvers/mutations/products/removeProductReviewVote.js.map +1 -1
- package/lib/resolvers/mutations/products/removeProductVariation.js +1 -1
- package/lib/resolvers/mutations/products/removeProductVariation.js.map +1 -1
- package/lib/resolvers/mutations/products/removeProductVariationOption.js +1 -1
- package/lib/resolvers/mutations/products/removeProductVariationOption.js.map +1 -1
- package/lib/resolvers/mutations/products/reorderProductMedia.js +1 -1
- package/lib/resolvers/mutations/products/reorderProductMedia.js.map +1 -1
- package/lib/resolvers/mutations/products/unpublishProduct.js +1 -1
- package/lib/resolvers/mutations/products/unpublishProduct.js.map +1 -1
- package/lib/resolvers/mutations/products/updateProduct.js +1 -1
- package/lib/resolvers/mutations/products/updateProduct.js.map +1 -1
- package/lib/resolvers/mutations/products/updateProductCommerce.js +1 -1
- package/lib/resolvers/mutations/products/updateProductCommerce.js.map +1 -1
- package/lib/resolvers/mutations/products/updateProductMediaTexts.js +1 -1
- package/lib/resolvers/mutations/products/updateProductMediaTexts.js.map +1 -1
- package/lib/resolvers/mutations/products/updateProductPlan.js +1 -1
- package/lib/resolvers/mutations/products/updateProductPlan.js.map +1 -1
- package/lib/resolvers/mutations/products/updateProductReview.js +1 -1
- package/lib/resolvers/mutations/products/updateProductReview.js.map +1 -1
- package/lib/resolvers/mutations/products/updateProductSupply.js +1 -1
- package/lib/resolvers/mutations/products/updateProductSupply.js.map +1 -1
- package/lib/resolvers/mutations/products/updateProductTexts.js +1 -1
- package/lib/resolvers/mutations/products/updateProductTexts.js.map +1 -1
- package/lib/resolvers/mutations/products/updateProductTokenization.js +1 -1
- package/lib/resolvers/mutations/products/updateProductTokenization.js.map +1 -1
- package/lib/resolvers/mutations/products/updateProductVariationTexts.js +1 -1
- package/lib/resolvers/mutations/products/updateProductVariationTexts.js.map +1 -1
- package/lib/resolvers/mutations/products/updateProductWarehousing.js +1 -1
- package/lib/resolvers/mutations/products/updateProductWarehousing.js.map +1 -1
- package/lib/resolvers/mutations/users/prepareUserAvatarUpload.js +0 -1
- package/lib/resolvers/mutations/users/prepareUserAvatarUpload.js.map +1 -1
- package/lib/resolvers/mutations/users/removeUser.d.ts +4 -0
- package/lib/resolvers/mutations/users/removeUser.js +11 -0
- package/lib/resolvers/mutations/users/removeUser.js.map +1 -0
- package/lib/resolvers/mutations/users/setRoles.js +1 -1
- package/lib/resolvers/mutations/users/setRoles.js.map +1 -1
- package/lib/resolvers/mutations/users/setUserTags.js +1 -1
- package/lib/resolvers/mutations/users/setUserTags.js.map +1 -1
- package/lib/resolvers/mutations/users/updateUserAvatar.js +1 -2
- package/lib/resolvers/mutations/users/updateUserAvatar.js.map +1 -1
- package/lib/resolvers/mutations/users/updateUserProfile.js +1 -1
- package/lib/resolvers/mutations/users/updateUserProfile.js.map +1 -1
- package/lib/resolvers/mutations/utils/getOrderCart.js +1 -1
- package/lib/resolvers/mutations/utils/getOrderCart.js.map +1 -1
- package/lib/resolvers/mutations/warehousing/createWarehousingProvider.js +1 -2
- package/lib/resolvers/mutations/warehousing/createWarehousingProvider.js.map +1 -1
- package/lib/resolvers/mutations/warehousing/removeWarehousingProvider.js +1 -1
- package/lib/resolvers/mutations/warehousing/removeWarehousingProvider.js.map +1 -1
- package/lib/resolvers/mutations/warehousing/updateWarehousingProvider.js +1 -1
- package/lib/resolvers/mutations/warehousing/updateWarehousingProvider.js.map +1 -1
- package/lib/resolvers/mutations/worker/addWork.js +1 -1
- package/lib/resolvers/mutations/worker/addWork.js.map +1 -1
- package/lib/resolvers/mutations/worker/finishWork.js +1 -1
- package/lib/resolvers/mutations/worker/finishWork.js.map +1 -1
- package/lib/resolvers/mutations/worker/removeWork.js +1 -1
- package/lib/resolvers/mutations/worker/removeWork.js.map +1 -1
- package/lib/resolvers/queries/products/productCatalogPrices.js +0 -1
- package/lib/resolvers/queries/products/productCatalogPrices.js.map +1 -1
- package/lib/resolvers/queries/users/users.d.ts +2 -1
- package/lib/resolvers/queries/users/users.js.map +1 -1
- package/lib/resolvers/queries/worker/workQueue.d.ts +1 -1
- package/lib/resolvers/queries/worker/workQueue.js +1 -1
- package/lib/resolvers/queries/worker/workQueue.js.map +1 -1
- package/lib/resolvers/type/assortment/assortment-filter-types.d.ts +2 -2
- package/lib/resolvers/type/assortment/assortment-filter-types.js +0 -1
- package/lib/resolvers/type/assortment/assortment-filter-types.js.map +1 -1
- package/lib/resolvers/type/assortment/assortment-link-types.d.ts +2 -2
- package/lib/resolvers/type/assortment/assortment-link-types.js +0 -2
- package/lib/resolvers/type/assortment/assortment-link-types.js.map +1 -1
- package/lib/resolvers/type/assortment/assortment-media-types.d.ts +1 -1
- package/lib/resolvers/type/assortment/assortment-media-types.js +2 -0
- package/lib/resolvers/type/assortment/assortment-media-types.js.map +1 -1
- package/lib/resolvers/type/assortment/assortment-path-link-types.d.ts +1 -4
- package/lib/resolvers/type/assortment/assortment-path-link-types.js +1 -7
- package/lib/resolvers/type/assortment/assortment-path-link-types.js.map +1 -1
- package/lib/resolvers/type/assortment/assortment-product-types.d.ts +2 -2
- package/lib/resolvers/type/assortment/assortment-product-types.js +0 -2
- package/lib/resolvers/type/assortment/assortment-product-types.js.map +1 -1
- package/lib/resolvers/type/assortment/assortment-types.d.ts +1 -1
- package/lib/resolvers/type/assortment/assortment-types.js +8 -4
- package/lib/resolvers/type/assortment/assortment-types.js.map +1 -1
- package/lib/resolvers/type/bookmark-types.d.ts +1 -1
- package/lib/resolvers/type/bookmark-types.js +0 -1
- package/lib/resolvers/type/bookmark-types.js.map +1 -1
- package/lib/resolvers/type/country-types.d.ts +1 -1
- package/lib/resolvers/type/delivery-provider-types.d.ts +1 -1
- package/lib/resolvers/type/enrollment/enrollment-delivery-types.d.ts +2 -2
- package/lib/resolvers/type/enrollment/enrollment-payment-types.d.ts +2 -2
- package/lib/resolvers/type/enrollment/enrollment-period-types.d.ts +2 -2
- package/lib/resolvers/type/enrollment/enrollment-plan-tyes.d.ts +2 -2
- package/lib/resolvers/type/enrollment/enrollment-plan-tyes.js +0 -1
- package/lib/resolvers/type/enrollment/enrollment-plan-tyes.js.map +1 -1
- package/lib/resolvers/type/enrollment/enrollment-types.d.ts +2 -2
- package/lib/resolvers/type/event-types.d.ts +1 -1
- package/lib/resolvers/type/filter/filter-option-types.d.ts +2 -2
- package/lib/resolvers/type/filter/filter-types.d.ts +2 -2
- package/lib/resolvers/type/index.d.ts +1 -0
- package/lib/resolvers/type/login-method-response-types.d.ts +1 -0
- package/lib/resolvers/type/order/order-delivery-discount-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-delivery-pickup-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-delivery-shipping-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-discount-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-global-discount-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-item-discount-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-item-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-item-types.js +0 -3
- package/lib/resolvers/type/order/order-item-types.js.map +1 -1
- package/lib/resolvers/type/order/order-payment-card-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-payment-discount-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-payment-generic-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-payment-invoice-types.d.ts +1 -1
- package/lib/resolvers/type/order/order-types.d.ts +1 -1
- package/lib/resolvers/type/price-types.d.ts +1 -1
- package/lib/resolvers/type/product/product-assortment-path-types.js +1 -0
- package/lib/resolvers/type/product/product-assortment-path-types.js.map +1 -1
- package/lib/resolvers/type/product/product-bundle-item-types.js +0 -1
- package/lib/resolvers/type/product/product-bundle-item-types.js.map +1 -1
- package/lib/resolvers/type/product/product-configurable-types.js +1 -0
- package/lib/resolvers/type/product/product-configurable-types.js.map +1 -1
- package/lib/resolvers/type/product/product-discount.d.ts +1 -1
- package/lib/resolvers/type/product/product-media-types.js +2 -0
- package/lib/resolvers/type/product/product-media-types.js.map +1 -1
- package/lib/resolvers/type/product/product-plan-types.js +1 -12
- package/lib/resolvers/type/product/product-plan-types.js.map +1 -1
- package/lib/resolvers/type/product/product-review-types.d.ts +1 -1
- package/lib/resolvers/type/product/product-review-types.js +0 -1
- package/lib/resolvers/type/product/product-review-types.js.map +1 -1
- package/lib/resolvers/type/product/product-variation-assignment-types.js +0 -1
- package/lib/resolvers/type/product/product-variation-assignment-types.js.map +1 -1
- package/lib/resolvers/type/quotation-types.d.ts +2 -2
- package/lib/resolvers/type/quotation-types.js +0 -1
- package/lib/resolvers/type/quotation-types.js.map +1 -1
- package/lib/resolvers/type/shop-types.d.ts +1 -1
- package/lib/resolvers/type/token-types.d.ts +1 -1
- package/lib/resolvers/type/token-types.js +2 -1
- package/lib/resolvers/type/token-types.js.map +1 -1
- package/lib/resolvers/type/user-types.d.ts +4 -3
- package/lib/resolvers/type/user-types.js +10 -21
- package/lib/resolvers/type/user-types.js.map +1 -1
- package/lib/resolvers/type/webauthn-credentials-types.d.ts +1 -1
- package/lib/resolvers/type/work-types.d.ts +1 -1
- package/lib/roles/admin.js +3 -72
- package/lib/roles/admin.js.map +1 -1
- package/lib/schema/{types/log.d.ts → directives.d.ts} +0 -0
- package/lib/schema/directives.js +15 -0
- package/lib/schema/directives.js.map +1 -0
- package/lib/schema/index.js +2 -1
- package/lib/schema/index.js.map +1 -1
- package/lib/schema/inputTypes.js +0 -15
- package/lib/schema/inputTypes.js.map +1 -1
- package/lib/schema/mutation.js +22 -36
- package/lib/schema/mutation.js.map +1 -1
- package/lib/schema/query.js +42 -22
- package/lib/schema/query.js.map +1 -1
- package/lib/schema/types/assortment.js +10 -10
- package/lib/schema/types/color.js +1 -1
- package/lib/schema/types/country.js +1 -1
- package/lib/schema/types/currency.js +1 -1
- package/lib/schema/types/delivery.js +3 -2
- package/lib/schema/types/delivery.js.map +1 -1
- package/lib/schema/types/dimensions.js +1 -1
- package/lib/schema/types/discount.js +1 -1
- package/lib/schema/types/filter.js +5 -8
- package/lib/schema/types/filter.js.map +1 -1
- package/lib/schema/types/geo-position.js +1 -1
- package/lib/schema/types/language.js +1 -1
- package/lib/schema/types/media.js +1 -1
- package/lib/schema/types/payment.js +3 -3
- package/lib/schema/types/price.js +2 -2
- package/lib/schema/types/product/bundle-product.js +2 -3
- package/lib/schema/types/product/bundle-product.js.map +1 -1
- package/lib/schema/types/product/configurable-product.js +7 -7
- package/lib/schema/types/product/plan-product.js +3 -3
- package/lib/schema/types/product/product.js +11 -11
- package/lib/schema/types/product/simple-product.js +4 -4
- package/lib/schema/types/product/tokenized-product.js +3 -3
- package/lib/schema/types/search.js +3 -8
- package/lib/schema/types/search.js.map +1 -1
- package/lib/schema/types/shop.js +2 -2
- package/lib/schema/types/types.js +1 -1
- package/lib/schema/types/user.js +4 -3
- package/lib/schema/types/user.js.map +1 -1
- package/lib/schema/types/warehousing.js +3 -3
- package/package.json +26 -12
- package/src/acl.ts +2 -2
- package/src/api-index.ts +6 -27
- package/src/context.ts +0 -18
- package/src/createGraphQLServer.ts +14 -68
- package/src/errors.ts +85 -0
- package/src/express/createApolloMiddleware.ts +40 -0
- package/src/express/createBulkImportMiddleware.ts +87 -0
- package/src/express/createERCMetadataMiddleware.ts +73 -0
- package/src/express/createSingleSignOnMiddleware.ts +84 -0
- package/src/express/index.ts +48 -0
- package/src/loaders/index.ts +27 -35
- package/src/resolvers/mutations/accounts/changePassword.ts +11 -6
- package/src/resolvers/mutations/accounts/createUser.ts +21 -6
- package/src/resolvers/mutations/accounts/disableTOTP.ts +13 -3
- package/src/resolvers/mutations/accounts/enableTOTP.ts +9 -2
- package/src/resolvers/mutations/accounts/enrollUser.ts +20 -5
- package/src/resolvers/mutations/accounts/forgotPassword.ts +8 -1
- package/src/resolvers/mutations/accounts/impersonate.ts +1 -1
- package/src/resolvers/mutations/accounts/loginWithPassword.ts +27 -5
- package/src/resolvers/mutations/accounts/loginWithWebAuthn.ts +13 -2
- package/src/resolvers/mutations/accounts/logout.ts +9 -2
- package/src/resolvers/mutations/accounts/logoutAllSessions.ts +7 -1
- package/src/resolvers/mutations/accounts/resetPassword.ts +21 -5
- package/src/resolvers/mutations/accounts/setPassword.ts +2 -2
- package/src/resolvers/mutations/assortments/addAssortmentFilter.ts +5 -9
- package/src/resolvers/mutations/assortments/addAssortmentLink.ts +22 -14
- package/src/resolvers/mutations/assortments/addAssortmentMedia.ts +2 -6
- package/src/resolvers/mutations/assortments/addAssortmentProduct.ts +0 -2
- package/src/resolvers/mutations/assortments/createAssortment.ts +4 -8
- package/src/resolvers/mutations/assortments/prepareAssortmentMediaUpload.ts +0 -1
- package/src/resolvers/mutations/assortments/removeAssortment.ts +1 -1
- package/src/resolvers/mutations/assortments/removeAssortmentFilter.ts +1 -1
- package/src/resolvers/mutations/assortments/removeAssortmentLink.ts +1 -1
- package/src/resolvers/mutations/assortments/removeAssortmentMedia.ts +2 -2
- package/src/resolvers/mutations/assortments/removeAssortmentProduct.ts +1 -1
- package/src/resolvers/mutations/assortments/reorderAssortmentFilters.ts +3 -6
- package/src/resolvers/mutations/assortments/reorderAssortmentLinks.ts +0 -1
- package/src/resolvers/mutations/assortments/reorderAssortmentMedia.ts +3 -6
- package/src/resolvers/mutations/assortments/reorderAssortmentProducts.ts +0 -1
- package/src/resolvers/mutations/assortments/setBaseAssortment.ts +1 -1
- package/src/resolvers/mutations/assortments/updateAssortment.ts +1 -1
- package/src/resolvers/mutations/assortments/updateAssortmentMediaTexts.ts +1 -1
- package/src/resolvers/mutations/assortments/updateAssortmentTexts.ts +1 -1
- package/src/resolvers/mutations/bookmarks/bookmark.ts +4 -7
- package/src/resolvers/mutations/bookmarks/createBookmark.ts +4 -7
- package/src/resolvers/mutations/countries/createCountry.ts +3 -7
- package/src/resolvers/mutations/countries/removeCountry.ts +1 -1
- package/src/resolvers/mutations/countries/updateCountry.ts +1 -1
- package/src/resolvers/mutations/currencies/createCurrency.ts +3 -7
- package/src/resolvers/mutations/currencies/removeCurrency.ts +1 -1
- package/src/resolvers/mutations/currencies/updateCurrency.ts +1 -1
- package/src/resolvers/mutations/delivery/createDeliveryProvider.ts +3 -7
- package/src/resolvers/mutations/delivery/removeDeliveryProvider.ts +1 -1
- package/src/resolvers/mutations/delivery/updateDeliveryProvider.ts +1 -1
- package/src/resolvers/mutations/enrollments/activateEnrollment.ts +1 -1
- package/src/resolvers/mutations/enrollments/terminateEnrollment.ts +1 -1
- package/src/resolvers/mutations/enrollments/updateEnrollment.ts +5 -5
- package/src/resolvers/mutations/filters/createFilter.ts +0 -2
- package/src/resolvers/mutations/filters/createFilterOption.ts +5 -1
- package/src/resolvers/mutations/filters/removeFilter.ts +4 -4
- package/src/resolvers/mutations/filters/updateFilter.ts +1 -1
- package/src/resolvers/mutations/filters/updateFilterTexts.ts +1 -1
- package/src/resolvers/mutations/index.ts +2 -0
- package/src/resolvers/mutations/languages/createLanguage.ts +3 -7
- package/src/resolvers/mutations/languages/removeLanguage.ts +1 -1
- package/src/resolvers/mutations/languages/updateLanguage.ts +1 -1
- package/src/resolvers/mutations/orders/createCart.ts +4 -1
- package/src/resolvers/mutations/orders/payOrder.ts +1 -1
- package/src/resolvers/mutations/orders/removeOrder.ts +1 -1
- package/src/resolvers/mutations/pageView.ts +2 -2
- package/src/resolvers/mutations/payment/createPaymentProvider.ts +3 -7
- package/src/resolvers/mutations/payment/registerPaymentCredentials.ts +6 -2
- package/src/resolvers/mutations/payment/removePaymentProvider.ts +1 -1
- package/src/resolvers/mutations/payment/updatePaymentProvider.ts +1 -1
- package/src/resolvers/mutations/products/addProductAssignment.ts +4 -8
- package/src/resolvers/mutations/products/addProductMedia.ts +1 -2
- package/src/resolvers/mutations/products/addProductReviewVote.ts +1 -1
- package/src/resolvers/mutations/products/createProduct.ts +4 -8
- package/src/resolvers/mutations/products/createProductBundleItem.ts +1 -1
- package/src/resolvers/mutations/products/createProductReview.ts +5 -8
- package/src/resolvers/mutations/products/createProductVariation.ts +6 -10
- package/src/resolvers/mutations/products/createProductVariationOption.ts +4 -5
- package/src/resolvers/mutations/products/prepareProductMediaUpload.ts +0 -1
- package/src/resolvers/mutations/products/publishProduct.ts +1 -1
- package/src/resolvers/mutations/products/removeBundleItem.ts +2 -2
- package/src/resolvers/mutations/products/removeProduct.ts +26 -7
- package/src/resolvers/mutations/products/removeProductAssignment.ts +1 -1
- package/src/resolvers/mutations/products/removeProductMedia.ts +2 -2
- package/src/resolvers/mutations/products/removeProductReview.ts +1 -1
- package/src/resolvers/mutations/products/removeProductReviewVote.ts +1 -1
- package/src/resolvers/mutations/products/removeProductVariation.ts +1 -1
- package/src/resolvers/mutations/products/removeProductVariationOption.ts +0 -1
- package/src/resolvers/mutations/products/reorderProductMedia.ts +1 -1
- package/src/resolvers/mutations/products/unpublishProduct.ts +1 -1
- package/src/resolvers/mutations/products/updateProduct.ts +1 -1
- package/src/resolvers/mutations/products/updateProductCommerce.ts +1 -1
- package/src/resolvers/mutations/products/updateProductMediaTexts.ts +1 -1
- package/src/resolvers/mutations/products/updateProductPlan.ts +1 -1
- package/src/resolvers/mutations/products/updateProductReview.ts +1 -1
- package/src/resolvers/mutations/products/updateProductSupply.ts +1 -1
- package/src/resolvers/mutations/products/updateProductTexts.ts +1 -1
- package/src/resolvers/mutations/products/updateProductTokenization.ts +1 -1
- package/src/resolvers/mutations/products/updateProductVariationTexts.ts +0 -1
- package/src/resolvers/mutations/products/updateProductWarehousing.ts +1 -1
- package/src/resolvers/mutations/users/prepareUserAvatarUpload.ts +0 -1
- package/src/resolvers/mutations/users/removeUser.ts +19 -0
- package/src/resolvers/mutations/users/setRoles.ts +1 -1
- package/src/resolvers/mutations/users/setUserTags.ts +1 -1
- package/src/resolvers/mutations/users/updateUserAvatar.ts +1 -2
- package/src/resolvers/mutations/users/updateUserProfile.ts +1 -1
- package/src/resolvers/mutations/utils/getOrderCart.ts +1 -1
- package/src/resolvers/mutations/warehousing/createWarehousingProvider.ts +3 -7
- package/src/resolvers/mutations/warehousing/removeWarehousingProvider.ts +1 -1
- package/src/resolvers/mutations/warehousing/updateWarehousingProvider.ts +1 -1
- package/src/resolvers/mutations/worker/addWork.ts +1 -1
- package/src/resolvers/mutations/worker/finishWork.ts +8 -12
- package/src/resolvers/mutations/worker/removeWork.ts +1 -1
- package/src/resolvers/queries/products/productCatalogPrices.ts +0 -1
- package/src/resolvers/queries/users/users.ts +2 -1
- package/src/resolvers/queries/worker/workQueue.ts +1 -1
- package/src/resolvers/type/assortment/assortment-filter-types.ts +0 -1
- package/src/resolvers/type/assortment/assortment-link-types.ts +0 -2
- package/src/resolvers/type/assortment/assortment-media-types.ts +2 -0
- package/src/resolvers/type/assortment/assortment-path-link-types.ts +1 -11
- package/src/resolvers/type/assortment/assortment-product-types.ts +0 -2
- package/src/resolvers/type/assortment/assortment-types.ts +9 -4
- package/src/resolvers/type/bookmark-types.ts +0 -1
- package/src/resolvers/type/enrollment/enrollment-plan-tyes.ts +0 -1
- package/src/resolvers/type/order/order-item-types.ts +0 -3
- package/src/resolvers/type/product/product-assortment-path-types.ts +1 -0
- package/src/resolvers/type/product/product-bundle-item-types.ts +0 -1
- package/src/resolvers/type/product/product-configurable-types.ts +1 -0
- package/src/resolvers/type/product/product-media-types.ts +2 -0
- package/src/resolvers/type/product/product-plan-types.ts +2 -18
- package/src/resolvers/type/product/product-review-types.ts +0 -1
- package/src/resolvers/type/product/product-variation-assignment-types.ts +0 -1
- package/src/resolvers/type/quotation-types.ts +0 -1
- package/src/resolvers/type/token-types.ts +2 -1
- package/src/resolvers/type/user-types.ts +14 -25
- package/src/roles/admin.ts +3 -72
- package/src/schema/directives.js +14 -0
- package/src/schema/index.js +2 -1
- package/src/schema/inputTypes.js +0 -15
- package/src/schema/mutation.js +22 -36
- package/src/schema/query.js +42 -22
- package/src/schema/types/assortment.js +10 -10
- package/src/schema/types/color.js +1 -1
- package/src/schema/types/country.js +1 -1
- package/src/schema/types/currency.js +1 -1
- package/src/schema/types/delivery.js +3 -2
- package/src/schema/types/dimensions.js +1 -1
- package/src/schema/types/discount.js +1 -1
- package/src/schema/types/filter.js +5 -8
- package/src/schema/types/geo-position.js +1 -1
- package/src/schema/types/language.js +1 -1
- package/src/schema/types/media.js +1 -1
- package/src/schema/types/payment.js +3 -3
- package/src/schema/types/price.js +2 -2
- package/src/schema/types/product/bundle-product.js +2 -3
- package/src/schema/types/product/configurable-product.js +7 -7
- package/src/schema/types/product/plan-product.js +3 -3
- package/src/schema/types/product/product.js +11 -11
- package/src/schema/types/product/simple-product.js +4 -4
- package/src/schema/types/product/tokenized-product.js +3 -3
- package/src/schema/types/search.js +3 -8
- package/src/schema/types/shop.js +2 -2
- package/src/schema/types/types.js +1 -1
- package/src/schema/types/user.js +4 -3
- package/src/schema/types/warehousing.js +3 -3
- package/tests/api-index.test.ts +78 -0
- package/lib/createBulkImportServer.d.ts +0 -2
- package/lib/createBulkImportServer.js +0 -81
- package/lib/createBulkImportServer.js.map +0 -1
- package/lib/createERCMetadataServer.d.ts +0 -2
- package/lib/createERCMetadataServer.js +0 -59
- package/lib/createERCMetadataServer.js.map +0 -1
- package/lib/schema/types/log.js +0 -16
- package/lib/schema/types/log.js.map +0 -1
- package/src/createBulkImportServer.ts +0 -95
- package/src/createERCMetadataServer.ts +0 -78
- package/src/schema/types/log.js +0 -15
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import cors from 'cors';
|
|
2
|
+
import { expressMiddleware } from '@apollo/server/express4';
|
|
3
|
+
import graphqlUploadExpress from 'graphql-upload/graphqlUploadExpress.mjs';
|
|
4
|
+
import e from 'express';
|
|
5
|
+
|
|
6
|
+
export default function createApolloMiddleware(
|
|
7
|
+
contextResolver,
|
|
8
|
+
{ apolloGraphQLServer, corsOrigins = undefined },
|
|
9
|
+
) {
|
|
10
|
+
const originFn =
|
|
11
|
+
corsOrigins && Array.isArray(corsOrigins)
|
|
12
|
+
? (origin, callback) => {
|
|
13
|
+
if (corsOrigins.length === 0 || !origin) {
|
|
14
|
+
callback(null, true);
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (corsOrigins.indexOf(origin) !== -1) {
|
|
18
|
+
callback(null, true);
|
|
19
|
+
} else {
|
|
20
|
+
callback(new Error('Not allowed by CORS'));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
: corsOrigins;
|
|
24
|
+
|
|
25
|
+
return [
|
|
26
|
+
cors(
|
|
27
|
+
!originFn
|
|
28
|
+
? undefined
|
|
29
|
+
: {
|
|
30
|
+
origin: originFn,
|
|
31
|
+
credentials: true,
|
|
32
|
+
},
|
|
33
|
+
),
|
|
34
|
+
e.json(),
|
|
35
|
+
graphqlUploadExpress({ maxFileSize: 10000000, maxFiles: 10 }),
|
|
36
|
+
expressMiddleware(apolloGraphQLServer, {
|
|
37
|
+
context: contextResolver,
|
|
38
|
+
}),
|
|
39
|
+
];
|
|
40
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
+
import { UnchainedContextResolver } from '@unchainedshop/types/api';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import { checkAction } from '../acl';
|
|
5
|
+
import { actions } from '../roles';
|
|
6
|
+
|
|
7
|
+
const logger = createLogger('unchained:bulk-import');
|
|
8
|
+
|
|
9
|
+
const { BULK_IMPORT_PAYLOAD_CACHE_DIRECTORY } = process.env;
|
|
10
|
+
|
|
11
|
+
const errorHandler = (res) => (e) => {
|
|
12
|
+
logger.error(e.message);
|
|
13
|
+
res.writeHead(503);
|
|
14
|
+
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const methodWrongHandler = (res) => () => {
|
|
18
|
+
logger.error('Method not supported, return 404');
|
|
19
|
+
res.writeHead(404);
|
|
20
|
+
res.end();
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const createWriteStreamToFilesystem = (cacheDirectory) => {
|
|
24
|
+
const date = new Date().toISOString();
|
|
25
|
+
const payloadFilePath = `${cacheDirectory}/${date}.json`;
|
|
26
|
+
const stream = fs.createWriteStream(payloadFilePath, { flags: 'a' });
|
|
27
|
+
return stream;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const createWriteStreamToMongoDB = (BulkImportPayloads) => {
|
|
31
|
+
const date = new Date().toISOString();
|
|
32
|
+
const stream = BulkImportPayloads.openUploadStreamWithId(date, `${date}.json`, {
|
|
33
|
+
contentType: 'application/json',
|
|
34
|
+
});
|
|
35
|
+
return stream;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default function bulkImportMiddleware(contextResolver: UnchainedContextResolver) {
|
|
39
|
+
return async (req, res) => {
|
|
40
|
+
try {
|
|
41
|
+
if (req.method !== 'POST') {
|
|
42
|
+
methodWrongHandler(res)();
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const context = await contextResolver({ req, res });
|
|
47
|
+
await checkAction(context, (actions as any).bulkImport);
|
|
48
|
+
|
|
49
|
+
const input: any = {
|
|
50
|
+
createShouldUpsertIfIDExists: !!req.query?.createShouldUpsertIfIDExists,
|
|
51
|
+
skipCacheInvalidation: !!req.query?.skipCacheInvalidation,
|
|
52
|
+
fsPayloadCacheDirectory: BULK_IMPORT_PAYLOAD_CACHE_DIRECTORY,
|
|
53
|
+
remoteAddress: context.remoteAddress,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const stream = input.fsPayloadCacheDirectory
|
|
57
|
+
? createWriteStreamToFilesystem(input.fsPayloadCacheDirectory)
|
|
58
|
+
: createWriteStreamToMongoDB(context.bulkImporter.BulkImportPayloads);
|
|
59
|
+
|
|
60
|
+
req
|
|
61
|
+
.pipe(stream)
|
|
62
|
+
.on('error', errorHandler(res))
|
|
63
|
+
.on('finish', async (file) => {
|
|
64
|
+
try {
|
|
65
|
+
if (input.fsPayloadCacheDirectory) {
|
|
66
|
+
input.payloadFilePath = stream.path;
|
|
67
|
+
} else {
|
|
68
|
+
input.payloadId = file._id;
|
|
69
|
+
input.payloadSize = file.length;
|
|
70
|
+
}
|
|
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
|
+
});
|
|
77
|
+
res.writeHead(200);
|
|
78
|
+
res.end(JSON.stringify(work));
|
|
79
|
+
} catch (e) {
|
|
80
|
+
errorHandler(res)(e);
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
} catch (e) {
|
|
84
|
+
errorHandler(res)(e);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
2
|
+
import { UnchainedContextResolver } from '@unchainedshop/types/api';
|
|
3
|
+
import { systemLocale } from '@unchainedshop/utils';
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
5
|
+
import localePkg from 'locale';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
|
|
8
|
+
const { Locale } = localePkg;
|
|
9
|
+
|
|
10
|
+
const logger = createLogger('unchained:erc-metadata');
|
|
11
|
+
|
|
12
|
+
const errorHandler = (res) => (e) => {
|
|
13
|
+
logger.error(e.message);
|
|
14
|
+
res.writeHead(503);
|
|
15
|
+
res.end(JSON.stringify({ name: e.name, code: e.code, message: e.message }));
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const methodWrongHandler = (res) => () => {
|
|
19
|
+
logger.error('Method not supported, return 404');
|
|
20
|
+
res.writeHead(404);
|
|
21
|
+
res.end();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default function ercMetadataMiddleware(contextResolver: UnchainedContextResolver) {
|
|
25
|
+
return async (req: IncomingMessage, res) => {
|
|
26
|
+
try {
|
|
27
|
+
if (req.method !== 'GET') {
|
|
28
|
+
methodWrongHandler(res)();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const context = await contextResolver({ req, res });
|
|
33
|
+
const url = new URL(req.url, process.env.ROOT_URL);
|
|
34
|
+
const parsedPath = path.parse(url.pathname);
|
|
35
|
+
|
|
36
|
+
if (parsedPath.ext !== '.json') throw new Error('Invalid ERC Metadata URI');
|
|
37
|
+
|
|
38
|
+
const [, productId, localeOrTokenFilename, tokenFileName] = url.pathname.split('/');
|
|
39
|
+
|
|
40
|
+
const locale = tokenFileName ? localeOrTokenFilename : systemLocale.language;
|
|
41
|
+
const chainTokenId = parsedPath.name;
|
|
42
|
+
|
|
43
|
+
const product = await context.modules.products.findProduct({
|
|
44
|
+
productId,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const [token] = await context.modules.warehousing.findTokens({
|
|
48
|
+
chainTokenId,
|
|
49
|
+
contractAddress: product?.tokenization?.contractAddress,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const ercMetadata = await context.modules.warehousing.tokenMetadata(
|
|
53
|
+
chainTokenId,
|
|
54
|
+
{
|
|
55
|
+
token,
|
|
56
|
+
product,
|
|
57
|
+
locale: new Locale(locale),
|
|
58
|
+
referenceDate: new Date(),
|
|
59
|
+
},
|
|
60
|
+
context,
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
const body = JSON.stringify(ercMetadata);
|
|
64
|
+
res.writeHead(200, {
|
|
65
|
+
'Content-Length': Buffer.byteLength(body),
|
|
66
|
+
'Content-Type': 'text/plain',
|
|
67
|
+
});
|
|
68
|
+
res.end(body);
|
|
69
|
+
} catch (e) {
|
|
70
|
+
errorHandler(res)(e);
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/// <reference lib="dom" />
|
|
2
|
+
import { createLogger } from '@unchainedshop/logger';
|
|
3
|
+
import { UnchainedContextResolver } from '@unchainedshop/types/api';
|
|
4
|
+
import { IncomingMessage } from 'http';
|
|
5
|
+
import cookie from 'cookie';
|
|
6
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
7
|
+
|
|
8
|
+
const { ROOT_URL, NODE_ENV, UNCHAINED_CLOUD_ENDPOINT } = process.env;
|
|
9
|
+
|
|
10
|
+
const logger = createLogger('unchained:unchained-cloud-sso');
|
|
11
|
+
|
|
12
|
+
const loginWithSingleSignOn = async (remoteToken, context: UnchainedCore) => {
|
|
13
|
+
const domain = process.env.UNCHAINED_COOKIE_DOMAIN || new URL(ROOT_URL).hostname || 'localhost';
|
|
14
|
+
const result = await fetch(UNCHAINED_CLOUD_ENDPOINT, {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: {
|
|
17
|
+
'content-type': 'application/json',
|
|
18
|
+
},
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
operationName: 'consume',
|
|
21
|
+
variables: {
|
|
22
|
+
token: remoteToken,
|
|
23
|
+
},
|
|
24
|
+
query:
|
|
25
|
+
'mutation consume($token: ID!) { controlConsumeSingleSignOnToken(token: $token) { domain } }',
|
|
26
|
+
}),
|
|
27
|
+
});
|
|
28
|
+
const json: any = await result.json();
|
|
29
|
+
if (json?.errors?.length > 0) {
|
|
30
|
+
throw new Error(json.errors[0].message);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (domain === 'localhost' || domain === json?.data?.controlConsumeSingleSignOnToken?.domain) {
|
|
34
|
+
// create sso user if not exist and login
|
|
35
|
+
const ssoUserId =
|
|
36
|
+
(await context.modules.users.findUser({ username: 'sso' }))?._id ||
|
|
37
|
+
(await context.modules.accounts.createUser(
|
|
38
|
+
{
|
|
39
|
+
username: 'sso',
|
|
40
|
+
roles: ['admin'],
|
|
41
|
+
email: 'sso@unchained.local',
|
|
42
|
+
password: null,
|
|
43
|
+
guest: false,
|
|
44
|
+
},
|
|
45
|
+
{ skipMessaging: true },
|
|
46
|
+
));
|
|
47
|
+
const { tokenExpires, token } = await context.modules.accounts.createLoginToken(ssoUserId, context);
|
|
48
|
+
const expires = new Date(tokenExpires || new Date().getTime() + 100000);
|
|
49
|
+
const authCookie = cookie.serialize(process.env.UNCHAINED_COOKIE_NAME, token, {
|
|
50
|
+
domain,
|
|
51
|
+
httpOnly: true,
|
|
52
|
+
expires,
|
|
53
|
+
path: '/',
|
|
54
|
+
sameSite: 'strict',
|
|
55
|
+
secure: NODE_ENV === 'production',
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
return authCookie;
|
|
59
|
+
}
|
|
60
|
+
throw new Error('Invalid token/domain pair');
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export default function singleSignOnMiddleware(contextResolver: UnchainedContextResolver) {
|
|
64
|
+
return async (req: IncomingMessage & { query?: any }, res, next) => {
|
|
65
|
+
try {
|
|
66
|
+
if (req.query?.token) {
|
|
67
|
+
const context = await contextResolver({ req, res });
|
|
68
|
+
const authCookie = await loginWithSingleSignOn(req.query.token, context);
|
|
69
|
+
|
|
70
|
+
if (authCookie) {
|
|
71
|
+
res.writeHead(303, {
|
|
72
|
+
'Set-Cookie': authCookie,
|
|
73
|
+
Location: '/',
|
|
74
|
+
});
|
|
75
|
+
res.end();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} catch (e) {
|
|
80
|
+
logger.error(e.message);
|
|
81
|
+
}
|
|
82
|
+
next();
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { UnchainedCore } from '@unchainedshop/types/core';
|
|
2
|
+
import { IncomingMessage, OutgoingMessage } from 'http';
|
|
3
|
+
import { ApolloServer } from '@apollo/server';
|
|
4
|
+
import type e from 'express';
|
|
5
|
+
import { getCurrentContextResolver } from '../context';
|
|
6
|
+
import createBulkImportMiddleware from './createBulkImportMiddleware';
|
|
7
|
+
import createERCMetadataMiddleware from './createERCMetadataMiddleware';
|
|
8
|
+
import createApolloMiddleware from './createApolloMiddleware';
|
|
9
|
+
import createSingleSignOnMiddleware from './createSingleSignOnMiddleware';
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
BULK_IMPORT_API_PATH = '/bulk-import',
|
|
13
|
+
ERC_METADATA_API_PATH = '/erc-metadata',
|
|
14
|
+
GRAPHQL_API_PATH = '/graphql',
|
|
15
|
+
} = process.env;
|
|
16
|
+
|
|
17
|
+
export const useMiddlewareWithCurrentContext = (expressApp, path, ...middleware) => {
|
|
18
|
+
const context = getCurrentContextResolver();
|
|
19
|
+
const addContext = async function middlewareWithContext(
|
|
20
|
+
req: IncomingMessage & { unchainedContext: UnchainedCore },
|
|
21
|
+
res: OutgoingMessage,
|
|
22
|
+
next,
|
|
23
|
+
) {
|
|
24
|
+
try {
|
|
25
|
+
req.unchainedContext = await context({ req, res });
|
|
26
|
+
next();
|
|
27
|
+
} catch (error) {
|
|
28
|
+
next(error);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
expressApp.use(path, addContext, ...middleware);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const connect = (
|
|
36
|
+
expressApp: e.Express,
|
|
37
|
+
{ apolloGraphQLServer }: { apolloGraphQLServer: ApolloServer },
|
|
38
|
+
) => {
|
|
39
|
+
const contextResolver = getCurrentContextResolver();
|
|
40
|
+
|
|
41
|
+
expressApp.use(GRAPHQL_API_PATH, createApolloMiddleware(contextResolver, { apolloGraphQLServer }));
|
|
42
|
+
expressApp.use(ERC_METADATA_API_PATH, createERCMetadataMiddleware(contextResolver));
|
|
43
|
+
expressApp.use(BULK_IMPORT_API_PATH, createBulkImportMiddleware(contextResolver));
|
|
44
|
+
expressApp.use(
|
|
45
|
+
['/', '/.well-known/unchained/cloud-sso'],
|
|
46
|
+
createSingleSignOnMiddleware(contextResolver),
|
|
47
|
+
);
|
|
48
|
+
};
|
package/src/loaders/index.ts
CHANGED
|
@@ -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
|
|
21
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
23
|
+
const assortments = await unchainedAPI.modules.assortments.findAssortments({
|
|
24
|
+
assortmentIds,
|
|
25
|
+
includeInactive: true,
|
|
26
|
+
includeLeaves: true,
|
|
27
|
+
});
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
|
122
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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,26 +1,31 @@
|
|
|
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,
|
|
6
7
|
params: {
|
|
7
|
-
oldPassword?: string;
|
|
8
8
|
oldPlainPassword?: string;
|
|
9
|
-
newPassword?: string;
|
|
10
9
|
newPlainPassword?: string;
|
|
11
10
|
},
|
|
12
11
|
{ modules, userId }: Context,
|
|
13
12
|
) {
|
|
14
13
|
log('mutation changePassword', { userId });
|
|
15
14
|
|
|
16
|
-
if (!params.
|
|
15
|
+
if (!params.newPlainPassword) {
|
|
17
16
|
throw new Error('New password is required');
|
|
18
17
|
}
|
|
19
|
-
if (!params.
|
|
18
|
+
if (!params.oldPlainPassword) {
|
|
20
19
|
throw new Error('Old password is required');
|
|
21
20
|
}
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
}
|
|
24
29
|
|
|
25
30
|
return { success };
|
|
26
31
|
}
|
|
@@ -2,18 +2,24 @@ 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;
|
|
8
14
|
|
|
9
15
|
log('mutation createUser', { email: params.email, username: params.username, userId });
|
|
10
16
|
|
|
11
|
-
if (!params.
|
|
17
|
+
if (!params.plainPassword && !params.webAuthnPublicKeyCredentials) {
|
|
12
18
|
throw new Error('Password or Public Key is required');
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
const mappedUser = { ...params };
|
|
16
|
-
if (
|
|
22
|
+
if (mappedUser.plainPassword) {
|
|
17
23
|
mappedUser.password = hashPassword(mappedUser.plainPassword);
|
|
18
24
|
}
|
|
19
25
|
delete mappedUser.plainPassword;
|
|
@@ -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
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -10,16 +16,25 @@ export default async function enrollUser(root: Root, params: UserData, context:
|
|
|
10
16
|
|
|
11
17
|
const mappedUserData = params;
|
|
12
18
|
mappedUserData.initialPassword = true;
|
|
13
|
-
if (
|
|
19
|
+
if (mappedUserData.plainPassword) {
|
|
14
20
|
mappedUserData.password = hashPassword(mappedUserData.plainPassword);
|
|
15
21
|
}
|
|
16
22
|
delete mappedUserData.plainPassword;
|
|
17
23
|
|
|
18
24
|
// Skip Messaging when password is set so we
|
|
19
25
|
// don't send a verification e-mail after enrollment
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
try {
|
|
27
|
+
const userId = await modules.accounts.createUser(mappedUserData, {
|
|
28
|
+
skipMessaging: !!mappedUserData.password,
|
|
29
|
+
});
|
|
23
30
|
|
|
24
|
-
|
|
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
|
-
|
|
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(
|
|
11
|
+
throw new UserNotFoundError({ userId });
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
if ((userToImpersonate.roles || []).includes('admin')) {
|