@pagamio/frontend-commons-lib 0.8.175 → 0.8.183
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/lib/api/client.d.ts +88 -0
- package/lib/api/client.js +339 -0
- package/lib/api/context.d.ts +112 -0
- package/lib/api/context.js +105 -0
- package/lib/api/index.d.ts +4 -0
- package/lib/api/index.js +4 -0
- package/lib/api/swr.d.ts +46 -0
- package/lib/api/swr.js +124 -0
- package/lib/api/types.d.ts +145 -0
- package/lib/api/types.js +10 -0
- package/lib/auth/authenticators/AuthenticatorFactory.d.ts +25 -0
- package/lib/auth/authenticators/AuthenticatorFactory.js +32 -0
- package/lib/auth/authenticators/index.d.ts +7 -0
- package/lib/auth/authenticators/index.js +7 -0
- package/lib/auth/authenticators/processors/DefaultAuthenticatorProcessor.d.ts +21 -0
- package/lib/auth/authenticators/processors/DefaultAuthenticatorProcessor.js +26 -0
- package/lib/auth/authenticators/processors/StrapiAuthenticatorProcessor.d.ts +74 -0
- package/lib/auth/authenticators/processors/StrapiAuthenticatorProcessor.js +99 -0
- package/lib/auth/authenticators/types.d.ts +26 -0
- package/lib/auth/authenticators/types.js +9 -0
- package/lib/auth/components/AppBanner.d.ts +7 -0
- package/lib/auth/components/AppBanner.js +9 -0
- package/lib/auth/components/AuthCard.d.ts +8 -0
- package/lib/auth/components/AuthCard.js +14 -0
- package/lib/auth/components/AuthFormUtils.d.ts +58 -0
- package/lib/auth/components/AuthFormUtils.js +52 -0
- package/lib/auth/components/AuthPageLayout.d.ts +45 -0
- package/lib/auth/components/AuthPageLayout.js +12 -0
- package/lib/auth/components/ChangePasswordPage.d.ts +12 -0
- package/lib/auth/components/ChangePasswordPage.js +59 -0
- package/lib/auth/components/CustomerRegistrationPage.d.ts +50 -0
- package/lib/auth/components/CustomerRegistrationPage.js +140 -0
- package/lib/auth/components/ForgotPasswordPage.d.ts +38 -0
- package/lib/auth/components/ForgotPasswordPage.js +76 -0
- package/lib/auth/components/LoginPage.d.ts +73 -0
- package/lib/auth/components/LoginPage.js +115 -0
- package/lib/auth/components/LogoutButton.d.ts +30 -0
- package/lib/auth/components/LogoutButton.js +47 -0
- package/lib/auth/components/ResetPasswordPage.d.ts +42 -0
- package/lib/auth/components/ResetPasswordPage.js +88 -0
- package/lib/auth/components/hooks/useChangeUserPassword.d.ts +26 -0
- package/lib/auth/components/hooks/useChangeUserPassword.js +63 -0
- package/lib/auth/components/index.d.ts +8 -0
- package/lib/auth/components/index.js +7 -0
- package/lib/auth/context/AuthContext.d.ts +65 -0
- package/lib/auth/context/AuthContext.js +150 -0
- package/lib/auth/context/index.d.ts +1 -0
- package/lib/auth/context/index.js +1 -0
- package/lib/auth/index.d.ts +7 -0
- package/lib/auth/index.js +7 -0
- package/lib/auth/services/AuthService.d.ts +230 -0
- package/lib/auth/services/AuthService.js +475 -0
- package/lib/auth/services/LogoutService.d.ts +27 -0
- package/lib/auth/services/LogoutService.js +98 -0
- package/lib/auth/services/index.d.ts +2 -0
- package/lib/auth/services/index.js +2 -0
- package/lib/auth/shared/index.d.ts +1 -0
- package/lib/auth/shared/index.js +1 -0
- package/lib/auth/shared/layout/AuthPageLayout.d.ts +10 -0
- package/lib/auth/shared/layout/AuthPageLayout.js +16 -0
- package/lib/auth/shared/layout/index.d.ts +1 -0
- package/lib/auth/shared/layout/index.js +1 -0
- package/lib/auth/types/auth.types.d.ts +234 -0
- package/lib/auth/types/auth.types.js +14 -0
- package/lib/auth/types/index.d.ts +1 -0
- package/lib/auth/types/index.js +1 -0
- package/lib/auth/utils/TokenManager.d.ts +43 -0
- package/lib/auth/utils/TokenManager.js +171 -0
- package/lib/auth/utils/Transformers.d.ts +158 -0
- package/lib/auth/utils/Transformers.js +263 -0
- package/lib/auth/utils/errorDetection.d.ts +22 -0
- package/lib/auth/utils/errorDetection.js +190 -0
- package/lib/auth/utils/index.d.ts +3 -0
- package/lib/auth/utils/index.js +3 -0
- package/lib/components/charts/LineGraph.d.ts +15 -0
- package/lib/components/charts/LineGraph.js +131 -0
- package/lib/components/icons/Icon.d.ts +8 -0
- package/lib/components/icons/Icon.js +13 -0
- package/lib/components/icons/index.d.ts +2 -0
- package/lib/components/icons/index.js +2 -0
- package/lib/components/icons/types.d.ts +26 -0
- package/lib/components/icons/types.js +33 -0
- package/lib/components/index.d.ts +3 -0
- package/lib/components/index.js +3 -0
- package/lib/components/layout/AppLayout.d.ts +34 -0
- package/lib/components/layout/AppLayout.js +19 -0
- package/lib/components/layout/AuthPageLayout.d.ts +13 -0
- package/lib/components/layout/AuthPageLayout.js +15 -0
- package/lib/components/layout/BreadcrumbNav.d.ts +2 -0
- package/lib/components/layout/BreadcrumbNav.js +10 -0
- package/lib/components/layout/LayoutContent.d.ts +6 -0
- package/lib/components/layout/LayoutContent.js +10 -0
- package/lib/components/layout/Navbar.d.ts +106 -0
- package/lib/components/layout/Navbar.js +66 -0
- package/lib/components/layout/PageHeader.d.ts +8 -0
- package/lib/components/layout/PageHeader.js +7 -0
- package/lib/components/layout/SessionExpiryModal.d.ts +10 -0
- package/lib/components/layout/SessionExpiryModal.js +9 -0
- package/lib/components/layout/Sidebar.d.ts +6 -0
- package/lib/components/layout/Sidebar.js +87 -0
- package/lib/components/layout/VerticalTabsLayout.d.ts +12 -0
- package/lib/components/layout/VerticalTabsLayout.js +14 -0
- package/lib/components/layout/index.d.ts +9 -0
- package/lib/components/layout/index.js +9 -0
- package/lib/components/ui/Avatar.d.ts +6 -0
- package/lib/components/ui/Avatar.js +11 -0
- package/lib/components/ui/AvatarIcon.d.ts +4 -0
- package/lib/components/ui/AvatarIcon.js +6 -0
- package/lib/components/ui/Button.d.ts +14 -0
- package/lib/components/ui/Button.js +30 -0
- package/lib/components/ui/Calendar.d.ts +9 -0
- package/lib/components/ui/Calendar.js +35 -0
- package/lib/components/ui/Card.d.ts +16 -0
- package/lib/components/ui/Card.js +6 -0
- package/lib/components/ui/Chart.d.ts +2 -0
- package/lib/components/ui/Chart.js +16 -0
- package/lib/components/ui/Checkbox.d.ts +4 -0
- package/lib/components/ui/Checkbox.js +8 -0
- package/lib/components/ui/Command.d.ts +80 -0
- package/lib/components/ui/Command.js +28 -0
- package/lib/components/ui/ContainedTab.d.ts +21 -0
- package/lib/components/ui/ContainedTab.js +37 -0
- package/lib/components/ui/DateFormat.d.ts +6 -0
- package/lib/components/ui/DateFormat.js +8 -0
- package/lib/components/ui/DatePicker.d.ts +14 -0
- package/lib/components/ui/DatePicker.js +91 -0
- package/lib/components/ui/DateRangeModal.d.ts +38 -0
- package/lib/components/ui/DateRangeModal.js +89 -0
- package/lib/components/ui/DetailsCard.d.ts +16 -0
- package/lib/components/ui/DetailsCard.js +14 -0
- package/lib/components/ui/DetailsPage.d.ts +36 -0
- package/lib/components/ui/DetailsPage.js +50 -0
- package/lib/components/ui/Dialog.d.ts +19 -0
- package/lib/components/ui/Dialog.js +22 -0
- package/lib/components/ui/EmptyState.d.ts +6 -0
- package/lib/components/ui/EmptyState.js +6 -0
- package/lib/components/ui/FilterComponent.d.ts +30 -0
- package/lib/components/ui/FilterComponent.js +80 -0
- package/lib/components/ui/FilterList.d.ts +52 -0
- package/lib/components/ui/FilterList.js +62 -0
- package/lib/components/ui/FilterSection.d.ts +31 -0
- package/lib/components/ui/FilterSection.js +21 -0
- package/lib/components/ui/FilterWrapper.d.ts +6 -0
- package/lib/components/ui/FilterWrapper.js +7 -0
- package/lib/components/ui/Form.d.ts +23 -0
- package/lib/components/ui/Form.js +62 -0
- package/lib/components/ui/HoverableValue.d.ts +7 -0
- package/lib/components/ui/HoverableValue.js +8 -0
- package/lib/components/ui/IconButton.d.ts +10 -0
- package/lib/components/ui/IconButton.js +10 -0
- package/lib/components/ui/ImageComponent.d.ts +8 -0
- package/lib/components/ui/ImageComponent.js +5 -0
- package/lib/components/ui/ImageUploader.d.ts +17 -0
- package/lib/components/ui/ImageUploader.js +144 -0
- package/lib/components/ui/Input.d.ts +4 -0
- package/lib/components/ui/Input.js +8 -0
- package/lib/components/ui/Label.d.ts +5 -0
- package/lib/components/ui/Label.js +9 -0
- package/lib/components/ui/Loader.d.ts +10 -0
- package/lib/components/ui/Loader.js +7 -0
- package/lib/components/ui/Modal.d.ts +72 -0
- package/lib/components/ui/Modal.js +31 -0
- package/lib/components/ui/MultiSelect.d.ts +16 -0
- package/lib/components/ui/MultiSelect.js +59 -0
- package/lib/components/ui/NotificationModal.d.ts +18 -0
- package/lib/components/ui/NotificationModal.js +40 -0
- package/lib/components/ui/PhoneInput.d.ts +12 -0
- package/lib/components/ui/PhoneInput.js +58 -0
- package/lib/components/ui/Popover.d.ts +7 -0
- package/lib/components/ui/Popover.js +10 -0
- package/lib/components/ui/Progress.d.ts +7 -0
- package/lib/components/ui/Progress.js +7 -0
- package/lib/components/ui/Radio.d.ts +5 -0
- package/lib/components/ui/Radio.js +14 -0
- package/lib/components/ui/RangeDatePicker.d.ts +78 -0
- package/lib/components/ui/RangeDatePicker.js +68 -0
- package/lib/components/ui/Select.d.ts +13 -0
- package/lib/components/ui/Select.js +57 -0
- package/lib/components/ui/Separator.d.ts +4 -0
- package/lib/components/ui/Separator.js +7 -0
- package/lib/components/ui/Sheet.d.ts +26 -0
- package/lib/components/ui/Sheet.js +37 -0
- package/lib/components/ui/StatusCell.d.ts +9 -0
- package/lib/components/ui/StatusCell.js +6 -0
- package/lib/components/ui/Switch.d.ts +10 -0
- package/lib/components/ui/Switch.js +22 -0
- package/lib/components/ui/Tab.d.ts +15 -0
- package/lib/components/ui/Tab.js +13 -0
- package/lib/components/ui/TableDownload.d.ts +11 -0
- package/lib/components/ui/TableDownload.js +82 -0
- package/lib/components/ui/TailwindIndicator.d.ts +1 -0
- package/lib/components/ui/TailwindIndicator.js +6 -0
- package/lib/components/ui/TextField.d.ts +60 -0
- package/lib/components/ui/TextField.js +42 -0
- package/lib/components/ui/Textarea.d.ts +5 -0
- package/lib/components/ui/Textarea.js +8 -0
- package/lib/components/ui/Toast.d.ts +12 -0
- package/lib/components/ui/Toast.js +25 -0
- package/lib/components/ui/UploadField.d.ts +15 -0
- package/lib/components/ui/UploadField.js +45 -0
- package/lib/components/ui/VerticalTab.d.ts +16 -0
- package/lib/components/ui/VerticalTab.js +13 -0
- package/lib/components/ui/index.d.ts +49 -0
- package/lib/components/ui/index.js +47 -0
- package/lib/context/BreadcrumbContext.d.ts +28 -0
- package/lib/context/BreadcrumbContext.js +238 -0
- package/lib/context/FormEngineDrawerProvider.d.ts +21 -0
- package/lib/context/FormEngineDrawerProvider.js +38 -0
- package/lib/context/MultiFormEngineDrawerProvider.d.ts +25 -0
- package/lib/context/MultiFormEngineDrawerProvider.js +89 -0
- package/lib/context/SidebarContext.d.ts +65 -0
- package/lib/context/SidebarContext.js +47 -0
- package/lib/context/ToastContext.d.ts +17 -0
- package/lib/context/ToastContext.js +29 -0
- package/lib/context/index.d.ts +5 -0
- package/lib/context/index.js +5 -0
- package/lib/dashboard-visuals/components/BaseChart.d.ts +55 -0
- package/lib/dashboard-visuals/components/BaseChart.js +201 -0
- package/lib/dashboard-visuals/components/CardWrapper.d.ts +10 -0
- package/lib/dashboard-visuals/components/CardWrapper.js +13 -0
- package/lib/dashboard-visuals/components/ChartDetailsModal.d.ts +57 -0
- package/lib/dashboard-visuals/components/ChartDetailsModal.js +27 -0
- package/lib/dashboard-visuals/components/ChartDetailsModalWrapper.d.ts +29 -0
- package/lib/dashboard-visuals/components/ChartDetailsModalWrapper.js +4 -0
- package/lib/dashboard-visuals/components/ChartFormatter.d.ts +22 -0
- package/lib/dashboard-visuals/components/ChartFormatter.js +46 -0
- package/lib/dashboard-visuals/components/ChartWrapper.d.ts +11 -0
- package/lib/dashboard-visuals/components/ChartWrapper.js +14 -0
- package/lib/dashboard-visuals/components/DashboardFilter.d.ts +8 -0
- package/lib/dashboard-visuals/components/DashboardFilter.js +17 -0
- package/lib/dashboard-visuals/components/DataTable.d.ts +3 -0
- package/lib/dashboard-visuals/components/DataTable.js +57 -0
- package/lib/dashboard-visuals/components/EmptyState.d.ts +6 -0
- package/lib/dashboard-visuals/components/EmptyState.js +6 -0
- package/lib/dashboard-visuals/components/ErrorState.d.ts +7 -0
- package/lib/dashboard-visuals/components/ErrorState.js +5 -0
- package/lib/dashboard-visuals/components/FilterComponentSkeleton.d.ts +3 -0
- package/lib/dashboard-visuals/components/FilterComponentSkeleton.js +11 -0
- package/lib/dashboard-visuals/components/Pagination.d.ts +10 -0
- package/lib/dashboard-visuals/components/Pagination.js +7 -0
- package/lib/dashboard-visuals/components/Switch.d.ts +8 -0
- package/lib/dashboard-visuals/components/Switch.js +10 -0
- package/lib/dashboard-visuals/components/TileSkeleton.d.ts +2 -0
- package/lib/dashboard-visuals/components/TileSkeleton.js +5 -0
- package/lib/dashboard-visuals/components/molecules/Analytics.d.ts +11 -0
- package/lib/dashboard-visuals/components/molecules/Analytics.js +9 -0
- package/lib/dashboard-visuals/components/molecules/DataGrid.d.ts +15 -0
- package/lib/dashboard-visuals/components/molecules/DataGrid.js +124 -0
- package/lib/dashboard-visuals/components/molecules/NoChartData.d.ts +6 -0
- package/lib/dashboard-visuals/components/molecules/NoChartData.js +6 -0
- package/lib/dashboard-visuals/components/molecules/VisualChart.d.ts +16 -0
- package/lib/dashboard-visuals/components/molecules/VisualChart.js +8 -0
- package/lib/dashboard-visuals/components/types.d.ts +62 -0
- package/lib/dashboard-visuals/components/types.js +1 -0
- package/lib/dashboard-visuals/hooks/useChartData.d.ts +15 -0
- package/lib/dashboard-visuals/hooks/useChartData.js +82 -0
- package/lib/dashboard-visuals/hooks/useTooltipFormatter.d.ts +13 -0
- package/lib/dashboard-visuals/hooks/useTooltipFormatter.js +10 -0
- package/lib/dashboard-visuals/index.d.ts +39 -0
- package/lib/dashboard-visuals/index.js +168 -0
- package/lib/dashboard-visuals/types/index.d.ts +83 -0
- package/lib/dashboard-visuals/types/index.js +1 -0
- package/lib/dashboard-visuals/types/metricDetailData.d.ts +25 -0
- package/lib/dashboard-visuals/types/metricDetailData.js +1 -0
- package/lib/dashboard-visuals/utils/api.d.ts +5 -0
- package/lib/dashboard-visuals/utils/api.js +6 -0
- package/lib/dashboard-visuals/utils/chartOptions.d.ts +481 -0
- package/lib/dashboard-visuals/utils/chartOptions.js +393 -0
- package/lib/dashboard-visuals/utils/chunkArray.d.ts +1 -0
- package/lib/dashboard-visuals/utils/chunkArray.js +7 -0
- package/lib/dashboard-visuals/utils/defaultColors.d.ts +1 -0
- package/lib/dashboard-visuals/utils/defaultColors.js +1 -0
- package/lib/dashboard-visuals/utils/formatUtil.d.ts +203 -0
- package/lib/dashboard-visuals/utils/formatUtil.js +472 -0
- package/lib/dashboard-visuals/utils/gridUtil.d.ts +11 -0
- package/lib/dashboard-visuals/utils/gridUtil.js +32 -0
- package/lib/dashboard-visuals/utils/index.d.ts +6 -0
- package/lib/dashboard-visuals/utils/index.js +6 -0
- package/lib/dashboard-visuals/utils/tooltipUtils.d.ts +11 -0
- package/lib/dashboard-visuals/utils/tooltipUtils.js +180 -0
- package/lib/dashboard-visuals/visualRegistry.d.ts +4 -0
- package/lib/dashboard-visuals/visualRegistry.js +41 -0
- package/lib/dashboard-visuals/visuals/BarChart.d.ts +58 -0
- package/lib/dashboard-visuals/visuals/BarChart.js +95 -0
- package/lib/dashboard-visuals/visuals/BarLineHybridChart.d.ts +33 -0
- package/lib/dashboard-visuals/visuals/BarLineHybridChart.js +60 -0
- package/lib/dashboard-visuals/visuals/BubbleChart.d.ts +25 -0
- package/lib/dashboard-visuals/visuals/BubbleChart.js +101 -0
- package/lib/dashboard-visuals/visuals/DistributionChart.d.ts +11 -0
- package/lib/dashboard-visuals/visuals/DistributionChart.js +48 -0
- package/lib/dashboard-visuals/visuals/DonutChart.d.ts +50 -0
- package/lib/dashboard-visuals/visuals/DonutChart.js +105 -0
- package/lib/dashboard-visuals/visuals/GaugeChart.d.ts +32 -0
- package/lib/dashboard-visuals/visuals/GaugeChart.js +53 -0
- package/lib/dashboard-visuals/visuals/GroupedBarChart.d.ts +47 -0
- package/lib/dashboard-visuals/visuals/GroupedBarChart.js +131 -0
- package/lib/dashboard-visuals/visuals/HeatmapChart.d.ts +79 -0
- package/lib/dashboard-visuals/visuals/HeatmapChart.js +146 -0
- package/lib/dashboard-visuals/visuals/HorizontalBarChart.d.ts +50 -0
- package/lib/dashboard-visuals/visuals/HorizontalBarChart.js +131 -0
- package/lib/dashboard-visuals/visuals/ItemPerformanceCard.d.ts +30 -0
- package/lib/dashboard-visuals/visuals/ItemPerformanceCard.js +31 -0
- package/lib/dashboard-visuals/visuals/LineChart.d.ts +56 -0
- package/lib/dashboard-visuals/visuals/LineChart.js +80 -0
- package/lib/dashboard-visuals/visuals/LineGraph.d.ts +50 -0
- package/lib/dashboard-visuals/visuals/LineGraph.js +189 -0
- package/lib/dashboard-visuals/visuals/MetricSummaryCard.d.ts +14 -0
- package/lib/dashboard-visuals/visuals/MetricSummaryCard.js +8 -0
- package/lib/dashboard-visuals/visuals/MultiGaugeChart.d.ts +39 -0
- package/lib/dashboard-visuals/visuals/MultiGaugeChart.js +119 -0
- package/lib/dashboard-visuals/visuals/PieChart.d.ts +59 -0
- package/lib/dashboard-visuals/visuals/PieChart.js +194 -0
- package/lib/dashboard-visuals/visuals/SelectedEventTile.d.ts +14 -0
- package/lib/dashboard-visuals/visuals/SelectedEventTile.js +35 -0
- package/lib/dashboard-visuals/visuals/SpeedometerChart.d.ts +53 -0
- package/lib/dashboard-visuals/visuals/SpeedometerChart.js +94 -0
- package/lib/dashboard-visuals/visuals/Table.d.ts +26 -0
- package/lib/dashboard-visuals/visuals/Table.js +113 -0
- package/lib/dashboard-visuals/visuals/Tile.d.ts +16 -0
- package/lib/dashboard-visuals/visuals/Tile.js +16 -0
- package/lib/dashboard-visuals/visuals/TreeMap.d.ts +25 -0
- package/lib/dashboard-visuals/visuals/TreeMap.js +45 -0
- package/lib/dashboard-visuals/visuals/WaterfallChart.d.ts +52 -0
- package/lib/dashboard-visuals/visuals/WaterfallChart.js +266 -0
- package/lib/form-engine/Form.d.ts +4 -0
- package/lib/form-engine/Form.js +14 -0
- package/lib/form-engine/FormEngine.d.ts +3 -0
- package/lib/form-engine/FormEngine.js +121 -0
- package/lib/form-engine/components/FieldWrapper.d.ts +18 -0
- package/lib/form-engine/components/FieldWrapper.js +63 -0
- package/lib/form-engine/components/index.d.ts +2 -0
- package/lib/form-engine/components/index.js +2 -0
- package/lib/form-engine/components/inputs/card-expiry-input/CardExpiryInput.d.ts +16 -0
- package/lib/form-engine/components/inputs/card-expiry-input/CardExpiryInput.js +48 -0
- package/lib/form-engine/components/inputs/checkbox-input/CheckboxInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/checkbox-input/CheckboxInput.js +5 -0
- package/lib/form-engine/components/inputs/credit-card-input/CreditCardInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/credit-card-input/CreditCardInput.js +82 -0
- package/lib/form-engine/components/inputs/date-input/DateInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/date-input/DateInput.js +7 -0
- package/lib/form-engine/components/inputs/date-input/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/date-input/index.js +1 -0
- package/lib/form-engine/components/inputs/email-input/EmailInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/email-input/EmailInput.js +5 -0
- package/lib/form-engine/components/inputs/email-input/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/email-input/index.js +1 -0
- package/lib/form-engine/components/inputs/index.d.ts +13 -0
- package/lib/form-engine/components/inputs/index.js +13 -0
- package/lib/form-engine/components/inputs/label-input/LabelInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/label-input/LabelInput.js +7 -0
- package/lib/form-engine/components/inputs/label-input/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/label-input/index.js +1 -0
- package/lib/form-engine/components/inputs/multi-select-input/MultiSelectInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/multi-select-input/MultiSelectInput.js +5 -0
- package/lib/form-engine/components/inputs/number-input/NumberInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/number-input/NumberInput.js +5 -0
- package/lib/form-engine/components/inputs/number-input/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/number-input/index.js +1 -0
- package/lib/form-engine/components/inputs/password-input/PasswordInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/password-input/PasswordInput.js +9 -0
- package/lib/form-engine/components/inputs/password-input/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/password-input/index.js +1 -0
- package/lib/form-engine/components/inputs/radio-button/RadioInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/radio-button/RadioInput.js +6 -0
- package/lib/form-engine/components/inputs/radio-button/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/radio-button/index.js +1 -0
- package/lib/form-engine/components/inputs/select/SelectInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/select/SelectInput.js +6 -0
- package/lib/form-engine/components/inputs/select/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/select/index.js +1 -0
- package/lib/form-engine/components/inputs/textarea-input/TextareaInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/textarea-input/TextareaInput.js +5 -0
- package/lib/form-engine/components/inputs/textarea-input/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/textarea-input/index.js +1 -0
- package/lib/form-engine/components/inputs/time-input/TimeInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/time-input/TimeInput.js +5 -0
- package/lib/form-engine/components/inputs/time-input/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/time-input/index.js +1 -0
- package/lib/form-engine/components/inputs/toggle-switch-input/ToggleSwitchInput.d.ts +4 -0
- package/lib/form-engine/components/inputs/toggle-switch-input/ToggleSwitchInput.js +7 -0
- package/lib/form-engine/components/inputs/toggle-switch-input/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/toggle-switch-input/index.js +1 -0
- package/lib/form-engine/components/inputs/upload-field/UploadFieldForm.d.ts +4 -0
- package/lib/form-engine/components/inputs/upload-field/UploadFieldForm.js +59 -0
- package/lib/form-engine/components/inputs/upload-field/index.d.ts +1 -0
- package/lib/form-engine/components/inputs/upload-field/index.js +1 -0
- package/lib/form-engine/hooks/useFormPersistence.d.ts +11 -0
- package/lib/form-engine/hooks/useFormPersistence.js +46 -0
- package/lib/form-engine/index.d.ts +5 -0
- package/lib/form-engine/index.js +5 -0
- package/lib/form-engine/registry/RegisterComponents.d.ts +1 -0
- package/lib/form-engine/registry/RegisterComponents.js +35 -0
- package/lib/form-engine/registry/Registry.d.ts +5 -0
- package/lib/form-engine/registry/Registry.js +13 -0
- package/lib/form-engine/registry/index.d.ts +2 -0
- package/lib/form-engine/registry/index.js +2 -0
- package/lib/form-engine/types/index.d.ts +311 -0
- package/lib/form-engine/types/index.js +1 -0
- package/lib/helpers/index.d.ts +2 -0
- package/lib/helpers/index.js +2 -0
- package/lib/helpers/utils.d.ts +37 -0
- package/lib/helpers/utils.js +77 -0
- package/lib/helpers/validations.d.ts +80 -0
- package/lib/helpers/validations.js +39 -0
- package/lib/index.d.ts +21 -0
- package/lib/index.js +30 -0
- package/lib/mocks/mockApiRequestsConfig.d.ts +2 -0
- package/lib/mocks/mockApiRequestsConfig.js +343 -0
- package/lib/pagamio-drawer/TopUpWalletDrawer/TopUpWalletContent.d.ts +14 -0
- package/lib/pagamio-drawer/TopUpWalletDrawer/TopUpWalletContent.js +40 -0
- package/lib/pagamio-drawer/TopUpWalletDrawer/index.d.ts +11 -0
- package/lib/pagamio-drawer/TopUpWalletDrawer/index.js +7 -0
- package/lib/pagamio-drawer/components/BaseDrawer.d.ts +11 -0
- package/lib/pagamio-drawer/components/BaseDrawer.js +10 -0
- package/lib/pagamio-drawer/components/DrawerContent.d.ts +27 -0
- package/lib/pagamio-drawer/components/DrawerContent.js +237 -0
- package/lib/pagamio-drawer/index.d.ts +22 -0
- package/lib/pagamio-drawer/index.js +133 -0
- package/lib/pagamio-table/data-table/ExportButton.d.ts +57 -0
- package/lib/pagamio-table/data-table/ExportButton.js +96 -0
- package/lib/pagamio-table/data-table/MantineCoreTable.d.ts +44 -0
- package/lib/pagamio-table/data-table/MantineCoreTable.js +129 -0
- package/lib/pagamio-table/data-table/Pagination.d.ts +10 -0
- package/lib/pagamio-table/data-table/Pagination.js +5 -0
- package/lib/pagamio-table/data-table/TableDownload.d.ts +8 -0
- package/lib/pagamio-table/data-table/TableDownload.js +81 -0
- package/lib/pagamio-table/data-table/TableToolbar.d.ts +3 -0
- package/lib/pagamio-table/data-table/TableToolbar.js +16 -0
- package/lib/pagamio-table/data-table/exportUtils.d.ts +42 -0
- package/lib/pagamio-table/data-table/exportUtils.js +782 -0
- package/lib/pagamio-table/data-table/index.d.ts +5 -0
- package/lib/pagamio-table/data-table/index.js +11 -0
- package/lib/pagamio-table/data-table/pdfExportUtils.d.ts +111 -0
- package/lib/pagamio-table/data-table/pdfExportUtils.js +113 -0
- package/lib/pagamio-table/data-table/types.d.ts +169 -0
- package/lib/pagamio-table/data-table/types.js +1 -0
- package/lib/pagamio-table/index.d.ts +4 -0
- package/lib/pagamio-table/index.js +4 -0
- package/lib/pagamio-table/utils/functionHelper.d.ts +12 -0
- package/lib/pagamio-table/utils/functionHelper.js +24 -0
- package/lib/pagamio-table/utils/index.d.ts +1 -0
- package/lib/pagamio-table/utils/index.js +1 -0
- package/lib/rbac/hooks.d.ts +39 -0
- package/lib/rbac/hooks.js +51 -0
- package/lib/rbac/index.d.ts +8 -0
- package/lib/rbac/index.js +11 -0
- package/lib/rbac/store.d.ts +24 -0
- package/lib/rbac/store.js +37 -0
- package/lib/rbac/types.d.ts +39 -0
- package/lib/rbac/types.js +4 -0
- package/lib/rbac/utils.d.ts +44 -0
- package/lib/rbac/utils.js +117 -0
- package/lib/shared/constants/index.d.ts +2 -0
- package/lib/shared/constants/index.js +2 -0
- package/lib/shared/hooks/index.d.ts +4 -0
- package/lib/shared/hooks/index.js +4 -0
- package/lib/shared/hooks/useAnyDrawerOpen.d.ts +4 -0
- package/lib/shared/hooks/useAnyDrawerOpen.js +18 -0
- package/lib/shared/hooks/useContainerWidth.d.ts +2 -0
- package/lib/shared/hooks/useContainerWidth.js +18 -0
- package/lib/shared/hooks/useImageUpload.d.ts +15 -0
- package/lib/shared/hooks/useImageUpload.js +66 -0
- package/lib/shared/hooks/useMediaQueries.d.ts +5 -0
- package/lib/shared/hooks/useMediaQueries.js +35 -0
- package/lib/shared/hooks/usePagamioTable.d.ts +158 -0
- package/lib/shared/hooks/usePagamioTable.js +475 -0
- package/lib/shared/hooks/useSessionTimer.d.ts +33 -0
- package/lib/shared/hooks/useSessionTimer.js +96 -0
- package/lib/shared/index.d.ts +4 -0
- package/lib/shared/index.js +4 -0
- package/lib/shared/types/index.d.ts +1 -0
- package/lib/shared/types/index.js +1 -0
- package/lib/shared/url/index.d.ts +9 -0
- package/lib/shared/url/index.js +20 -0
- package/lib/shared/utils/filterUtils.d.ts +5 -0
- package/lib/shared/utils/filterUtils.js +31 -0
- package/lib/shared/utils/functionHelper.d.ts +27 -0
- package/lib/shared/utils/functionHelper.js +124 -0
- package/lib/shared/utils/index.d.ts +2 -0
- package/lib/shared/utils/index.js +2 -0
- package/lib/shared/utils/localStorage.d.ts +53 -0
- package/lib/shared/utils/localStorage.js +139 -0
- package/lib/styles.css +6247 -0
- package/lib/translations/components/LocaleSwitcher.d.ts +7 -0
- package/lib/translations/components/LocaleSwitcher.js +18 -0
- package/lib/translations/components/index.d.ts +1 -0
- package/lib/translations/components/index.js +1 -0
- package/lib/translations/context/TranslationContext.d.ts +5 -0
- package/lib/translations/context/TranslationContext.js +151 -0
- package/lib/translations/context/index.d.ts +1 -0
- package/lib/translations/context/index.js +1 -0
- package/lib/translations/hooks/index.d.ts +2 -0
- package/lib/translations/hooks/index.js +2 -0
- package/lib/translations/hooks/useLibTranslations.d.ts +7 -0
- package/lib/translations/hooks/useLibTranslations.js +46 -0
- package/lib/translations/hooks/useTranslation.d.ts +7 -0
- package/lib/translations/hooks/useTranslation.js +11 -0
- package/lib/translations/index.d.ts +91 -0
- package/lib/translations/index.js +11 -0
- package/lib/translations/locales/en.json +21 -0
- package/lib/translations/locales/es.json +21 -0
- package/lib/translations/locales/fr.json +21 -0
- package/lib/translations/locales/pt.json +21 -0
- package/lib/translations/types/index.d.ts +24 -0
- package/lib/translations/types/index.js +1 -0
- package/lib/translations/utils/index.d.ts +6 -0
- package/lib/translations/utils/index.js +25 -0
- package/package.json +9 -1
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import type { ApiClient } from '../../api';
|
|
2
|
+
import type { AuthResponse, CustomAuthConfig } from '../types';
|
|
3
|
+
import { TokenManager } from '../utils';
|
|
4
|
+
/**
|
|
5
|
+
* Registration request payload
|
|
6
|
+
* Basic version with required email and password fields
|
|
7
|
+
*/
|
|
8
|
+
interface RegistrationRequest {
|
|
9
|
+
email: string;
|
|
10
|
+
password: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generic registration request type that can be any object type
|
|
15
|
+
* while maintaining backward compatibility with RegistrationRequest
|
|
16
|
+
*/
|
|
17
|
+
type GenericRegistrationRequest = RegistrationRequest | Record<string, any>;
|
|
18
|
+
/**
|
|
19
|
+
* Password reset request payload
|
|
20
|
+
*/
|
|
21
|
+
interface ResetPasswordRequest {
|
|
22
|
+
token: string;
|
|
23
|
+
newPassword: string;
|
|
24
|
+
newPasswordConfirm: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Forgot password request payload
|
|
28
|
+
*/
|
|
29
|
+
interface ForgotPasswordRequest {
|
|
30
|
+
email: string;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Password change request
|
|
34
|
+
*/
|
|
35
|
+
interface PasswordChangeRequest {
|
|
36
|
+
currentPassword: string;
|
|
37
|
+
newPassword: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Configuration for AuthService
|
|
41
|
+
* @template T - Type extending CustomAuthConfig for type-safe auth operations
|
|
42
|
+
*/
|
|
43
|
+
interface AuthServiceConfig<T extends CustomAuthConfig> {
|
|
44
|
+
/** Token manager instance for handling auth tokens */
|
|
45
|
+
tokenManager: TokenManager<T>;
|
|
46
|
+
/** Api Client instance for handling api calls */
|
|
47
|
+
apiClient: ApiClient<T>;
|
|
48
|
+
/** Base URL for API endpoints */
|
|
49
|
+
baseUrl: string;
|
|
50
|
+
/** Endpoint configuration */
|
|
51
|
+
endpoints: {
|
|
52
|
+
login: string;
|
|
53
|
+
logout: string;
|
|
54
|
+
refresh: string;
|
|
55
|
+
validateToken: string;
|
|
56
|
+
resetPassword: string;
|
|
57
|
+
changePassword: string;
|
|
58
|
+
register: string;
|
|
59
|
+
verifyEmail: string;
|
|
60
|
+
updateProfile: string;
|
|
61
|
+
[key: string]: string;
|
|
62
|
+
};
|
|
63
|
+
/** Storage configuration */
|
|
64
|
+
storage?: {
|
|
65
|
+
prefix?: string;
|
|
66
|
+
keys?: string[];
|
|
67
|
+
};
|
|
68
|
+
/** Service options */
|
|
69
|
+
options?: {
|
|
70
|
+
autoRefreshToken?: boolean;
|
|
71
|
+
refreshThresholdMs?: number;
|
|
72
|
+
maxRefreshAttempts?: number;
|
|
73
|
+
};
|
|
74
|
+
/** redirect To Login Page */
|
|
75
|
+
handleRedirectToLoginPage: () => void;
|
|
76
|
+
}
|
|
77
|
+
type RequiredEndpoints = Required<AuthServiceConfig<any>['endpoints']>;
|
|
78
|
+
/**
|
|
79
|
+
* Complete Authentication Service implementation
|
|
80
|
+
* Uses shared API client through useApi hook for all operations
|
|
81
|
+
*
|
|
82
|
+
* @template T - Type extending CustomAuthConfig
|
|
83
|
+
*/
|
|
84
|
+
export declare class AuthService<T extends CustomAuthConfig> {
|
|
85
|
+
/**
|
|
86
|
+
* Keeps a reference to the interval to clear it on unmount.
|
|
87
|
+
*/
|
|
88
|
+
intervalRef: import("react").MutableRefObject<NodeJS.Timeout | null>;
|
|
89
|
+
private readonly tokenManager;
|
|
90
|
+
private readonly apiClient;
|
|
91
|
+
private readonly endpoints;
|
|
92
|
+
private readonly storageConfig;
|
|
93
|
+
private readonly options;
|
|
94
|
+
private readonly handleRedirectToLoginPage;
|
|
95
|
+
private refreshAttempts;
|
|
96
|
+
constructor(config: AuthServiceConfig<T>);
|
|
97
|
+
/**
|
|
98
|
+
* Creates a new AuthService instance
|
|
99
|
+
* @param config - Service configuration
|
|
100
|
+
* @returns Configured AuthService instance
|
|
101
|
+
*/
|
|
102
|
+
static create<T extends CustomAuthConfig>(config: Omit<AuthServiceConfig<T>, 'tokenManager'>): AuthService<T>;
|
|
103
|
+
/**
|
|
104
|
+
* Gets all configured endpoints
|
|
105
|
+
* @returns Copy of all configured endpoint URLs
|
|
106
|
+
*/
|
|
107
|
+
getEndpoints(): RequiredEndpoints;
|
|
108
|
+
/**
|
|
109
|
+
* Updates an endpoint URL
|
|
110
|
+
* @param name - Name of the endpoint to update
|
|
111
|
+
* @param url - New URL for the endpoint
|
|
112
|
+
*/
|
|
113
|
+
setEndpoint(name: keyof RequiredEndpoints, url: string): void;
|
|
114
|
+
/**
|
|
115
|
+
* Adds a new custom endpoint
|
|
116
|
+
* @param name - Name for the new endpoint
|
|
117
|
+
* @param url - URL for the new endpoint
|
|
118
|
+
*/
|
|
119
|
+
addEndpoint(name: string, url: string): void;
|
|
120
|
+
/**
|
|
121
|
+
* Handles user login
|
|
122
|
+
* @param credentials - User credentials
|
|
123
|
+
* @param remember - Whether to remember the user
|
|
124
|
+
* @returns Authentication response with user and token info
|
|
125
|
+
*/
|
|
126
|
+
login(credentials: T['Credentials'], remember?: boolean): Promise<AuthResponse<T>>;
|
|
127
|
+
/**
|
|
128
|
+
* Validates if the response is a valid Strapi authentication response
|
|
129
|
+
* @param response - API response to validate
|
|
130
|
+
* @returns Boolean indicating if response is a valid Strapi auth response
|
|
131
|
+
*/
|
|
132
|
+
private isStrapiAuthResponse;
|
|
133
|
+
/**
|
|
134
|
+
* Handles user registration
|
|
135
|
+
* @param data - Registration data, can be any object with registration information
|
|
136
|
+
* @returns Authentication response if auto-login is enabled
|
|
137
|
+
*/
|
|
138
|
+
register(data: GenericRegistrationRequest): Promise<AuthResponse<T>>;
|
|
139
|
+
/**
|
|
140
|
+
* Handles user logout
|
|
141
|
+
* @param everywhere - Whether to logout from all devices
|
|
142
|
+
*/
|
|
143
|
+
logout(everywhere?: boolean): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Refreshes authentication tokens
|
|
146
|
+
* @returns Whether the refresh was successful
|
|
147
|
+
*/
|
|
148
|
+
refreshTokens(): Promise<boolean>;
|
|
149
|
+
/**
|
|
150
|
+
* Gets the access token expiry timestamp
|
|
151
|
+
*/
|
|
152
|
+
getAccessTokenExpiry(): number | null;
|
|
153
|
+
/**
|
|
154
|
+
* Changes user password
|
|
155
|
+
* @param data - Password change data
|
|
156
|
+
*/
|
|
157
|
+
changePassword(data: PasswordChangeRequest): Promise<void>;
|
|
158
|
+
/**
|
|
159
|
+
* Initiates the password reset process
|
|
160
|
+
* @param data - Email address for password reset
|
|
161
|
+
*/
|
|
162
|
+
forgotPassword(data: ForgotPasswordRequest): Promise<void>;
|
|
163
|
+
/**
|
|
164
|
+
* Completes the password reset process
|
|
165
|
+
* @param data - Reset password data including token and new password
|
|
166
|
+
*/
|
|
167
|
+
resetPassword(data: ResetPasswordRequest): Promise<void>;
|
|
168
|
+
/**
|
|
169
|
+
* Verifies email with token
|
|
170
|
+
* @param token - Email verification token
|
|
171
|
+
*/
|
|
172
|
+
verifyEmail(token: string): Promise<void>;
|
|
173
|
+
/**
|
|
174
|
+
* Updates user profile
|
|
175
|
+
* @param data - Updated user data
|
|
176
|
+
* @returns Updated user info
|
|
177
|
+
*/
|
|
178
|
+
updateProfile(data: Partial<T['UserInfo']>): Promise<T['UserInfo']>;
|
|
179
|
+
/**
|
|
180
|
+
* Gets current user data
|
|
181
|
+
* @returns Current user info or null if not authenticated
|
|
182
|
+
*/
|
|
183
|
+
getUser(): T['UserInfo'] | null;
|
|
184
|
+
/**
|
|
185
|
+
* Gets remember user session option
|
|
186
|
+
* @returns remember user session option or null
|
|
187
|
+
*/
|
|
188
|
+
getRememberUserSessionOption(): boolean | null;
|
|
189
|
+
/**
|
|
190
|
+
* Validates current session
|
|
191
|
+
* @returns Whether the session is valid
|
|
192
|
+
*/
|
|
193
|
+
validateSession(): Promise<boolean>;
|
|
194
|
+
/**
|
|
195
|
+
* Gets the URL for an endpoint
|
|
196
|
+
*/
|
|
197
|
+
private getEndpointUrl;
|
|
198
|
+
/**
|
|
199
|
+
* Initializes automatic token refresh
|
|
200
|
+
*/
|
|
201
|
+
private initializeAutoRefresh;
|
|
202
|
+
/**
|
|
203
|
+
* Stops automatic token refresh
|
|
204
|
+
*/
|
|
205
|
+
private stopAutoRefresh;
|
|
206
|
+
/**
|
|
207
|
+
* Clears all authentication data
|
|
208
|
+
*/
|
|
209
|
+
private clearAuth;
|
|
210
|
+
/**
|
|
211
|
+
* Storage utility methods
|
|
212
|
+
*/
|
|
213
|
+
private getStorageKey;
|
|
214
|
+
private setStorageItem;
|
|
215
|
+
private getStorageItem;
|
|
216
|
+
private clearStorage;
|
|
217
|
+
/**
|
|
218
|
+
* Error handler
|
|
219
|
+
*/
|
|
220
|
+
private handleError;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Factory function to create an AuthService instance
|
|
224
|
+
* @param config - Basic service configuration
|
|
225
|
+
* @param tokenManager
|
|
226
|
+
* @param apiClient - Shared API client instance
|
|
227
|
+
* @returns Configured AuthService instance
|
|
228
|
+
*/
|
|
229
|
+
export declare function createAuthService<T extends CustomAuthConfig>(config: Omit<AuthServiceConfig<T>, 'tokenManager' | 'apiClient'>, tokenManager: TokenManager<T>, apiClient: ApiClient<T>): AuthService<T>;
|
|
230
|
+
export type { AuthServiceConfig, RegistrationRequest, GenericRegistrationRequest, PasswordChangeRequest, ResetPasswordRequest, ForgotPasswordRequest, };
|
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Complete authentication service implementation
|
|
3
|
+
* Handles auth operations with configurable endpoints and token management
|
|
4
|
+
*/
|
|
5
|
+
import { useRef } from 'react';
|
|
6
|
+
import { transformStrapiResponse, } from '../authenticators/processors/StrapiAuthenticatorProcessor';
|
|
7
|
+
import { ResponseTransformerFactory, TokenManager } from '../utils';
|
|
8
|
+
/**
|
|
9
|
+
* Complete Authentication Service implementation
|
|
10
|
+
* Uses shared API client through useApi hook for all operations
|
|
11
|
+
*
|
|
12
|
+
* @template T - Type extending CustomAuthConfig
|
|
13
|
+
*/
|
|
14
|
+
export class AuthService {
|
|
15
|
+
/**
|
|
16
|
+
* Keeps a reference to the interval to clear it on unmount.
|
|
17
|
+
*/
|
|
18
|
+
intervalRef = useRef(null);
|
|
19
|
+
tokenManager;
|
|
20
|
+
apiClient;
|
|
21
|
+
endpoints;
|
|
22
|
+
storageConfig;
|
|
23
|
+
options;
|
|
24
|
+
handleRedirectToLoginPage;
|
|
25
|
+
refreshAttempts = 0;
|
|
26
|
+
constructor(config) {
|
|
27
|
+
this.tokenManager = config.tokenManager;
|
|
28
|
+
this.apiClient = config.apiClient;
|
|
29
|
+
this.handleRedirectToLoginPage = config.handleRedirectToLoginPage;
|
|
30
|
+
// Initialize endpoints with overrides and defaults
|
|
31
|
+
const defaultEndpoints = {
|
|
32
|
+
login: '/auth/login',
|
|
33
|
+
logout: '/auth/logout',
|
|
34
|
+
refresh: '/auth/refresh',
|
|
35
|
+
validateToken: '/auth/validate',
|
|
36
|
+
resetPassword: '/auth/reset-password',
|
|
37
|
+
forgotPassword: '/auth/forgot-password',
|
|
38
|
+
changePassword: '/auth/change-password',
|
|
39
|
+
register: '/auth/register',
|
|
40
|
+
verifyEmail: '/auth/verify-email',
|
|
41
|
+
updateProfile: '/auth/update-profile',
|
|
42
|
+
};
|
|
43
|
+
this.endpoints = {
|
|
44
|
+
...defaultEndpoints,
|
|
45
|
+
...config.endpoints,
|
|
46
|
+
};
|
|
47
|
+
// Initialize storage configuration
|
|
48
|
+
this.storageConfig = {
|
|
49
|
+
prefix: 'auth_',
|
|
50
|
+
keys: ['user', 'remember', 'session'],
|
|
51
|
+
...config.storage,
|
|
52
|
+
};
|
|
53
|
+
// Initialize options
|
|
54
|
+
this.options = {
|
|
55
|
+
autoRefreshToken: true,
|
|
56
|
+
refreshThresholdMs: 5 * 60 * 1000, // 5 minutes before expiry
|
|
57
|
+
maxRefreshAttempts: 3,
|
|
58
|
+
...config.options,
|
|
59
|
+
};
|
|
60
|
+
// Start auto refresh if enabled
|
|
61
|
+
if (this.options.autoRefreshToken) {
|
|
62
|
+
this.initializeAutoRefresh();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new AuthService instance
|
|
67
|
+
* @param config - Service configuration
|
|
68
|
+
* @returns Configured AuthService instance
|
|
69
|
+
*/
|
|
70
|
+
static create(config) {
|
|
71
|
+
const tokenManager = new TokenManager({
|
|
72
|
+
baseUrl: config.baseUrl,
|
|
73
|
+
refreshEndpoint: config.endpoints.refresh,
|
|
74
|
+
});
|
|
75
|
+
return new AuthService({
|
|
76
|
+
...config,
|
|
77
|
+
tokenManager,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets all configured endpoints
|
|
82
|
+
* @returns Copy of all configured endpoint URLs
|
|
83
|
+
*/
|
|
84
|
+
getEndpoints() {
|
|
85
|
+
return { ...this.endpoints };
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Updates an endpoint URL
|
|
89
|
+
* @param name - Name of the endpoint to update
|
|
90
|
+
* @param url - New URL for the endpoint
|
|
91
|
+
*/
|
|
92
|
+
setEndpoint(name, url) {
|
|
93
|
+
this.endpoints[name] = url;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Adds a new custom endpoint
|
|
97
|
+
* @param name - Name for the new endpoint
|
|
98
|
+
* @param url - URL for the new endpoint
|
|
99
|
+
*/
|
|
100
|
+
addEndpoint(name, url) {
|
|
101
|
+
this.endpoints[name] = url;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Handles user login
|
|
105
|
+
* @param credentials - User credentials
|
|
106
|
+
* @param remember - Whether to remember the user
|
|
107
|
+
* @returns Authentication response with user and token info
|
|
108
|
+
*/
|
|
109
|
+
async login(credentials, remember = false) {
|
|
110
|
+
try {
|
|
111
|
+
const apiResponse = await this.apiClient.post(this.getEndpointUrl('login'), credentials, {
|
|
112
|
+
skipAuth: true,
|
|
113
|
+
isProtected: false,
|
|
114
|
+
});
|
|
115
|
+
// Handle Strapi format JWT response
|
|
116
|
+
if (this.isStrapiAuthResponse(apiResponse)) {
|
|
117
|
+
// Convert Strapi response to our expected format
|
|
118
|
+
const authResponse = transformStrapiResponse(apiResponse);
|
|
119
|
+
this.tokenManager.handleAuthTokens(authResponse.auth);
|
|
120
|
+
this.setStorageItem('user', authResponse.user);
|
|
121
|
+
this.setStorageItem('remember', remember);
|
|
122
|
+
this.setStorageItem('session', {
|
|
123
|
+
loginTime: new Date().toISOString(),
|
|
124
|
+
lastActive: new Date().toISOString(),
|
|
125
|
+
});
|
|
126
|
+
return authResponse;
|
|
127
|
+
}
|
|
128
|
+
// Standard flow using transformers for non-Strapi APIs
|
|
129
|
+
const transformer = ResponseTransformerFactory.getTransformer(apiResponse);
|
|
130
|
+
const authResponse = transformer.transform(apiResponse, remember);
|
|
131
|
+
this.tokenManager.handleAuthTokens(authResponse.auth);
|
|
132
|
+
this.setStorageItem('user', authResponse.user);
|
|
133
|
+
this.setStorageItem('remember', remember);
|
|
134
|
+
this.setStorageItem('session', {
|
|
135
|
+
loginTime: new Date().toISOString(),
|
|
136
|
+
lastActive: new Date().toISOString(),
|
|
137
|
+
});
|
|
138
|
+
return authResponse;
|
|
139
|
+
}
|
|
140
|
+
catch (error) {
|
|
141
|
+
throw this.handleError(error);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Validates if the response is a valid Strapi authentication response
|
|
146
|
+
* @param response - API response to validate
|
|
147
|
+
* @returns Boolean indicating if response is a valid Strapi auth response
|
|
148
|
+
*/
|
|
149
|
+
isStrapiAuthResponse(response) {
|
|
150
|
+
if (!response || typeof response !== 'object') {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
const potentialStrapiResponse = response;
|
|
154
|
+
// Check if jwt exists and is a non-empty string
|
|
155
|
+
if (typeof potentialStrapiResponse.jwt !== 'string' || potentialStrapiResponse.jwt.trim() === '') {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
// Check if user exists and is an object
|
|
159
|
+
if (!potentialStrapiResponse.user || typeof potentialStrapiResponse.user !== 'object') {
|
|
160
|
+
return false;
|
|
161
|
+
}
|
|
162
|
+
// Optional: Add additional validation for critical user properties
|
|
163
|
+
// For example, check if required user fields are present
|
|
164
|
+
const user = potentialStrapiResponse.user;
|
|
165
|
+
if (!user.id || typeof user.email !== 'string' || user.email.trim() === '') {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
return true;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Handles user registration
|
|
172
|
+
* @param data - Registration data, can be any object with registration information
|
|
173
|
+
* @returns Authentication response if auto-login is enabled
|
|
174
|
+
*/
|
|
175
|
+
async register(data) {
|
|
176
|
+
try {
|
|
177
|
+
const response = await this.apiClient.post(this.getEndpointUrl('register'), data, {
|
|
178
|
+
skipAuth: true,
|
|
179
|
+
isProtected: false,
|
|
180
|
+
});
|
|
181
|
+
// Handle Strapi format JWT response
|
|
182
|
+
if (response && typeof response === 'object' && 'jwt' in response && 'user' in response) {
|
|
183
|
+
// Create our expected format from Strapi response using the imported transformer
|
|
184
|
+
const authResponse = transformStrapiResponse(response);
|
|
185
|
+
this.tokenManager.handleAuthTokens(authResponse.auth);
|
|
186
|
+
this.setStorageItem('user', authResponse.user);
|
|
187
|
+
return authResponse;
|
|
188
|
+
}
|
|
189
|
+
// Handle standard response format
|
|
190
|
+
const standardResponse = response;
|
|
191
|
+
if (standardResponse.auth) {
|
|
192
|
+
this.tokenManager.handleAuthTokens(standardResponse.auth);
|
|
193
|
+
this.setStorageItem('user', standardResponse.user);
|
|
194
|
+
}
|
|
195
|
+
return standardResponse;
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
throw this.handleError(error);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Handles user logout
|
|
203
|
+
* @param everywhere - Whether to logout from all devices
|
|
204
|
+
*/
|
|
205
|
+
async logout(everywhere = false) {
|
|
206
|
+
try {
|
|
207
|
+
// Disabled logout from the server for now, there is no backend implementation
|
|
208
|
+
// const token = this.tokenManager.getAccessToken().token;
|
|
209
|
+
// if (token) {
|
|
210
|
+
// await this.apiClient.post(
|
|
211
|
+
// this.getEndpointUrl('logout'),
|
|
212
|
+
// { everywhere },
|
|
213
|
+
// {
|
|
214
|
+
// skipRefresh: true,
|
|
215
|
+
// isProtected: true,
|
|
216
|
+
// },
|
|
217
|
+
// );
|
|
218
|
+
// }
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
console.error('Logout request failed:', error);
|
|
222
|
+
}
|
|
223
|
+
finally {
|
|
224
|
+
this.clearAuth();
|
|
225
|
+
this.stopAutoRefresh();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Refreshes authentication tokens
|
|
230
|
+
* @returns Whether the refresh was successful
|
|
231
|
+
*/
|
|
232
|
+
async refreshTokens() {
|
|
233
|
+
try {
|
|
234
|
+
if (this.refreshAttempts >= this.options.maxRefreshAttempts) {
|
|
235
|
+
this.clearAuth();
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
this.refreshAttempts++;
|
|
239
|
+
const success = await this.tokenManager.refreshTokens();
|
|
240
|
+
if (success) {
|
|
241
|
+
this.refreshAttempts = 0;
|
|
242
|
+
if (this.options.autoRefreshToken) {
|
|
243
|
+
this.initializeAutoRefresh();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
this.clearAuth();
|
|
248
|
+
}
|
|
249
|
+
return success;
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
console.error('Token refresh failed:', error);
|
|
253
|
+
this.clearAuth();
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Gets the access token expiry timestamp
|
|
259
|
+
*/
|
|
260
|
+
getAccessTokenExpiry() {
|
|
261
|
+
const { expiresAt } = this.tokenManager.getAccessToken();
|
|
262
|
+
return expiresAt;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Changes user password
|
|
266
|
+
* @param data - Password change data
|
|
267
|
+
*/
|
|
268
|
+
async changePassword(data) {
|
|
269
|
+
await this.apiClient.post(this.getEndpointUrl('changePassword'), data, { isProtected: true });
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Initiates the password reset process
|
|
273
|
+
* @param data - Email address for password reset
|
|
274
|
+
*/
|
|
275
|
+
async forgotPassword(data) {
|
|
276
|
+
try {
|
|
277
|
+
await this.apiClient.post(this.getEndpointUrl('forgotPassword'), data, {
|
|
278
|
+
skipAuth: true,
|
|
279
|
+
isProtected: false,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
throw this.handleError(error);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Completes the password reset process
|
|
288
|
+
* @param data - Reset password data including token and new password
|
|
289
|
+
*/
|
|
290
|
+
async resetPassword(data) {
|
|
291
|
+
try {
|
|
292
|
+
await this.apiClient.post(this.getEndpointUrl('resetPassword'), data, {
|
|
293
|
+
skipAuth: true,
|
|
294
|
+
isProtected: false,
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
throw this.handleError(error);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Verifies email with token
|
|
303
|
+
* @param token - Email verification token
|
|
304
|
+
*/
|
|
305
|
+
async verifyEmail(token) {
|
|
306
|
+
await this.apiClient.post(this.getEndpointUrl('verifyEmail'), { token }, { skipAuth: true, isProtected: false });
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Updates user profile
|
|
310
|
+
* @param data - Updated user data
|
|
311
|
+
* @returns Updated user info
|
|
312
|
+
*/
|
|
313
|
+
async updateProfile(data) {
|
|
314
|
+
const response = await this.apiClient.post(this.getEndpointUrl('updateProfile'), data, {
|
|
315
|
+
isProtected: true,
|
|
316
|
+
});
|
|
317
|
+
this.setStorageItem('user', response);
|
|
318
|
+
return response;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Gets current user data
|
|
322
|
+
* @returns Current user info or null if not authenticated
|
|
323
|
+
*/
|
|
324
|
+
getUser() {
|
|
325
|
+
const user = this.getStorageItem('user');
|
|
326
|
+
const data = typeof user === 'string' ? JSON.parse(user) : user;
|
|
327
|
+
return user ? data : null;
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Gets remember user session option
|
|
331
|
+
* @returns remember user session option or null
|
|
332
|
+
*/
|
|
333
|
+
getRememberUserSessionOption() {
|
|
334
|
+
const rememberOption = this.getStorageItem('remember');
|
|
335
|
+
const data = typeof rememberOption === 'string' ? JSON.parse(rememberOption) : rememberOption;
|
|
336
|
+
return rememberOption ? data : null;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Validates current session
|
|
340
|
+
* @returns Whether the session is valid
|
|
341
|
+
*/
|
|
342
|
+
async validateSession() {
|
|
343
|
+
try {
|
|
344
|
+
await this.apiClient.post(this.getEndpointUrl('validateToken'), undefined, {
|
|
345
|
+
skipRefresh: true,
|
|
346
|
+
isProtected: true,
|
|
347
|
+
});
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
catch {
|
|
351
|
+
return false;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Gets the URL for an endpoint
|
|
356
|
+
*/
|
|
357
|
+
getEndpointUrl(endpoint) {
|
|
358
|
+
return this.endpoints[endpoint];
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Initializes automatic token refresh
|
|
362
|
+
*/
|
|
363
|
+
initializeAutoRefresh() {
|
|
364
|
+
const rememberSession = this.getRememberUserSessionOption();
|
|
365
|
+
this.stopAutoRefresh();
|
|
366
|
+
const scheduleNextCheck = () => {
|
|
367
|
+
const { expiresAt } = this.tokenManager.getAccessToken();
|
|
368
|
+
if (!expiresAt) {
|
|
369
|
+
this.clearAuth();
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
const now = Date.now();
|
|
373
|
+
const timeUntilExpiry = expiresAt - now;
|
|
374
|
+
const timeUntilRefresh = timeUntilExpiry - this.options.refreshThresholdMs;
|
|
375
|
+
if (timeUntilRefresh <= 0) {
|
|
376
|
+
if (rememberSession) {
|
|
377
|
+
this.refreshTokens().then((success) => {
|
|
378
|
+
if (success) {
|
|
379
|
+
scheduleNextCheck();
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
this.clearAuth();
|
|
385
|
+
}
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
// If more than 5 minutes until refresh, check every minute
|
|
389
|
+
// Otherwise, check more frequently as we get closer to expiry
|
|
390
|
+
const nextCheckInterval = timeUntilRefresh > 5 * 60 * 1000
|
|
391
|
+
? 60 * 1000 // check every minute
|
|
392
|
+
: Math.max(1000, Math.min(timeUntilRefresh / 10, 30 * 1000)); // check between 1-30 seconds
|
|
393
|
+
this.intervalRef.current = setTimeout(scheduleNextCheck, nextCheckInterval);
|
|
394
|
+
};
|
|
395
|
+
scheduleNextCheck();
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Stops automatic token refresh
|
|
399
|
+
*/
|
|
400
|
+
stopAutoRefresh() {
|
|
401
|
+
if (this.intervalRef.current) {
|
|
402
|
+
clearInterval(this.intervalRef.current);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Clears all authentication data
|
|
407
|
+
*/
|
|
408
|
+
clearAuth() {
|
|
409
|
+
this.tokenManager.clearAllTokens();
|
|
410
|
+
this.clearStorage();
|
|
411
|
+
this.refreshAttempts = 0;
|
|
412
|
+
this.stopAutoRefresh();
|
|
413
|
+
this.handleRedirectToLoginPage();
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Storage utility methods
|
|
417
|
+
*/
|
|
418
|
+
getStorageKey(key) {
|
|
419
|
+
return `${this.storageConfig.prefix}${key}`;
|
|
420
|
+
}
|
|
421
|
+
setStorageItem(key, value) {
|
|
422
|
+
if (typeof window === 'undefined')
|
|
423
|
+
return;
|
|
424
|
+
localStorage.setItem(this.getStorageKey(key), typeof value === 'string' ? value : JSON.stringify(value));
|
|
425
|
+
}
|
|
426
|
+
getStorageItem(key) {
|
|
427
|
+
if (typeof window === 'undefined')
|
|
428
|
+
return null;
|
|
429
|
+
const item = localStorage.getItem(this.getStorageKey(key));
|
|
430
|
+
if (!item)
|
|
431
|
+
return null;
|
|
432
|
+
try {
|
|
433
|
+
return JSON.parse(item);
|
|
434
|
+
}
|
|
435
|
+
catch {
|
|
436
|
+
return item;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
clearStorage() {
|
|
440
|
+
if (typeof window === 'undefined')
|
|
441
|
+
return;
|
|
442
|
+
this.storageConfig.keys.forEach((key) => {
|
|
443
|
+
localStorage.removeItem(this.getStorageKey(key));
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Error handler
|
|
448
|
+
*/
|
|
449
|
+
handleError(error) {
|
|
450
|
+
if (error instanceof Error) {
|
|
451
|
+
return {
|
|
452
|
+
code: 'UNKNOWN_ERROR',
|
|
453
|
+
message: error.message,
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
return {
|
|
457
|
+
code: 'UNKNOWN_ERROR',
|
|
458
|
+
message: 'An unknown error occurred',
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Factory function to create an AuthService instance
|
|
464
|
+
* @param config - Basic service configuration
|
|
465
|
+
* @param tokenManager
|
|
466
|
+
* @param apiClient - Shared API client instance
|
|
467
|
+
* @returns Configured AuthService instance
|
|
468
|
+
*/
|
|
469
|
+
export function createAuthService(config, tokenManager, apiClient) {
|
|
470
|
+
return new AuthService({
|
|
471
|
+
...config,
|
|
472
|
+
tokenManager,
|
|
473
|
+
apiClient,
|
|
474
|
+
});
|
|
475
|
+
}
|