@greatapps/common 1.1.139 → 1.1.141

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.
Files changed (392) hide show
  1. package/dist/components/account/AccountModals.mjs +18 -0
  2. package/dist/components/account/AccountModals.mjs.map +1 -0
  3. package/dist/components/account/ConfigurationsMyAccountModal.mjs +132 -0
  4. package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +1 -0
  5. package/dist/components/account/ConfirmDeleteAccountModal.mjs +45 -0
  6. package/dist/components/account/ConfirmDeleteAccountModal.mjs.map +1 -0
  7. package/dist/components/account/ConfirmGlobalPreferencesModal.mjs +45 -0
  8. package/dist/components/account/ConfirmGlobalPreferencesModal.mjs.map +1 -0
  9. package/dist/components/account/DeleteAccountModal.mjs +123 -0
  10. package/dist/components/account/DeleteAccountModal.mjs.map +1 -0
  11. package/dist/components/account/DisableTwoFactorAuthModal.mjs +67 -0
  12. package/dist/components/account/DisableTwoFactorAuthModal.mjs.map +1 -0
  13. package/dist/components/account/IsntPossibleDeleteAccountModal.mjs +42 -0
  14. package/dist/components/account/IsntPossibleDeleteAccountModal.mjs.map +1 -0
  15. package/dist/components/account/TwoFactorAuthModal.mjs +190 -0
  16. package/dist/components/account/TwoFactorAuthModal.mjs.map +1 -0
  17. package/dist/components/account/constants.mjs +29 -0
  18. package/dist/components/account/constants.mjs.map +1 -0
  19. package/dist/components/account/hooks/useChangeEmailForm.mjs +53 -0
  20. package/dist/components/account/hooks/useChangeEmailForm.mjs.map +1 -0
  21. package/dist/components/account/hooks/useChangePasswordForm.mjs +47 -0
  22. package/dist/components/account/hooks/useChangePasswordForm.mjs.map +1 -0
  23. package/dist/components/account/hooks/useChangePhoneForm.mjs +64 -0
  24. package/dist/components/account/hooks/useChangePhoneForm.mjs.map +1 -0
  25. package/dist/components/account/hooks/useConfigurationsModal.mjs +33 -0
  26. package/dist/components/account/hooks/useConfigurationsModal.mjs.map +1 -0
  27. package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs +54 -0
  28. package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs.map +1 -0
  29. package/dist/components/account/hooks/useOtpVerification.mjs +94 -0
  30. package/dist/components/account/hooks/useOtpVerification.mjs.map +1 -0
  31. package/dist/components/account/hooks/useTwoFactorAuthForm.mjs +80 -0
  32. package/dist/components/account/hooks/useTwoFactorAuthForm.mjs.map +1 -0
  33. package/dist/components/account/sections/ChangeEmailModal.mjs +180 -0
  34. package/dist/components/account/sections/ChangeEmailModal.mjs.map +1 -0
  35. package/dist/components/account/sections/ChangePasswordSection.mjs +64 -0
  36. package/dist/components/account/sections/ChangePasswordSection.mjs.map +1 -0
  37. package/dist/components/account/sections/ChangePhoneModal.mjs +182 -0
  38. package/dist/components/account/sections/ChangePhoneModal.mjs.map +1 -0
  39. package/dist/components/account/sections/MyProfileSection.mjs +303 -0
  40. package/dist/components/account/sections/MyProfileSection.mjs.map +1 -0
  41. package/dist/components/account/sections/PreferencesSection.mjs +250 -0
  42. package/dist/components/account/sections/PreferencesSection.mjs.map +1 -0
  43. package/dist/components/account/sections/SecuritySection.mjs +147 -0
  44. package/dist/components/account/sections/SecuritySection.mjs.map +1 -0
  45. package/dist/components/handlers/SearchParamsHandler.mjs +24 -0
  46. package/dist/components/handlers/SearchParamsHandler.mjs.map +1 -0
  47. package/dist/components/layouts/AppMobileNavBar.mjs +115 -0
  48. package/dist/components/layouts/AppMobileNavBar.mjs.map +1 -0
  49. package/dist/components/layouts/AppNavBar.mjs +49 -0
  50. package/dist/components/layouts/AppNavBar.mjs.map +1 -0
  51. package/dist/components/layouts/MainLayout.mjs +60 -0
  52. package/dist/components/layouts/MainLayout.mjs.map +1 -0
  53. package/dist/components/layouts/MdSideBarNavigation.mjs +54 -0
  54. package/dist/components/layouts/MdSideBarNavigation.mjs.map +1 -0
  55. package/dist/components/layouts/NavBar.mjs +132 -0
  56. package/dist/components/layouts/NavBar.mjs.map +1 -0
  57. package/dist/components/layouts/NavBarItem.mjs +23 -0
  58. package/dist/components/layouts/NavBarItem.mjs.map +1 -0
  59. package/dist/components/layouts/NotificationsPopover.mjs +97 -0
  60. package/dist/components/layouts/NotificationsPopover.mjs.map +1 -0
  61. package/dist/components/layouts/ProfilePopover.mjs +150 -0
  62. package/dist/components/layouts/ProfilePopover.mjs.map +1 -0
  63. package/dist/components/layouts/SideBarNavigation.mjs +22 -0
  64. package/dist/components/layouts/SideBarNavigation.mjs.map +1 -0
  65. package/dist/components/layouts/UsersSelectorPopover.mjs +236 -0
  66. package/dist/components/layouts/UsersSelectorPopover.mjs.map +1 -0
  67. package/dist/components/modals/ModalManager.mjs +19 -0
  68. package/dist/components/modals/ModalManager.mjs.map +1 -0
  69. package/dist/components/modals/Modals.mjs +20 -0
  70. package/dist/components/modals/Modals.mjs.map +1 -0
  71. package/dist/components/navigation/AppNavigation.mjs +30 -0
  72. package/dist/components/navigation/AppNavigation.mjs.map +1 -0
  73. package/dist/components/navigation/AppNavigationContext.mjs +13 -0
  74. package/dist/components/navigation/AppNavigationContext.mjs.map +1 -0
  75. package/dist/components/navigation/NavItem.mjs +35 -0
  76. package/dist/components/navigation/NavItem.mjs.map +1 -0
  77. package/dist/components/navigation/NavItemsContext.mjs +16 -0
  78. package/dist/components/navigation/NavItemsContext.mjs.map +1 -0
  79. package/dist/components/navigation/ProjectSelectorPopover.mjs +128 -0
  80. package/dist/components/navigation/ProjectSelectorPopover.mjs.map +1 -0
  81. package/dist/components/navigation/shells/DesktopShell.mjs +11 -0
  82. package/dist/components/navigation/shells/DesktopShell.mjs.map +1 -0
  83. package/dist/components/navigation/shells/MdShell.mjs +11 -0
  84. package/dist/components/navigation/shells/MdShell.mjs.map +1 -0
  85. package/dist/components/navigation/shells/MobileShell.mjs +27 -0
  86. package/dist/components/navigation/shells/MobileShell.mjs.map +1 -0
  87. package/dist/components/navigation/shells/TabsMobileShell.mjs +59 -0
  88. package/dist/components/navigation/shells/TabsMobileShell.mjs.map +1 -0
  89. package/dist/components/navigation/subcomponents/CreditsCard.mjs +30 -0
  90. package/dist/components/navigation/subcomponents/CreditsCard.mjs.map +1 -0
  91. package/dist/components/navigation/subcomponents/NavItems.mjs +25 -0
  92. package/dist/components/navigation/subcomponents/NavItems.mjs.map +1 -0
  93. package/dist/components/navigation/subcomponents/PlanCard.mjs +25 -0
  94. package/dist/components/navigation/subcomponents/PlanCard.mjs.map +1 -0
  95. package/dist/components/navigation/subcomponents/ProjectSelector.mjs +130 -0
  96. package/dist/components/navigation/subcomponents/ProjectSelector.mjs.map +1 -0
  97. package/dist/components/navigation/types.mjs +1 -0
  98. package/dist/components/pages/notifications/Notifications.mjs +156 -0
  99. package/dist/components/pages/notifications/Notifications.mjs.map +1 -0
  100. package/dist/components/ui/buttons/Button.mjs +52 -0
  101. package/dist/components/ui/buttons/Button.mjs.map +1 -0
  102. package/dist/components/ui/buttons/CancelButton.mjs +17 -0
  103. package/dist/components/ui/buttons/CancelButton.mjs.map +1 -0
  104. package/dist/components/ui/buttons/CopyButton.mjs +42 -0
  105. package/dist/components/ui/buttons/CopyButton.mjs.map +1 -0
  106. package/dist/components/ui/data-display/Accordion.mjs +76 -0
  107. package/dist/components/ui/data-display/Accordion.mjs.map +1 -0
  108. package/dist/components/ui/data-display/Badge.mjs +42 -0
  109. package/dist/components/ui/data-display/Badge.mjs.map +1 -0
  110. package/dist/components/ui/data-display/Card.mjs +92 -0
  111. package/dist/components/ui/data-display/Card.mjs.map +1 -0
  112. package/dist/components/ui/data-display/Pagination.mjs +118 -0
  113. package/dist/components/ui/data-display/Pagination.mjs.map +1 -0
  114. package/dist/components/ui/data-display/ScrollArea.mjs +62 -0
  115. package/dist/components/ui/data-display/ScrollArea.mjs.map +1 -0
  116. package/dist/components/ui/data-display/Separator.mjs +28 -0
  117. package/dist/components/ui/data-display/Separator.mjs.map +1 -0
  118. package/dist/components/ui/data-display/Table.mjs +116 -0
  119. package/dist/components/ui/data-display/Table.mjs.map +1 -0
  120. package/dist/components/ui/data-display/Tabs.mjs +69 -0
  121. package/dist/components/ui/data-display/Tabs.mjs.map +1 -0
  122. package/dist/components/ui/data-display/UserAvatar.mjs +49 -0
  123. package/dist/components/ui/data-display/UserAvatar.mjs.map +1 -0
  124. package/dist/components/ui/feedback/CircularProgress.mjs +71 -0
  125. package/dist/components/ui/feedback/CircularProgress.mjs.map +1 -0
  126. package/dist/components/ui/feedback/DefaultCircularProgress.mjs +50 -0
  127. package/dist/components/ui/feedback/DefaultCircularProgress.mjs.map +1 -0
  128. package/dist/components/ui/feedback/LoadingOverlay.mjs +19 -0
  129. package/dist/components/ui/feedback/LoadingOverlay.mjs.map +1 -0
  130. package/dist/components/ui/feedback/Progress.mjs +37 -0
  131. package/dist/components/ui/feedback/Progress.mjs.map +1 -0
  132. package/dist/components/ui/feedback/Toast.mjs +77 -0
  133. package/dist/components/ui/feedback/Toast.mjs.map +1 -0
  134. package/dist/components/ui/form/Calendar.mjs +204 -0
  135. package/dist/components/ui/form/Calendar.mjs.map +1 -0
  136. package/dist/components/ui/form/Checkbox.mjs +33 -0
  137. package/dist/components/ui/form/Checkbox.mjs.map +1 -0
  138. package/dist/components/ui/form/ComboboxField.mjs +130 -0
  139. package/dist/components/ui/form/ComboboxField.mjs.map +1 -0
  140. package/dist/components/ui/form/DatePicker.mjs +82 -0
  141. package/dist/components/ui/form/DatePicker.mjs.map +1 -0
  142. package/dist/components/ui/form/DateRangePicker.mjs +92 -0
  143. package/dist/components/ui/form/DateRangePicker.mjs.map +1 -0
  144. package/dist/components/ui/form/FormField.mjs +103 -0
  145. package/dist/components/ui/form/FormField.mjs.map +1 -0
  146. package/dist/components/ui/form/Input.mjs +21 -0
  147. package/dist/components/ui/form/Input.mjs.map +1 -0
  148. package/dist/components/ui/form/InputOtp.mjs +70 -0
  149. package/dist/components/ui/form/InputOtp.mjs.map +1 -0
  150. package/dist/components/ui/form/PhoneInput.mjs +78 -0
  151. package/dist/components/ui/form/PhoneInput.mjs.map +1 -0
  152. package/dist/components/ui/form/RadioGroup.mjs +37 -0
  153. package/dist/components/ui/form/RadioGroup.mjs.map +1 -0
  154. package/dist/components/ui/form/Select.mjs +179 -0
  155. package/dist/components/ui/form/Select.mjs.map +1 -0
  156. package/dist/components/ui/form/SelectField.mjs +80 -0
  157. package/dist/components/ui/form/SelectField.mjs.map +1 -0
  158. package/dist/components/ui/form/Switch.mjs +33 -0
  159. package/dist/components/ui/form/Switch.mjs.map +1 -0
  160. package/dist/components/ui/form/SwitchOptionFieldWithIcon.mjs +40 -0
  161. package/dist/components/ui/form/SwitchOptionFieldWithIcon.mjs.map +1 -0
  162. package/dist/components/ui/form/TextAreaField.mjs +56 -0
  163. package/dist/components/ui/form/TextAreaField.mjs.map +1 -0
  164. package/dist/components/ui/form/Textarea.mjs +20 -0
  165. package/dist/components/ui/form/Textarea.mjs.map +1 -0
  166. package/dist/components/ui/overlay/Command.mjs +178 -0
  167. package/dist/components/ui/overlay/Command.mjs.map +1 -0
  168. package/dist/components/ui/overlay/Dialog.mjs +142 -0
  169. package/dist/components/ui/overlay/Dialog.mjs.map +1 -0
  170. package/dist/components/ui/overlay/Popover.mjs +46 -0
  171. package/dist/components/ui/overlay/Popover.mjs.map +1 -0
  172. package/dist/components/ui/overlay/Sheet.mjs +142 -0
  173. package/dist/components/ui/overlay/Sheet.mjs.map +1 -0
  174. package/dist/components/ui/overlay/Tooltip.mjs +57 -0
  175. package/dist/components/ui/overlay/Tooltip.mjs.map +1 -0
  176. package/dist/components/widgets/notifications/NotificationCard.mjs +54 -0
  177. package/dist/components/widgets/notifications/NotificationCard.mjs.map +1 -0
  178. package/dist/enums/AccountSectionType.mjs +11 -0
  179. package/dist/enums/AccountSectionType.mjs.map +1 -0
  180. package/dist/hooks/copy-to-clipboard.hook.mjs +52 -0
  181. package/dist/hooks/copy-to-clipboard.hook.mjs.map +1 -0
  182. package/dist/hooks/useCountdownTimer.mjs +29 -0
  183. package/dist/hooks/useCountdownTimer.mjs.map +1 -0
  184. package/dist/hooks/useDebounce.mjs +19 -0
  185. package/dist/hooks/useDebounce.mjs.map +1 -0
  186. package/dist/hooks/useDebounceState.mjs +12 -0
  187. package/dist/hooks/useDebounceState.mjs.map +1 -0
  188. package/dist/hooks/useDebouncedEffect.mjs +44 -0
  189. package/dist/hooks/useDebouncedEffect.mjs.map +1 -0
  190. package/dist/hooks/useIsMobile.mjs +18 -0
  191. package/dist/hooks/useIsMobile.mjs.map +1 -0
  192. package/dist/hooks/usePasswordVisibility.mjs +13 -0
  193. package/dist/hooks/usePasswordVisibility.mjs.map +1 -0
  194. package/dist/index.mjs +259 -9841
  195. package/dist/index.mjs.map +1 -1
  196. package/dist/{chunk-R2FMWFY6.mjs → infra/api/client.mjs} +10 -14
  197. package/dist/infra/api/client.mjs.map +1 -0
  198. package/dist/infra/api/types.mjs +31 -0
  199. package/dist/infra/api/types.mjs.map +1 -0
  200. package/dist/infra/utils/client-info.mjs +27 -0
  201. package/dist/infra/utils/client-info.mjs.map +1 -0
  202. package/dist/infra/utils/clsx.mjs +9 -0
  203. package/dist/infra/utils/clsx.mjs.map +1 -0
  204. package/dist/infra/utils/params.mjs +21 -0
  205. package/dist/infra/utils/params.mjs.map +1 -0
  206. package/dist/infra/utils/parser.mjs +24 -0
  207. package/dist/infra/utils/parser.mjs.map +1 -0
  208. package/dist/infra/utils/percentage.mjs +20 -0
  209. package/dist/infra/utils/percentage.mjs.map +1 -0
  210. package/dist/middleware.mjs +3 -69
  211. package/dist/middleware.mjs.map +1 -1
  212. package/dist/middlewares/chain.mjs +37 -0
  213. package/dist/middlewares/chain.mjs.map +1 -0
  214. package/dist/middlewares/create-auth-middleware.mjs +28 -0
  215. package/dist/middlewares/create-auth-middleware.mjs.map +1 -0
  216. package/dist/middlewares/types.mjs +11 -0
  217. package/dist/middlewares/types.mjs.map +1 -0
  218. package/dist/modules/accounts/actions/account-management.action.mjs +82 -0
  219. package/dist/modules/accounts/actions/account-management.action.mjs.map +1 -0
  220. package/dist/modules/accounts/actions/find-current-account.action.mjs +10 -0
  221. package/dist/modules/accounts/actions/find-current-account.action.mjs.map +1 -0
  222. package/dist/modules/accounts/actions/list-currencies.action.mjs +10 -0
  223. package/dist/modules/accounts/actions/list-currencies.action.mjs.map +1 -0
  224. package/dist/modules/accounts/actions/list-timezones.action.mjs +10 -0
  225. package/dist/modules/accounts/actions/list-timezones.action.mjs.map +1 -0
  226. package/dist/modules/accounts/hooks/current-account.hook.mjs +24 -0
  227. package/dist/modules/accounts/hooks/current-account.hook.mjs.map +1 -0
  228. package/dist/modules/accounts/hooks/useAccountManagement.mjs +71 -0
  229. package/dist/modules/accounts/hooks/useAccountManagement.mjs.map +1 -0
  230. package/dist/modules/accounts/hooks/useCurrencies.mjs +17 -0
  231. package/dist/modules/accounts/hooks/useCurrencies.mjs.map +1 -0
  232. package/dist/modules/accounts/hooks/useTimezones.mjs +17 -0
  233. package/dist/modules/accounts/hooks/useTimezones.mjs.map +1 -0
  234. package/dist/{chunk-EDTDKGI5.mjs → modules/accounts/services/account.service.mjs} +9 -65
  235. package/dist/modules/accounts/services/account.service.mjs.map +1 -0
  236. package/dist/modules/accounts/services/currency.service.mjs +24 -0
  237. package/dist/modules/accounts/services/currency.service.mjs.map +1 -0
  238. package/dist/modules/accounts/services/timezone.service.mjs +65 -0
  239. package/dist/modules/accounts/services/timezone.service.mjs.map +1 -0
  240. package/dist/modules/accounts/services/two-factor.service.mjs +77 -0
  241. package/dist/modules/accounts/services/two-factor.service.mjs.map +1 -0
  242. package/dist/modules/accounts/types.mjs +1 -0
  243. package/dist/modules/auth/actions/login.action.mjs +14 -0
  244. package/dist/modules/auth/actions/login.action.mjs.map +1 -0
  245. package/dist/modules/auth/actions/logout.action.mjs +14 -0
  246. package/dist/modules/auth/actions/logout.action.mjs.map +1 -0
  247. package/dist/modules/auth/actions/register.action.mjs +14 -0
  248. package/dist/modules/auth/actions/register.action.mjs.map +1 -0
  249. package/dist/{validate-session.action-TMZN36SG.mjs → modules/auth/actions/validate-session.action.mjs} +3 -10
  250. package/dist/modules/auth/actions/validate-session.action.mjs.map +1 -0
  251. package/dist/{verify-two-factor.action-IQM6SU5U.mjs → modules/auth/actions/verify-two-factor.action.mjs} +4 -13
  252. package/dist/modules/auth/actions/verify-two-factor.action.mjs.map +1 -0
  253. package/dist/modules/auth/hooks/login.hook.mjs +18 -0
  254. package/dist/modules/auth/hooks/login.hook.mjs.map +1 -0
  255. package/dist/modules/auth/hooks/logout.hook.mjs +13 -0
  256. package/dist/modules/auth/hooks/logout.hook.mjs.map +1 -0
  257. package/dist/modules/auth/hooks/register.hook.mjs +13 -0
  258. package/dist/modules/auth/hooks/register.hook.mjs.map +1 -0
  259. package/dist/modules/auth/hooks/useUserQuery.mjs +63 -0
  260. package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -0
  261. package/dist/modules/auth/schema.mjs +1 -0
  262. package/dist/{chunk-I26OTCGJ.mjs → modules/auth/services/auth.service.mjs} +13 -47
  263. package/dist/modules/auth/services/auth.service.mjs.map +1 -0
  264. package/dist/modules/auth/utils/get-user-context.mjs +24 -0
  265. package/dist/modules/auth/utils/get-user-context.mjs.map +1 -0
  266. package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs +10 -0
  267. package/dist/modules/ia-credits/actions/list-ia-credits.action.mjs.map +1 -0
  268. package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs +76 -0
  269. package/dist/modules/ia-credits/hooks/ia-credits.hook.mjs.map +1 -0
  270. package/dist/modules/ia-credits/services/ia-credits.service.mjs +31 -0
  271. package/dist/modules/ia-credits/services/ia-credits.service.mjs.map +1 -0
  272. package/dist/modules/ia-credits/types.mjs +25 -0
  273. package/dist/modules/ia-credits/types.mjs.map +1 -0
  274. package/dist/modules/projects/actions/add-project-user.action.mjs +10 -0
  275. package/dist/modules/projects/actions/add-project-user.action.mjs.map +1 -0
  276. package/dist/modules/projects/actions/list-available-users.action.mjs +10 -0
  277. package/dist/modules/projects/actions/list-available-users.action.mjs.map +1 -0
  278. package/dist/modules/projects/actions/list-project-users.action.mjs +10 -0
  279. package/dist/modules/projects/actions/list-project-users.action.mjs.map +1 -0
  280. package/dist/modules/projects/actions/remove-project-user.action.mjs +10 -0
  281. package/dist/modules/projects/actions/remove-project-user.action.mjs.map +1 -0
  282. package/dist/modules/projects/hooks/list-available-users.hook.mjs +34 -0
  283. package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -0
  284. package/dist/modules/projects/hooks/list-project-users.hook.mjs +34 -0
  285. package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -0
  286. package/dist/modules/projects/services/project-users.service.mjs +78 -0
  287. package/dist/modules/projects/services/project-users.service.mjs.map +1 -0
  288. package/dist/modules/projects/types.mjs +22 -0
  289. package/dist/modules/projects/types.mjs.map +1 -0
  290. package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs +10 -0
  291. package/dist/modules/subscriptions/actions/list-subscriptions.action.mjs.map +1 -0
  292. package/dist/modules/subscriptions/constants/addons.constants.mjs +12 -0
  293. package/dist/modules/subscriptions/constants/addons.constants.mjs.map +1 -0
  294. package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs +20 -0
  295. package/dist/modules/subscriptions/hooks/find-active-subscription.hook.mjs.map +1 -0
  296. package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs +18 -0
  297. package/dist/modules/subscriptions/hooks/list-subscriptions.hook.mjs.map +1 -0
  298. package/dist/modules/subscriptions/services/subscriptions.service.mjs +32 -0
  299. package/dist/modules/subscriptions/services/subscriptions.service.mjs.map +1 -0
  300. package/dist/modules/subscriptions/types.mjs +57 -0
  301. package/dist/modules/subscriptions/types.mjs.map +1 -0
  302. package/dist/modules/users/action/find-user-by-id.action.mjs +10 -0
  303. package/dist/modules/users/action/find-user-by-id.action.mjs.map +1 -0
  304. package/dist/modules/users/action/list-messages.action.mjs +13 -0
  305. package/dist/modules/users/action/list-messages.action.mjs.map +1 -0
  306. package/dist/modules/users/action/mark-all-messages-as-read.action.mjs +10 -0
  307. package/dist/modules/users/action/mark-all-messages-as-read.action.mjs.map +1 -0
  308. package/dist/modules/users/action/mark-message-as-read.action.mjs +10 -0
  309. package/dist/modules/users/action/mark-message-as-read.action.mjs.map +1 -0
  310. package/dist/modules/users/hooks/messages.hook.mjs +57 -0
  311. package/dist/modules/users/hooks/messages.hook.mjs.map +1 -0
  312. package/dist/modules/users/schema/messages.schema.mjs +21 -0
  313. package/dist/modules/users/schema/messages.schema.mjs.map +1 -0
  314. package/dist/modules/users/schema.mjs +11 -0
  315. package/dist/modules/users/schema.mjs.map +1 -0
  316. package/dist/modules/users/services/messages.service.mjs +35 -0
  317. package/dist/modules/users/services/messages.service.mjs.map +1 -0
  318. package/dist/{chunk-ZQZNWUKB.mjs → modules/users/services/user.service.mjs} +8 -14
  319. package/dist/modules/users/services/user.service.mjs.map +1 -0
  320. package/dist/modules/whitelabel/actions/find-whitelabel-styles.action.mjs +15 -0
  321. package/dist/modules/whitelabel/actions/find-whitelabel-styles.action.mjs.map +1 -0
  322. package/dist/modules/whitelabel/actions/find-whitelabel.action.mjs +21 -0
  323. package/dist/modules/whitelabel/actions/find-whitelabel.action.mjs.map +1 -0
  324. package/dist/modules/whitelabel/schema.mjs +1 -0
  325. package/dist/modules/whitelabel/schema.mjs.map +1 -0
  326. package/dist/modules/whitelabel/services/whitelabel-styles.service.mjs +76 -0
  327. package/dist/modules/whitelabel/services/whitelabel-styles.service.mjs.map +1 -0
  328. package/dist/{chunk-4IBSIBU6.mjs → modules/whitelabel/services/whitelabel.service.mjs} +9 -60
  329. package/dist/modules/whitelabel/services/whitelabel.service.mjs.map +1 -0
  330. package/dist/modules/whitelabel/styles-schema.mjs +1 -0
  331. package/dist/modules/whitelabel/styles-schema.mjs.map +1 -0
  332. package/dist/providers/auth.provider.mjs +94 -0
  333. package/dist/providers/auth.provider.mjs.map +1 -0
  334. package/dist/providers/query.provider.mjs +99 -0
  335. package/dist/providers/query.provider.mjs.map +1 -0
  336. package/dist/providers/whitelabel.provider.mjs +31 -0
  337. package/dist/providers/whitelabel.provider.mjs.map +1 -0
  338. package/dist/server.mjs +40 -1445
  339. package/dist/server.mjs.map +1 -1
  340. package/dist/store/useAccountModals.mjs +18 -0
  341. package/dist/store/useAccountModals.mjs.map +1 -0
  342. package/dist/store/useMdSidebarStore.mjs +11 -0
  343. package/dist/store/useMdSidebarStore.mjs.map +1 -0
  344. package/dist/store/useMobileNavbarSheet.mjs +14 -0
  345. package/dist/store/useMobileNavbarSheet.mjs.map +1 -0
  346. package/dist/store/useModalManager.mjs +75 -0
  347. package/dist/store/useModalManager.mjs.map +1 -0
  348. package/dist/utils/browser/clipboard.mjs +36 -0
  349. package/dist/utils/browser/clipboard.mjs.map +1 -0
  350. package/dist/utils/file/index.mjs +9 -0
  351. package/dist/utils/file/index.mjs.map +1 -0
  352. package/dist/utils/format/masks.mjs +56 -0
  353. package/dist/utils/format/masks.mjs.map +1 -0
  354. package/dist/utils/intl/locales.mjs +12 -0
  355. package/dist/utils/intl/locales.mjs.map +1 -0
  356. package/dist/{chunk-MXQIEEP6.mjs → utils/safeServerAction.mjs} +2 -8
  357. package/dist/utils/safeServerAction.mjs.map +1 -0
  358. package/dist/utils/validators/account.mjs +26 -0
  359. package/dist/utils/validators/account.mjs.map +1 -0
  360. package/dist/utils/validators/common.mjs +47 -0
  361. package/dist/utils/validators/common.mjs.map +1 -0
  362. package/dist/utils/withAction.mjs +13 -0
  363. package/dist/utils/withAction.mjs.map +1 -0
  364. package/package.json +1 -1
  365. package/dist/MMQ4R4NB-HKE335ZM.mjs +0 -62
  366. package/dist/MMQ4R4NB-HKE335ZM.mjs.map +0 -1
  367. package/dist/V4HPSUGU-XMVFKNNR.mjs +0 -52
  368. package/dist/V4HPSUGU-XMVFKNNR.mjs.map +0 -1
  369. package/dist/account-management.action-4D4A3IPF.mjs +0 -41
  370. package/dist/account.service-FPMIFBBX.mjs +0 -10
  371. package/dist/chunk-4IBSIBU6.mjs.map +0 -1
  372. package/dist/chunk-CO6HSV2G.mjs +0 -165
  373. package/dist/chunk-CO6HSV2G.mjs.map +0 -1
  374. package/dist/chunk-EDTDKGI5.mjs.map +0 -1
  375. package/dist/chunk-I26OTCGJ.mjs.map +0 -1
  376. package/dist/chunk-MXQIEEP6.mjs.map +0 -1
  377. package/dist/chunk-OO354ZZZ.mjs +0 -12702
  378. package/dist/chunk-OO354ZZZ.mjs.map +0 -1
  379. package/dist/chunk-OXVONU6X.mjs +0 -2930
  380. package/dist/chunk-OXVONU6X.mjs.map +0 -1
  381. package/dist/chunk-R2FMWFY6.mjs.map +0 -1
  382. package/dist/chunk-ZQZNWUKB.mjs.map +0 -1
  383. package/dist/find-user-by-id.action-K7PB7IH6.mjs +0 -18
  384. package/dist/find-user-by-id.action-K7PB7IH6.mjs.map +0 -1
  385. package/dist/modern-P2CXBCGW.mjs +0 -427
  386. package/dist/modern-P2CXBCGW.mjs.map +0 -1
  387. package/dist/user.service-GCI4YGGI.mjs +0 -9
  388. package/dist/validate-session.action-TMZN36SG.mjs.map +0 -1
  389. package/dist/verify-two-factor.action-IQM6SU5U.mjs.map +0 -1
  390. /package/dist/{account-management.action-4D4A3IPF.mjs.map → components/navigation/types.mjs.map} +0 -0
  391. /package/dist/{account.service-FPMIFBBX.mjs.map → modules/accounts/types.mjs.map} +0 -0
  392. /package/dist/{user.service-GCI4YGGI.mjs.map → modules/auth/schema.mjs.map} +0 -0
package/dist/server.mjs CHANGED
@@ -1,1449 +1,44 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropNames = Object.getOwnPropertyNames;
3
- var __esm = (fn, res) => function __init() {
4
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
5
- };
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
-
11
- // src/infra/api/types.ts
12
- import z from "zod";
13
- var PaginationParamsSchema, SearchParamsSchema, SortParamsSchema, ApiError;
14
- var init_types = __esm({
15
- "src/infra/api/types.ts"() {
16
- "use strict";
17
- PaginationParamsSchema = z.object({
18
- page: z.number().min(1).optional().default(20),
19
- limit: z.number().optional().default(20)
20
- });
21
- SearchParamsSchema = z.object({
22
- search: z.string().optional()
23
- });
24
- SortParamsSchema = z.object({
25
- sort: z.string().optional()
26
- });
27
- ApiError = class _ApiError extends Error {
28
- code;
29
- statusCode;
30
- constructor(message, code = "UNKNOWN_ERROR", statusCode = 500) {
31
- super(message);
32
- this.name = "ApiError";
33
- this.code = code;
34
- this.statusCode = statusCode;
35
- }
36
- static isApiError(error) {
37
- return error instanceof _ApiError;
38
- }
39
- };
40
- }
41
- });
42
-
43
- // src/modules/whitelabel/services/whitelabel.service.ts
44
- import greatCache from "@greatapps/cache";
45
- var WhitelabelService, whitelabelService;
46
- var init_whitelabel_service = __esm({
47
- "src/modules/whitelabel/services/whitelabel.service.ts"() {
48
- "use strict";
49
- init_types();
50
- WhitelabelService = class {
51
- getApiUrl() {
52
- const apiUrl = process.env.GAPPS_R3_API_URL;
53
- if (!apiUrl) {
54
- throw new ApiError("GAPPS_R3_API_URL not configured", "CONFIG_ERROR", 500);
55
- }
56
- return apiUrl;
57
- }
58
- getToken() {
59
- const token = process.env.WHITELABEL_TOKEN_MASTER;
60
- if (!token) {
61
- throw new ApiError("WHITELABEL_TOKEN_MASTER not configured", "CONFIG_ERROR", 500);
62
- }
63
- return token;
64
- }
65
- async getTokenByDomain(hostname) {
66
- hostname = "greatapps.com.br";
67
- const apiUrl = this.getApiUrl();
68
- const whitelabelMasterToken = this.getToken();
69
- const url = `${apiUrl}/v1/pt-br/1/whitelabel/${hostname}/token`;
70
- console.log("[WhitelabelService] Fetching token for domain", { url });
71
- const cache3 = new greatCache({
72
- service: "whitelabel-service",
73
- version: "1.0",
74
- domain: "whitelabel-cache.greatapps.com.br",
75
- ambient: process.env.NODE_ENV || "development"
76
- });
77
- const cachedData = await cache3.select(`whitelabel-token-${hostname}`);
78
- if (cachedData.status == 1 && "data" in cachedData && cachedData.data) {
79
- console.log("[WhitelabelService] Cache hit for domain", { hostname });
80
- return JSON.parse(cachedData.data);
81
- }
82
- const response = await fetch(url, {
83
- method: "GET",
84
- headers: {
85
- authorization: whitelabelMasterToken
86
- }
87
- });
88
- if (!response.ok) {
89
- console.error("[WhitelabelService] Failed to fetch whitelabel token", { response });
90
- throw new ApiError(
91
- `Failed to fetch whitelabel token: ${response.status}`,
92
- "FETCH_ERROR",
93
- response.status
94
- );
95
- }
96
- const result = await response.json();
97
- if (result.status !== 1 || !result.data?.length) {
98
- throw new ApiError("Whitelabel token not found", "TOKEN_NOT_FOUND", 404);
99
- }
100
- await cache3.insert(`whitelabel-token-${hostname}`, JSON.stringify(result.data[0]), 604800);
101
- return result.data[0];
102
- }
103
- };
104
- whitelabelService = new WhitelabelService();
105
- }
106
- });
107
-
108
- // src/modules/whitelabel/actions/find-whitelabel.action.ts
109
- import { headers } from "next/headers";
110
- import { cache } from "react";
111
- var findWhitelabel;
112
- var init_find_whitelabel_action = __esm({
113
- "src/modules/whitelabel/actions/find-whitelabel.action.ts"() {
114
- "use strict";
115
- "use server";
116
- init_whitelabel_service();
117
- init_types();
118
- findWhitelabel = cache(async () => {
119
- const headersList = await headers();
120
- const host = headersList.get("host");
121
- if (!host) {
122
- throw new ApiError("Host header not found", "HOST_NOT_FOUND", 400);
123
- }
124
- const whitelabel = await whitelabelService.getTokenByDomain(host);
125
- if (!whitelabel) {
126
- throw new ApiError("Whitelabel not found", "WL_NOT_FOUND", 404);
127
- }
128
- return whitelabel;
129
- });
130
- }
131
- });
132
-
133
- // src/infra/api/client.ts
134
- var ApiClient, api, apiClient;
135
- var init_client = __esm({
136
- "src/infra/api/client.ts"() {
137
- "use strict";
138
- init_types();
139
- init_find_whitelabel_action();
140
- ApiClient = class {
141
- baseUrl;
142
- apiVersion = "v1";
143
- apiLocale = "pt-br";
144
- omitApiVersion;
145
- constructor(baseUrl, options) {
146
- this.baseUrl = baseUrl.replace(/\/$/, "");
147
- this.omitApiVersion = options?.omitApiVersion ?? false;
148
- }
149
- async buildUrl(endpoint, whiteLabelId) {
150
- const wlPath = this.omitApiVersion ? `/${this.apiLocale}/${whiteLabelId}` : `/${this.apiVersion}/${this.apiLocale}/${whiteLabelId}`;
151
- const path = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
152
- const url = `${this.baseUrl}${wlPath}${path}`;
153
- console.log("[ApiClient] buildUrl", {
154
- baseURL: this.baseUrl,
155
- whiteLabelId,
156
- endpoint,
157
- fullUrl: url
158
- });
159
- return url;
160
- }
161
- async getDefaultHeaders(token, isFormData = false) {
162
- console.log("[ApiClient] getDefaultHeaders", {
163
- token: token.substring(0, 20) + "..."
164
- });
165
- const headers4 = {
166
- authorization: token
167
- };
168
- if (!isFormData) {
169
- headers4["Content-Type"] = "application/json";
170
- }
171
- return headers4;
172
- }
173
- async request(endpoint, config = {}) {
174
- console.log("[ApiClient] request called", { endpoint, method: config.method });
175
- const { timeout = 3e4, responseType = "json", ...fetchConfig } = config;
176
- const controller = new AbortController();
177
- const timeoutId = setTimeout(() => controller.abort(), timeout);
178
- try {
179
- console.log("[ApiClient] Building URL and headers...");
180
- const { id, token } = await findWhitelabel();
181
- const [url, defaultHeaders] = await Promise.all([
182
- this.buildUrl(endpoint, id),
183
- this.getDefaultHeaders(token, fetchConfig.body instanceof FormData)
184
- ]);
185
- console.log("[ApiClient] Fetching", {
186
- url,
187
- method: fetchConfig.method,
188
- headers: defaultHeaders
189
- });
190
- const response = await fetch(url, {
191
- ...fetchConfig,
192
- headers: {
193
- ...defaultHeaders,
194
- ...fetchConfig.headers
195
- },
196
- signal: controller.signal
197
- });
198
- console.log("[ApiClient] Response received", { status: response.status, ok: response.ok });
199
- if (!response.ok) {
200
- const errBody = await response.text();
201
- let message = `HTTP error ${response.status}`;
202
- let code = "HTTP_ERROR";
203
- try {
204
- const errorData = JSON.parse(errBody);
205
- if (typeof errorData.message === "string") message = errorData.message;
206
- if (typeof errorData.code === "string") code = errorData.code;
207
- } catch {
208
- if (errBody.trim()) message = errBody.trim();
209
- }
210
- console.error("[ApiClient] Request failed", { status: response.status, message });
211
- throw new ApiError(message, code, response.status);
212
- }
213
- if (responseType === "text") {
214
- return await response.text();
215
- }
216
- const data = await response.json();
217
- console.log("[ApiClient] Request successful", { hasData: !!data });
218
- return data;
219
- } catch (error) {
220
- console.error("[ApiClient] Request error", { error });
221
- if (error instanceof ApiError) {
222
- throw error;
223
- }
224
- if (error instanceof Error) {
225
- if (error.name === "AbortError") {
226
- throw new ApiError("Tempo de requisi\xE7\xE3o excedido", "TIMEOUT", 408);
227
- }
228
- throw new ApiError(error.message, "NETWORK_ERROR", 0);
229
- }
230
- throw new ApiError("Erro desconhecido", "UNKNOWN_ERROR", 500);
231
- } finally {
232
- clearTimeout(timeoutId);
233
- }
234
- }
235
- async get(endpoint, config) {
236
- return this.request(endpoint, { ...config, method: "GET" });
237
- }
238
- async post(endpoint, data, config) {
239
- return this.request(endpoint, {
240
- ...config,
241
- method: "POST",
242
- body: data instanceof FormData ? data : data ? JSON.stringify(data) : void 0
243
- });
244
- }
245
- async put(endpoint, data, config) {
246
- return this.request(endpoint, {
247
- ...config,
248
- method: "PUT",
249
- body: data instanceof FormData ? data : data ? JSON.stringify(data) : void 0
250
- });
251
- }
252
- async patch(endpoint, data, config) {
253
- return this.request(endpoint, {
254
- ...config,
255
- method: "PATCH",
256
- body: data instanceof FormData ? data : data ? JSON.stringify(data) : void 0
257
- });
258
- }
259
- async delete(endpoint, config) {
260
- return this.request(endpoint, { ...config, method: "DELETE" });
261
- }
262
- };
263
- api = {
264
- apps: new ApiClient(process.env.GAPPS_R3_API_URL || "https://r3-api.greatapps.dev.br"),
265
- pages: new ApiClient(process.env.GPAGES_R3_API_URL || "https://r3-api.greatpages.dev.br")
266
- };
267
- apiClient = api.apps;
268
- }
269
- });
270
-
271
- // src/modules/users/services/user.service.ts
272
- var user_service_exports = {};
273
- __export(user_service_exports, {
274
- userService: () => userService
275
- });
276
- import { cookies } from "next/headers";
277
- var AUTH_COOKIE_NAME, API_BASE_URL, UserService, userService;
278
- var init_user_service = __esm({
279
- "src/modules/users/services/user.service.ts"() {
280
- "use strict";
281
- init_types();
282
- init_find_whitelabel_action();
283
- AUTH_COOKIE_NAME = "greatapps";
284
- API_BASE_URL = process.env.GAPPS_R3_API_URL || "https://r3-api.greatapps.dev.br";
285
- UserService = class {
286
- async getAuthToken() {
287
- if (process.env.DUMMY_AUTH_TOKEN) return process.env.DUMMY_AUTH_TOKEN;
288
- const cookieStore = await cookies();
289
- const token = cookieStore.get(AUTH_COOKIE_NAME)?.value;
290
- if (!token) {
291
- throw new ApiError("N\xE3o autenticado", "NOT_AUTHENTICATED_GAT", 401);
292
- }
293
- return token;
294
- }
295
- decodeJWT(token) {
296
- try {
297
- return JSON.parse(atob(token.split(".")[1]));
298
- } catch {
299
- throw new ApiError("Token inv\xE1lido", "INVALID_TOKEN", 401);
300
- }
301
- }
302
- async findById() {
303
- const token = await this.getAuthToken();
304
- const payload = this.decodeJWT(token);
305
- const { id_wl, id_account, id_user } = payload;
306
- const { token: wlToken } = await findWhitelabel();
307
- const url = `${API_BASE_URL}/v1/pt-br/${id_wl}/accounts/${id_account}/users/${id_user}`;
308
- const response = await fetch(url, {
309
- method: "GET",
310
- headers: {
311
- "Content-Type": "application/json",
312
- authorization: wlToken
313
- }
314
- });
315
- if (!response.ok) {
316
- throw new ApiError("Erro ao buscar dados do usu\xE1rio", "FETCH_ERROR", response.status);
317
- }
318
- const data = await response.json();
319
- if (data.status === 0 || !data.data || data.data.length === 0) {
320
- throw new ApiError("Dados do usu\xE1rio n\xE3o encontrados", "USER_NOT_FOUND", 404);
321
- }
322
- return data.data[0];
323
- }
324
- };
325
- userService = new UserService();
326
- }
327
- });
328
-
329
- // src/infra/utils/params.ts
330
- function buildQueryParams(params) {
331
- if (!params) {
332
- return "";
333
- }
334
- const queryParams = new URLSearchParams();
335
- for (const [key, value] of Object.entries(params)) {
336
- if (value === null || value === void 0 || value === "") {
337
- continue;
338
- }
339
- if (Array.isArray(value)) {
340
- queryParams.set(key, value.join(","));
341
- } else {
342
- queryParams.set(key, value.toString());
343
- }
344
- }
345
- return queryParams.toString();
346
- }
347
- var init_params = __esm({
348
- "src/infra/utils/params.ts"() {
349
- "use strict";
350
- }
351
- });
352
-
353
- // src/modules/auth/utils/get-user-context.ts
354
- import "server-only";
355
- import { cookies as cookies2 } from "next/headers";
356
- async function getUserContext() {
357
- const cookieStore = await cookies2();
358
- const token = process.env.DUMMY_AUTH_TOKEN || cookieStore.get(AUTH_COOKIE_NAME2)?.value;
359
- if (!token) {
360
- throw new ApiError("Usu\xE1rio n\xE3o autenticado", "NOT_AUTHENTICATED_GUC", 401);
361
- }
362
- try {
363
- const payload = JSON.parse(atob(token.split(".")[1]));
364
- return {
365
- id_account: payload.id_account,
366
- id_user: payload.id_user
367
- };
368
- } catch {
369
- throw new ApiError("Token inv\xE1lido", "INVALID_TOKEN", 401);
370
- }
371
- }
372
- var AUTH_COOKIE_NAME2;
373
- var init_get_user_context = __esm({
374
- "src/modules/auth/utils/get-user-context.ts"() {
375
- "use strict";
376
- init_types();
377
- AUTH_COOKIE_NAME2 = "greatapps";
378
- }
379
- });
380
-
381
- // src/utils/file/index.ts
382
- var fileToBase64;
383
- var init_file = __esm({
384
- "src/utils/file/index.ts"() {
385
- "use strict";
386
- fileToBase64 = async (file) => {
387
- const buffer = Buffer.from(await file.arrayBuffer());
388
- const mimeType = file.type || "application/octet-stream";
389
- return `data:${mimeType};base64,${buffer.toString("base64")}`;
390
- };
391
- }
392
- });
393
-
394
- // src/modules/accounts/services/account.service.ts
395
- var account_service_exports = {};
396
- __export(account_service_exports, {
397
- accountService: () => accountService
398
- });
399
- import "server-only";
400
- var AccountService, accountService;
401
- var init_account_service = __esm({
402
- "src/modules/accounts/services/account.service.ts"() {
403
- "use strict";
404
- init_client();
405
- init_types();
406
- init_params();
407
- init_get_user_context();
408
- init_file();
409
- AccountService = class {
410
- async findCurrentAccount() {
411
- const { id_account } = await getUserContext();
412
- const response = await api.apps.get(`/accounts/${id_account}`);
413
- if (response.status === 0 || !response.data?.[0]) {
414
- throw new ApiError(
415
- response.message || "Erro ao buscar dados da conta",
416
- "GET_ACCOUNT_FAILED",
417
- 400
418
- );
419
- }
420
- return response.data[0];
421
- }
422
- async listAccountUsers(params) {
423
- const { id_account } = await getUserContext();
424
- const queryParams = buildQueryParams(params);
425
- const endpoint = `/accounts/${id_account}/users?${queryParams}`;
426
- const response = await api.apps.get(endpoint);
427
- if (response.status === 0) {
428
- throw new ApiError(
429
- response.message || "Erro ao listar usu\xE1rios",
430
- "LIST_ACCOUNT_USERS_FAILED",
431
- 400
432
- );
433
- }
434
- return {
435
- users: response.data || [],
436
- total: response.total || 0
437
- };
438
- }
439
- async changeUserPhoto(userId, photo) {
440
- const { id_account } = await getUserContext();
441
- const base64 = await fileToBase64(photo);
442
- const response = await api.apps.put(
443
- `/accounts/${id_account}/users/${userId}/file/photo`,
444
- { file: base64 }
445
- );
446
- if (response.status === 0) {
447
- throw new ApiError(
448
- response.message || "Erro ao mudar foto do usu\xE1rio",
449
- "CHANGE_USER_PHOTO_FAILED",
450
- 400
451
- );
452
- }
453
- return response;
454
- }
455
- async deleteAccountUser(userId) {
456
- const { id_account } = await getUserContext();
457
- const response = await api.apps.delete(
458
- `/accounts/${id_account}/users/${userId}`
459
- );
460
- if (response.status === 0) {
461
- throw new ApiError(response.message || "Erro ao deletar usu\xE1rio", "DELETE_USER_FAILED", 400);
462
- }
463
- return response;
464
- }
465
- async deleteAccount() {
466
- const { id_account } = await getUserContext();
467
- const response = await api.apps.delete(`/accounts/${id_account}`);
468
- if (response.status === 0) {
469
- throw new ApiError(response.message || "Erro ao deletar conta", "DELETE_ACCOUNT_FAILED", 400);
470
- }
471
- return response;
472
- }
473
- async createAccountUser(user) {
474
- const { id_account } = await getUserContext();
475
- const response = await api.apps.post(
476
- `/accounts/${id_account}/users`,
477
- {
478
- ...user,
479
- photo: user.photo ? await fileToBase64(user.photo) : null
480
- }
481
- );
482
- if (response.status === 0) {
483
- throw new ApiError(response.message || "Erro ao criar usu\xE1rio", "CREATE_USER_FAILED", 400);
484
- }
485
- return response;
486
- }
487
- async resolvePhotoField(user) {
488
- if (user.photo === void 0) return {};
489
- const photo = user.photo != null && typeof user.photo !== "string" ? await fileToBase64(user.photo) : user.photo;
490
- return { photo };
491
- }
492
- async updateAccountUser(user) {
493
- const { id_account, id_user } = await getUserContext();
494
- const response = await api.apps.put(
495
- `/accounts/${id_account}/users/${id_user}`,
496
- { ...user, ...await this.resolvePhotoField(user) }
497
- );
498
- if (response.status === 0) {
499
- throw new ApiError(
500
- response.message || "Erro ao atualizar usu\xE1rio",
501
- "UPDATE_USER_FAILED",
502
- 400
503
- );
504
- }
505
- return response;
506
- }
507
- async updateAccountUserById(userId, user) {
508
- const { id_account } = await getUserContext();
509
- const response = await api.apps.put(
510
- `/accounts/${id_account}/users/${userId}`,
511
- { ...user, ...await this.resolvePhotoField(user) }
512
- );
513
- if (response.status === 0) {
514
- throw new ApiError(
515
- response.message || "Erro ao atualizar usu\xE1rio",
516
- "UPDATE_USER_FAILED",
517
- 400
518
- );
519
- }
520
- return response;
521
- }
522
- async updateAccount(data) {
523
- const { id_account } = await getUserContext();
524
- const response = await api.apps.put(`/accounts/${id_account}`, data);
525
- if (response.status === 0) {
526
- throw new ApiError(
527
- response.message || "Erro ao atualizar conta",
528
- "UPDATE_ACCOUNT_FAILED",
529
- 400
530
- );
531
- }
532
- return response;
533
- }
534
- async requestContactReset(type, newContact) {
535
- const { id_account, id_user } = await getUserContext();
536
- const response = await api.apps.post(
537
- `/accounts/${id_account}/users/${id_user}/resetContact/request`,
538
- { type, newContact }
539
- );
540
- if (response.status === 0) {
541
- throw new ApiError(
542
- response.message || "Erro ao solicitar altera\xE7\xE3o",
543
- "REQUEST_CONTACT_RESET_FAILED",
544
- 400
545
- );
546
- }
547
- }
548
- async confirmContactReset(type, token, newContact) {
549
- const { id_account, id_user } = await getUserContext();
550
- const response = await api.apps.post(
551
- `/accounts/${id_account}/users/${id_user}/resetContact/confirm`,
552
- { type, token, newContact }
553
- );
554
- if (response.status === 0) {
555
- throw new ApiError(
556
- response.message || "C\xF3digo inv\xE1lido ou expirado",
557
- "CONFIRM_CONTACT_RESET_FAILED",
558
- 400
559
- );
560
- }
561
- }
562
- async changePassword(data) {
563
- const { id_account, id_user } = await getUserContext();
564
- const response = await api.apps.put(
565
- `/accounts/${id_account}/users/${id_user}/action/changePassword`,
566
- data
567
- );
568
- if (response.status === 0) {
569
- throw new ApiError(
570
- response.message || "Erro ao alterar senha",
571
- "CHANGE_PASSWORD_FAILED",
572
- 400
573
- );
574
- }
575
- return response;
576
- }
577
- };
578
- accountService = new AccountService();
579
- }
580
- });
581
-
582
- // src/server.ts
583
- init_client();
584
- import "server-only";
585
-
586
- // src/modules/auth/services/auth.service.ts
587
- init_client();
588
- init_types();
589
- import { cookies as cookies3 } from "next/headers";
590
- var AUTH_COOKIE_NAME3 = "greatapps";
591
- var COOKIE_MAX_AGE = 60 * 60 * 24 * 30;
592
- var COOKIE_OPTIONS = {
593
- httpOnly: true,
594
- secure: process.env.NODE_ENV === "production",
595
- sameSite: "lax",
596
- path: "/",
597
- domain: process.env.DOMAIN_COOKIE
598
- };
599
- var AuthService = class {
600
- async login(credentials, clientInfo) {
601
- const response = await api.apps.post("/auth/login", {
602
- email: credentials.email,
603
- password: credentials.password,
604
- location: clientInfo.location,
605
- ip: clientInfo.ip,
606
- timezone: clientInfo.timezone,
607
- agent: clientInfo.agent
608
- });
609
- console.log("[AuthService.login] response", JSON.stringify(response));
610
- if (response.status === 0) {
611
- throw new ApiError(
612
- response.message || "E-mail ou senha incorretos",
613
- response.code || "LOGIN_FAILED",
614
- 401
615
- );
616
- }
617
- if (!response.cookie) {
618
- throw new ApiError(
619
- "Resposta de autentica\xE7\xE3o inv\xE1lida",
620
- "INVALID_RESPONSE",
621
- 500
622
- );
623
- }
624
- if (response.two_factor_required) {
625
- return { result: "two_factor_required", cookie: response.cookie };
626
- }
627
- await this.setAuthCookie(response.cookie);
628
- const [{ userService: userService2 }, { accountService: accountService2 }] = await Promise.all([
629
- Promise.resolve().then(() => (init_user_service(), user_service_exports)),
630
- Promise.resolve().then(() => (init_account_service(), account_service_exports))
631
- ]);
632
- const [user, account] = await Promise.all([
633
- userService2.findById(),
634
- accountService2.findCurrentAccount()
635
- ]);
636
- return {
637
- result: "success",
638
- user,
639
- account,
640
- accessToken: response.cookie,
641
- refreshToken: "",
642
- expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1e3).toISOString()
643
- };
644
- }
645
- async verifyTwoFactor(cookie, code, clientInfo) {
646
- const payload = {
647
- location: clientInfo.location,
648
- ip: clientInfo.ip,
649
- timezone: clientInfo.timezone,
650
- agent: clientInfo.agent,
651
- cookie,
652
- code
653
- };
654
- const response = await api.apps.post(
655
- "/auth/code",
656
- payload
657
- );
658
- if (response.status === 0) {
659
- throw new ApiError("C\xF3digo 2FA inv\xE1lido", "TWO_FACTOR_FAILED", 401);
660
- }
661
- if (!response?.data?.cookie) {
662
- throw new ApiError(
663
- "Resposta de autentica\xE7\xE3o inv\xE1lida ap\xF3s 2FA",
664
- "INVALID_RESPONSE",
665
- 500
666
- );
667
- }
668
- await this.setAuthCookie(response.data.cookie);
669
- return { status: 1 };
670
- }
671
- async register(data, _clientInfo) {
672
- const today = /* @__PURE__ */ new Date();
673
- const trialEndDate = new Date(today);
674
- trialEndDate.setDate(today.getDate() + 7);
675
- const payload = {
676
- name: data.accountName,
677
- bussiness_type: data.businessType,
678
- language: "pt-br",
679
- timezone: "America/Sao_Paulo",
680
- currency: "BRL",
681
- user: {
682
- id_api: "",
683
- name: data.name,
684
- last_name: data.lastName || "",
685
- rg: data.rg || "",
686
- cpf: data.cpf || "",
687
- gender: data.gender,
688
- email: data.email,
689
- phone: data.phone,
690
- password: data.password,
691
- profile: "owner",
692
- language: "pt-br"
693
- },
694
- subscription: {
695
- type: "trial",
696
- id_cupom: data.couponCode || "",
697
- id_plan: data.idPlan || 1,
698
- due_date: trialEndDate.toISOString().split("T")[0],
699
- id_product: 1
700
- }
701
- };
702
- const response = await api.apps.post(
703
- "/accounts",
704
- payload
705
- );
706
- if (response.status === 0) {
707
- throw new ApiError(
708
- response.message || "Erro ao criar conta",
709
- "REGISTER_FAILED",
710
- 400
711
- );
712
- }
713
- if (!response.data || response.data.length === 0) {
714
- throw new ApiError(
715
- "Resposta de registro inv\xE1lida",
716
- "INVALID_RESPONSE",
717
- 500
718
- );
719
- }
720
- if (!response.cookie) {
721
- throw new ApiError(
722
- "Resposta de autentica\xE7\xE3o inv\xE1lida",
723
- "INVALID_RESPONSE",
724
- 500
725
- );
726
- }
727
- const accountData = response.data[0];
728
- await this.setAuthCookie(response.cookie);
729
- const [{ userService: userService2 }, { accountService: accountService2 }] = await Promise.all([
730
- Promise.resolve().then(() => (init_user_service(), user_service_exports)),
731
- Promise.resolve().then(() => (init_account_service(), account_service_exports))
732
- ]);
733
- const [user, account] = await Promise.all([
734
- userService2.findById(),
735
- accountService2.findCurrentAccount()
736
- ]);
737
- return {
738
- user,
739
- account,
740
- accessToken: response.cookie,
741
- refreshToken: "",
742
- expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1e3).toISOString(),
743
- requiresEmailVerification: !accountData.verified
744
- };
745
- }
746
- async logout(clientInfo) {
747
- const cookie = await this.getToken();
748
- if (!cookie) {
749
- throw new ApiError(
750
- "Usu\xE1rio n\xE3o autenticado",
751
- "NOT_AUTHENTICATED_LOGOUT",
752
- 401
753
- );
754
- }
755
- const payload = {
756
- location: clientInfo.location,
757
- ip: clientInfo.ip,
758
- timezone: clientInfo.timezone,
759
- agent: clientInfo.agent,
760
- cookie
761
- };
762
- try {
763
- const response = await api.apps.post(
764
- "/auth/logout",
765
- payload
766
- );
767
- if (response.status === 0) {
768
- throw new ApiError(
769
- response.message || "Erro ao realizar logout",
770
- response.code || "LOGOUT_FAILED",
771
- 400
772
- );
773
- }
774
- } finally {
775
- await this.removeAuthCookie();
776
- }
777
- return {
778
- success: true
779
- };
780
- }
781
- async forgotPassword(_data) {
782
- throw new ApiError(
783
- "Recupera\xE7\xE3o de senha n\xE3o implementada",
784
- "NOT_IMPLEMENTED",
785
- 501
786
- );
787
- }
788
- async resetPassword(_data) {
789
- throw new ApiError(
790
- "Redefini\xE7\xE3o de senha n\xE3o implementada",
791
- "NOT_IMPLEMENTED",
792
- 501
793
- );
794
- }
795
- async verifyEmail(_data) {
796
- throw new ApiError(
797
- "Verifica\xE7\xE3o de email n\xE3o implementada",
798
- "NOT_IMPLEMENTED",
799
- 501
800
- );
801
- }
802
- async resendVerification(_data) {
803
- throw new ApiError(
804
- "Reenvio de verifica\xE7\xE3o n\xE3o implementado",
805
- "NOT_IMPLEMENTED",
806
- 501
807
- );
808
- }
809
- async validateSession(clientInfo) {
810
- const cookie = await this.getToken();
811
- if (!cookie) {
812
- return false;
813
- }
814
- try {
815
- const payload = {
816
- location: clientInfo.location,
817
- ip: clientInfo.ip,
818
- timezone: clientInfo.timezone,
819
- agent: clientInfo.agent,
820
- cookie
821
- };
822
- const response = await api.apps.post(
823
- "/auth/keep",
824
- payload
825
- );
826
- return response.status === 1;
827
- } catch (error) {
828
- console.error("[AuthService] validateSession error", error);
829
- return false;
830
- }
831
- }
832
- async isAuthenticated() {
833
- const token = await this.getToken();
834
- return !!token;
835
- }
836
- async getToken() {
837
- if (process.env.DUMMY_AUTH_TOKEN) return process.env.DUMMY_AUTH_TOKEN;
838
- const cookieStore = await cookies3();
839
- return cookieStore.get(AUTH_COOKIE_NAME3)?.value;
840
- }
841
- async setAuthCookie(token) {
842
- const cookieStore = await cookies3();
843
- cookieStore.set(AUTH_COOKIE_NAME3, token, {
844
- ...COOKIE_OPTIONS,
845
- maxAge: COOKIE_MAX_AGE
846
- });
847
- }
848
- async removeAuthCookie() {
849
- const cookieStore = await cookies3();
850
- cookieStore.delete({
851
- name: AUTH_COOKIE_NAME3,
852
- ...COOKIE_OPTIONS
853
- });
854
- }
855
- };
856
- var authService = new AuthService();
857
-
858
- // src/server.ts
859
- init_whitelabel_service();
860
-
861
- // src/modules/whitelabel/services/whitelabel-styles.service.ts
862
- init_types();
863
- import greatCache2 from "@greatapps/cache";
864
- function parseStyleField(value) {
865
- if (typeof value === "string") {
866
- try {
867
- return JSON.parse(value);
868
- } catch {
869
- return null;
870
- }
871
- }
872
- if (value && typeof value === "object") return value;
873
- return null;
874
- }
875
- function mapWithStyleResponse(row) {
876
- return {
877
- id: row["style_id"],
878
- id_wl: row["style_id_wl"],
879
- general: parseStyleField(row["style_general"]),
880
- signin_page: parseStyleField(row["style_signin_page"]),
881
- signup_page: parseStyleField(row["style_signup_page"]),
882
- dashboard: parseStyleField(row["style_dashboard"])
883
- };
884
- }
885
- var WhitelabelStylesService = class {
886
- getApiUrl() {
887
- const apiUrl = process.env.GAPPS_R3_API_URL;
888
- if (!apiUrl) throw new ApiError("GAPPS_R3_API_URL not configured", "CONFIG_ERROR", 500);
889
- return apiUrl;
890
- }
891
- getToken() {
892
- const token = process.env.WHITELABEL_TOKEN_MASTER;
893
- if (!token) throw new ApiError("WHITELABEL_TOKEN_MASTER not configured", "CONFIG_ERROR", 500);
894
- return token;
895
- }
896
- async getByWlId(id_wl) {
897
- const apiUrl = this.getApiUrl();
898
- const token = this.getToken();
899
- const url = `${apiUrl}/v1/pt-br/1/whitelabels/${id_wl}/with-style`;
900
- console.log("[WhitelabelStylesService] Fetching with-style for id_wl", { id_wl, url });
901
- const cache3 = new greatCache2({
902
- service: "whitelabel-styles-service",
903
- version: "1.0",
904
- domain: "whitelabel-cache.greatapps.com.br",
905
- ambient: process.env.NODE_ENV || "development"
906
- });
907
- const cacheKey = `whitelabel-styles-${id_wl}`;
908
- const cachedData = await cache3.select(cacheKey);
909
- if (cachedData.status == 1 && "data" in cachedData && cachedData.data) {
910
- console.log("[WhitelabelStylesService] Cache hit for id_wl", { id_wl });
911
- return JSON.parse(cachedData.data);
912
- }
913
- const response = await fetch(url, {
914
- method: "GET",
915
- headers: { authorization: token }
916
- });
917
- if (!response.ok) {
918
- console.error("[WhitelabelStylesService] Failed to fetch with-style", { status: response.status });
919
- return null;
920
- }
921
- const result = await response.json();
922
- if (result.status !== 1 || !result.data?.length) {
923
- console.warn("[WhitelabelStylesService] No data in with-style for id_wl", { id_wl });
924
- return null;
925
- }
926
- const parsed = mapWithStyleResponse(result.data[0]);
927
- if (parsed.id) {
928
- await cache3.insert(cacheKey, JSON.stringify(parsed), 300);
929
- }
930
- return parsed;
931
- }
932
- };
933
- var whitelabelStylesService = new WhitelabelStylesService();
934
-
935
- // src/modules/whitelabel/actions/find-whitelabel-styles.action.ts
936
- import { cache as cache2 } from "react";
937
- var findWhitelabelStyles = cache2(async (id_wl) => {
938
- try {
939
- return await whitelabelStylesService.getByWlId(id_wl);
940
- } catch (error) {
941
- console.error("[findWhitelabelStyles] Error fetching styles:", error);
942
- return null;
943
- }
944
- });
945
-
946
- // src/modules/subscriptions/services/subscriptions.service.ts
947
- init_client();
948
- init_types();
949
- init_params();
950
- init_get_user_context();
951
1
  import "server-only";
952
-
953
- // src/modules/subscriptions/types.ts
954
- import z2 from "zod";
955
- var SubscriptionItemSchema = z2.object({
956
- id: z2.union([z2.number(), z2.string()]),
957
- deleted: z2.number(),
958
- datetime_alt: z2.coerce.date().nullable().optional(),
959
- datetime_del: z2.coerce.date().nullable().optional(),
960
- datetime_add: z2.coerce.date(),
961
- id_wl: z2.number(),
962
- id_subscription: z2.union([z2.number(), z2.string()]),
963
- id_addon: z2.number().nullable(),
964
- addon_name: z2.string().optional(),
965
- value: z2.number(),
966
- currency: z2.string(),
967
- quantity: z2.number(),
968
- payment_status: z2.number(),
969
- id_charge: z2.union([z2.number(), z2.string()]).nullable(),
970
- trial: z2.boolean(),
971
- trial_ends_at: z2.coerce.date().nullable().optional()
972
- });
973
- var SubscriptionSchema = z2.object({
974
- id: z2.union([z2.number(), z2.string()]),
975
- deleted: z2.number(),
976
- datetime_alt: z2.coerce.date().nullable().optional(),
977
- datetime_del: z2.coerce.date().nullable().optional(),
978
- datetime_add: z2.coerce.date(),
979
- id_wl: z2.number(),
980
- id_account: z2.union([z2.number(), z2.string()]),
981
- id_card: z2.union([z2.number(), z2.string()]).nullable(),
982
- id_coupon: z2.union([z2.number(), z2.string()]).nullable(),
983
- type: z2.string(),
984
- payment_method: z2.number().nullable(),
985
- periodicity: z2.union([z2.number(), z2.string()]).nullable(),
986
- value: z2.number().nullable(),
987
- id_product: z2.number(),
988
- id_plan: z2.number(),
989
- plan_name: z2.string().nullable().optional(),
990
- id_gateway: z2.union([z2.number(), z2.string()]).nullable(),
991
- gateway_account: z2.string().nullable(),
992
- date_hiring: z2.coerce.date().nullable(),
993
- date_due: z2.coerce.date(),
994
- date_cancellation: z2.coerce.date().nullable(),
995
- date_verification: z2.coerce.date().nullable(),
996
- cancellation_reason: z2.string().nullable(),
997
- cancellation_description: z2.string().nullable(),
998
- active: z2.boolean(),
999
- charged: z2.boolean(),
1000
- datetime_last_update_periodicity: z2.coerce.date().nullable().optional(),
1001
- card_name: z2.string().nullable().optional(),
1002
- card_brand: z2.string().nullable().optional(),
1003
- card_number: z2.string().nullable().optional(),
1004
- items: z2.array(SubscriptionItemSchema)
1005
- });
1006
-
1007
- // src/modules/subscriptions/services/subscriptions.service.ts
1008
- var SubscriptionsService = class {
1009
- async listSubscriptions(params) {
1010
- const { id_account } = await getUserContext();
1011
- const query = buildQueryParams(params);
1012
- const url = `/accounts/${id_account}/subscriptions${query ? `?${query}` : ""}`;
1013
- const response = await api.apps.get(url);
1014
- if (response.status === 0) {
1015
- throw new ApiError(
1016
- response.message || "Erro ao listar assinaturas",
1017
- "LIST_SUBSCRIPTIONS_FAILED",
1018
- 400
1019
- );
1020
- }
1021
- const data = response.data.map((item) => SubscriptionSchema.parse(item));
1022
- return {
1023
- data,
1024
- total: response.total,
1025
- success: true
1026
- };
1027
- }
1028
- };
1029
- var subscriptionsService = new SubscriptionsService();
1030
-
1031
- // src/modules/ia-credits/services/ia-credits.service.ts
1032
- init_client();
1033
- init_types();
1034
- init_get_user_context();
1035
- import "server-only";
1036
-
1037
- // src/modules/ia-credits/types.ts
1038
- import z3 from "zod";
1039
- var IaCreditOperationSchema = z3.object({
1040
- id: z3.union([z3.number(), z3.string()]),
1041
- deleted: z3.number(),
1042
- datetime_add: z3.coerce.date().nullable(),
1043
- id_wl: z3.number(),
1044
- id_subscription: z3.union([z3.number(), z3.string()]),
1045
- id_addon: z3.number(),
1046
- operation: z3.string(),
1047
- // 'add' | 'subtract'
1048
- operation_value: z3.union([z3.number(), z3.string()]).transform((v) => Number(v)),
1049
- balance_after_operation: z3.union([z3.number(), z3.string()]).optional(),
1050
- balance_before_operation: z3.union([z3.number(), z3.string()]).optional(),
1051
- operation_ref: z3.string().nullable().optional(),
1052
- operation_origin: z3.string().nullable().optional(),
1053
- expiration_time: z3.string().nullable(),
1054
- has_expired: z3.boolean(),
1055
- consumed_from_add_id: z3.union([z3.number(), z3.string()]).nullable(),
1056
- id_user_add: z3.union([z3.number(), z3.string()]).nullable(),
1057
- user_name: z3.string().nullable().optional()
1058
- }).passthrough();
1059
-
1060
- // src/modules/ia-credits/services/ia-credits.service.ts
1061
- var IaCreditsService = class {
1062
- async listOperations(subscriptionId) {
1063
- const { id_account } = await getUserContext();
1064
- const endpoint = `/accounts/${id_account}/subscriptions/${subscriptionId}/items/balance/list?page=1&limit=20&sort=id:DESC`;
1065
- const response = await api.apps.get(endpoint);
1066
- if (response.status === 0) {
1067
- throw new ApiError(
1068
- response.message || "Erro ao listar cr\xE9ditos de IA",
1069
- "LIST_IA_CREDITS_FAILED",
1070
- 400
1071
- );
1072
- }
1073
- const raw = response.data ?? [];
1074
- const data = raw.map((item) => IaCreditOperationSchema.parse(item));
1075
- return {
1076
- data,
1077
- total: response.total ?? data.length,
1078
- success: true
1079
- };
1080
- }
1081
- };
1082
- var iaCreditsService = new IaCreditsService();
1083
-
1084
- // src/server.ts
1085
- init_find_whitelabel_action();
1086
-
1087
- // src/modules/auth/actions/validate-session.action.ts
1088
- import { redirect } from "next/navigation";
1089
- import { cookies as cookies4, headers as headers3 } from "next/headers";
1090
-
1091
- // src/infra/utils/client-info.ts
1092
- import { headers as headers2 } from "next/headers";
1093
- async function getClientInfoFromRequest(request) {
1094
- let headerStore;
1095
- if (request) {
1096
- headerStore = request.headers;
1097
- } else {
1098
- const nextHeaders = await headers2();
1099
- headerStore = nextHeaders;
1100
- }
1101
- return {
1102
- location: {
1103
- continent: headerStore.get("cf-ipcountry") || headerStore.get("x-vercel-ip-country") || "Unknown",
1104
- country: headerStore.get("x-vercel-ip-country") || "Unknown",
1105
- region: headerStore.get("x-vercel-ip-country-region") || "Unknown",
1106
- city: headerStore.get("x-vercel-ip-city") || "Unknown",
1107
- latitude: headerStore.get("x-vercel-ip-latitude") || "0",
1108
- longitude: headerStore.get("x-vercel-ip-longitude") || "0"
1109
- },
1110
- ip: headerStore.get("cf-connecting-ip") || headerStore.get("x-forwarded-for") || headerStore.get("x-real-ip") || "Unknown",
1111
- timezone: headerStore.get("cf-timezone") || "America/Sao_Paulo",
1112
- agent: headerStore.get("user-agent") || "Unknown"
1113
- };
1114
- }
1115
-
1116
- // src/modules/auth/actions/validate-session.action.ts
1117
- async function redirectToLogin() {
1118
- const h = await headers3();
1119
- const referer = h.get("referer") || "/";
1120
- if (!referer) {
1121
- redirect("/login");
1122
- return;
1123
- }
1124
- const url = new URL(referer);
1125
- if (["/login", "/register", "/forgot-password"].includes(url.pathname)) {
1126
- return;
1127
- }
1128
- redirect("/login");
1129
- }
1130
- async function validateSessionAction() {
1131
- if (process.env.DUMMY_AUTH_TOKEN) return true;
1132
- const cookieStore = await cookies4();
1133
- const cookie = cookieStore.get("greatapps")?.value;
1134
- if (!cookie) {
1135
- await redirectToLogin();
1136
- return false;
1137
- }
1138
- try {
1139
- const clientInfo = await getClientInfoFromRequest();
1140
- const isValid = await authService.validateSession(clientInfo);
1141
- if (!isValid) {
1142
- await authService.removeAuthCookie();
1143
- await redirectToLogin();
1144
- return false;
1145
- }
1146
- return true;
1147
- } catch (error) {
1148
- console.error("[validateSessionAction] Error:", error);
1149
- await authService.removeAuthCookie();
1150
- await redirectToLogin();
1151
- return false;
1152
- }
1153
- }
1154
-
1155
- // src/utils/safeServerAction.ts
1156
- init_types();
1157
- import { isRedirectError } from "next/dist/client/components/redirect-error";
1158
- async function safeServerAction(fn) {
1159
- try {
1160
- const data = await fn();
1161
- return { success: true, data };
1162
- } catch (error) {
1163
- if (isRedirectError(error)) throw error;
1164
- const message = error instanceof ApiError ? error.message : error instanceof Error ? error.message : "Erro desconhecido";
1165
- return { success: false, error: message };
1166
- }
1167
- }
1168
-
1169
- // src/modules/users/action/find-user-by-id.action.ts
1170
- init_user_service();
1171
- async function findUserById() {
1172
- return safeServerAction(() => userService.findById());
1173
- }
1174
-
1175
- // src/modules/accounts/actions/find-current-account.action.ts
1176
- init_account_service();
1177
- async function findCurrentAccount() {
1178
- return safeServerAction(() => accountService.findCurrentAccount());
1179
- }
1180
-
1181
- // src/modules/subscriptions/actions/list-subscriptions.action.ts
1182
- async function listSubscriptionsAction(params) {
1183
- return safeServerAction(() => subscriptionsService.listSubscriptions(params));
1184
- }
1185
-
1186
- // src/modules/ia-credits/actions/list-ia-credits.action.ts
1187
- async function listIaCreditsAction(subscriptionId) {
1188
- return safeServerAction(() => iaCreditsService.listOperations(subscriptionId));
1189
- }
1190
-
1191
- // src/modules/projects/services/project-users.service.ts
1192
- init_client();
1193
- init_types();
1194
- init_params();
1195
- init_get_user_context();
1196
- import "server-only";
1197
-
1198
- // src/modules/projects/types.ts
1199
- import { z as z4 } from "zod";
1200
- var ProjectUserSchema = z4.object({
1201
- id_user: z4.union([z4.number(), z4.string()]).transform(Number),
1202
- id_account: z4.union([z4.number(), z4.string()]).transform(Number),
1203
- id_project: z4.union([z4.number(), z4.string()]).transform(Number),
1204
- name: z4.string().nullable(),
1205
- email: z4.string().nullable(),
1206
- profile: z4.string().nullable().optional().default("viewer"),
1207
- photo: z4.string().nullable().optional()
1208
- });
1209
- var AccountUserSchema = z4.object({
1210
- id: z4.union([z4.number(), z4.string()]).transform(Number),
1211
- name: z4.string().nullable(),
1212
- email: z4.string().nullable(),
1213
- profile: z4.string().nullable().optional().default("viewer"),
1214
- photo: z4.string().nullable().optional()
1215
- });
1216
-
1217
- // src/modules/projects/services/project-users.service.ts
1218
- var ProjectUsersService = class {
1219
- async listInProject(projectId, params = {}) {
1220
- const { id_account, id_user } = await getUserContext();
1221
- const query = buildQueryParams(params);
1222
- const url = `/account/${id_account}/user/${id_user}/projects/${projectId}/users${query ? `?${query}` : ""}`;
1223
- const response = await api.apps.get(url);
1224
- if (response.status === 0) {
1225
- throw new ApiError(
1226
- response.message || "Erro ao listar usu\xE1rios do projeto",
1227
- "LIST_PROJECT_USERS_FAILED",
1228
- 400
1229
- );
1230
- }
1231
- return {
1232
- data: response.data.map((item) => ProjectUserSchema.parse(item)),
1233
- total: response.total,
1234
- page: params.page ?? 1
1235
- };
1236
- }
1237
- async listNotInProject(projectId, params = {}) {
1238
- const { id_account } = await getUserContext();
1239
- const query = buildQueryParams({ notInProject: projectId, ...params });
1240
- const url = `/accounts/${id_account}/users${query ? `?${query}` : ""}`;
1241
- const response = await api.apps.get(url);
1242
- if (response.status === 0) {
1243
- throw new ApiError(
1244
- response.message || "Erro ao listar usu\xE1rios dispon\xEDveis",
1245
- "LIST_AVAILABLE_USERS_FAILED",
1246
- 400
1247
- );
1248
- }
1249
- return {
1250
- data: response.data.map((item) => AccountUserSchema.parse(item)),
1251
- total: response.total,
1252
- page: params.page ?? 1
1253
- };
1254
- }
1255
- async addToProject({ projectId, users }) {
1256
- const { id_account, id_user } = await getUserContext();
1257
- const url = `/account/${id_account}/user/${id_user}/projects/${projectId}/users`;
1258
- const response = await api.apps.post(url, { users });
1259
- if (response.status === 0) {
1260
- throw new ApiError(
1261
- response.message || "Erro ao adicionar usu\xE1rio ao projeto",
1262
- "ADD_PROJECT_USER_FAILED",
1263
- 400
1264
- );
1265
- }
1266
- }
1267
- async removeFromProject({ projectId, users }) {
1268
- const { id_account, id_user } = await getUserContext();
1269
- const url = `/account/${id_account}/user/${id_user}/projects/${projectId}/users`;
1270
- const response = await api.apps.delete(url, {
1271
- body: JSON.stringify({ users })
1272
- });
1273
- if (response.status === 0) {
1274
- throw new ApiError(
1275
- response.message || "Erro ao remover usu\xE1rio do projeto",
1276
- "REMOVE_PROJECT_USER_FAILED",
1277
- 400
1278
- );
1279
- }
1280
- }
1281
- };
1282
- var projectUsersService = new ProjectUsersService();
1283
-
1284
- // src/modules/projects/actions/list-project-users.action.ts
1285
- async function listProjectUsersAction(projectId, params = {}) {
1286
- return safeServerAction(() => projectUsersService.listInProject(projectId, params));
1287
- }
1288
-
1289
- // src/modules/projects/actions/list-available-users.action.ts
1290
- async function listAvailableUsersAction(projectId, params = {}) {
1291
- return safeServerAction(() => projectUsersService.listNotInProject(projectId, params));
1292
- }
1293
-
1294
- // src/modules/projects/actions/add-project-user.action.ts
1295
- async function addProjectUserAction(params) {
1296
- return safeServerAction(() => projectUsersService.addToProject(params));
1297
- }
1298
-
1299
- // src/modules/projects/actions/remove-project-user.action.ts
1300
- async function removeProjectUserAction(params) {
1301
- return safeServerAction(() => projectUsersService.removeFromProject(params));
1302
- }
1303
-
1304
- // src/server.ts
1305
- init_account_service();
1306
-
1307
- // src/modules/accounts/services/two-factor.service.ts
1308
- init_types();
1309
- init_get_user_context();
1310
- init_find_whitelabel_action();
1311
- import "server-only";
1312
- var TWO_FA_BASE_URL = process.env.R2_2FA_URL || "https://r2-2fa.greatapps.dev.br";
1313
- var TwoFactorService = class {
1314
- async request(path, body) {
1315
- const { id, token } = await findWhitelabel();
1316
- const { id_account, id_user } = await getUserContext();
1317
- const url = `${TWO_FA_BASE_URL}/v1/${id}/account/${id_account}/users/${id_user}/2fa/${path}`;
1318
- const response = await fetch(url, {
1319
- method: "POST",
1320
- headers: {
1321
- "Content-Type": "application/json",
1322
- authorization: token
1323
- },
1324
- body: body ? JSON.stringify(body) : void 0
1325
- });
1326
- if (!response.ok) {
1327
- const errorData = await response.json().catch(() => ({}));
1328
- throw new ApiError(
1329
- errorData.message || `HTTP error ${response.status}`,
1330
- "HTTP_ERROR",
1331
- response.status
1332
- );
1333
- }
1334
- return response.json();
1335
- }
1336
- async generate() {
1337
- const response = await this.request("generate");
1338
- if (response.status === 0) {
1339
- throw new ApiError(response.message || "Erro ao gerar QR Code", "GENERATE_2FA_FAILED", 400);
1340
- }
1341
- return response;
1342
- }
1343
- async confirm(code) {
1344
- const response = await this.request("confirm", { code });
1345
- if (response.status === 0) {
1346
- throw new ApiError(response.message || "C\xF3digo inv\xE1lido", "CONFIRM_2FA_FAILED", 400);
1347
- }
1348
- return response;
1349
- }
1350
- async verify(code) {
1351
- const response = await this.request("verify", { code });
1352
- if (response.status === 0) {
1353
- throw new ApiError(response.message || "C\xF3digo inv\xE1lido", "VERIFY_2FA_FAILED", 400);
1354
- }
1355
- return response;
1356
- }
1357
- async disable() {
1358
- const { id, token } = await findWhitelabel();
1359
- const { id_account, id_user } = await getUserContext();
1360
- const url = `${TWO_FA_BASE_URL}/v1/${id}/account/${id_account}/users/${id_user}/2fa`;
1361
- const response = await fetch(url, {
1362
- method: "DELETE",
1363
- headers: { authorization: token }
1364
- });
1365
- if (!response.ok) {
1366
- const errorData = await response.json().catch(() => ({}));
1367
- throw new ApiError(
1368
- errorData.message || `HTTP error ${response.status}`,
1369
- "HTTP_ERROR",
1370
- response.status
1371
- );
1372
- }
1373
- const data = await response.json();
1374
- if (data.status === 0) {
1375
- throw new ApiError(data.message || "Erro ao desabilitar 2FA", "DISABLE_2FA_FAILED", 400);
1376
- }
1377
- return data;
1378
- }
1379
- };
1380
- var twoFactorService = new TwoFactorService();
1381
-
1382
- // src/modules/accounts/actions/account-management.action.ts
1383
- init_account_service();
1384
- async function listAccountUsersAction(params) {
1385
- return safeServerAction(async () => {
1386
- const { users, total } = await accountService.listAccountUsers(params);
1387
- return { data: users, total };
1388
- });
1389
- }
1390
- async function updateUserAction(user) {
1391
- return safeServerAction(() => accountService.updateAccountUser(user));
1392
- }
1393
- async function updateAccountUserByIdAction(userId, user) {
1394
- return safeServerAction(() => accountService.updateAccountUserById(userId, user));
1395
- }
1396
- async function updateAccountAction(data) {
1397
- return safeServerAction(() => accountService.updateAccount(data));
1398
- }
1399
- async function deleteAccountUserAction(userId) {
1400
- return safeServerAction(() => accountService.deleteAccountUser(userId));
1401
- }
1402
- async function deleteAccountAction() {
1403
- return safeServerAction(() => accountService.deleteAccount());
1404
- }
1405
- async function createAccountUserAction(user) {
1406
- return safeServerAction(() => accountService.createAccountUser(user));
1407
- }
1408
- async function changePasswordAction(data) {
1409
- return safeServerAction(() => accountService.changePassword(data));
1410
- }
1411
- async function requestEmailChangeAction(newEmail) {
1412
- return safeServerAction(() => accountService.requestContactReset("email", newEmail));
1413
- }
1414
- async function confirmEmailChangeAction(token, newEmail) {
1415
- return safeServerAction(() => accountService.confirmContactReset("email", token, newEmail));
1416
- }
1417
- async function requestPhoneChangeAction(newPhone) {
1418
- return safeServerAction(() => accountService.requestContactReset("phone", newPhone));
1419
- }
1420
- async function confirmPhoneChangeAction(token, newPhone) {
1421
- return safeServerAction(() => accountService.confirmContactReset("phone", token, newPhone));
1422
- }
1423
- async function generateTwoFactorAction() {
1424
- return safeServerAction(async () => {
1425
- const result = await twoFactorService.generate();
1426
- return {
1427
- qrcode: result.data.qrcode,
1428
- backupCodes: result.data.backup_codes
1429
- };
1430
- });
1431
- }
1432
- async function confirmTwoFactorAction(code) {
1433
- return safeServerAction(async () => {
1434
- await twoFactorService.confirm(code);
1435
- await accountService.updateAccountUser({ two_factor_authentication: true });
1436
- });
1437
- }
1438
- async function disableTwoFactorAction(code) {
1439
- return safeServerAction(async () => {
1440
- await twoFactorService.verify(code);
1441
- await twoFactorService.disable();
1442
- });
1443
- }
1444
-
1445
- // src/server.ts
1446
- init_get_user_context();
2
+ import { ApiClient, api, apiClient } from "./infra/api/client";
3
+ import { authService } from "./modules/auth/services/auth.service";
4
+ import { whitelabelService } from "./modules/whitelabel/services/whitelabel.service";
5
+ import { whitelabelStylesService } from "./modules/whitelabel/services/whitelabel-styles.service";
6
+ import { findWhitelabelStyles } from "./modules/whitelabel/actions/find-whitelabel-styles.action";
7
+ import { subscriptionsService } from "./modules/subscriptions/services/subscriptions.service";
8
+ import { iaCreditsService } from "./modules/ia-credits/services/ia-credits.service";
9
+ import { findWhitelabel } from "./modules/whitelabel/actions/find-whitelabel.action";
10
+ import { validateSessionAction } from "./modules/auth/actions/validate-session.action";
11
+ import { findUserById } from "./modules/users/action/find-user-by-id.action";
12
+ import { findCurrentAccount } from "./modules/accounts/actions/find-current-account.action";
13
+ import { listSubscriptionsAction } from "./modules/subscriptions/actions/list-subscriptions.action";
14
+ import { listIaCreditsAction } from "./modules/ia-credits/actions/list-ia-credits.action";
15
+ import { projectUsersService } from "./modules/projects/services/project-users.service";
16
+ import { listProjectUsersAction } from "./modules/projects/actions/list-project-users.action";
17
+ import { listAvailableUsersAction } from "./modules/projects/actions/list-available-users.action";
18
+ import { addProjectUserAction } from "./modules/projects/actions/add-project-user.action";
19
+ import { removeProjectUserAction } from "./modules/projects/actions/remove-project-user.action";
20
+ import { accountService } from "./modules/accounts/services/account.service";
21
+ import { twoFactorService } from "./modules/accounts/services/two-factor.service";
22
+ import {
23
+ listAccountUsersAction,
24
+ updateUserAction,
25
+ updateAccountAction,
26
+ updateAccountUserByIdAction,
27
+ deleteAccountUserAction,
28
+ deleteAccountAction,
29
+ createAccountUserAction,
30
+ changePasswordAction,
31
+ requestEmailChangeAction,
32
+ confirmEmailChangeAction,
33
+ requestPhoneChangeAction,
34
+ confirmPhoneChangeAction,
35
+ generateTwoFactorAction,
36
+ confirmTwoFactorAction,
37
+ disableTwoFactorAction
38
+ } from "./modules/accounts/actions/account-management.action";
39
+ import { getClientInfoFromRequest } from "./infra/utils/client-info";
40
+ import { getUserContext } from "./modules/auth/utils/get-user-context";
41
+ import { safeServerAction } from "./utils/safeServerAction";
1447
42
  export {
1448
43
  ApiClient,
1449
44
  accountService,