@greatapps/common 1.1.542 → 1.1.543

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 (49) hide show
  1. package/dist/components/account/ConfigurationsMyAccountModal.mjs +1 -1
  2. package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +1 -1
  3. package/dist/modules/accounts/actions/account-management.action.mjs +15 -14
  4. package/dist/modules/accounts/actions/account-management.action.mjs.map +1 -1
  5. package/dist/modules/auth/utils/require-valid-session.mjs +17 -0
  6. package/dist/modules/auth/utils/require-valid-session.mjs.map +1 -0
  7. package/dist/modules/cards/actions/create-card.action.mjs +2 -2
  8. package/dist/modules/cards/actions/create-card.action.mjs.map +1 -1
  9. package/dist/modules/cards/actions/delete-card.action.mjs +2 -2
  10. package/dist/modules/cards/actions/delete-card.action.mjs.map +1 -1
  11. package/dist/modules/cards/actions/set-default-card.action.mjs +2 -2
  12. package/dist/modules/cards/actions/set-default-card.action.mjs.map +1 -1
  13. package/dist/modules/projects/actions/add-project-user.action.mjs +2 -2
  14. package/dist/modules/projects/actions/add-project-user.action.mjs.map +1 -1
  15. package/dist/modules/projects/actions/create-project.action.mjs +2 -2
  16. package/dist/modules/projects/actions/create-project.action.mjs.map +1 -1
  17. package/dist/modules/projects/actions/delete-project.action.mjs +2 -2
  18. package/dist/modules/projects/actions/delete-project.action.mjs.map +1 -1
  19. package/dist/modules/projects/actions/remove-project-user.action.mjs +2 -2
  20. package/dist/modules/projects/actions/remove-project-user.action.mjs.map +1 -1
  21. package/dist/modules/projects/actions/update-project.action.mjs +2 -2
  22. package/dist/modules/projects/actions/update-project.action.mjs.map +1 -1
  23. package/dist/modules/subscriptions/actions/update-subscription-plan.action.mjs +2 -2
  24. package/dist/modules/subscriptions/actions/update-subscription-plan.action.mjs.map +1 -1
  25. package/dist/modules/users/action/mark-all-messages-as-read.action.mjs +2 -2
  26. package/dist/modules/users/action/mark-all-messages-as-read.action.mjs.map +1 -1
  27. package/dist/modules/users/action/mark-message-as-read.action.mjs +2 -2
  28. package/dist/modules/users/action/mark-message-as-read.action.mjs.map +1 -1
  29. package/dist/server.mjs +4 -0
  30. package/dist/server.mjs.map +1 -1
  31. package/dist/utils/safeMutationAction.mjs +13 -0
  32. package/dist/utils/safeMutationAction.mjs.map +1 -0
  33. package/package.json +1 -1
  34. package/src/components/account/ConfigurationsMyAccountModal.tsx +1 -0
  35. package/src/modules/accounts/actions/account-management.action.ts +15 -14
  36. package/src/modules/auth/utils/require-valid-session.ts +35 -0
  37. package/src/modules/cards/actions/create-card.action.ts +2 -2
  38. package/src/modules/cards/actions/delete-card.action.ts +2 -2
  39. package/src/modules/cards/actions/set-default-card.action.ts +2 -2
  40. package/src/modules/projects/actions/add-project-user.action.ts +2 -2
  41. package/src/modules/projects/actions/create-project.action.ts +2 -2
  42. package/src/modules/projects/actions/delete-project.action.ts +2 -2
  43. package/src/modules/projects/actions/remove-project-user.action.ts +2 -2
  44. package/src/modules/projects/actions/update-project.action.ts +2 -2
  45. package/src/modules/subscriptions/actions/update-subscription-plan.action.ts +2 -2
  46. package/src/modules/users/action/mark-all-messages-as-read.action.ts +2 -2
  47. package/src/modules/users/action/mark-message-as-read.action.ts +2 -2
  48. package/src/server.ts +2 -0
  49. package/src/utils/safeMutationAction.ts +30 -0
@@ -27,7 +27,7 @@ function ConfigurationsMyAccountModal() {
27
27
  const { data: subscriptionData } = useActiveSubscription();
28
28
  const subscription = subscriptionData?.data?.[0] ?? null;
29
29
  const isPaidSubscriptionType = !!subscription && subscription.type !== "free" && subscription.type !== "trial";
30
- const isBlockingSubscription = isPaidSubscriptionType && subscription.active === true && !hasSubscriptionExpired(subscription.date_due);
30
+ const isBlockingSubscription = isPaidSubscriptionType && subscription.active === true && !subscription.date_cancellation && !hasSubscriptionExpired(subscription.date_due);
31
31
  const { user } = useAuth();
32
32
  const isOwner = user?.profile === UserProfile.owner;
33
33
  const isMobile = useIsMobile();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/account/ConfigurationsMyAccountModal.tsx"],"sourcesContent":["'use client';\n\nimport { IconKey, IconLock, IconSettings2, IconX } from '@tabler/icons-react';\nimport { Dialog, DialogContent, DialogHeader, DialogTitle } from '../ui/overlay/Dialog';\nimport { Tabs, TabsList, TabsTrigger, TabsContent } from '../ui/data-display/Tabs';\nimport { cn } from '../../infra/utils/clsx';\nimport { AccountSectionType } from '../../enums/AccountSectionType';\nimport { PreferencesSection } from './sections/PreferencesSection';\nimport { ChangePasswordSection } from './sections/ChangePasswordSection';\nimport { TokenSection } from './sections/TokenSection';\nimport { SecuritySection } from './sections/SecuritySection';\nimport useConfigurationsModal from './hooks/useConfigurationsModal';\nimport useIsMobile from '../../hooks/useIsMobile';\nimport { useAccountModals } from '../../store/useAccountModals';\nimport { useAuth } from '../../providers/auth.provider';\nimport { UserProfile } from '../../modules/users/schema';\nimport { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';\nimport { hasSubscriptionExpired } from '../../modules/subscriptions/utils/has-subscription-expired';\n\nexport default function ConfigurationsMyAccountModal() {\n const {\n activeModal,\n openDeleteAccount,\n openIsntPossibleDelete,\n close,\n } = useAccountModals();\n\n const open = activeModal === 'configurations';\n\n const { data: subscriptionData } = useActiveSubscription();\n const subscription = subscriptionData?.data?.[0] ?? null;\n const isPaidSubscriptionType =\n !!subscription &&\n subscription.type !== 'free' &&\n subscription.type !== 'trial';\n const isBlockingSubscription =\n isPaidSubscriptionType &&\n subscription.active === true &&\n !hasSubscriptionExpired(subscription.date_due);\n\n const { user } = useAuth();\n const isOwner = user?.profile === UserProfile.owner;\n\n const isMobile = useIsMobile();\n const { activeSection, setActiveSection } = useConfigurationsModal({\n isOpen: open,\n });\n\n const handleDeleteAccount = () => {\n close();\n if (isBlockingSubscription) {\n openIsntPossibleDelete();\n } else {\n openDeleteAccount();\n }\n };\n\n const tabTriggerClasses = cn(\n 'border-0! px-0 py-0',\n\n 'lg:rounded-md lg:flex lg:items-center lg:gap-2 lg:p-3 lg:justify-start lg:w-full',\n 'lg:bg-white lg:hover:bg-gray-100 lg:active:bg-gray-50 lg:border-0',\n 'lg:data-[state=active]:bg-gray-50',\n\n 'flex items-center gap-1.5 px-3 py-3 justify-center whitespace-nowrap',\n 'border-b-2 border-transparent',\n 'data-[state=active]:bg-gray-50 rounded-lg',\n\n 'text-gray-500 data-[state=active]:text-gray-950',\n 'hover:text-gray-900 transition-colors'\n );\n\n return (\n <Dialog open={open} onOpenChange={close}>\n <DialogContent\n showCloseButton={!isMobile}\n overlayClassName=\"bg-black/20 lg:bg-black/50\"\n className=\"\n flex flex-col p-0 gap-0 max-w-full sm:max-w-full overflow-x-hidden border-0\n rounded-t-2xl rounded-b-none h-[100dvh] top-0 bottom-0 left-0 right-0 translate-x-0 translate-y-0\n lg:flex-row lg:w-[892px] lg:max-w-[892px] lg:h-[626px] lg:rounded-lg lg:border\n lg:top-[50%] lg:bottom-auto lg:left-[50%] lg:right-auto lg:translate-x-[-50%] lg:translate-y-[-50%]\"\n >\n <DialogHeader className=\"sr-only\">\n <DialogTitle>Configurações</DialogTitle>\n </DialogHeader>\n <div className=\"md:hidden flex items-center justify-between px-5 py-3 border-b border-gray-200\">\n <span className=\"text-gray-950 paragraph-medium-semibold\">Configurações</span>\n <button\n type=\"button\"\n className=\"size-8 flex items-center justify-center text-gray-500 cursor-pointer\"\n onClick={close}\n >\n <IconX size={18} />\n </button>\n </div>\n <Tabs\n value={activeSection}\n onValueChange={(value) => setActiveSection(value as AccountSectionType)}\n orientation=\"vertical\"\n className=\"flex lg:flex-row flex-col w-full h-full flex-1 lg:h-full lg:pt-0 lg:gap-0\"\n >\n <TabsList\n className={cn(\n 'flex gap-0 bg-transparent border-b-0',\n\n 'lg:flex-col lg:items-stretch lg:justify-start lg:w-auto lg:min-w-60',\n 'lg:border-r lg:border-gray-200 lg:pl-5 lg:pr-5 lg:pt-5 lg:gap-5 lg:overflow-x-visible lg:self-stretch',\n\n 'flex-row items-center justify-start w-full overflow-x-auto scrollbar-hide shrink-0',\n 'px-4 py-3',\n '[mask-image:linear-gradient(to_right,transparent,black_16px,black_calc(100%-24px),transparent)] lg:[mask-image:none]'\n )}\n >\n <span className=\"hidden lg:block paragraph-medium-semibold text-gray-950 mb-0\">\n Configurações\n </span>\n\n <div className=\"lg:flex lg:flex-col flex flex-row lg:gap-0 gap-0 lg:w-full\">\n <TabsTrigger value={AccountSectionType.PREFERENCES} className={tabTriggerClasses}>\n <IconSettings2 size={20} className=\"shrink-0\" />\n <span className=\"paragraph-small-medium\">Preferências</span>\n </TabsTrigger>\n\n {isOwner && (\n <TabsTrigger value={AccountSectionType.TOKEN} className={tabTriggerClasses}>\n <IconKey size={20} className=\"shrink-0\" />\n <span className=\"paragraph-small-medium\">Token da conta</span>\n </TabsTrigger>\n )}\n\n {isOwner && (\n <TabsTrigger value={AccountSectionType.SECURITY} className={tabTriggerClasses}>\n <IconLock size={20} className=\"shrink-0\" />\n <span className=\"paragraph-small-medium\">Segurança</span>\n </TabsTrigger>\n )}\n </div>\n </TabsList>\n\n <div className=\"w-full flex-1 min-h-0 lg:h-full overflow-hidden lg:overflow-visible relative flex flex-col\">\n <TabsContent value={AccountSectionType.PREFERENCES} className=\"h-full! relative overflow-hidden\">\n <PreferencesSection onClose={close} />\n </TabsContent>\n\n {isOwner && (\n <TabsContent value={AccountSectionType.TOKEN} className=\"h-full! relative overflow-hidden\">\n <TokenSection />\n </TabsContent>\n )}\n\n {isOwner && (\n <>\n <TabsContent value={AccountSectionType.SECURITY} className=\"h-full! relative overflow-hidden\">\n <SecuritySection\n setActiveSection={setActiveSection}\n onClose={close}\n onDeleteAccount={handleDeleteAccount}\n />\n </TabsContent>\n\n <TabsContent value={AccountSectionType.CHANGE_PASSWORD} className=\"h-full! relative overflow-hidden\">\n <ChangePasswordSection onBack={() => setActiveSection(AccountSectionType.SECURITY)} />\n </TabsContent>\n </>\n )}\n </div>\n </Tabs>\n </DialogContent>\n </Dialog>\n );\n}\n"],"mappings":";A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WAAU,0BAAyB,0BAAS;AAAA,yBACpD;AAAA,uBAEJ;AAAA;AAAA;AAAA,cACF;AAAA,cAEA,qBAAC,SAAI,WAAU,8FACb;AAAA,oCAAC,eAAY,OAAO,mBAAmB,aAAa,WAAU,oCAC5D,8BAAC,sBAAmB,SAAS,OAAO,GACtC;AAAA,gBAEC,WACC,oBAAC,eAAY,OAAO,mBAAmB,OAAO,WAAU,oCACtD,8BAAC,gBAAa,GAChB;AAAA,gBAGD,WACC,iCACE;AAAA,sCAAC,eAAY,OAAO,mBAAmB,UAAU,WAAU,oCACzD;AAAA,oBAAC;AAAA;AAAA,sBACC;AAAA,sBACA,SAAS;AAAA,sBACT,iBAAiB;AAAA;AAAA,kBACnB,GACF;AAAA,kBAEA,oBAAC,eAAY,OAAO,mBAAmB,iBAAiB,WAAU,oCAChE,8BAAC,yBAAsB,QAAQ,MAAM,iBAAiB,mBAAmB,QAAQ,GAAG,GACtF;AAAA,mBACF;AAAA,iBAEJ;AAAA;AAAA;AAAA,QACF;AAAA;AAAA;AAAA,EACF,GACF;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../src/components/account/ConfigurationsMyAccountModal.tsx"],"sourcesContent":["'use client';\n\nimport { IconKey, IconLock, IconSettings2, IconX } from '@tabler/icons-react';\nimport { Dialog, DialogContent, DialogHeader, DialogTitle } from '../ui/overlay/Dialog';\nimport { Tabs, TabsList, TabsTrigger, TabsContent } from '../ui/data-display/Tabs';\nimport { cn } from '../../infra/utils/clsx';\nimport { AccountSectionType } from '../../enums/AccountSectionType';\nimport { PreferencesSection } from './sections/PreferencesSection';\nimport { ChangePasswordSection } from './sections/ChangePasswordSection';\nimport { TokenSection } from './sections/TokenSection';\nimport { SecuritySection } from './sections/SecuritySection';\nimport useConfigurationsModal from './hooks/useConfigurationsModal';\nimport useIsMobile from '../../hooks/useIsMobile';\nimport { useAccountModals } from '../../store/useAccountModals';\nimport { useAuth } from '../../providers/auth.provider';\nimport { UserProfile } from '../../modules/users/schema';\nimport { useActiveSubscription } from '../../modules/subscriptions/hooks/find-active-subscription.hook';\nimport { hasSubscriptionExpired } from '../../modules/subscriptions/utils/has-subscription-expired';\n\nexport default function ConfigurationsMyAccountModal() {\n const {\n activeModal,\n openDeleteAccount,\n openIsntPossibleDelete,\n close,\n } = useAccountModals();\n\n const open = activeModal === 'configurations';\n\n const { data: subscriptionData } = useActiveSubscription();\n const subscription = subscriptionData?.data?.[0] ?? null;\n const isPaidSubscriptionType =\n !!subscription &&\n subscription.type !== 'free' &&\n subscription.type !== 'trial';\n const isBlockingSubscription =\n isPaidSubscriptionType &&\n subscription.active === true &&\n !subscription.date_cancellation &&\n !hasSubscriptionExpired(subscription.date_due);\n\n const { user } = useAuth();\n const isOwner = user?.profile === UserProfile.owner;\n\n const isMobile = useIsMobile();\n const { activeSection, setActiveSection } = useConfigurationsModal({\n isOpen: open,\n });\n\n const handleDeleteAccount = () => {\n close();\n if (isBlockingSubscription) {\n openIsntPossibleDelete();\n } else {\n openDeleteAccount();\n }\n };\n\n const tabTriggerClasses = cn(\n 'border-0! px-0 py-0',\n\n 'lg:rounded-md lg:flex lg:items-center lg:gap-2 lg:p-3 lg:justify-start lg:w-full',\n 'lg:bg-white lg:hover:bg-gray-100 lg:active:bg-gray-50 lg:border-0',\n 'lg:data-[state=active]:bg-gray-50',\n\n 'flex items-center gap-1.5 px-3 py-3 justify-center whitespace-nowrap',\n 'border-b-2 border-transparent',\n 'data-[state=active]:bg-gray-50 rounded-lg',\n\n 'text-gray-500 data-[state=active]:text-gray-950',\n 'hover:text-gray-900 transition-colors'\n );\n\n return (\n <Dialog open={open} onOpenChange={close}>\n <DialogContent\n showCloseButton={!isMobile}\n overlayClassName=\"bg-black/20 lg:bg-black/50\"\n className=\"\n flex flex-col p-0 gap-0 max-w-full sm:max-w-full overflow-x-hidden border-0\n rounded-t-2xl rounded-b-none h-[100dvh] top-0 bottom-0 left-0 right-0 translate-x-0 translate-y-0\n lg:flex-row lg:w-[892px] lg:max-w-[892px] lg:h-[626px] lg:rounded-lg lg:border\n lg:top-[50%] lg:bottom-auto lg:left-[50%] lg:right-auto lg:translate-x-[-50%] lg:translate-y-[-50%]\"\n >\n <DialogHeader className=\"sr-only\">\n <DialogTitle>Configurações</DialogTitle>\n </DialogHeader>\n <div className=\"md:hidden flex items-center justify-between px-5 py-3 border-b border-gray-200\">\n <span className=\"text-gray-950 paragraph-medium-semibold\">Configurações</span>\n <button\n type=\"button\"\n className=\"size-8 flex items-center justify-center text-gray-500 cursor-pointer\"\n onClick={close}\n >\n <IconX size={18} />\n </button>\n </div>\n <Tabs\n value={activeSection}\n onValueChange={(value) => setActiveSection(value as AccountSectionType)}\n orientation=\"vertical\"\n className=\"flex lg:flex-row flex-col w-full h-full flex-1 lg:h-full lg:pt-0 lg:gap-0\"\n >\n <TabsList\n className={cn(\n 'flex gap-0 bg-transparent border-b-0',\n\n 'lg:flex-col lg:items-stretch lg:justify-start lg:w-auto lg:min-w-60',\n 'lg:border-r lg:border-gray-200 lg:pl-5 lg:pr-5 lg:pt-5 lg:gap-5 lg:overflow-x-visible lg:self-stretch',\n\n 'flex-row items-center justify-start w-full overflow-x-auto scrollbar-hide shrink-0',\n 'px-4 py-3',\n '[mask-image:linear-gradient(to_right,transparent,black_16px,black_calc(100%-24px),transparent)] lg:[mask-image:none]'\n )}\n >\n <span className=\"hidden lg:block paragraph-medium-semibold text-gray-950 mb-0\">\n Configurações\n </span>\n\n <div className=\"lg:flex lg:flex-col flex flex-row lg:gap-0 gap-0 lg:w-full\">\n <TabsTrigger value={AccountSectionType.PREFERENCES} className={tabTriggerClasses}>\n <IconSettings2 size={20} className=\"shrink-0\" />\n <span className=\"paragraph-small-medium\">Preferências</span>\n </TabsTrigger>\n\n {isOwner && (\n <TabsTrigger value={AccountSectionType.TOKEN} className={tabTriggerClasses}>\n <IconKey size={20} className=\"shrink-0\" />\n <span className=\"paragraph-small-medium\">Token da conta</span>\n </TabsTrigger>\n )}\n\n {isOwner && (\n <TabsTrigger value={AccountSectionType.SECURITY} className={tabTriggerClasses}>\n <IconLock size={20} className=\"shrink-0\" />\n <span className=\"paragraph-small-medium\">Segurança</span>\n </TabsTrigger>\n )}\n </div>\n </TabsList>\n\n <div className=\"w-full flex-1 min-h-0 lg:h-full overflow-hidden lg:overflow-visible relative flex flex-col\">\n <TabsContent value={AccountSectionType.PREFERENCES} className=\"h-full! relative overflow-hidden\">\n <PreferencesSection onClose={close} />\n </TabsContent>\n\n {isOwner && (\n <TabsContent value={AccountSectionType.TOKEN} className=\"h-full! relative overflow-hidden\">\n <TokenSection />\n </TabsContent>\n )}\n\n {isOwner && (\n <>\n <TabsContent value={AccountSectionType.SECURITY} className=\"h-full! relative overflow-hidden\">\n <SecuritySection\n setActiveSection={setActiveSection}\n onClose={close}\n onDeleteAccount={handleDeleteAccount}\n />\n </TabsContent>\n\n <TabsContent value={AccountSectionType.CHANGE_PASSWORD} className=\"h-full! relative overflow-hidden\">\n <ChangePasswordSection onBack={() => setActiveSection(AccountSectionType.SECURITY)} />\n </TabsContent>\n </>\n )}\n </div>\n </Tabs>\n </DialogContent>\n </Dialog>\n );\n}\n"],"mappings":";AAqFU,SAoEI,UApEJ,KAEF,YAFE;AAnFV,SAAS,SAAS,UAAU,eAAe,aAAa;AACxD,SAAS,QAAQ,eAAe,cAAc,mBAAmB;AACjE,SAAS,MAAM,UAAU,aAAa,mBAAmB;AACzD,SAAS,UAAU;AACnB,SAAS,0BAA0B;AACnC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAC7B,SAAS,uBAAuB;AAChC,OAAO,4BAA4B;AACnC,OAAO,iBAAiB;AACxB,SAAS,wBAAwB;AACjC,SAAS,eAAe;AACxB,SAAS,mBAAmB;AAC5B,SAAS,6BAA6B;AACtC,SAAS,8BAA8B;AAExB,SAAR,+BAAgD;AACrD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,iBAAiB;AAErB,QAA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AU,oCAChE,8BAAC,yBAAsB,QAAQ,MAAM,iBAAiB,mBAAmB,QAAQ,GAAG,GACtF;AAAA,mBACF;AAAA,iBAEJ;AAAA;AAAA;AAAA,QACF;AAAA;AAAA;AAAA,EACF,GACF;AAEJ;","names":[]}
@@ -1,5 +1,6 @@
1
1
  "use server";
2
2
  import { safeServerAction } from "../../../utils/safeServerAction";
3
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
4
  import { accountService } from "../services/account.service";
4
5
  import { twoFactorService } from "../services/two-factor.service";
5
6
  import { findUserById } from "../../users/action/find-user-by-id.action";
@@ -12,13 +13,13 @@ async function listAccountUsersAction(params) {
12
13
  });
13
14
  }
14
15
  async function updateUserAction(user) {
15
- return safeServerAction(() => accountService.updateAccountUser(user));
16
+ return safeMutationAction(() => accountService.updateAccountUser(user));
16
17
  }
17
18
  async function updateAccountUserByIdAction(userId, user) {
18
- return safeServerAction(() => accountService.updateAccountUserById(userId, user));
19
+ return safeMutationAction(() => accountService.updateAccountUserById(userId, user));
19
20
  }
20
21
  async function updateAccountAction(data) {
21
- return safeServerAction(async () => {
22
+ return safeMutationAction(async () => {
22
23
  if (data.name !== void 0) {
23
24
  const userResult = await findUserById();
24
25
  if (!userResult.success || userResult.data?.profile !== UserProfile.owner) {
@@ -33,31 +34,31 @@ async function updateAccountAction(data) {
33
34
  });
34
35
  }
35
36
  async function deleteAccountUserAction(userId) {
36
- return safeServerAction(() => accountService.deleteAccountUser(userId));
37
+ return safeMutationAction(() => accountService.deleteAccountUser(userId));
37
38
  }
38
39
  async function deleteAccountAction() {
39
- return safeServerAction(() => accountService.deleteAccount());
40
+ return safeMutationAction(() => accountService.deleteAccount());
40
41
  }
41
42
  async function createAccountUserAction(user) {
42
- return safeServerAction(() => accountService.createAccountUser(user));
43
+ return safeMutationAction(() => accountService.createAccountUser(user));
43
44
  }
44
45
  async function changePasswordAction(data) {
45
- return safeServerAction(() => accountService.changePassword(data));
46
+ return safeMutationAction(() => accountService.changePassword(data));
46
47
  }
47
48
  async function requestEmailChangeAction(newEmail) {
48
- return safeServerAction(() => accountService.requestContactReset("email", newEmail));
49
+ return safeMutationAction(() => accountService.requestContactReset("email", newEmail));
49
50
  }
50
51
  async function confirmEmailChangeAction(token, newEmail) {
51
- return safeServerAction(() => accountService.confirmContactReset("email", token, newEmail));
52
+ return safeMutationAction(() => accountService.confirmContactReset("email", token, newEmail));
52
53
  }
53
54
  async function requestPhoneChangeAction(newPhone, ddi) {
54
- return safeServerAction(() => accountService.requestContactReset("phone", newPhone, ddi));
55
+ return safeMutationAction(() => accountService.requestContactReset("phone", newPhone, ddi));
55
56
  }
56
57
  async function confirmPhoneChangeAction(token, newPhone, ddi) {
57
- return safeServerAction(() => accountService.confirmContactReset("phone", token, newPhone, ddi));
58
+ return safeMutationAction(() => accountService.confirmContactReset("phone", token, newPhone, ddi));
58
59
  }
59
60
  async function generateTwoFactorAction() {
60
- return safeServerAction(async () => {
61
+ return safeMutationAction(async () => {
61
62
  const result = await twoFactorService.generate();
62
63
  return {
63
64
  qrcode: result.data.qrcode,
@@ -66,13 +67,13 @@ async function generateTwoFactorAction() {
66
67
  });
67
68
  }
68
69
  async function confirmTwoFactorAction(code) {
69
- return safeServerAction(async () => {
70
+ return safeMutationAction(async () => {
70
71
  await twoFactorService.confirm(code);
71
72
  await accountService.updateAccountUser({ two_factor_authentication: true });
72
73
  });
73
74
  }
74
75
  async function disableTwoFactorAction(code) {
75
- return safeServerAction(async () => {
76
+ return safeMutationAction(async () => {
76
77
  await twoFactorService.verify(code);
77
78
  await twoFactorService.disable();
78
79
  await accountService.updateAccountUser({ two_factor_authentication: false });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/accounts/actions/account-management.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { accountService } from '../services/account.service';\nimport type {\n AccountUsersPaginationParams,\n ChangePasswordRequest,\n CreateAccountUserRequest,\n UpdateAccountRequest,\n UpdateAccountUserRequest,\n} from '../types';\nimport { twoFactorService } from '../services/two-factor.service';\nimport { findUserById } from '../../users/action/find-user-by-id.action';\nimport { UserProfile } from '../../users/schema';\nimport { ApiError } from '../../../infra/api/types';\n\nexport async function listAccountUsersAction(params?: AccountUsersPaginationParams) {\n return safeServerAction(async () => {\n const { users, total } = await accountService.listAccountUsers(params);\n return { data: users, total };\n });\n}\n\nexport async function updateUserAction(user: UpdateAccountUserRequest) {\n return safeServerAction(() => accountService.updateAccountUser(user));\n}\n\nexport async function updateAccountUserByIdAction(\n userId: number,\n user: UpdateAccountUserRequest\n) {\n return safeServerAction(() => accountService.updateAccountUserById(userId, user));\n}\n\nexport async function updateAccountAction(data: UpdateAccountRequest) {\n return safeServerAction(async () => {\n if (data.name !== undefined) {\n const userResult = await findUserById();\n if (!userResult.success || userResult.data?.profile !== UserProfile.owner) {\n throw new ApiError(\n 'Apenas o proprietário da conta pode alterar o nome da empresa',\n 'FORBIDDEN',\n 403\n );\n }\n }\n\n return accountService.updateAccount(data);\n });\n}\n\nexport async function deleteAccountUserAction(userId: number) {\n return safeServerAction(() => accountService.deleteAccountUser(userId));\n}\n\nexport async function deleteAccountAction() {\n return safeServerAction(() => accountService.deleteAccount());\n}\n\nexport async function createAccountUserAction(user: CreateAccountUserRequest) {\n return safeServerAction(() => accountService.createAccountUser(user));\n}\n\nexport async function changePasswordAction(data: ChangePasswordRequest) {\n return safeServerAction(() => accountService.changePassword(data));\n}\n\nexport async function requestEmailChangeAction(newEmail: string) {\n return safeServerAction(() => accountService.requestContactReset('email', newEmail));\n}\n\nexport async function confirmEmailChangeAction(token: string, newEmail: string) {\n return safeServerAction(() => accountService.confirmContactReset('email', token, newEmail));\n}\n\nexport async function requestPhoneChangeAction(newPhone: string, ddi?: string) {\n return safeServerAction(() => accountService.requestContactReset('phone', newPhone, ddi));\n}\n\nexport async function confirmPhoneChangeAction(token: string, newPhone: string, ddi?: string) {\n return safeServerAction(() => accountService.confirmContactReset('phone', token, newPhone, ddi));\n}\n\nexport async function generateTwoFactorAction() {\n return safeServerAction(async () => {\n const result = await twoFactorService.generate();\n return {\n qrcode: result.data.qrcode,\n backupCodes: result.data.backup_codes,\n };\n });\n}\n\nexport async function confirmTwoFactorAction(code: string) {\n return safeServerAction(async () => {\n await twoFactorService.confirm(code);\n await accountService.updateAccountUser({ two_factor_authentication: true });\n });\n}\n\nexport async function disableTwoFactorAction(code: string) {\n return safeServerAction(async () => {\n await twoFactorService.verify(code);\n await twoFactorService.disable();\n await accountService.updateAccountUser({ two_factor_authentication: false });\n });\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAQ/B,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,eAAsB,uBAAuB,QAAuC;AAClF,SAAO,iBAAiB,YAAY;AAClC,UAAM,EAAE,OAAO,MAAM,IAAI,MAAM,eAAe,iBAAiB,MAAM;AACrE,WAAO,EAAE,MAAM,OAAO,MAAM;AAAA,EAC9B,CAAC;AACH;AAEA,eAAsB,iBAAiB,MAAgC;AACrE,SAAO,iBAAiB,MAAM,eAAe,kBAAkB,IAAI,CAAC;AACtE;AAEA,eAAsB,4BACpB,QACA,MACA;AACA,SAAO,iBAAiB,MAAM,eAAe,sBAAsB,QAAQ,IAAI,CAAC;AAClF;AAEA,eAAsB,oBAAoB,MAA4B;AACpE,SAAO,iBAAiB,YAAY;AAClC,QAAI,KAAK,SAAS,QAAW;AAC3B,YAAM,aAAa,MAAM,aAAa;AACtC,UAAI,CAAC,WAAW,WAAW,WAAW,MAAM,YAAY,YAAY,OAAO;AACzE,cAAM,IAAI;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAEA,WAAO,eAAe,cAAc,IAAI;AAAA,EAC1C,CAAC;AACH;AAEA,eAAsB,wBAAwB,QAAgB;AAC5D,SAAO,iBAAiB,MAAM,eAAe,kBAAkB,M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A,EAC7E,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/accounts/actions/account-management.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { accountService } from '../services/account.service';\nimport type {\n AccountUsersPaginationParams,\n ChangePasswordRequest,\n CreateAccountUserRequest,\n UpdateAccountRequest,\n UpdateAccountUserRequest,\n} from '../types';\nimport { twoFactorService } from '../services/two-factor.service';\nimport { findUserById } from '../../users/action/find-user-by-id.action';\nimport { UserProfile } from '../../users/schema';\nimport { ApiError } from '../../../infra/api/types';\n\nexport async function listAccountUsersAction(params?: AccountUsersPaginationParams) {\n return safeServerAction(async () => {\n const { users, total } = await accountService.listAccountUsers(params);\n return { data: users, total };\n });\n}\n\nexport async function updateUserAction(user: UpdateAccountUserRequest) {\n return safeMutationAction(() => accountService.updateAccountUser(user));\n}\n\nexport async function updateAccountUserByIdAction(\n userId: number,\n user: UpdateAccountUserRequest\n) {\n return safeMutationAction(() => accountService.updateAccountUserById(userId, user));\n}\n\nexport async function updateAccountAction(data: UpdateAccountRequest) {\n return safeMutationAction(async () => {\n if (data.name !== undefined) {\n const userResult = await findUserById();\n if (!userResult.success || userResult.data?.profile !== UserProfile.owner) {\n throw new ApiError(\n 'Apenas o proprietário da conta pode alterar o nome da empresa',\n 'FORBIDDEN',\n 403\n );\n }\n }\n\n return accountService.updateAccount(data);\n });\n}\n\nexport async function deleteAccountUserAction(userId: number) {\n return safeMutationAction(() => accountService.deleteAccountUser(userId));\n}\n\nexport async function deleteAccountAction() {\n return safeMutationAction(() => accountService.deleteAccount());\n}\n\nexport async function createAccountUserAction(user: CreateAccountUserRequest) {\n return safeMutationAction(() => accountService.createAccountUser(user));\n}\n\nexport async function changePasswordAction(data: ChangePasswordRequest) {\n return safeMutationAction(() => accountService.changePassword(data));\n}\n\nexport async function requestEmailChangeAction(newEmail: string) {\n return safeMutationAction(() => accountService.requestContactReset('email', newEmail));\n}\n\nexport async function confirmEmailChangeAction(token: string, newEmail: string) {\n return safeMutationAction(() => accountService.confirmContactReset('email', token, newEmail));\n}\n\nexport async function requestPhoneChangeAction(newPhone: string, ddi?: string) {\n return safeMutationAction(() => accountService.requestContactReset('phone', newPhone, ddi));\n}\n\nexport async function confirmPhoneChangeAction(token: string, newPhone: string, ddi?: string) {\n return safeMutationAction(() => accountService.confirmContactReset('phone', token, newPhone, ddi));\n}\n\nexport async function generateTwoFactorAction() {\n return safeMutationAction(async () => {\n const result = await twoFactorService.generate();\n return {\n qrcode: result.data.qrcode,\n backupCodes: result.data.backup_codes,\n };\n });\n}\n\nexport async function confirmTwoFactorAction(code: string) {\n return safeMutationAction(async () => {\n await twoFactorService.confirm(code);\n await accountService.updateAccountUser({ two_factor_authentication: true });\n });\n}\n\nexport async function disableTwoFactorAction(code: string) {\n return safeMutationAction(async () => {\n await twoFactorService.verify(code);\n await twoFactorService.disable();\n await accountService.updateAccountUser({ two_factor_authentication: false });\n });\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AACnC,SAAS,sBAAsB;AAQ/B,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAC7B,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB;AAEzB,eAAsB,uBAAuB,QAAuC;AAClF,SAAO,iBAAiB,YAAY;AAClC,UAAM,EAAE,OAAO,MAAM,IAAI,MAAM,eAAe,iBAAiB,MAAM;AACrE,WAAO,EAAE,MAAM,OAAO,MAAM;AAAA,EAC9B,CAAC;AACH;AAEA,eAAsB,iBAAiB,MAAgC;AACrE,SAAO,mBAAmB,MAAM,eAAe,kBAAkB,IAAI,CAAC;AACxE;AAEA,eAAsB,4BACpB,QACA,MACA;AACA,SAAO,mBAAmB,MAAM,eAAe,sBAAsB,QAAQ,IAAI,CAAC;AACpF;AAEA,eAAsB,oBAAoB,MAA4B;AACpE,SAAO,mBAAmB,YAAY;AACpC,QAAI,KAAK,SAAS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ACzD,SAAO,mBAAmB,YAAY;AACpC,UAAM,iBAAiB,QAAQ,IAAI;AACnC,UAAM,eAAe,kBAAkB,EAAE,2BAA2B,KAAK,CAAC;AAAA,EAC5E,CAAC;AACH;AAEA,eAAsB,uBAAuB,MAAc;AACzD,SAAO,mBAAmB,YAAY;AACpC,UAAM,iBAAiB,OAAO,IAAI;AAClC,UAAM,iBAAiB,QAAQ;AAC/B,UAAM,eAAe,kBAAkB,EAAE,2BAA2B,MAAM,CAAC;AAAA,EAC7E,CAAC;AACH;","names":[]}
@@ -0,0 +1,17 @@
1
+ import "server-only";
2
+ import { cache } from "react";
3
+ import { ApiError } from "../../../infra/api/types";
4
+ import { getClientInfoFromRequest } from "../../../infra/utils/client-info";
5
+ import { authService } from "../services/auth.service";
6
+ const requireValidSession = cache(async () => {
7
+ if (process.env.DUMMY_AUTH_TOKEN) return;
8
+ const clientInfo = await getClientInfoFromRequest();
9
+ const isValid = await authService.validateSession(clientInfo);
10
+ if (!isValid) {
11
+ throw new ApiError("Sess\xE3o inv\xE1lida ou expirada", "SESSION_INVALID", 401);
12
+ }
13
+ });
14
+ export {
15
+ requireValidSession
16
+ };
17
+ //# sourceMappingURL=require-valid-session.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/modules/auth/utils/require-valid-session.ts"],"sourcesContent":["import 'server-only';\n\nimport { cache } from 'react';\n\nimport { ApiError } from '../../../infra/api/types';\nimport { getClientInfoFromRequest } from '../../../infra/utils/client-info';\nimport { authService } from '../services/auth.service';\n\n/**\n * Valida a sessão do usuário chamando POST /auth/keep no backend.\n *\n * Garante que o cookie `greatapps`:\n * 1. Existe.\n * 2. Corresponde a uma sessão registrada no banco (não foi forjado).\n * 3. Ainda é considerada válida pelo backend (não foi revogada/expirada).\n *\n * Deduplicada por request via React.cache — múltiplas chamadas dentro do\n * mesmo server action resultam em 1 round-trip ao backend, não N.\n *\n * Use em server actions sensíveis (mutações, billing, destrutivas).\n * Prefira o wrapper `safeMutationAction` que já envelopa isto junto com\n * o `safeServerAction` padrão.\n *\n * Em caso de erro de rede/backend, falha fechada (SESSION_INVALID 401).\n */\nexport const requireValidSession = cache(async (): Promise<void> => {\n if (process.env.DUMMY_AUTH_TOKEN) return;\n\n const clientInfo = await getClientInfoFromRequest();\n const isValid = await authService.validateSession(clientInfo);\n\n if (!isValid) {\n throw new ApiError('Sessão inválida ou expirada', 'SESSION_INVALID', 401);\n }\n});\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,aAAa;AAEtB,SAAS,gBAAgB;AACzB,SAAS,gCAAgC;AACzC,SAAS,mBAAmB;AAmBrB,MAAM,sBAAsB,MAAM,YAA2B;AAClE,MAAI,QAAQ,IAAI,iBAAkB;AAElC,QAAM,aAAa,MAAM,yBAAyB;AAClD,QAAM,UAAU,MAAM,YAAY,gBAAgB,UAAU;AAE5D,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,SAAS,qCAA+B,mBAAmB,GAAG;AAAA,EAC1E;AACF,CAAC;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { cardsService } from "../services/cards.service";
4
4
  async function createCardAction(data) {
5
- return safeServerAction(() => cardsService.createCard(data));
5
+ return safeMutationAction(() => cardsService.createCard(data));
6
6
  }
7
7
  export {
8
8
  createCardAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/cards/actions/create-card.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { cardsService } from '../services/cards.service';\nimport { CreateCardRequest } from '../types';\n\nexport async function createCardAction(data: CreateCardRequest) {\n return safeServerAction(() => cardsService.createCard(data));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAG7B,eAAsB,iBAAiB,MAAyB;AAC9D,SAAO,iBAAiB,MAAM,aAAa,WAAW,IAAI,CAAC;AAC7D;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/cards/actions/create-card.action.ts"],"sourcesContent":["'use server';\n\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { cardsService } from '../services/cards.service';\nimport { CreateCardRequest } from '../types';\n\nexport async function createCardAction(data: CreateCardRequest) {\n return safeMutationAction(() => cardsService.createCard(data));\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAG7B,eAAsB,iBAAiB,MAAyB;AAC9D,SAAO,mBAAmB,MAAM,aAAa,WAAW,IAAI,CAAC;AAC/D;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { cardsService } from "../services/cards.service";
4
4
  async function deleteCardAction(id) {
5
- return safeServerAction(() => cardsService.deleteCard(id));
5
+ return safeMutationAction(() => cardsService.deleteCard(id));
6
6
  }
7
7
  export {
8
8
  deleteCardAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/cards/actions/delete-card.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { cardsService } from '../services/cards.service';\n\nexport async function deleteCardAction(id: string) {\n return safeServerAction(() => cardsService.deleteCard(id));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAE7B,eAAsB,iBAAiB,IAAY;AACjD,SAAO,iBAAiB,MAAM,aAAa,WAAW,EAAE,CAAC;AAC3D;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/cards/actions/delete-card.action.ts"],"sourcesContent":["'use server';\n\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { cardsService } from '../services/cards.service';\n\nexport async function deleteCardAction(id: string) {\n return safeMutationAction(() => cardsService.deleteCard(id));\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAE7B,eAAsB,iBAAiB,IAAY;AACjD,SAAO,mBAAmB,MAAM,aAAa,WAAW,EAAE,CAAC;AAC7D;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { cardsService } from "../services/cards.service";
4
4
  async function setDefaultCardAction(cardId) {
5
- return safeServerAction(() => cardsService.setDefaultCard(cardId));
5
+ return safeMutationAction(() => cardsService.setDefaultCard(cardId));
6
6
  }
7
7
  export {
8
8
  setDefaultCardAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/cards/actions/set-default-card.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { cardsService } from '../services/cards.service';\n\nexport async function setDefaultCardAction(cardId: string) {\n return safeServerAction(() => cardsService.setDefaultCard(cardId));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,oBAAoB;AAE7B,eAAsB,qBAAqB,QAAgB;AACzD,SAAO,iBAAiB,MAAM,aAAa,eAAe,MAAM,CAAC;AACnE;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/cards/actions/set-default-card.action.ts"],"sourcesContent":["'use server';\n\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { cardsService } from '../services/cards.service';\n\nexport async function setDefaultCardAction(cardId: string) {\n return safeMutationAction(() => cardsService.setDefaultCard(cardId));\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAE7B,eAAsB,qBAAqB,QAAgB;AACzD,SAAO,mBAAmB,MAAM,aAAa,eAAe,MAAM,CAAC;AACrE;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { projectUsersService } from "../services/project-users.service";
4
4
  async function addProjectUserAction(params) {
5
- return safeServerAction(() => projectUsersService.addToProject(params));
5
+ return safeMutationAction(() => projectUsersService.addToProject(params));
6
6
  }
7
7
  export {
8
8
  addProjectUserAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/projects/actions/add-project-user.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { projectUsersService } from '../services/project-users.service';\nimport type { AddRemoveProjectUsersParams } from '../types';\n\nexport async function addProjectUserAction(params: AddRemoveProjectUsersParams) {\n return safeServerAction(() => projectUsersService.addToProject(params));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AAGpC,eAAsB,qBAAqB,QAAqC;AAC9E,SAAO,iBAAiB,MAAM,oBAAoB,aAAa,MAAM,CAAC;AACxE;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/projects/actions/add-project-user.action.ts"],"sourcesContent":["'use server';\n\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { projectUsersService } from '../services/project-users.service';\nimport type { AddRemoveProjectUsersParams } from '../types';\n\nexport async function addProjectUserAction(params: AddRemoveProjectUsersParams) {\n return safeMutationAction(() => projectUsersService.addToProject(params));\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AAGpC,eAAsB,qBAAqB,QAAqC;AAC9E,SAAO,mBAAmB,MAAM,oBAAoB,aAAa,MAAM,CAAC;AAC1E;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { projectsService } from "../services/projects.service";
4
4
  async function createProjectAction(data) {
5
- return safeServerAction(() => projectsService.create(data));
5
+ return safeMutationAction(() => projectsService.create(data));
6
6
  }
7
7
  export {
8
8
  createProjectAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/projects/actions/create-project.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { projectsService } from '../services/projects.service';\nimport type { CreateProjectRequest } from '../types';\n\nexport async function createProjectAction(data: CreateProjectRequest) {\n return safeServerAction(() => projectsService.create(data));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAGhC,eAAsB,oBAAoB,MAA4B;AACpE,SAAO,iBAAiB,MAAM,gBAAgB,OAAO,IAAI,CAAC;AAC5D;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/projects/actions/create-project.action.ts"],"sourcesContent":["'use server';\n\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { projectsService } from '../services/projects.service';\nimport type { CreateProjectRequest } from '../types';\n\nexport async function createProjectAction(data: CreateProjectRequest) {\n return safeMutationAction(() => projectsService.create(data));\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAGhC,eAAsB,oBAAoB,MAA4B;AACpE,SAAO,mBAAmB,MAAM,gBAAgB,OAAO,IAAI,CAAC;AAC9D;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { projectsService } from "../services/projects.service";
4
4
  async function deleteProjectAction(projectId, moveToProjectId) {
5
- return safeServerAction(() => projectsService.delete(projectId, moveToProjectId));
5
+ return safeMutationAction(() => projectsService.delete(projectId, moveToProjectId));
6
6
  }
7
7
  export {
8
8
  deleteProjectAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/projects/actions/delete-project.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { projectsService } from '../services/projects.service';\n\nexport async function deleteProjectAction(projectId: number, moveToProjectId: number) {\n return safeServerAction(() => projectsService.delete(projectId, moveToProjectId));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAEhC,eAAsB,oBAAoB,WAAmB,iBAAyB;AACpF,SAAO,iBAAiB,MAAM,gBAAgB,OAAO,WAAW,eAAe,CAAC;AAClF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/projects/actions/delete-project.action.ts"],"sourcesContent":["'use server';\n\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { projectsService } from '../services/projects.service';\n\nexport async function deleteProjectAction(projectId: number, moveToProjectId: number) {\n return safeMutationAction(() => projectsService.delete(projectId, moveToProjectId));\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAEhC,eAAsB,oBAAoB,WAAmB,iBAAyB;AACpF,SAAO,mBAAmB,MAAM,gBAAgB,OAAO,WAAW,eAAe,CAAC;AACpF;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { projectUsersService } from "../services/project-users.service";
4
4
  async function removeProjectUserAction(params) {
5
- return safeServerAction(() => projectUsersService.removeFromProject(params));
5
+ return safeMutationAction(() => projectUsersService.removeFromProject(params));
6
6
  }
7
7
  export {
8
8
  removeProjectUserAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/projects/actions/remove-project-user.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { projectUsersService } from '../services/project-users.service';\nimport type { AddRemoveProjectUsersParams } from '../types';\n\nexport async function removeProjectUserAction(params: AddRemoveProjectUsersParams) {\n return safeServerAction(() => projectUsersService.removeFromProject(params));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,2BAA2B;AAGpC,eAAsB,wBAAwB,QAAqC;AACjF,SAAO,iBAAiB,MAAM,oBAAoB,kBAAkB,MAAM,CAAC;AAC7E;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/projects/actions/remove-project-user.action.ts"],"sourcesContent":["'use server';\n\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { projectUsersService } from '../services/project-users.service';\nimport type { AddRemoveProjectUsersParams } from '../types';\n\nexport async function removeProjectUserAction(params: AddRemoveProjectUsersParams) {\n return safeMutationAction(() => projectUsersService.removeFromProject(params));\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AACnC,SAAS,2BAA2B;AAGpC,eAAsB,wBAAwB,QAAqC;AACjF,SAAO,mBAAmB,MAAM,oBAAoB,kBAAkB,MAAM,CAAC;AAC/E;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { projectsService } from "../services/projects.service";
4
4
  async function updateProjectAction(projectId, data) {
5
- return safeServerAction(() => projectsService.update(projectId, data));
5
+ return safeMutationAction(() => projectsService.update(projectId, data));
6
6
  }
7
7
  export {
8
8
  updateProjectAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/projects/actions/update-project.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { projectsService } from '../services/projects.service';\nimport type { UpdateProjectRequest } from '../types';\n\nexport async function updateProjectAction(projectId: number, data: UpdateProjectRequest) {\n return safeServerAction(() => projectsService.update(projectId, data));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAGhC,eAAsB,oBAAoB,WAAmB,MAA4B;AACvF,SAAO,iBAAiB,MAAM,gBAAgB,OAAO,WAAW,IAAI,CAAC;AACvE;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/projects/actions/update-project.action.ts"],"sourcesContent":["'use server';\n\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { projectsService } from '../services/projects.service';\nimport type { UpdateProjectRequest } from '../types';\n\nexport async function updateProjectAction(projectId: number, data: UpdateProjectRequest) {\n return safeMutationAction(() => projectsService.update(projectId, data));\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAGhC,eAAsB,oBAAoB,WAAmB,MAA4B;AACvF,SAAO,mBAAmB,MAAM,gBAAgB,OAAO,WAAW,IAAI,CAAC;AACzE;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { subscriptionsService } from "../services/subscriptions.service";
4
4
  async function updateSubscriptionPlanAction(subscriptionId, data) {
5
- return safeServerAction(async () => {
5
+ return safeMutationAction(async () => {
6
6
  return subscriptionsService.updateSubscriptionPlan(subscriptionId, data);
7
7
  });
8
8
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/subscriptions/actions/update-subscription-plan.action.ts"],"sourcesContent":["\"use server\";\n\nimport { safeServerAction } from \"../../../utils/safeServerAction\";\nimport type { UpdateSubscriptionPlanRequest } from \"../types/calculate-subscription.type\";\nimport { subscriptionsService } from \"../services/subscriptions.service\";\n\nexport async function updateSubscriptionPlanAction(\n subscriptionId: number | string,\n data: UpdateSubscriptionPlanRequest,\n) {\n return safeServerAction(async () => {\n return subscriptionsService.updateSubscriptionPlan(subscriptionId, data);\n });\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AAEjC,SAAS,4BAA4B;AAErC,eAAsB,6BACpB,gBACA,MACA;AACA,SAAO,iBAAiB,YAAY;AAClC,WAAO,qBAAqB,uBAAuB,gBAAgB,IAAI;AAAA,EACzE,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/subscriptions/actions/update-subscription-plan.action.ts"],"sourcesContent":["\"use server\";\n\nimport { safeMutationAction } from \"../../../utils/safeMutationAction\";\nimport type { UpdateSubscriptionPlanRequest } from \"../types/calculate-subscription.type\";\nimport { subscriptionsService } from \"../services/subscriptions.service\";\n\nexport async function updateSubscriptionPlanAction(\n subscriptionId: number | string,\n data: UpdateSubscriptionPlanRequest,\n) {\n return safeMutationAction(async () => {\n return subscriptionsService.updateSubscriptionPlan(subscriptionId, data);\n });\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AAEnC,SAAS,4BAA4B;AAErC,eAAsB,6BACpB,gBACA,MACA;AACA,SAAO,mBAAmB,YAAY;AACpC,WAAO,qBAAqB,uBAAuB,gBAAgB,IAAI;AAAA,EACzE,CAAC;AACH;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { messagesService } from "../services/messages.service";
4
4
  async function markAllMessagesAsReadAction() {
5
- return safeServerAction(() => messagesService.markAllAsRead());
5
+ return safeMutationAction(() => messagesService.markAllAsRead());
6
6
  }
7
7
  export {
8
8
  markAllMessagesAsReadAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/users/action/mark-all-messages-as-read.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { messagesService } from '../services/messages.service';\n\nexport async function markAllMessagesAsReadAction() {\n return safeServerAction(() => messagesService.markAllAsRead());\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAEhC,eAAsB,8BAA8B;AAClD,SAAO,iBAAiB,MAAM,gBAAgB,cAAc,CAAC;AAC/D;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/users/action/mark-all-messages-as-read.action.ts"],"sourcesContent":["'use server';\n\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { messagesService } from '../services/messages.service';\n\nexport async function markAllMessagesAsReadAction() {\n return safeMutationAction(() => messagesService.markAllAsRead());\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAEhC,eAAsB,8BAA8B;AAClD,SAAO,mBAAmB,MAAM,gBAAgB,cAAc,CAAC;AACjE;","names":[]}
@@ -1,8 +1,8 @@
1
1
  "use server";
2
- import { safeServerAction } from "../../../utils/safeServerAction";
2
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
3
3
  import { messagesService } from "../services/messages.service";
4
4
  async function markMessageAsReadAction(messageId) {
5
- return safeServerAction(() => messagesService.markAsRead(messageId));
5
+ return safeMutationAction(() => messagesService.markAsRead(messageId));
6
6
  }
7
7
  export {
8
8
  markMessageAsReadAction
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/modules/users/action/mark-message-as-read.action.ts"],"sourcesContent":["'use server';\n\nimport { safeServerAction } from '../../../utils/safeServerAction';\nimport { messagesService } from '../services/messages.service';\n\nexport async function markMessageAsReadAction(messageId: string) {\n return safeServerAction(() => messagesService.markAsRead(messageId));\n}\n"],"mappings":";AAEA,SAAS,wBAAwB;AACjC,SAAS,uBAAuB;AAEhC,eAAsB,wBAAwB,WAAmB;AAC/D,SAAO,iBAAiB,MAAM,gBAAgB,WAAW,SAAS,CAAC;AACrE;","names":[]}
1
+ {"version":3,"sources":["../../../../src/modules/users/action/mark-message-as-read.action.ts"],"sourcesContent":["'use server';\n\nimport { safeMutationAction } from '../../../utils/safeMutationAction';\nimport { messagesService } from '../services/messages.service';\n\nexport async function markMessageAsReadAction(messageId: string) {\n return safeMutationAction(() => messagesService.markAsRead(messageId));\n}\n"],"mappings":";AAEA,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAEhC,eAAsB,wBAAwB,WAAmB;AAC/D,SAAO,mBAAmB,MAAM,gBAAgB,WAAW,SAAS,CAAC;AACvE;","names":[]}
package/dist/server.mjs CHANGED
@@ -59,8 +59,10 @@ import {
59
59
  } from "./modules/accounts/actions/account-management.action";
60
60
  import { getClientInfoFromRequest } from "./infra/utils/client-info";
61
61
  import { getUserContext } from "./modules/auth/utils/get-user-context";
62
+ import { requireValidSession } from "./modules/auth/utils/require-valid-session";
62
63
  import { buildWlOverride, buildWlOverrideFromJwt } from "./modules/auth/utils/build-wl-override";
63
64
  import { safeServerAction } from "./utils/safeServerAction";
65
+ import { safeMutationAction } from "./utils/safeMutationAction";
64
66
  import { processImageAction } from "./modules/images/actions/process-image.action";
65
67
  import { processImage } from "./modules/images/services/image-processing.service";
66
68
  export {
@@ -117,8 +119,10 @@ export {
117
119
  removeProjectUserAction,
118
120
  requestEmailChangeAction,
119
121
  requestPhoneChangeAction,
122
+ requireValidSession,
120
123
  resolvePlanExtrasPrices,
121
124
  revalidateWhitelabelAction,
125
+ safeMutationAction,
122
126
  safeServerAction,
123
127
  subscriptionsService,
124
128
  twoFactorService,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/server.ts"],"sourcesContent":["import 'server-only';\r\n\r\n// API Client\r\nexport { ApiClient, api, apiClient } from './infra/api/client';\r\n\r\n// Services\r\nexport { authService } from './modules/auth/services/auth.service';\r\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\r\nexport { revalidateWhitelabelAction } from './modules/whitelabel/actions/revalidate-whitelabel.action';\r\nexport { assertManagementPermission } from './modules/auth/utils/assert-management-permission';\r\nexport { assertManagementSubscription } from './modules/auth/utils/assert-management-subscription';\r\nexport { assertSubscriptionAddon } from './modules/auth/utils/assert-subscription-addon';\r\nexport { assertPaidSubscription } from './modules/auth/utils/assert-paid-subscription';\r\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';\r\nexport { plansService } from './modules/plans/services/plans.service';\r\nexport { cardsService } from './modules/cards/services/cards.service';\r\nexport { iaCreditsService } from './modules/ia-credits/services/ia-credits.service';\r\n\r\n// Actions\r\nexport { findWhitelabel } from './modules/whitelabel/actions/find-whitelabel.action';\r\nexport { validateSessionAction } from './modules/auth/actions/validate-session.action';\r\nexport { findUserById } from './modules/users/action/find-user-by-id.action';\r\nexport { findCurrentAccount } from './modules/accounts/actions/find-current-account.action';\r\nexport { getAccountTokenAction } from './modules/accounts/actions/get-account-token.action';\r\nexport { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';\r\nexport { findPlanByIdAction } from './modules/plans/actions/find-plan-by-id.action';\r\nexport { listPlansAction } from './modules/plans/actions/list-plans.action';\r\nexport { calculateSubscriptionAction } from './modules/subscriptions/actions/calculate-subscription.action';\r\nexport { updateSubscriptionPlanAction } from './modules/subscriptions/actions/update-subscription-plan.action';\r\nexport { listCardsAction } from './modules/cards/actions/list-cards.action';\r\nexport { createCardAction } from './modules/cards/actions/create-card.action';\r\nexport { resolvePlanExtrasPrices } from './modules/subscriptions/utils/resolve-plan-extras-prices';\r\nexport { hasSubscriptionExpired } from './modules/subscriptions/utils/has-subscription-expired';\r\nexport { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';\r\nexport { countPagesAction } from './modules/pages/actions/count-pages.action';\r\n\r\n// Project Services & Actions (server-only)\r\nexport { projectsService } from './modules/projects/services/projects.service';\r\nexport { listProjectsAction } from './modules/projects/actions/list-projects.action';\r\nexport { findProjectAction } from './modules/projects/actions/find-project.action';\r\nexport { createProjectAction } from './modules/projects/actions/create-project.action';\r\nexport { updateProjectAction } from './modules/projects/actions/update-project.action';\r\nexport { deleteProjectAction } from './modules/projects/actions/delete-project.action';\r\n\r\n// Project Users Services & Actions (server-only)\r\nexport { projectUsersService } from './modules/projects/services/project-users.service';\r\nexport { listProjectUsersAction } from './modules/projects/actions/list-project-users.action';\r\nexport { listAvailableUsersAction } from './modules/projects/actions/list-available-users.action';\r\nexport { addProjectUserAction } from './modules/projects/actions/add-project-user.action';\r\nexport { removeProjectUserAction } from './modules/projects/actions/remove-project-user.action';\r\n\r\n// Account Services & Actions (server-only)\r\nexport { accountService } from './modules/accounts/services/account.service';\r\nexport { twoFactorService } from './modules/accounts/services/two-factor.service';\r\nexport {\r\n listAccountUsersAction,\r\n updateUserAction,\r\n updateAccountAction,\r\n updateAccountUserByIdAction,\r\n deleteAccountUserAction,\r\n deleteAccountAction,\r\n createAccountUserAction,\r\n changePasswordAction,\r\n requestEmailChangeAction,\r\n confirmEmailChangeAction,\r\n requestPhoneChangeAction,\r\n confirmPhoneChangeAction,\r\n generateTwoFactorAction,\r\n confirmTwoFactorAction,\r\n disableTwoFactorAction,\r\n} from './modules/accounts/actions/account-management.action';\r\n\r\n// Server Utils\r\nexport { getClientInfoFromRequest } from './infra/utils/client-info';\r\nexport { getUserContext } from './modules/auth/utils/get-user-context';\r\nexport { buildWlOverride, buildWlOverrideFromJwt } from './modules/auth/utils/build-wl-override';\r\nexport { safeServerAction } from './utils/safeServerAction';\r\n\r\n// Image Processing (server-side)\r\nexport { processImageAction } from './modules/images/actions/process-image.action';\r\nexport { processImage } from './modules/images/services/image-processing.service';\r\nexport type {\r\n ProcessImageInput,\r\n ProcessImageOutput,\r\n ProcessImageActionInput,\r\n ProcessImageActionOutput,\r\n} from './modules/images/types/image.type';\r\n"],"mappings":"AAAA,OAAO;AAGP,SAAS,WAAW,KAAK,iBAAiB;AAG1C,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,kCAAkC;AAC3C,SAAS,kCAAkC;AAC3C,SAAS,oCAAoC;AAC7C,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AACvC,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AAGjC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,mCAAmC;AAC5C,SAAS,oCAAoC;AAC7C,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AAGjC,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AAGpC,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,gCAAgC;AACzC,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AAGxC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,gCAAgC;AACzC,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB,8BAA8B;AACxD,SAAS,wBAAwB;AAGjC,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;","names":[]}
1
+ {"version":3,"sources":["../src/server.ts"],"sourcesContent":["import 'server-only';\r\n\r\n// API Client\r\nexport { ApiClient, api, apiClient } from './infra/api/client';\r\n\r\n// Services\r\nexport { authService } from './modules/auth/services/auth.service';\r\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\r\nexport { revalidateWhitelabelAction } from './modules/whitelabel/actions/revalidate-whitelabel.action';\r\nexport { assertManagementPermission } from './modules/auth/utils/assert-management-permission';\r\nexport { assertManagementSubscription } from './modules/auth/utils/assert-management-subscription';\r\nexport { assertSubscriptionAddon } from './modules/auth/utils/assert-subscription-addon';\r\nexport { assertPaidSubscription } from './modules/auth/utils/assert-paid-subscription';\r\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';\r\nexport { plansService } from './modules/plans/services/plans.service';\r\nexport { cardsService } from './modules/cards/services/cards.service';\r\nexport { iaCreditsService } from './modules/ia-credits/services/ia-credits.service';\r\n\r\n// Actions\r\nexport { findWhitelabel } from './modules/whitelabel/actions/find-whitelabel.action';\r\nexport { validateSessionAction } from './modules/auth/actions/validate-session.action';\r\nexport { findUserById } from './modules/users/action/find-user-by-id.action';\r\nexport { findCurrentAccount } from './modules/accounts/actions/find-current-account.action';\r\nexport { getAccountTokenAction } from './modules/accounts/actions/get-account-token.action';\r\nexport { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';\r\nexport { findPlanByIdAction } from './modules/plans/actions/find-plan-by-id.action';\r\nexport { listPlansAction } from './modules/plans/actions/list-plans.action';\r\nexport { calculateSubscriptionAction } from './modules/subscriptions/actions/calculate-subscription.action';\r\nexport { updateSubscriptionPlanAction } from './modules/subscriptions/actions/update-subscription-plan.action';\r\nexport { listCardsAction } from './modules/cards/actions/list-cards.action';\r\nexport { createCardAction } from './modules/cards/actions/create-card.action';\r\nexport { resolvePlanExtrasPrices } from './modules/subscriptions/utils/resolve-plan-extras-prices';\r\nexport { hasSubscriptionExpired } from './modules/subscriptions/utils/has-subscription-expired';\r\nexport { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';\r\nexport { countPagesAction } from './modules/pages/actions/count-pages.action';\r\n\r\n// Project Services & Actions (server-only)\r\nexport { projectsService } from './modules/projects/services/projects.service';\r\nexport { listProjectsAction } from './modules/projects/actions/list-projects.action';\r\nexport { findProjectAction } from './modules/projects/actions/find-project.action';\r\nexport { createProjectAction } from './modules/projects/actions/create-project.action';\r\nexport { updateProjectAction } from './modules/projects/actions/update-project.action';\r\nexport { deleteProjectAction } from './modules/projects/actions/delete-project.action';\r\n\r\n// Project Users Services & Actions (server-only)\r\nexport { projectUsersService } from './modules/projects/services/project-users.service';\r\nexport { listProjectUsersAction } from './modules/projects/actions/list-project-users.action';\r\nexport { listAvailableUsersAction } from './modules/projects/actions/list-available-users.action';\r\nexport { addProjectUserAction } from './modules/projects/actions/add-project-user.action';\r\nexport { removeProjectUserAction } from './modules/projects/actions/remove-project-user.action';\r\n\r\n// Account Services & Actions (server-only)\r\nexport { accountService } from './modules/accounts/services/account.service';\r\nexport { twoFactorService } from './modules/accounts/services/two-factor.service';\r\nexport {\r\n listAccountUsersAction,\r\n updateUserAction,\r\n updateAccountAction,\r\n updateAccountUserByIdAction,\r\n deleteAccountUserAction,\r\n deleteAccountAction,\r\n createAccountUserAction,\r\n changePasswordAction,\r\n requestEmailChangeAction,\r\n confirmEmailChangeAction,\r\n requestPhoneChangeAction,\r\n confirmPhoneChangeAction,\r\n generateTwoFactorAction,\r\n confirmTwoFactorAction,\r\n disableTwoFactorAction,\r\n} from './modules/accounts/actions/account-management.action';\r\n\r\n// Server Utils\r\nexport { getClientInfoFromRequest } from './infra/utils/client-info';\r\nexport { getUserContext } from './modules/auth/utils/get-user-context';\r\nexport { requireValidSession } from './modules/auth/utils/require-valid-session';\r\nexport { buildWlOverride, buildWlOverrideFromJwt } from './modules/auth/utils/build-wl-override';\r\nexport { safeServerAction } from './utils/safeServerAction';\r\nexport { safeMutationAction } from './utils/safeMutationAction';\r\n\r\n// Image Processing (server-side)\r\nexport { processImageAction } from './modules/images/actions/process-image.action';\r\nexport { processImage } from './modules/images/services/image-processing.service';\r\nexport type {\r\n ProcessImageInput,\r\n ProcessImageOutput,\r\n ProcessImageActionInput,\r\n ProcessImageActionOutput,\r\n} from './modules/images/types/image.type';\r\n"],"mappings":"AAAA,OAAO;AAGP,SAAS,WAAW,KAAK,iBAAiB;AAG1C,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,kCAAkC;AAC3C,SAAS,kCAAkC;AAC3C,SAAS,oCAAoC;AAC7C,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AACvC,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAC7B,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB;AAGjC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,mCAAmC;AAC5C,SAAS,oCAAoC;AAC7C,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AAGjC,SAAS,uBAAuB;AAChC,SAAS,0BAA0B;AACnC,SAAS,yBAAyB;AAClC,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AACpC,SAAS,2BAA2B;AAGpC,SAAS,2BAA2B;AACpC,SAAS,8BAA8B;AACvC,SAAS,gCAAgC;AACzC,SAAS,4BAA4B;AACrC,SAAS,+BAA+B;AAGxC,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,gCAAgC;AACzC,SAAS,sBAAsB;AAC/B,SAAS,2BAA2B;AACpC,SAAS,iBAAiB,8BAA8B;AACxD,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AAGnC,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;","names":[]}
@@ -0,0 +1,13 @@
1
+ import "server-only";
2
+ import { requireValidSession } from "../modules/auth/utils/require-valid-session";
3
+ import { safeServerAction } from "./safeServerAction";
4
+ async function safeMutationAction(fn) {
5
+ return safeServerAction(async () => {
6
+ await requireValidSession();
7
+ return fn();
8
+ });
9
+ }
10
+ export {
11
+ safeMutationAction
12
+ };
13
+ //# sourceMappingURL=safeMutationAction.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/utils/safeMutationAction.ts"],"sourcesContent":["import 'server-only';\n\nimport type { ActionResult } from '../infra/api/types';\nimport { requireValidSession } from '../modules/auth/utils/require-valid-session';\nimport { safeServerAction } from './safeServerAction';\n\n/**\n * Wrapper para server actions que mutam estado (delete/update/create/publish/\n * billing/etc.). Faz validação de sessão contra o backend (`POST /auth/keep`)\n * antes de executar a ação e roteia erros via `safeServerAction`.\n *\n * A validação é deduplicada por request — múltiplas actions sensíveis que\n * rodem dentro de uma mesma request pagam 1 round-trip ao backend, não N.\n *\n * Motivação (resumo): o backend confia no par `(whitelabel-token, id_account\n * no path)` nos endpoints de CRUD; o Next.js deriva `id_account` de\n * `atob(cookie)` sem verificar assinatura. Chamar `requireValidSession`\n * aqui garante que o cookie corresponde a uma sessão real no banco antes\n * de qualquer mutação.\n *\n * Para reads não-sensíveis, continue usando `safeServerAction` direto.\n */\nexport async function safeMutationAction<T>(\n fn: () => Promise<T>\n): Promise<ActionResult<T>> {\n return safeServerAction(async () => {\n await requireValidSession();\n return fn();\n });\n}\n"],"mappings":"AAAA,OAAO;AAGP,SAAS,2BAA2B;AACpC,SAAS,wBAAwB;AAkBjC,eAAsB,mBACpB,IAC0B;AAC1B,SAAO,iBAAiB,YAAY;AAClC,UAAM,oBAAoB;AAC1B,WAAO,GAAG;AAAA,EACZ,CAAC;AACH;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatapps/common",
3
- "version": "1.1.542",
3
+ "version": "1.1.543",
4
4
  "description": "Shared library for GreatApps frontend applications",
5
5
  "main": "./dist/index.mjs",
6
6
  "types": "./src/index.ts",
@@ -36,6 +36,7 @@ export default function ConfigurationsMyAccountModal() {
36
36
  const isBlockingSubscription =
37
37
  isPaidSubscriptionType &&
38
38
  subscription.active === true &&
39
+ !subscription.date_cancellation &&
39
40
  !hasSubscriptionExpired(subscription.date_due);
40
41
 
41
42
  const { user } = useAuth();
@@ -1,6 +1,7 @@
1
1
  'use server';
2
2
 
3
3
  import { safeServerAction } from '../../../utils/safeServerAction';
4
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
5
  import { accountService } from '../services/account.service';
5
6
  import type {
6
7
  AccountUsersPaginationParams,
@@ -22,18 +23,18 @@ export async function listAccountUsersAction(params?: AccountUsersPaginationPara
22
23
  }
23
24
 
24
25
  export async function updateUserAction(user: UpdateAccountUserRequest) {
25
- return safeServerAction(() => accountService.updateAccountUser(user));
26
+ return safeMutationAction(() => accountService.updateAccountUser(user));
26
27
  }
27
28
 
28
29
  export async function updateAccountUserByIdAction(
29
30
  userId: number,
30
31
  user: UpdateAccountUserRequest
31
32
  ) {
32
- return safeServerAction(() => accountService.updateAccountUserById(userId, user));
33
+ return safeMutationAction(() => accountService.updateAccountUserById(userId, user));
33
34
  }
34
35
 
35
36
  export async function updateAccountAction(data: UpdateAccountRequest) {
36
- return safeServerAction(async () => {
37
+ return safeMutationAction(async () => {
37
38
  if (data.name !== undefined) {
38
39
  const userResult = await findUserById();
39
40
  if (!userResult.success || userResult.data?.profile !== UserProfile.owner) {
@@ -50,39 +51,39 @@ export async function updateAccountAction(data: UpdateAccountRequest) {
50
51
  }
51
52
 
52
53
  export async function deleteAccountUserAction(userId: number) {
53
- return safeServerAction(() => accountService.deleteAccountUser(userId));
54
+ return safeMutationAction(() => accountService.deleteAccountUser(userId));
54
55
  }
55
56
 
56
57
  export async function deleteAccountAction() {
57
- return safeServerAction(() => accountService.deleteAccount());
58
+ return safeMutationAction(() => accountService.deleteAccount());
58
59
  }
59
60
 
60
61
  export async function createAccountUserAction(user: CreateAccountUserRequest) {
61
- return safeServerAction(() => accountService.createAccountUser(user));
62
+ return safeMutationAction(() => accountService.createAccountUser(user));
62
63
  }
63
64
 
64
65
  export async function changePasswordAction(data: ChangePasswordRequest) {
65
- return safeServerAction(() => accountService.changePassword(data));
66
+ return safeMutationAction(() => accountService.changePassword(data));
66
67
  }
67
68
 
68
69
  export async function requestEmailChangeAction(newEmail: string) {
69
- return safeServerAction(() => accountService.requestContactReset('email', newEmail));
70
+ return safeMutationAction(() => accountService.requestContactReset('email', newEmail));
70
71
  }
71
72
 
72
73
  export async function confirmEmailChangeAction(token: string, newEmail: string) {
73
- return safeServerAction(() => accountService.confirmContactReset('email', token, newEmail));
74
+ return safeMutationAction(() => accountService.confirmContactReset('email', token, newEmail));
74
75
  }
75
76
 
76
77
  export async function requestPhoneChangeAction(newPhone: string, ddi?: string) {
77
- return safeServerAction(() => accountService.requestContactReset('phone', newPhone, ddi));
78
+ return safeMutationAction(() => accountService.requestContactReset('phone', newPhone, ddi));
78
79
  }
79
80
 
80
81
  export async function confirmPhoneChangeAction(token: string, newPhone: string, ddi?: string) {
81
- return safeServerAction(() => accountService.confirmContactReset('phone', token, newPhone, ddi));
82
+ return safeMutationAction(() => accountService.confirmContactReset('phone', token, newPhone, ddi));
82
83
  }
83
84
 
84
85
  export async function generateTwoFactorAction() {
85
- return safeServerAction(async () => {
86
+ return safeMutationAction(async () => {
86
87
  const result = await twoFactorService.generate();
87
88
  return {
88
89
  qrcode: result.data.qrcode,
@@ -92,14 +93,14 @@ export async function generateTwoFactorAction() {
92
93
  }
93
94
 
94
95
  export async function confirmTwoFactorAction(code: string) {
95
- return safeServerAction(async () => {
96
+ return safeMutationAction(async () => {
96
97
  await twoFactorService.confirm(code);
97
98
  await accountService.updateAccountUser({ two_factor_authentication: true });
98
99
  });
99
100
  }
100
101
 
101
102
  export async function disableTwoFactorAction(code: string) {
102
- return safeServerAction(async () => {
103
+ return safeMutationAction(async () => {
103
104
  await twoFactorService.verify(code);
104
105
  await twoFactorService.disable();
105
106
  await accountService.updateAccountUser({ two_factor_authentication: false });
@@ -0,0 +1,35 @@
1
+ import 'server-only';
2
+
3
+ import { cache } from 'react';
4
+
5
+ import { ApiError } from '../../../infra/api/types';
6
+ import { getClientInfoFromRequest } from '../../../infra/utils/client-info';
7
+ import { authService } from '../services/auth.service';
8
+
9
+ /**
10
+ * Valida a sessão do usuário chamando POST /auth/keep no backend.
11
+ *
12
+ * Garante que o cookie `greatapps`:
13
+ * 1. Existe.
14
+ * 2. Corresponde a uma sessão registrada no banco (não foi forjado).
15
+ * 3. Ainda é considerada válida pelo backend (não foi revogada/expirada).
16
+ *
17
+ * Deduplicada por request via React.cache — múltiplas chamadas dentro do
18
+ * mesmo server action resultam em 1 round-trip ao backend, não N.
19
+ *
20
+ * Use em server actions sensíveis (mutações, billing, destrutivas).
21
+ * Prefira o wrapper `safeMutationAction` que já envelopa isto junto com
22
+ * o `safeServerAction` padrão.
23
+ *
24
+ * Em caso de erro de rede/backend, falha fechada (SESSION_INVALID 401).
25
+ */
26
+ export const requireValidSession = cache(async (): Promise<void> => {
27
+ if (process.env.DUMMY_AUTH_TOKEN) return;
28
+
29
+ const clientInfo = await getClientInfoFromRequest();
30
+ const isValid = await authService.validateSession(clientInfo);
31
+
32
+ if (!isValid) {
33
+ throw new ApiError('Sessão inválida ou expirada', 'SESSION_INVALID', 401);
34
+ }
35
+ });
@@ -1,9 +1,9 @@
1
1
  'use server';
2
2
 
3
- import { safeServerAction } from '../../../utils/safeServerAction';
3
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
4
  import { cardsService } from '../services/cards.service';
5
5
  import { CreateCardRequest } from '../types';
6
6
 
7
7
  export async function createCardAction(data: CreateCardRequest) {
8
- return safeServerAction(() => cardsService.createCard(data));
8
+ return safeMutationAction(() => cardsService.createCard(data));
9
9
  }
@@ -1,8 +1,8 @@
1
1
  'use server';
2
2
 
3
- import { safeServerAction } from '../../../utils/safeServerAction';
3
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
4
  import { cardsService } from '../services/cards.service';
5
5
 
6
6
  export async function deleteCardAction(id: string) {
7
- return safeServerAction(() => cardsService.deleteCard(id));
7
+ return safeMutationAction(() => cardsService.deleteCard(id));
8
8
  }
@@ -1,8 +1,8 @@
1
1
  'use server';
2
2
 
3
- import { safeServerAction } from '../../../utils/safeServerAction';
3
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
4
  import { cardsService } from '../services/cards.service';
5
5
 
6
6
  export async function setDefaultCardAction(cardId: string) {
7
- return safeServerAction(() => cardsService.setDefaultCard(cardId));
7
+ return safeMutationAction(() => cardsService.setDefaultCard(cardId));
8
8
  }
@@ -1,9 +1,9 @@
1
1
  'use server';
2
2
 
3
- import { safeServerAction } from '../../../utils/safeServerAction';
3
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
4
  import { projectUsersService } from '../services/project-users.service';
5
5
  import type { AddRemoveProjectUsersParams } from '../types';
6
6
 
7
7
  export async function addProjectUserAction(params: AddRemoveProjectUsersParams) {
8
- return safeServerAction(() => projectUsersService.addToProject(params));
8
+ return safeMutationAction(() => projectUsersService.addToProject(params));
9
9
  }
@@ -1,9 +1,9 @@
1
1
  'use server';
2
2
 
3
- import { safeServerAction } from '../../../utils/safeServerAction';
3
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
4
  import { projectsService } from '../services/projects.service';
5
5
  import type { CreateProjectRequest } from '../types';
6
6
 
7
7
  export async function createProjectAction(data: CreateProjectRequest) {
8
- return safeServerAction(() => projectsService.create(data));
8
+ return safeMutationAction(() => projectsService.create(data));
9
9
  }
@@ -1,8 +1,8 @@
1
1
  'use server';
2
2
 
3
- import { safeServerAction } from '../../../utils/safeServerAction';
3
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
4
  import { projectsService } from '../services/projects.service';
5
5
 
6
6
  export async function deleteProjectAction(projectId: number, moveToProjectId: number) {
7
- return safeServerAction(() => projectsService.delete(projectId, moveToProjectId));
7
+ return safeMutationAction(() => projectsService.delete(projectId, moveToProjectId));
8
8
  }
@@ -1,9 +1,9 @@
1
1
  'use server';
2
2
 
3
- import { safeServerAction } from '../../../utils/safeServerAction';
3
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
4
  import { projectUsersService } from '../services/project-users.service';
5
5
  import type { AddRemoveProjectUsersParams } from '../types';
6
6
 
7
7
  export async function removeProjectUserAction(params: AddRemoveProjectUsersParams) {
8
- return safeServerAction(() => projectUsersService.removeFromProject(params));
8
+ return safeMutationAction(() => projectUsersService.removeFromProject(params));
9
9
  }
@@ -1,9 +1,9 @@
1
1
  'use server';
2
2
 
3
- import { safeServerAction } from '../../../utils/safeServerAction';
3
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
4
  import { projectsService } from '../services/projects.service';
5
5
  import type { UpdateProjectRequest } from '../types';
6
6
 
7
7
  export async function updateProjectAction(projectId: number, data: UpdateProjectRequest) {
8
- return safeServerAction(() => projectsService.update(projectId, data));
8
+ return safeMutationAction(() => projectsService.update(projectId, data));
9
9
  }
@@ -1,6 +1,6 @@
1
1
  "use server";
2
2
 
3
- import { safeServerAction } from "../../../utils/safeServerAction";
3
+ import { safeMutationAction } from "../../../utils/safeMutationAction";
4
4
  import type { UpdateSubscriptionPlanRequest } from "../types/calculate-subscription.type";
5
5
  import { subscriptionsService } from "../services/subscriptions.service";
6
6
 
@@ -8,7 +8,7 @@ export async function updateSubscriptionPlanAction(
8
8
  subscriptionId: number | string,
9
9
  data: UpdateSubscriptionPlanRequest,
10
10
  ) {
11
- return safeServerAction(async () => {
11
+ return safeMutationAction(async () => {
12
12
  return subscriptionsService.updateSubscriptionPlan(subscriptionId, data);
13
13
  });
14
14
  }
@@ -1,8 +1,8 @@
1
1
  'use server';
2
2
 
3
- import { safeServerAction } from '../../../utils/safeServerAction';
3
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
4
  import { messagesService } from '../services/messages.service';
5
5
 
6
6
  export async function markAllMessagesAsReadAction() {
7
- return safeServerAction(() => messagesService.markAllAsRead());
7
+ return safeMutationAction(() => messagesService.markAllAsRead());
8
8
  }
@@ -1,8 +1,8 @@
1
1
  'use server';
2
2
 
3
- import { safeServerAction } from '../../../utils/safeServerAction';
3
+ import { safeMutationAction } from '../../../utils/safeMutationAction';
4
4
  import { messagesService } from '../services/messages.service';
5
5
 
6
6
  export async function markMessageAsReadAction(messageId: string) {
7
- return safeServerAction(() => messagesService.markAsRead(messageId));
7
+ return safeMutationAction(() => messagesService.markAsRead(messageId));
8
8
  }
package/src/server.ts CHANGED
@@ -73,8 +73,10 @@ export {
73
73
  // Server Utils
74
74
  export { getClientInfoFromRequest } from './infra/utils/client-info';
75
75
  export { getUserContext } from './modules/auth/utils/get-user-context';
76
+ export { requireValidSession } from './modules/auth/utils/require-valid-session';
76
77
  export { buildWlOverride, buildWlOverrideFromJwt } from './modules/auth/utils/build-wl-override';
77
78
  export { safeServerAction } from './utils/safeServerAction';
79
+ export { safeMutationAction } from './utils/safeMutationAction';
78
80
 
79
81
  // Image Processing (server-side)
80
82
  export { processImageAction } from './modules/images/actions/process-image.action';
@@ -0,0 +1,30 @@
1
+ import 'server-only';
2
+
3
+ import type { ActionResult } from '../infra/api/types';
4
+ import { requireValidSession } from '../modules/auth/utils/require-valid-session';
5
+ import { safeServerAction } from './safeServerAction';
6
+
7
+ /**
8
+ * Wrapper para server actions que mutam estado (delete/update/create/publish/
9
+ * billing/etc.). Faz validação de sessão contra o backend (`POST /auth/keep`)
10
+ * antes de executar a ação e roteia erros via `safeServerAction`.
11
+ *
12
+ * A validação é deduplicada por request — múltiplas actions sensíveis que
13
+ * rodem dentro de uma mesma request pagam 1 round-trip ao backend, não N.
14
+ *
15
+ * Motivação (resumo): o backend confia no par `(whitelabel-token, id_account
16
+ * no path)` nos endpoints de CRUD; o Next.js deriva `id_account` de
17
+ * `atob(cookie)` sem verificar assinatura. Chamar `requireValidSession`
18
+ * aqui garante que o cookie corresponde a uma sessão real no banco antes
19
+ * de qualquer mutação.
20
+ *
21
+ * Para reads não-sensíveis, continue usando `safeServerAction` direto.
22
+ */
23
+ export async function safeMutationAction<T>(
24
+ fn: () => Promise<T>
25
+ ): Promise<ActionResult<T>> {
26
+ return safeServerAction(async () => {
27
+ await requireValidSession();
28
+ return fn();
29
+ });
30
+ }