npm-pkg-hook 1.3.9 → 1.4.0
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/.babelrc +2 -10
- package/.env +5 -1
- package/dist/index.js +17953 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +17711 -0
- package/dist/index.mjs.map +1 -0
- package/eslint.config.mjs +154 -0
- package/expire.json +1 -0
- package/index.d.ts +2 -0
- package/jest.config.ts +9 -0
- package/package.json +45 -36
- package/src/config/client/errors.ts +39 -0
- package/src/config/content/en.json +5 -0
- package/src/config/content/es.json +5 -0
- package/src/config/content/index.ts +16 -0
- package/src/hooks/addTenMinutes/index.ts +14 -0
- package/src/hooks/calculateLogLatHaversine/index.ts +41 -0
- package/src/hooks/completeSchedules/index.ts +22 -0
- package/src/hooks/convertToMilitaryTime/index.ts +18 -0
- package/src/hooks/generateStoreURL/index.ts +41 -0
- package/src/hooks/generateTemplate/index.ts +66 -0
- package/src/hooks/getCardType/index.ts +24 -0
- package/src/hooks/getCategoriesWithProduct/{index.js → index.ts} +7 -7
- package/src/hooks/getGlobalSession/index.ts +69 -0
- package/src/hooks/getSession/index.ts +72 -0
- package/src/hooks/getTodayTimestamps/index.ts +70 -0
- package/src/hooks/getTotalHours/index.ts +76 -0
- package/src/hooks/handleLogin/index.ts +14 -0
- package/src/hooks/index.ts +154 -0
- package/src/hooks/isTokenExpired/index.ts +17 -0
- package/src/hooks/newMessageSubscription/index.ts +28 -0
- package/src/hooks/newStoreOrderSubscription/index.ts +26 -0
- package/src/hooks/{useStatusOpenStore/helpers/index.js → statusOpenStores/helpers/index.ts} +24 -1
- package/src/hooks/statusOpenStores/index.ts +221 -0
- package/src/hooks/updateExtProductFoodsOptional/{index.js → index.ts} +15 -6
- package/src/hooks/useAcumulateDate/index.ts +18 -0
- package/src/hooks/useAllStoresPendingToRegister/index.ts +37 -0
- package/src/hooks/useAmountInput/index.ts +127 -0
- package/src/hooks/useAnimationText/{index.jsx → index.ts} +2 -2
- package/src/hooks/useAsideCart/index.ts +217 -0
- package/src/hooks/useBanner/{index.js → index.ts} +2 -1
- package/src/hooks/useCart/{queries.js → queries.ts} +11 -1
- package/src/hooks/useCart/useCart/helpers/{index.js → index.ts} +10 -6
- package/src/hooks/useCart/useCart/{index.js → index.ts} +58 -44
- package/src/hooks/useCart/useGetCart/{index.js → index.ts} +6 -3
- package/src/hooks/useCatWithProduct/{index.js → index.ts} +17 -7
- package/src/hooks/useCatWithProduct/{queries.js → queries.ts} +50 -23
- package/src/hooks/useCatWithProduct/types/index.ts +104 -0
- package/src/hooks/useCatWithProductClient/{index.js → index.ts} +19 -18
- package/src/hooks/useCatWithProductClient/{queries.js → queries.ts} +1 -0
- package/src/hooks/useCategoriesProduct/{index.js → index.ts} +3 -1
- package/src/hooks/useCategoriesProduct/{queries.js → queries.ts} +2 -2
- package/src/hooks/useCategoryInStore/index.ts +167 -0
- package/src/hooks/useCategoryInStore/{queries.js → queries.ts} +2 -2
- package/src/hooks/useCategoryStore/{index.js → index.ts} +4 -3
- package/src/hooks/useCategoryStore/{queries.js → queries.ts} +2 -2
- package/src/hooks/useChartData/{index.js → index.ts} +31 -34
- package/src/hooks/useChartData/useChartData/{index.js → index.ts} +31 -30
- package/src/hooks/useChartData/useChartDataAllOrders/{index.js → index.ts} +4 -4
- package/src/hooks/useChatRoomSubscription/index.ts +28 -0
- package/src/hooks/useCheckbox/{index.js → index.ts} +1 -1
- package/src/hooks/useCities/index.ts +14 -0
- package/src/hooks/useCities/queries.ts +12 -0
- package/src/hooks/useClients/{index.js → index.ts} +36 -10
- package/src/hooks/useClients/queries.ts +215 -0
- package/src/hooks/useColorByLetters/helpers/alea.ts +73 -0
- package/src/hooks/useColorByLetters/helpers/colors.ts +45 -0
- package/src/hooks/useColorByLetters/helpers/index.ts +24 -0
- package/src/hooks/useColorByLetters/helpers/mersenne_twister.ts +118 -0
- package/src/hooks/useColorByLetters/index.ts +24 -0
- package/src/hooks/useConnection/index.ts +24 -0
- package/src/hooks/useCountries/index.ts +20 -0
- package/src/hooks/useCountries/queries.ts +12 -0
- package/src/hooks/useCreateDeliveryTime/index.ts +51 -0
- package/src/hooks/useCreateOrderStatusType/index.ts +134 -0
- package/src/hooks/useCreateProduct/helpers/index.ts +23 -0
- package/src/hooks/useCreateProduct/helpers/manageCacheDataCatProduct/{index.js → index.ts} +1 -1
- package/src/hooks/useCreateProduct/helpers/useEditImageProduct/{index.js → index.ts} +14 -8
- package/src/hooks/useCreateProduct/index.ts +337 -0
- package/src/hooks/useCreateStorePendingToRegister/index.ts +17 -0
- package/src/hooks/useCreateStorePendingToRegister/queries.ts +10 -0
- package/src/hooks/useDashboardComponents/index.ts +50 -0
- package/src/hooks/useDeleteExtraProductFoods/index.ts +13 -0
- package/src/hooks/useDeleteSubProductOptional/{index.js → index.ts} +5 -3
- package/src/hooks/useDeliveryTime/index.ts +29 -0
- package/src/hooks/useDepartments/index.ts +14 -0
- package/src/hooks/useDepartments/queries.ts +13 -0
- package/src/hooks/useDessert/{index.js → index.ts} +162 -114
- package/src/hooks/useDessertWithPrice/helpers/index.ts +76 -0
- package/src/hooks/useDessertWithPrice/index.ts +381 -0
- package/src/hooks/useDessertWithPrice/queries.ts +18 -0
- package/src/hooks/useDevWS/index.ts +53 -0
- package/src/hooks/useDevices/index.ts +2 -0
- package/src/hooks/useDevices/queries.ts +28 -0
- package/src/hooks/useDevices/useGetDevices.ts +28 -0
- package/src/hooks/useDevices/useRegisterDevices.ts +75 -0
- package/src/hooks/useDownloadReports/helpers/downloadFileFromResponse.ts +21 -0
- package/src/hooks/useDownloadReports/index.ts +2 -0
- package/src/hooks/useDownloadReports/useDownloadReportByDay/index.ts +105 -0
- package/src/hooks/useDownloadReports/useGetReportByDateRange/index.ts +116 -0
- package/src/hooks/useDrag/{index.js → index.ts} +16 -0
- package/src/hooks/useDropzone/{index.js → index.ts} +2 -2
- package/src/hooks/useDynamicAuth/{index.js → index.ts} +2 -1
- package/src/hooks/useEditCategory/{index.js → index.ts} +14 -14
- package/src/hooks/useEditOneExtProductFoodOptional/index.ts +28 -0
- package/src/hooks/useEditOneExtProductFoodOptional/{queries.js → queries.ts} +2 -2
- package/src/hooks/useEditSubProductOptional/index.ts +12 -0
- package/src/hooks/useEmployee/index.ts +18 -0
- package/src/hooks/useEmployee/queries.ts +85 -0
- package/src/hooks/useEmployee/useCreateEmployee.ts +90 -0
- package/src/hooks/useEvent/{index.js → index.ts} +1 -0
- package/src/hooks/useFavoriteStores/index.ts +31 -0
- package/src/hooks/useFavoriteStores/queries.ts +54 -0
- package/src/hooks/useFetchMoreInteractions/index.jsx +26 -26
- package/src/hooks/useFilterConfigs/index.ts +173 -0
- package/src/hooks/useFingerprintjs/{index.js → index.ts} +32 -7
- package/src/hooks/useFormTools/index.ts +143 -0
- package/src/hooks/useFormatDate/index.ts +91 -0
- package/src/hooks/useFullScreenMode/{index.js → index.ts} +1 -5
- package/src/hooks/useGetAllLocationUser/index.ts +13 -0
- package/src/hooks/useGetAllLocationUser/queries.ts +44 -0
- package/src/hooks/{useSales/useGetAllSales/index.js → useGetAllSales/index.ts} +3 -2
- package/src/hooks/useGetCookies/index.ts +43 -0
- package/src/hooks/useGetExtProductFoodsSubOptionalAll/{index.js → index.ts} +2 -1
- package/src/hooks/useGetFoodRecomended/{index.js → index.ts} +2 -1
- package/src/hooks/useGetMessagesToRoom/index.ts +23 -0
- package/src/hooks/useGetMinPrice/{index.js → index.ts} +2 -1
- package/src/hooks/useGetOneStoreRating/{index.js → index.ts} +2 -1
- package/src/hooks/useGetSalesAmountToday/index.ts +31 -0
- package/src/hooks/useGetStoreCookie/index.ts +21 -0
- package/src/hooks/useGoogleLogin/{index.js → index.ts} +14 -5
- package/src/hooks/useHover/{index.js → index.ts} +3 -0
- package/src/hooks/useImageOptimization/{index.js → index.ts} +4 -0
- package/src/hooks/useImageUploaderProduct/helper/canvasUtils.ts +146 -0
- package/src/hooks/useImageUploaderProduct/helper/getOrientation.ts +54 -0
- package/src/hooks/useImageUploaderProduct/helper/index.ts +5 -0
- package/src/hooks/useImageUploaderProduct/index.ts +295 -0
- package/src/hooks/useImageWeight/{index.js → index.ts} +4 -0
- package/src/hooks/useImagesStore/index.ts +227 -0
- package/src/hooks/useImagesStore/{queries.js → queries.ts} +4 -68
- package/src/hooks/useImagesStore/utils/index.ts +4 -0
- package/src/hooks/useIncomingOrders/index.ts +11 -0
- package/src/hooks/useIncomingOrders/queries.ts +87 -0
- package/src/hooks/useIntersection/{index.js → index.ts} +1 -1
- package/src/hooks/useInventory/index.ts +2 -0
- package/src/hooks/useInventory/queries.ts +58 -0
- package/src/hooks/useInventory/useGetProductsInStock.ts +16 -0
- package/src/hooks/useInventory/useUpdateManageStock.ts +41 -0
- package/src/hooks/useLazyScript/{index.js → index.ts} +3 -0
- package/src/hooks/useLocalBackendIp/index.ts +34 -0
- package/src/hooks/useLocalSorage/{index.js → index.ts} +3 -3
- package/src/hooks/useLocationManager/index.ts +63 -0
- package/src/hooks/useLoginEmployeeInStore/index.ts +38 -0
- package/src/hooks/useLogout/helpers/BroadcastChannel.ts +74 -0
- package/src/hooks/useLogout/helpers/apiBaseUrl.ts +12 -0
- package/src/hooks/useLogout/helpers/fetchData.ts +37 -0
- package/src/hooks/useLogout/helpers/getCsrfToken.ts +37 -0
- package/src/hooks/useLogout/helpers/index.ts +65 -0
- package/src/hooks/useLogout/helpers/logger.ts +88 -0
- package/src/hooks/useLogout/helpers/parseUrl.ts +39 -0
- package/src/hooks/useLogout/index.ts +105 -0
- package/src/hooks/useManageNewOrder/helpers/index.ts +45 -0
- package/src/hooks/useManageNewOrder/index.ts +104 -0
- package/src/hooks/useManageQueryParams/index.ts +120 -0
- package/src/hooks/useMobile/index.ts +65 -0
- package/src/hooks/useModules/helpers/index.ts +1 -0
- package/src/hooks/useModules/helpers/validateModules.ts +43 -0
- package/src/hooks/useModules/index.ts +124 -0
- package/src/hooks/useMouse/index.ts +55 -0
- package/src/hooks/useOrderStatusTypes/index.ts +2 -0
- package/src/hooks/useOrderStatusTypes/useOrderStatusTypes/index.ts +133 -0
- package/src/hooks/useOrderStatusTypes/useUpdateOrderStatusPriorities/index.ts +99 -0
- package/src/hooks/useOrders/index.ts +3 -0
- package/src/hooks/useOrders/queries.ts +99 -0
- package/src/hooks/useOrders/useChangeOrderState/index.ts +128 -0
- package/src/hooks/useOrders/{index.js → useOrdersFromStore/index.ts} +20 -18
- package/src/hooks/usePWAInstall/index.ts +38 -0
- package/src/hooks/usePaymentMethod/index.ts +3 -0
- package/src/hooks/usePaymentMethod/paymentMethod.gql.ts +62 -0
- package/src/hooks/usePaymentMethod/paymentMethod.types.ts +28 -0
- package/src/hooks/usePaymentMethod/useCreatePaymentMethod/index.ts +25 -0
- package/src/hooks/usePaymentMethod/useGetAllPaymentMethods/index.ts +19 -0
- package/src/hooks/usePaymentMethod/useGetPaymentMethod/index.ts +26 -0
- package/src/hooks/usePortFetcher/index.ts +33 -0
- package/src/hooks/usePrintSaleTicket/index.ts +68 -0
- package/src/hooks/useProductsFood/index.ts +341 -0
- package/src/hooks/useProductsFood/{queriesStore.js → queriesStore.ts} +151 -84
- package/src/hooks/useProductsFood/types/index.ts +0 -0
- package/src/hooks/useProductsFood/useEditProduct.ts +49 -0
- package/src/hooks/useProductsFood/usetagsProducts.ts +101 -0
- package/src/hooks/useProviders/useProvidersCreateStore/{index.js → index.ts} +2 -1
- package/src/hooks/useProviders/useProvidersDataStore/{index.js → index.ts} +2 -1
- package/src/hooks/useProvidersStore/{index.js → index.ts} +2 -1
- package/src/hooks/usePushNotificationOrder/index.ts +52 -0
- package/src/hooks/usePushNotifications/helpers/index.ts +123 -0
- package/src/hooks/usePushNotifications/index.ts +150 -0
- package/src/hooks/useQueryLocationsMap/index.ts +20 -0
- package/src/hooks/useQueryLocationsMap/queries.ts +40 -0
- package/src/hooks/useRatingArrayData/{index.js → index.ts} +4 -4
- package/src/hooks/useRatingArrayData/{queries.js → queries.ts} +1 -1
- package/src/hooks/useReactToPrint/index.ts +4 -0
- package/src/hooks/useRemoveExtraProductFoodsOptional/{index.js → index.ts} +2 -1
- package/src/hooks/useRemoveExtraProductFoodsOptional/{queries.js → queries.ts} +4 -4
- package/src/hooks/useReport/{index.js → index.ts} +5 -5
- package/src/hooks/useReport/{queries.js → queries.ts} +4 -55
- package/src/hooks/useRestaurant/helpers/index.ts +28 -0
- package/src/hooks/useRestaurant/helpers/manageStatusOpen.ts +26 -0
- package/src/hooks/useRestaurant/index.ts +71 -0
- package/src/hooks/useRestaurant/{queries.js → queries.ts} +2 -1
- package/src/hooks/useRoads/index.ts +20 -0
- package/src/hooks/useRoads/queries.ts +13 -0
- package/src/hooks/useRoles/index.ts +4 -0
- package/src/hooks/useRoles/queries.ts +70 -0
- package/src/hooks/useRoles/useCreateRole.ts +40 -0
- package/src/hooks/useRoles/useGetRoles.ts +37 -0
- package/src/hooks/useRoles/useRemoveRoles.ts +40 -0
- package/src/hooks/useRoles/useUpdateRolesPriority.ts +44 -0
- package/src/hooks/useSales/helpers/add-product.utils.ts +120 -0
- package/src/hooks/useSales/helpers/apply-discount-to-cart.utils.ts +292 -0
- package/src/hooks/useSales/helpers/comment-product.utils.ts +41 -0
- package/src/hooks/useSales/helpers/constants/index.ts +38 -0
- package/src/hooks/useSales/helpers/extras.utils.ts +42 -0
- package/src/hooks/useSales/helpers/filterProductsByCarProId.utils.ts +17 -0
- package/src/hooks/useSales/helpers/increment-product-quantity.utils.ts +76 -0
- package/src/hooks/useSales/helpers/index.ts +3 -0
- package/src/hooks/useSales/helpers/initializer.utils.ts +22 -0
- package/src/hooks/useSales/helpers/isStockInsufficient.ts +3 -0
- package/src/hooks/useSales/helpers/remove-product.utils.test.ts +49 -0
- package/src/hooks/useSales/helpers/remove-product.utils.ts +34 -0
- package/src/hooks/useSales/helpers/resolveProduct.ts +29 -0
- package/src/hooks/useSales/helpers/useAddToCart.ts +64 -0
- package/src/hooks/useSales/index.ts +1418 -0
- package/src/hooks/useSales/{queries.js → queries.ts} +256 -166
- package/src/hooks/useSales/types/index.ts +206 -0
- package/src/hooks/useSales/types/use-sales.types.ts +8 -0
- package/src/hooks/useSales/useGetSale.ts +21 -0
- package/src/hooks/useSales/useTotalSales.ts +24 -0
- package/src/hooks/useSaveAvailableProduct/helpers/{index.js → index.ts} +4 -4
- package/src/hooks/useSaveAvailableProduct/{index.js → index.ts} +7 -1
- package/src/hooks/useSaveLocation/index.ts +17 -0
- package/src/hooks/useSaveLocation/queries.ts +19 -0
- package/src/hooks/useSchedule/{index.jsx → index.ts} +16 -4
- package/src/hooks/useSchedule/{index.js → schedule.ts} +22 -15
- package/src/hooks/useScheduleData/{index.js → index.ts} +21 -9
- package/src/hooks/useSetImageProducts/index.ts +59 -0
- package/src/hooks/useSetImageProducts/queries.ts +18 -0
- package/src/hooks/useSetSession/{index.js → index.ts} +16 -17
- package/src/hooks/useSetupSchedule/helpers/index.ts +85 -0
- package/src/hooks/useSetupSchedule/index.ts +284 -0
- package/src/hooks/useStatusOpenStore/helpers/index.ts +124 -0
- package/src/hooks/useStatusOpenStore/{index.js → index.ts} +39 -16
- package/src/hooks/useStatusOrdersClient/{index.js → index.ts} +3 -2
- package/src/hooks/useStatusOrdersClient/{queries.js → queries.ts} +2 -2
- package/src/hooks/useStock/index.ts +1 -0
- package/src/hooks/useStock/useStockUpdatedAllSubscription.ts +40 -0
- package/src/hooks/useStockMovements/helpers/index.ts +16 -0
- package/src/hooks/useStockMovements/index.ts +39 -0
- package/src/hooks/useStore/index.ts +83 -0
- package/src/hooks/useStore/{queries.js → queries.ts} +71 -71
- package/src/hooks/useStoreContacts/{index.js → index.ts} +11 -5
- package/src/hooks/useStoreTable/index.ts +2 -0
- package/src/hooks/useStoreTable/queries.ts +47 -0
- package/src/hooks/useStoreTable/useStoreTableCreate.ts +77 -0
- package/src/hooks/useStoreTable/useStoreTables.ts +15 -0
- package/src/hooks/useSubscriptionValidation/index.ts +112 -0
- package/src/hooks/useTagProducts/index.ts +3 -0
- package/src/hooks/useTagProducts/useDeleteOneTag.ts +106 -0
- package/src/hooks/useTagProducts/useGetAllTags.ts +68 -0
- package/src/hooks/useTagProducts/useRegisterMultipleTags.ts +157 -0
- package/src/hooks/useTheme/index.ts +65 -0
- package/src/hooks/useTimeAgo/{useTimeAgo.js → useTimeAgo.ts} +7 -7
- package/src/hooks/useTokenCards/index.ts +45 -0
- package/src/hooks/useTopProductsMovements/index.ts +27 -0
- package/src/hooks/useTotalAllSales/index.ts +25 -0
- package/src/hooks/useTotalProductsInStock/index.ts +23 -0
- package/src/hooks/useTotalProductsSold/index.ts +23 -0
- package/src/hooks/useTotalProductsSolded/index.ts +20 -0
- package/src/hooks/useUpdateCart/{index.js → index.ts} +3 -2
- package/src/hooks/useUpdateCartCookie/index.ts +60 -0
- package/src/hooks/useUpdateDashboardComponent/index.ts +91 -0
- package/src/hooks/useUpdateExistingOrders/{index.js → index.ts} +5 -11
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.ts +61 -0
- package/src/hooks/useUpdateModuleOrder/index.ts +37 -0
- package/src/hooks/useUpdateMultipleExtProduct/index.ts +34 -0
- package/src/hooks/useUpdateMultipleExtProduct/queries.ts +33 -0
- package/src/hooks/useUpdateMultipleProducts/index.ts +117 -0
- package/src/hooks/useUpdateMultipleProducts/queries.ts +51 -0
- package/src/hooks/useUploadProducts/helpers/index.ts +1 -0
- package/src/hooks/useUploadProducts/helpers/parseNumber.ts +37 -0
- package/src/hooks/useUploadProducts/helpers/validateProductDataExcel.ts +73 -0
- package/src/hooks/useUploadProducts/index.ts +442 -0
- package/src/hooks/useUpsertGoal/index.ts +68 -0
- package/src/hooks/useUser/{index.js → index.ts} +11 -4
- package/src/hooks/useUser/{queries.js → queries.ts} +9 -4
- package/src/hooks/useWeeklyStockMovement/helpers/index.ts +32 -0
- package/src/hooks/useWeeklyStockMovement/index.ts +52 -0
- package/src/hooks/useWindowSize/{index.js → index.ts} +9 -2
- package/src/index.ts +12 -0
- package/src/security/index.ts +1 -0
- package/src/services/index.ts +1 -0
- package/src/utils/UtilDateRange.ts +56 -0
- package/src/utils/generateCode.ts +222 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/utils.ts +344 -0
- package/tsconfig.eslint.json +17 -0
- package/tsconfig.json +21 -0
- package/tsup.config.ts +24 -0
- package/.eslintrc.js +0 -38
- package/.eslintrc.json +0 -127
- package/next.config.js +0 -126
- package/src/config/client/errors.js +0 -26
- package/src/hooks/getGlobalSession/index.js +0 -49
- package/src/hooks/getSession/index.js +0 -18
- package/src/hooks/handleLogin/index.js +0 -10
- package/src/hooks/index.js +0 -77
- package/src/hooks/useAcumulateDate/index.js +0 -16
- package/src/hooks/useAsideCart/index.js +0 -155
- package/src/hooks/useCategoryInStore/index.js +0 -98
- package/src/hooks/useClients/queries.js +0 -127
- package/src/hooks/useConnection/index.js +0 -22
- package/src/hooks/useCreateProduct/index.js +0 -291
- package/src/hooks/useDevices/index.js +0 -35
- package/src/hooks/useDevices/queries.js +0 -19
- package/src/hooks/useEditOneExtProductFoodOptional/index.js +0 -28
- package/src/hooks/useEditSubProductOptional/index.js +0 -11
- package/src/hooks/useEmployee/index.js +0 -13
- package/src/hooks/useEmployee/queries.js +0 -17
- package/src/hooks/useFavoriteStores/index.js +0 -19
- package/src/hooks/useFavoriteStores/queries.js +0 -47
- package/src/hooks/useFormTools/index.js +0 -100
- package/src/hooks/useFormatDate/index.js +0 -33
- package/src/hooks/useGetStoreCookie/index.js +0 -22
- package/src/hooks/useImagesStore/index.js +0 -183
- package/src/hooks/useLogout/helpers/BroadcastChannel.js +0 -32
- package/src/hooks/useLogout/helpers/apiBaseUrl.js +0 -8
- package/src/hooks/useLogout/helpers/fetchData.js +0 -29
- package/src/hooks/useLogout/helpers/getCsrfToken.js +0 -30
- package/src/hooks/useLogout/helpers/index.js +0 -54
- package/src/hooks/useLogout/helpers/logger.js +0 -72
- package/src/hooks/useLogout/helpers/parseUrl.js +0 -36
- package/src/hooks/useLogout/index.js +0 -46
- package/src/hooks/useManageQueryParams/index.js +0 -37
- package/src/hooks/useMobile/index.js +0 -39
- package/src/hooks/useOrders/queries.js +0 -328
- package/src/hooks/useProductsFood/index.js +0 -234
- package/src/hooks/useProductsFood/useEditProduct.js +0 -8
- package/src/hooks/useProductsFood/usetagsProducts.js +0 -94
- package/src/hooks/useRestaurant/index.js +0 -19
- package/src/hooks/useSales/helpers/index.js +0 -8
- package/src/hooks/useSales/index.js +0 -1102
- package/src/hooks/useSales/useGetSale.js +0 -13
- package/src/hooks/useSales/useTotalSales.js +0 -24
- package/src/hooks/useStore/index.js +0 -70
- package/src/hooks/useUpdateExtProductFoodsSubOptional/index.js +0 -38
- package/src/index.jsx +0 -4
- package/src/utils/index.js +0 -141
- /package/src/config/client/{index.js → index.ts} +0 -0
- /package/src/hooks/getCategoriesWithProduct/helpers/{index.js → index.ts} +0 -0
- /package/src/hooks/useAnimationFrame/{index.js → index.ts} +0 -0
- /package/src/hooks/useAsideCart/helpers/{index.js → index.ts} +0 -0
- /package/src/hooks/useAsideCart/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useCart/{index.js → index.ts} +0 -0
- /package/src/hooks/useDeleteSubProductOptional/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useDessert/helpers/{index.js → index.ts} +0 -0
- /package/src/hooks/useDynamicAuth/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useEditSubProductOptional/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useFetchJson/{index.js → index.ts} +0 -0
- /package/src/hooks/useFormatNumberPhone/{index.js → index.ts} +0 -0
- /package/src/hooks/useGenerateNumberArray/{index.js → index.ts} +0 -0
- /package/src/hooks/useGetFoodRecomended/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useGetMinPrice/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useGetOneStoreRating/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useGoogleLogin/{loadScript.js → loadScript.ts} +0 -0
- /package/src/hooks/useGoogleLogin/{removeScript.js → removeScript.ts} +0 -0
- /package/src/hooks/useInnerHtml/{index.js → index.ts} +0 -0
- /package/src/hooks/useKeypress/{index.js → index.ts} +0 -0
- /package/src/hooks/useLocationNavigate/{index.js → index.ts} +0 -0
- /package/src/{security/index.js → hooks/useManageNewOrder/helpers/mock.ts} +0 -0
- /package/src/hooks/useMutateHeight/{index.js → index.ts} +0 -0
- /package/src/hooks/useOrderClient/{index.js → index.ts} +0 -0
- /package/src/hooks/useProviders/{index.js → index.ts} +0 -0
- /package/src/hooks/useProviders/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useProvidersStore/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useReactToPrint/{index.js → index.txt} +0 -0
- /package/src/hooks/useSaveAvailableProduct/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useSchedule/{queries.js → queries.ts} +0 -0
- /package/src/hooks/useScroll/{index.js → index.ts} +0 -0
- /package/src/hooks/useScrollRotate/{index.js → index.ts} +0 -0
- /package/src/hooks/useSetState/{index.js → index.ts} +0 -0
- /package/src/hooks/useStatusOrdersClient/helpers/{index.js → index.ts} +0 -0
- /package/src/hooks/useStoreCalendar/{index.js → index.ts} +0 -0
- /package/src/hooks/useStoreContacts/{queries.js → queries.ts} +0 -0
- /package/src/mock/dessert/{index.js → index.ts} +0 -0
- /package/src/mock/{index.js → index.ts} +0 -0
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { gql } from '@apollo/client'
|
|
2
|
-
|
|
3
|
-
export const GET_ALL_FAV_STORE = gql`
|
|
4
|
-
query getFavorite{
|
|
5
|
-
getFavorite{
|
|
6
|
-
fIStoreId
|
|
7
|
-
fState
|
|
8
|
-
createAt
|
|
9
|
-
updateAt
|
|
10
|
-
idStore
|
|
11
|
-
|
|
12
|
-
getOneStore {
|
|
13
|
-
idStore
|
|
14
|
-
cId
|
|
15
|
-
id
|
|
16
|
-
Image
|
|
17
|
-
open
|
|
18
|
-
cateStore{
|
|
19
|
-
catStore
|
|
20
|
-
cName
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
ctId
|
|
24
|
-
catStore
|
|
25
|
-
dId
|
|
26
|
-
storeName
|
|
27
|
-
Image
|
|
28
|
-
city{
|
|
29
|
-
ctId
|
|
30
|
-
dId
|
|
31
|
-
cName
|
|
32
|
-
}
|
|
33
|
-
department {
|
|
34
|
-
dId
|
|
35
|
-
cId
|
|
36
|
-
dName
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
pais {
|
|
40
|
-
cId
|
|
41
|
-
cName
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
`
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
useCallback,
|
|
3
|
-
useEffect,
|
|
4
|
-
useState
|
|
5
|
-
} from 'react'
|
|
6
|
-
import { validationSubmitHooks } from '../../utils'
|
|
7
|
-
/**
|
|
8
|
-
* @version 0.0.1
|
|
9
|
-
* @description Hook con herramientas de validación y eventos de cambio
|
|
10
|
-
* @return {Array} devuelve la función onChange a ejecutar y el estado de error de cada input
|
|
11
|
-
*/
|
|
12
|
-
export const useFormTools = ({ sendNotification = () => { } } = {}) => {
|
|
13
|
-
const [dataForm, setDataForm] = useState({})
|
|
14
|
-
const [errorForm, setErrorForm] = useState({})
|
|
15
|
-
const [errorSubmit, setErrorSubmit] = useState(false)
|
|
16
|
-
const [calledSubmit, setCalledSubmit] = useState(false)
|
|
17
|
-
// Handle Change
|
|
18
|
-
const handleChange = useCallback((e, error) => {
|
|
19
|
-
setDataForm({ ...dataForm, [e.target.name]: e.target.value })
|
|
20
|
-
setErrorForm({ ...errorForm, [e.target.name]: error })
|
|
21
|
-
}, [setDataForm, dataForm, errorForm, setErrorForm])
|
|
22
|
-
|
|
23
|
-
// Forzar datos desde una ventana externa
|
|
24
|
-
const handleForcedData = useCallback(data => {
|
|
25
|
-
setDataForm(data)
|
|
26
|
-
}, [setDataForm])
|
|
27
|
-
|
|
28
|
-
// Forzar datos de error desde una ventana externa
|
|
29
|
-
const setForcedError = useCallback(errors => {
|
|
30
|
-
setErrorForm(errors)
|
|
31
|
-
}, [setErrorForm])
|
|
32
|
-
|
|
33
|
-
// Handle submit, al enviar formulario
|
|
34
|
-
const listErrors = Object.values(errorForm)
|
|
35
|
-
const errors = listErrors.find((error) => {
|
|
36
|
-
return error === true
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
const handleSubmit = ({
|
|
40
|
-
event,
|
|
41
|
-
msgError = '',
|
|
42
|
-
msgSuccess,
|
|
43
|
-
action = () => { },
|
|
44
|
-
actionAfterSuccess = () => { }
|
|
45
|
-
}) => {
|
|
46
|
-
event.preventDefault()
|
|
47
|
-
setCalledSubmit(true)
|
|
48
|
-
let errSub = false
|
|
49
|
-
|
|
50
|
-
// Valida los errores locales
|
|
51
|
-
for (const x in errorForm) {
|
|
52
|
-
if (errorForm[x]) errSub = true
|
|
53
|
-
}
|
|
54
|
-
if (errSub) {
|
|
55
|
-
sendNotification({
|
|
56
|
-
title: 'Completa los campos requeridos',
|
|
57
|
-
description: 'Error',
|
|
58
|
-
backgroundColor: 'error'
|
|
59
|
-
})
|
|
60
|
-
}
|
|
61
|
-
if (errors) {
|
|
62
|
-
setErrorSubmit(true)
|
|
63
|
-
return setForcedError({ ...errorForm })
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (errSub) return setErrorSubmit(errSub)
|
|
67
|
-
|
|
68
|
-
// Valida los errores desde el evento
|
|
69
|
-
const errores = validationSubmitHooks(event.target.elements)
|
|
70
|
-
setErrorForm(errores)
|
|
71
|
-
for (const x in errores) {
|
|
72
|
-
if (errores[x]) errSub = true
|
|
73
|
-
}
|
|
74
|
-
if (errSub) return setErrorSubmit(errSub)
|
|
75
|
-
|
|
76
|
-
// Ejecuta la accion si es válido
|
|
77
|
-
if (!errSub && action) {
|
|
78
|
-
action().then(res => {
|
|
79
|
-
if (res) {
|
|
80
|
-
sendNotification({
|
|
81
|
-
message: msgSuccess || 'Operación exitosa',
|
|
82
|
-
description: 'Operación exitosa',
|
|
83
|
-
backgroundColor: 'success'
|
|
84
|
-
})
|
|
85
|
-
!!actionAfterSuccess && actionAfterSuccess()
|
|
86
|
-
}
|
|
87
|
-
}).catch(e => { return sendNotification({ title: msgError || e?.message || 'Ha ocurrido un error', backgroundColor: 'error' }) })
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
setErrorSubmit(errSub)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
useEffect(() => { return setCalledSubmit(false) }, [calledSubmit])
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
return setCalledSubmit(false)
|
|
96
|
-
},
|
|
97
|
-
[])
|
|
98
|
-
|
|
99
|
-
return [handleChange, handleSubmit, handleForcedData, { dataForm, errorForm, errorSubmit, calledSubmit, setForcedError }]
|
|
100
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export const useFormatDate = ({
|
|
2
|
-
date,
|
|
3
|
-
local = 'ES'
|
|
4
|
-
} = {}) => {
|
|
5
|
-
const dateToFormat = new Date(date ?? Date.now())
|
|
6
|
-
const fullDate = dateToFormat.toLocaleDateString(local, { year: 'numeric', month: '2-digit', day: '2-digit' })
|
|
7
|
-
const day = fullDate.split('/')[0]
|
|
8
|
-
const month = fullDate.split('/')[1]
|
|
9
|
-
const year = fullDate.split('/')[2]
|
|
10
|
-
const yearMonthDay = dateToFormat.toLocaleDateString('en-CA')
|
|
11
|
-
const numberDay = dateToFormat.getDay()
|
|
12
|
-
const shortDayName = dateToFormat.toLocaleDateString(local, { weekday: 'short' })
|
|
13
|
-
const longDayName = dateToFormat.toLocaleDateString(local, { weekday: 'long' })
|
|
14
|
-
const hourMinutes12 = dateToFormat.toLocaleTimeString('ES-CO', { hour: '2-digit', minute: '2-digit' })
|
|
15
|
-
const hourMinutes24 = dateToFormat.toLocaleTimeString('ES-CO', { hour: '2-digit', minute: '2-digit', hour12: false })
|
|
16
|
-
const handleHourPmAM = (hour) => {
|
|
17
|
-
const hourPmAm = new Date(`1/1/1999 ${hour}`).toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true })
|
|
18
|
-
return hour ? hourPmAm : ''
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
day,
|
|
22
|
-
fullDate,
|
|
23
|
-
hourMinutes12,
|
|
24
|
-
numberDay,
|
|
25
|
-
yearMonthDay,
|
|
26
|
-
hourMinutes24,
|
|
27
|
-
longDayName,
|
|
28
|
-
shortDayName,
|
|
29
|
-
month,
|
|
30
|
-
year,
|
|
31
|
-
handleHourPmAM
|
|
32
|
-
}
|
|
33
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect } from 'react';
|
|
2
|
-
import Cookies from 'js-cookie';
|
|
3
|
-
|
|
4
|
-
export const useGetStoreCookie = () => {
|
|
5
|
-
const [vpStoreCookie, setVpStoreCookie] = useState(null);
|
|
6
|
-
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const getCookieValue = () => {
|
|
9
|
-
const cookieValue = Cookies.get(process.env.SESSION_NAME);
|
|
10
|
-
console.log('Cookie Value:', cookieValue);
|
|
11
|
-
|
|
12
|
-
if (cookieValue) {
|
|
13
|
-
setVpStoreCookie(cookieValue);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
getCookieValue();
|
|
18
|
-
}, []); // Empty dependency array, so this effect runs once
|
|
19
|
-
|
|
20
|
-
return vpStoreCookie;
|
|
21
|
-
};
|
|
22
|
-
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import { useMutation } from '@apollo/client'
|
|
2
|
-
import {
|
|
3
|
-
useRef,
|
|
4
|
-
useState
|
|
5
|
-
} from 'react'
|
|
6
|
-
import {
|
|
7
|
-
CREATE_BANNER_STORE,
|
|
8
|
-
CREATE_LOGO,
|
|
9
|
-
DELETE_ONE_BANNER_STORE,
|
|
10
|
-
DELETE_ONE_LOGO_STORE,
|
|
11
|
-
GET_ONE_BANNER_STORE
|
|
12
|
-
} from '../useProductsFood/queriesStore'
|
|
13
|
-
import { GET_ONE_STORE } from '../useStore/queries'
|
|
14
|
-
export { GET_MIN_PEDIDO } from './queries'
|
|
15
|
-
export * from './queries'
|
|
16
|
-
|
|
17
|
-
export const useImageStore = ({ idStore, sendNotification = () => { } } = {}) => {
|
|
18
|
-
// STATES
|
|
19
|
-
const fileInputRef = useRef(null)
|
|
20
|
-
const [{ altLogo, srcLogo }, setPreviewImgLogo] = useState({})
|
|
21
|
-
const initialState = { alt: '/images/DEFAULTBANNER.png', src: '/images/DEFAULTBANNER.png' }
|
|
22
|
-
const [{ alt, src }, setPreviewImg] = useState(initialState)
|
|
23
|
-
const fileInputRefLogo = useRef(null)
|
|
24
|
-
// HOOKS
|
|
25
|
-
const [registerBanner] = useMutation(CREATE_BANNER_STORE, {
|
|
26
|
-
onCompleted: (data) => { return sendNotification({ message: data?.registerBanner?.message }) },
|
|
27
|
-
context: { clientName: 'admin-server' }
|
|
28
|
-
})
|
|
29
|
-
const [setALogoStore] = useMutation(CREATE_LOGO, {
|
|
30
|
-
onCompleted: (data) => { return sendNotification({ message: data?.setALogoStore?.message }) },
|
|
31
|
-
context: { clientName: 'admin-server' }
|
|
32
|
-
})
|
|
33
|
-
const [DeleteOneBanner] = useMutation(DELETE_ONE_BANNER_STORE, {
|
|
34
|
-
onCompleted: (data) => { return sendNotification({ message: data?.DeleteOneBanner?.message }) },
|
|
35
|
-
context: { clientName: 'admin-server' }
|
|
36
|
-
})
|
|
37
|
-
const [deleteALogoStore] = useMutation(DELETE_ONE_LOGO_STORE, {
|
|
38
|
-
onCompleted: (data) => {
|
|
39
|
-
sendNotification({
|
|
40
|
-
message: data.deleteALogoStore.message
|
|
41
|
-
})
|
|
42
|
-
setPreviewImgLogo(initialState)
|
|
43
|
-
},
|
|
44
|
-
context: { clientName: 'admin-server' },
|
|
45
|
-
update (cache) {
|
|
46
|
-
cache.modify({
|
|
47
|
-
fields: {
|
|
48
|
-
getStore (dataOld = []) {
|
|
49
|
-
return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
// HANDLESS
|
|
56
|
-
const handleDeleteLogo = () => {
|
|
57
|
-
return deleteALogoStore({
|
|
58
|
-
variables: {
|
|
59
|
-
Image: ''
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const handleUpdateBanner = event => {
|
|
65
|
-
try {
|
|
66
|
-
const { files } = event.target
|
|
67
|
-
setPreviewImg(
|
|
68
|
-
files.length
|
|
69
|
-
? {
|
|
70
|
-
src: URL.createObjectURL(files[0]),
|
|
71
|
-
alt: files[0].name
|
|
72
|
-
}
|
|
73
|
-
: initialState
|
|
74
|
-
)
|
|
75
|
-
registerBanner({
|
|
76
|
-
variables: {
|
|
77
|
-
input: {
|
|
78
|
-
bnImage: files[0],
|
|
79
|
-
idStore
|
|
80
|
-
}
|
|
81
|
-
},
|
|
82
|
-
update (cache) {
|
|
83
|
-
cache.modify({
|
|
84
|
-
fields: {
|
|
85
|
-
getOneBanners (dataOld = []) {
|
|
86
|
-
return cache.writeQuery({ query: GET_ONE_BANNER_STORE, data: dataOld })
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
}).catch(() => {
|
|
92
|
-
sendNotification({
|
|
93
|
-
title: 'No pudimos cargar la imagen',
|
|
94
|
-
description: 'Error',
|
|
95
|
-
backgroundColor: 'error'
|
|
96
|
-
})
|
|
97
|
-
setPreviewImg(initialState)
|
|
98
|
-
})
|
|
99
|
-
} catch {
|
|
100
|
-
setPreviewImg(initialState)
|
|
101
|
-
sendNotification({
|
|
102
|
-
title: 'No pudimos cargar la imagen',
|
|
103
|
-
description: 'Error',
|
|
104
|
-
backgroundColor: 'error'
|
|
105
|
-
})
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
const handleInputChangeLogo = event => {
|
|
109
|
-
const { files } = event.target
|
|
110
|
-
setPreviewImgLogo(
|
|
111
|
-
files.length
|
|
112
|
-
? {
|
|
113
|
-
srcLogo: URL.createObjectURL(files[0]),
|
|
114
|
-
altLogo: files[0].name
|
|
115
|
-
}
|
|
116
|
-
: initialState
|
|
117
|
-
)
|
|
118
|
-
setALogoStore({
|
|
119
|
-
variables: {
|
|
120
|
-
logo: files[0],
|
|
121
|
-
idStore
|
|
122
|
-
},
|
|
123
|
-
update (cache) {
|
|
124
|
-
cache.modify({
|
|
125
|
-
fields: {
|
|
126
|
-
getStore (dataOld = []) {
|
|
127
|
-
return cache.writeQuery({ query: GET_ONE_STORE, data: dataOld })
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
})
|
|
131
|
-
}
|
|
132
|
-
}).catch(() => {
|
|
133
|
-
sendNotification({
|
|
134
|
-
title: 'No pudimos cargar la imagen',
|
|
135
|
-
description: 'Error',
|
|
136
|
-
backgroundColor: 'error'
|
|
137
|
-
})
|
|
138
|
-
setPreviewImgLogo(initialState)
|
|
139
|
-
})
|
|
140
|
-
}
|
|
141
|
-
const HandleDeleteBanner = async () => {
|
|
142
|
-
setPreviewImg(initialState)
|
|
143
|
-
DeleteOneBanner({
|
|
144
|
-
variables: {
|
|
145
|
-
idStore
|
|
146
|
-
},
|
|
147
|
-
update (cache) {
|
|
148
|
-
cache.modify({
|
|
149
|
-
fields: {
|
|
150
|
-
getOneBanners (dataOld = []) {
|
|
151
|
-
return cache.writeQuery({ query: GET_ONE_BANNER_STORE, data: dataOld })
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
})
|
|
155
|
-
}
|
|
156
|
-
}).then(() => {
|
|
157
|
-
setPreviewImg(initialState)
|
|
158
|
-
})
|
|
159
|
-
}
|
|
160
|
-
const onTargetClickLogo = e => {
|
|
161
|
-
e.preventDefault()
|
|
162
|
-
fileInputRefLogo.current.click()
|
|
163
|
-
}
|
|
164
|
-
const onTargetClick = e => {
|
|
165
|
-
e.preventDefault()
|
|
166
|
-
fileInputRef.current.click()
|
|
167
|
-
}
|
|
168
|
-
return {
|
|
169
|
-
fileInputRefLogo,
|
|
170
|
-
src,
|
|
171
|
-
alt,
|
|
172
|
-
initialState,
|
|
173
|
-
srcLogo,
|
|
174
|
-
altLogo,
|
|
175
|
-
fileInputRef,
|
|
176
|
-
handleDeleteLogo,
|
|
177
|
-
onTargetClick,
|
|
178
|
-
onTargetClickLogo,
|
|
179
|
-
HandleDeleteBanner,
|
|
180
|
-
handleInputChangeLogo,
|
|
181
|
-
handleUpdateBanner
|
|
182
|
-
}
|
|
183
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
function BroadcastChannel(name = "nextauth.message") {
|
|
2
|
-
return {
|
|
3
|
-
receive: function (onReceive) {
|
|
4
|
-
const handler = function (event) {
|
|
5
|
-
if (event.key !== name) return;
|
|
6
|
-
const message = JSON.parse(event.newValue ?? "{}");
|
|
7
|
-
if (message?.event !== "session" || !message?.data) return;
|
|
8
|
-
onReceive(message);
|
|
9
|
-
};
|
|
10
|
-
window.addEventListener("storage", handler);
|
|
11
|
-
return function () {
|
|
12
|
-
window.removeEventListener("storage", handler);
|
|
13
|
-
};
|
|
14
|
-
},
|
|
15
|
-
post: function (message) {
|
|
16
|
-
if (typeof window === "undefined") return;
|
|
17
|
-
try {
|
|
18
|
-
localStorage.setItem(
|
|
19
|
-
name,
|
|
20
|
-
JSON.stringify({ ...message, timestamp: now() })
|
|
21
|
-
);
|
|
22
|
-
} catch {
|
|
23
|
-
// The localStorage API isn't always available.
|
|
24
|
-
// It won't work in private mode prior to Safari 11 for example.
|
|
25
|
-
// Notifications are simply dropped if an error is encountered.
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export { BroadcastChannel };
|
|
32
|
-
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export function apiBaseUrl(__NEXTAUTH) {
|
|
2
|
-
if (typeof window === "undefined") {
|
|
3
|
-
// Return absolute path when called server side
|
|
4
|
-
return `${__NEXTAUTH.baseUrlServer}${__NEXTAUTH.basePathServer}`
|
|
5
|
-
}
|
|
6
|
-
// Return relative path when called client side
|
|
7
|
-
return __NEXTAUTH.basePath
|
|
8
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { apiBaseUrl } from "./apiBaseUrl";
|
|
2
|
-
|
|
3
|
-
async function fetchData(path, __NEXTAUTH, logger, { ctx, req } = {}) {
|
|
4
|
-
const url = `${apiBaseUrl(__NEXTAUTH)}/${path}`;
|
|
5
|
-
try {
|
|
6
|
-
const options = {
|
|
7
|
-
headers: {
|
|
8
|
-
"Content-Type": "application/json",
|
|
9
|
-
...(req?.headers?.cookie ? { cookie: req.headers.cookie } : {}),
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
if (req?.body) {
|
|
14
|
-
options.body = JSON.stringify(req.body);
|
|
15
|
-
options.method = "POST";
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const res = await fetch(url, options);
|
|
19
|
-
const data = await res.json();
|
|
20
|
-
if (!res.ok) throw data;
|
|
21
|
-
return Object.keys(data).length > 0 ? data : null; // Return null if data is empty
|
|
22
|
-
} catch (error) {
|
|
23
|
-
logger.error("CLIENT_FETCH_ERROR", { error, url });
|
|
24
|
-
return null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export { fetchData };
|
|
29
|
-
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { fetchData } from "./fetchData"
|
|
2
|
-
import _logger, { proxyLogger } from "./logger"
|
|
3
|
-
import { parseUrl } from "./parseUrl";
|
|
4
|
-
|
|
5
|
-
const __NEXTAUTH = {
|
|
6
|
-
baseUrl: parseUrl(process.env.NEXTAUTH_URL || process.env.VERCEL_URL).origin,
|
|
7
|
-
basePath: parseUrl(process.env.NEXTAUTH_URL).path,
|
|
8
|
-
baseUrlServer: parseUrl(
|
|
9
|
-
process.env.NEXTAUTH_URL_INTERNAL ||
|
|
10
|
-
process.env.NEXTAUTH_URL ||
|
|
11
|
-
process.env.VERCEL_URL
|
|
12
|
-
).origin,
|
|
13
|
-
basePathServer: parseUrl(
|
|
14
|
-
process.env.NEXTAUTH_URL_INTERNAL || process.env.NEXTAUTH_URL
|
|
15
|
-
).path,
|
|
16
|
-
_lastSync: 0,
|
|
17
|
-
_session: undefined,
|
|
18
|
-
_getSession: () => {},
|
|
19
|
-
};
|
|
20
|
-
const logger = proxyLogger(_logger, __NEXTAUTH.basePath)
|
|
21
|
-
|
|
22
|
-
export async function getCsrfToken(params) {
|
|
23
|
-
const response = await fetchData(
|
|
24
|
-
"csrf",
|
|
25
|
-
__NEXTAUTH,
|
|
26
|
-
logger,
|
|
27
|
-
params
|
|
28
|
-
)
|
|
29
|
-
return response?.csrfToken
|
|
30
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { apiBaseUrl } from "./apiBaseUrl";
|
|
2
|
-
import { getCsrfToken } from "./getCsrfToken";
|
|
3
|
-
import { parseUrl } from "./parseUrl";
|
|
4
|
-
import { BroadcastChannel } from "./BroadcastChannel";
|
|
5
|
-
|
|
6
|
-
const broadcast = BroadcastChannel()
|
|
7
|
-
|
|
8
|
-
export const __NEXTAUTH = {
|
|
9
|
-
baseUrl: parseUrl(process.env.NEXTAUTH_URL || process.env.VERCEL_URL).origin,
|
|
10
|
-
basePath: parseUrl(process.env.NEXTAUTH_URL).path,
|
|
11
|
-
baseUrlServer: parseUrl(
|
|
12
|
-
process.env.NEXTAUTH_URL_INTERNAL ||
|
|
13
|
-
process.env.NEXTAUTH_URL ||
|
|
14
|
-
process.env.VERCEL_URL
|
|
15
|
-
).origin,
|
|
16
|
-
basePathServer: parseUrl(
|
|
17
|
-
process.env.NEXTAUTH_URL_INTERNAL || process.env.NEXTAUTH_URL
|
|
18
|
-
).path,
|
|
19
|
-
_lastSync: 0,
|
|
20
|
-
_session: undefined,
|
|
21
|
-
_getSession: () => {},
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export async function signOutAuth(options) {
|
|
25
|
-
const { callbackUrl = window.location.href } = options ?? {}
|
|
26
|
-
const baseUrl = apiBaseUrl(__NEXTAUTH)
|
|
27
|
-
const fetchOptions = {
|
|
28
|
-
method: "post",
|
|
29
|
-
headers: {
|
|
30
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
31
|
-
},
|
|
32
|
-
// @ts-expect-error
|
|
33
|
-
body: new URLSearchParams({
|
|
34
|
-
csrfToken: await getCsrfToken(),
|
|
35
|
-
callbackUrl,
|
|
36
|
-
json: true,
|
|
37
|
-
}),
|
|
38
|
-
}
|
|
39
|
-
const res = await fetch(`${baseUrl}/signout`, fetchOptions)
|
|
40
|
-
const data = await res.json()
|
|
41
|
-
|
|
42
|
-
broadcast.post({ event: "session", data: { trigger: "signout" } })
|
|
43
|
-
|
|
44
|
-
if (options?.redirect ?? true) {
|
|
45
|
-
const url = data.url ?? callbackUrl
|
|
46
|
-
window.location.href = url
|
|
47
|
-
// If url contains a hash, the browser does not reload the page. We reload manually
|
|
48
|
-
if (url.includes("#")) window.location.reload()
|
|
49
|
-
// @ts-expect-error
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
await __NEXTAUTH._getSession({ event: "storage" })
|
|
53
|
-
return data
|
|
54
|
-
}
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
function formatError(o) {
|
|
2
|
-
if (hasErrorProperty(o)) {
|
|
3
|
-
o.error = formatError(o.error);
|
|
4
|
-
o.message = o.message ?? o.error.message;
|
|
5
|
-
}
|
|
6
|
-
return o;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function hasErrorProperty(x) {
|
|
10
|
-
return !!(x?.error);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const _logger = {
|
|
14
|
-
error(code, metadata) {
|
|
15
|
-
metadata = formatError(metadata);
|
|
16
|
-
console.error(
|
|
17
|
-
`[next-auth][error][${code}]`,
|
|
18
|
-
`\nhttps://next-auth.js.org/errors#${code.toLowerCase()}`,
|
|
19
|
-
metadata.message,
|
|
20
|
-
metadata
|
|
21
|
-
);
|
|
22
|
-
},
|
|
23
|
-
warn(code) {
|
|
24
|
-
console.warn(
|
|
25
|
-
`[next-auth][warn][${code}]`,
|
|
26
|
-
`\nhttps://next-auth.js.org/warnings#${code.toLowerCase()}`
|
|
27
|
-
);
|
|
28
|
-
},
|
|
29
|
-
debug(code, metadata) {
|
|
30
|
-
console.log(`[next-auth][debug][${code}]`, metadata);
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export function setLogger(newLogger = {}, debug) {
|
|
36
|
-
if (!debug) _logger.debug = () => {};
|
|
37
|
-
|
|
38
|
-
if (newLogger.error) _logger.error = newLogger.error;
|
|
39
|
-
if (newLogger.warn) _logger.warn = newLogger.warn;
|
|
40
|
-
if (newLogger.debug) _logger.debug = newLogger.debug;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function proxyLogger(logger = _logger, basePath) {
|
|
44
|
-
try {
|
|
45
|
-
if (typeof window === "undefined") {
|
|
46
|
-
return logger;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const clientLogger = {};
|
|
50
|
-
for (const level in logger) {
|
|
51
|
-
clientLogger[level] = (code, metadata) => {
|
|
52
|
-
_logger[level](code, metadata);
|
|
53
|
-
|
|
54
|
-
if (level === "error") {
|
|
55
|
-
metadata = formatError(metadata);
|
|
56
|
-
}
|
|
57
|
-
metadata.client = true;
|
|
58
|
-
const url = `${basePath}/_log`;
|
|
59
|
-
const body = new URLSearchParams({ level, code, ...metadata });
|
|
60
|
-
if (navigator.sendBeacon) {
|
|
61
|
-
return navigator.sendBeacon(url, body);
|
|
62
|
-
}
|
|
63
|
-
return fetch(url, { method: "POST", body, keepalive: true });
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
return clientLogger;
|
|
67
|
-
} catch {
|
|
68
|
-
return _logger;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
export { _logger as default };
|
|
72
|
-
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/** Interface for the internal URL structure */
|
|
2
|
-
const InternalUrl = {
|
|
3
|
-
origin: 'http://localhost:3000',
|
|
4
|
-
host: 'localhost:3000',
|
|
5
|
-
path: '/api/auth',
|
|
6
|
-
base: 'http://localhost:3000/api/auth',
|
|
7
|
-
toString: function() {
|
|
8
|
-
return this.base;
|
|
9
|
-
},
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/** Function to parse a URL-like object for server-side requests/redirects */
|
|
13
|
-
function parseUrl(url) {
|
|
14
|
-
const defaultUrl = new URL('http://localhost:3000/api/auth');
|
|
15
|
-
|
|
16
|
-
if (url && !url.startsWith('http')) {
|
|
17
|
-
url = `https://${url}`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const _url = new URL(url || defaultUrl);
|
|
21
|
-
const path = (_url.pathname === '/' ? defaultUrl.pathname : _url.pathname).replace(/\/$/, '');
|
|
22
|
-
|
|
23
|
-
const base = `${_url.origin}${path}`;
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
origin: _url.origin,
|
|
27
|
-
host: _url.host,
|
|
28
|
-
path,
|
|
29
|
-
base,
|
|
30
|
-
toString: function() {
|
|
31
|
-
return base;
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { InternalUrl, parseUrl };
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { useApolloClient } from '@apollo/client'
|
|
2
|
-
import { useState } from 'react'
|
|
3
|
-
import { Cookies } from '../../cookies'
|
|
4
|
-
import { signOutAuth } from './helpers'
|
|
5
|
-
export { signOutAuth } from './helpers'
|
|
6
|
-
|
|
7
|
-
export const useLogout = ({ setAlertBox = () => { } } = {}) => {
|
|
8
|
-
const [loading, setLoading] = useState(false)
|
|
9
|
-
const [error, setError] = useState(false)
|
|
10
|
-
const client = useApolloClient()
|
|
11
|
-
|
|
12
|
-
const onClickLogout = async () => {
|
|
13
|
-
try {
|
|
14
|
-
setLoading(true)
|
|
15
|
-
// Logout from the server
|
|
16
|
-
const logoutResponse = await window.fetch(`${process.env.URL_BASE}/api/auth/logout/`, {})
|
|
17
|
-
if (!logoutResponse.ok) return
|
|
18
|
-
await window
|
|
19
|
-
.fetch(`${process.env.URL_BASE}/api/auth/logout/`, {})
|
|
20
|
-
.then(res => {
|
|
21
|
-
if (res) {
|
|
22
|
-
Cookies.remove(process.env.SESSION_NAME)
|
|
23
|
-
Cookies.remove(process.env.LOCAL_SALES_STORE)
|
|
24
|
-
Cookies.remove('restaurant')
|
|
25
|
-
Cookies.remove('usuario')
|
|
26
|
-
Cookies.remove('session')
|
|
27
|
-
client?.clearStore()
|
|
28
|
-
setLoading(false)
|
|
29
|
-
console.log('Borrado todo')
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
signOutAuth({ redirect: true, callbackUrl: '/' })
|
|
33
|
-
.catch(() => {
|
|
34
|
-
setError(true)
|
|
35
|
-
setAlertBox({ message: 'Ocurrió un error al cerrar session' })
|
|
36
|
-
})
|
|
37
|
-
setLoading(false)
|
|
38
|
-
} catch (error) {
|
|
39
|
-
setLoading(false)
|
|
40
|
-
setError(true)
|
|
41
|
-
setAlertBox({ message: 'Ocurrió un error al cerrar session' })
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return [onClickLogout, { loading, error }]
|
|
46
|
-
}
|