@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,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Generic API client for making HTTP requests with authentication support
|
|
3
|
+
*/
|
|
4
|
+
import { type CustomAuthConfig } from '../auth';
|
|
5
|
+
import { type ApiClientConfig, type MockConfigArray, type RequestConfig } from './types';
|
|
6
|
+
export declare class ApiClient<T extends CustomAuthConfig> {
|
|
7
|
+
private readonly config;
|
|
8
|
+
private readonly activeControllers;
|
|
9
|
+
private mockConfig?;
|
|
10
|
+
constructor(config: ApiClientConfig<T>);
|
|
11
|
+
/**
|
|
12
|
+
* Sets the mock configurations for the API client.
|
|
13
|
+
* @param mockConfig - Array of mock configurations.
|
|
14
|
+
*/
|
|
15
|
+
setMockConfig(mockConfig: MockConfigArray): void;
|
|
16
|
+
/**
|
|
17
|
+
* Makes a GET request.
|
|
18
|
+
*/
|
|
19
|
+
get<ResponseType>(endpoint: string, config?: RequestConfig): Promise<ResponseType>;
|
|
20
|
+
/**
|
|
21
|
+
* Makes a POST request.
|
|
22
|
+
*/
|
|
23
|
+
post<ResponseType>(endpoint: string, data?: unknown, config?: RequestConfig): Promise<ResponseType>;
|
|
24
|
+
/**
|
|
25
|
+
* Makes a PUT request.
|
|
26
|
+
*/
|
|
27
|
+
put<ResponseType>(endpoint: string, data?: unknown, config?: RequestConfig): Promise<ResponseType>;
|
|
28
|
+
/**
|
|
29
|
+
* Makes a PATCH request.
|
|
30
|
+
*/
|
|
31
|
+
patch<ResponseType>(endpoint: string, data?: unknown, config?: RequestConfig): Promise<ResponseType>;
|
|
32
|
+
/**
|
|
33
|
+
* Makes a DELETE request.
|
|
34
|
+
*/
|
|
35
|
+
delete<ResponseType>(endpoint: string, config?: RequestConfig): Promise<ResponseType>;
|
|
36
|
+
/**
|
|
37
|
+
* Aborts all ongoing requests.
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* Aborts all ongoing requests started without a custom signal.
|
|
41
|
+
*/
|
|
42
|
+
abort(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Sets a default header for all requests.
|
|
45
|
+
*/
|
|
46
|
+
setDefaultHeader(key: string, value: string): void;
|
|
47
|
+
/**
|
|
48
|
+
* Finds a mock response that matches the request path, method, and params.
|
|
49
|
+
* @param path - The API endpoint path.
|
|
50
|
+
* @param method - The HTTP method.
|
|
51
|
+
* @param params - The query parameters or payload.
|
|
52
|
+
* @returns The mock response if a match is found, otherwise undefined.
|
|
53
|
+
*/
|
|
54
|
+
private findMockResponse;
|
|
55
|
+
/**
|
|
56
|
+
* Normalizes request parameters or body into a plain object.
|
|
57
|
+
* @param params - The query parameters or body.
|
|
58
|
+
* @returns A plain object representation of the parameters or body.
|
|
59
|
+
*/
|
|
60
|
+
private normalizeParams;
|
|
61
|
+
/**
|
|
62
|
+
* Creates a URL with query parameters.
|
|
63
|
+
*/
|
|
64
|
+
private createUrl;
|
|
65
|
+
/**
|
|
66
|
+
* Handles a request by checking for a matching mock response.
|
|
67
|
+
* If no mock is found, proceeds with the real API request.
|
|
68
|
+
*/
|
|
69
|
+
private handleRequest;
|
|
70
|
+
/**
|
|
71
|
+
* Makes the actual HTTP request.
|
|
72
|
+
*/
|
|
73
|
+
private makeRequest;
|
|
74
|
+
private buildRequestConfig;
|
|
75
|
+
private injectAuthHeader;
|
|
76
|
+
private applyOnRequestHook;
|
|
77
|
+
private fetchWithTimeout;
|
|
78
|
+
private shouldHandle401;
|
|
79
|
+
private handle401AndRetry;
|
|
80
|
+
/**
|
|
81
|
+
* Handles the API response.
|
|
82
|
+
*/
|
|
83
|
+
private handleResponse;
|
|
84
|
+
/**
|
|
85
|
+
* Handles API errors.
|
|
86
|
+
*/
|
|
87
|
+
private handleError;
|
|
88
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import { ApiError, } from './types';
|
|
2
|
+
export class ApiClient {
|
|
3
|
+
config;
|
|
4
|
+
activeControllers = new Set();
|
|
5
|
+
mockConfig;
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.config = {
|
|
8
|
+
timeout: 30000,
|
|
9
|
+
retries: 1,
|
|
10
|
+
retryDelay: 1000,
|
|
11
|
+
defaultHeaders: {
|
|
12
|
+
'Content-Type': 'application/json',
|
|
13
|
+
},
|
|
14
|
+
...config,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Sets the mock configurations for the API client.
|
|
19
|
+
* @param mockConfig - Array of mock configurations.
|
|
20
|
+
*/
|
|
21
|
+
setMockConfig(mockConfig) {
|
|
22
|
+
this.mockConfig = mockConfig;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Makes a GET request.
|
|
26
|
+
*/
|
|
27
|
+
async get(endpoint, config) {
|
|
28
|
+
return this.handleRequest(endpoint, 'GET', config);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Makes a POST request.
|
|
32
|
+
*/
|
|
33
|
+
async post(endpoint, data, config) {
|
|
34
|
+
if (data instanceof FormData) {
|
|
35
|
+
const headers = {};
|
|
36
|
+
// Copy existing headers except Content-Type
|
|
37
|
+
if (config?.headers) {
|
|
38
|
+
Object.entries(config.headers).forEach(([key, value]) => {
|
|
39
|
+
if (key !== 'Content-Type' && typeof value === 'string') {
|
|
40
|
+
headers[key] = value;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const defaultHeaders = {};
|
|
45
|
+
// Copy existing default headers except Content-Type
|
|
46
|
+
if (this.config.defaultHeaders) {
|
|
47
|
+
Object.entries(this.config.defaultHeaders).forEach(([key, value]) => {
|
|
48
|
+
if (key !== 'Content-Type' && typeof value === 'string') {
|
|
49
|
+
defaultHeaders[key] = value;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const requestConfig = {
|
|
54
|
+
...config,
|
|
55
|
+
body: data,
|
|
56
|
+
headers,
|
|
57
|
+
};
|
|
58
|
+
return this.handleRequest(endpoint, 'POST', requestConfig, defaultHeaders);
|
|
59
|
+
}
|
|
60
|
+
const body = data ? JSON.stringify(data) : undefined;
|
|
61
|
+
return this.handleRequest(endpoint, 'POST', { ...config, body });
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Makes a PUT request.
|
|
65
|
+
*/
|
|
66
|
+
async put(endpoint, data, config) {
|
|
67
|
+
const body = data ? JSON.stringify(data) : undefined;
|
|
68
|
+
return this.handleRequest(endpoint, 'PUT', { ...config, body });
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Makes a PATCH request.
|
|
72
|
+
*/
|
|
73
|
+
async patch(endpoint, data, config) {
|
|
74
|
+
const body = data ? JSON.stringify(data) : undefined;
|
|
75
|
+
return this.handleRequest(endpoint, 'PATCH', { ...config, body });
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Makes a DELETE request.
|
|
79
|
+
*/
|
|
80
|
+
async delete(endpoint, config) {
|
|
81
|
+
return this.handleRequest(endpoint, 'DELETE', config);
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Aborts all ongoing requests.
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Aborts all ongoing requests started without a custom signal.
|
|
88
|
+
*/
|
|
89
|
+
abort() {
|
|
90
|
+
this.activeControllers.forEach((controller) => controller.abort());
|
|
91
|
+
this.activeControllers.clear();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Sets a default header for all requests.
|
|
95
|
+
*/
|
|
96
|
+
setDefaultHeader(key, value) {
|
|
97
|
+
if (this.config.defaultHeaders) {
|
|
98
|
+
this.config.defaultHeaders = {
|
|
99
|
+
...this.config.defaultHeaders,
|
|
100
|
+
[key]: value,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
this.config.defaultHeaders = { [key]: value };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Finds a mock response that matches the request path, method, and params.
|
|
109
|
+
* @param path - The API endpoint path.
|
|
110
|
+
* @param method - The HTTP method.
|
|
111
|
+
* @param params - The query parameters or payload.
|
|
112
|
+
* @returns The mock response if a match is found, otherwise undefined.
|
|
113
|
+
*/
|
|
114
|
+
findMockResponse(path, method, params) {
|
|
115
|
+
if (!this.mockConfig)
|
|
116
|
+
return undefined;
|
|
117
|
+
// Convert BodyInit (e.g., FormData, URLSearchParams) to a plain object
|
|
118
|
+
const normalizedParams = this.normalizeParams(params);
|
|
119
|
+
return this.mockConfig.find((mock) => mock.path === path &&
|
|
120
|
+
mock.method === method &&
|
|
121
|
+
(!mock.params || JSON.stringify(mock.params) === JSON.stringify(normalizedParams)))?.response;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Normalizes request parameters or body into a plain object.
|
|
125
|
+
* @param params - The query parameters or body.
|
|
126
|
+
* @returns A plain object representation of the parameters or body.
|
|
127
|
+
*/
|
|
128
|
+
normalizeParams(params) {
|
|
129
|
+
if (!params)
|
|
130
|
+
return undefined;
|
|
131
|
+
// Handle FormData
|
|
132
|
+
if (params instanceof FormData) {
|
|
133
|
+
const result = {};
|
|
134
|
+
params.forEach((value, key) => {
|
|
135
|
+
result[key] = value;
|
|
136
|
+
});
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
// Handle URLSearchParams
|
|
140
|
+
if (params instanceof URLSearchParams) {
|
|
141
|
+
const result = {};
|
|
142
|
+
params.forEach((value, key) => {
|
|
143
|
+
result[key] = value;
|
|
144
|
+
});
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
// Handle Blob, ArrayBuffer, etc. (wrap in an object)
|
|
148
|
+
if (params instanceof Blob || params instanceof ArrayBuffer) {
|
|
149
|
+
return { body: params }; // Wrap in an object to make it compatible
|
|
150
|
+
}
|
|
151
|
+
if (typeof params === 'string') {
|
|
152
|
+
return JSON.parse(params);
|
|
153
|
+
}
|
|
154
|
+
// Handle plain objects or arrays
|
|
155
|
+
return params;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Creates a URL with query parameters.
|
|
159
|
+
*/
|
|
160
|
+
createUrl(endpoint, params) {
|
|
161
|
+
const url = new URL(endpoint.startsWith('http') ? endpoint : `${this.config.baseURL}${endpoint}`);
|
|
162
|
+
if (params) {
|
|
163
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
164
|
+
url.searchParams.append(key, value);
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return url.toString();
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Handles a request by checking for a matching mock response.
|
|
171
|
+
* If no mock is found, proceeds with the real API request.
|
|
172
|
+
*/
|
|
173
|
+
async handleRequest(endpoint, method, config = {}, overrideDefaultHeaders) {
|
|
174
|
+
// Check for a mock response
|
|
175
|
+
const mockResponse = this.findMockResponse(endpoint, method, config.params || config.body);
|
|
176
|
+
if (mockResponse !== undefined) {
|
|
177
|
+
// Simulate network delay
|
|
178
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
179
|
+
return mockResponse;
|
|
180
|
+
}
|
|
181
|
+
// Proceed with the real API request
|
|
182
|
+
const { params, timeout = this.config.timeout, retries = this.config.retries, skipAuth = false, skipRetry = false, skipRefresh = false, signal, ...requestConfig } = config;
|
|
183
|
+
let attempt = 0;
|
|
184
|
+
const maxAttempts = skipRetry ? 1 : (retries ?? 0) + 1;
|
|
185
|
+
while (attempt < maxAttempts) {
|
|
186
|
+
try {
|
|
187
|
+
const response = await this.makeRequest(endpoint, method, {
|
|
188
|
+
params,
|
|
189
|
+
timeout,
|
|
190
|
+
skipAuth,
|
|
191
|
+
skipRefresh,
|
|
192
|
+
signal,
|
|
193
|
+
requestConfig,
|
|
194
|
+
overrideDefaultHeaders,
|
|
195
|
+
});
|
|
196
|
+
const data = await this.handleResponse(response);
|
|
197
|
+
if (!response.ok) {
|
|
198
|
+
throw new ApiError(data?.message ?? 'Request failed', response.status, data);
|
|
199
|
+
}
|
|
200
|
+
return data;
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
attempt++;
|
|
204
|
+
if (attempt >= maxAttempts) {
|
|
205
|
+
await this.handleError(error);
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
await new Promise((resolve) => setTimeout(resolve, this.config.retryDelay));
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
throw new ApiError('Request failed after all retries', 0);
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Makes the actual HTTP request.
|
|
215
|
+
*/
|
|
216
|
+
async makeRequest(endpoint, method, config) {
|
|
217
|
+
const { params, timeout, skipAuth, skipRefresh, requestConfig, overrideDefaultHeaders, signal } = config;
|
|
218
|
+
const url = this.createUrl(endpoint, params);
|
|
219
|
+
// Use provided signal, or create a new AbortController for this request
|
|
220
|
+
let requestSignal;
|
|
221
|
+
let controller;
|
|
222
|
+
if (signal) {
|
|
223
|
+
requestSignal = signal;
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
controller = new AbortController();
|
|
227
|
+
this.activeControllers.add(controller);
|
|
228
|
+
requestSignal = controller.signal;
|
|
229
|
+
}
|
|
230
|
+
let finalConfig = this.buildRequestConfig(requestConfig, method, overrideDefaultHeaders, requestSignal);
|
|
231
|
+
finalConfig = await this.injectAuthHeader(finalConfig, skipAuth);
|
|
232
|
+
finalConfig = await this.applyOnRequestHook(finalConfig);
|
|
233
|
+
let response;
|
|
234
|
+
try {
|
|
235
|
+
response = await this.fetchWithTimeout(url, finalConfig, timeout, controller);
|
|
236
|
+
}
|
|
237
|
+
finally {
|
|
238
|
+
if (controller)
|
|
239
|
+
this.activeControllers.delete(controller);
|
|
240
|
+
}
|
|
241
|
+
if (await this.shouldHandle401(response, skipAuth, skipRefresh)) {
|
|
242
|
+
return this.handle401AndRetry(endpoint, method, config);
|
|
243
|
+
}
|
|
244
|
+
return response;
|
|
245
|
+
}
|
|
246
|
+
buildRequestConfig(requestConfig, method, overrideDefaultHeaders, signal) {
|
|
247
|
+
return {
|
|
248
|
+
...requestConfig,
|
|
249
|
+
method,
|
|
250
|
+
headers: {
|
|
251
|
+
...(overrideDefaultHeaders ?? this.config.defaultHeaders),
|
|
252
|
+
...requestConfig.headers,
|
|
253
|
+
},
|
|
254
|
+
signal,
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
async injectAuthHeader(finalConfig, skipAuth) {
|
|
258
|
+
if (!skipAuth && this.config.tokenManager) {
|
|
259
|
+
const { token } = this.config.tokenManager.getAccessToken();
|
|
260
|
+
if (token) {
|
|
261
|
+
return {
|
|
262
|
+
...finalConfig,
|
|
263
|
+
headers: {
|
|
264
|
+
...finalConfig.headers,
|
|
265
|
+
Authorization: `Bearer ${token}`,
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return finalConfig;
|
|
271
|
+
}
|
|
272
|
+
async applyOnRequestHook(finalConfig) {
|
|
273
|
+
if (this.config.onRequest) {
|
|
274
|
+
return this.config.onRequest(finalConfig);
|
|
275
|
+
}
|
|
276
|
+
return finalConfig;
|
|
277
|
+
}
|
|
278
|
+
async fetchWithTimeout(url, finalConfig, timeout, controller) {
|
|
279
|
+
let timeoutId = null;
|
|
280
|
+
try {
|
|
281
|
+
if (timeout && controller) {
|
|
282
|
+
timeoutId = setTimeout(() => {
|
|
283
|
+
controller.abort();
|
|
284
|
+
}, timeout);
|
|
285
|
+
}
|
|
286
|
+
return await fetch(url, finalConfig);
|
|
287
|
+
}
|
|
288
|
+
finally {
|
|
289
|
+
if (timeoutId)
|
|
290
|
+
clearTimeout(timeoutId);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
async shouldHandle401(response, skipAuth, skipRefresh) {
|
|
294
|
+
return response.status === 401 && !skipAuth && !skipRefresh && !!this.config.tokenManager;
|
|
295
|
+
}
|
|
296
|
+
async handle401AndRetry(endpoint, method, config) {
|
|
297
|
+
const refreshed = await this.config.tokenManager.refreshTokens();
|
|
298
|
+
if (refreshed) {
|
|
299
|
+
const newToken = this.config.tokenManager.getAccessToken().token;
|
|
300
|
+
if (newToken) {
|
|
301
|
+
return this.makeRequest(endpoint, method, {
|
|
302
|
+
...config,
|
|
303
|
+
skipRefresh: true, // Prevent infinite refresh loop
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
this.config.onUnauthorized?.();
|
|
308
|
+
throw new ApiError('Unauthorized', 401);
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Handles the API response.
|
|
312
|
+
*/
|
|
313
|
+
async handleResponse(response) {
|
|
314
|
+
let data;
|
|
315
|
+
const contentType = response.headers.get('content-type');
|
|
316
|
+
if (contentType?.includes('application/json')) {
|
|
317
|
+
data = await response.json();
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
data = response;
|
|
321
|
+
}
|
|
322
|
+
if (this.config.onResponse) {
|
|
323
|
+
data = await this.config.onResponse(response, data);
|
|
324
|
+
}
|
|
325
|
+
return data;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Handles API errors.
|
|
329
|
+
*/
|
|
330
|
+
async handleError(error) {
|
|
331
|
+
if (error instanceof ApiError) {
|
|
332
|
+
await this.config.onError?.(error);
|
|
333
|
+
}
|
|
334
|
+
else if (error instanceof Error) {
|
|
335
|
+
const apiError = new ApiError(error.message, 0, { originalError: error });
|
|
336
|
+
await this.config.onError?.(apiError);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview API Context and utilities for managing a shared API client instance
|
|
3
|
+
* Provides context, provider component, and hooks for consistent API access across the application
|
|
4
|
+
*/
|
|
5
|
+
import { type ReactNode } from 'react';
|
|
6
|
+
import type { CustomAuthConfig, TokenManager } from '../auth';
|
|
7
|
+
import { ApiClient } from './client';
|
|
8
|
+
import type { MockConfigArray } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* Props for the ApiProvider component
|
|
11
|
+
*
|
|
12
|
+
* @template T - Type extending CustomAuthConfig that defines the shape of authentication data
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* const apiClient = createApiClient<MyAuthConfig>({...});
|
|
17
|
+
*
|
|
18
|
+
* return (
|
|
19
|
+
* <ApiProvider apiClient={apiClient}>
|
|
20
|
+
* <App />
|
|
21
|
+
* </ApiProvider>
|
|
22
|
+
* );
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
interface ApiProviderProps<T extends CustomAuthConfig> {
|
|
26
|
+
/** React children nodes */
|
|
27
|
+
children: ReactNode;
|
|
28
|
+
/** Configured API client instance */
|
|
29
|
+
apiClient: ApiClient<T>;
|
|
30
|
+
/** Whether to use mock API */
|
|
31
|
+
mocked?: boolean;
|
|
32
|
+
/** Mock configurations for API requests */
|
|
33
|
+
mockConfig?: MockConfigArray;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Provider component for the API context
|
|
37
|
+
* Makes the API client instance available to all child components
|
|
38
|
+
*
|
|
39
|
+
* @template T - Type extending CustomAuthConfig
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* function App() {
|
|
44
|
+
* return (
|
|
45
|
+
* <ApiProvider apiClient={apiClient}>
|
|
46
|
+
* <MyComponents />
|
|
47
|
+
* </ApiProvider>
|
|
48
|
+
* );
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function ApiProvider<T extends CustomAuthConfig>({ children, apiClient, mocked, mockConfig, }: Readonly<ApiProviderProps<T>>): import("react/jsx-runtime").JSX.Element;
|
|
53
|
+
/**
|
|
54
|
+
* Hook for accessing the API client instance
|
|
55
|
+
* Must be used within an ApiProvider component
|
|
56
|
+
*
|
|
57
|
+
* @template T - Type extending CustomAuthConfig for type-safe API operations
|
|
58
|
+
* @returns The shared API client instance
|
|
59
|
+
* @throws Error if used outside of ApiProvider
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```tsx
|
|
63
|
+
* function MyComponent() {
|
|
64
|
+
* const api = useApi<MyAuthConfig>();
|
|
65
|
+
*
|
|
66
|
+
* const fetchData = async () => {
|
|
67
|
+
* try {
|
|
68
|
+
* const data = await api.get('/endpoint');
|
|
69
|
+
* // Handle response
|
|
70
|
+
* } catch (error) {
|
|
71
|
+
* // Handle error
|
|
72
|
+
* }
|
|
73
|
+
* };
|
|
74
|
+
*
|
|
75
|
+
* return <div>...</div>;
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function useApi<T extends CustomAuthConfig>(): ApiClient<T>;
|
|
80
|
+
/**
|
|
81
|
+
* Factory function to create a configured ApiClient instance
|
|
82
|
+
*
|
|
83
|
+
* @template T - Type extending CustomAuthConfig that defines the shape of authentication data
|
|
84
|
+
* @param config - Configuration options for the API client
|
|
85
|
+
* @param config.baseURL - Base URL for all API requests
|
|
86
|
+
* @param config.tokenManager - Token manager instance for handling authentication
|
|
87
|
+
* @param config.defaultHeaders - Default headers to include in all requests
|
|
88
|
+
* @param config.timeout - Request timeout in milliseconds (default: 30000)
|
|
89
|
+
* @param config.retries - Number of retry attempts for failed requests (default: 1)
|
|
90
|
+
* @returns Configured ApiClient instance
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* const apiClient = createApiClient<MyAuthConfig>({
|
|
95
|
+
* baseURL: 'https://api.example.com',
|
|
96
|
+
* tokenManager: tokenManager,
|
|
97
|
+
* defaultHeaders: {
|
|
98
|
+
* 'Content-Type': 'application/json',
|
|
99
|
+
* },
|
|
100
|
+
* timeout: 5000,
|
|
101
|
+
* retries: 2,
|
|
102
|
+
* });
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export declare function createApiClient<T extends CustomAuthConfig>({ baseURL, tokenManager, defaultHeaders, timeout, retries, }: {
|
|
106
|
+
baseURL: string;
|
|
107
|
+
tokenManager: TokenManager<T>;
|
|
108
|
+
defaultHeaders?: HeadersInit;
|
|
109
|
+
timeout?: number;
|
|
110
|
+
retries?: number;
|
|
111
|
+
}): ApiClient<T>;
|
|
112
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview API Context and utilities for managing a shared API client instance
|
|
4
|
+
* Provides context, provider component, and hooks for consistent API access across the application
|
|
5
|
+
*/
|
|
6
|
+
import { createContext, useContext, useMemo } from 'react';
|
|
7
|
+
import { ApiClient } from './client';
|
|
8
|
+
/**
|
|
9
|
+
* React context for sharing the API client instance
|
|
10
|
+
* Initialized as undefined to ensure proper provider wrapping
|
|
11
|
+
*/
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
13
|
+
const ApiContext = createContext(undefined);
|
|
14
|
+
/**
|
|
15
|
+
* Provider component for the API context
|
|
16
|
+
* Makes the API client instance available to all child components
|
|
17
|
+
*
|
|
18
|
+
* @template T - Type extending CustomAuthConfig
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* function App() {
|
|
23
|
+
* return (
|
|
24
|
+
* <ApiProvider apiClient={apiClient}>
|
|
25
|
+
* <MyComponents />
|
|
26
|
+
* </ApiProvider>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export function ApiProvider({ children, apiClient, mocked = false, mockConfig = [], }) {
|
|
32
|
+
// Set mock config on the API client if mocking is enabled
|
|
33
|
+
if (mocked) {
|
|
34
|
+
apiClient.setMockConfig(mockConfig);
|
|
35
|
+
}
|
|
36
|
+
const value = useMemo(() => ({ apiClient }), [apiClient]);
|
|
37
|
+
return _jsx(ApiContext.Provider, { value: value, children: children });
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Hook for accessing the API client instance
|
|
41
|
+
* Must be used within an ApiProvider component
|
|
42
|
+
*
|
|
43
|
+
* @template T - Type extending CustomAuthConfig for type-safe API operations
|
|
44
|
+
* @returns The shared API client instance
|
|
45
|
+
* @throws Error if used outside of ApiProvider
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```tsx
|
|
49
|
+
* function MyComponent() {
|
|
50
|
+
* const api = useApi<MyAuthConfig>();
|
|
51
|
+
*
|
|
52
|
+
* const fetchData = async () => {
|
|
53
|
+
* try {
|
|
54
|
+
* const data = await api.get('/endpoint');
|
|
55
|
+
* // Handle response
|
|
56
|
+
* } catch (error) {
|
|
57
|
+
* // Handle error
|
|
58
|
+
* }
|
|
59
|
+
* };
|
|
60
|
+
*
|
|
61
|
+
* return <div>...</div>;
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export function useApi() {
|
|
66
|
+
const context = useContext(ApiContext);
|
|
67
|
+
if (!context) {
|
|
68
|
+
throw new Error('useApi must be used within an ApiProvider');
|
|
69
|
+
}
|
|
70
|
+
return context.apiClient;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Factory function to create a configured ApiClient instance
|
|
74
|
+
*
|
|
75
|
+
* @template T - Type extending CustomAuthConfig that defines the shape of authentication data
|
|
76
|
+
* @param config - Configuration options for the API client
|
|
77
|
+
* @param config.baseURL - Base URL for all API requests
|
|
78
|
+
* @param config.tokenManager - Token manager instance for handling authentication
|
|
79
|
+
* @param config.defaultHeaders - Default headers to include in all requests
|
|
80
|
+
* @param config.timeout - Request timeout in milliseconds (default: 30000)
|
|
81
|
+
* @param config.retries - Number of retry attempts for failed requests (default: 1)
|
|
82
|
+
* @returns Configured ApiClient instance
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* const apiClient = createApiClient<MyAuthConfig>({
|
|
87
|
+
* baseURL: 'https://api.example.com',
|
|
88
|
+
* tokenManager: tokenManager,
|
|
89
|
+
* defaultHeaders: {
|
|
90
|
+
* 'Content-Type': 'application/json',
|
|
91
|
+
* },
|
|
92
|
+
* timeout: 5000,
|
|
93
|
+
* retries: 2,
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export function createApiClient({ baseURL, tokenManager, defaultHeaders = {}, timeout = 30000, retries = 1, }) {
|
|
98
|
+
return new ApiClient({
|
|
99
|
+
baseURL,
|
|
100
|
+
tokenManager,
|
|
101
|
+
defaultHeaders,
|
|
102
|
+
timeout,
|
|
103
|
+
retries,
|
|
104
|
+
});
|
|
105
|
+
}
|
package/lib/api/index.js
ADDED
package/lib/api/swr.d.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview SWR integration for the API client
|
|
3
|
+
*/
|
|
4
|
+
import { type Key, type SWRConfiguration, type SWRResponse } from 'swr';
|
|
5
|
+
import type { ApiErrorResponse, RequestConfig, SpringBootResponse } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Main SWR hook that automatically inherits auth config
|
|
8
|
+
* @template ResponseData - Type of the expected response data
|
|
9
|
+
* @template ErrorData - Type of the error response (defaults to ApiErrorResponse)
|
|
10
|
+
*/
|
|
11
|
+
export declare function useApiSWR<ResponseData, ErrorData = ApiErrorResponse>(endpoint: Key, config?: RequestConfig & SWRConfiguration<ResponseData, ErrorData>): SWRResponse<ResponseData, ErrorData>;
|
|
12
|
+
/**
|
|
13
|
+
* Paginated SWR hook that inherits auth config
|
|
14
|
+
* @template ItemType - Type of items in the paginated response
|
|
15
|
+
* @template ResponseType - Type of the full response (defaults to SpringBootResponse)
|
|
16
|
+
*/
|
|
17
|
+
export declare function usePaginatedApiSWR<ItemType, ResponseType extends {
|
|
18
|
+
content: ItemType[];
|
|
19
|
+
} = SpringBootResponse<ItemType>>(endpoint: Key, config?: RequestConfig & SWRConfiguration<ResponseType>): SWRResponse<ResponseType>;
|
|
20
|
+
/**
|
|
21
|
+
* Mutation hook that inherits auth config
|
|
22
|
+
* @template ResponseData - Type of the expected response data
|
|
23
|
+
*/
|
|
24
|
+
export declare function useApiMutation<ResponseData>(): {
|
|
25
|
+
post: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
|
|
26
|
+
put: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
|
|
27
|
+
patch: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
|
|
28
|
+
delete: (endpoint: string, config?: RequestConfig) => Promise<ResponseData>;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Combined SWR and mutation hook
|
|
32
|
+
* @template ResponseData - Type of the expected response data
|
|
33
|
+
*/
|
|
34
|
+
export declare function useApiSWRWithMutation<ResponseData>(endpoint: Key, config?: RequestConfig & SWRConfiguration<ResponseData>): {
|
|
35
|
+
mutate: {
|
|
36
|
+
post: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
|
|
37
|
+
put: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
|
|
38
|
+
patch: (endpoint: string, data?: unknown, config?: RequestConfig) => Promise<ResponseData>;
|
|
39
|
+
delete: (endpoint: string, config?: RequestConfig) => Promise<ResponseData>;
|
|
40
|
+
};
|
|
41
|
+
refresh: () => Promise<any>;
|
|
42
|
+
data: ResponseData | undefined;
|
|
43
|
+
error: ApiErrorResponse | undefined;
|
|
44
|
+
isValidating: boolean;
|
|
45
|
+
isLoading: boolean;
|
|
46
|
+
};
|