@greatapps/common 1.1.133 → 1.1.134
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/dist/MMQ4R4NB-B36VHW65.mjs +61 -0
- package/dist/MMQ4R4NB-B36VHW65.mjs.map +1 -0
- package/dist/V4HPSUGU-6BOE4IPH.mjs +51 -0
- package/dist/V4HPSUGU-6BOE4IPH.mjs.map +1 -0
- package/dist/account-management.action-7QQCACDJ.mjs +40 -0
- package/dist/account.service-XTZDEIPS.mjs +9 -0
- package/dist/{modules/auth/services/auth.service.mjs → chunk-7MBVHKTC.mjs} +46 -13
- package/dist/chunk-7MBVHKTC.mjs.map +1 -0
- package/dist/{modules/users/services/user.service.mjs → chunk-B2W2HK7C.mjs} +13 -8
- package/dist/chunk-B2W2HK7C.mjs.map +1 -0
- package/dist/{modules/auth/actions/validate-session.action.mjs → chunk-EC3T7NF6.mjs} +8 -4
- package/dist/chunk-EC3T7NF6.mjs.map +1 -0
- package/dist/chunk-EKZZ2RWJ.mjs +12701 -0
- package/dist/chunk-EKZZ2RWJ.mjs.map +1 -0
- package/dist/chunk-ICUZDG2N.mjs +283 -0
- package/dist/chunk-ICUZDG2N.mjs.map +1 -0
- package/dist/{utils/safeServerAction.mjs → chunk-JW4XRHLX.mjs} +7 -2
- package/dist/chunk-JW4XRHLX.mjs.map +1 -0
- package/dist/chunk-QEFMNBSY.mjs +165 -0
- package/dist/chunk-QEFMNBSY.mjs.map +1 -0
- package/dist/{infra/api/client.mjs → chunk-RV7ECGIH.mjs} +12 -7
- package/dist/chunk-RV7ECGIH.mjs.map +1 -0
- package/dist/chunk-S53NE5H4.mjs +2928 -0
- package/dist/chunk-S53NE5H4.mjs.map +1 -0
- package/dist/{modules/whitelabel/services/whitelabel.service.mjs → chunk-UEWT6VFS.mjs} +57 -9
- package/dist/chunk-UEWT6VFS.mjs.map +1 -0
- package/dist/chunk-XY4LNPBR.mjs +16 -0
- package/dist/chunk-XY4LNPBR.mjs.map +1 -0
- package/dist/{modules/accounts/services/account.service.mjs → chunk-Z3Q2LLBS.mjs} +64 -9
- package/dist/chunk-Z3Q2LLBS.mjs.map +1 -0
- package/dist/find-user-by-id.action-BUFTU3ZY.mjs +11 -0
- package/dist/index.mjs +9584 -258
- package/dist/index.mjs.map +1 -1
- package/dist/modern-4YXF5ES3.mjs +426 -0
- package/dist/modern-4YXF5ES3.mjs.map +1 -0
- package/dist/server.mjs +140 -36
- package/dist/server.mjs.map +1 -1
- package/dist/user.service-VDR4JKHO.mjs +8 -0
- package/dist/validate-session.action-K7RWN2GE.mjs +11 -0
- package/dist/{modules/auth/actions/verify-two-factor.action.mjs → verify-two-factor.action-V6JQATK2.mjs} +12 -4
- package/dist/verify-two-factor.action-V6JQATK2.mjs.map +1 -0
- package/package.json +1 -1
- package/dist/components/account/AccountModals.mjs +0 -18
- package/dist/components/account/AccountModals.mjs.map +0 -1
- package/dist/components/account/ConfigurationsMyAccountModal.mjs +0 -132
- package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +0 -1
- package/dist/components/account/ConfirmDeleteAccountModal.mjs +0 -45
- package/dist/components/account/ConfirmDeleteAccountModal.mjs.map +0 -1
- package/dist/components/account/ConfirmGlobalPreferencesModal.mjs +0 -45
- package/dist/components/account/ConfirmGlobalPreferencesModal.mjs.map +0 -1
- package/dist/components/account/DeleteAccountModal.mjs +0 -123
- package/dist/components/account/DeleteAccountModal.mjs.map +0 -1
- package/dist/components/account/DisableTwoFactorAuthModal.mjs +0 -67
- package/dist/components/account/DisableTwoFactorAuthModal.mjs.map +0 -1
- package/dist/components/account/IsntPossibleDeleteAccountModal.mjs +0 -42
- package/dist/components/account/IsntPossibleDeleteAccountModal.mjs.map +0 -1
- package/dist/components/account/TwoFactorAuthModal.mjs +0 -190
- package/dist/components/account/TwoFactorAuthModal.mjs.map +0 -1
- package/dist/components/account/constants.mjs +0 -29
- package/dist/components/account/constants.mjs.map +0 -1
- package/dist/components/account/hooks/useChangeEmailForm.mjs +0 -53
- package/dist/components/account/hooks/useChangeEmailForm.mjs.map +0 -1
- package/dist/components/account/hooks/useChangePasswordForm.mjs +0 -47
- package/dist/components/account/hooks/useChangePasswordForm.mjs.map +0 -1
- package/dist/components/account/hooks/useChangePhoneForm.mjs +0 -64
- package/dist/components/account/hooks/useChangePhoneForm.mjs.map +0 -1
- package/dist/components/account/hooks/useConfigurationsModal.mjs +0 -33
- package/dist/components/account/hooks/useConfigurationsModal.mjs.map +0 -1
- package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs +0 -54
- package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs.map +0 -1
- package/dist/components/account/hooks/useOtpVerification.mjs +0 -94
- package/dist/components/account/hooks/useOtpVerification.mjs.map +0 -1
- package/dist/components/account/hooks/useTwoFactorAuthForm.mjs +0 -80
- package/dist/components/account/hooks/useTwoFactorAuthForm.mjs.map +0 -1
- package/dist/components/account/sections/ChangeEmailModal.mjs +0 -180
- package/dist/components/account/sections/ChangeEmailModal.mjs.map +0 -1
- package/dist/components/account/sections/ChangePasswordSection.mjs +0 -64
- package/dist/components/account/sections/ChangePasswordSection.mjs.map +0 -1
- package/dist/components/account/sections/ChangePhoneModal.mjs +0 -182
- package/dist/components/account/sections/ChangePhoneModal.mjs.map +0 -1
- package/dist/components/account/sections/MyProfileSection.mjs +0 -303
- package/dist/components/account/sections/MyProfileSection.mjs.map +0 -1
- package/dist/components/account/sections/PreferencesSection.mjs +0 -250
- package/dist/components/account/sections/PreferencesSection.mjs.map +0 -1
- package/dist/components/account/sections/SecuritySection.mjs +0 -147
- package/dist/components/account/sections/SecuritySection.mjs.map +0 -1
- package/dist/components/handlers/SearchParamsHandler.mjs +0 -24
- package/dist/components/handlers/SearchParamsHandler.mjs.map +0 -1
- package/dist/components/layouts/AppMobileNavBar.mjs +0 -115
- package/dist/components/layouts/AppMobileNavBar.mjs.map +0 -1
- package/dist/components/layouts/AppNavBar.mjs +0 -49
- package/dist/components/layouts/AppNavBar.mjs.map +0 -1
- package/dist/components/layouts/MainLayout.mjs +0 -60
- package/dist/components/layouts/MainLayout.mjs.map +0 -1
- package/dist/components/layouts/MdSideBarNavigation.mjs +0 -54
- package/dist/components/layouts/MdSideBarNavigation.mjs.map +0 -1
- package/dist/components/layouts/NavBar.mjs +0 -132
- package/dist/components/layouts/NavBar.mjs.map +0 -1
- package/dist/components/layouts/NavBarItem.mjs +0 -23
- package/dist/components/layouts/NavBarItem.mjs.map +0 -1
- package/dist/components/layouts/NotificationsPopover.mjs +0 -97
- package/dist/components/layouts/NotificationsPopover.mjs.map +0 -1
- package/dist/components/layouts/ProfilePopover.mjs +0 -150
- package/dist/components/layouts/ProfilePopover.mjs.map +0 -1
- package/dist/components/layouts/SideBarNavigation.mjs +0 -22
- package/dist/components/layouts/SideBarNavigation.mjs.map +0 -1
- package/dist/components/layouts/UsersSelectorPopover.mjs +0 -236
- package/dist/components/layouts/UsersSelectorPopover.mjs.map +0 -1
- package/dist/components/modals/ModalManager.mjs +0 -19
- package/dist/components/modals/ModalManager.mjs.map +0 -1
- package/dist/components/modals/Modals.mjs +0 -20
- package/dist/components/modals/Modals.mjs.map +0 -1
- package/dist/components/navigation/AppNavigation.mjs +0 -30
- package/dist/components/navigation/AppNavigation.mjs.map +0 -1
- package/dist/components/navigation/AppNavigationContext.mjs +0 -13
- package/dist/components/navigation/AppNavigationContext.mjs.map +0 -1
- package/dist/components/navigation/NavItem.mjs +0 -35
- package/dist/components/navigation/NavItem.mjs.map +0 -1
- package/dist/components/navigation/NavItemsContext.mjs +0 -16
- package/dist/components/navigation/NavItemsContext.mjs.map +0 -1
- package/dist/components/navigation/ProjectSelectorPopover.mjs +0 -128
- package/dist/components/navigation/ProjectSelectorPopover.mjs.map +0 -1
- package/dist/components/navigation/shells/DesktopShell.mjs +0 -11
- package/dist/components/navigation/shells/DesktopShell.mjs.map +0 -1
- package/dist/components/navigation/shells/MdShell.mjs +0 -11
- package/dist/components/navigation/shells/MdShell.mjs.map +0 -1
- package/dist/components/navigation/shells/MobileShell.mjs +0 -27
- package/dist/components/navigation/shells/MobileShell.mjs.map +0 -1
- package/dist/components/navigation/shells/TabsMobileShell.mjs +0 -59
- package/dist/components/navigation/shells/TabsMobileShell.mjs.map +0 -1
- package/dist/components/navigation/subcomponents/CreditsCard.mjs +0 -30
- package/dist/components/navigation/subcomponents/CreditsCard.mjs.map +0 -1
- package/dist/components/navigation/subcomponents/NavItems.mjs +0 -25
- package/dist/components/navigation/subcomponents/NavItems.mjs.map +0 -1
- package/dist/components/navigation/subcomponents/PlanCard.mjs +0 -25
- package/dist/components/navigation/subcomponents/PlanCard.mjs.map +0 -1
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs +0 -130
- package/dist/components/navigation/subcomponents/ProjectSelector.mjs.map +0 -1
- package/dist/components/navigation/types.mjs +0 -1
- package/dist/components/pages/notifications/Notifications.mjs +0 -156
- package/dist/components/pages/notifications/Notifications.mjs.map +0 -1
- package/dist/components/ui/buttons/Button.mjs +0 -52
- package/dist/components/ui/buttons/Button.mjs.map +0 -1
- package/dist/components/ui/buttons/CancelButton.mjs +0 -17
- package/dist/components/ui/buttons/CancelButton.mjs.map +0 -1
- package/dist/components/ui/buttons/CopyButton.mjs +0 -42
- package/dist/components/ui/buttons/CopyButton.mjs.map +0 -1
- package/dist/components/ui/data-display/Accordion.mjs +0 -76
- package/dist/components/ui/data-display/Accordion.mjs.map +0 -1
- package/dist/components/ui/data-display/Badge.mjs +0 -42
- package/dist/components/ui/data-display/Badge.mjs.map +0 -1
- package/dist/components/ui/data-display/Card.mjs +0 -92
- package/dist/components/ui/data-display/Card.mjs.map +0 -1
- package/dist/components/ui/data-display/Pagination.mjs +0 -118
- package/dist/components/ui/data-display/Pagination.mjs.map +0 -1
- package/dist/components/ui/data-display/ScrollArea.mjs +0 -62
- package/dist/components/ui/data-display/ScrollArea.mjs.map +0 -1
- package/dist/components/ui/data-display/Separator.mjs +0 -28
- package/dist/components/ui/data-display/Separator.mjs.map +0 -1
- package/dist/components/ui/data-display/Table.mjs +0 -116
- package/dist/components/ui/data-display/Table.mjs.map +0 -1
- package/dist/components/ui/data-display/Tabs.mjs +0 -69
- package/dist/components/ui/data-display/Tabs.mjs.map +0 -1
- package/dist/components/ui/data-display/UserAvatar.mjs +0 -49
- package/dist/components/ui/data-display/UserAvatar.mjs.map +0 -1
- package/dist/components/ui/feedback/CircularProgress.mjs +0 -71
- package/dist/components/ui/feedback/CircularProgress.mjs.map +0 -1
- package/dist/components/ui/feedback/DefaultCircularProgress.mjs +0 -50
- package/dist/components/ui/feedback/DefaultCircularProgress.mjs.map +0 -1
- package/dist/components/ui/feedback/LoadingOverlay.mjs +0 -19
- package/dist/components/ui/feedback/LoadingOverlay.mjs.map +0 -1
- package/dist/components/ui/feedback/Progress.mjs +0 -37
- package/dist/components/ui/feedback/Progress.mjs.map +0 -1
- package/dist/components/ui/feedback/Toast.mjs +0 -77
- package/dist/components/ui/feedback/Toast.mjs.map +0 -1
- package/dist/components/ui/form/Calendar.mjs +0 -204
- package/dist/components/ui/form/Calendar.mjs.map +0 -1
- package/dist/components/ui/form/Checkbox.mjs +0 -33
- package/dist/components/ui/form/Checkbox.mjs.map +0 -1
- package/dist/components/ui/form/ComboboxField.mjs +0 -130
- package/dist/components/ui/form/ComboboxField.mjs.map +0 -1
- package/dist/components/ui/form/DatePicker.mjs +0 -82
- package/dist/components/ui/form/DatePicker.mjs.map +0 -1
- package/dist/components/ui/form/DateRangePicker.mjs +0 -92
- package/dist/components/ui/form/DateRangePicker.mjs.map +0 -1
- package/dist/components/ui/form/FormField.mjs +0 -103
- package/dist/components/ui/form/FormField.mjs.map +0 -1
- package/dist/components/ui/form/Input.mjs +0 -21
- package/dist/components/ui/form/Input.mjs.map +0 -1
- package/dist/components/ui/form/InputOtp.mjs +0 -70
- package/dist/components/ui/form/InputOtp.mjs.map +0 -1
- package/dist/components/ui/form/PhoneInput.mjs +0 -78
- package/dist/components/ui/form/PhoneInput.mjs.map +0 -1
- package/dist/components/ui/form/RadioGroup.mjs +0 -37
- package/dist/components/ui/form/RadioGroup.mjs.map +0 -1
- package/dist/components/ui/form/Select.mjs +0 -179
- package/dist/components/ui/form/Select.mjs.map +0 -1
- package/dist/components/ui/form/SelectField.mjs +0 -80
- package/dist/components/ui/form/SelectField.mjs.map +0 -1
- package/dist/components/ui/form/Switch.mjs +0 -33
- package/dist/components/ui/form/Switch.mjs.map +0 -1
- package/dist/components/ui/form/SwitchOptionFieldWithIcon.mjs +0 -40
- package/dist/components/ui/form/SwitchOptionFieldWithIcon.mjs.map +0 -1
- package/dist/components/ui/form/TextAreaField.mjs +0 -56
- package/dist/components/ui/form/TextAreaField.mjs.map +0 -1
- package/dist/components/ui/form/Textarea.mjs +0 -20
- package/dist/components/ui/form/Textarea.mjs.map +0 -1
- package/dist/components/ui/overlay/Command.mjs +0 -178
- package/dist/components/ui/overlay/Command.mjs.map +0 -1
- package/dist/components/ui/overlay/Dialog.mjs +0 -142
- package/dist/components/ui/overlay/Dialog.mjs.map +0 -1
- package/dist/components/ui/overlay/Popover.mjs +0 -46
- package/dist/components/ui/overlay/Popover.mjs.map +0 -1
- package/dist/components/ui/overlay/Sheet.mjs +0 -142
- package/dist/components/ui/overlay/Sheet.mjs.map +0 -1
- package/dist/components/ui/overlay/Tooltip.mjs +0 -57
- package/dist/components/ui/overlay/Tooltip.mjs.map +0 -1
- package/dist/components/widgets/notifications/NotificationCard.mjs +0 -54
- package/dist/components/widgets/notifications/NotificationCard.mjs.map +0 -1
- package/dist/enums/AccountSectionType.mjs +0 -11
- package/dist/enums/AccountSectionType.mjs.map +0 -1
- package/dist/hooks/copy-to-clipboard.hook.mjs +0 -52
- package/dist/hooks/copy-to-clipboard.hook.mjs.map +0 -1
- package/dist/hooks/useCountdownTimer.mjs +0 -29
- package/dist/hooks/useCountdownTimer.mjs.map +0 -1
- package/dist/hooks/useDebounce.mjs +0 -19
- package/dist/hooks/useDebounce.mjs.map +0 -1
- package/dist/hooks/useDebounceState.mjs +0 -12
- package/dist/hooks/useDebounceState.mjs.map +0 -1
- package/dist/hooks/useDebouncedEffect.mjs +0 -44
- package/dist/hooks/useDebouncedEffect.mjs.map +0 -1
- package/dist/hooks/useIsMobile.mjs +0 -18
- package/dist/hooks/useIsMobile.mjs.map +0 -1
- package/dist/hooks/usePasswordVisibility.mjs +0 -13
- package/dist/hooks/usePasswordVisibility.mjs.map +0 -1
- package/dist/infra/api/client.mjs.map +0 -1
- package/dist/infra/api/types.mjs +0 -31
- package/dist/infra/api/types.mjs.map +0 -1
- package/dist/infra/utils/client-info.mjs +0 -27
- package/dist/infra/utils/client-info.mjs.map +0 -1
- package/dist/infra/utils/clsx.mjs +0 -9
- package/dist/infra/utils/clsx.mjs.map +0 -1
- package/dist/infra/utils/params.mjs +0 -21
- package/dist/infra/utils/params.mjs.map +0 -1
- package/dist/infra/utils/parser.mjs +0 -24
- package/dist/infra/utils/parser.mjs.map +0 -1
- package/dist/infra/utils/percentage.mjs +0 -20
- package/dist/infra/utils/percentage.mjs.map +0 -1
- package/dist/middlewares/chain.mjs +0 -37
- package/dist/middlewares/chain.mjs.map +0 -1
- package/dist/middlewares/create-auth-middleware.mjs +0 -28
- package/dist/middlewares/create-auth-middleware.mjs.map +0 -1
- package/dist/middlewares/types.mjs +0 -11
- package/dist/middlewares/types.mjs.map +0 -1
- package/dist/modules/accounts/actions/account-management.action.mjs +0 -82
- package/dist/modules/accounts/actions/account-management.action.mjs.map +0 -1
- package/dist/modules/accounts/actions/find-current-account.action.mjs +0 -10
- package/dist/modules/accounts/actions/find-current-account.action.mjs.map +0 -1
- package/dist/modules/accounts/actions/list-currencies.action.mjs +0 -10
- package/dist/modules/accounts/actions/list-currencies.action.mjs.map +0 -1
- package/dist/modules/accounts/actions/list-timezones.action.mjs +0 -10
- package/dist/modules/accounts/actions/list-timezones.action.mjs.map +0 -1
- package/dist/modules/accounts/hooks/current-account.hook.mjs +0 -24
- package/dist/modules/accounts/hooks/current-account.hook.mjs.map +0 -1
- package/dist/modules/accounts/hooks/useAccountManagement.mjs +0 -71
- package/dist/modules/accounts/hooks/useAccountManagement.mjs.map +0 -1
- package/dist/modules/accounts/hooks/useCurrencies.mjs +0 -17
- package/dist/modules/accounts/hooks/useCurrencies.mjs.map +0 -1
- package/dist/modules/accounts/hooks/useTimezones.mjs +0 -17
- package/dist/modules/accounts/hooks/useTimezones.mjs.map +0 -1
- package/dist/modules/accounts/services/account.service.mjs.map +0 -1
- package/dist/modules/accounts/services/currency.service.mjs +0 -24
- package/dist/modules/accounts/services/currency.service.mjs.map +0 -1
- package/dist/modules/accounts/services/timezone.service.mjs +0 -65
- package/dist/modules/accounts/services/timezone.service.mjs.map +0 -1
- package/dist/modules/accounts/services/two-factor.service.mjs +0 -77
- package/dist/modules/accounts/services/two-factor.service.mjs.map +0 -1
- package/dist/modules/accounts/types.mjs +0 -1
- package/dist/modules/auth/actions/login.action.mjs +0 -14
- package/dist/modules/auth/actions/login.action.mjs.map +0 -1
- package/dist/modules/auth/actions/logout.action.mjs +0 -14
- package/dist/modules/auth/actions/logout.action.mjs.map +0 -1
- package/dist/modules/auth/actions/register.action.mjs +0 -14
- package/dist/modules/auth/actions/register.action.mjs.map +0 -1
- package/dist/modules/auth/actions/validate-session.action.mjs.map +0 -1
- package/dist/modules/auth/actions/verify-two-factor.action.mjs.map +0 -1
- package/dist/modules/auth/hooks/login.hook.mjs +0 -18
- package/dist/modules/auth/hooks/login.hook.mjs.map +0 -1
- package/dist/modules/auth/hooks/logout.hook.mjs +0 -13
- package/dist/modules/auth/hooks/logout.hook.mjs.map +0 -1
- package/dist/modules/auth/hooks/register.hook.mjs +0 -13
- package/dist/modules/auth/hooks/register.hook.mjs.map +0 -1
- package/dist/modules/auth/hooks/useUserQuery.mjs +0 -63
- package/dist/modules/auth/hooks/useUserQuery.mjs.map +0 -1
- package/dist/modules/auth/schema.mjs +0 -1
- package/dist/modules/auth/services/auth.service.mjs.map +0 -1
- package/dist/modules/auth/utils/get-user-context.mjs +0 -24
- package/dist/modules/auth/utils/get-user-context.mjs.map +0 -1
- package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs +0 -10
- package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs.map +0 -1
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +0 -76
- package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +0 -1
- package/dist/modules/ia-credits/services/ia-credits.service.mjs +0 -31
- package/dist/modules/ia-credits/services/ia-credits.service.mjs.map +0 -1
- package/dist/modules/ia-credits/types.mjs +0 -25
- package/dist/modules/ia-credits/types.mjs.map +0 -1
- package/dist/modules/projects/actions/add-project-user.action.mjs +0 -10
- package/dist/modules/projects/actions/add-project-user.action.mjs.map +0 -1
- package/dist/modules/projects/actions/list-available-users.action.mjs +0 -10
- package/dist/modules/projects/actions/list-available-users.action.mjs.map +0 -1
- package/dist/modules/projects/actions/list-project-users.action.mjs +0 -10
- package/dist/modules/projects/actions/list-project-users.action.mjs.map +0 -1
- package/dist/modules/projects/actions/remove-project-user.action.mjs +0 -10
- package/dist/modules/projects/actions/remove-project-user.action.mjs.map +0 -1
- package/dist/modules/projects/hooks/list-available-users.hook.mjs +0 -34
- package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +0 -1
- package/dist/modules/projects/hooks/list-project-users.hook.mjs +0 -34
- package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +0 -1
- package/dist/modules/projects/services/project-users.service.mjs +0 -78
- package/dist/modules/projects/services/project-users.service.mjs.map +0 -1
- package/dist/modules/projects/types.mjs +0 -22
- package/dist/modules/projects/types.mjs.map +0 -1
- package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs +0 -10
- package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs.map +0 -1
- package/dist/modules/subscriptions/constants/addons.constants.mjs +0 -12
- package/dist/modules/subscriptions/constants/addons.constants.mjs.map +0 -1
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +0 -20
- package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +0 -1
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +0 -18
- package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +0 -1
- package/dist/modules/subscriptions/services/subscriptions.service.mjs +0 -32
- package/dist/modules/subscriptions/services/subscriptions.service.mjs.map +0 -1
- package/dist/modules/subscriptions/types.mjs +0 -57
- package/dist/modules/subscriptions/types.mjs.map +0 -1
- package/dist/modules/users/action/find-user-by-id.action.mjs +0 -10
- package/dist/modules/users/action/find-user-by-id.action.mjs.map +0 -1
- package/dist/modules/users/action/list-messages.action.mjs +0 -13
- package/dist/modules/users/action/list-messages.action.mjs.map +0 -1
- package/dist/modules/users/action/mark-all-messages-as-read.action.mjs +0 -10
- package/dist/modules/users/action/mark-all-messages-as-read.action.mjs.map +0 -1
- package/dist/modules/users/action/mark-message-as-read.action.mjs +0 -10
- package/dist/modules/users/action/mark-message-as-read.action.mjs.map +0 -1
- package/dist/modules/users/hooks/messages.hook.mjs +0 -57
- package/dist/modules/users/hooks/messages.hook.mjs.map +0 -1
- package/dist/modules/users/schema/messages.schema.mjs +0 -21
- package/dist/modules/users/schema/messages.schema.mjs.map +0 -1
- package/dist/modules/users/schema.mjs +0 -11
- package/dist/modules/users/schema.mjs.map +0 -1
- package/dist/modules/users/services/messages.service.mjs +0 -35
- package/dist/modules/users/services/messages.service.mjs.map +0 -1
- package/dist/modules/users/services/user.service.mjs.map +0 -1
- package/dist/modules/whitelabel/actions/find-whitelabel-styles.action.mjs +0 -15
- package/dist/modules/whitelabel/actions/find-whitelabel-styles.action.mjs.map +0 -1
- package/dist/modules/whitelabel/actions/find-whitelabel.action.mjs +0 -21
- package/dist/modules/whitelabel/actions/find-whitelabel.action.mjs.map +0 -1
- package/dist/modules/whitelabel/schema.mjs +0 -1
- package/dist/modules/whitelabel/services/whitelabel-styles.service.mjs +0 -76
- package/dist/modules/whitelabel/services/whitelabel-styles.service.mjs.map +0 -1
- package/dist/modules/whitelabel/services/whitelabel.service.mjs.map +0 -1
- package/dist/modules/whitelabel/styles-schema.mjs +0 -1
- package/dist/providers/auth.provider.mjs +0 -94
- package/dist/providers/auth.provider.mjs.map +0 -1
- package/dist/providers/query.provider.mjs +0 -99
- package/dist/providers/query.provider.mjs.map +0 -1
- package/dist/providers/whitelabel.provider.mjs +0 -31
- package/dist/providers/whitelabel.provider.mjs.map +0 -1
- package/dist/store/useAccountModals.mjs +0 -18
- package/dist/store/useAccountModals.mjs.map +0 -1
- package/dist/store/useMdSidebarStore.mjs +0 -11
- package/dist/store/useMdSidebarStore.mjs.map +0 -1
- package/dist/store/useMobileNavbarSheet.mjs +0 -14
- package/dist/store/useMobileNavbarSheet.mjs.map +0 -1
- package/dist/store/useModalManager.mjs +0 -75
- package/dist/store/useModalManager.mjs.map +0 -1
- package/dist/utils/browser/clipboard.mjs +0 -36
- package/dist/utils/browser/clipboard.mjs.map +0 -1
- package/dist/utils/file/index.mjs +0 -9
- package/dist/utils/file/index.mjs.map +0 -1
- package/dist/utils/format/masks.mjs +0 -56
- package/dist/utils/format/masks.mjs.map +0 -1
- package/dist/utils/intl/locales.mjs +0 -12
- package/dist/utils/intl/locales.mjs.map +0 -1
- package/dist/utils/safeServerAction.mjs.map +0 -1
- package/dist/utils/validators/account.mjs +0 -26
- package/dist/utils/validators/account.mjs.map +0 -1
- package/dist/utils/validators/common.mjs +0 -47
- package/dist/utils/validators/common.mjs.map +0 -1
- package/dist/utils/withAction.mjs +0 -13
- package/dist/utils/withAction.mjs.map +0 -1
- /package/dist/{components/navigation/types.mjs.map → account-management.action-7QQCACDJ.mjs.map} +0 -0
- /package/dist/{modules/accounts/types.mjs.map → account.service-XTZDEIPS.mjs.map} +0 -0
- /package/dist/{modules/auth/schema.mjs.map → find-user-by-id.action-BUFTU3ZY.mjs.map} +0 -0
- /package/dist/{modules/whitelabel/schema.mjs.map → user.service-VDR4JKHO.mjs.map} +0 -0
- /package/dist/{modules/whitelabel/styles-schema.mjs.map → validate-session.action-K7RWN2GE.mjs.map} +0 -0
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { api } from "../../../infra/api/client";
|
|
2
|
-
function parseOffsetMinutes(offsetStr) {
|
|
3
|
-
const match = offsetStr.match(/GMT([+-])(\d+)(?::(\d+))?/);
|
|
4
|
-
if (!match) return 0;
|
|
5
|
-
const sign = match[1] === "+" ? 1 : -1;
|
|
6
|
-
return sign * (parseInt(match[2], 10) * 60 + parseInt(match[3] ?? "0", 10));
|
|
7
|
-
}
|
|
8
|
-
const FALLBACK_TIMEZONES = [
|
|
9
|
-
{ value: "America/Noronha", label: "(GMT-2) America/Noronha", displayValue: "(GMT-2) Noronha" },
|
|
10
|
-
{ value: "America/Sao_Paulo", label: "(GMT-3) America/Sao Paulo", displayValue: "(GMT-3) Sao Paulo" },
|
|
11
|
-
{ value: "America/Manaus", label: "(GMT-4) America/Manaus", displayValue: "(GMT-4) Manaus" },
|
|
12
|
-
{ value: "America/Rio_Branco", label: "(GMT-5) America/Rio Branco", displayValue: "(GMT-5) Rio Branco" },
|
|
13
|
-
{ value: "America/New_York", label: "(GMT-5) America/New York", displayValue: "(GMT-5) New York" },
|
|
14
|
-
{ value: "America/Los_Angeles", label: "(GMT-8) America/Los Angeles", displayValue: "(GMT-8) Los Angeles" },
|
|
15
|
-
{ value: "Europe/London", label: "(GMT+0) Europe/London", displayValue: "(GMT+0) London" },
|
|
16
|
-
{ value: "Europe/Paris", label: "(GMT+1) Europe/Paris", displayValue: "(GMT+1) Paris" },
|
|
17
|
-
{ value: "Asia/Tokyo", label: "(GMT+9) Asia/Tokyo", displayValue: "(GMT+9) Tokyo" }
|
|
18
|
-
];
|
|
19
|
-
class TimezoneService {
|
|
20
|
-
async fetchOptions() {
|
|
21
|
-
try {
|
|
22
|
-
const response = await api.apps.get("/accounts/action/timezones");
|
|
23
|
-
const now = /* @__PURE__ */ new Date();
|
|
24
|
-
const items = response.data.map((item) => {
|
|
25
|
-
const offsetStr = new Intl.DateTimeFormat("en", { timeZone: item.value, timeZoneName: "shortOffset" }).formatToParts(now).find((p) => p.type === "timeZoneName")?.value ?? "GMT";
|
|
26
|
-
const city = item.value.split("/").slice(1).join("/").replace(/_/g, " ") || item.value;
|
|
27
|
-
return {
|
|
28
|
-
value: item.value,
|
|
29
|
-
label: `(${offsetStr}) ${item.value.replace(/_/g, " ")}`,
|
|
30
|
-
displayValue: `(${offsetStr}) ${city}`,
|
|
31
|
-
sort: parseOffsetMinutes(offsetStr)
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
items.sort((a, b) => a.sort - b.sort || a.label.localeCompare(b.label));
|
|
35
|
-
return items.map(({ value, label, displayValue }) => ({ value, label, displayValue }));
|
|
36
|
-
} catch {
|
|
37
|
-
return FALLBACK_TIMEZONES;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
buildOptions() {
|
|
41
|
-
try {
|
|
42
|
-
const zones = Intl.supportedValuesOf("timeZone");
|
|
43
|
-
const now = /* @__PURE__ */ new Date();
|
|
44
|
-
const items = zones.map((tz) => {
|
|
45
|
-
const offsetStr = new Intl.DateTimeFormat("en", { timeZone: tz, timeZoneName: "shortOffset" }).formatToParts(now).find((p) => p.type === "timeZoneName")?.value ?? "GMT";
|
|
46
|
-
const city = tz.split("/").slice(1).join("/").replace(/_/g, " ") || tz;
|
|
47
|
-
return {
|
|
48
|
-
value: tz,
|
|
49
|
-
label: `(${offsetStr}) ${tz.replace(/_/g, " ")}`,
|
|
50
|
-
displayValue: `(${offsetStr}) ${city}`,
|
|
51
|
-
sort: parseOffsetMinutes(offsetStr)
|
|
52
|
-
};
|
|
53
|
-
});
|
|
54
|
-
items.sort((a, b) => a.sort - b.sort || a.label.localeCompare(b.label));
|
|
55
|
-
return items.map(({ value, label, displayValue }) => ({ value, label, displayValue }));
|
|
56
|
-
} catch {
|
|
57
|
-
return FALLBACK_TIMEZONES;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const timezoneService = new TimezoneService();
|
|
62
|
-
export {
|
|
63
|
-
timezoneService
|
|
64
|
-
};
|
|
65
|
-
//# sourceMappingURL=timezone.service.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/accounts/services/timezone.service.ts"],"sourcesContent":["import { api } from '../../../infra/api/client';\r\n\r\nexport type TimezoneOption = {\r\n value: string;\r\n label: string;\r\n displayValue: string;\r\n};\r\n\r\ntype TimezoneApiResponse = {\r\n message: string;\r\n data: { value: string; title: string }[];\r\n};\r\n\r\nfunction parseOffsetMinutes(offsetStr: string): number {\r\n const match = offsetStr.match(/GMT([+-])(\\d+)(?::(\\d+))?/);\r\n if (!match) return 0;\r\n const sign = match[1] === '+' ? 1 : -1;\r\n return sign * (parseInt(match[2], 10) * 60 + parseInt(match[3] ?? '0', 10));\r\n}\r\n\r\nconst FALLBACK_TIMEZONES: TimezoneOption[] = [\r\n { value: 'America/Noronha', label: '(GMT-2) America/Noronha', displayValue: '(GMT-2) Noronha' },\r\n { value: 'America/Sao_Paulo', label: '(GMT-3) America/Sao Paulo', displayValue: '(GMT-3) Sao Paulo' },\r\n { value: 'America/Manaus', label: '(GMT-4) America/Manaus', displayValue: '(GMT-4) Manaus' },\r\n { value: 'America/Rio_Branco', label: '(GMT-5) America/Rio Branco', displayValue: '(GMT-5) Rio Branco' },\r\n { value: 'America/New_York', label: '(GMT-5) America/New York', displayValue: '(GMT-5) New York' },\r\n { value: 'America/Los_Angeles', label: '(GMT-8) America/Los Angeles', displayValue: '(GMT-8) Los Angeles' },\r\n { value: 'Europe/London', label: '(GMT+0) Europe/London', displayValue: '(GMT+0) London' },\r\n { value: 'Europe/Paris', label: '(GMT+1) Europe/Paris', displayValue: '(GMT+1) Paris' },\r\n { value: 'Asia/Tokyo', label: '(GMT+9) Asia/Tokyo', displayValue: '(GMT+9) Tokyo' },\r\n];\r\n\r\nclass TimezoneService {\r\n async fetchOptions(): Promise<TimezoneOption[]> {\r\n try {\r\n const response = await api.apps.get<TimezoneApiResponse>('/accounts/action/timezones');\r\n const now = new Date();\r\n\r\n const items = response.data.map((item) => {\r\n const offsetStr =\r\n new Intl.DateTimeFormat('en', { timeZone: item.value, timeZoneName: 'shortOffset' })\r\n .formatToParts(now)\r\n .find((p) => p.type === 'timeZoneName')?.value ?? 'GMT';\r\n\r\n const city = item.value.split('/').slice(1).join('/').replace(/_/g, ' ') || item.value;\r\n\r\n return {\r\n value: item.value,\r\n label: `(${offsetStr}) ${item.value.replace(/_/g, ' ')}`,\r\n displayValue: `(${offsetStr}) ${city}`,\r\n sort: parseOffsetMinutes(offsetStr),\r\n };\r\n });\r\n\r\n items.sort((a, b) => a.sort - b.sort || a.label.localeCompare(b.label));\r\n\r\n return items.map(({ value, label, displayValue }) => ({ value, label, displayValue }));\r\n } catch {\r\n return FALLBACK_TIMEZONES;\r\n }\r\n }\r\n\r\n buildOptions(): TimezoneOption[] {\r\n try {\r\n const zones = Intl.supportedValuesOf('timeZone');\r\n const now = new Date();\r\n\r\n const items = zones.map((tz) => {\r\n const offsetStr =\r\n new Intl.DateTimeFormat('en', { timeZone: tz, timeZoneName: 'shortOffset' })\r\n .formatToParts(now)\r\n .find((p) => p.type === 'timeZoneName')?.value ?? 'GMT';\r\n\r\n const city = tz.split('/').slice(1).join('/').replace(/_/g, ' ') || tz;\r\n\r\n return {\r\n value: tz,\r\n label: `(${offsetStr}) ${tz.replace(/_/g, ' ')}`,\r\n displayValue: `(${offsetStr}) ${city}`,\r\n sort: parseOffsetMinutes(offsetStr),\r\n };\r\n });\r\n\r\n items.sort((a, b) => a.sort - b.sort || a.label.localeCompare(b.label));\r\n\r\n return items.map(({ value, label, displayValue }) => ({ value, label, displayValue }));\r\n } catch {\r\n return FALLBACK_TIMEZONES;\r\n }\r\n }\r\n}\r\n\r\nexport const timezoneService = new TimezoneService();\r\n"],"mappings":"AAAA,SAAS,WAAW;AAapB,SAAS,mBAAmB,WAA2B;AACrD,QAAM,QAAQ,UAAU,MAAM,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AO,aAAa,EAAE;AAAA,IACvF,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,kBAAkB,IAAI,gBAAgB;","names":[]}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import "server-only";
|
|
2
|
-
import { ApiError } from "../../../infra/api/types";
|
|
3
|
-
import { getUserContext } from "../../auth/utils/get-user-context";
|
|
4
|
-
import { findWhitelabel } from "../../whitelabel/actions/find-whitelabel.action";
|
|
5
|
-
const TWO_FA_BASE_URL = process.env.R2_2FA_URL || "https://r2-2fa.greatapps.dev.br";
|
|
6
|
-
class TwoFactorService {
|
|
7
|
-
async request(path, body) {
|
|
8
|
-
const { id, token } = await findWhitelabel();
|
|
9
|
-
const { id_account, id_user } = await getUserContext();
|
|
10
|
-
const url = `${TWO_FA_BASE_URL}/v1/${id}/account/${id_account}/users/${id_user}/2fa/${path}`;
|
|
11
|
-
const response = await fetch(url, {
|
|
12
|
-
method: "POST",
|
|
13
|
-
headers: {
|
|
14
|
-
"Content-Type": "application/json",
|
|
15
|
-
authorization: token
|
|
16
|
-
},
|
|
17
|
-
body: body ? JSON.stringify(body) : void 0
|
|
18
|
-
});
|
|
19
|
-
if (!response.ok) {
|
|
20
|
-
const errorData = await response.json().catch(() => ({}));
|
|
21
|
-
throw new ApiError(
|
|
22
|
-
errorData.message || `HTTP error ${response.status}`,
|
|
23
|
-
"HTTP_ERROR",
|
|
24
|
-
response.status
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
return response.json();
|
|
28
|
-
}
|
|
29
|
-
async generate() {
|
|
30
|
-
const response = await this.request("generate");
|
|
31
|
-
if (response.status === 0) {
|
|
32
|
-
throw new ApiError(response.message || "Erro ao gerar QR Code", "GENERATE_2FA_FAILED", 400);
|
|
33
|
-
}
|
|
34
|
-
return response;
|
|
35
|
-
}
|
|
36
|
-
async confirm(code) {
|
|
37
|
-
const response = await this.request("confirm", { code });
|
|
38
|
-
if (response.status === 0) {
|
|
39
|
-
throw new ApiError(response.message || "C\xF3digo inv\xE1lido", "CONFIRM_2FA_FAILED", 400);
|
|
40
|
-
}
|
|
41
|
-
return response;
|
|
42
|
-
}
|
|
43
|
-
async verify(code) {
|
|
44
|
-
const response = await this.request("verify", { code });
|
|
45
|
-
if (response.status === 0) {
|
|
46
|
-
throw new ApiError(response.message || "C\xF3digo inv\xE1lido", "VERIFY_2FA_FAILED", 400);
|
|
47
|
-
}
|
|
48
|
-
return response;
|
|
49
|
-
}
|
|
50
|
-
async disable() {
|
|
51
|
-
const { id, token } = await findWhitelabel();
|
|
52
|
-
const { id_account, id_user } = await getUserContext();
|
|
53
|
-
const url = `${TWO_FA_BASE_URL}/v1/${id}/account/${id_account}/users/${id_user}/2fa`;
|
|
54
|
-
const response = await fetch(url, {
|
|
55
|
-
method: "DELETE",
|
|
56
|
-
headers: { authorization: token }
|
|
57
|
-
});
|
|
58
|
-
if (!response.ok) {
|
|
59
|
-
const errorData = await response.json().catch(() => ({}));
|
|
60
|
-
throw new ApiError(
|
|
61
|
-
errorData.message || `HTTP error ${response.status}`,
|
|
62
|
-
"HTTP_ERROR",
|
|
63
|
-
response.status
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
const data = await response.json();
|
|
67
|
-
if (data.status === 0) {
|
|
68
|
-
throw new ApiError(data.message || "Erro ao desabilitar 2FA", "DISABLE_2FA_FAILED", 400);
|
|
69
|
-
}
|
|
70
|
-
return data;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const twoFactorService = new TwoFactorService();
|
|
74
|
-
export {
|
|
75
|
-
twoFactorService
|
|
76
|
-
};
|
|
77
|
-
//# sourceMappingURL=two-factor.service.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/accounts/services/two-factor.service.ts"],"sourcesContent":["import 'server-only';\r\n\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { getUserContext } from '../../auth/utils/get-user-context';\r\nimport { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';\r\nimport type { TwoFactorActionResponse, TwoFactorGenerateResponse } from '../types';\r\n\r\nconst TWO_FA_BASE_URL = process.env.R2_2FA_URL || 'https://r2-2fa.greatapps.dev.br';\r\n\r\nclass TwoFactorService {\r\n private async request<T>(path: string, body?: object): Promise<T> {\r\n const { id, token } = await findWhitelabel();\r\n const { id_account, id_user } = await getUserContext();\r\n\r\n const url = `${TWO_FA_BASE_URL}/v1/${id}/account/${id_account}/users/${id_user}/2fa/${path}`;\r\n\r\n const response = await fetch(url, {\r\n method: 'POST',\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n authorization: token,\r\n },\r\n body: body ? JSON.stringify(body) : undefined,\r\n });\r\n\r\n if (!response.ok) {\r\n const errorData = await response.json().catch(() => ({})) as Record<string, unknown>;\r\n throw new ApiError(\r\n (errorData.message as string) || `HTTP error ${response.status}`,\r\n 'HTTP_ERROR',\r\n response.status\r\n );\r\n }\r\n\r\n return response.json() as Promise<T>;\r\n }\r\n\r\n async generate(): Promise<TwoFactorGenerateResponse> {\r\n const response = await this.request<TwoFactorGenerateResponse>('generate');\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'Erro ao gerar QR Code', 'GENERATE_2FA_FAILED', 400);\r\n }\r\n\r\n return response;\r\n }\r\n\r\n async confirm(code: string): Promise<TwoFactorActionResponse> {\r\n const response = await this.request<TwoFactorActionResponse>('confirm', { code });\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'Código inválido', 'CONFIRM_2FA_FAILED', 400);\r\n }\r\n\r\n return response;\r\n }\r\n\r\n async verify(code: string): Promise<TwoFactorActionResponse> {\r\n const response = await this.request<TwoFactorActionResponse>('verify', { code });\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'Código inválido', 'VERIFY_2FA_FAILED', 400);\r\n }\r\n\r\n return response;\r\n }\r\n\r\n async disable(): Promise<TwoFactorActionResponse> {\r\n const { id, token } = await findWhitelabel();\r\n const { id_account, id_user } = await getUserContext();\r\n\r\n const url = `${TWO_FA_BASE_URL}/v1/${id}/account/${id_account}/users/${id_user}/2fa`;\r\n\r\n const response = await fetch(url, {\r\n method: 'DELETE',\r\n headers: { authorization: token },\r\n });\r\n\r\n if (!response.ok) {\r\n const errorData = await response.json().catch(() => ({})) as Record<string, unknown>;\r\n throw new ApiError(\r\n (errorData.message as string) || `HTTP error ${response.status}`,\r\n 'HTTP_ERROR',\r\n response.status\r\n );\r\n }\r\n\r\n const data = await response.json() as TwoFactorActionResponse;\r\n\r\n if (data.status === 0) {\r\n throw new ApiError(data.message || 'Erro ao desabilitar 2FA', 'DISABLE_2FA_FAILED', 400);\r\n }\r\n\r\n return data;\r\n }\r\n}\r\n\r\nexport const twoFactorService = new TwoFactorService();\r\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAG/B,MAAM,kBAAkB,QAAQ,IAAI,cAAc;AAElD,MAAM,iBAAiB;AAAA,EACrB,MAAc,QAAW,MAAc,MAA2B;AAChE,UAAM,EAAE,IAAI,MAAM,IAAI,MAAM,eAAe;AAC3C,UAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,eAAe;AAErD,UAAM,MAAM,GAAG,eAAe,OAAO,EAAE,YAAY,UAAU,UAAU,OAAO,QAAQ,IAAI;AAE1F,UAAM,WAAW,MAAM,MAAM,KAAK;AAAA,MAChC,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,eAAe;AAAA,MACjB;AAAA,MACA,MAAM,OAAO,KAAK,UAAU,IAAI,IAAI;AAAA,IACtC,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,YAAY,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACxD,YAAM,IAAI;AAAA,QACP,UAAU,WAAsB,cAAc,SAAS,MAAM;AAAA,QAC9D;AAAA,QACA,SAAS;AAAA,MACX;AAA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,KAAK,WAAW,GAAG;AACrB,YAAM,IAAI,SAAS,KAAK,WAAW,2BAA2B,sBAAsB,GAAG;AAAA,IACzF;AAEA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,mBAAmB,IAAI,iBAAiB;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=types.mjs.map
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
3
|
-
import { authService } from "../services/auth.service";
|
|
4
|
-
import { getClientInfoFromRequest } from "../../../infra/utils/client-info";
|
|
5
|
-
async function loginAction(credentials) {
|
|
6
|
-
return safeServerAction(async () => {
|
|
7
|
-
const clientInfo = await getClientInfoFromRequest();
|
|
8
|
-
return authService.login(credentials, clientInfo);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
loginAction
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=login.action.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/actions/login.action.ts"],"sourcesContent":["\"use server\";\r\n\r\nimport { safeServerAction } from \"../../../utils/safeServerAction\";\r\nimport { authService } from \"../services/auth.service\";\r\nimport { LoginRequest } from \"../schema\";\r\nimport { getClientInfoFromRequest } from \"../../../infra/utils/client-info\";\r\n\r\nexport async function loginAction(credentials: LoginRequest) {\r\n return safeServerAction(async () => {\r\n const clientInfo = await getClientInfoFromRequest();\r\n return authService.login(credentials, clientInfo);\r\n });\r\n}\r\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAE5B,SAAS,gCAAgC;AAEzC,eAAsB,YAAY,aAA2B;AAC3D,SAAO,iBAAiB,YAAY;AAClC,UAAM,aAAa,MAAM,yBAAyB;AAClD,WAAO,YAAY,MAAM,aAAa,UAAU;AAAA,EAClD,CAAC;AACH;","names":[]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
3
|
-
import { getClientInfoFromRequest } from "../../../infra/utils/client-info";
|
|
4
|
-
import { authService } from "../services/auth.service";
|
|
5
|
-
async function logoutAction() {
|
|
6
|
-
return safeServerAction(async () => {
|
|
7
|
-
const clientInfo = await getClientInfoFromRequest();
|
|
8
|
-
return authService.logout(clientInfo);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
logoutAction
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=logout.action.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/actions/logout.action.ts"],"sourcesContent":["'use server';\r\n\r\nimport { safeServerAction } from '../../../utils/safeServerAction';\r\nimport { getClientInfoFromRequest } from '../../../infra/utils/client-info';\r\nimport { authService } from '../services/auth.service';\r\n\r\nexport async function logoutAction() {\r\n return safeServerAction(async () => {\r\n const clientInfo = await getClientInfoFromRequest();\r\n return authService.logout(clientInfo);\r\n });\r\n}\r\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,gCAAgC;AACzC,SAAS,mBAAmB;AAE5B,eAAsB,eAAe;AACnC,SAAO,iBAAiB,YAAY;AAClC,UAAM,aAAa,MAAM,yBAAyB;AAClD,WAAO,YAAY,OAAO,UAAU;AAAA,EACtC,CAAC;AACH;","names":[]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
3
|
-
import { authService } from "../services/auth.service";
|
|
4
|
-
import { getClientInfoFromRequest } from "../../../infra/utils/client-info";
|
|
5
|
-
async function registerAction(data) {
|
|
6
|
-
return safeServerAction(async () => {
|
|
7
|
-
const clientInfo = await getClientInfoFromRequest();
|
|
8
|
-
return authService.register(data, clientInfo);
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
registerAction
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=register.action.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/actions/register.action.ts"],"sourcesContent":["'use server';\r\n\r\nimport { safeServerAction } from '../../../utils/safeServerAction';\r\nimport { RegisterRequest } from '../schema';\r\nimport { authService } from '../services/auth.service';\r\nimport { getClientInfoFromRequest } from '../../../infra/utils/client-info';\r\n\r\nexport async function registerAction(data: RegisterRequest) {\r\n return safeServerAction(async () => {\r\n const clientInfo = await getClientInfoFromRequest();\r\n return authService.register(data, clientInfo);\r\n });\r\n}\r\n"],"mappings":";AAEA,SAAS,wBAAwB;AAEjC,SAAS,mBAAmB;AAC5B,SAAS,gCAAgC;AAEzC,eAAsB,eAAe,MAAuB;AAC1D,SAAO,iBAAiB,YAAY;AAClC,UAAM,aAAa,MAAM,yBAAyB;AAClD,WAAO,YAAY,SAAS,MAAM,UAAU;AAAA,EAC9C,CAAC;AACH;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/actions/validate-session.action.ts"],"sourcesContent":["'use server';\r\n\r\nimport { redirect } from 'next/navigation';\r\nimport { cookies, headers } from 'next/headers';\r\nimport { authService } from '../services/auth.service';\r\nimport { getClientInfoFromRequest } from '../../../infra/utils/client-info';\r\n\r\nasync function redirectToLogin() {\r\n const h = await headers();\r\n const referer = h.get('referer') || '/';\r\n\r\n if (!referer) {\r\n redirect('/login');\r\n return;\r\n }\r\n\r\n const url = new URL(referer);\r\n\r\n if (['/login', '/register', '/forgot-password'].includes(url.pathname)) {\r\n return;\r\n }\r\n\r\n redirect('/login');\r\n}\r\n\r\nexport async function validateSessionAction(): Promise<boolean> {\r\n if (process.env.DUMMY_AUTH_TOKEN) return true;\r\n\r\n const cookieStore = await cookies();\r\n const cookie = cookieStore.get('greatapps')?.value;\r\n\r\n if (!cookie) {\r\n await redirectToLogin();\r\n return false;\r\n }\r\n\r\n try {\r\n const clientInfo = await getClientInfoFromRequest();\r\n const isValid = await authService.validateSession(clientInfo);\r\n\r\n if (!isValid) {\r\n await authService.removeAuthCookie();\r\n await redirectToLogin();\r\n return false;\r\n }\r\n\r\n return true;\r\n } catch (error) {\r\n console.error('[validateSessionAction] Error:', error);\r\n await authService.removeAuthCookie();\r\n await redirectToLogin();\r\n return false;\r\n }\r\n}\r\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,SAAS,eAAe;AACjC,SAAS,mBAAmB;AAC5B,SAAS,gCAAgC;AAEzC,eAAe,kBAAkB;AAC/B,QAAM,IAAI,MAAM,QAAQ;AACxB,QAAM,UAAU,EAAE,IAAI,SAAS,KAAK;AAEpC,MAAI,CAAC,SAAS;AACZ,aAAS,QAAQ;AACjB;AAAA,EACF;AAEA,QAAM,MAAM,IAAI,IAAI,OAAO;AAE3B,MAAI,CAAC,UAAU,aAAa,kBAAkB,EAAE,SAAS,IAAI,QAAQ,GAAG;AACtE;AAAA,EACF;AAEA,WAAS,QAAQ;AACnB;AAEA,eAAsB,wBAA0C;AAC9D,MAAI,QAAQ,IAAI,iBAAkB,QAAO;AAEzC,QAAM,cAAc,MAAM,QAAQ;AAClC,QAAM,SAAS,YAAY,IAAI,WAAW,GAAG;AAE7C,MAAI,CAAC,QAAQ;AACX,UAAM,gBAAgB;AACtB,WAAO;AAAA,EACT;AAEA,MAAI;AACF,UAAM,aAAa,MAAM,yBAAyB;AAClD,UAAM,UAAU,MAAM,YAAY,gBAAgB,UAAU;AAE5D,QAAI,CAAC,SAAS;AACZ,YAAM,YAAY,iBAAiB;AACnC,YAAM,gBAAgB;AACtB,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,kCAAkC,KAAK;AACrD,UAAM,YAAY,iBAAiB;AACnC,UAAM,gBAAgB;AACtB,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/actions/verify-two-factor.action.ts"],"sourcesContent":["'use server';\r\n\r\nimport { safeServerAction } from '../../../utils/safeServerAction';\r\nimport { authService } from '../services/auth.service';\r\nimport { getClientInfoFromRequest } from '../../../infra/utils/client-info';\r\n\r\nexport async function verifyTwoFactorAction(cookie: string, code: string) {\r\n return safeServerAction(async () => {\r\n if (!/^\\d{6}$/.test(code)) {\r\n throw new Error('Formato inválido');\r\n }\r\n const clientInfo = await getClientInfoFromRequest();\r\n await authService.verifyTwoFactor(cookie, code, clientInfo);\r\n });\r\n}\r\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,mBAAmB;AAC5B,SAAS,gCAAgC;AAEzC,eAAsB,sBAAsB,QAAgB,MAAc;AACxE,SAAO,iBAAiB,YAAY;AAClC,QAAI,CAAC,UAAU,KAAK,IAAI,GAAG;AACzB,YAAM,IAAI,MAAM,qBAAkB;AAAA,IACpC;AACA,UAAM,aAAa,MAAM,yBAAyB;AAClD,UAAM,YAAY,gBAAgB,QAAQ,MAAM,UAAU;AAAA,EAC5D,CAAC;AACH;","names":[]}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useMutation } from "@tanstack/react-query";
|
|
3
|
-
import { loginAction } from "../actions/login.action";
|
|
4
|
-
function useLogin() {
|
|
5
|
-
return useMutation({
|
|
6
|
-
mutationFn: async (credentials) => {
|
|
7
|
-
const result = await loginAction(credentials);
|
|
8
|
-
if (!result.success) throw new Error(result.error ?? "Erro desconhecido");
|
|
9
|
-
const data = result.data;
|
|
10
|
-
if (data.result === "error") throw new Error(data.message);
|
|
11
|
-
return data;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
export {
|
|
16
|
-
useLogin
|
|
17
|
-
};
|
|
18
|
-
//# sourceMappingURL=login.hook.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/hooks/login.hook.tsx"],"sourcesContent":["\"use client\";\n\nimport { useMutation } from \"@tanstack/react-query\";\nimport { loginAction } from \"../actions/login.action\";\nimport { LoginRequest, LoginSuccessResponse } from \"../schema\";\n\nexport function useLogin() {\n return useMutation({\n mutationFn: async (credentials: LoginRequest): Promise<LoginSuccessResponse> => {\n const result = await loginAction(credentials);\n if (!result.success) throw new Error(result.error ?? 'Erro desconhecido');\n const data = result.data!;\n if (data.result === 'error') throw new Error(data.message);\n return data as LoginSuccessResponse;\n },\n });\n}\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAGrB,SAAS,WAAW;AACzB,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,gBAA6D;AAC9E,YAAM,SAAS,MAAM,YAAY,WAAW;AAC5C,UAAI,CAAC,OAAO,QAAS,OAAM,IAAI,MAAM,OAAO,SAAS,mBAAmB;AACxE,YAAM,OAAO,OAAO;AACpB,UAAI,KAAK,WAAW,QAAS,OAAM,IAAI,MAAM,KAAK,OAAO;AACzD,aAAO;AAAA,IACT;AAAA,EACF,CAAC;AACH;","names":[]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useMutation } from "@tanstack/react-query";
|
|
3
|
-
import { logoutAction } from "../actions/logout.action";
|
|
4
|
-
import { withAction } from "../../../utils/withAction";
|
|
5
|
-
function useLogout() {
|
|
6
|
-
return useMutation({
|
|
7
|
-
mutationFn: withAction(logoutAction)
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
useLogout
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=logout.hook.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/hooks/logout.hook.tsx"],"sourcesContent":["\"use client\";\n\nimport { useMutation } from \"@tanstack/react-query\";\nimport { logoutAction } from \"../actions/logout.action\";\nimport { withAction } from \"../../../utils/withAction\";\n\nexport function useLogout() {\n return useMutation({\n mutationFn: withAction(logoutAction),\n });\n}\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,kBAAkB;AAEpB,SAAS,YAAY;AAC1B,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,YAAY;AAAA,EACrC,CAAC;AACH;","names":[]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useMutation } from "@tanstack/react-query";
|
|
3
|
-
import { registerAction } from "../actions/register.action";
|
|
4
|
-
import { withAction } from "../../../utils/withAction";
|
|
5
|
-
function useRegister() {
|
|
6
|
-
return useMutation({
|
|
7
|
-
mutationFn: withAction(registerAction)
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
useRegister
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=register.hook.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/hooks/register.hook.tsx"],"sourcesContent":["\"use client\";\n\nimport { useMutation } from \"@tanstack/react-query\";\nimport { registerAction } from \"../actions/register.action\";\nimport { withAction } from \"../../../utils/withAction\";\n\nexport function useRegister() {\n return useMutation({\n mutationFn: withAction(registerAction),\n });\n}\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAEpB,SAAS,cAAc;AAC5B,SAAO,YAAY;AAAA,IACjB,YAAY,WAAW,cAAc;AAAA,EACvC,CAAC;AACH;","names":[]}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
3
|
-
import { withAction } from "../../../utils/withAction";
|
|
4
|
-
const USER_QUERY_KEY = ["user"];
|
|
5
|
-
async function fetchUser() {
|
|
6
|
-
const { findUserById: getUserDataAction } = await import("../../users/action/find-user-by-id.action");
|
|
7
|
-
const result = await getUserDataAction();
|
|
8
|
-
return result.success && result.data ? result.data : null;
|
|
9
|
-
}
|
|
10
|
-
async function validateUserSession() {
|
|
11
|
-
const { validateSessionAction } = await import("../actions/validate-session.action");
|
|
12
|
-
return await validateSessionAction();
|
|
13
|
-
}
|
|
14
|
-
function useUserQuery() {
|
|
15
|
-
return useQuery({
|
|
16
|
-
queryKey: USER_QUERY_KEY,
|
|
17
|
-
queryFn: fetchUser,
|
|
18
|
-
staleTime: 5 * 60 * 1e3,
|
|
19
|
-
gcTime: 10 * 60 * 1e3,
|
|
20
|
-
retry: false
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
function useUserValidateSession(options) {
|
|
24
|
-
return useQuery({
|
|
25
|
-
queryKey: ["user-validate-session"],
|
|
26
|
-
queryFn: validateUserSession,
|
|
27
|
-
retry: false,
|
|
28
|
-
staleTime: 5 * 60 * 1e3,
|
|
29
|
-
...options,
|
|
30
|
-
refetchOnMount: "always",
|
|
31
|
-
refetchOnWindowFocus: true
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function useTwoFactorVerify() {
|
|
35
|
-
const queryClient = useQueryClient();
|
|
36
|
-
return useMutation({
|
|
37
|
-
mutationFn: async ({ cookie, code }) => {
|
|
38
|
-
const { verifyTwoFactorAction } = await import("../actions/verify-two-factor.action");
|
|
39
|
-
return withAction(() => verifyTwoFactorAction(cookie, code))();
|
|
40
|
-
},
|
|
41
|
-
onSuccess: () => {
|
|
42
|
-
queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
43
|
-
queryClient.invalidateQueries({ queryKey: ["two-factor-pending"] });
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
function useInvalidateUser() {
|
|
48
|
-
const queryClient = useQueryClient();
|
|
49
|
-
return () => queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });
|
|
50
|
-
}
|
|
51
|
-
function useSetUserData() {
|
|
52
|
-
const queryClient = useQueryClient();
|
|
53
|
-
return (user) => queryClient.setQueryData(USER_QUERY_KEY, user);
|
|
54
|
-
}
|
|
55
|
-
export {
|
|
56
|
-
USER_QUERY_KEY,
|
|
57
|
-
useInvalidateUser,
|
|
58
|
-
useSetUserData,
|
|
59
|
-
useTwoFactorVerify,
|
|
60
|
-
useUserQuery,
|
|
61
|
-
useUserValidateSession
|
|
62
|
-
};
|
|
63
|
-
//# sourceMappingURL=useUserQuery.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/hooks/useUserQuery.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useMutation, useQuery, useQueryClient, UseQueryOptions } from '@tanstack/react-query';\r\nimport { User } from '../../users/schema';\r\nimport { withAction } from '../../../utils/withAction';\r\n\r\nexport const USER_QUERY_KEY = ['user'];\r\n\r\nasync function fetchUser(): Promise<User | null> {\r\n const { findUserById: getUserDataAction } = await import('../../users/action/find-user-by-id.action');\r\n const result = await getUserDataAction();\r\n return result.success && result.data ? result.data : null;\r\n}\r\n\r\nasync function validateUserSession(): Promise<boolean> {\r\n const { validateSessionAction } = await import('../actions/validate-session.action');\r\n return await validateSessionAction();\r\n}\r\n\r\nexport function useUserQuery() {\r\n return useQuery({\r\n queryKey: USER_QUERY_KEY,\r\n queryFn: fetchUser,\r\n staleTime: 5 * 60 * 1000,\r\n gcTime: 10 * 60 * 1000,\r\n retry: false,\r\n });\r\n}\r\n\r\nexport function useUserValidateSession(options?: UseQueryOptions) {\r\n return useQuery({\r\n queryKey: ['user-validate-session'],\r\n queryFn: validateUserSession,\r\n retry: false,\r\n staleTime: 5 * 60 * 1000,\r\n ...options,\r\n refetchOnMount: 'always',\r\n refetchOnWindowFocus: true,\r\n });\r\n}\r\n\r\nexport function useTwoFactorVerify() {\r\n const queryClient = useQueryClient();\r\n\r\n return useMutation({\r\n mutationFn: async ({ cookie, code }: { cookie: string; code: string }) => {\r\n const { verifyTwoFactorAction } = await import('../actions/verify-two-factor.action');\r\n return withAction(() => verifyTwoFactorAction(cookie, code))();\r\n },\r\n onSuccess: () => {\r\n queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });\r\n queryClient.invalidateQueries({ queryKey: ['two-factor-pending'] });\r\n },\r\n });\r\n}\r\n\r\nexport function useInvalidateUser() {\r\n const queryClient = useQueryClient();\r\n return () => queryClient.invalidateQueries({ queryKey: USER_QUERY_KEY });\r\n}\r\n\r\nexport function useSetUserData() {\r\n const queryClient = useQueryClient();\r\n return (user: User | null) => queryClient.setQueryData(USER_QUERY_KEY, user);\r\n}\r\n"],"mappings":";AAEA,SAAS,aAAa,UAAU,sBAAuC;AAEvE,SAAS,kBAAkB;AAEpB,MAAM,iBAAiB,CAAC,MAAM;AAErC,eAAe,YAAkC;AAC/C,QAAM,EAAE,cAAc,kBAAkB,IAAI,MAAM,OAAO,2CAA2C;AACpG,QAAM,SAAS,MAAM,kBAAkB;AACvC,SAAO,OAAO,WAAW,OAAO,OAAO,OAAO,OAAO;AACvD;AAEA,eAAe,sBAAwC;AACrD,QAAM,EAAE,sBAAsB,IAAI,MAAM,OAAO,oCAAoC;AACnF,SAAO,MAAM,sBAAsB;AACrC;AAEO,SAAS,eAAe;AAC7B,SAAO,SAAS;AAAA,IACd,UAAU;AAAA,IACV,SAAS;AAAA,IACT,WAAW,IAAI,KAAK;AAAA,IACpB,QAAQ,KAAK,KAAK;AAAA,IAClB,OAAO;AAAA,EACT,CAAC;AACH;AAEO,SAAS,uBAAuB,SAA2B;AAChE,SAAO,SAAS;AAAA,IACd,UAAU,CAAC,uBAAuB;AAAA,IAClC,SAAS;AAAA,IACT,OAAO;AAAA,IACP,WAAW,IAAI,KAAK;AAAA,IACpB,GAAG;AAAA,IACH,gBAAgB;AAAA,IAChB,sBAAsB;AAAA,EACxB,CAAC;AACH;AAEO,SAAS,qBAAqB;AACnC,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,EAAE,QAAQ,KAAK,MAAwC;AACxE,YAAM,EAAE,sBAAsB,IAAI,MAAM,OAAO,qCAAqC;AACpF,aAAO,WAAW,MAAM,sBAAsB,QAAQ,IAAI,CAAC,EAAE;AAAA,IAC/D;AAAA,IACA,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,eAAe,CAAC;AAC1D,kBAAY,kBAAkB,EAAE,UAAU,CAAC,oBAAoB,EAAE,CAAC;AAAA,IACpE;AAAA,EACF,CAAC;AACH;AAEO,SAAS,oBAAoB;AAClC,QAAM,cAAc,eAAe;AACnC,SAAO,MAAM,YAAY,kBAAkB,EAAE,UAAU,eAAe,CAAC;AACzE;AAEO,SAAS,iBAAiB;AAC/B,QAAM,cAAc,eAAe;AACnC,SAAO,CAAC,SAAsB,YAAY,aAAa,gBAAgB,IAAI;AAC7E;","names":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
//# sourceMappingURL=schema.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/services/auth.service.ts"],"sourcesContent":["import { cookies } from \"next/headers\";\r\n\r\nimport { api } from \"../../../infra/api/client\";\r\nimport { ApiError } from \"../../../infra/api/types\";\r\nimport {\r\n ClientInfo,\r\n ForgotPasswordRequest,\r\n ForgotPasswordResponse,\r\n GeoLocation,\r\n LoginApiResponse,\r\n LoginRequest,\r\n LoginResponse,\r\n LogoutApiResponse,\r\n LogoutRequest,\r\n LogoutResponse,\r\n RegisterApiRequest,\r\n RegisterApiResponse,\r\n RegisterRequest,\r\n RegisterResponse,\r\n ResendVerificationRequest,\r\n ResendVerificationResponse,\r\n ResetPasswordRequest,\r\n ResetPasswordResponse,\r\n SessionKeepRequest,\r\n SessionKeepResponse,\r\n TwoFactorApiResponse,\r\n TwoFactorRequest,\r\n TwoFactorResponse,\r\n VerifyEmailRequest,\r\n VerifyEmailResponse,\r\n} from \"../schema\";\r\n\r\nconst AUTH_COOKIE_NAME = \"greatapps\";\r\nconst COOKIE_MAX_AGE = 60 * 60 * 24 * 30;\r\n\r\nconst COOKIE_OPTIONS = {\r\n httpOnly: true,\r\n secure: process.env.NODE_ENV === \"production\",\r\n sameSite: \"lax\" as const,\r\n path: \"/\",\r\n domain: process.env.DOMAIN_COOKIE,\r\n};\r\n\r\nclass AuthService {\r\n async login(\r\n credentials: LoginRequest,\r\n clientInfo: ClientInfo\r\n ): Promise<LoginResponse> {\r\n const response = await api.apps.post<LoginApiResponse>(\"/auth/login\", {\r\n email: credentials.email,\r\n password: credentials.password,\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n });\r\n\r\n console.log(\"[AuthService.login] response\", JSON.stringify(response));\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"E-mail ou senha incorretos\",\r\n response.code || \"LOGIN_FAILED\",\r\n 401\r\n );\r\n }\r\n\r\n if (!response.cookie) {\r\n throw new ApiError(\r\n \"Resposta de autenticação inválida\",\r\n \"INVALID_RESPONSE\",\r\n 500\r\n );\r\n }\r\n\r\n if (response.two_factor_required) {\r\n return { result: 'two_factor_required', cookie: response.cookie };\r\n }\r\n\r\n await this.setAuthCookie(response.cookie);\r\n\r\n const [{ userService }, { accountService }] = await Promise.all([\r\n import('../../users/services/user.service'),\r\n import('../../accounts/services/account.service'),\r\n ]);\r\n const [user, account] = await Promise.all([\r\n userService.findById(),\r\n accountService.findCurrentAccount(),\r\n ]);\r\n\r\n return {\r\n result: 'success',\r\n user,\r\n account,\r\n accessToken: response.cookie,\r\n refreshToken: \"\",\r\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\r\n };\r\n }\r\n\r\n async verifyTwoFactor(\r\n cookie: string,\r\n code: string,\r\n clientInfo: ClientInfo\r\n ): Promise<TwoFactorResponse> {\r\n const payload: TwoFactorRequest = {\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n cookie,\r\n code,\r\n };\r\n\r\n const response = await api.apps.post<TwoFactorApiResponse>(\r\n \"/auth/code\",\r\n payload\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\"Código 2FA inválido\", \"TWO_FACTOR_FAILED\", 401);\r\n }\r\n\r\n if (!response?.data?.cookie) {\r\n throw new ApiError(\r\n \"Resposta de autenticação inválida após 2FA\",\r\n \"INVALID_RESPONSE\",\r\n 500\r\n );\r\n }\r\n\r\n await this.setAuthCookie(response.data.cookie);\r\n\r\n return { status: 1 };\r\n }\r\n async register(data: RegisterRequest, _clientInfo: ClientInfo): Promise<RegisterResponse> {\r\n const today = new Date();\r\n const trialEndDate = new Date(today);\r\n trialEndDate.setDate(today.getDate() + 7); // 7 dias de trial\r\n\r\n const payload: RegisterApiRequest = {\r\n name: data.accountName,\r\n bussiness_type: data.businessType,\r\n language: \"pt-br\",\r\n timezone: \"America/Sao_Paulo\",\r\n currency: \"BRL\",\r\n user: {\r\n id_api: \"\",\r\n name: data.name,\r\n last_name: data.lastName || \"\",\r\n rg: data.rg || \"\",\r\n cpf: data.cpf || \"\",\r\n gender: data.gender,\r\n email: data.email,\r\n phone: data.phone,\r\n password: data.password,\r\n profile: \"owner\",\r\n language: \"pt-br\",\r\n },\r\n subscription: {\r\n type: \"trial\",\r\n id_cupom: data.couponCode || \"\",\r\n id_plan: data.idPlan || 1,\r\n due_date: trialEndDate.toISOString().split(\"T\")[0],\r\n id_product: 1,\r\n },\r\n };\r\n\r\n const response = await api.apps.post<RegisterApiResponse>(\r\n \"/accounts\",\r\n payload\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao criar conta\",\r\n \"REGISTER_FAILED\",\r\n 400\r\n );\r\n }\r\n\r\n if (!response.data || response.data.length === 0) {\r\n throw new ApiError(\r\n \"Resposta de registro inválida\",\r\n \"INVALID_RESPONSE\",\r\n 500\r\n );\r\n }\r\n\r\n if (!response.cookie) {\r\n throw new ApiError(\r\n \"Resposta de autenticação inválida\",\r\n \"INVALID_RESPONSE\",\r\n 500\r\n );\r\n }\r\n\r\n const accountData = response.data[0];\r\n\r\n await this.setAuthCookie(response.cookie);\r\n\r\n const [{ userService }, { accountService }] = await Promise.all([\r\n import('../../users/services/user.service'),\r\n import('../../accounts/services/account.service'),\r\n ]);\r\n const [user, account] = await Promise.all([\r\n userService.findById(),\r\n accountService.findCurrentAccount(),\r\n ]);\r\n\r\n return {\r\n user,\r\n account,\r\n accessToken: response.cookie,\r\n refreshToken: \"\",\r\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\r\n requiresEmailVerification: !accountData.verified,\r\n };\r\n }\r\n\r\n async logout(clientInfo: ClientInfo): Promise<LogoutResponse> {\r\n const cookie = await this.getToken();\r\n\r\n if (!cookie) {\r\n throw new ApiError(\r\n \"Usuário não autenticado\",\r\n \"NOT_AUTHENTICATED_LOGOUT\",\r\n 401\r\n );\r\n }\r\n\r\n const payload: LogoutRequest = {\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n cookie,\r\n };\r\n\r\n try {\r\n const response = await api.apps.post<LogoutApiResponse>(\r\n \"/auth/logout\",\r\n payload\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao realizar logout\",\r\n response.code || \"LOGOUT_FAILED\",\r\n 400\r\n );\r\n }\r\n } finally {\r\n await this.removeAuthCookie();\r\n }\r\n\r\n return {\r\n success: true,\r\n };\r\n }\r\n\r\n async forgotPassword(\r\n _data: ForgotPasswordRequest\r\n ): Promise<ForgotPasswordResponse> {\r\n throw new ApiError(\r\n \"Recuperação de senha não implementada\",\r\n \"NOT_IMPLEMENTED\",\r\n 501\r\n );\r\n }\r\n\r\n async resetPassword(\r\n _data: ResetPasswordRequest\r\n ): Promise<ResetPasswordResponse> {\r\n throw new ApiError(\r\n \"Redefinição de senha não implementada\",\r\n \"NOT_IMPLEMENTED\",\r\n 501\r\n );\r\n }\r\n\r\n async verifyEmail(_data: VerifyEmailRequest): Promise<VerifyEmailResponse> {\r\n throw new ApiError(\r\n \"Verificação de email não implementada\",\r\n \"NOT_IMPLEMENTED\",\r\n 501\r\n );\r\n }\r\n\r\n async resendVerification(\r\n _data: ResendVerificationRequest\r\n ): Promise<ResendVerificationResponse> {\r\n throw new ApiError(\r\n \"Reenvio de verificação não implementado\",\r\n \"NOT_IMPLEMENTED\",\r\n 501\r\n );\r\n }\r\n\r\n async validateSession(clientInfo: ClientInfo): Promise<boolean> {\r\n const cookie = await this.getToken();\r\n\r\n if (!cookie) {\r\n return false;\r\n }\r\n\r\n try {\r\n const payload: SessionKeepRequest = {\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n cookie,\r\n };\r\n\r\n const response = await api.apps.post<SessionKeepResponse>(\r\n \"/auth/keep\",\r\n payload\r\n );\r\n\r\n return response.status === 1;\r\n } catch (error) {\r\n console.error(\"[AuthService] validateSession error\", error);\r\n return false;\r\n }\r\n }\r\n\r\n async isAuthenticated(): Promise<boolean> {\r\n const token = await this.getToken();\r\n return !!token;\r\n }\r\n\r\n async getToken(): Promise<string | undefined> {\r\n if (process.env.DUMMY_AUTH_TOKEN) return process.env.DUMMY_AUTH_TOKEN;\r\n const cookieStore = await cookies();\r\n return cookieStore.get(AUTH_COOKIE_NAME)?.value;\r\n }\r\n\r\n private async setAuthCookie(token: string): Promise<void> {\r\n const cookieStore = await cookies();\r\n cookieStore.set(AUTH_COOKIE_NAME, token, {\r\n ...COOKIE_OPTIONS,\r\n maxAge: COOKIE_MAX_AGE,\r\n });\r\n }\r\n\r\n async removeAuthCookie(): Promise<void> {\r\n const cookieStore = await cookies();\r\n cookieStore.delete({\r\n name: AUTH_COOKIE_NAME,\r\n ...COOKIE_OPTIONS,\r\n });\r\n }\r\n}\r\n\r\nexport const authService = new AuthService();\r\n\r\nexport type {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ACrB,IAAI,WAAW;AAAA,QACf,UAAU,WAAW;AAAA,QACrB,OAAO,WAAW;AAAA,QAClB;AAAA,MACF;AAEA,YAAM,WAAW,MAAM,IAAI,KAAK;AAAA,QAC9B;AAAA,QACA;AAAA,MACF;AAEA,aAAO,SAAS,WAAW;AAAA,IAC7B,SAAS,OAAO;AACd,cAAQ,MAAM,uCAAuC,KAAK;AAC1D,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,kBAAoC;AACxC,UAAM,QAAQ,MAAM,KAAK,SAAS;AAClC,WAAO,CAAC,CAAC;AAAA,EACX;AAAA,EAEA,MAAM,WAAwC;AAC5C,QAAI,QAAQ,IAAI,iBAAkB,QAAO,QAAQ,IAAI;AACrD,UAAM,cAAc,MAAM,QAAQ;AAClC,WAAO,YAAY,IAAI,gBAAgB,GAAG;AAAA,EAC5C;AAAA,EAEA,MAAc,cAAc,OAA8B;AACxD,UAAM,cAAc,MAAM,QAAQ;AAClC,gBAAY,IAAI,kBAAkB,OAAO;AAAA,MACvC,GAAG;AAAA,MACH,QAAQ;AAAA,IACV,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,mBAAkC;AACtC,UAAM,cAAc,MAAM,QAAQ;AAClC,gBAAY,OAAO;AAAA,MACjB,MAAM;AAAA,MACN,GAAG;AAAA,IACL,CAAC;AAAA,EACH;AACF;AAEO,MAAM,cAAc,IAAI,YAAY;","names":[]}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import "server-only";
|
|
2
|
-
import { cookies } from "next/headers";
|
|
3
|
-
import { ApiError } from "../../../infra/api/types";
|
|
4
|
-
const AUTH_COOKIE_NAME = "greatapps";
|
|
5
|
-
async function getUserContext() {
|
|
6
|
-
const cookieStore = await cookies();
|
|
7
|
-
const token = process.env.DUMMY_AUTH_TOKEN || cookieStore.get(AUTH_COOKIE_NAME)?.value;
|
|
8
|
-
if (!token) {
|
|
9
|
-
throw new ApiError("Usu\xE1rio n\xE3o autenticado", "NOT_AUTHENTICATED_GUC", 401);
|
|
10
|
-
}
|
|
11
|
-
try {
|
|
12
|
-
const payload = JSON.parse(atob(token.split(".")[1]));
|
|
13
|
-
return {
|
|
14
|
-
id_account: payload.id_account,
|
|
15
|
-
id_user: payload.id_user
|
|
16
|
-
};
|
|
17
|
-
} catch {
|
|
18
|
-
throw new ApiError("Token inv\xE1lido", "INVALID_TOKEN", 401);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
export {
|
|
22
|
-
getUserContext
|
|
23
|
-
};
|
|
24
|
-
//# sourceMappingURL=get-user-context.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/utils/get-user-context.ts"],"sourcesContent":["import 'server-only';\r\n\r\nimport { cookies } from 'next/headers';\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { JWTPayload } from '../../users/schema';\r\n\r\nconst AUTH_COOKIE_NAME = 'greatapps';\r\n\r\nexport async function getUserContext(): Promise<{\r\n id_account: number;\r\n id_user: number;\r\n}> {\r\n const cookieStore = await cookies();\r\n const token = process.env.DUMMY_AUTH_TOKEN || cookieStore.get(AUTH_COOKIE_NAME)?.value;\r\n\r\n if (!token) {\r\n throw new ApiError('Usuário não autenticado', 'NOT_AUTHENTICATED_GUC', 401);\r\n }\r\n\r\n try {\r\n const payload = JSON.parse(atob(token.split('.')[1])) as JWTPayload;\r\n\r\n return {\r\n id_account: payload.id_account,\r\n id_user: payload.id_user,\r\n };\r\n } catch {\r\n throw new ApiError('Token inválido', 'INVALID_TOKEN', 401);\r\n }\r\n}\r\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,eAAe;AACxB,SAAS,gBAAgB;AAGzB,MAAM,mBAAmB;AAEzB,eAAsB,iBAGnB;AACD,QAAM,cAAc,MAAM,QAAQ;AAClC,QAAM,QAAQ,QAAQ,IAAI,oBAAoB,YAAY,IAAI,gBAAgB,GAAG;AAEjF,MAAI,CAAC,OAAO;AACV,UAAM,IAAI,SAAS,iCAA2B,yBAAyB,GAAG;AAAA,EAC5E;AAEA,MAAI;AACF,UAAM,UAAU,KAAK,MAAM,KAAK,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;AAEpD,WAAO;AAAA,MACL,YAAY,QAAQ;AAAA,MACpB,SAAS,QAAQ;AAAA,IACnB;AAAA,EACF,QAAQ;AACN,UAAM,IAAI,SAAS,qBAAkB,iBAAiB,GAAG;AAAA,EAC3D;AACF;","names":[]}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
import { safeServerAction } from "../../../utils/safeServerAction";
|
|
3
|
-
import { iaCreditsService } from "../services/ia-credits.service";
|
|
4
|
-
async function listIaCreditsAction(subscriptionId) {
|
|
5
|
-
return safeServerAction(() => iaCreditsService.listOperations(subscriptionId));
|
|
6
|
-
}
|
|
7
|
-
export {
|
|
8
|
-
listIaCreditsAction
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=list-ia-credits.action.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/ia-credits/actions/list-ia-credits.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { iaCreditsService } from '../services/ia-credits.service';\n\nexport async function listIaCreditsAction(subscriptionId: number | string) {\n return safeServerAction(() => iaCreditsService.listOperations(subscriptionId));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AAEjC,eAAsB,oBAAoB,gBAAiC;AACzE,SAAO,iBAAiB,MAAM,iBAAiB,eAAe,cAAc,CAAC;AAC/E;","names":[]}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useMemo } from "react";
|
|
3
|
-
import { useQuery } from "@tanstack/react-query";
|
|
4
|
-
import { listIaCreditsAction } from "../actions/list-ia-credits.action";
|
|
5
|
-
import { useActiveSubscription } from "../../subscriptions/hooks/find-active-subscription.hook";
|
|
6
|
-
import { withAction } from "../../../utils/withAction";
|
|
7
|
-
function calculateSummary(operations) {
|
|
8
|
-
const today = /* @__PURE__ */ new Date();
|
|
9
|
-
const todayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
|
10
|
-
const adds = operations.filter((op) => op.operation === "add");
|
|
11
|
-
const subtracts = operations.filter((op) => op.operation === "subtract");
|
|
12
|
-
let totalCredits = 0;
|
|
13
|
-
let usedCredits = 0;
|
|
14
|
-
let nextExpirationInDays = null;
|
|
15
|
-
let nextExpiringCredits = null;
|
|
16
|
-
for (const add of adds) {
|
|
17
|
-
const expirationRaw = add.expiration_time;
|
|
18
|
-
if (!expirationRaw) continue;
|
|
19
|
-
const expiration = new Date(expirationRaw);
|
|
20
|
-
const expirationDate = new Date(
|
|
21
|
-
expiration.getFullYear(),
|
|
22
|
-
expiration.getMonth(),
|
|
23
|
-
expiration.getDate()
|
|
24
|
-
);
|
|
25
|
-
const expiredByDate = expirationDate.getTime() < todayDate.getTime();
|
|
26
|
-
const hasExpired = add.has_expired || expiredByDate;
|
|
27
|
-
if (hasExpired) continue;
|
|
28
|
-
const addedCredits = add.operation_value;
|
|
29
|
-
const consumedForAdd = subtracts.filter((sub) => String(sub.consumed_from_add_id) === String(add.id)).reduce((sum, sub) => sum + sub.operation_value, 0);
|
|
30
|
-
const remainingForAdd = Math.max(0, addedCredits - consumedForAdd);
|
|
31
|
-
totalCredits += addedCredits;
|
|
32
|
-
usedCredits += consumedForAdd;
|
|
33
|
-
const diffMs = expirationDate.getTime() - todayDate.getTime();
|
|
34
|
-
const days = Math.max(0, Math.ceil(diffMs / (1e3 * 60 * 60 * 24)));
|
|
35
|
-
if (remainingForAdd > 0) {
|
|
36
|
-
if (nextExpirationInDays === null || days < nextExpirationInDays) {
|
|
37
|
-
nextExpirationInDays = days;
|
|
38
|
-
nextExpiringCredits = remainingForAdd;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const availableCredits = Math.max(0, totalCredits - usedCredits);
|
|
43
|
-
return {
|
|
44
|
-
totalCredits,
|
|
45
|
-
usedCredits,
|
|
46
|
-
availableCredits,
|
|
47
|
-
nextExpiringCredits,
|
|
48
|
-
nextExpirationInDays
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function useIaCredits() {
|
|
52
|
-
const { data: subscriptionData, isPending: isSubscriptionLoading } = useActiveSubscription();
|
|
53
|
-
const subscription = subscriptionData?.data?.[0] ?? null;
|
|
54
|
-
const subscriptionId = subscription?.id;
|
|
55
|
-
const query = useQuery({
|
|
56
|
-
queryKey: ["ia-credits", subscriptionId],
|
|
57
|
-
queryFn: withAction(() => listIaCreditsAction(subscriptionId)),
|
|
58
|
-
enabled: subscriptionId != null
|
|
59
|
-
});
|
|
60
|
-
const operations = query.data?.data ?? [];
|
|
61
|
-
const summary = useMemo(() => calculateSummary(operations), [operations]);
|
|
62
|
-
return {
|
|
63
|
-
subscription,
|
|
64
|
-
operations,
|
|
65
|
-
summary,
|
|
66
|
-
isLoading: isSubscriptionLoading || query.isPending,
|
|
67
|
-
isSubscriptionLoading,
|
|
68
|
-
isCreditsLoading: query.isPending,
|
|
69
|
-
isError: query.isError,
|
|
70
|
-
error: query.error
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
export {
|
|
74
|
-
useIaCredits
|
|
75
|
-
};
|
|
76
|
-
//# sourceMappingURL=ia-credits.hook.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/ia-credits/hooks/ia-credits.hook.ts"],"sourcesContent":["'use client';\r\n\r\nimport { useMemo } from 'react';\r\nimport { useQuery } from '@tanstack/react-query';\r\nimport { listIaCreditsAction } from '../actions/list-ia-credits.action';\r\nimport type { IaCreditOperation, IaCreditsSummary } from '../types';\r\nimport { useActiveSubscription } from '../../subscriptions/hooks/find-active-subscription.hook';\r\nimport { withAction } from '../../../utils/withAction';\r\n\r\nfunction calculateSummary(operations: IaCreditOperation[]): IaCreditsSummary {\r\n const today = new Date();\r\n const todayDate = new Date(today.getFullYear(), today.getMonth(), today.getDate());\r\n\r\n const adds = operations.filter((op) => op.operation === 'add');\r\n const subtracts = operations.filter((op) => op.operation === 'subtract');\r\n\r\n let totalCredits = 0;\r\n let usedCredits = 0;\r\n let nextExpirationInDays: number | null = null;\r\n let nextExpiringCredits: number | null = null;\r\n\r\n for (const add of adds) {\r\n const expirationRaw = add.expiration_time;\r\n if (!expirationRaw) continue;\r\n\r\n const expiration = new Date(expirationRaw);\r\n const expirationDate = new Date(\r\n expiration.getFullYear(),\r\n expiration.getMonth(),\r\n expiration.getDate()\r\n );\r\n\r\n const expiredByDate = expirationDate.getTime() < todayDate.getTime();\r\n const hasExpired = add.has_expired || expiredByDate;\r\n\r\n if (hasExpired) continue;\r\n\r\n const addedCredits = add.operation_value;\r\n\r\n const consumedForAdd = subtracts\r\n .filter((sub) => String(sub.consumed_from_add_id) === String(add.id))\r\n .reduce((sum, sub) => sum + sub.operation_value, 0);\r\n\r\n const remainingForAdd = Math.max(0, addedCredits - consumedForAdd);\r\n\r\n totalCredits += addedCredits;\r\n usedCredits += consumedForAdd;\r\n\r\n const diffMs = expirationDate.getTime() - todayDate.getTime();\r\n const days = Math.max(0, Math.ceil(diffMs / (1000 * 60 * 60 * 24)));\r\n\r\n if (remainingForAdd > 0) {\r\n if (nextExpirationInDays === null || days < nextExpirationInDays) {\r\n nextExpirationInDays = days;\r\n nextExpiringCredits = remainingForAdd;\r\n }\r\n }\r\n }\r\n\r\n const availableCredits = Math.max(0, totalCredits - usedCredits);\r\n\r\n return {\r\n totalCredits,\r\n usedCredits,\r\n availableCredits,\r\n nextExpiringCredits,\r\n nextExpirationInDays,\r\n };\r\n}\r\n\r\nexport function useIaCredits() {\r\n const { data: subscriptionData, isPending: isSubscriptionLoading } = useActiveSubscription();\r\n const subscription = subscriptionData?.data?.[0] ?? null;\r\n const subscriptionId = subscription?.id;\r\n\r\n const query = useQuery({\r\n queryKey: ['ia-credits', subscriptionId],\r\n queryFn: withAction(() => listIaCreditsAction(subscriptionId!)),\r\n enabled: subscriptionId != null,\r\n });\r\n\r\n const operations = query.data?.data ?? [];\r\n\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n const summary = useMemo(() => calculateSummary(operations), [operations]);\r\n\r\n return {\r\n subscription,\r\n operations,\r\n summary,\r\n isLoading: isSubscriptionLoading || query.isPending,\r\n isSubscriptionLoading,\r\n isCreditsLoading: query.isPending,\r\n isError: query.isError,\r\n error: query.error,\r\n };\r\n}\r\n"],"mappings":";AAEA,SAAS,eAAe;AACxB,SAAS,gBAAgB;AACzB,SAAS,2BAA2B;AAEpC,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;AAE3B,SAAS,iBAAiB,YAAmD;AAC3E,QAAM,QAAQ,oBAAI,KAAK;AACvB,QAAM,YAAY,IAAI,KAAK,MAAM,YAAY,GAAG,MAAM,SAAS,GAAG,MAAM,QAAQ,CAAC;AAEjF,QAAM,OAAO,WAAW,OAAO,CAAC,OAAO,GAAG,cAAc,KAAK;AAC7D,QAAM,YAAY,WAAW,OAAO,CAAC,OAAO,GAAG,cAAc,UAAU;AAEvE,MAAI,eAAe;AACnB,MAAI,cAAc;AAClB,MAAI,uBAAsC;AAC1C,MAAI,sBAAqC;AAEzC,aAAW,OAAO,MAAM;AACtB,UAAM,gBAAgB,IAAI;AAC1B,QAAI,CAAC,cAAe;AAEpB,UAAM,aAAa,IAAI,KAAK,aAAa;AACzC,UAAM,iBAAiB,IAAI;AAAA,MACzB,WAAW,YAAY;AAAA,MACvB,WAAW,SAAS;AAAA,MACpB,WAAW,QAAQ;AAAA,IACrB;AAEA,UAAM,gBAAgB,eAAe,QAAQ,IAAI,UAAU,QAAQ;AACnE,UAAM,aAAa,IAAI,eAAe;AAEtC,QAAI,WAAY;AAEhB,UAAM,eAAe,IAAI;AAEzB,UAAM,iBAAiB,UACpB,OAAO,CAAC,QAAQ,OAAO,IAAI,oBAAoB,MAAM,OAA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} from "../../../infra/api/client";
|
|
3
|
-
import { ApiError } from "../../../infra/api/types";
|
|
4
|
-
import { getUserContext } from "../../auth/utils/get-user-context";
|
|
5
|
-
import { IaCreditOperationSchema } from "../types";
|
|
6
|
-
class IaCreditsService {
|
|
7
|
-
async listOperations(subscriptionId) {
|
|
8
|
-
const { id_account } = await getUserContext();
|
|
9
|
-
const endpoint = `/accounts/${id_account}/subscriptions/${subscriptionId}/items/balance/list?page=1&limit=20&sort=id:DESC`;
|
|
10
|
-
const response = await api.apps.get(endpoint);
|
|
11
|
-
if (response.status === 0) {
|
|
12
|
-
throw new ApiError(
|
|
13
|
-
response.message || "Erro ao listar cr\xE9ditos de IA",
|
|
14
|
-
"LIST_IA_CREDITS_FAILED",
|
|
15
|
-
400
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
const raw = response.data ?? [];
|
|
19
|
-
const data = raw.map((item) => IaCreditOperationSchema.parse(item));
|
|
20
|
-
return {
|
|
21
|
-
data,
|
|
22
|
-
total: response.total ?? data.length,
|
|
23
|
-
success: true
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
const iaCreditsService = new IaCreditsService();
|
|
28
|
-
export {
|
|
29
|
-
iaCreditsService
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=ia-credits.service.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/ia-credits/services/ia-credits.service.ts"],"sourcesContent":["import 'server-only';\r\n\r\nimport { api } from '../../../infra/api/client';\r\nimport { ApiError, ApiPaginatedActionResult, PaginatedSuccessResult } from '../../../infra/api/types';\r\nimport { getUserContext } from '../../auth/utils/get-user-context';\r\nimport { IaCreditOperation, IaCreditOperationSchema } from '../types';\r\n\r\nclass IaCreditsService {\r\n async listOperations(\r\n subscriptionId: number | string\r\n ): Promise<PaginatedSuccessResult<IaCreditOperation>> {\r\n const { id_account } = await getUserContext();\r\n\r\n const endpoint = `/accounts/${id_account}/subscriptions/${subscriptionId}/items/balance/list?page=1&limit=20&sort=id:DESC`;\r\n\r\n const response = await api.apps.get<ApiPaginatedActionResult<IaCreditOperation>>(endpoint);\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || 'Erro ao listar créditos de IA',\r\n 'LIST_IA_CREDITS_FAILED',\r\n 400\r\n );\r\n }\r\n\r\n const raw = response.data ?? [];\r\n const data = raw.map((item) => IaCreditOperationSchema.parse(item));\r\n\r\n return {\r\n data,\r\n total: response.total ?? data.length,\r\n success: true,\r\n };\r\n }\r\n}\r\n\r\nexport const iaCreditsService = new IaCreditsService();\r\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,WAAW;AACpB,SAAS,gBAAkE;AAC3E,SAAS,sBAAsB;AAC/B,SAA4B,+BAA+B;AAE3D,MAAM,iBAAiB;AAAA,EACrB,MAAM,eACJ,gBACoD;AACpD,UAAM,EAAE,WAAW,IAAI,MAAM,eAAe;AAE5C,UAAM,WAAW,aAAa,UAAU,kBAAkB,cAAc;AAExE,UAAM,WAAW,MAAM,IAAI,KAAK,IAAiD,QAAQ;AAEzF,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,UAAM,MAAM,SAAS,QAAQ,CAAC;AAC9B,UAAM,OAAO,IAAI,IAAI,CAAC,SAAS,wBAAwB,MAAM,IAAI,CAAC;AAElE,WAAO;AAAA,MACL;AAAA,MACA,OAAO,SAAS,SAAS,KAAK;AAAA,MAC9B,SAAS;AAAA,IACX;AAAA,EACF;AACF;AAEO,MAAM,mBAAmB,IAAI,iBAAiB;","names":[]}
|