@greatapps/common 1.1.789 → 1.1.791

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 (785) hide show
  1. package/dist/components/account/AccountHubLinkHandler.mjs +36 -0
  2. package/dist/components/account/AccountHubLinkHandler.mjs.map +1 -0
  3. package/dist/components/account/AccountModalLayout.mjs +137 -0
  4. package/dist/components/account/AccountModalLayout.mjs.map +1 -0
  5. package/dist/components/account/AccountModals.mjs +10 -3
  6. package/dist/components/account/AccountModals.mjs.map +1 -1
  7. package/dist/components/account/DeleteAccountModal.mjs +1 -1
  8. package/dist/components/account/DeleteAccountModal.mjs.map +1 -1
  9. package/dist/components/account/IsntPossibleDeleteAccountModal.mjs +8 -1
  10. package/dist/components/account/IsntPossibleDeleteAccountModal.mjs.map +1 -1
  11. package/dist/components/account/MyAccountModal.mjs +167 -0
  12. package/dist/components/account/MyAccountModal.mjs.map +1 -0
  13. package/dist/components/account/TwoFactorAuthModal.mjs +1 -1
  14. package/dist/components/account/TwoFactorAuthModal.mjs.map +1 -1
  15. package/dist/components/account/hooks/useAccountHubActions.mjs +85 -0
  16. package/dist/components/account/hooks/useAccountHubActions.mjs.map +1 -0
  17. package/dist/components/account/hooks/useAddCardWithPaymentSwitch.mjs +44 -0
  18. package/dist/components/account/hooks/useAddCardWithPaymentSwitch.mjs.map +1 -0
  19. package/dist/components/account/hooks/useAffiliatesActions.mjs +69 -0
  20. package/dist/components/account/hooks/useAffiliatesActions.mjs.map +1 -0
  21. package/dist/components/account/hooks/useMyAccountModal.mjs +27 -0
  22. package/dist/components/account/hooks/useMyAccountModal.mjs.map +1 -0
  23. package/dist/components/account/hooks/useProjectsActions.mjs +40 -0
  24. package/dist/components/account/hooks/useProjectsActions.mjs.map +1 -0
  25. package/dist/components/account/hooks/useSubscriptionActions.mjs +87 -0
  26. package/dist/components/account/hooks/useSubscriptionActions.mjs.map +1 -0
  27. package/dist/components/account/hooks/useTeamActions.mjs +31 -0
  28. package/dist/components/account/hooks/useTeamActions.mjs.map +1 -0
  29. package/dist/components/account/sections/AffiliatesSection.mjs +313 -0
  30. package/dist/components/account/sections/AffiliatesSection.mjs.map +1 -0
  31. package/dist/components/account/sections/ChangePasswordSection.mjs +5 -5
  32. package/dist/components/account/sections/ChangePasswordSection.mjs.map +1 -1
  33. package/dist/components/account/sections/MyProfileSection.mjs +194 -144
  34. package/dist/components/account/sections/MyProfileSection.mjs.map +1 -1
  35. package/dist/components/account/sections/PreferencesSection.mjs +60 -49
  36. package/dist/components/account/sections/PreferencesSection.mjs.map +1 -1
  37. package/dist/components/account/sections/ProjectsSection.mjs +77 -0
  38. package/dist/components/account/sections/ProjectsSection.mjs.map +1 -0
  39. package/dist/components/account/sections/SecuritySection.mjs +55 -36
  40. package/dist/components/account/sections/SecuritySection.mjs.map +1 -1
  41. package/dist/components/account/sections/SubscriptionSection.mjs +29 -0
  42. package/dist/components/account/sections/SubscriptionSection.mjs.map +1 -0
  43. package/dist/components/account/sections/TeamSection.mjs +119 -0
  44. package/dist/components/account/sections/TeamSection.mjs.map +1 -0
  45. package/dist/components/account/sections/TokenSection.mjs +41 -43
  46. package/dist/components/account/sections/TokenSection.mjs.map +1 -1
  47. package/dist/components/account/sections/affiliates/AffiliateCommissionCard.mjs +73 -0
  48. package/dist/components/account/sections/affiliates/AffiliateCommissionCard.mjs.map +1 -0
  49. package/dist/components/account/sections/affiliates/AffiliateFlows.mjs +20 -0
  50. package/dist/components/account/sections/affiliates/AffiliateFlows.mjs.map +1 -0
  51. package/dist/components/account/sections/affiliates/AffiliateLeadsSheet.mjs +99 -0
  52. package/dist/components/account/sections/affiliates/AffiliateLeadsSheet.mjs.map +1 -0
  53. package/dist/components/account/sections/affiliates/AffiliateStatsCard.mjs +31 -0
  54. package/dist/components/account/sections/affiliates/AffiliateStatsCard.mjs.map +1 -0
  55. package/dist/components/account/sections/affiliates/AffiliateStepCard.mjs +15 -0
  56. package/dist/components/account/sections/affiliates/AffiliateStepCard.mjs.map +1 -0
  57. package/dist/components/account/sections/affiliates/AffiliateTransactionsList.mjs +108 -0
  58. package/dist/components/account/sections/affiliates/AffiliateTransactionsList.mjs.map +1 -0
  59. package/dist/components/account/sections/affiliates/NoReceivingAccountModal.mjs +49 -0
  60. package/dist/components/account/sections/affiliates/NoReceivingAccountModal.mjs.map +1 -0
  61. package/dist/components/account/sections/affiliates/ReceivingAccountModal.mjs +182 -0
  62. package/dist/components/account/sections/affiliates/ReceivingAccountModal.mjs.map +1 -0
  63. package/dist/components/account/sections/affiliates/RequestWithdrawalSheet.mjs +476 -0
  64. package/dist/components/account/sections/affiliates/RequestWithdrawalSheet.mjs.map +1 -0
  65. package/dist/components/account/sections/affiliates/ViewAttachmentModal.mjs +34 -0
  66. package/dist/components/account/sections/affiliates/ViewAttachmentModal.mjs.map +1 -0
  67. package/dist/components/account/sections/affiliates/reports/AffiliatesIndicatorsChart.mjs +27 -0
  68. package/dist/components/account/sections/affiliates/reports/AffiliatesIndicatorsChart.mjs.map +1 -0
  69. package/dist/components/account/sections/affiliates/reports/AffiliatesReportsTab.mjs +30 -0
  70. package/dist/components/account/sections/affiliates/reports/AffiliatesReportsTab.mjs.map +1 -0
  71. package/dist/components/account/sections/affiliates/reports/useAffiliatesIndicatorsChart.mjs +120 -0
  72. package/dist/components/account/sections/affiliates/reports/useAffiliatesIndicatorsChart.mjs.map +1 -0
  73. package/dist/components/account/sections/projects/DeleteProjectModal.mjs +205 -0
  74. package/dist/components/account/sections/projects/DeleteProjectModal.mjs.map +1 -0
  75. package/dist/components/account/sections/projects/ProjectFlows.mjs +16 -0
  76. package/dist/components/account/sections/projects/ProjectFlows.mjs.map +1 -0
  77. package/dist/components/account/sections/projects/ProjectMembersStack.mjs +53 -0
  78. package/dist/components/account/sections/projects/ProjectMembersStack.mjs.map +1 -0
  79. package/dist/components/account/sections/projects/ProjectRow.mjs +85 -0
  80. package/dist/components/account/sections/projects/ProjectRow.mjs.map +1 -0
  81. package/dist/components/account/sections/projects/ProjectSheet.mjs +499 -0
  82. package/dist/components/account/sections/projects/ProjectSheet.mjs.map +1 -0
  83. package/dist/components/account/sections/projects/ProjectsDisabledModal.mjs +55 -0
  84. package/dist/components/account/sections/projects/ProjectsDisabledModal.mjs.map +1 -0
  85. package/dist/components/account/sections/projects/project-form.schema.mjs +28 -0
  86. package/dist/components/account/sections/projects/project-form.schema.mjs.map +1 -0
  87. package/dist/components/account/sections/shared/ConnectListRow.mjs +45 -0
  88. package/dist/components/account/sections/shared/ConnectListRow.mjs.map +1 -0
  89. package/dist/components/account/sections/shared/DateFilterPopover.mjs +51 -0
  90. package/dist/components/account/sections/shared/DateFilterPopover.mjs.map +1 -0
  91. package/dist/components/account/sections/shared/EntityAvatar.mjs +41 -0
  92. package/dist/components/account/sections/shared/EntityAvatar.mjs.map +1 -0
  93. package/dist/components/account/sections/shared/FilterPopover.mjs +62 -0
  94. package/dist/components/account/sections/shared/FilterPopover.mjs.map +1 -0
  95. package/dist/components/account/sections/shared/FormSection.mjs +14 -0
  96. package/dist/components/account/sections/shared/FormSection.mjs.map +1 -0
  97. package/dist/components/account/sections/shared/IconBox.mjs +18 -0
  98. package/dist/components/account/sections/shared/IconBox.mjs.map +1 -0
  99. package/dist/components/account/sections/shared/InfiniteScrollList.mjs +36 -0
  100. package/dist/components/account/sections/shared/InfiniteScrollList.mjs.map +1 -0
  101. package/dist/components/account/sections/shared/ListPagination.mjs +69 -0
  102. package/dist/components/account/sections/shared/ListPagination.mjs.map +1 -0
  103. package/dist/components/account/sections/shared/RowActionsMenu.mjs +52 -0
  104. package/dist/components/account/sections/shared/RowActionsMenu.mjs.map +1 -0
  105. package/dist/components/account/sections/shared/SectionLoadError.mjs +20 -0
  106. package/dist/components/account/sections/shared/SectionLoadError.mjs.map +1 -0
  107. package/dist/components/account/sections/shared/StatusBadge.mjs +26 -0
  108. package/dist/components/account/sections/shared/StatusBadge.mjs.map +1 -0
  109. package/dist/components/account/sections/shared/WorkspaceSection.mjs +10 -0
  110. package/dist/components/account/sections/shared/WorkspaceSection.mjs.map +1 -0
  111. package/dist/components/account/sections/subscription/AiCreditsUsage.mjs +106 -0
  112. package/dist/components/account/sections/subscription/AiCreditsUsage.mjs.map +1 -0
  113. package/dist/components/account/sections/subscription/BillingAddressSheet.mjs +407 -0
  114. package/dist/components/account/sections/subscription/BillingAddressSheet.mjs.map +1 -0
  115. package/dist/components/account/sections/subscription/BoletoDetailsDialog.mjs +73 -0
  116. package/dist/components/account/sections/subscription/BoletoDetailsDialog.mjs.map +1 -0
  117. package/dist/components/account/sections/subscription/BoletoGeneratedDialog.mjs +22 -0
  118. package/dist/components/account/sections/subscription/BoletoGeneratedDialog.mjs.map +1 -0
  119. package/dist/components/account/sections/subscription/CancelPlanDialog.mjs +161 -0
  120. package/dist/components/account/sections/subscription/CancelPlanDialog.mjs.map +1 -0
  121. package/dist/components/account/sections/subscription/ChargeRow.mjs +127 -0
  122. package/dist/components/account/sections/subscription/ChargeRow.mjs.map +1 -0
  123. package/dist/components/account/sections/subscription/ChargeStatusBadge.mjs +27 -0
  124. package/dist/components/account/sections/subscription/ChargeStatusBadge.mjs.map +1 -0
  125. package/dist/components/account/sections/subscription/ChargesList.mjs +88 -0
  126. package/dist/components/account/sections/subscription/ChargesList.mjs.map +1 -0
  127. package/dist/components/account/sections/subscription/ManageCardsSheet.mjs +49 -0
  128. package/dist/components/account/sections/subscription/ManageCardsSheet.mjs.map +1 -0
  129. package/dist/components/account/sections/subscription/OverdueReceiptOpener.mjs +26 -0
  130. package/dist/components/account/sections/subscription/OverdueReceiptOpener.mjs.map +1 -0
  131. package/dist/components/account/sections/subscription/PayChargeDialog.mjs +222 -0
  132. package/dist/components/account/sections/subscription/PayChargeDialog.mjs.map +1 -0
  133. package/dist/components/account/sections/subscription/PaymentConfirmationDialog.mjs +61 -0
  134. package/dist/components/account/sections/subscription/PaymentConfirmationDialog.mjs.map +1 -0
  135. package/dist/components/account/sections/subscription/PaymentMethodsCard.mjs +72 -0
  136. package/dist/components/account/sections/subscription/PaymentMethodsCard.mjs.map +1 -0
  137. package/dist/components/account/sections/subscription/PendingChangeDialog.mjs +117 -0
  138. package/dist/components/account/sections/subscription/PendingChangeDialog.mjs.map +1 -0
  139. package/dist/components/account/sections/subscription/PixDetailsDialog.mjs +165 -0
  140. package/dist/components/account/sections/subscription/PixDetailsDialog.mjs.map +1 -0
  141. package/dist/components/account/sections/subscription/PixPaymentDialog.mjs +155 -0
  142. package/dist/components/account/sections/subscription/PixPaymentDialog.mjs.map +1 -0
  143. package/dist/components/account/sections/subscription/PlanDetailsSheet.mjs +253 -0
  144. package/dist/components/account/sections/subscription/PlanDetailsSheet.mjs.map +1 -0
  145. package/dist/components/account/sections/subscription/ReceiptDetailsSheet.mjs +237 -0
  146. package/dist/components/account/sections/subscription/ReceiptDetailsSheet.mjs.map +1 -0
  147. package/dist/components/account/sections/subscription/SubscriptionFlows.mjs +40 -0
  148. package/dist/components/account/sections/subscription/SubscriptionFlows.mjs.map +1 -0
  149. package/dist/components/account/sections/subscription/SubscriptionPlanCard.mjs +303 -0
  150. package/dist/components/account/sections/subscription/SubscriptionPlanCard.mjs.map +1 -0
  151. package/dist/components/account/sections/subscription/UsageReportSheet.mjs +163 -0
  152. package/dist/components/account/sections/subscription/UsageReportSheet.mjs.map +1 -0
  153. package/dist/components/account/sections/subscription/change-plan/ChangePlanSheet.mjs +75 -0
  154. package/dist/components/account/sections/subscription/change-plan/ChangePlanSheet.mjs.map +1 -0
  155. package/dist/components/account/sections/subscription/change-plan/components/AbTestDetailsDialog.mjs +55 -0
  156. package/dist/components/account/sections/subscription/change-plan/components/AbTestDetailsDialog.mjs.map +1 -0
  157. package/dist/components/account/sections/subscription/change-plan/components/AddonsBlock.mjs +188 -0
  158. package/dist/components/account/sections/subscription/change-plan/components/AddonsBlock.mjs.map +1 -0
  159. package/dist/components/account/sections/subscription/change-plan/components/AlternativeBucketsSection.mjs +66 -0
  160. package/dist/components/account/sections/subscription/change-plan/components/AlternativeBucketsSection.mjs.map +1 -0
  161. package/dist/components/account/sections/subscription/change-plan/components/CouponBlock.mjs +42 -0
  162. package/dist/components/account/sections/subscription/change-plan/components/CouponBlock.mjs.map +1 -0
  163. package/dist/components/account/sections/subscription/change-plan/components/CouponDialog.mjs +119 -0
  164. package/dist/components/account/sections/subscription/change-plan/components/CouponDialog.mjs.map +1 -0
  165. package/dist/components/account/sections/subscription/change-plan/components/PricePreview.mjs +17 -0
  166. package/dist/components/account/sections/subscription/change-plan/components/PricePreview.mjs.map +1 -0
  167. package/dist/components/account/sections/subscription/change-plan/components/SummaryBlock.mjs +130 -0
  168. package/dist/components/account/sections/subscription/change-plan/components/SummaryBlock.mjs.map +1 -0
  169. package/dist/components/account/sections/subscription/change-plan/plan-comparison.mjs +38 -0
  170. package/dist/components/account/sections/subscription/change-plan/plan-comparison.mjs.map +1 -0
  171. package/dist/components/account/sections/subscription/change-plan/steps/PaymentSummaryStep.mjs +127 -0
  172. package/dist/components/account/sections/subscription/change-plan/steps/PaymentSummaryStep.mjs.map +1 -0
  173. package/dist/components/account/sections/subscription/change-plan/steps/PlanComparisonStep.mjs +111 -0
  174. package/dist/components/account/sections/subscription/change-plan/steps/PlanComparisonStep.mjs.map +1 -0
  175. package/dist/components/account/sections/subscription/change-plan/steps/PlanViewStep.mjs +69 -0
  176. package/dist/components/account/sections/subscription/change-plan/steps/PlanViewStep.mjs.map +1 -0
  177. package/dist/components/account/sections/subscription/change-plan/steps/ReactivationConfigStep.mjs +88 -0
  178. package/dist/components/account/sections/subscription/change-plan/steps/ReactivationConfigStep.mjs.map +1 -0
  179. package/dist/components/account/sections/subscription/change-plan/steps/ReactivationPaymentStep.mjs +115 -0
  180. package/dist/components/account/sections/subscription/change-plan/steps/ReactivationPaymentStep.mjs.map +1 -0
  181. package/dist/components/account/sections/subscription/change-plan/useChangePlanState.mjs +918 -0
  182. package/dist/components/account/sections/subscription/change-plan/useChangePlanState.mjs.map +1 -0
  183. package/dist/components/account/sections/subscription/downgrade/CannotDowngradeDialog.mjs +216 -0
  184. package/dist/components/account/sections/subscription/downgrade/CannotDowngradeDialog.mjs.map +1 -0
  185. package/dist/components/account/sections/subscription/downgrade/DowngradeReasonDialog.mjs +128 -0
  186. package/dist/components/account/sections/subscription/downgrade/DowngradeReasonDialog.mjs.map +1 -0
  187. package/dist/components/account/sections/subscription/plans/PlanCard.mjs +281 -0
  188. package/dist/components/account/sections/subscription/plans/PlanCard.mjs.map +1 -0
  189. package/dist/components/account/sections/subscription/plans/PlanCardSkeleton.mjs +53 -0
  190. package/dist/components/account/sections/subscription/plans/PlanCardSkeleton.mjs.map +1 -0
  191. package/dist/components/account/sections/subscription/plans/PlansCatalogDialog.mjs +119 -0
  192. package/dist/components/account/sections/subscription/plans/PlansCatalogDialog.mjs.map +1 -0
  193. package/dist/components/account/sections/team/DeleteUserModal.mjs +116 -0
  194. package/dist/components/account/sections/team/DeleteUserModal.mjs.map +1 -0
  195. package/dist/components/account/sections/team/TeamFlows.mjs +14 -0
  196. package/dist/components/account/sections/team/TeamFlows.mjs.map +1 -0
  197. package/dist/components/account/sections/team/TeamMemberRow.mjs +99 -0
  198. package/dist/components/account/sections/team/TeamMemberRow.mjs.map +1 -0
  199. package/dist/components/account/sections/team/UserSheet.mjs +570 -0
  200. package/dist/components/account/sections/team/UserSheet.mjs.map +1 -0
  201. package/dist/components/account/sections/team/steps/NotificationsStep.mjs +80 -0
  202. package/dist/components/account/sections/team/steps/NotificationsStep.mjs.map +1 -0
  203. package/dist/components/account/sections/team/steps/ProjectSelectionStep.mjs +180 -0
  204. package/dist/components/account/sections/team/steps/ProjectSelectionStep.mjs.map +1 -0
  205. package/dist/components/account/sections/team/steps/UserInformationStep.mjs +371 -0
  206. package/dist/components/account/sections/team/steps/UserInformationStep.mjs.map +1 -0
  207. package/dist/components/account/sections/team/user-form.schema.mjs +37 -0
  208. package/dist/components/account/sections/team/user-form.schema.mjs.map +1 -0
  209. package/dist/components/account/types/workspace-actions.type.mjs +1 -0
  210. package/dist/components/account/types/workspace-actions.type.mjs.map +1 -0
  211. package/dist/components/layouts/ProfilePopover.mjs +10 -12
  212. package/dist/components/layouts/ProfilePopover.mjs.map +1 -1
  213. package/dist/components/layouts/UsersSelectorPopover.mjs +7 -4
  214. package/dist/components/layouts/UsersSelectorPopover.mjs.map +1 -1
  215. package/dist/components/modals/AccountDeletionWarningModal.mjs +4 -5
  216. package/dist/components/modals/AccountDeletionWarningModal.mjs.map +1 -1
  217. package/dist/components/modals/AccountFrozenModal.mjs +6 -3
  218. package/dist/components/modals/AccountFrozenModal.mjs.map +1 -1
  219. package/dist/components/modals/Modals.mjs +3 -3
  220. package/dist/components/modals/Modals.mjs.map +1 -1
  221. package/dist/components/modals/PaidPlanRequiredModal.mjs +4 -5
  222. package/dist/components/modals/PaidPlanRequiredModal.mjs.map +1 -1
  223. package/dist/components/modals/cards/AddFirstCardWarningModal.mjs +63 -0
  224. package/dist/components/modals/cards/AddFirstCardWarningModal.mjs.map +1 -0
  225. package/dist/components/modals/cards/SwitchPaymentToCardModal.mjs +187 -0
  226. package/dist/components/modals/cards/SwitchPaymentToCardModal.mjs.map +1 -0
  227. package/dist/components/modals/promo/AiCreditsOfferModal/AiCreditsOfferModal.mjs +5 -4
  228. package/dist/components/modals/promo/AiCreditsOfferModal/AiCreditsOfferModal.mjs.map +1 -1
  229. package/dist/components/ui/data-display/CardItem.mjs +9 -1
  230. package/dist/components/ui/data-display/CardItem.mjs.map +1 -1
  231. package/dist/components/ui/data-display/PaymentMethodIcons.mjs +50 -0
  232. package/dist/components/ui/data-display/PaymentMethodIcons.mjs.map +1 -0
  233. package/dist/components/ui/form/BillingPeriodSelector.mjs +108 -0
  234. package/dist/components/ui/form/BillingPeriodSelector.mjs.map +1 -0
  235. package/dist/components/ui/form/PaymentMethodToggle.mjs +82 -0
  236. package/dist/components/ui/form/PaymentMethodToggle.mjs.map +1 -0
  237. package/dist/components/ui/form/RadioOptionFieldIcon.mjs +57 -0
  238. package/dist/components/ui/form/RadioOptionFieldIcon.mjs.map +1 -0
  239. package/dist/components/ui/form/SegmentedControl.mjs +56 -0
  240. package/dist/components/ui/form/SegmentedControl.mjs.map +1 -0
  241. package/dist/components/ui/overlay/Dialog.mjs +41 -6
  242. package/dist/components/ui/overlay/Dialog.mjs.map +1 -1
  243. package/dist/components/ui/overlay/Sheet.mjs +43 -13
  244. package/dist/components/ui/overlay/Sheet.mjs.map +1 -1
  245. package/dist/components/ui/overlay/layers.mjs +72 -26
  246. package/dist/components/ui/overlay/layers.mjs.map +1 -1
  247. package/dist/enums/AccountHubFlow.mjs +13 -0
  248. package/dist/enums/AccountHubFlow.mjs.map +1 -0
  249. package/dist/enums/DateFilterPeriod.mjs +22 -0
  250. package/dist/enums/DateFilterPeriod.mjs.map +1 -0
  251. package/dist/enums/WorkspaceSectionType.mjs +11 -0
  252. package/dist/enums/WorkspaceSectionType.mjs.map +1 -0
  253. package/dist/handlers.mjs +24 -0
  254. package/dist/handlers.mjs.map +1 -1
  255. package/dist/hooks/useDebounce.mjs +5 -3
  256. package/dist/hooks/useDebounce.mjs.map +1 -1
  257. package/dist/hooks/useUploadProgress.mjs +33 -0
  258. package/dist/hooks/useUploadProgress.mjs.map +1 -0
  259. package/dist/i18n/messages/en-us.mjs +863 -3
  260. package/dist/i18n/messages/en-us.mjs.map +1 -1
  261. package/dist/i18n/messages/es-es.mjs +863 -3
  262. package/dist/i18n/messages/es-es.mjs.map +1 -1
  263. package/dist/i18n/messages/pt-br.mjs +863 -3
  264. package/dist/i18n/messages/pt-br.mjs.map +1 -1
  265. package/dist/index.mjs +87 -7
  266. package/dist/index.mjs.map +1 -1
  267. package/dist/infra/http/paged.mjs +20 -0
  268. package/dist/infra/http/paged.mjs.map +1 -0
  269. package/dist/middleware.mjs +2 -0
  270. package/dist/middleware.mjs.map +1 -1
  271. package/dist/middlewares/create-auth-middleware.mjs +1 -3
  272. package/dist/middlewares/create-auth-middleware.mjs.map +1 -1
  273. package/dist/middlewares/create-legacy-account-routes-middleware.mjs +44 -0
  274. package/dist/middlewares/create-legacy-account-routes-middleware.mjs.map +1 -0
  275. package/dist/middlewares/is-route-equals.mjs +7 -0
  276. package/dist/middlewares/is-route-equals.mjs.map +1 -0
  277. package/dist/modules/accounts/actions/account-management.action.mjs +20 -1
  278. package/dist/modules/accounts/actions/account-management.action.mjs.map +1 -1
  279. package/dist/modules/accounts/constants/account-hub-link.constants.mjs +9 -0
  280. package/dist/modules/accounts/constants/account-hub-link.constants.mjs.map +1 -0
  281. package/dist/modules/accounts/constants/legacy-account-routes.constants.mjs +5 -0
  282. package/dist/modules/accounts/constants/legacy-account-routes.constants.mjs.map +1 -0
  283. package/dist/modules/accounts/handlers/list-account-members.handler.mjs +22 -0
  284. package/dist/modules/accounts/handlers/list-account-members.handler.mjs.map +1 -0
  285. package/dist/modules/accounts/hooks/add-user-projects.hook.mjs +51 -0
  286. package/dist/modules/accounts/hooks/add-user-projects.hook.mjs.map +1 -0
  287. package/dist/modules/accounts/hooks/create-account-user.hook.mjs +20 -0
  288. package/dist/modules/accounts/hooks/create-account-user.hook.mjs.map +1 -0
  289. package/dist/modules/accounts/hooks/remove-user-projects.hook.mjs +47 -0
  290. package/dist/modules/accounts/hooks/remove-user-projects.hook.mjs.map +1 -0
  291. package/dist/modules/accounts/hooks/use-account-members.hook.mjs +20 -0
  292. package/dist/modules/accounts/hooks/use-account-members.hook.mjs.map +1 -0
  293. package/dist/modules/accounts/services/account.service.mjs +59 -0
  294. package/dist/modules/accounts/services/account.service.mjs.map +1 -1
  295. package/dist/modules/accounts/types/account-hub-link.type.mjs +1 -0
  296. package/dist/modules/accounts/types/account-hub-link.type.mjs.map +1 -0
  297. package/dist/modules/accounts/utils/build-account-hub-url.mjs +16 -0
  298. package/dist/modules/accounts/utils/build-account-hub-url.mjs.map +1 -0
  299. package/dist/modules/accounts/utils/is-account-hub-flow.mjs +9 -0
  300. package/dist/modules/accounts/utils/is-account-hub-flow.mjs.map +1 -0
  301. package/dist/modules/accounts/utils/is-account-section.mjs +9 -0
  302. package/dist/modules/accounts/utils/is-account-section.mjs.map +1 -0
  303. package/dist/modules/accounts/utils/is-my-account-section.mjs +13 -0
  304. package/dist/modules/accounts/utils/is-my-account-section.mjs.map +1 -0
  305. package/dist/modules/accounts/utils/map-legacy-account-route.mjs +93 -0
  306. package/dist/modules/accounts/utils/map-legacy-account-route.mjs.map +1 -0
  307. package/dist/modules/accounts/utils/parse-account-hub-link.mjs +20 -0
  308. package/dist/modules/accounts/utils/parse-account-hub-link.mjs.map +1 -0
  309. package/dist/modules/affiliates/actions/ensure-affiliate.action.mjs +10 -0
  310. package/dist/modules/affiliates/actions/ensure-affiliate.action.mjs.map +1 -0
  311. package/dist/modules/affiliates/actions/request-deposit.action.mjs +10 -0
  312. package/dist/modules/affiliates/actions/request-deposit.action.mjs.map +1 -0
  313. package/dist/modules/affiliates/actions/update-affiliate.action.mjs +10 -0
  314. package/dist/modules/affiliates/actions/update-affiliate.action.mjs.map +1 -0
  315. package/dist/modules/affiliates/constants/affiliate.constants.mjs +11 -0
  316. package/dist/modules/affiliates/constants/affiliate.constants.mjs.map +1 -0
  317. package/dist/modules/affiliates/constants/query-keys.constants.mjs +15 -0
  318. package/dist/modules/affiliates/constants/query-keys.constants.mjs.map +1 -0
  319. package/dist/modules/affiliates/handlers/affiliate-report-analytics.handler.mjs +16 -0
  320. package/dist/modules/affiliates/handlers/affiliate-report-analytics.handler.mjs.map +1 -0
  321. package/dist/modules/affiliates/handlers/affiliate-withdrawal-limits.handler.mjs +12 -0
  322. package/dist/modules/affiliates/handlers/affiliate-withdrawal-limits.handler.mjs.map +1 -0
  323. package/dist/modules/affiliates/handlers/current-affiliate.handler.mjs +12 -0
  324. package/dist/modules/affiliates/handlers/current-affiliate.handler.mjs.map +1 -0
  325. package/dist/modules/affiliates/handlers/list-affiliate-coupons.handler.mjs +12 -0
  326. package/dist/modules/affiliates/handlers/list-affiliate-coupons.handler.mjs.map +1 -0
  327. package/dist/modules/affiliates/handlers/list-affiliate-leads.handler.mjs +22 -0
  328. package/dist/modules/affiliates/handlers/list-affiliate-leads.handler.mjs.map +1 -0
  329. package/dist/modules/affiliates/handlers/list-affiliate-transactions.handler.mjs +22 -0
  330. package/dist/modules/affiliates/handlers/list-affiliate-transactions.handler.mjs.map +1 -0
  331. package/dist/modules/affiliates/hooks/use-affiliate-coupons.hook.mjs +17 -0
  332. package/dist/modules/affiliates/hooks/use-affiliate-coupons.hook.mjs.map +1 -0
  333. package/dist/modules/affiliates/hooks/use-affiliate-leads.hook.mjs +22 -0
  334. package/dist/modules/affiliates/hooks/use-affiliate-leads.hook.mjs.map +1 -0
  335. package/dist/modules/affiliates/hooks/use-affiliate-report-analytics.hook.mjs +17 -0
  336. package/dist/modules/affiliates/hooks/use-affiliate-report-analytics.hook.mjs.map +1 -0
  337. package/dist/modules/affiliates/hooks/use-affiliate-transactions.hook.mjs +20 -0
  338. package/dist/modules/affiliates/hooks/use-affiliate-transactions.hook.mjs.map +1 -0
  339. package/dist/modules/affiliates/hooks/use-current-affiliate.hook.mjs +17 -0
  340. package/dist/modules/affiliates/hooks/use-current-affiliate.hook.mjs.map +1 -0
  341. package/dist/modules/affiliates/hooks/use-ensure-affiliate.hook.mjs +23 -0
  342. package/dist/modules/affiliates/hooks/use-ensure-affiliate.hook.mjs.map +1 -0
  343. package/dist/modules/affiliates/hooks/use-request-deposit.hook.mjs +28 -0
  344. package/dist/modules/affiliates/hooks/use-request-deposit.hook.mjs.map +1 -0
  345. package/dist/modules/affiliates/hooks/use-update-affiliate.hook.mjs +22 -0
  346. package/dist/modules/affiliates/hooks/use-update-affiliate.hook.mjs.map +1 -0
  347. package/dist/modules/affiliates/hooks/use-withdrawal-limits.hook.mjs +17 -0
  348. package/dist/modules/affiliates/hooks/use-withdrawal-limits.hook.mjs.map +1 -0
  349. package/dist/modules/affiliates/services/affiliates.service.mjs +183 -0
  350. package/dist/modules/affiliates/services/affiliates.service.mjs.map +1 -0
  351. package/dist/modules/affiliates/types/affiliate.type.mjs +100 -0
  352. package/dist/modules/affiliates/types/affiliate.type.mjs.map +1 -0
  353. package/dist/modules/affiliates/utils/get-affiliate-share-link.mjs +9 -0
  354. package/dist/modules/affiliates/utils/get-affiliate-share-link.mjs.map +1 -0
  355. package/dist/modules/charges/actions/get-nota-fiscal.action.mjs +10 -0
  356. package/dist/modules/charges/actions/get-nota-fiscal.action.mjs.map +1 -0
  357. package/dist/modules/charges/actions/refresh-pix.action.mjs +10 -0
  358. package/dist/modules/charges/actions/refresh-pix.action.mjs.map +1 -0
  359. package/dist/modules/charges/hooks/nota-fiscal.hook.mjs +13 -0
  360. package/dist/modules/charges/hooks/nota-fiscal.hook.mjs.map +1 -0
  361. package/dist/modules/charges/hooks/refresh-pix.hook.mjs +13 -0
  362. package/dist/modules/charges/hooks/refresh-pix.hook.mjs.map +1 -0
  363. package/dist/modules/charges/services/charges.service.mjs +67 -0
  364. package/dist/modules/charges/services/charges.service.mjs.map +1 -1
  365. package/dist/modules/charges/types/nota-fiscal.type.mjs +1 -0
  366. package/dist/modules/charges/types/nota-fiscal.type.mjs.map +1 -0
  367. package/dist/modules/charges/types/refresh-pix.type.mjs +1 -0
  368. package/dist/modules/charges/types/refresh-pix.type.mjs.map +1 -0
  369. package/dist/modules/charges/utils/get-charge-download-url.mjs +8 -0
  370. package/dist/modules/charges/utils/get-charge-download-url.mjs.map +1 -0
  371. package/dist/modules/coupons/constants/query-keys.constants.mjs +5 -0
  372. package/dist/modules/coupons/constants/query-keys.constants.mjs.map +1 -0
  373. package/dist/modules/coupons/handlers/find-coupon-by-code.handler.mjs +17 -0
  374. package/dist/modules/coupons/handlers/find-coupon-by-code.handler.mjs.map +1 -0
  375. package/dist/modules/coupons/handlers/find-coupon-by-id.handler.mjs +16 -0
  376. package/dist/modules/coupons/handlers/find-coupon-by-id.handler.mjs.map +1 -0
  377. package/dist/modules/coupons/hooks/use-coupon-by-code.hook.mjs +15 -0
  378. package/dist/modules/coupons/hooks/use-coupon-by-code.hook.mjs.map +1 -0
  379. package/dist/modules/coupons/hooks/use-coupon-by-id.hook.mjs +18 -0
  380. package/dist/modules/coupons/hooks/use-coupon-by-id.hook.mjs.map +1 -0
  381. package/dist/modules/coupons/services/coupons.service.mjs +44 -0
  382. package/dist/modules/coupons/services/coupons.service.mjs.map +1 -0
  383. package/dist/modules/coupons/types/coupon.type.mjs +61 -0
  384. package/dist/modules/coupons/types/coupon.type.mjs.map +1 -0
  385. package/dist/modules/coupons/utils/coupon-restrictions.mjs +60 -0
  386. package/dist/modules/coupons/utils/coupon-restrictions.mjs.map +1 -0
  387. package/dist/modules/domains/handlers/count-domains.handler.mjs +12 -0
  388. package/dist/modules/domains/handlers/count-domains.handler.mjs.map +1 -0
  389. package/dist/modules/domains/hooks/count-domains.hook.mjs +17 -0
  390. package/dist/modules/domains/hooks/count-domains.hook.mjs.map +1 -0
  391. package/dist/modules/domains/services/domains.service.mjs +18 -0
  392. package/dist/modules/domains/services/domains.service.mjs.map +1 -0
  393. package/dist/modules/ia-credits/handlers/list-ia-credit-operations.handler.mjs +15 -0
  394. package/dist/modules/ia-credits/handlers/list-ia-credit-operations.handler.mjs.map +1 -0
  395. package/dist/modules/ia-credits/hooks/ia-credit-operations.hook.mjs +28 -0
  396. package/dist/modules/ia-credits/hooks/ia-credit-operations.hook.mjs.map +1 -0
  397. package/dist/modules/ia-credits/services/ia-credits.service.mjs +23 -2
  398. package/dist/modules/ia-credits/services/ia-credits.service.mjs.map +1 -1
  399. package/dist/modules/pages/handlers/count-pages.handler.mjs +4 -2
  400. package/dist/modules/pages/handlers/count-pages.handler.mjs.map +1 -1
  401. package/dist/modules/pages/hooks/count-published-pages.hook.mjs +26 -0
  402. package/dist/modules/pages/hooks/count-published-pages.hook.mjs.map +1 -0
  403. package/dist/modules/pages/services/pages.service.mjs +3 -2
  404. package/dist/modules/pages/services/pages.service.mjs.map +1 -1
  405. package/dist/modules/plans/constants/plan-tooltips.constants.mjs +14 -0
  406. package/dist/modules/plans/constants/plan-tooltips.constants.mjs.map +1 -0
  407. package/dist/modules/plans/hooks/use-enriched-plans.hook.mjs +28 -0
  408. package/dist/modules/plans/hooks/use-enriched-plans.hook.mjs.map +1 -0
  409. package/dist/modules/plans/hooks/use-ui-plans.hook.mjs +20 -0
  410. package/dist/modules/plans/hooks/use-ui-plans.hook.mjs.map +1 -0
  411. package/dist/modules/projects/hooks/add-project-users.hook.mjs +25 -0
  412. package/dist/modules/projects/hooks/add-project-users.hook.mjs.map +1 -0
  413. package/dist/modules/projects/hooks/list-all-account-users.hook.mjs +3 -6
  414. package/dist/modules/projects/hooks/list-all-account-users.hook.mjs.map +1 -1
  415. package/dist/modules/projects/hooks/list-available-users.hook.mjs +3 -6
  416. package/dist/modules/projects/hooks/list-available-users.hook.mjs.map +1 -1
  417. package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs +3 -6
  418. package/dist/modules/projects/hooks/list-infinite-projects.hook.mjs.map +1 -1
  419. package/dist/modules/projects/hooks/list-project-users.hook.mjs +3 -6
  420. package/dist/modules/projects/hooks/list-project-users.hook.mjs.map +1 -1
  421. package/dist/modules/projects/hooks/remove-project-users.hook.mjs +25 -0
  422. package/dist/modules/projects/hooks/remove-project-users.hook.mjs.map +1 -0
  423. package/dist/modules/projects/services/project-users.service.mjs +5 -0
  424. package/dist/modules/projects/services/project-users.service.mjs.map +1 -1
  425. package/dist/modules/projects/types.mjs +3 -2
  426. package/dist/modules/projects/types.mjs.map +1 -1
  427. package/dist/modules/subscriptions/actions/cancel-subscription.action.mjs +10 -0
  428. package/dist/modules/subscriptions/actions/cancel-subscription.action.mjs.map +1 -0
  429. package/dist/modules/subscriptions/actions/create-subscription.action.mjs +10 -0
  430. package/dist/modules/subscriptions/actions/create-subscription.action.mjs.map +1 -0
  431. package/dist/modules/subscriptions/actions/find-pending-pix-status.action.mjs +10 -0
  432. package/dist/modules/subscriptions/actions/find-pending-pix-status.action.mjs.map +1 -0
  433. package/dist/modules/subscriptions/actions/find-subscription-by-id.action.mjs +10 -0
  434. package/dist/modules/subscriptions/actions/find-subscription-by-id.action.mjs.map +1 -0
  435. package/dist/modules/subscriptions/constants/addons.constants.mjs +35 -0
  436. package/dist/modules/subscriptions/constants/addons.constants.mjs.map +1 -1
  437. package/dist/modules/subscriptions/constants/downgrade.constants.mjs +25 -0
  438. package/dist/modules/subscriptions/constants/downgrade.constants.mjs.map +1 -0
  439. package/dist/modules/subscriptions/constants/subscription.constants.mjs +2 -0
  440. package/dist/modules/subscriptions/constants/subscription.constants.mjs.map +1 -1
  441. package/dist/modules/subscriptions/handlers/pending-pix-status.handler.mjs +15 -0
  442. package/dist/modules/subscriptions/handlers/pending-pix-status.handler.mjs.map +1 -0
  443. package/dist/modules/subscriptions/hooks/cancel-subscription.hook.mjs +25 -0
  444. package/dist/modules/subscriptions/hooks/cancel-subscription.hook.mjs.map +1 -0
  445. package/dist/modules/subscriptions/hooks/create-subscription.hook.mjs +33 -0
  446. package/dist/modules/subscriptions/hooks/create-subscription.hook.mjs.map +1 -0
  447. package/dist/modules/subscriptions/hooks/find-subscription-by-id.hook.mjs +18 -0
  448. package/dist/modules/subscriptions/hooks/find-subscription-by-id.hook.mjs.map +1 -0
  449. package/dist/modules/subscriptions/hooks/pending-pix-status.hook.mjs +25 -0
  450. package/dist/modules/subscriptions/hooks/pending-pix-status.hook.mjs.map +1 -0
  451. package/dist/modules/subscriptions/services/subscriptions.service.mjs +71 -0
  452. package/dist/modules/subscriptions/services/subscriptions.service.mjs.map +1 -1
  453. package/dist/modules/subscriptions/types/cancel-subscription.type.mjs +9 -0
  454. package/dist/modules/subscriptions/types/cancel-subscription.type.mjs.map +1 -0
  455. package/dist/modules/subscriptions/types/create-subscription.type.mjs +62 -0
  456. package/dist/modules/subscriptions/types/create-subscription.type.mjs.map +1 -0
  457. package/dist/modules/subscriptions/types/pending-pix-status.type.mjs +28 -0
  458. package/dist/modules/subscriptions/types/pending-pix-status.type.mjs.map +1 -0
  459. package/dist/modules/subscriptions/types/subscription.type.mjs +9 -1
  460. package/dist/modules/subscriptions/types/subscription.type.mjs.map +1 -1
  461. package/dist/modules/subscriptions/utils/addon-buckets.mjs +69 -0
  462. package/dist/modules/subscriptions/utils/addon-buckets.mjs.map +1 -0
  463. package/dist/modules/subscriptions/utils/confirm-payment-if-required.mjs +8 -2
  464. package/dist/modules/subscriptions/utils/confirm-payment-if-required.mjs.map +1 -1
  465. package/dist/modules/subscriptions/utils/first-period-pricing.mjs +25 -0
  466. package/dist/modules/subscriptions/utils/first-period-pricing.mjs.map +1 -0
  467. package/dist/modules/subscriptions/utils/is-api-subscription.mjs +8 -0
  468. package/dist/modules/subscriptions/utils/is-api-subscription.mjs.map +1 -0
  469. package/dist/modules/subscriptions/utils/is-boleto-payer.mjs +17 -0
  470. package/dist/modules/subscriptions/utils/is-boleto-payer.mjs.map +1 -0
  471. package/dist/modules/subscriptions/utils/is-free-subscription.mjs +8 -0
  472. package/dist/modules/subscriptions/utils/is-free-subscription.mjs.map +1 -0
  473. package/dist/modules/subscriptions/utils/periodicity.mjs +55 -1
  474. package/dist/modules/subscriptions/utils/periodicity.mjs.map +1 -1
  475. package/dist/modules/subscriptions/utils/resolve-subscription-plan-name.mjs +27 -0
  476. package/dist/modules/subscriptions/utils/resolve-subscription-plan-name.mjs.map +1 -0
  477. package/dist/modules/users/hooks/messages.hook.mjs +3 -5
  478. package/dist/modules/users/hooks/messages.hook.mjs.map +1 -1
  479. package/dist/server.mjs +6 -0
  480. package/dist/server.mjs.map +1 -1
  481. package/dist/store/useAccountModals.mjs +9 -2
  482. package/dist/store/useAccountModals.mjs.map +1 -1
  483. package/dist/store/useAffiliateFlows.mjs +23 -0
  484. package/dist/store/useAffiliateFlows.mjs.map +1 -0
  485. package/dist/store/useProjectFlows.mjs +18 -0
  486. package/dist/store/useProjectFlows.mjs.map +1 -0
  487. package/dist/store/useSubscriptionFlows.mjs +58 -0
  488. package/dist/store/useSubscriptionFlows.mjs.map +1 -0
  489. package/dist/store/useTeamFlows.mjs +15 -0
  490. package/dist/store/useTeamFlows.mjs.map +1 -0
  491. package/dist/testing/factories/coupon.factory.mjs +19 -0
  492. package/dist/testing/factories/coupon.factory.mjs.map +1 -0
  493. package/dist/testing/factories/index.mjs +6 -0
  494. package/dist/testing/factories/index.mjs.map +1 -1
  495. package/dist/testing/factories/project-user.factory.mjs +17 -0
  496. package/dist/testing/factories/project-user.factory.mjs.map +1 -0
  497. package/dist/testing/factories/project.factory.mjs +21 -0
  498. package/dist/testing/factories/project.factory.mjs.map +1 -0
  499. package/dist/testing/react/providers.mjs +1 -1
  500. package/dist/testing/react/providers.mjs.map +1 -1
  501. package/dist/utils/browser/chart-custom-tooltip.mjs +69 -0
  502. package/dist/utils/browser/chart-custom-tooltip.mjs.map +1 -0
  503. package/dist/utils/browser/get-css-variable.mjs +9 -0
  504. package/dist/utils/browser/get-css-variable.mjs.map +1 -0
  505. package/dist/utils/constants/scrollbar.mjs +5 -0
  506. package/dist/utils/constants/scrollbar.mjs.map +1 -0
  507. package/dist/utils/date-filter-period.mjs +34 -0
  508. package/dist/utils/date-filter-period.mjs.map +1 -0
  509. package/dist/utils/file/index.mjs +11 -1
  510. package/dist/utils/file/index.mjs.map +1 -1
  511. package/dist/utils/format/initials.mjs +8 -0
  512. package/dist/utils/format/initials.mjs.map +1 -0
  513. package/dist/utils/format/masks.mjs +32 -1
  514. package/dist/utils/format/masks.mjs.map +1 -1
  515. package/dist/utils/qrcode/to-data-url.mjs +12 -0
  516. package/dist/utils/qrcode/to-data-url.mjs.map +1 -0
  517. package/dist/utils/validators/account.mjs +1 -7
  518. package/dist/utils/validators/account.mjs.map +1 -1
  519. package/package.json +20 -8
  520. package/src/components/account/AccountHubLinkHandler.tsx +39 -0
  521. package/src/components/account/AccountModalLayout.tsx +190 -0
  522. package/src/components/account/AccountModals.tsx +12 -2
  523. package/src/components/account/DeleteAccountModal.tsx +1 -1
  524. package/src/components/account/IsntPossibleDeleteAccountModal.tsx +9 -1
  525. package/src/components/account/MyAccountModal.tsx +215 -0
  526. package/src/components/account/TwoFactorAuthModal.tsx +1 -1
  527. package/src/components/account/hooks/useAccountHubActions.ts +95 -0
  528. package/src/components/account/hooks/useAddCardWithPaymentSwitch.ts +70 -0
  529. package/src/components/account/hooks/useAffiliatesActions.tsx +78 -0
  530. package/src/components/account/hooks/useMyAccountModal.ts +40 -0
  531. package/src/components/account/hooks/useProjectsActions.ts +44 -0
  532. package/src/components/account/hooks/useSubscriptionActions.ts +99 -0
  533. package/src/components/account/hooks/useTeamActions.ts +35 -0
  534. package/src/components/account/sections/AffiliatesSection.tsx +342 -0
  535. package/src/components/account/sections/ChangePasswordSection.tsx +6 -10
  536. package/src/components/account/sections/MyProfileSection.tsx +207 -143
  537. package/src/components/account/sections/PreferencesSection.tsx +55 -51
  538. package/src/components/account/sections/ProjectsSection.tsx +110 -0
  539. package/src/components/account/sections/SecuritySection.tsx +72 -62
  540. package/src/components/account/sections/SubscriptionSection.tsx +36 -0
  541. package/src/components/account/sections/TeamSection.tsx +161 -0
  542. package/src/components/account/sections/TokenSection.tsx +4 -8
  543. package/src/components/account/sections/affiliates/AffiliateCommissionCard.tsx +83 -0
  544. package/src/components/account/sections/affiliates/AffiliateFlows.tsx +20 -0
  545. package/src/components/account/sections/affiliates/AffiliateLeadsSheet.tsx +143 -0
  546. package/src/components/account/sections/affiliates/AffiliateStatsCard.tsx +56 -0
  547. package/src/components/account/sections/affiliates/AffiliateStepCard.tsx +20 -0
  548. package/src/components/account/sections/affiliates/AffiliateTransactionsList.tsx +194 -0
  549. package/src/components/account/sections/affiliates/NoReceivingAccountModal.tsx +63 -0
  550. package/src/components/account/sections/affiliates/ReceivingAccountModal.tsx +213 -0
  551. package/src/components/account/sections/affiliates/RequestWithdrawalSheet.tsx +586 -0
  552. package/src/components/account/sections/affiliates/ViewAttachmentModal.tsx +47 -0
  553. package/src/components/account/sections/affiliates/reports/AffiliatesIndicatorsChart.tsx +45 -0
  554. package/src/components/account/sections/affiliates/reports/AffiliatesReportsTab.tsx +44 -0
  555. package/src/components/account/sections/affiliates/reports/useAffiliatesIndicatorsChart.ts +148 -0
  556. package/src/components/account/sections/projects/DeleteProjectModal.tsx +246 -0
  557. package/src/components/account/sections/projects/ProjectFlows.tsx +16 -0
  558. package/src/components/account/sections/projects/ProjectMembersStack.tsx +75 -0
  559. package/src/components/account/sections/projects/ProjectRow.tsx +96 -0
  560. package/src/components/account/sections/projects/ProjectSheet.tsx +603 -0
  561. package/src/components/account/sections/projects/ProjectsDisabledModal.tsx +69 -0
  562. package/src/components/account/sections/projects/project-form.schema.ts +30 -0
  563. package/src/components/account/sections/shared/ConnectListRow.tsx +68 -0
  564. package/src/components/account/sections/shared/DateFilterPopover.tsx +58 -0
  565. package/src/components/account/sections/shared/EntityAvatar.tsx +54 -0
  566. package/src/components/account/sections/shared/FilterPopover.tsx +79 -0
  567. package/src/components/account/sections/shared/FormSection.tsx +23 -0
  568. package/src/components/account/sections/shared/IconBox.tsx +21 -0
  569. package/src/components/account/sections/shared/InfiniteScrollList.tsx +57 -0
  570. package/src/components/account/sections/shared/ListPagination.tsx +84 -0
  571. package/src/components/account/sections/shared/RowActionsMenu.tsx +66 -0
  572. package/src/components/account/sections/shared/SectionLoadError.tsx +27 -0
  573. package/src/components/account/sections/shared/StatusBadge.tsx +33 -0
  574. package/src/components/account/sections/shared/WorkspaceSection.tsx +22 -0
  575. package/src/components/account/sections/subscription/AiCreditsUsage.tsx +152 -0
  576. package/src/components/account/sections/subscription/BillingAddressSheet.tsx +460 -0
  577. package/src/components/account/sections/subscription/BoletoDetailsDialog.tsx +104 -0
  578. package/src/components/account/sections/subscription/BoletoGeneratedDialog.tsx +24 -0
  579. package/src/components/account/sections/subscription/CancelPlanDialog.tsx +221 -0
  580. package/src/components/account/sections/subscription/ChargeRow.tsx +161 -0
  581. package/src/components/account/sections/subscription/ChargeStatusBadge.tsx +29 -0
  582. package/src/components/account/sections/subscription/ChargesList.tsx +125 -0
  583. package/src/components/account/sections/subscription/ManageCardsSheet.tsx +93 -0
  584. package/src/components/account/sections/subscription/OverdueReceiptOpener.tsx +29 -0
  585. package/src/components/account/sections/subscription/PayChargeDialog.tsx +306 -0
  586. package/src/components/account/sections/subscription/PaymentConfirmationDialog.tsx +70 -0
  587. package/src/components/account/sections/subscription/PaymentMethodsCard.tsx +117 -0
  588. package/src/components/account/sections/subscription/PendingChangeDialog.tsx +168 -0
  589. package/src/components/account/sections/subscription/PixDetailsDialog.tsx +246 -0
  590. package/src/components/account/sections/subscription/PixPaymentDialog.tsx +242 -0
  591. package/src/components/account/sections/subscription/PlanDetailsSheet.tsx +380 -0
  592. package/src/components/account/sections/subscription/ReceiptDetailsSheet.tsx +318 -0
  593. package/src/components/account/sections/subscription/SubscriptionFlows.tsx +40 -0
  594. package/src/components/account/sections/subscription/SubscriptionPlanCard.tsx +433 -0
  595. package/src/components/account/sections/subscription/UsageReportSheet.tsx +244 -0
  596. package/src/components/account/sections/subscription/change-plan/ChangePlanSheet.tsx +95 -0
  597. package/src/components/account/sections/subscription/change-plan/components/AbTestDetailsDialog.tsx +57 -0
  598. package/src/components/account/sections/subscription/change-plan/components/AddonsBlock.tsx +214 -0
  599. package/src/components/account/sections/subscription/change-plan/components/AlternativeBucketsSection.tsx +92 -0
  600. package/src/components/account/sections/subscription/change-plan/components/CouponBlock.tsx +42 -0
  601. package/src/components/account/sections/subscription/change-plan/components/CouponDialog.tsx +134 -0
  602. package/src/components/account/sections/subscription/change-plan/components/PricePreview.tsx +28 -0
  603. package/src/components/account/sections/subscription/change-plan/components/SummaryBlock.tsx +194 -0
  604. package/src/components/account/sections/subscription/change-plan/plan-comparison.ts +52 -0
  605. package/src/components/account/sections/subscription/change-plan/steps/PaymentSummaryStep.tsx +161 -0
  606. package/src/components/account/sections/subscription/change-plan/steps/PlanComparisonStep.tsx +165 -0
  607. package/src/components/account/sections/subscription/change-plan/steps/PlanViewStep.tsx +89 -0
  608. package/src/components/account/sections/subscription/change-plan/steps/ReactivationConfigStep.tsx +117 -0
  609. package/src/components/account/sections/subscription/change-plan/steps/ReactivationPaymentStep.tsx +139 -0
  610. package/src/components/account/sections/subscription/change-plan/useChangePlanState.tsx +1158 -0
  611. package/src/components/account/sections/subscription/downgrade/CannotDowngradeDialog.tsx +297 -0
  612. package/src/components/account/sections/subscription/downgrade/DowngradeReasonDialog.tsx +154 -0
  613. package/src/components/account/sections/subscription/plans/PlanCard.tsx +417 -0
  614. package/src/components/account/sections/subscription/plans/PlanCardSkeleton.tsx +70 -0
  615. package/src/components/account/sections/subscription/plans/PlansCatalogDialog.tsx +156 -0
  616. package/src/components/account/sections/team/DeleteUserModal.tsx +134 -0
  617. package/src/components/account/sections/team/TeamFlows.tsx +14 -0
  618. package/src/components/account/sections/team/TeamMemberRow.tsx +151 -0
  619. package/src/components/account/sections/team/UserSheet.tsx +688 -0
  620. package/src/components/account/sections/team/steps/NotificationsStep.tsx +109 -0
  621. package/src/components/account/sections/team/steps/ProjectSelectionStep.tsx +219 -0
  622. package/src/components/account/sections/team/steps/UserInformationStep.tsx +423 -0
  623. package/src/components/account/sections/team/user-form.schema.ts +43 -0
  624. package/src/components/account/types/workspace-actions.type.ts +56 -0
  625. package/src/components/layouts/ProfilePopover.tsx +11 -12
  626. package/src/components/layouts/UsersSelectorPopover.tsx +7 -4
  627. package/src/components/modals/AccountDeletionWarningModal.tsx +4 -5
  628. package/src/components/modals/AccountFrozenModal.tsx +6 -3
  629. package/src/components/modals/Modals.tsx +6 -3
  630. package/src/components/modals/PaidPlanRequiredModal.tsx +4 -5
  631. package/src/components/modals/cards/AddFirstCardWarningModal.tsx +72 -0
  632. package/src/components/modals/cards/SwitchPaymentToCardModal.tsx +232 -0
  633. package/src/components/modals/promo/AiCreditsOfferModal/AiCreditsOfferModal.tsx +5 -4
  634. package/src/components/ui/data-display/CardItem.tsx +9 -5
  635. package/src/components/ui/data-display/PaymentMethodIcons.tsx +43 -0
  636. package/src/components/ui/form/BillingPeriodSelector.tsx +173 -0
  637. package/src/components/ui/form/PaymentMethodToggle.tsx +119 -0
  638. package/src/components/ui/form/RadioOptionFieldIcon.tsx +64 -0
  639. package/src/components/ui/form/SegmentedControl.tsx +77 -0
  640. package/src/components/ui/overlay/Dialog.tsx +70 -33
  641. package/src/components/ui/overlay/Sheet.tsx +89 -56
  642. package/src/components/ui/overlay/layers.tsx +114 -27
  643. package/src/enums/AccountHubFlow.ts +8 -0
  644. package/src/enums/DateFilterPeriod.ts +17 -0
  645. package/src/enums/WorkspaceSectionType.ts +6 -0
  646. package/src/handlers.ts +14 -0
  647. package/src/hooks/useDebounce.ts +5 -3
  648. package/src/hooks/useUploadProgress.ts +42 -0
  649. package/src/i18n/messages/en-us.ts +904 -2
  650. package/src/i18n/messages/es-es.ts +908 -2
  651. package/src/i18n/messages/pt-br.ts +908 -2
  652. package/src/index.ts +56 -1
  653. package/src/infra/http/paged.ts +24 -0
  654. package/src/middleware.ts +1 -0
  655. package/src/middlewares/create-auth-middleware.ts +1 -4
  656. package/src/middlewares/create-legacy-account-routes-middleware.ts +54 -0
  657. package/src/middlewares/is-route-equals.ts +3 -0
  658. package/src/modules/accounts/actions/account-management.action.ts +22 -1
  659. package/src/modules/accounts/constants/account-hub-link.constants.ts +3 -0
  660. package/src/modules/accounts/constants/legacy-account-routes.constants.ts +1 -0
  661. package/src/modules/accounts/handlers/list-account-members.handler.ts +23 -0
  662. package/src/modules/accounts/hooks/add-user-projects.hook.ts +72 -0
  663. package/src/modules/accounts/hooks/create-account-user.hook.ts +21 -0
  664. package/src/modules/accounts/hooks/remove-user-projects.hook.ts +68 -0
  665. package/src/modules/accounts/hooks/use-account-members.hook.ts +31 -0
  666. package/src/modules/accounts/services/account.service.ts +71 -0
  667. package/src/modules/accounts/types/account-hub-link.type.ts +13 -0
  668. package/src/modules/accounts/types.ts +9 -0
  669. package/src/modules/accounts/utils/build-account-hub-url.ts +14 -0
  670. package/src/modules/accounts/utils/is-account-hub-flow.ts +7 -0
  671. package/src/modules/accounts/utils/is-account-section.ts +7 -0
  672. package/src/modules/accounts/utils/is-my-account-section.ts +12 -0
  673. package/src/modules/accounts/utils/map-legacy-account-route.ts +108 -0
  674. package/src/modules/accounts/utils/parse-account-hub-link.ts +21 -0
  675. package/src/modules/affiliates/actions/ensure-affiliate.action.ts +9 -0
  676. package/src/modules/affiliates/actions/request-deposit.action.ts +9 -0
  677. package/src/modules/affiliates/actions/update-affiliate.action.ts +9 -0
  678. package/src/modules/affiliates/constants/affiliate.constants.ts +11 -0
  679. package/src/modules/affiliates/constants/query-keys.constants.ts +7 -0
  680. package/src/modules/affiliates/handlers/affiliate-report-analytics.handler.ts +16 -0
  681. package/src/modules/affiliates/handlers/affiliate-withdrawal-limits.handler.ts +10 -0
  682. package/src/modules/affiliates/handlers/current-affiliate.handler.ts +10 -0
  683. package/src/modules/affiliates/handlers/list-affiliate-coupons.handler.ts +10 -0
  684. package/src/modules/affiliates/handlers/list-affiliate-leads.handler.ts +23 -0
  685. package/src/modules/affiliates/handlers/list-affiliate-transactions.handler.ts +23 -0
  686. package/src/modules/affiliates/hooks/use-affiliate-coupons.hook.ts +19 -0
  687. package/src/modules/affiliates/hooks/use-affiliate-leads.hook.ts +27 -0
  688. package/src/modules/affiliates/hooks/use-affiliate-report-analytics.hook.ts +19 -0
  689. package/src/modules/affiliates/hooks/use-affiliate-transactions.hook.ts +25 -0
  690. package/src/modules/affiliates/hooks/use-current-affiliate.hook.ts +19 -0
  691. package/src/modules/affiliates/hooks/use-ensure-affiliate.hook.ts +24 -0
  692. package/src/modules/affiliates/hooks/use-request-deposit.hook.ts +29 -0
  693. package/src/modules/affiliates/hooks/use-update-affiliate.hook.ts +24 -0
  694. package/src/modules/affiliates/hooks/use-withdrawal-limits.hook.ts +20 -0
  695. package/src/modules/affiliates/services/affiliates.service.ts +240 -0
  696. package/src/modules/affiliates/types/affiliate.type.ts +180 -0
  697. package/src/modules/affiliates/utils/get-affiliate-share-link.ts +8 -0
  698. package/src/modules/charges/actions/get-nota-fiscal.action.ts +8 -0
  699. package/src/modules/charges/actions/refresh-pix.action.ts +8 -0
  700. package/src/modules/charges/hooks/nota-fiscal.hook.ts +13 -0
  701. package/src/modules/charges/hooks/refresh-pix.hook.ts +13 -0
  702. package/src/modules/charges/services/charges.service.ts +121 -0
  703. package/src/modules/charges/types/nota-fiscal.type.ts +20 -0
  704. package/src/modules/charges/types/refresh-pix.type.ts +14 -0
  705. package/src/modules/charges/utils/get-charge-download-url.ts +10 -0
  706. package/src/modules/coupons/constants/query-keys.constants.ts +1 -0
  707. package/src/modules/coupons/handlers/find-coupon-by-code.handler.ts +16 -0
  708. package/src/modules/coupons/handlers/find-coupon-by-id.handler.ts +15 -0
  709. package/src/modules/coupons/hooks/use-coupon-by-code.hook.ts +16 -0
  710. package/src/modules/coupons/hooks/use-coupon-by-id.hook.ts +20 -0
  711. package/src/modules/coupons/services/coupons.service.ts +54 -0
  712. package/src/modules/coupons/types/coupon.type.ts +70 -0
  713. package/src/modules/coupons/utils/coupon-restrictions.ts +112 -0
  714. package/src/modules/domains/handlers/count-domains.handler.ts +10 -0
  715. package/src/modules/domains/hooks/count-domains.hook.ts +17 -0
  716. package/src/modules/domains/services/domains.service.ts +18 -0
  717. package/src/modules/ia-credits/handlers/list-ia-credit-operations.handler.ts +14 -0
  718. package/src/modules/ia-credits/hooks/ia-credit-operations.hook.ts +33 -0
  719. package/src/modules/ia-credits/services/ia-credits.service.ts +32 -1
  720. package/src/modules/pages/handlers/count-pages.handler.ts +5 -2
  721. package/src/modules/pages/hooks/count-published-pages.hook.ts +26 -0
  722. package/src/modules/pages/services/pages.service.ts +3 -2
  723. package/src/modules/plans/constants/plan-tooltips.constants.ts +16 -0
  724. package/src/modules/plans/hooks/use-enriched-plans.hook.ts +31 -0
  725. package/src/modules/plans/hooks/use-ui-plans.hook.ts +22 -0
  726. package/src/modules/projects/hooks/add-project-users.hook.ts +29 -0
  727. package/src/modules/projects/hooks/list-all-account-users.hook.ts +3 -6
  728. package/src/modules/projects/hooks/list-available-users.hook.ts +3 -6
  729. package/src/modules/projects/hooks/list-infinite-projects.hook.ts +3 -6
  730. package/src/modules/projects/hooks/list-project-users.hook.ts +3 -6
  731. package/src/modules/projects/hooks/remove-project-users.hook.ts +29 -0
  732. package/src/modules/projects/services/project-users.service.ts +135 -130
  733. package/src/modules/projects/types.ts +89 -88
  734. package/src/modules/subscriptions/actions/cancel-subscription.action.ts +12 -0
  735. package/src/modules/subscriptions/actions/create-subscription.action.ts +9 -0
  736. package/src/modules/subscriptions/actions/find-pending-pix-status.action.ts +8 -0
  737. package/src/modules/subscriptions/actions/find-subscription-by-id.action.ts +8 -0
  738. package/src/modules/subscriptions/constants/addons.constants.ts +50 -0
  739. package/src/modules/subscriptions/constants/downgrade.constants.ts +30 -0
  740. package/src/modules/subscriptions/constants/subscription.constants.ts +3 -0
  741. package/src/modules/subscriptions/handlers/pending-pix-status.handler.ts +17 -0
  742. package/src/modules/subscriptions/hooks/cancel-subscription.hook.ts +28 -0
  743. package/src/modules/subscriptions/hooks/create-subscription.hook.ts +34 -0
  744. package/src/modules/subscriptions/hooks/find-subscription-by-id.hook.ts +17 -0
  745. package/src/modules/subscriptions/hooks/pending-pix-status.hook.ts +30 -0
  746. package/src/modules/subscriptions/services/subscriptions.service.ts +401 -301
  747. package/src/modules/subscriptions/types/cancel-subscription.type.ts +8 -0
  748. package/src/modules/subscriptions/types/create-subscription.type.ts +79 -0
  749. package/src/modules/subscriptions/types/pending-pix-status.type.ts +33 -0
  750. package/src/modules/subscriptions/types/subscription.type.ts +157 -147
  751. package/src/modules/subscriptions/utils/addon-buckets.ts +129 -0
  752. package/src/modules/subscriptions/utils/confirm-payment-if-required.ts +9 -2
  753. package/src/modules/subscriptions/utils/first-period-pricing.ts +63 -0
  754. package/src/modules/subscriptions/utils/is-api-subscription.ts +6 -0
  755. package/src/modules/subscriptions/utils/is-boleto-payer.ts +21 -0
  756. package/src/modules/subscriptions/utils/is-free-subscription.ts +6 -0
  757. package/src/modules/subscriptions/utils/periodicity.ts +101 -0
  758. package/src/modules/subscriptions/utils/resolve-subscription-plan-name.ts +44 -0
  759. package/src/modules/users/hooks/messages.hook.ts +3 -5
  760. package/src/server.ts +102 -99
  761. package/src/store/useAccountModals.ts +22 -5
  762. package/src/store/useAffiliateFlows.ts +46 -0
  763. package/src/store/useProjectFlows.ts +42 -0
  764. package/src/store/useSubscriptionFlows.ts +176 -0
  765. package/src/store/useTeamFlows.ts +34 -0
  766. package/src/testing/factories/coupon.factory.ts +17 -0
  767. package/src/testing/factories/index.ts +3 -0
  768. package/src/testing/factories/project-user.factory.ts +15 -0
  769. package/src/testing/factories/project.factory.ts +19 -0
  770. package/src/testing/react/providers.tsx +2 -1
  771. package/src/utils/browser/chart-custom-tooltip.ts +85 -0
  772. package/src/utils/browser/get-css-variable.ts +6 -0
  773. package/src/utils/constants/scrollbar.ts +10 -0
  774. package/src/utils/date-filter-period.ts +34 -0
  775. package/src/utils/file/index.ts +13 -0
  776. package/src/utils/format/initials.ts +10 -0
  777. package/src/utils/format/masks.ts +41 -0
  778. package/src/utils/qrcode/to-data-url.ts +23 -0
  779. package/src/utils/validators/account.ts +0 -8
  780. package/dist/components/account/ConfigurationsMyAccountModal.mjs +0 -143
  781. package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +0 -1
  782. package/dist/components/account/hooks/useConfigurationsModal.mjs +0 -34
  783. package/dist/components/account/hooks/useConfigurationsModal.mjs.map +0 -1
  784. package/src/components/account/ConfigurationsMyAccountModal.tsx +0 -179
  785. package/src/components/account/hooks/useConfigurationsModal.ts +0 -45
@@ -0,0 +1,33 @@
1
+ "use client";
2
+ import { useMutation, useQueryClient } from "@tanstack/react-query";
3
+ import { useStripe } from "@stripe/react-stripe-js";
4
+ import { useTranslations } from "next-intl";
5
+ import { withAction } from "../../../utils/withAction";
6
+ import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
7
+ import { createSubscriptionAction } from "../actions/create-subscription.action";
8
+ import { SUBSCRIPTIONS_QUERY_KEY, CHARGES_QUERY_KEY } from "../constants/query-keys.constants";
9
+ import { confirmPaymentIfRequired } from "../utils/confirm-payment-if-required";
10
+ function useCreateSubscription() {
11
+ const queryClient = useQueryClient();
12
+ const stripe = useStripe();
13
+ const translate = useTranslations();
14
+ const subscriptionsKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY]);
15
+ const chargesKey = useAuthQueryKey([...CHARGES_QUERY_KEY]);
16
+ const iaCreditsKey = useAuthQueryKey(["ia-credits"]);
17
+ return useMutation({
18
+ mutationFn: async (data) => {
19
+ const result = await withAction(createSubscriptionAction)(data);
20
+ await confirmPaymentIfRequired(stripe, result, translate("common.payment.authFailed"));
21
+ return result;
22
+ },
23
+ onSettled: () => {
24
+ queryClient.invalidateQueries({ queryKey: subscriptionsKey });
25
+ queryClient.invalidateQueries({ queryKey: chargesKey });
26
+ queryClient.invalidateQueries({ queryKey: iaCreditsKey });
27
+ }
28
+ });
29
+ }
30
+ export {
31
+ useCreateSubscription
32
+ };
33
+ //# sourceMappingURL=create-subscription.hook.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/hooks/create-subscription.hook.ts"],"sourcesContent":["'use client';\n\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { useStripe } from '@stripe/react-stripe-js';\nimport { useTranslations } from 'next-intl';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { createSubscriptionAction } from '../actions/create-subscription.action';\nimport { SUBSCRIPTIONS_QUERY_KEY, CHARGES_QUERY_KEY } from '../constants/query-keys.constants';\nimport { confirmPaymentIfRequired } from '../utils/confirm-payment-if-required';\nimport type { CreateSubscriptionRequest } from '../types/create-subscription.type';\n\nexport function useCreateSubscription() {\n const queryClient = useQueryClient();\n const stripe = useStripe();\n const translate = useTranslations();\n const subscriptionsKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY]);\n const chargesKey = useAuthQueryKey([...CHARGES_QUERY_KEY]);\n const iaCreditsKey = useAuthQueryKey(['ia-credits']);\n\n return useMutation({\n mutationFn: async (data: CreateSubscriptionRequest) => {\n const result = await withAction(createSubscriptionAction)(data);\n // Cobrança que exige 3DS volta com client_secret e só completa depois do desafio.\n await confirmPaymentIfRequired(stripe, result, translate('common.payment.authFailed'));\n return result;\n },\n onSettled: () => {\n queryClient.invalidateQueries({ queryKey: subscriptionsKey });\n queryClient.invalidateQueries({ queryKey: chargesKey });\n queryClient.invalidateQueries({ queryKey: iaCreditsKey });\n },\n });\n}\n"],"mappings":";AAEA,SAAS,aAAa,sBAAsB;AAC5C,SAAS,iBAAiB;AAC1B,SAAS,uBAAuB;AAChC,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,gCAAgC;AACzC,SAAS,yBAAyB,yBAAyB;AAC3D,SAAS,gCAAgC;AAGlC,SAAS,wBAAwB;AACtC,QAAM,cAAc,eAAe;AACnC,QAAM,SAAS,UAAU;AACzB,QAAM,YAAY,gBAAgB;AAClC,QAAM,mBAAmB,gBAAgB,CAAC,GAAG,uBAAuB,CAAC;AACrE,QAAM,aAAa,gBAAgB,CAAC,GAAG,iBAAiB,CAAC;AACzD,QAAM,eAAe,gBAAgB,CAAC,YAAY,CAAC;AAEnD,SAAO,YAAY;AAAA,IACjB,YAAY,OAAO,SAAoC;AACrD,YAAM,SAAS,MAAM,WAAW,wBAAwB,EAAE,IAAI;AAE9D,YAAM,yBAAyB,QAAQ,QAAQ,UAAU,2BAA2B,CAAC;AACrF,aAAO;AAAA,IACT;AAAA,IACA,WAAW,MAAM;AACf,kBAAY,kBAAkB,EAAE,UAAU,iBAAiB,CAAC;AAC5D,kBAAY,kBAAkB,EAAE,UAAU,WAAW,CAAC;AACtD,kBAAY,kBAAkB,EAAE,UAAU,aAAa,CAAC;AAAA,IAC1D;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -0,0 +1,18 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { withAction } from "../../../utils/withAction";
4
+ import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
5
+ import { findSubscriptionByIdAction } from "../actions/find-subscription-by-id.action";
6
+ import { SUBSCRIPTIONS_QUERY_KEY } from "../constants/query-keys.constants";
7
+ function useSubscriptionById(subscriptionId) {
8
+ const queryKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY, "by-id", subscriptionId]);
9
+ return useQuery({
10
+ queryKey,
11
+ queryFn: () => withAction(findSubscriptionByIdAction)(subscriptionId),
12
+ enabled: subscriptionId != null && subscriptionId !== ""
13
+ });
14
+ }
15
+ export {
16
+ useSubscriptionById
17
+ };
18
+ //# sourceMappingURL=find-subscription-by-id.hook.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/hooks/find-subscription-by-id.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { withAction } from '../../../utils/withAction';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport { findSubscriptionByIdAction } from '../actions/find-subscription-by-id.action';\nimport { SUBSCRIPTIONS_QUERY_KEY } from '../constants/query-keys.constants';\n\nexport function useSubscriptionById(subscriptionId: string | number | undefined) {\n const queryKey = useAuthQueryKey([...SUBSCRIPTIONS_QUERY_KEY, 'by-id', subscriptionId]);\n\n return useQuery({\n queryKey,\n queryFn: () => withAction(findSubscriptionByIdAction)(subscriptionId!),\n enabled: subscriptionId != null && subscriptionId !== '',\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,uBAAuB;AAChC,SAAS,kCAAkC;AAC3C,SAAS,+BAA+B;AAEjC,SAAS,oBAAoB,gBAA6C;AAC/E,QAAM,WAAW,gBAAgB,CAAC,GAAG,yBAAyB,SAAS,cAAc,CAAC;AAEtF,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,MAAM,WAAW,0BAA0B,EAAE,cAAe;AAAA,IACrE,SAAS,kBAAkB,QAAQ,mBAAmB;AAAA,EACxD,CAAC;AACH;","names":[]}
@@ -0,0 +1,25 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import { apiFetch } from "../../../infra/http/api-fetch";
4
+ import { useAuthQueryKey } from "../../../hooks/useAuthQueryKey";
5
+ const TERMINAL_PHASES = ["completed", "rejected", "expired"];
6
+ const isTerminal = (phase) => !!phase && TERMINAL_PHASES.includes(phase);
7
+ function usePendingPixStatus(correlationId) {
8
+ const queryKey = useAuthQueryKey(["pending-pix-status", correlationId]);
9
+ return useQuery({
10
+ queryKey,
11
+ queryFn: ({ signal }) => apiFetch(
12
+ `/api/subscriptions/pending-pix/${correlationId}`,
13
+ { signal }
14
+ ),
15
+ enabled: Boolean(correlationId),
16
+ refetchInterval: (query) => isTerminal(query.state.data?.data?.phase) ? false : 15e3,
17
+ refetchOnWindowFocus: (query) => !isTerminal(query.state.data?.data?.phase),
18
+ refetchOnReconnect: (query) => !isTerminal(query.state.data?.data?.phase),
19
+ refetchOnMount: (query) => isTerminal(query.state.data?.data?.phase) ? false : "always"
20
+ });
21
+ }
22
+ export {
23
+ usePendingPixStatus
24
+ };
25
+ //# sourceMappingURL=pending-pix-status.hook.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/hooks/pending-pix-status.hook.ts"],"sourcesContent":["'use client';\n\nimport { useQuery } from '@tanstack/react-query';\nimport { apiFetch } from '../../../infra/http/api-fetch';\nimport { useAuthQueryKey } from '../../../hooks/useAuthQueryKey';\nimport type { SuccessResult } from '../../../infra/api/types';\nimport type { PendingPixStatusData } from '../types/pending-pix-status.type';\n\nconst TERMINAL_PHASES = ['completed', 'rejected', 'expired'];\n\nconst isTerminal = (phase?: string) => !!phase && TERMINAL_PHASES.includes(phase);\n\n/** Status do pix pendente, em polling de 15s até chegar numa fase terminal. */\nexport function usePendingPixStatus(correlationId?: string | null) {\n const queryKey = useAuthQueryKey(['pending-pix-status', correlationId]);\n\n return useQuery({\n queryKey,\n queryFn: ({ signal }) =>\n apiFetch<SuccessResult<PendingPixStatusData>>(\n `/api/subscriptions/pending-pix/${correlationId}`,\n { signal }\n ),\n enabled: Boolean(correlationId),\n refetchInterval: (query) => (isTerminal(query.state.data?.data?.phase) ? false : 15_000),\n refetchOnWindowFocus: (query) => !isTerminal(query.state.data?.data?.phase),\n refetchOnReconnect: (query) => !isTerminal(query.state.data?.data?.phase),\n refetchOnMount: (query) => (isTerminal(query.state.data?.data?.phase) ? false : 'always'),\n });\n}\n"],"mappings":";AAEA,SAAS,gBAAgB;AACzB,SAAS,gBAAgB;AACzB,SAAS,uBAAuB;AAIhC,MAAM,kBAAkB,CAAC,aAAa,YAAY,SAAS;AAE3D,MAAM,aAAa,CAAC,UAAmB,CAAC,CAAC,SAAS,gBAAgB,SAAS,KAAK;AAGzE,SAAS,oBAAoB,eAA+B;AACjE,QAAM,WAAW,gBAAgB,CAAC,sBAAsB,aAAa,CAAC;AAEtE,SAAO,SAAS;AAAA,IACd;AAAA,IACA,SAAS,CAAC,EAAE,OAAO,MACjB;AAAA,MACE,kCAAkC,aAAa;AAAA,MAC/C,EAAE,OAAO;AAAA,IACX;AAAA,IACF,SAAS,QAAQ,aAAa;AAAA,IAC9B,iBAAiB,CAAC,UAAW,WAAW,MAAM,MAAM,MAAM,MAAM,KAAK,IAAI,QAAQ;AAAA,IACjF,sBAAsB,CAAC,UAAU,CAAC,WAAW,MAAM,MAAM,MAAM,MAAM,KAAK;AAAA,IAC1E,oBAAoB,CAAC,UAAU,CAAC,WAAW,MAAM,MAAM,MAAM,MAAM,KAAK;AAAA,IACxE,gBAAgB,CAAC,UAAW,WAAW,MAAM,MAAM,MAAM,MAAM,KAAK,IAAI,QAAQ;AAAA,EAClF,CAAC;AACH;","names":[]}
@@ -9,6 +9,13 @@ import { getUserContext } from "../../auth/utils/get-user-context";
9
9
  import {
10
10
  SubscriptionSchema
11
11
  } from "../types/subscription.type";
12
+ import {
13
+ isPendingPixCreateSubscriptionResponse,
14
+ CreateSubscriptionPendingPixResponseSchema
15
+ } from "../types/create-subscription.type";
16
+ import {
17
+ PendingPixStatusDataSchema
18
+ } from "../types/pending-pix-status.type";
12
19
  import {
13
20
  CalculateSubscriptionResponseSchema
14
21
  } from "../types/calculate-subscription.type";
@@ -138,6 +145,70 @@ class SubscriptionsService {
138
145
  ...response.charge_now ? { charge_now: response.charge_now } : {}
139
146
  };
140
147
  }
148
+ async findSubscriptionById(subscriptionId) {
149
+ const { id_account } = await getUserContext();
150
+ const response = await api.apps.get(
151
+ `/accounts/${id_account}/subscriptions/${subscriptionId}`
152
+ );
153
+ if (response.status === 0 || !response.data?.[0]) {
154
+ throw new ApiError("Assinatura n\xE3o encontrada", "FIND_SUBSCRIPTION_FAILED", 400);
155
+ }
156
+ return { success: true, data: SubscriptionSchema.parse(response.data[0]) };
157
+ }
158
+ async cancelSubscription(subscriptionId, data) {
159
+ await assertManagementPermission("manage_subscriptions");
160
+ const { id_account } = await getUserContext();
161
+ const response = await api.apps.put(
162
+ `/accounts/${id_account}/subscriptions/${subscriptionId}/action/cancel`,
163
+ data
164
+ );
165
+ if (response.status === 0) {
166
+ throw new ApiError(
167
+ response.message || "Erro ao cancelar assinatura",
168
+ "CANCEL_SUBSCRIPTION_FAILED",
169
+ 400
170
+ );
171
+ }
172
+ return { success: true };
173
+ }
174
+ /** Contratação de plano. Pode devolver um pix pendente no lugar da assinatura. */
175
+ async createSubscription(data) {
176
+ const { id_account } = await getUserContext();
177
+ const response = await api.apps.post(`/accounts/${id_account}/subscriptions`, data);
178
+ if (response.status === 0) {
179
+ throw new ApiError(
180
+ response.message || "Erro ao criar assinatura",
181
+ "CREATE_SUBSCRIPTION_FAILED",
182
+ 400
183
+ );
184
+ }
185
+ return {
186
+ success: true,
187
+ data: (response.data ?? []).map(
188
+ (item) => isPendingPixCreateSubscriptionResponse(item) ? CreateSubscriptionPendingPixResponseSchema.parse(item) : SubscriptionSchema.parse(item)
189
+ ),
190
+ total: response.total,
191
+ ...response.client_secret ? { client_secret: response.client_secret } : {}
192
+ };
193
+ }
194
+ /** Status do pix pendente, consultado em polling enquanto o cliente paga. */
195
+ async findPendingPixStatus(correlationId) {
196
+ const { id_account } = await getUserContext();
197
+ const response = await api.apps.get(
198
+ `/accounts/${id_account}/subscriptions/pending-pix/${encodeURIComponent(correlationId)}`
199
+ );
200
+ if (response.status === 0) {
201
+ throw new ApiError(
202
+ response.message || "Erro ao consultar o status do Pix",
203
+ "FIND_PENDING_PIX_STATUS_FAILED",
204
+ 400
205
+ );
206
+ }
207
+ if (!response.data?.length) {
208
+ throw new ApiError("Pix pendente n\xE3o encontrado", "PENDING_PIX_NOT_FOUND", 404);
209
+ }
210
+ return { success: true, data: PendingPixStatusDataSchema.parse(response.data[0]) };
211
+ }
141
212
  async getFreezeNotice() {
142
213
  const { id_account } = await getUserContext();
143
214
  const response = await api.apps.get(
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/subscriptions/services/subscriptions.service.ts"],"sourcesContent":["import \"server-only\";\r\n\r\nimport { api } from \"../../../infra/api/client\";\r\nimport {\r\n ApiError,\r\n ApiActionResult,\r\n ApiPaginatedActionResult,\r\n PaginatedSuccessResult,\r\n SuccessResult,\r\n} from \"../../../infra/api/types\";\r\nimport { buildQueryParams } from \"../../../infra/utils/params\";\r\nimport { assertManagementPermission } from \"../../auth/utils/assert-management-permission\";\r\nimport { getUserContext } from \"../../auth/utils/get-user-context\";\r\nimport {\r\n Subscription,\r\n SubscriptionSchema,\r\n FindSubscriptionsParams,\r\n type ChargeNowResult,\r\n} from \"../types/subscription.type\";\r\nimport {\r\n type CalculateSubscriptionRequest,\r\n type CalculateSubscriptionResponse,\r\n type UpdateSubscriptionPlanRequest,\r\n CalculateSubscriptionResponseSchema,\r\n} from \"../types/calculate-subscription.type\";\r\nimport {\r\n SubscriptionPendingPixResponseSchema,\r\n type SubscriptionPendingPixResponse,\r\n} from \"../types/pix-pending.type\";\r\nimport type { FreezeNotice } from \"../types/freeze-notice.type\";\r\n\r\n/**\r\n * Timeout das mutations de assinatura que ESCREVEM (action/plan e action/payment).\r\n *\r\n * O default do ApiClient é 30s. Essas duas rotas caem no mesmo motor pesado do\r\n * backend (planEdit delega pra paymentEdit) — troca de método de pagamento, mandato\r\n * PIX recorrente Woovi, void-and-replace de fatura — e passam de 30s com alguma\r\n * frequência: em produção elas aparecem como `outcome=canceled` com wallTime ~29.9s.\r\n *\r\n * O problema não é o usuário ver \"Tempo excedido\": é que o abort MATA o worker no\r\n * meio da saga. Se o corte cai depois de criar o mandato Woovi e suprimir a fatura\r\n * de ciclo, sobra mandato órfão + fatura sem dunning, o usuário não recebe QR nenhum\r\n * e a próxima tentativa cria um segundo mandato. Deixar a request terminar converte\r\n * uma escrita parcial numa escrita completa.\r\n *\r\n * Não é a solução definitiva — a rota deveria ser assíncrona (202 + polling no\r\n * correlation_id). É o teto que dá folga enquanto isso.\r\n *\r\n * Só nas mutations: calculateSubscription é idempotente (não escreve nada), então\r\n * um timeout nela não deixa rastro e não precisa esperar mais.\r\n */\r\nconst SUBSCRIPTION_WRITE_TIMEOUT_MS = 60000;\r\n\r\nexport type UpdateSubscriptionPlanResponse =\r\n | Subscription\r\n | SubscriptionPendingPixResponse;\r\n\r\nclass SubscriptionsService {\r\n async listSubscriptions(\r\n params?: Partial<FindSubscriptionsParams>,\r\n ): Promise<PaginatedSuccessResult<Subscription>> {\r\n const { id_account } = await getUserContext();\r\n\r\n const query = buildQueryParams(\r\n params as Record<string, string | boolean | undefined>,\r\n );\r\n const url = `/accounts/${id_account}/subscriptions${query ? `?${query}` : \"\"}`;\r\n\r\n const response =\r\n await api.apps.get<ApiPaginatedActionResult<Subscription>>(url);\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao listar assinaturas\",\r\n \"LIST_SUBSCRIPTIONS_FAILED\",\r\n 400,\r\n );\r\n }\r\n\r\n const data = response.data.map((item) => SubscriptionSchema.parse(item));\r\n\r\n return {\r\n data,\r\n total: response.total,\r\n success: true,\r\n } satisfies PaginatedSuccessResult<Subscription>;\r\n }\r\n\r\n /**\r\n * A assinatura corrente do plano da conta, pela regra única do backend\r\n * (`GET .../subscriptions/action/current`): contrato de domínio nunca é\r\n * corrente, encerrada é decidida por `active`. Sem `id_product`, paridade\r\n * com hoje (melhor rank entre todos os produtos, nunca item/domínio).\r\n */\r\n async getCurrentSubscription(\r\n params?: { id_product?: number },\r\n ): Promise<SuccessResult<Subscription | null>> {\r\n const { id_account } = await getUserContext();\r\n\r\n const query = buildQueryParams(\r\n params as Record<string, string | number | undefined>,\r\n );\r\n const url = `/accounts/${id_account}/subscriptions/action/current${query ? `?${query}` : \"\"}`;\r\n\r\n const response = await api.apps.get<ApiPaginatedActionResult<Subscription>>(url);\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao consultar assinatura corrente\",\r\n \"GET_CURRENT_SUBSCRIPTION_FAILED\",\r\n 400,\r\n );\r\n }\r\n\r\n const raw = response.data[0];\r\n\r\n return {\r\n success: true,\r\n data: raw ? SubscriptionSchema.parse(raw) : null,\r\n };\r\n }\r\n\r\n async calculateSubscription(\r\n data: CalculateSubscriptionRequest,\r\n ): Promise<SuccessResult<CalculateSubscriptionResponse>> {\r\n const { id_account } = await getUserContext();\r\n\r\n const response = await api.apps.post<\r\n ApiActionResult<CalculateSubscriptionResponse>\r\n >(`/accounts/${id_account}/subscriptions/action/calculate`, data);\r\n\r\n console.log(\"Calculate subscription response:\", {\r\n response,\r\n data: JSON.stringify(data, null, 2),\r\n });\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao calcular assinatura\",\r\n \"CALCULATE_SUBSCRIPTION_FAILED\",\r\n 400,\r\n );\r\n }\r\n\r\n return {\r\n success: true,\r\n data: CalculateSubscriptionResponseSchema.parse(response.data),\r\n };\r\n }\r\n\r\n async updateSubscriptionPlan(\r\n subscriptionId: number | string,\r\n data: UpdateSubscriptionPlanRequest,\r\n ): Promise<\r\n SuccessResult<UpdateSubscriptionPlanResponse | null> & { client_secret?: string }\r\n > {\r\n await assertManagementPermission('manage_subscriptions');\r\n const { id_account } = await getUserContext();\r\n\r\n const response = await api.apps.put<\r\n ApiActionResult<UpdateSubscriptionPlanResponse | UpdateSubscriptionPlanResponse[]> & {\r\n client_secret?: string;\r\n }\r\n >(\r\n `/accounts/${id_account}/subscriptions/${subscriptionId}/action/plan`,\r\n data,\r\n { timeout: SUBSCRIPTION_WRITE_TIMEOUT_MS },\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao atualizar plano\",\r\n \"UPDATE_SUBSCRIPTION_PLAN_FAILED\",\r\n 400,\r\n );\r\n }\r\n\r\n const raw = Array.isArray(response.data) ? response.data[0] : response.data;\r\n\r\n // Preserva resposta pix-pending (id: null, pending: true, pix: {...})\r\n // pra clientes poderem rotear o user pra fluxo dedicado de pix em vez\r\n // de tratar como subscription comum. Caso contrário, parseia como\r\n // Subscription (compatível com o comportamento antigo de devolver { id }).\r\n let parsed: UpdateSubscriptionPlanResponse | null = null;\r\n if (raw) {\r\n const pixResult = SubscriptionPendingPixResponseSchema.safeParse(raw);\r\n parsed = pixResult.success ? pixResult.data : SubscriptionSchema.parse(raw);\r\n }\r\n\r\n return {\r\n success: true,\r\n data: parsed,\r\n ...(response.client_secret ? { client_secret: response.client_secret } : {}),\r\n };\r\n }\r\n\r\n async updateSubscriptionPayment(\r\n subscriptionId: number | string,\r\n data: {\r\n id_card?: string;\r\n payment_method_id?: string;\r\n payment_method: number;\r\n charge_now?: boolean;\r\n },\r\n ): Promise<\r\n SuccessResult<void> & {\r\n applied: boolean;\r\n client_secret?: string;\r\n charge_now?: ChargeNowResult;\r\n }\r\n > {\r\n await assertManagementPermission(\"manage_subscriptions\");\r\n const { id_account } = await getUserContext();\r\n\r\n /* O `status: 2` do guard de 3DS pendente não cabe em `ApiActionResult`, que só conhece 0 e 1.\r\n * Declarar o terceiro estado aqui é o que permite tratá-lo — sem isso o TypeScript apaga o\r\n * ramo como inalcançável e o caso volta a atravessar como sucesso. */\r\n const response = await api.apps.put<\r\n (ApiActionResult<void> | { status: 2; message?: string }) & {\r\n charge_now?: ChargeNowResult;\r\n client_secret?: string;\r\n }\r\n >(\r\n `/accounts/${id_account}/subscriptions/${subscriptionId}/action/payment`,\r\n data,\r\n { timeout: SUBSCRIPTION_WRITE_TIMEOUT_MS },\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao atualizar método de pagamento\",\r\n \"UPDATE_SUBSCRIPTION_PAYMENT_FAILED\",\r\n 400,\r\n );\r\n }\r\n\r\n /* `status: 2` NÃO é sucesso: o guard de 3DS pendente do paymentEdit devolve esse status sem\r\n * aplicar a troca, e como só o `status === 0` era tratado como erro, a chamada caía no\r\n * `success: true` e a tela dizia \"sua assinatura passou a ser cobrada neste cartão\" para uma\r\n * troca que não aconteceu — descartando junto o `client_secret` que resolveria a pendência.\r\n *\r\n * Por isso o retorno carrega `applied`: quem chama precisa poder distinguir \"trocou\" de\r\n * \"não trocou, conclua o pagamento pendente primeiro\". */\r\n if (response.status === 2) {\r\n return {\r\n success: true,\r\n applied: false,\r\n ...(response.client_secret ? { client_secret: response.client_secret } : {}),\r\n };\r\n }\r\n\r\n /* O desfecho da cobrança imediata precisa atravessar: descartá-lo (como este método fazia com\r\n * o corpo inteiro) apagaria tanto a recusa quanto o `client_secret` do 3DS, e a tela\r\n * anunciaria \"tudo certo\" para uma fatura que continua em aberto. */\r\n return {\r\n success: true,\r\n applied: true,\r\n ...(response.charge_now ? { charge_now: response.charge_now } : {}),\r\n };\r\n }\r\n\r\n async getFreezeNotice(): Promise<FreezeNotice> {\r\n const { id_account } = await getUserContext();\r\n\r\n const response = await api.apps.get<ApiActionResult<FreezeNotice>>(\r\n `/accounts/${id_account}/notices/freeze`,\r\n );\r\n\r\n if (response.status === 0 || !response.data) {\r\n throw new ApiError(\r\n (response.status === 0 ? response.message : \"\") ||\r\n \"Erro ao consultar aviso de congelamento\",\r\n \"GET_FREEZE_NOTICE_FAILED\",\r\n 400,\r\n );\r\n }\r\n\r\n return response.data;\r\n }\r\n\r\n async ackFreezeNotice(cycle: string): Promise<SuccessResult<void>> {\r\n const { id_account } = await getUserContext();\r\n\r\n const response = await api.apps.post<ApiActionResult<void>>(\r\n `/accounts/${id_account}/notices/freeze/ack`,\r\n { cycle },\r\n );\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(\r\n response.message || \"Erro ao confirmar aviso de congelamento\",\r\n \"ACK_FREEZE_NOTICE_FAILED\",\r\n 400,\r\n );\r\n }\r\n\r\n return { success: true };\r\n }\r\n}\r\n\r\nexport const subscriptionsService = new SubscriptionsService();\r\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,WAAW;AACpB;AAAA,EACE;AAAA,OAKK;AACP,SAAS,wBAAwB;AACjC,SAAS,kCAAkC;AAC3C,SAAS,sBAAsB;AAC/B;AAAA,EAEE;AAAA,OAGK;AACP;AAAA,EAIE;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAEK;AAuBP,MAAM,gCAAgC;AAMtC,MAAM,qBAAqB;AAAA,EACzB,MAAM,kBACJ,QAC+C;AAC/C,UAAM,EAAE,WAAW,IAAI,MAAM,eAAe;AAE5C,UAAM,QAAQ;AAAA,MACZ;AAAA,IACF;AACA,UAAM,MAAM,aAAa,UAAU,iBAAiB,QAAQ,IAAI,KAAK,KAAK,EAAE;AAE5E,UAAM,WACJ,MAAM,IAAI,KAAK,IAA4C,GAAG;AAEhE,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,UAAM,OAAO,SAAS,KAAK,IAAI,CAAC,SAAS,mBAAmB,MAAM,IAAI,CAAC;AAEvE,WAAO;AAAA,MACL;AAAA,MACA,OAAO,SAAS;AAAA,MAChB,SAAS;AAAA,IACX;AAAA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AM,IAAI,KAAK;AAAA,MAC9B,aAAa,UAAU;AAAA,IACzB;AAEA,QAAI,SAAS,WAAW,KAAK,CAAC,SAAS,MAAM;AAC3C,YAAM,IAAI;AAAA,SACP,SAAS,WAAW,IAAI,SAAS,UAAU,OAC1C;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,SAAS;AAAA,EAClB;AAAA,EAEA,MAAM,gBAAgB,OAA6C;AACjE,UAAM,EAAE,WAAW,IAAI,MAAM,eAAe;AAE5C,UAAM,WAAW,MAAM,IAAI,KAAK;AAAA,MAC9B,aAAa,UAAU;AAAA,MACvB,EAAE,MAAM;AAAA,IACV;AAEA,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,EAAE,SAAS,KAAK;AAAA,EACzB;AACF;AAEO,MAAM,uBAAuB,IAAI,qBAAqB;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/services/subscriptions.service.ts"],"sourcesContent":["import \"server-only\";\n\nimport { api } from \"../../../infra/api/client\";\nimport {\n ApiError,\n ApiActionResult,\n ApiPaginatedActionResult,\n PaginatedSuccessResult,\n SuccessResult,\n} from \"../../../infra/api/types\";\nimport { buildQueryParams } from \"../../../infra/utils/params\";\nimport { assertManagementPermission } from \"../../auth/utils/assert-management-permission\";\nimport { getUserContext } from \"../../auth/utils/get-user-context\";\nimport {\n Subscription,\n SubscriptionSchema,\n FindSubscriptionsParams,\n type ChargeNowResult,\n} from \"../types/subscription.type\";\nimport type { CancelSubscriptionRequest } from \"../types/cancel-subscription.type\";\nimport {\n isPendingPixCreateSubscriptionResponse,\n CreateSubscriptionPendingPixResponseSchema,\n type CreateSubscriptionRequest,\n type CreateSubscriptionResponse,\n} from \"../types/create-subscription.type\";\nimport {\n PendingPixStatusDataSchema,\n type PendingPixStatusData,\n} from \"../types/pending-pix-status.type\";\nimport {\n type CalculateSubscriptionRequest,\n type CalculateSubscriptionResponse,\n type UpdateSubscriptionPlanRequest,\n CalculateSubscriptionResponseSchema,\n} from \"../types/calculate-subscription.type\";\nimport {\n SubscriptionPendingPixResponseSchema,\n type SubscriptionPendingPixResponse,\n} from \"../types/pix-pending.type\";\nimport type { FreezeNotice } from \"../types/freeze-notice.type\";\n\n/**\n * Timeout das mutations de assinatura que ESCREVEM (action/plan e action/payment).\n *\n * O default do ApiClient é 30s. Essas duas rotas caem no mesmo motor pesado do\n * backend (planEdit delega pra paymentEdit) — troca de método de pagamento, mandato\n * PIX recorrente Woovi, void-and-replace de fatura — e passam de 30s com alguma\n * frequência: em produção elas aparecem como `outcome=canceled` com wallTime ~29.9s.\n *\n * O problema não é o usuário ver \"Tempo excedido\": é que o abort MATA o worker no\n * meio da saga. Se o corte cai depois de criar o mandato Woovi e suprimir a fatura\n * de ciclo, sobra mandato órfão + fatura sem dunning, o usuário não recebe QR nenhum\n * e a próxima tentativa cria um segundo mandato. Deixar a request terminar converte\n * uma escrita parcial numa escrita completa.\n *\n * Não é a solução definitiva — a rota deveria ser assíncrona (202 + polling no\n * correlation_id). É o teto que dá folga enquanto isso.\n *\n * Só nas mutations: calculateSubscription é idempotente (não escreve nada), então\n * um timeout nela não deixa rastro e não precisa esperar mais.\n */\nconst SUBSCRIPTION_WRITE_TIMEOUT_MS = 60000;\n\nexport type UpdateSubscriptionPlanResponse =\n | Subscription\n | SubscriptionPendingPixResponse;\n\nclass SubscriptionsService {\n async listSubscriptions(\n params?: Partial<FindSubscriptionsParams>,\n ): Promise<PaginatedSuccessResult<Subscription>> {\n const { id_account } = await getUserContext();\n\n const query = buildQueryParams(\n params as Record<string, string | boolean | undefined>,\n );\n const url = `/accounts/${id_account}/subscriptions${query ? `?${query}` : \"\"}`;\n\n const response =\n await api.apps.get<ApiPaginatedActionResult<Subscription>>(url);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao listar assinaturas\",\n \"LIST_SUBSCRIPTIONS_FAILED\",\n 400,\n );\n }\n\n const data = response.data.map((item) => SubscriptionSchema.parse(item));\n\n return {\n data,\n total: response.total,\n success: true,\n } satisfies PaginatedSuccessResult<Subscription>;\n }\n\n /**\n * A assinatura corrente do plano da conta, pela regra única do backend\n * (`GET .../subscriptions/action/current`): contrato de domínio nunca é\n * corrente, encerrada é decidida por `active`. Sem `id_product`, paridade\n * com hoje (melhor rank entre todos os produtos, nunca item/domínio).\n */\n async getCurrentSubscription(\n params?: { id_product?: number },\n ): Promise<SuccessResult<Subscription | null>> {\n const { id_account } = await getUserContext();\n\n const query = buildQueryParams(\n params as Record<string, string | number | undefined>,\n );\n const url = `/accounts/${id_account}/subscriptions/action/current${query ? `?${query}` : \"\"}`;\n\n const response = await api.apps.get<ApiPaginatedActionResult<Subscription>>(url);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao consultar assinatura corrente\",\n \"GET_CURRENT_SUBSCRIPTION_FAILED\",\n 400,\n );\n }\n\n const raw = response.data[0];\n\n return {\n success: true,\n data: raw ? SubscriptionSchema.parse(raw) : null,\n };\n }\n\n async calculateSubscription(\n data: CalculateSubscriptionRequest,\n ): Promise<SuccessResult<CalculateSubscriptionResponse>> {\n const { id_account } = await getUserContext();\n\n const response = await api.apps.post<\n ApiActionResult<CalculateSubscriptionResponse>\n >(`/accounts/${id_account}/subscriptions/action/calculate`, data);\n\n console.log(\"Calculate subscription response:\", {\n response,\n data: JSON.stringify(data, null, 2),\n });\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao calcular assinatura\",\n \"CALCULATE_SUBSCRIPTION_FAILED\",\n 400,\n );\n }\n\n return {\n success: true,\n data: CalculateSubscriptionResponseSchema.parse(response.data),\n };\n }\n\n async updateSubscriptionPlan(\n subscriptionId: number | string,\n data: UpdateSubscriptionPlanRequest,\n ): Promise<\n SuccessResult<UpdateSubscriptionPlanResponse | null> & { client_secret?: string }\n > {\n await assertManagementPermission('manage_subscriptions');\n const { id_account } = await getUserContext();\n\n const response = await api.apps.put<\n ApiActionResult<UpdateSubscriptionPlanResponse | UpdateSubscriptionPlanResponse[]> & {\n client_secret?: string;\n }\n >(\n `/accounts/${id_account}/subscriptions/${subscriptionId}/action/plan`,\n data,\n { timeout: SUBSCRIPTION_WRITE_TIMEOUT_MS },\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao atualizar plano\",\n \"UPDATE_SUBSCRIPTION_PLAN_FAILED\",\n 400,\n );\n }\n\n const raw = Array.isArray(response.data) ? response.data[0] : response.data;\n\n // Preserva resposta pix-pending (id: null, pending: true, pix: {...})\n // pra clientes poderem rotear o user pra fluxo dedicado de pix em vez\n // de tratar como subscription comum. Caso contrário, parseia como\n // Subscription (compatível com o comportamento antigo de devolver { id }).\n let parsed: UpdateSubscriptionPlanResponse | null = null;\n if (raw) {\n const pixResult = SubscriptionPendingPixResponseSchema.safeParse(raw);\n parsed = pixResult.success ? pixResult.data : SubscriptionSchema.parse(raw);\n }\n\n return {\n success: true,\n data: parsed,\n ...(response.client_secret ? { client_secret: response.client_secret } : {}),\n };\n }\n\n async updateSubscriptionPayment(\n subscriptionId: number | string,\n data: {\n id_card?: string;\n payment_method_id?: string;\n payment_method: number;\n charge_now?: boolean;\n },\n ): Promise<\n SuccessResult<void> & {\n applied: boolean;\n client_secret?: string;\n charge_now?: ChargeNowResult;\n }\n > {\n await assertManagementPermission(\"manage_subscriptions\");\n const { id_account } = await getUserContext();\n\n /* O `status: 2` do guard de 3DS pendente não cabe em `ApiActionResult`, que só conhece 0 e 1.\n * Declarar o terceiro estado aqui é o que permite tratá-lo — sem isso o TypeScript apaga o\n * ramo como inalcançável e o caso volta a atravessar como sucesso. */\n const response = await api.apps.put<\n (ApiActionResult<void> | { status: 2; message?: string }) & {\n charge_now?: ChargeNowResult;\n client_secret?: string;\n }\n >(\n `/accounts/${id_account}/subscriptions/${subscriptionId}/action/payment`,\n data,\n { timeout: SUBSCRIPTION_WRITE_TIMEOUT_MS },\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao atualizar método de pagamento\",\n \"UPDATE_SUBSCRIPTION_PAYMENT_FAILED\",\n 400,\n );\n }\n\n /* `status: 2` NÃO é sucesso: o guard de 3DS pendente do paymentEdit devolve esse status sem\n * aplicar a troca, e como só o `status === 0` era tratado como erro, a chamada caía no\n * `success: true` e a tela dizia \"sua assinatura passou a ser cobrada neste cartão\" para uma\n * troca que não aconteceu — descartando junto o `client_secret` que resolveria a pendência.\n *\n * Por isso o retorno carrega `applied`: quem chama precisa poder distinguir \"trocou\" de\n * \"não trocou, conclua o pagamento pendente primeiro\". */\n if (response.status === 2) {\n return {\n success: true,\n applied: false,\n ...(response.client_secret ? { client_secret: response.client_secret } : {}),\n };\n }\n\n /* O desfecho da cobrança imediata precisa atravessar: descartá-lo (como este método fazia com\n * o corpo inteiro) apagaria tanto a recusa quanto o `client_secret` do 3DS, e a tela\n * anunciaria \"tudo certo\" para uma fatura que continua em aberto. */\n return {\n success: true,\n applied: true,\n ...(response.charge_now ? { charge_now: response.charge_now } : {}),\n };\n }\n\n async findSubscriptionById(subscriptionId: string | number): Promise<SuccessResult<Subscription>> {\n const { id_account } = await getUserContext();\n const response = await api.apps.get<ApiPaginatedActionResult<Subscription>>(\n `/accounts/${id_account}/subscriptions/${subscriptionId}`\n );\n\n if (response.status === 0 || !response.data?.[0]) {\n throw new ApiError(\"Assinatura não encontrada\", \"FIND_SUBSCRIPTION_FAILED\", 400);\n }\n\n return { success: true, data: SubscriptionSchema.parse(response.data[0]) };\n }\n\n async cancelSubscription(\n subscriptionId: number | string,\n data: CancelSubscriptionRequest\n ): Promise<SuccessResult<void>> {\n await assertManagementPermission(\"manage_subscriptions\");\n const { id_account } = await getUserContext();\n\n const response = await api.apps.put<ApiActionResult<void>>(\n `/accounts/${id_account}/subscriptions/${subscriptionId}/action/cancel`,\n data\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao cancelar assinatura\",\n \"CANCEL_SUBSCRIPTION_FAILED\",\n 400\n );\n }\n\n return { success: true };\n }\n\n /** Contratação de plano. Pode devolver um pix pendente no lugar da assinatura. */\n async createSubscription(\n data: CreateSubscriptionRequest\n ): Promise<PaginatedSuccessResult<CreateSubscriptionResponse> & { client_secret?: string }> {\n const { id_account } = await getUserContext();\n\n const response = await api.apps.post<\n ApiPaginatedActionResult<CreateSubscriptionResponse> & { client_secret?: string }\n >(`/accounts/${id_account}/subscriptions`, data);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao criar assinatura\",\n \"CREATE_SUBSCRIPTION_FAILED\",\n 400\n );\n }\n\n return {\n success: true,\n data: (response.data ?? []).map((item) =>\n isPendingPixCreateSubscriptionResponse(item)\n ? CreateSubscriptionPendingPixResponseSchema.parse(item)\n : SubscriptionSchema.parse(item)\n ),\n total: response.total,\n ...(response.client_secret ? { client_secret: response.client_secret } : {}),\n };\n }\n\n /** Status do pix pendente, consultado em polling enquanto o cliente paga. */\n async findPendingPixStatus(correlationId: string): Promise<SuccessResult<PendingPixStatusData>> {\n const { id_account } = await getUserContext();\n\n const response = await api.apps.get<ApiPaginatedActionResult<PendingPixStatusData>>(\n `/accounts/${id_account}/subscriptions/pending-pix/${encodeURIComponent(correlationId)}`\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao consultar o status do Pix\",\n \"FIND_PENDING_PIX_STATUS_FAILED\",\n 400\n );\n }\n\n if (!response.data?.length) {\n throw new ApiError(\"Pix pendente não encontrado\", \"PENDING_PIX_NOT_FOUND\", 404);\n }\n\n return { success: true, data: PendingPixStatusDataSchema.parse(response.data[0]) };\n }\n\n async getFreezeNotice(): Promise<FreezeNotice> {\n const { id_account } = await getUserContext();\n\n const response = await api.apps.get<ApiActionResult<FreezeNotice>>(\n `/accounts/${id_account}/notices/freeze`,\n );\n\n if (response.status === 0 || !response.data) {\n throw new ApiError(\n (response.status === 0 ? response.message : \"\") ||\n \"Erro ao consultar aviso de congelamento\",\n \"GET_FREEZE_NOTICE_FAILED\",\n 400,\n );\n }\n\n return response.data;\n }\n\n async ackFreezeNotice(cycle: string): Promise<SuccessResult<void>> {\n const { id_account } = await getUserContext();\n\n const response = await api.apps.post<ApiActionResult<void>>(\n `/accounts/${id_account}/notices/freeze/ack`,\n { cycle },\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || \"Erro ao confirmar aviso de congelamento\",\n \"ACK_FREEZE_NOTICE_FAILED\",\n 400,\n );\n }\n\n return { success: true };\n }\n}\n\nexport const subscriptionsService = new SubscriptionsService();\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,WAAW;AACpB;AAAA,EACE;AAAA,OAKK;AACP,SAAS,wBAAwB;AACjC,SAAS,kCAAkC;AAC3C,SAAS,sBAAsB;AAC/B;AAAA,EAEE;AAAA,OAGK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,OAEK;AACP;AAAA,EAIE;AAAA,OACK;AACP;AAAA,EACE;AAAA,OAEK;AAuBP,MAAM,gCAAgC;AAMtC,MAAM,qBAAqB;AAAA,EACzB,MAAM,kBACJ,QAC+C;AAC/C,UAAM,EAAE,WAAW,IAAI,MAAM,eAAe;AAE5C,UAAM,QAAQ;AAAA,MACZ;AAAA,IACF;AACA,UAAM,MAAM,aAAa,UAAU,iBAAiB,QAAQ,IAAI,KAAK,KAAK,EAAE;AAE5E,UAAM,WACJ,MAAM,IAAI,KAAK,IAA4C,GAAG;AAEhE,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,UAAM,OAAO,SAAS,KAAK,IAAI,CAAC,SAAS,mBAAmB,MAAM,IAAI,CAAC;AAEvE,WAAO;AAAA,MACL;AAAA,MACA,OAAO,SAAS;AAAA,MAChB,SAAS;AAAA,IACX;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA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: z.string().min(1),
4
+ cancellation_description: z.string().min(1)
5
+ });
6
+ export {
7
+ CancelSubscriptionRequestSchema
8
+ };
9
+ //# sourceMappingURL=cancel-subscription.type.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/types/cancel-subscription.type.ts"],"sourcesContent":["import z from 'zod';\n\nexport const CancelSubscriptionRequestSchema = z.object({\n cancellation_reason: z.string().min(1),\n cancellation_description: z.string().min(1),\n});\n\nexport type CancelSubscriptionRequest = z.infer<typeof CancelSubscriptionRequestSchema>;\n"],"mappings":"AAAA,OAAO,OAAO;AAEP,MAAM,kCAAkC,EAAE,OAAO;AAAA,EACtD,qBAAqB,EAAE,OAAO,EAAE,IAAI,CAAC;AAAA,EACrC,0BAA0B,EAAE,OAAO,EAAE,IAAI,CAAC;AAC5C,CAAC;","names":[]}
@@ -0,0 +1,62 @@
1
+ import z from "zod";
2
+ const CreateSubscriptionPlanItemSchema = z.object({
3
+ id_addon: z.number(),
4
+ quantity: z.number(),
5
+ value: z.number().optional(),
6
+ trial: z.boolean().optional()
7
+ });
8
+ const CreateSubscriptionRequestSchema = z.object({
9
+ id_product: z.number(),
10
+ id_plan: z.number(),
11
+ type: z.string(),
12
+ payment_method: z.number(),
13
+ payment_method_id: z.string().optional(),
14
+ id_card: z.union([z.number(), z.string()]).optional(),
15
+ periodicity: z.number().optional(),
16
+ date_hiring: z.string().optional(),
17
+ date_due: z.string().optional(),
18
+ id_coupon: z.number().optional(),
19
+ plan_items: z.array(CreateSubscriptionPlanItemSchema.partial({ quantity: true })).optional(),
20
+ financial_document_type: z.number().optional(),
21
+ financial_document: z.string().optional(),
22
+ financial_name: z.string().optional(),
23
+ financial_email: z.string().optional(),
24
+ zipcode: z.string().optional(),
25
+ address: z.string().optional(),
26
+ address_number: z.string().optional(),
27
+ address_complement: z.string().optional(),
28
+ neighborhood: z.string().optional(),
29
+ city: z.string().optional(),
30
+ state: z.string().optional(),
31
+ tracking: z.object({
32
+ gclid: z.string().optional(),
33
+ fbclid: z.string().optional(),
34
+ fbp: z.string().optional(),
35
+ fbc: z.string().optional(),
36
+ ga_client_id: z.string().optional(),
37
+ ga_session_id: z.string().optional()
38
+ }).optional()
39
+ });
40
+ const PixCreateSubscriptionDataSchema = z.object({
41
+ qr_code: z.string().nullable().optional(),
42
+ payment_link: z.string().nullable().optional(),
43
+ correlation_id: z.string(),
44
+ expires_at: z.string().nullable().optional()
45
+ });
46
+ const CreateSubscriptionPendingPixResponseSchema = z.object({
47
+ id: z.union([z.string(), z.null()]).optional(),
48
+ pending: z.literal(true),
49
+ payment_method: z.literal(3),
50
+ pix: PixCreateSubscriptionDataSchema
51
+ }).passthrough();
52
+ function isPendingPixCreateSubscriptionResponse(value) {
53
+ return CreateSubscriptionPendingPixResponseSchema.safeParse(value).success;
54
+ }
55
+ export {
56
+ CreateSubscriptionPendingPixResponseSchema,
57
+ CreateSubscriptionPlanItemSchema,
58
+ CreateSubscriptionRequestSchema,
59
+ PixCreateSubscriptionDataSchema,
60
+ isPendingPixCreateSubscriptionResponse
61
+ };
62
+ //# sourceMappingURL=create-subscription.type.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/types/create-subscription.type.ts"],"sourcesContent":["import z from 'zod';\nimport type { Subscription } from './subscription.type';\n\nexport const CreateSubscriptionPlanItemSchema = z.object({\n id_addon: z.number(),\n quantity: z.number(),\n value: z.number().optional(),\n trial: z.boolean().optional(),\n});\n\nexport const CreateSubscriptionRequestSchema = z.object({\n id_product: z.number(),\n id_plan: z.number(),\n type: z.string(),\n payment_method: z.number(),\n payment_method_id: z.string().optional(),\n id_card: z.union([z.number(), z.string()]).optional(),\n periodicity: z.number().optional(),\n date_hiring: z.string().optional(),\n date_due: z.string().optional(),\n id_coupon: z.number().optional(),\n plan_items: z.array(CreateSubscriptionPlanItemSchema.partial({ quantity: true })).optional(),\n financial_document_type: z.number().optional(),\n financial_document: z.string().optional(),\n financial_name: z.string().optional(),\n financial_email: z.string().optional(),\n zipcode: z.string().optional(),\n address: z.string().optional(),\n address_number: z.string().optional(),\n address_complement: z.string().optional(),\n neighborhood: z.string().optional(),\n city: z.string().optional(),\n state: z.string().optional(),\n tracking: z\n .object({\n gclid: z.string().optional(),\n fbclid: z.string().optional(),\n fbp: z.string().optional(),\n fbc: z.string().optional(),\n ga_client_id: z.string().optional(),\n ga_session_id: z.string().optional(),\n })\n .optional(),\n});\n\nexport type CreateSubscriptionRequest = z.infer<typeof CreateSubscriptionRequestSchema>;\n\nexport const PixCreateSubscriptionDataSchema = z.object({\n qr_code: z.string().nullable().optional(),\n payment_link: z.string().nullable().optional(),\n correlation_id: z.string(),\n expires_at: z.string().nullable().optional(),\n});\n\n/**\n * Discrimina por `pending` + `payment_method` + presença de `pix`. `id` aceita null ou string\n * porque as trilhas de pix do backend divergem nesse campo (ver `SubscriptionPendingPixResponse`).\n */\nexport const CreateSubscriptionPendingPixResponseSchema = z\n .object({\n id: z.union([z.string(), z.null()]).optional(),\n pending: z.literal(true),\n payment_method: z.literal(3),\n pix: PixCreateSubscriptionDataSchema,\n })\n .passthrough();\n\nexport type CreateSubscriptionPendingPixResponse = z.infer<\n typeof CreateSubscriptionPendingPixResponseSchema\n>;\n\nexport type CreateSubscriptionResponse = Subscription | CreateSubscriptionPendingPixResponse;\n\nexport function isPendingPixCreateSubscriptionResponse(\n value: unknown\n): value is CreateSubscriptionPendingPixResponse {\n return CreateSubscriptionPendingPixResponseSchema.safeParse(value).success;\n}\n\n"],"mappings":"AAAA,OAAO,OAAO;AAGP,MAAM,mCAAmC,EAAE,OAAO;AAAA,EACvD,UAAU,EAAE,OAAO;AAAA,EACnB,UAAU,EAAE,OAAO;AAAA,EACnB,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,OAAO,EAAE,QAAQ,EAAE,SAAS;AAC9B,CAAC;AAEM,MAAM,kCAAkC,EAAE,OAAO;AAAA,EACtD,YAAY,EAAE,OAAO;AAAA,EACrB,S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E,SAAS;AAAA,EACrC,CAAC,EACA,SAAS;AACd,CAAC;AAIM,MAAM,kCAAkC,EAAE,OAAO;AAAA,EACtD,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EACxC,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC7C,gBAAgB,EAAE,OAAO;AAAA,EACzB,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAC7C,CAAC;AAMM,MAAM,6CAA6C,EACvD,OAAO;AAAA,EACN,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,KAAK,CAAC,CAAC,EAAE,SAAS;AAAA,EAC7C,SAAS,EAAE,QAAQ,IAAI;AAAA,EACvB,gBAAgB,EAAE,QAAQ,CAAC;AAAA,EAC3B,KAAK;AACP,CAAC,EACA,YAAY;AAQR,SAAS,uCACd,OAC+C;AAC/C,SAAO,2CAA2C,UAAU,KAAK,EAAE;AACrE;","names":[]}
@@ -0,0 +1,28 @@
1
+ import z from "zod";
2
+ const PendingPixStatusPhaseSchema = z.enum([
3
+ "creating",
4
+ "awaiting_authorization",
5
+ "completed",
6
+ "rejected",
7
+ "expired"
8
+ ]);
9
+ const PendingPixStatusDataSchema = z.object({
10
+ phase: PendingPixStatusPhaseSchema,
11
+ payment_method: z.number().nullable().optional(),
12
+ subscription_id: z.union([z.number(), z.string()]).optional(),
13
+ completed_at: z.string().nullable().optional(),
14
+ pix: z.object({
15
+ qr_code: z.string().nullable().optional(),
16
+ payment_link: z.string().nullable().optional(),
17
+ correlation_id: z.string().nullable().optional(),
18
+ expires_at: z.string().nullable().optional(),
19
+ expires_at_inferred: z.boolean().nullable().optional(),
20
+ expires_at_source: z.string().nullable().optional(),
21
+ authorization_created_at: z.string().nullable().optional()
22
+ }).optional()
23
+ }).passthrough();
24
+ export {
25
+ PendingPixStatusDataSchema,
26
+ PendingPixStatusPhaseSchema
27
+ };
28
+ //# sourceMappingURL=pending-pix-status.type.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/types/pending-pix-status.type.ts"],"sourcesContent":["import z from 'zod';\n\nexport const PendingPixStatusPhaseSchema = z.enum([\n 'creating',\n 'awaiting_authorization',\n 'completed',\n 'rejected',\n 'expired',\n]);\n\nexport type PendingPixStatusPhase = z.infer<typeof PendingPixStatusPhaseSchema>;\n\nexport const PendingPixStatusDataSchema = z\n .object({\n phase: PendingPixStatusPhaseSchema,\n payment_method: z.number().nullable().optional(),\n subscription_id: z.union([z.number(), z.string()]).optional(),\n completed_at: z.string().nullable().optional(),\n pix: z\n .object({\n qr_code: z.string().nullable().optional(),\n payment_link: z.string().nullable().optional(),\n correlation_id: z.string().nullable().optional(),\n expires_at: z.string().nullable().optional(),\n expires_at_inferred: z.boolean().nullable().optional(),\n expires_at_source: z.string().nullable().optional(),\n authorization_created_at: z.string().nullable().optional(),\n })\n .optional(),\n })\n .passthrough();\n\nexport type PendingPixStatusData = z.infer<typeof PendingPixStatusDataSchema>;\n"],"mappings":"AAAA,OAAO,OAAO;AAEP,MAAM,8BAA8B,EAAE,KAAK;AAAA,EAChD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAIM,MAAM,6BAA6B,EACvC,OAAO;AAAA,EACN,OAAO;AAAA,EACP,gBAAgB,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC/C,iBAAiB,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,SAAS;AAAA,EAC5D,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC7C,KAAK,EACF,OAAO;AAAA,IACN,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,IACxC,cAAc,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,IAC7C,gBAAgB,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,IAC/C,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,IAC3C,qBAAqB,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS;AAAA,IACrD,mBAAmB,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,IAClD,0BAA0B,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,EAC3D,CAAC,EACA,SAAS;AACd,CAAC,EACA,YAAY;","names":[]}
@@ -88,7 +88,15 @@ const SubscriptionSchema = z.object({
88
88
  is_ai_credit: z.boolean()
89
89
  })),
90
90
  new_limits: z.record(z.string(), z.number()).nullable().optional(),
91
- new_discounts: z.array(z.unknown()),
91
+ // Descontos aplicados na alteração agendada (periodicidade e cupom), usados no resumo.
92
+ new_discounts: z.array(
93
+ z.object({
94
+ name: z.string().nullish(),
95
+ kind: z.string().nullish(),
96
+ percent_off: z.number().nullish(),
97
+ amount_off: z.number().nullish()
98
+ }).passthrough()
99
+ ),
92
100
  changes: z.array(z.object({
93
101
  type: z.string(),
94
102
  id_addon: z.number().nullable().optional(),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/subscriptions/types/subscription.type.ts"],"sourcesContent":["import z from 'zod';\r\nimport { calendarDateSchema } from '../../../infra/utils/date';\r\n\r\nexport const SubscriptionItemSchema = z.object({\r\n id: z.union([z.number(), z.string()]),\r\n deleted: z.number(),\r\n datetime_alt: z.coerce.date().nullable().optional(),\r\n datetime_del: z.coerce.date().nullable().optional(),\r\n datetime_add: z.coerce.date(),\r\n id_wl: z.number(),\r\n id_subscription: z.union([z.number(), z.string()]),\r\n id_addon: z.number().nullable(),\r\n addon_name: z.string().optional(),\r\n value: z.number().nullable(),\r\n currency: z.string(),\r\n quantity: z.number().nullable().transform((v) => v ?? 0),\r\n payment_status: z.number().nullable(),\r\n id_charge: z.union([z.number(), z.string()]).nullable(),\r\n trial: z.boolean().nullable(),\r\n trial_ends_at: z.coerce.date().nullable().optional(),\r\n});\r\n\r\nexport type SubscriptionItem = z.infer<typeof SubscriptionItemSchema>;\r\n\r\nexport const SubscriptionSchema = z.object({\r\n id: z.union([z.number(), z.string()]),\r\n deleted: z.number(),\r\n datetime_alt: z.coerce.date().nullable().optional(),\r\n datetime_del: z.coerce.date().nullable().optional(),\r\n datetime_add: z.coerce.date(),\r\n id_wl: z.number(),\r\n id_account: z.union([z.number(), z.string()]),\r\n id_card: z.union([z.number(), z.string()]).nullable(),\r\n id_coupon: z.union([z.number(), z.string()]).nullable(),\r\n type: z.string(),\r\n payment_method: z.number().nullable(),\r\n periodicity: z.coerce.number().nullable(),\r\n value: z.number().nullable(),\r\n id_product: z.number(),\r\n id_plan: z.number().nullable(),\r\n plan_name: z.string().nullable().optional(),\r\n id_gateway: z.union([z.number(), z.string()]).nullable(),\r\n gateway_account: z.string().nullable(),\r\n date_hiring: calendarDateSchema().nullable(),\r\n date_due: calendarDateSchema().nullable(),\r\n date_cancellation: calendarDateSchema().nullable(),\r\n date_verification: calendarDateSchema().nullable(),\r\n cancellation_reason: z.string().nullable(),\r\n cancellation_description: z.string().nullable(),\r\n active: z.boolean(),\r\n charged: z.boolean(),\r\n datetime_last_update_periodicity: z.coerce.date().nullable().optional(),\r\n card_name: z.string().nullable().optional(),\r\n card_brand: z.string().nullable().optional(),\r\n card_number: z.string().nullable().optional(),\r\n card: z.object({\r\n id_card: z.union([z.number(), z.string()]).nullable().optional(),\r\n brand: z.string().nullable().optional(),\r\n expires_at: z.string().nullable().optional(),\r\n last4: z.string().nullable().optional(),\r\n name: z.string().nullable().optional(),\r\n }).nullable().optional(),\r\n /* payment_retry: tentativas de cobrança no cartão (Stripe Smart Retries / dunning),\r\n * lidas ao vivo do latest_invoice. null para boleto/pix (sem retries). Ver gapps-r3-api #229. */\r\n payment_retry: z.object({\r\n attempt_count: z.number(),\r\n next_attempt_at: z.string().nullable(),\r\n invoice_status: z.string().nullable(),\r\n }).nullable().optional(),\r\n items: z.array(SubscriptionItemSchema),\r\n pending_change: z.object({\r\n schedule_id: z.string(),\r\n schedule_status: z.string(),\r\n kind: z.string(),\r\n takes_effect_at: z.number().nullable(),\r\n takes_effect_at_iso: z.string().nullable(),\r\n new_plan: z.object({\r\n id: z.number(),\r\n name: z.string(),\r\n periodicity: z.number().nullable(),\r\n value: z.number(),\r\n value_gross: z.number(),\r\n }).nullable(),\r\n new_items: z.array(z.object({\r\n price_id: z.string(),\r\n id_addon: z.number().nullable(),\r\n addon_name: z.string().nullable(),\r\n quantity: z.number(),\r\n unit_value: z.number(),\r\n value: z.number(),\r\n is_plan_base: z.boolean(),\r\n is_ai_credit: z.boolean(),\r\n })),\r\n new_limits: z.record(z.string(), z.number()).nullable().optional(),\r\n new_discounts: z.array(z.unknown()),\r\n changes: z.array(z.object({\r\n type: z.string(),\r\n id_addon: z.number().nullable().optional(),\r\n addon_name: z.string().nullable().optional(),\r\n quantity: z.number().optional(),\r\n from: z.unknown().optional(),\r\n to: z.unknown().optional(),\r\n })),\r\n }).nullable().optional(),\r\n metadata: z.record(z.string(), z.unknown()).optional(),\r\n});\r\n\r\nexport type Subscription = z.infer<typeof SubscriptionSchema>;\r\n\r\n/* Desfecho da cobrança imediata pedida com `charge_now` na troca de forma de pagamento\r\n * (gapps-r3-api, PUT subscriptions/:id/action/payment).\r\n *\r\n * Vem separado do `status` da resposta de propósito: quando isto chega, a troca JÁ está firmada\r\n * no banco e na Stripe. Uma cobrança recusada aqui não desfaz a troca — o dunning da Stripe segue\r\n * armado no cartão novo —, então a tela precisa contar as duas coisas em separado.\r\n *\r\n * `outcome` é a ÚNICA fonte da verdade sobre o que aconteceu, e a tela deve falar só a partir dele.\r\n * Substituiu um par de booleanos (`attempted`/`paid`) que não distinguia recusa de 3DS pendente: a\r\n * tela lia `paid: false` depois de um desafio bem-sucedido e anunciava falha para um pagamento que\r\n * tinha acabado de completar.\r\n *\r\n * `amount` vem em centavos, na `currency` da fatura, e é o valor REALMENTE cobrado — não uma\r\n * previsão feita antes da chamada. */\r\nexport interface ChargeNowResult {\r\n outcome: 'charged' | 'requires_action' | 'declined' | 'none';\r\n invoice_id?: string;\r\n amount?: number | null;\r\n currency?: string | null;\r\n client_secret?: string;\r\n /* Presente em `declined`: a razão que o emissor deu. */\r\n message?: string;\r\n /* Presente em `none`: por que não houve o que cobrar (`sem_fatura_de_ciclo_aberta`,\r\n * `deteccao_falhou`, `sem_contexto_de_cobranca`). */\r\n reason?: string;\r\n}\r\n\r\nexport interface FindSubscriptionsParams {\r\n active?: boolean;\r\n trial?: boolean;\r\n date_start?: string;\r\n date_end?: string;\r\n date_hiring_start?: string;\r\n date_hiring_end?: string;\r\n limit?: number;\r\n page?: number;\r\n id_product?: number;\r\n}\r\n"],"mappings":"AAAA,OAAO,OAAO;AACd,SAAS,0BAA0B;AAE5B,MAAM,yBAAyB,EAAE,OAAO;AAAA,EAC7C,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC;AAAA,EACpC,SAAS,EAAE,OAAO;AAAA,EAClB,cAAc,EAAE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS;AAAA,EAClD,cAAc,EAAE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS;AAAA,EAClD,cAAc,EAAE,OAAO,KAAK;AAAA,EAC5B,OAAO,EAAE,OAAO;AAAA,EAChB,iBAAiB,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC;AAAA,EACjD,UAAU,EAAE,OAAO,EAAE,SAAS;AAAA,EAC9B,YAAY,EAAE,OAAO,EAAE,SAAS;AAAA,EAChC,OAAO,EAAE,OAAO,EAAE,SAAS;AAAA,EAC3B,UAAU,EAAE,OAAO;AAAA,EACnB,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,CAAC,MAAM,KAAK,CAAC;AAAA,EACvD,gBAAgB,EAAE,OAAO,EAAE,SAAS;AAAA,EACpC,WAAW,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC,EAAE,S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","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/types/subscription.type.ts"],"sourcesContent":["import z from 'zod';\nimport { calendarDateSchema } from '../../../infra/utils/date';\n\nexport const SubscriptionItemSchema = z.object({\n id: z.union([z.number(), z.string()]),\n deleted: z.number(),\n datetime_alt: z.coerce.date().nullable().optional(),\n datetime_del: z.coerce.date().nullable().optional(),\n datetime_add: z.coerce.date(),\n id_wl: z.number(),\n id_subscription: z.union([z.number(), z.string()]),\n id_addon: z.number().nullable(),\n addon_name: z.string().optional(),\n value: z.number().nullable(),\n currency: z.string(),\n quantity: z.number().nullable().transform((v) => v ?? 0),\n payment_status: z.number().nullable(),\n id_charge: z.union([z.number(), z.string()]).nullable(),\n trial: z.boolean().nullable(),\n trial_ends_at: z.coerce.date().nullable().optional(),\n});\n\nexport type SubscriptionItem = z.infer<typeof SubscriptionItemSchema>;\n\nexport const SubscriptionSchema = z.object({\n id: z.union([z.number(), z.string()]),\n deleted: z.number(),\n datetime_alt: z.coerce.date().nullable().optional(),\n datetime_del: z.coerce.date().nullable().optional(),\n datetime_add: z.coerce.date(),\n id_wl: z.number(),\n id_account: z.union([z.number(), z.string()]),\n id_card: z.union([z.number(), z.string()]).nullable(),\n id_coupon: z.union([z.number(), z.string()]).nullable(),\n type: z.string(),\n payment_method: z.number().nullable(),\n periodicity: z.coerce.number().nullable(),\n value: z.number().nullable(),\n id_product: z.number(),\n id_plan: z.number().nullable(),\n plan_name: z.string().nullable().optional(),\n id_gateway: z.union([z.number(), z.string()]).nullable(),\n gateway_account: z.string().nullable(),\n date_hiring: calendarDateSchema().nullable(),\n date_due: calendarDateSchema().nullable(),\n date_cancellation: calendarDateSchema().nullable(),\n date_verification: calendarDateSchema().nullable(),\n cancellation_reason: z.string().nullable(),\n cancellation_description: z.string().nullable(),\n active: z.boolean(),\n charged: z.boolean(),\n datetime_last_update_periodicity: z.coerce.date().nullable().optional(),\n card_name: z.string().nullable().optional(),\n card_brand: z.string().nullable().optional(),\n card_number: z.string().nullable().optional(),\n card: z.object({\n id_card: z.union([z.number(), z.string()]).nullable().optional(),\n brand: z.string().nullable().optional(),\n expires_at: z.string().nullable().optional(),\n last4: z.string().nullable().optional(),\n name: z.string().nullable().optional(),\n }).nullable().optional(),\n /* payment_retry: tentativas de cobrança no cartão (Stripe Smart Retries / dunning),\n * lidas ao vivo do latest_invoice. null para boleto/pix (sem retries). Ver gapps-r3-api #229. */\n payment_retry: z.object({\n attempt_count: z.number(),\n next_attempt_at: z.string().nullable(),\n invoice_status: z.string().nullable(),\n }).nullable().optional(),\n items: z.array(SubscriptionItemSchema),\n pending_change: z.object({\n schedule_id: z.string(),\n schedule_status: z.string(),\n kind: z.string(),\n takes_effect_at: z.number().nullable(),\n takes_effect_at_iso: z.string().nullable(),\n new_plan: z.object({\n id: z.number(),\n name: z.string(),\n periodicity: z.number().nullable(),\n value: z.number(),\n value_gross: z.number(),\n }).nullable(),\n new_items: z.array(z.object({\n price_id: z.string(),\n id_addon: z.number().nullable(),\n addon_name: z.string().nullable(),\n quantity: z.number(),\n unit_value: z.number(),\n value: z.number(),\n is_plan_base: z.boolean(),\n is_ai_credit: z.boolean(),\n })),\n new_limits: z.record(z.string(), z.number()).nullable().optional(),\n // Descontos aplicados na alteração agendada (periodicidade e cupom), usados no resumo.\n new_discounts: z.array(\n z\n .object({\n name: z.string().nullish(),\n kind: z.string().nullish(),\n percent_off: z.number().nullish(),\n amount_off: z.number().nullish(),\n })\n .passthrough()\n ),\n changes: z.array(z.object({\n type: z.string(),\n id_addon: z.number().nullable().optional(),\n addon_name: z.string().nullable().optional(),\n quantity: z.number().optional(),\n from: z.unknown().optional(),\n to: z.unknown().optional(),\n })),\n }).nullable().optional(),\n metadata: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport type Subscription = z.infer<typeof SubscriptionSchema>;\n\n/* Desfecho da cobrança imediata pedida com `charge_now` na troca de forma de pagamento\n * (gapps-r3-api, PUT subscriptions/:id/action/payment).\n *\n * Vem separado do `status` da resposta de propósito: quando isto chega, a troca JÁ está firmada\n * no banco e na Stripe. Uma cobrança recusada aqui não desfaz a troca — o dunning da Stripe segue\n * armado no cartão novo —, então a tela precisa contar as duas coisas em separado.\n *\n * `outcome` é a ÚNICA fonte da verdade sobre o que aconteceu, e a tela deve falar só a partir dele.\n * Substituiu um par de booleanos (`attempted`/`paid`) que não distinguia recusa de 3DS pendente: a\n * tela lia `paid: false` depois de um desafio bem-sucedido e anunciava falha para um pagamento que\n * tinha acabado de completar.\n *\n * `amount` vem em centavos, na `currency` da fatura, e é o valor REALMENTE cobrado — não uma\n * previsão feita antes da chamada. */\nexport interface ChargeNowResult {\n outcome: 'charged' | 'requires_action' | 'declined' | 'none';\n invoice_id?: string;\n amount?: number | null;\n currency?: string | null;\n client_secret?: string;\n /* Presente em `declined`: a razão que o emissor deu. */\n message?: string;\n /* Presente em `none`: por que não houve o que cobrar (`sem_fatura_de_ciclo_aberta`,\n * `deteccao_falhou`, `sem_contexto_de_cobranca`). */\n reason?: string;\n}\n\nexport interface FindSubscriptionsParams {\n active?: boolean;\n trial?: boolean;\n date_start?: string;\n date_end?: string;\n date_hiring_start?: string;\n date_hiring_end?: string;\n limit?: number;\n page?: number;\n id_product?: number;\n}\n"],"mappings":"AAAA,OAAO,OAAO;AACd,SAAS,0BAA0B;AAE5B,MAAM,yBAAyB,EAAE,OAAO;AAAA,EAC7C,IAAI,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC;AAAA,EACpC,SAAS,EAAE,OAAO;AAAA,EAClB,cAAc,EAAE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS;AAAA,EAClD,cAAc,EAAE,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS;AAAA,EAClD,cAAc,EAAE,OAAO,KAAK;AAAA,EAC5B,OAAO,EAAE,OAAO;AAAA,EAChB,iBAAiB,EAAE,MAAM,CAAC,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC,CAAC;AAAA,EACjD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AAO,EAAE,QAAQ;AAAA,QAChC,YAAY,EAAE,OAAO,EAAE,QAAQ;AAAA,MACjC,CAAC,EACA,YAAY;AAAA,IACjB;AAAA,IACA,SAAS,EAAE,MAAM,EAAE,OAAO;AAAA,MACxB,MAAM,EAAE,OAAO;AAAA,MACf,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,MACzC,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS;AAAA,MAC3C,UAAU,EAAE,OAAO,EAAE,SAAS;AAAA,MAC9B,MAAM,EAAE,QAAQ,EAAE,SAAS;AAAA,MAC3B,IAAI,EAAE,QAAQ,EAAE,SAAS;AAAA,IAC3B,CAAC,CAAC;AAAA,EACJ,CAAC,EAAE,SAAS,EAAE,SAAS;AAAA,EACvB,UAAU,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,SAAS;AACvD,CAAC;","names":[]}
@@ -0,0 +1,69 @@
1
+ function getAddonBuckets(addonId, subscriptionItems, planPrice, bucketEdits) {
2
+ const relevant = subscriptionItems.filter(
3
+ (item) => item.id_addon === addonId && (item.value ?? 0) > 0
4
+ );
5
+ const grouped = /* @__PURE__ */ new Map();
6
+ for (const item of relevant) {
7
+ const value = item.value;
8
+ grouped.set(value, (grouped.get(value) ?? 0) + item.quantity);
9
+ }
10
+ const buckets = [];
11
+ for (const [value, originalQuantity] of grouped.entries()) {
12
+ const key = `${addonId}_${value}`;
13
+ const isPrimary = Math.abs(value - planPrice) < 0.01;
14
+ const quantity = key in bucketEdits ? bucketEdits[key] : originalQuantity;
15
+ buckets.push({ key, idAddon: addonId, value, quantity, originalQuantity, isPrimary });
16
+ }
17
+ const hasPrimary = buckets.some((b) => b.isPrimary);
18
+ if (!hasPrimary) {
19
+ const key = `${addonId}_${planPrice}`;
20
+ const quantity = key in bucketEdits ? bucketEdits[key] : 0;
21
+ buckets.push({
22
+ key,
23
+ idAddon: addonId,
24
+ value: planPrice,
25
+ quantity,
26
+ originalQuantity: 0,
27
+ isPrimary: true
28
+ });
29
+ }
30
+ buckets.sort((a, b) => {
31
+ if (a.isPrimary !== b.isPrimary) return a.isPrimary ? -1 : 1;
32
+ return b.value - a.value;
33
+ });
34
+ return buckets;
35
+ }
36
+ function buildDomainPlanExtras(buckets) {
37
+ return buckets.map((bucket) => ({
38
+ id_addon: bucket.idAddon,
39
+ value: bucket.value,
40
+ quantity: bucket.quantity
41
+ }));
42
+ }
43
+ function buildZeroedOldBuckets(addonId, subscriptionItems, primaryPrice) {
44
+ const seen = /* @__PURE__ */ new Set();
45
+ const result = [];
46
+ for (const item of subscriptionItems) {
47
+ if (item.id_addon !== addonId) continue;
48
+ const value = item.value ?? 0;
49
+ if (value <= 0) continue;
50
+ if (Math.abs(value - primaryPrice) <= 0.01) continue;
51
+ if (seen.has(value)) continue;
52
+ seen.add(value);
53
+ result.push({
54
+ key: `${addonId}_${value}`,
55
+ idAddon: addonId,
56
+ value,
57
+ quantity: 0,
58
+ originalQuantity: item.quantity,
59
+ isPrimary: false
60
+ });
61
+ }
62
+ return result;
63
+ }
64
+ export {
65
+ buildDomainPlanExtras,
66
+ buildZeroedOldBuckets,
67
+ getAddonBuckets
68
+ };
69
+ //# sourceMappingURL=addon-buckets.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/utils/addon-buckets.ts"],"sourcesContent":["import type { SubscriptionItem } from '../types/subscription.type';\n\nexport type AddonBucket = {\n key: string; // `${idAddon}_${value}` — used as bucketEdits key\n idAddon: number;\n value: number; // unit price (R$)\n quantity: number; // current editor qty (edited or original)\n originalQuantity: number; // qty from subscription (ceiling for alternatives)\n isPrimary: boolean; // true = value matches plan price\n};\n\n/**\n * Groups subscription items for a given addon into price buckets,\n * applies any in-progress edits, and ensures a primary bucket always exists.\n *\n * - Filters items where `id_addon === addonId` and `value > 0`\n * - Groups by value (backend já entrega value mensal por unidade), summing quantities\n * - Marks the bucket whose price is within R$0.01 of `planPrice` as primary\n * - If no bucket is primary, creates a synthetic primary with qty=0\n * - Applies `bucketEdits[key]` overrides when present\n * - Sorts: primary first, then by value descending\n */\nexport function getAddonBuckets(\n addonId: number,\n subscriptionItems: SubscriptionItem[],\n planPrice: number,\n bucketEdits: Record<string, number>,\n): AddonBucket[] {\n // Filter relevant items\n const relevant = subscriptionItems.filter(\n (item) => item.id_addon === addonId && (item.value ?? 0) > 0\n );\n\n // Group by value (já é mensal por unidade, conforme contrato do backend),\n // summing quantities\n const grouped = new Map<number, number>();\n for (const item of relevant) {\n const value = item.value!;\n grouped.set(value, (grouped.get(value) ?? 0) + item.quantity);\n }\n\n // Build buckets\n const buckets: AddonBucket[] = [];\n for (const [value, originalQuantity] of grouped.entries()) {\n const key = `${addonId}_${value}`;\n const isPrimary = Math.abs(value - planPrice) < 0.01;\n const quantity = key in bucketEdits ? bucketEdits[key] : originalQuantity;\n buckets.push({ key, idAddon: addonId, value, quantity, originalQuantity, isPrimary });\n }\n\n // Ensure a primary bucket exists\n const hasPrimary = buckets.some((b) => b.isPrimary);\n if (!hasPrimary) {\n const key = `${addonId}_${planPrice}`;\n const quantity = key in bucketEdits ? bucketEdits[key] : 0;\n buckets.push({\n key,\n idAddon: addonId,\n value: planPrice,\n quantity,\n originalQuantity: 0,\n isPrimary: true,\n });\n }\n\n // Sort: primary first, then by value descending\n buckets.sort((a, b) => {\n if (a.isPrimary !== b.isPrimary) return a.isPrimary ? -1 : 1;\n return b.value - a.value;\n });\n\n return buckets;\n}\n\n/**\n * Converts addon buckets into the `plan_extras` shape expected by the API.\n *\n * Bucket quantities already represent the EXTRA paid domains only\n * (items with value > 0 from the subscription), never the plan-included base.\n * All buckets are included (even qty=0) so the backend can explicitly zero them.\n */\nexport function buildDomainPlanExtras(\n buckets: AddonBucket[],\n): Array<{ id_addon: number; quantity: number; value: number }> {\n return buckets.map((bucket) => ({\n id_addon: bucket.idAddon,\n value: bucket.value,\n quantity: bucket.quantity,\n }));\n}\n\n/**\n * Em fluxos de upgrade/troca de plano (ou reativação), a UI colapsa todos os\n * extras num único bucket no preço do novo plano. Mas a sub atual pode ter items\n * em outros preços (ex: extras antigos de R$ 8,50 e R$ 8,90 quando o novo plano\n * cobra R$ 9,00). Sem enviar esses preços antigos com `quantity: 0`, o backend\n * mantém os items legados ativos junto com o bucket novo.\n *\n * Esta função retorna AddonBucket sintéticos com `quantity: 0` pra cada preço\n * único da sub atual que difere do `primaryPrice`. A comparação `< 0.01` filtra\n * apenas ruído de IEEE 754 (ex: 8.500000001 vs 8.5) — preços reais separados por\n * exatamente R$ 0,01 (ex: 8.50 vs 8.51) são intencionalmente tratados como\n * distintos.\n */\nexport function buildZeroedOldBuckets(\n addonId: number,\n subscriptionItems: SubscriptionItem[],\n primaryPrice: number,\n): AddonBucket[] {\n const seen = new Set<number>();\n const result: AddonBucket[] = [];\n for (const item of subscriptionItems) {\n if (item.id_addon !== addonId) continue;\n const value = item.value ?? 0;\n if (value <= 0) continue;\n if (Math.abs(value - primaryPrice) <= 0.01) continue;\n if (seen.has(value)) continue;\n seen.add(value);\n result.push({\n key: `${addonId}_${value}`,\n idAddon: addonId,\n value,\n quantity: 0,\n originalQuantity: item.quantity,\n isPrimary: false,\n });\n }\n return result;\n}\n"],"mappings":"AAsBO,SAAS,gBACd,SACA,mBACA,WACA,aACe;AAEf,QAAM,WAAW,kBAAkB;AAAA,IACjC,CAAC,SAAS,KAAK,aAAa,YAAY,KAAK,SAAS,KAAK;AAAA,EAC7D;AAIA,QAAM,UAAU,oBAAI,IAAoB;AACxC,aAAW,QAAQ,UAAU;AAC3B,UAAM,QAAQ,KAAK;AACnB,YAAQ,IAAI,QAAQ,QAAQ,IAAI,KAAK,KAAK,KAAK,KAAK,QAAQ;AAAA,EAC9D;AAGA,QAAM,UAAyB,CAAC;AAChC,aAAW,CAAC,OAAO,gBAAgB,KAAK,QAAQ,QAAQ,GAAG;AACzD,UAAM,MAAM,GAAG,OAAO,IAAI,KAAK;AAC/B,UAAM,YAAY,KAAK,I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AAK;AAAA,MACvB,WAAW;AAAA,IACb,CAAC;AAAA,EACH;AACA,SAAO;AACT;","names":[]}
@@ -1,7 +1,13 @@
1
1
  class PaymentAuthenticationError extends Error {
2
- constructor(message) {
2
+ /**
3
+ * Segredo da cobrança que ficou pendente. A retentativa autentica ESTA cobrança em vez de
4
+ * criar outra assinatura — sem isso, errar o desafio e tentar de novo cobra duas vezes.
5
+ */
6
+ clientSecret;
7
+ constructor(message, clientSecret) {
3
8
  super(message);
4
9
  this.name = "PaymentAuthenticationError";
10
+ this.clientSecret = clientSecret;
5
11
  }
6
12
  }
7
13
  async function confirmPaymentIfRequired(stripe, result, fallbackErrorMessage) {
@@ -9,7 +15,7 @@ async function confirmPaymentIfRequired(stripe, result, fallbackErrorMessage) {
9
15
  if (!clientSecret || !stripe) return;
10
16
  const { error } = await stripe.confirmCardPayment(clientSecret);
11
17
  if (error) {
12
- throw new PaymentAuthenticationError(error.message || fallbackErrorMessage);
18
+ throw new PaymentAuthenticationError(error.message || fallbackErrorMessage, clientSecret);
13
19
  }
14
20
  }
15
21
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/subscriptions/utils/confirm-payment-if-required.ts"],"sourcesContent":["import type { Stripe } from \"@stripe/stripe-js\";\n\n/**\n * Falha no desafio 3DS/SCA. Distinta de erro de API: quando ela é lançada a\n * assinatura JÁ existe (ou o plano já mudou) no backend — só o pagamento não\n * foi autenticado. Quem trata precisa recuperar a cobrança existente em vez de\n * criar outra, senão vira cobrança duplicada (Asana ID-4743).\n */\nexport class PaymentAuthenticationError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"PaymentAuthenticationError\";\n }\n}\n\n/**\n * Cobrança que exige autenticação do banco volta com `client_secret` — o\n * pagamento só completa depois do desafio. Ignorar esse campo deixa a\n * assinatura criada/alterada sem pagamento confirmado, sem nada na tela.\n *\n * No-op quando não há `client_secret` (pagamento já capturado) ou quando o\n * Stripe não carregou.\n */\nexport async function confirmPaymentIfRequired(\n stripe: Stripe | null,\n result: { client_secret?: string } | null | undefined,\n fallbackErrorMessage: string,\n): Promise<void> {\n const clientSecret = result?.client_secret;\n if (!clientSecret || !stripe) return;\n\n const { error } = await stripe.confirmCardPayment(clientSecret);\n if (error) {\n throw new PaymentAuthenticationError(error.message || fallbackErrorMessage);\n }\n}\n"],"mappings":"AAQO,MAAM,mCAAmC,MAAM;AAAA,EACpD,YAAY,SAAiB;AAC3B,UAAM,OAAO;AACb,SAAK,OAAO;AAAA,EACd;AACF;AAUA,eAAsB,yBACpB,QACA,QACA,sBACe;AACf,QAAM,eAAe,QAAQ;AAC7B,MAAI,CAAC,gBAAgB,CAAC,OAAQ;AAE9B,QAAM,EAAE,MAAM,IAAI,MAAM,OAAO,mBAAmB,YAAY;AAC9D,MAAI,OAAO;AACT,UAAM,IAAI,2BAA2B,MAAM,WAAW,oBAAoB;AAAA,EAC5E;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/utils/confirm-payment-if-required.ts"],"sourcesContent":["import type { Stripe } from \"@stripe/stripe-js\";\n\n/**\n * Falha no desafio 3DS/SCA. Distinta de erro de API: quando ela é lançada a\n * assinatura JÁ existe (ou o plano já mudou) no backend — só o pagamento não\n * foi autenticado. Quem trata precisa recuperar a cobrança existente em vez de\n * criar outra, senão vira cobrança duplicada (Asana ID-4743).\n */\nexport class PaymentAuthenticationError extends Error {\n /**\n * Segredo da cobrança que ficou pendente. A retentativa autentica ESTA cobrança em vez de\n * criar outra assinatura — sem isso, errar o desafio e tentar de novo cobra duas vezes.\n */\n readonly clientSecret?: string;\n\n constructor(message: string, clientSecret?: string) {\n super(message);\n this.name = \"PaymentAuthenticationError\";\n this.clientSecret = clientSecret;\n }\n}\n\n/**\n * Cobrança que exige autenticação do banco volta com `client_secret` — o\n * pagamento só completa depois do desafio. Ignorar esse campo deixa a\n * assinatura criada/alterada sem pagamento confirmado, sem nada na tela.\n *\n * No-op quando não há `client_secret` (pagamento já capturado) ou quando o\n * Stripe não carregou.\n */\nexport async function confirmPaymentIfRequired(\n stripe: Stripe | null,\n result: { client_secret?: string } | null | undefined,\n fallbackErrorMessage: string,\n): Promise<void> {\n const clientSecret = result?.client_secret;\n if (!clientSecret || !stripe) return;\n\n const { error } = await stripe.confirmCardPayment(clientSecret);\n if (error) {\n throw new PaymentAuthenticationError(error.message || fallbackErrorMessage, clientSecret);\n }\n}\n"],"mappings":"AAQO,MAAM,mCAAmC,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAK3C;AAAA,EAET,YAAY,SAAiB,cAAuB;AAClD,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,eAAe;AAAA,EACtB;AACF;AAUA,eAAsB,yBACpB,QACA,QACA,sBACe;AACf,QAAM,eAAe,QAAQ;AAC7B,MAAI,CAAC,gBAAgB,CAAC,OAAQ;AAE9B,QAAM,EAAE,MAAM,IAAI,MAAM,OAAO,mBAAmB,YAAY;AAC9D,MAAI,OAAO;AACT,UAAM,IAAI,2BAA2B,MAAM,WAAW,sBAAsB,YAAY;AAAA,EAC1F;AACF;","names":[]}
@@ -0,0 +1,25 @@
1
+ function getFirstPeriodPricing(params) {
2
+ const { stripeData, total, couponDiscount } = params;
3
+ const duration = stripeData?.duration;
4
+ if (duration !== "once" && duration !== "repeating") return null;
5
+ if (couponDiscount <= 0) return null;
6
+ return {
7
+ kind: duration,
8
+ firstPrice: total,
9
+ recurringPrice: total + couponDiscount,
10
+ durationMonths: duration === "repeating" ? stripeData?.duration_in_months ?? null : null
11
+ };
12
+ }
13
+ function getFirstPeriodLabelKey(period, pricing) {
14
+ if (pricing.kind === "repeating" && period === "monthly" && Number.isInteger(pricing.durationMonths) && (pricing.durationMonths ?? 0) > 1) {
15
+ return "firstMonths";
16
+ }
17
+ if (period === "annual") return "firstAnnual";
18
+ if (period === "semiannual") return "firstSemiannual";
19
+ return "firstMonthly";
20
+ }
21
+ export {
22
+ getFirstPeriodLabelKey,
23
+ getFirstPeriodPricing
24
+ };
25
+ //# sourceMappingURL=first-period-pricing.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/utils/first-period-pricing.ts"],"sourcesContent":["import type { CouponStripeData } from '../../coupons/types/coupon.type';\nimport type { BillingPeriod } from '../types/billing-period.type';\n\n/**\n * Split de preço para cupom de duração limitada (Stripe `duration: once | repeating`): o 1º\n * período sai com desconto e os seguintes voltam ao preço cheio. Exibir só o preço descontado\n * prometeria um valor que não se mantém.\n */\nexport type FirstPeriodPricing = {\n kind: 'once' | 'repeating';\n /** Total do 1º período (já com cupom). */\n firstPrice: number;\n /** Total recorrente sem o cupom = total + desconto do cupom. */\n recurringPrice: number;\n /** Meses de vigência quando `repeating`; null em `once`. */\n durationMonths: number | null;\n};\n\n/**\n * Deriva o split 1º período × recorrente. Retorna null (sem split) quando o cupom não tem\n * duração limitada (`forever`/ausente) ou quando `couponDiscount <= 0` — cupom rejeitado pelo\n * backend ou não aplicável à periodicidade escolhida (o calculate zera a coluna do período).\n */\nexport function getFirstPeriodPricing(params: {\n stripeData: CouponStripeData | null | undefined;\n total: number;\n couponDiscount: number;\n}): FirstPeriodPricing | null {\n const { stripeData, total, couponDiscount } = params;\n const duration = stripeData?.duration;\n\n if (duration !== 'once' && duration !== 'repeating') return null;\n if (couponDiscount <= 0) return null;\n\n return {\n kind: duration,\n firstPrice: total,\n recurringPrice: total + couponDiscount,\n durationMonths: duration === 'repeating' ? (stripeData?.duration_in_months ?? null) : null,\n };\n}\n\n/**\n * Chave do rótulo do 1º período. `firstMonths` só no período mensal com `durationMonths`\n * inteiro > 1 — nunca renderizar `{count}` vazio; qualquer outro `repeating` aproxima para\n * \"1º {período}\", já que a fatura semestral/anual cobre o período inteiro.\n */\nexport function getFirstPeriodLabelKey(\n period: BillingPeriod,\n pricing: FirstPeriodPricing\n): 'firstMonthly' | 'firstSemiannual' | 'firstAnnual' | 'firstMonths' {\n if (\n pricing.kind === 'repeating' &&\n period === 'monthly' &&\n Number.isInteger(pricing.durationMonths) &&\n (pricing.durationMonths ?? 0) > 1\n ) {\n return 'firstMonths';\n }\n if (period === 'annual') return 'firstAnnual';\n if (period === 'semiannual') return 'firstSemiannual';\n return 'firstMonthly';\n}\n"],"mappings":"AAuBO,SAAS,sBAAsB,QAIR;AAC5B,QAAM,EAAE,YAAY,OAAO,eAAe,IAAI;AAC9C,QAAM,WAAW,YAAY;AAE7B,MAAI,aAAa,UAAU,aAAa,YAAa,QAAO;AAC5D,MAAI,kBAAkB,EAAG,QAAO;AAEhC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,gBAAgB,QAAQ;AAAA,IACxB,gBAAgB,aAAa,cAAe,YAAY,sBAAsB,OAAQ;AAAA,EACxF;AACF;AAOO,SAAS,uBACd,QACA,SACoE;AACpE,MACE,QAAQ,SAAS,eACjB,WAAW,aACX,OAAO,UAAU,QAAQ,cAAc,MACtC,QAAQ,kBAAkB,KAAK,GAChC;AACA,WAAO;AAAA,EACT;AACA,MAAI,WAAW,SAAU,QAAO;AAChC,MAAI,WAAW,aAAc,QAAO;AACpC,SAAO;AACT;","names":[]}