@greatapps/common 1.1.287 → 1.1.289
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -1
- package/dist/modules/accounts/services/account.service.mjs +4 -2
- package/dist/modules/accounts/services/account.service.mjs.map +1 -1
- package/dist/modules/auth/utils/assert-management-permission.mjs +37 -0
- package/dist/modules/auth/utils/assert-management-permission.mjs.map +1 -0
- package/dist/modules/auth/utils/assert-management-subscription.mjs +26 -0
- package/dist/modules/auth/utils/assert-management-subscription.mjs.map +1 -0
- package/dist/modules/auth/utils/build-wl-override.mjs +10 -3
- package/dist/modules/auth/utils/build-wl-override.mjs.map +1 -1
- package/dist/modules/subscriptions/hooks/use-cancelled-subscription-guard.mjs +37 -0
- package/dist/modules/subscriptions/hooks/use-cancelled-subscription-guard.mjs.map +1 -0
- package/dist/modules/subscriptions/utils/has-subscription-expired.mjs +10 -0
- package/dist/modules/subscriptions/utils/has-subscription-expired.mjs.map +1 -0
- package/dist/modules/users/services/user.service.mjs +3 -1
- package/dist/modules/users/services/user.service.mjs.map +1 -1
- package/dist/server.mjs +6 -0
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +2 -0
- package/src/modules/accounts/services/account.service.ts +4 -2
- package/src/modules/auth/utils/assert-management-permission.ts +46 -0
- package/src/modules/auth/utils/assert-management-subscription.ts +27 -0
- package/src/modules/auth/utils/build-wl-override.ts +18 -6
- package/src/modules/subscriptions/hooks/use-cancelled-subscription-guard.ts +39 -0
- package/src/modules/subscriptions/utils/has-subscription-expired.ts +8 -0
- package/src/modules/users/services/user.service.ts +3 -1
- package/src/server.ts +9 -6
package/dist/index.mjs
CHANGED
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
import { useSubscriptions } from "./modules/subscriptions/hooks/list-subscriptions.hook";
|
|
27
27
|
import { SUBSCRIPTIONS_QUERY_KEY } from "./modules/subscriptions/constants/query-keys.constants";
|
|
28
28
|
import { useActiveSubscription } from "./modules/subscriptions/hooks/find-active-subscription.hook";
|
|
29
|
+
import { useCancelledSubscriptionGuard } from "./modules/subscriptions/hooks/use-cancelled-subscription-guard";
|
|
29
30
|
import { usePlanById } from "./modules/plans/hooks/use-plan-by-id.hook";
|
|
30
31
|
import { useHasPlanAddon } from "./modules/plans/hooks/use-has-plan-addon.hook";
|
|
31
32
|
import { useCalculateSubscription } from "./modules/subscriptions/hooks/calculate-subscription.hook";
|
|
@@ -41,6 +42,7 @@ import { ADDON_IDS, AI_CREDIT_OPTIONS, AI_CREDIT_VALUES } from "./modules/subscr
|
|
|
41
42
|
import { PlanSchema, PlanItemSchema } from "./modules/plans/types/plan.type";
|
|
42
43
|
import { CardSchema, CreateCardRequestSchema } from "./modules/cards/types";
|
|
43
44
|
import { buildPlanExtras } from "./modules/subscriptions/utils/build-plan-extras";
|
|
45
|
+
import { hasSubscriptionExpired } from "./modules/subscriptions/utils/has-subscription-expired";
|
|
44
46
|
import { getPriceFromCalculatedData, periodicityToBillingPeriod } from "./modules/subscriptions/utils/periodicity";
|
|
45
47
|
import { useBuyCreditsModal } from "./store/useBuyCreditsModal";
|
|
46
48
|
import { default as default2 } from "./components/modals/BuyCreditsModal";
|
|
@@ -461,6 +463,7 @@ export {
|
|
|
461
463
|
formatShortDate,
|
|
462
464
|
formatTimer,
|
|
463
465
|
getPriceFromCalculatedData,
|
|
466
|
+
hasSubscriptionExpired,
|
|
464
467
|
hideCrisp,
|
|
465
468
|
openCrispHelpdesk,
|
|
466
469
|
parseResult,
|
|
@@ -475,6 +478,7 @@ export {
|
|
|
475
478
|
useActiveSubscription,
|
|
476
479
|
useBuyCreditsModal,
|
|
477
480
|
useCalculateSubscription,
|
|
481
|
+
useCancelledSubscriptionGuard,
|
|
478
482
|
useCards,
|
|
479
483
|
default6 as useCopyToClipboard,
|
|
480
484
|
default11 as useCountdownTimer,
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Types\nexport * from \"./modules/auth/schema\";\nexport * from \"./modules/users/schema\";\nexport * from \"./modules/whitelabel/schema\";\n// Style types now come from whitelabel schema directly\nexport * from \"./infra/api/types\";\n\n// Contexts\nexport * from \"./providers/query.provider\";\nexport * from \"./providers/auth.provider\";\nexport * from \"./providers/whitelabel.provider\";\n\n// Hooks\nexport {\n useListProjectUsers,\n LIST_PROJECT_USERS_QUERY_KEY,\n LIST_PROJECT_USERS_BASE_KEY,\n} from \"./modules/projects/hooks/list-project-users.hook\";\nexport {\n useListAvailableUsers,\n LIST_AVAILABLE_USERS_QUERY_KEY,\n LIST_AVAILABLE_USERS_BASE_KEY,\n} from \"./modules/projects/hooks/list-available-users.hook\";\nexport type {\n ProjectUser,\n AccountUser,\n AddRemoveProjectUsersParams,\n ListUsersParams,\n UsersPage,\n} from \"./modules/projects/types\";\nexport {\n useUserQuery,\n useUserValidateSession,\n useInvalidateUser,\n useSetUserData,\n useTwoFactorVerify,\n USER_QUERY_KEY,\n} from \"./modules/auth/hooks/useUserQuery\";\nexport { useSubscriptions } from \"./modules/subscriptions/hooks/list-subscriptions.hook\";\nexport { SUBSCRIPTIONS_QUERY_KEY } from \"./modules/subscriptions/constants/query-keys.constants\";\nexport { useActiveSubscription } from \"./modules/subscriptions/hooks/find-active-subscription.hook\";\nexport { usePlanById } from \"./modules/plans/hooks/use-plan-by-id.hook\";\nexport { useHasPlanAddon } from \"./modules/plans/hooks/use-has-plan-addon.hook\";\nexport { useCalculateSubscription } from \"./modules/subscriptions/hooks/calculate-subscription.hook\";\nexport { useUpdateSubscriptionPlan } from \"./modules/subscriptions/hooks/update-subscription-plan.hook\";\nexport { useCards, CARDS_QUERY_KEY } from \"./modules/cards/hooks/cards.hook\";\nexport { useCreateCard } from \"./modules/cards/hooks/create-card.hook\";\nexport { useIaCredits } from \"./modules/ia-credits/hooks/ia-credits.hook\";\nexport type {\n IaCreditsSummary,\n IaCreditOperation,\n} from \"./modules/ia-credits/types\";\nexport type {\n Subscription,\n SubscriptionItem,\n FindSubscriptionsParams,\n} from \"./modules/subscriptions/types/subscription.type\";\nexport {\n SubscriptionSchema,\n SubscriptionItemSchema,\n} from \"./modules/subscriptions/types/subscription.type\";\nexport { ADDON_IDS, AI_CREDIT_OPTIONS, AI_CREDIT_VALUES } from \"./modules/subscriptions/constants/addons.constants\";\nexport type { AddonKindEnum, AiCreditOption } from \"./modules/subscriptions/constants/addons.constants\";\nexport type { Plan, PlanItem } from \"./modules/plans/types/plan.type\";\nexport { PlanSchema, PlanItemSchema } from \"./modules/plans/types/plan.type\";\nexport type { BillingPeriod } from \"./modules/subscriptions/types/billing-period.type\";\nexport type {\n CalculateSubscriptionRequest,\n CalculateSubscriptionResponse,\n UpdateSubscriptionPlanRequest,\n} from \"./modules/subscriptions/types/calculate-subscription.type\";\nexport type { Card as PaymentCard, CreateCardRequest } from \"./modules/cards/types\";\nexport { CardSchema as PaymentCardSchema, CreateCardRequestSchema } from \"./modules/cards/types\";\nexport { buildPlanExtras } from \"./modules/subscriptions/utils/build-plan-extras\";\nexport { getPriceFromCalculatedData, periodicityToBillingPeriod } from \"./modules/subscriptions/utils/periodicity\";\nexport { useBuyCreditsModal } from \"./store/useBuyCreditsModal\";\nexport { default as BuyCreditsModal } from \"./components/modals/BuyCreditsModal\";\nexport { default as AddCardModal } from \"./components/modals/cards/AddCardModal\";\nexport { CardFormFields, cardFormSchema } from \"./components/modals/cards/CardFormFields\";\nexport type { CardFormData } from \"./components/modals/cards/CardFormFields\";\nexport { Skeleton } from \"./components/ui/feedback/Skeleton\";\nexport { PaymentInfoCard } from \"./components/ui/data-display/PaymentInfoCard\";\nexport { CardBrandIcon } from \"./components/ui/data-display/CardBrandIcons\";\nexport { CardItem } from \"./components/ui/data-display/CardItem\";\n\n// Providers\nexport { QueryProvider } from \"./providers/query.provider\";\n\n// Middleware\nexport { createAuthMiddleware } from \"./middlewares/create-auth-middleware\";\nexport { createMiddlewareChain } from \"./middlewares/chain\";\nexport { continueChain, stopChain } from \"./middlewares/types\";\nexport type {\n MiddlewareFunction,\n MiddlewareConfig,\n MiddlewareResult,\n} from \"./middlewares/types\";\n\n// Utils\nexport { cn } from \"./infra/utils/clsx\";\nexport { formatShortDate } from \"./infra/utils/date\";\nexport { buildQueryParams } from \"./infra/utils/params\";\nexport { parseSchema, parseResult } from \"./infra/utils/parser\";\nexport { withAction } from \"./utils/withAction\";\n\n// Layout\nexport {\n MainLayout,\n MainLayoutContent,\n MainLayoutSpacer,\n MainLayoutMain,\n} from \"./components/layouts/MainLayout\";\nexport { NavBar } from \"./components/layouts/NavBar\";\nexport type { NavBarProps } from \"./components/layouts/NavBar\";\nexport { AppNavBar } from \"./components/layouts/AppNavBar\";\nexport type { AppNavBarProps } from \"./components/layouts/AppNavBar\";\nexport { AppMobileNavBar } from \"./components/layouts/AppMobileNavBar\";\nexport type { AppMobileNavBarProps } from \"./components/layouts/AppMobileNavBar\";\nexport { SideBarNavigation } from \"./components/layouts/SideBarNavigation\";\nexport { MdSideBarNavigation } from \"./components/layouts/MdSideBarNavigation\";\nexport { default as NotificationCard } from \"./components/widgets/notifications/NotificationCard\";\nexport type { NotificationCardProps } from \"./components/widgets/notifications/NotificationCard\";\nexport { NotificationsPopover } from \"./components/layouts/NotificationsPopover\";\nexport type { NotificationsPopoverProps } from \"./components/layouts/NotificationsPopover\";\nexport { NotificationPageContent } from \"./components/pages/notifications/Notifications\";\nexport { NotFoundPage } from \"./components/pages/NotFoundPage\";\nexport { UsersSelectorPopover } from \"./components/layouts/UsersSelectorPopover\";\nexport type { UsersSelectorPopoverProps } from \"./components/layouts/UsersSelectorPopover\";\nexport { ProfilePopover } from \"./components/layouts/ProfilePopover\";\nexport type {\n ProfilePopoverProps,\n ProfileMenuItem,\n} from \"./components/layouts/ProfilePopover\";\nexport { default as WhitelabelCodes } from \"./components/layouts/WhitelabelCodes\";\nexport { NavBarItem } from \"./components/layouts/NavBarItem\";\nexport type { NavBarItemProps } from \"./components/layouts/NavBarItem\";\n\n// Navigation\nexport { AppNavigation } from './components/navigation/AppNavigation';\nexport { CancelledSubscriptionBanner } from './components/navigation/CancelledSubscriptionBanner';\nexport type { NavItemConfig } from './components/navigation/subcomponents/NavItems';\nexport type { NavigationProject } from './components/navigation/types';\nexport { useMobileNavbarSheet } from './store/useMobileNavbarSheet';\n\n// Hooks\nexport { default as useCopyToClipboard } from \"./hooks/copy-to-clipboard.hook\";\n\n// UI - Buttons\nexport { Button, buttonVariants } from \"./components/ui/buttons/Button\";\nexport { CopyButton } from \"./components/ui/buttons/CopyButton\";\nexport { default as CancelButton } from \"./components/ui/buttons/CancelButton\";\n\n// UI - Data Display\nexport {\n Accordion,\n AccordionItem,\n AccordionTrigger,\n AccordionContent,\n} from \"./components/ui/data-display/Accordion\";\nexport { Badge, badgeVariants } from \"./components/ui/data-display/Badge\";\nexport {\n Card,\n CardHeader,\n CardFooter,\n CardTitle,\n CardAction,\n CardDescription,\n CardContent,\n} from \"./components/ui/data-display/Card\";\nexport {\n Pagination,\n PaginationContent,\n PaginationLink,\n PaginationItem,\n PaginationPrevious,\n PaginationNext,\n PaginationEllipsis,\n} from \"./components/ui/data-display/Pagination\";\nexport { ScrollArea, ScrollBar } from \"./components/ui/data-display/ScrollArea\";\nexport { Separator } from \"./components/ui/data-display/Separator\";\nexport {\n Table,\n TableHeader,\n TableBody,\n TableFooter,\n TableHead,\n TableRow,\n TableCell,\n TableCaption,\n} from \"./components/ui/data-display/Table\";\nexport {\n Tabs,\n TabsList,\n TabsTrigger,\n TabsContent,\n} from \"./components/ui/data-display/Tabs\";\nexport { UserAvatar } from \"./components/ui/data-display/UserAvatar\";\nexport type { UserAvatarProps } from \"./components/ui/data-display/UserAvatar\";\n\n// UI - Feedback\nexport { default as CircularProgress } from \"./components/ui/feedback/CircularProgress\";\nexport { default as DefaultCircularProgress } from \"./components/ui/feedback/DefaultCircularProgress\";\nexport { Progress } from \"./components/ui/feedback/Progress\";\nexport { LoadingOverlay } from \"./components/ui/feedback/LoadingOverlay\";\nexport {\n Toast,\n toastVariants,\n toastIconContainerVariants,\n} from \"./components/ui/feedback/Toast\";\nexport type { ToastProps } from \"./components/ui/feedback/Toast\";\n\n// UI - Form\nexport { Calendar, CalendarDayButton } from \"./components/ui/form/Calendar\";\nexport { Checkbox } from \"./components/ui/form/Checkbox\";\nexport { DatePicker } from \"./components/ui/form/DatePicker\";\nexport { DateRangePicker } from \"./components/ui/form/DateRangePicker\";\nexport { Input } from \"./components/ui/form/Input\";\nexport {\n InputOTP,\n InputOTPGroup,\n InputOTPSlot,\n InputOTPSeparator,\n} from \"./components/ui/form/InputOtp\";\nexport { RadioGroup, RadioGroupItem } from \"./components/ui/form/RadioGroup\";\nexport {\n Select,\n SelectContent,\n SelectGroup,\n SelectItem,\n SelectLabel,\n SelectScrollDownButton,\n SelectScrollUpButton,\n SelectSeparator,\n SelectTrigger,\n SelectValue,\n} from \"./components/ui/form/Select\";\nexport { Switch } from \"./components/ui/form/Switch\";\nexport { Textarea } from \"./components/ui/form/Textarea\";\n\n// UI - Overlay\nexport {\n Command,\n CommandDialog,\n CommandInput,\n CommandList,\n CommandEmpty,\n CommandGroup,\n CommandItem,\n CommandShortcut,\n CommandSeparator,\n} from \"./components/ui/overlay/Command\";\nexport {\n Dialog,\n DialogClose,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogOverlay,\n DialogPortal,\n DialogTitle,\n DialogTrigger,\n} from \"./components/ui/overlay/Dialog\";\nexport {\n Popover,\n PopoverTrigger,\n PopoverContent,\n PopoverAnchor,\n} from \"./components/ui/overlay/Popover\";\nexport {\n Sheet,\n SheetTrigger,\n SheetClose,\n SheetContent,\n SheetHeader,\n SheetFooter,\n SheetTitle,\n SheetDescription,\n} from \"./components/ui/overlay/Sheet\";\nexport {\n Tooltip,\n TooltipTrigger,\n TooltipContent,\n TooltipProvider,\n} from \"./components/ui/overlay/Tooltip\";\n\n// Embeds\nexport { FrillEmbed } from \"./components/embeds/FrillEmbed\";\nexport { CrispEmbed, openCrispHelpdesk, hideCrisp, showCrisp } from \"./components/embeds/CrispEmbed\";\n\n// Store\nexport { useMdSidebarStore } from \"./store/useMdSidebarStore\";\nexport { useModalManager } from \"./store/useModalManager\";\nexport type { ModalData } from \"./store/useModalManager\";\n\n// Enums\nexport { AccountSectionType } from \"./enums/AccountSectionType\";\n\n// Hooks\nexport { default as usePasswordVisibility } from \"./hooks/usePasswordVisibility\";\nexport { default as useCountdownTimer } from \"./hooks/useCountdownTimer\";\nexport { default as useIsMobile } from \"./hooks/useIsMobile\";\nexport { useDebounce } from \"./hooks/useDebounce\";\nexport { useDebouncedEffect } from \"./hooks/useDebouncedEffect\";\nexport { useDebounceState } from \"./hooks/useDebounceState\";\n\n// Utils\nexport {\n formatPhone,\n formatTimer,\n formatFullName,\n formatCPF,\n formatCardNumber,\n} from \"./utils/format/masks\";\nexport type { TimezoneOption } from \"./modules/accounts/services/timezone.service\";\nexport {\n buildLocaleOptions,\n LANGUAGE_OPTIONS as LOCALE_LANGUAGE_OPTIONS,\n} from \"./utils/intl/locales\";\nexport type { LocaleOption } from \"./utils/intl/locales\";\nexport { copyToClipboard, readFromClipboard } from \"./utils/browser/clipboard\";\n\n// UI - Form (new widgets)\nexport { FormField } from \"./components/ui/form/FormField\";\nexport { SelectField } from \"./components/ui/form/SelectField\";\nexport { ComboboxField } from \"./components/ui/form/ComboboxField\";\nexport type { ComboboxOption } from \"./components/ui/form/ComboboxField\";\nexport { default as PhoneInput } from \"./components/ui/form/PhoneInput\";\nexport { default as SwitchOptionFieldWithIcon } from \"./components/ui/form/SwitchOptionFieldWithIcon\";\nexport { TextAreaField } from \"./components/ui/form/TextAreaField\";\n\n// Account Module - Hooks\nexport {\n useCurrentAccount,\n ACCOUNT_QUERY_KEY,\n} from \"./modules/accounts/hooks/current-account.hook\";\nexport {\n useUpdateAccount,\n useUpdateAccountUser,\n useUpdateAccountUserById,\n useDeleteAccountUser,\n useDeleteAccount,\n} from \"./modules/accounts/hooks/useAccountManagement\";\n\n// Account Types\nexport type {\n UpdateAccountRequest,\n UpdateAccountUserRequest,\n ChangePasswordRequest,\n DeleteAccountActionResult,\n DeleteUserActionResult,\n UpdateAccountActionResult,\n UpdateUserActionResult,\n TwoFactorGenerateResult,\n TwoFactorActionResult,\n ContactResetResult,\n} from \"./modules/accounts/types\";\n\nexport { default as AccountModals } from \"./components/account/AccountModals\";\nexport { useAccountModals } from \"./store/useAccountModals\";\nexport type { AccountModalsConfig } from \"./store/useAccountModals\";\n\nexport { ModalManager } from \"./components/modals/ModalManager\";\nexport { Modals } from \"./components/modals/Modals\";\n\nexport { default as TwoFactorAuthModal } from \"./components/account/TwoFactorAuthModal\";\nexport { default as DisableTwoFactorAuthModal } from \"./components/account/DisableTwoFactorAuthModal\";\nexport { default as ConfirmGlobalPreferencesModal } from \"./components/account/ConfirmGlobalPreferencesModal\";\nexport { MyProfileSection } from \"./components/account/sections/MyProfileSection\";\nexport { PreferencesSection } from \"./components/account/sections/PreferencesSection\";\nexport { SecuritySection } from \"./components/account/sections/SecuritySection\";\nexport { ChangePasswordSection } from \"./components/account/sections/ChangePasswordSection\";\nexport { ChangeEmailModal } from \"./components/account/sections/ChangeEmailModal\";\nexport { ChangePhoneModal } from \"./components/account/sections/ChangePhoneModal\";\n\n// Account Constants\nexport {\n GENDER_OPTIONS,\n CURRENCY_OPTIONS,\n TIME_FORMAT_OPTIONS,\n NOTIFICATION_TYPES,\n LANGUAGE_OPTIONS,\n} from \"./components/account/constants\";\n"],"mappings":"AACA,cAAc;AACd,cAAc;AACd,cAAc;AAEd,cAAc;AAGd,cAAc;AACd,cAAc;AACd,cAAc;AAGd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,O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AChC,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AAGjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,oBAAAC;AAAA,OACK;","names":["default","LANGUAGE_OPTIONS"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Types\nexport * from \"./modules/auth/schema\";\nexport * from \"./modules/users/schema\";\nexport * from \"./modules/whitelabel/schema\";\n// Style types now come from whitelabel schema directly\nexport * from \"./infra/api/types\";\n\n// Contexts\nexport * from \"./providers/query.provider\";\nexport * from \"./providers/auth.provider\";\nexport * from \"./providers/whitelabel.provider\";\n\n// Hooks\nexport {\n useListProjectUsers,\n LIST_PROJECT_USERS_QUERY_KEY,\n LIST_PROJECT_USERS_BASE_KEY,\n} from \"./modules/projects/hooks/list-project-users.hook\";\nexport {\n useListAvailableUsers,\n LIST_AVAILABLE_USERS_QUERY_KEY,\n LIST_AVAILABLE_USERS_BASE_KEY,\n} from \"./modules/projects/hooks/list-available-users.hook\";\nexport type {\n ProjectUser,\n AccountUser,\n AddRemoveProjectUsersParams,\n ListUsersParams,\n UsersPage,\n} from \"./modules/projects/types\";\nexport {\n useUserQuery,\n useUserValidateSession,\n useInvalidateUser,\n useSetUserData,\n useTwoFactorVerify,\n USER_QUERY_KEY,\n} from \"./modules/auth/hooks/useUserQuery\";\nexport { useSubscriptions } from \"./modules/subscriptions/hooks/list-subscriptions.hook\";\nexport { SUBSCRIPTIONS_QUERY_KEY } from \"./modules/subscriptions/constants/query-keys.constants\";\nexport { useActiveSubscription } from \"./modules/subscriptions/hooks/find-active-subscription.hook\";\nexport { useCancelledSubscriptionGuard } from \"./modules/subscriptions/hooks/use-cancelled-subscription-guard\";\nexport { usePlanById } from \"./modules/plans/hooks/use-plan-by-id.hook\";\nexport { useHasPlanAddon } from \"./modules/plans/hooks/use-has-plan-addon.hook\";\nexport { useCalculateSubscription } from \"./modules/subscriptions/hooks/calculate-subscription.hook\";\nexport { useUpdateSubscriptionPlan } from \"./modules/subscriptions/hooks/update-subscription-plan.hook\";\nexport { useCards, CARDS_QUERY_KEY } from \"./modules/cards/hooks/cards.hook\";\nexport { useCreateCard } from \"./modules/cards/hooks/create-card.hook\";\nexport { useIaCredits } from \"./modules/ia-credits/hooks/ia-credits.hook\";\nexport type {\n IaCreditsSummary,\n IaCreditOperation,\n} from \"./modules/ia-credits/types\";\nexport type {\n Subscription,\n SubscriptionItem,\n FindSubscriptionsParams,\n} from \"./modules/subscriptions/types/subscription.type\";\nexport {\n SubscriptionSchema,\n SubscriptionItemSchema,\n} from \"./modules/subscriptions/types/subscription.type\";\nexport { ADDON_IDS, AI_CREDIT_OPTIONS, AI_CREDIT_VALUES } from \"./modules/subscriptions/constants/addons.constants\";\nexport type { AddonKindEnum, AiCreditOption } from \"./modules/subscriptions/constants/addons.constants\";\nexport type { Plan, PlanItem } from \"./modules/plans/types/plan.type\";\nexport { PlanSchema, PlanItemSchema } from \"./modules/plans/types/plan.type\";\nexport type { BillingPeriod } from \"./modules/subscriptions/types/billing-period.type\";\nexport type {\n CalculateSubscriptionRequest,\n CalculateSubscriptionResponse,\n UpdateSubscriptionPlanRequest,\n} from \"./modules/subscriptions/types/calculate-subscription.type\";\nexport type { Card as PaymentCard, CreateCardRequest } from \"./modules/cards/types\";\nexport { CardSchema as PaymentCardSchema, CreateCardRequestSchema } from \"./modules/cards/types\";\nexport { buildPlanExtras } from \"./modules/subscriptions/utils/build-plan-extras\";\nexport { hasSubscriptionExpired } from \"./modules/subscriptions/utils/has-subscription-expired\";\nexport { getPriceFromCalculatedData, periodicityToBillingPeriod } from \"./modules/subscriptions/utils/periodicity\";\nexport { useBuyCreditsModal } from \"./store/useBuyCreditsModal\";\nexport { default as BuyCreditsModal } from \"./components/modals/BuyCreditsModal\";\nexport { default as AddCardModal } from \"./components/modals/cards/AddCardModal\";\nexport { CardFormFields, cardFormSchema } from \"./components/modals/cards/CardFormFields\";\nexport type { CardFormData } from \"./components/modals/cards/CardFormFields\";\nexport { Skeleton } from \"./components/ui/feedback/Skeleton\";\nexport { PaymentInfoCard } from \"./components/ui/data-display/PaymentInfoCard\";\nexport { CardBrandIcon } from \"./components/ui/data-display/CardBrandIcons\";\nexport { CardItem } from \"./components/ui/data-display/CardItem\";\n\n// Providers\nexport { QueryProvider } from \"./providers/query.provider\";\n\n// Middleware\nexport { createAuthMiddleware } from \"./middlewares/create-auth-middleware\";\nexport { createMiddlewareChain } from \"./middlewares/chain\";\nexport { continueChain, stopChain } from \"./middlewares/types\";\nexport type {\n MiddlewareFunction,\n MiddlewareConfig,\n MiddlewareResult,\n} from \"./middlewares/types\";\n\n// Utils\nexport { cn } from \"./infra/utils/clsx\";\nexport { formatShortDate } from \"./infra/utils/date\";\nexport { buildQueryParams } from \"./infra/utils/params\";\nexport { parseSchema, parseResult } from \"./infra/utils/parser\";\nexport { withAction } from \"./utils/withAction\";\n\n// Layout\nexport {\n MainLayout,\n MainLayoutContent,\n MainLayoutSpacer,\n MainLayoutMain,\n} from \"./components/layouts/MainLayout\";\nexport { NavBar } from \"./components/layouts/NavBar\";\nexport type { NavBarProps } from \"./components/layouts/NavBar\";\nexport { AppNavBar } from \"./components/layouts/AppNavBar\";\nexport type { AppNavBarProps } from \"./components/layouts/AppNavBar\";\nexport { AppMobileNavBar } from \"./components/layouts/AppMobileNavBar\";\nexport type { AppMobileNavBarProps } from \"./components/layouts/AppMobileNavBar\";\nexport { SideBarNavigation } from \"./components/layouts/SideBarNavigation\";\nexport { MdSideBarNavigation } from \"./components/layouts/MdSideBarNavigation\";\nexport { default as NotificationCard } from \"./components/widgets/notifications/NotificationCard\";\nexport type { NotificationCardProps } from \"./components/widgets/notifications/NotificationCard\";\nexport { NotificationsPopover } from \"./components/layouts/NotificationsPopover\";\nexport type { NotificationsPopoverProps } from \"./components/layouts/NotificationsPopover\";\nexport { NotificationPageContent } from \"./components/pages/notifications/Notifications\";\nexport { NotFoundPage } from \"./components/pages/NotFoundPage\";\nexport { UsersSelectorPopover } from \"./components/layouts/UsersSelectorPopover\";\nexport type { UsersSelectorPopoverProps } from \"./components/layouts/UsersSelectorPopover\";\nexport { ProfilePopover } from \"./components/layouts/ProfilePopover\";\nexport type {\n ProfilePopoverProps,\n ProfileMenuItem,\n} from \"./components/layouts/ProfilePopover\";\nexport { default as WhitelabelCodes } from \"./components/layouts/WhitelabelCodes\";\nexport { NavBarItem } from \"./components/layouts/NavBarItem\";\nexport type { NavBarItemProps } from \"./components/layouts/NavBarItem\";\n\n// Navigation\nexport { AppNavigation } from './components/navigation/AppNavigation';\nexport { CancelledSubscriptionBanner } from './components/navigation/CancelledSubscriptionBanner';\nexport type { NavItemConfig } from './components/navigation/subcomponents/NavItems';\nexport type { NavigationProject } from './components/navigation/types';\nexport { useMobileNavbarSheet } from './store/useMobileNavbarSheet';\n\n// Hooks\nexport { default as useCopyToClipboard } from \"./hooks/copy-to-clipboard.hook\";\n\n// UI - Buttons\nexport { Button, buttonVariants } from \"./components/ui/buttons/Button\";\nexport { CopyButton } from \"./components/ui/buttons/CopyButton\";\nexport { default as CancelButton } from \"./components/ui/buttons/CancelButton\";\n\n// UI - Data Display\nexport {\n Accordion,\n AccordionItem,\n AccordionTrigger,\n AccordionContent,\n} from \"./components/ui/data-display/Accordion\";\nexport { Badge, badgeVariants } from \"./components/ui/data-display/Badge\";\nexport {\n Card,\n CardHeader,\n CardFooter,\n CardTitle,\n CardAction,\n CardDescription,\n CardContent,\n} from \"./components/ui/data-display/Card\";\nexport {\n Pagination,\n PaginationContent,\n PaginationLink,\n PaginationItem,\n PaginationPrevious,\n PaginationNext,\n PaginationEllipsis,\n} from \"./components/ui/data-display/Pagination\";\nexport { ScrollArea, ScrollBar } from \"./components/ui/data-display/ScrollArea\";\nexport { Separator } from \"./components/ui/data-display/Separator\";\nexport {\n Table,\n TableHeader,\n TableBody,\n TableFooter,\n TableHead,\n TableRow,\n TableCell,\n TableCaption,\n} from \"./components/ui/data-display/Table\";\nexport {\n Tabs,\n TabsList,\n TabsTrigger,\n TabsContent,\n} from \"./components/ui/data-display/Tabs\";\nexport { UserAvatar } from \"./components/ui/data-display/UserAvatar\";\nexport type { UserAvatarProps } from \"./components/ui/data-display/UserAvatar\";\n\n// UI - Feedback\nexport { default as CircularProgress } from \"./components/ui/feedback/CircularProgress\";\nexport { default as DefaultCircularProgress } from \"./components/ui/feedback/DefaultCircularProgress\";\nexport { Progress } from \"./components/ui/feedback/Progress\";\nexport { LoadingOverlay } from \"./components/ui/feedback/LoadingOverlay\";\nexport {\n Toast,\n toastVariants,\n toastIconContainerVariants,\n} from \"./components/ui/feedback/Toast\";\nexport type { ToastProps } from \"./components/ui/feedback/Toast\";\n\n// UI - Form\nexport { Calendar, CalendarDayButton } from \"./components/ui/form/Calendar\";\nexport { Checkbox } from \"./components/ui/form/Checkbox\";\nexport { DatePicker } from \"./components/ui/form/DatePicker\";\nexport { DateRangePicker } from \"./components/ui/form/DateRangePicker\";\nexport { Input } from \"./components/ui/form/Input\";\nexport {\n InputOTP,\n InputOTPGroup,\n InputOTPSlot,\n InputOTPSeparator,\n} from \"./components/ui/form/InputOtp\";\nexport { RadioGroup, RadioGroupItem } from \"./components/ui/form/RadioGroup\";\nexport {\n Select,\n SelectContent,\n SelectGroup,\n SelectItem,\n SelectLabel,\n SelectScrollDownButton,\n SelectScrollUpButton,\n SelectSeparator,\n SelectTrigger,\n SelectValue,\n} from \"./components/ui/form/Select\";\nexport { Switch } from \"./components/ui/form/Switch\";\nexport { Textarea } from \"./components/ui/form/Textarea\";\n\n// UI - Overlay\nexport {\n Command,\n CommandDialog,\n CommandInput,\n CommandList,\n CommandEmpty,\n CommandGroup,\n CommandItem,\n CommandShortcut,\n CommandSeparator,\n} from \"./components/ui/overlay/Command\";\nexport {\n Dialog,\n DialogClose,\n DialogContent,\n DialogDescription,\n DialogFooter,\n DialogHeader,\n DialogOverlay,\n DialogPortal,\n DialogTitle,\n DialogTrigger,\n} from \"./components/ui/overlay/Dialog\";\nexport {\n Popover,\n PopoverTrigger,\n PopoverContent,\n PopoverAnchor,\n} from \"./components/ui/overlay/Popover\";\nexport {\n Sheet,\n SheetTrigger,\n SheetClose,\n SheetContent,\n SheetHeader,\n SheetFooter,\n SheetTitle,\n SheetDescription,\n} from \"./components/ui/overlay/Sheet\";\nexport {\n Tooltip,\n TooltipTrigger,\n TooltipContent,\n TooltipProvider,\n} from \"./components/ui/overlay/Tooltip\";\n\n// Embeds\nexport { FrillEmbed } from \"./components/embeds/FrillEmbed\";\nexport { CrispEmbed, openCrispHelpdesk, hideCrisp, showCrisp } from \"./components/embeds/CrispEmbed\";\n\n// Store\nexport { useMdSidebarStore } from \"./store/useMdSidebarStore\";\nexport { useModalManager } from \"./store/useModalManager\";\nexport type { ModalData } from \"./store/useModalManager\";\n\n// Enums\nexport { AccountSectionType } from \"./enums/AccountSectionType\";\n\n// Hooks\nexport { default as usePasswordVisibility } from \"./hooks/usePasswordVisibility\";\nexport { default as useCountdownTimer } from \"./hooks/useCountdownTimer\";\nexport { default as useIsMobile } from \"./hooks/useIsMobile\";\nexport { useDebounce } from \"./hooks/useDebounce\";\nexport { useDebouncedEffect } from \"./hooks/useDebouncedEffect\";\nexport { useDebounceState } from \"./hooks/useDebounceState\";\n\n// Utils\nexport {\n formatPhone,\n formatTimer,\n formatFullName,\n formatCPF,\n formatCardNumber,\n} from \"./utils/format/masks\";\nexport type { TimezoneOption } from \"./modules/accounts/services/timezone.service\";\nexport {\n buildLocaleOptions,\n LANGUAGE_OPTIONS as LOCALE_LANGUAGE_OPTIONS,\n} from \"./utils/intl/locales\";\nexport type { LocaleOption } from \"./utils/intl/locales\";\nexport { copyToClipboard, readFromClipboard } from \"./utils/browser/clipboard\";\n\n// UI - Form (new widgets)\nexport { FormField } from \"./components/ui/form/FormField\";\nexport { SelectField } from \"./components/ui/form/SelectField\";\nexport { ComboboxField } from \"./components/ui/form/ComboboxField\";\nexport type { ComboboxOption } from \"./components/ui/form/ComboboxField\";\nexport { default as PhoneInput } from \"./components/ui/form/PhoneInput\";\nexport { default as SwitchOptionFieldWithIcon } from \"./components/ui/form/SwitchOptionFieldWithIcon\";\nexport { TextAreaField } from \"./components/ui/form/TextAreaField\";\n\n// Account Module - Hooks\nexport {\n useCurrentAccount,\n ACCOUNT_QUERY_KEY,\n} from \"./modules/accounts/hooks/current-account.hook\";\nexport {\n useUpdateAccount,\n useUpdateAccountUser,\n useUpdateAccountUserById,\n useDeleteAccountUser,\n useDeleteAccount,\n} from \"./modules/accounts/hooks/useAccountManagement\";\n\n// Account Types\nexport type {\n UpdateAccountRequest,\n UpdateAccountUserRequest,\n ChangePasswordRequest,\n DeleteAccountActionResult,\n DeleteUserActionResult,\n UpdateAccountActionResult,\n UpdateUserActionResult,\n TwoFactorGenerateResult,\n TwoFactorActionResult,\n ContactResetResult,\n} from \"./modules/accounts/types\";\n\nexport { default as AccountModals } from \"./components/account/AccountModals\";\nexport { useAccountModals } from \"./store/useAccountModals\";\nexport type { AccountModalsConfig } from \"./store/useAccountModals\";\n\nexport { ModalManager } from \"./components/modals/ModalManager\";\nexport { Modals } from \"./components/modals/Modals\";\n\nexport { default as TwoFactorAuthModal } from \"./components/account/TwoFactorAuthModal\";\nexport { default as DisableTwoFactorAuthModal } from \"./components/account/DisableTwoFactorAuthModal\";\nexport { default as ConfirmGlobalPreferencesModal } from \"./components/account/ConfirmGlobalPreferencesModal\";\nexport { MyProfileSection } from \"./components/account/sections/MyProfileSection\";\nexport { PreferencesSection } from \"./components/account/sections/PreferencesSection\";\nexport { SecuritySection } from \"./components/account/sections/SecuritySection\";\nexport { ChangePasswordSection } from \"./components/account/sections/ChangePasswordSection\";\nexport { ChangeEmailModal } from \"./components/account/sections/ChangeEmailModal\";\nexport { ChangePhoneModal } from \"./components/account/sections/ChangePhoneModal\";\n\n// Account Constants\nexport {\n GENDER_OPTIONS,\n CURRENCY_OPTIONS,\n TIME_FORMAT_OPTIONS,\n NOTIFICATION_TYPES,\n LANGUAGE_OPTIONS,\n} from \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A,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAgBP,SAAoB,WAAXA,iBAAgC;AACzC,SAAS,wBAAwB;AAGjC,SAAS,oBAAoB;AAC7B,SAAS,cAAc;AAEvB,SAAoB,WAAXA,iBAAqC;AAC9C,SAAoB,WAAXA,iBAA4C;AACrD,SAAoB,WAAXA,iBAAgD;AACzD,SAAS,wBAAwB;AACjC,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,wBAAwB;AACjC,SAAS,wBAAwB;AAGjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,oBAAAC;AAAA,OACK;","names":["default","LANGUAGE_OPTIONS"]}
|
|
@@ -4,10 +4,12 @@ import { ApiError } from "../../../infra/api/types";
|
|
|
4
4
|
import { buildQueryParams } from "../../../infra/utils/params";
|
|
5
5
|
import { getUserContext } from "../../auth/utils/get-user-context";
|
|
6
6
|
import { fileToBase64 } from "../../../utils/file/index";
|
|
7
|
+
import { buildWlOverride } from "../../auth/utils/build-wl-override";
|
|
7
8
|
class AccountService {
|
|
8
9
|
async findCurrentAccount(config) {
|
|
9
|
-
const { id_account } = await getUserContext();
|
|
10
|
-
const
|
|
10
|
+
const { id_wl, id_account } = await getUserContext();
|
|
11
|
+
const effectiveConfig = config ?? await buildWlOverride(id_wl);
|
|
12
|
+
const response = await api.apps.get(`/accounts/${id_account}`, effectiveConfig);
|
|
11
13
|
if (response.status === 0 || !response.data?.[0]) {
|
|
12
14
|
throw new ApiError(
|
|
13
15
|
response.message || "Erro ao buscar dados da conta",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/accounts/services/account.service.ts"],"sourcesContent":["import 'server-only';\n\nimport { api } from '../../../infra/api/client';\nimport { ApiError } from '../../../infra/api/types';\nimport { buildQueryParams } from '../../../infra/utils/params';\nimport { getUserContext } from '../../auth/utils/get-user-context';\nimport { fileToBase64 } from '../../../utils/file/index';\nimport type { RequestConfig } from '../../../infra/api/client';\nimport type {\n Account,\n AccountUsersPaginationParams,\n ChangePasswordRequest,\n ChangePasswordResponse,\n ChangeUserPhotoResponse,\n CreateAccountUserRequest,\n CreateAccountUserResponse,\n DeleteAccountResponse,\n DeleteAccountUserResponse,\n GetAccountDataResponse,\n ListAccountUsersResponse,\n UpdateAccountRequest,\n UpdateAccountResponse,\n UpdateAccountUserRequest,\n UpdateAccountUserResponse,\n} from '../types';\n\nclass AccountService {\n async findCurrentAccount(config?: RequestConfig): Promise<Account> {\n const { id_account } = await getUserContext();\n const response = await api.apps.get<GetAccountDataResponse>(`/accounts/${id_account}`, config);\n\n if (response.status === 0 || !response.data?.[0]) {\n throw new ApiError(\n response.message || 'Erro ao buscar dados da conta',\n 'GET_ACCOUNT_FAILED',\n 400\n );\n }\n\n return response.data[0];\n }\n\n async listAccountUsers(params?: Partial<AccountUsersPaginationParams>) {\n const { id_account } = await getUserContext();\n const queryParams = buildQueryParams(params);\n const endpoint = `/accounts/${id_account}/users?${queryParams}`;\n const response = await api.apps.get<ListAccountUsersResponse>(endpoint);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao listar usuários',\n 'LIST_ACCOUNT_USERS_FAILED',\n 400\n );\n }\n\n return {\n users: response.data || [],\n total: response.total || 0,\n };\n }\n\n async changeUserPhoto(userId: number, photo: File): Promise<ChangeUserPhotoResponse> {\n const { id_account } = await getUserContext();\n const base64 = await fileToBase64(photo);\n const response = await api.apps.put<ChangeUserPhotoResponse>(\n `/accounts/${id_account}/users/${userId}/file/photo`,\n { file: base64 }\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao mudar foto do usuário',\n 'CHANGE_USER_PHOTO_FAILED',\n 400\n );\n }\n\n return response;\n }\n\n async deleteAccountUser(userId: number): Promise<DeleteAccountUserResponse> {\n const { id_account } = await getUserContext();\n const response = await api.apps.delete<DeleteAccountUserResponse>(\n `/accounts/${id_account}/users/${userId}`\n );\n\n if (response.status === 0) {\n throw new ApiError(response.message || 'Erro ao deletar usuário', 'DELETE_USER_FAILED', 400);\n }\n\n return response;\n }\n\n async deleteAccount(): Promise<DeleteAccountResponse> {\n const { id_account } = await getUserContext();\n const response = await api.apps.delete<DeleteAccountResponse>(`/accounts/${id_account}`);\n\n if (response.status === 0) {\n throw new ApiError(response.message || 'Erro ao deletar conta', 'DELETE_ACCOUNT_FAILED', 400);\n }\n\n return response;\n }\n\n async createAccountUser(user: CreateAccountUserRequest): Promise<CreateAccountUserResponse> {\n const { id_account } = await getUserContext();\n const response = await api.apps.post<CreateAccountUserResponse>(\n `/accounts/${id_account}/users`,\n {\n ...user,\n photo: user.photo ? await fileToBase64(user.photo) : null,\n }\n );\n\n if (response.status === 0) {\n throw new ApiError(response.message || 'Erro ao criar usuário', 'CREATE_USER_FAILED', 400);\n }\n\n return response;\n }\n\n private async resolvePhotoField(user: UpdateAccountUserRequest): Promise<{ photo?: string | null }> {\n if (user.photo === undefined) return {};\n const photo =\n user.photo != null && typeof user.photo !== 'string'\n ? await fileToBase64(user.photo)\n : user.photo;\n return { photo };\n }\n\n async updateAccountUser(user: UpdateAccountUserRequest): Promise<UpdateAccountUserResponse> {\n const { id_account, id_user } = await getUserContext();\n const response = await api.apps.put<UpdateAccountUserResponse>(\n `/accounts/${id_account}/users/${id_user}`,\n { ...user, ...(await this.resolvePhotoField(user)) }\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao atualizar usuário',\n 'UPDATE_USER_FAILED',\n 400\n );\n }\n\n return response;\n }\n\n async updateAccountUserById(\n userId: number,\n user: UpdateAccountUserRequest\n ): Promise<UpdateAccountUserResponse> {\n const { id_account } = await getUserContext();\n const response = await api.apps.put<UpdateAccountUserResponse>(\n `/accounts/${id_account}/users/${userId}`,\n { ...user, ...(await this.resolvePhotoField(user)) }\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao atualizar usuário',\n 'UPDATE_USER_FAILED',\n 400\n );\n }\n\n return response;\n }\n\n async updateAccount(data: UpdateAccountRequest): Promise<UpdateAccountResponse> {\n const { id_account } = await getUserContext();\n const response = await api.apps.put<UpdateAccountResponse>(`/accounts/${id_account}`, data);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao atualizar conta',\n 'UPDATE_ACCOUNT_FAILED',\n 400\n );\n }\n\n return response;\n }\n\n async requestContactReset(type: 'email' | 'phone', newContact: string, ddi?: string): Promise<void> {\n const { id_account, id_user } = await getUserContext();\n const response = await api.apps.post<{ status: number; message: string }>(\n `/accounts/${id_account}/users/${id_user}/resetContact/request`,\n { type, newContact, ...(ddi ? { ddi } : {}) }\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao solicitar alteração',\n 'REQUEST_CONTACT_RESET_FAILED',\n 400\n );\n }\n }\n\n async confirmContactReset(type: 'email' | 'phone', token: string, newContact: string, ddi?: string): Promise<void> {\n const { id_account, id_user } = await getUserContext();\n const response = await api.apps.post<{ status: number; message: string }>(\n `/accounts/${id_account}/users/${id_user}/resetContact/confirm`,\n { type, token, newContact, ...(ddi ? { ddi } : {}) }\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Código inválido ou expirado',\n 'CONFIRM_CONTACT_RESET_FAILED',\n 400\n );\n }\n }\n\n async changePassword(data: ChangePasswordRequest): Promise<ChangePasswordResponse> {\n const { id_account, id_user } = await getUserContext();\n const response = await api.apps.put<ChangePasswordResponse>(\n `/accounts/${id_account}/users/${id_user}/action/changePassword`,\n data\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao alterar senha',\n 'CHANGE_PASSWORD_FAILED',\n 400\n );\n }\n\n return response;\n }\n}\n\nexport const accountService = new AccountService();\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,WAAW;AACpB,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,oBA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,EACF;AAAA,EAEA,MAAM,oBAAoB,MAAyB,OAAe,YAAoB,KAA6B;AACjH,UAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,eAAe;AACrD,UAAM,WAAW,MAAM,IAAI,KAAK;AAAA,MAC9B,aAAa,UAAU,UAAU,OAAO;AAAA,MACxC,EAAE,MAAM,OAAO,YAAY,GAAI,MAAM,EAAE,IAAI,IAAI,CAAC,EAAG;AAAA,IACrD;AAEA,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,eAAe,MAA8D;AACjF,UAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,eAAe;AACrD,UAAM,WAAW,MAAM,IAAI,KAAK;AAAA,MAC9B,aAAa,UAAU,UAAU,OAAO;AAAA,MACxC;AAAA,IACF;AAEA,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,iBAAiB,IAAI,eAAe;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/services/account.service.ts"],"sourcesContent":["import 'server-only';\n\nimport { api } from '../../../infra/api/client';\nimport { ApiError } from '../../../infra/api/types';\nimport { buildQueryParams } from '../../../infra/utils/params';\nimport { getUserContext } from '../../auth/utils/get-user-context';\nimport { fileToBase64 } from '../../../utils/file/index';\nimport type { RequestConfig } from '../../../infra/api/client';\nimport { buildWlOverride } from '../../auth/utils/build-wl-override';\nimport type {\n Account,\n AccountUsersPaginationParams,\n ChangePasswordRequest,\n ChangePasswordResponse,\n ChangeUserPhotoResponse,\n CreateAccountUserRequest,\n CreateAccountUserResponse,\n DeleteAccountResponse,\n DeleteAccountUserResponse,\n GetAccountDataResponse,\n ListAccountUsersResponse,\n UpdateAccountRequest,\n UpdateAccountResponse,\n UpdateAccountUserRequest,\n UpdateAccountUserResponse,\n} from '../types';\n\nclass AccountService {\n async findCurrentAccount(config?: RequestConfig): Promise<Account> {\n const { id_wl, id_account } = await getUserContext();\n const effectiveConfig = config ?? await buildWlOverride(id_wl);\n const response = await api.apps.get<GetAccountDataResponse>(`/accounts/${id_account}`, effectiveConfig);\n\n if (response.status === 0 || !response.data?.[0]) {\n throw new ApiError(\n response.message || 'Erro ao buscar dados da conta',\n 'GET_ACCOUNT_FAILED',\n 400\n );\n }\n\n return response.data[0];\n }\n\n async listAccountUsers(params?: Partial<AccountUsersPaginationParams>) {\n const { id_account } = await getUserContext();\n const queryParams = buildQueryParams(params);\n const endpoint = `/accounts/${id_account}/users?${queryParams}`;\n const response = await api.apps.get<ListAccountUsersResponse>(endpoint);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao listar usuários',\n 'LIST_ACCOUNT_USERS_FAILED',\n 400\n );\n }\n\n return {\n users: response.data || [],\n total: response.total || 0,\n };\n }\n\n async changeUserPhoto(userId: number, photo: File): Promise<ChangeUserPhotoResponse> {\n const { id_account } = await getUserContext();\n const base64 = await fileToBase64(photo);\n const response = await api.apps.put<ChangeUserPhotoResponse>(\n `/accounts/${id_account}/users/${userId}/file/photo`,\n { file: base64 }\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao mudar foto do usuário',\n 'CHANGE_USER_PHOTO_FAILED',\n 400\n );\n }\n\n return response;\n }\n\n async deleteAccountUser(userId: number): Promise<DeleteAccountUserResponse> {\n const { id_account } = await getUserContext();\n const response = await api.apps.delete<DeleteAccountUserResponse>(\n `/accounts/${id_account}/users/${userId}`\n );\n\n if (response.status === 0) {\n throw new ApiError(response.message || 'Erro ao deletar usuário', 'DELETE_USER_FAILED', 400);\n }\n\n return response;\n }\n\n async deleteAccount(): Promise<DeleteAccountResponse> {\n const { id_account } = await getUserContext();\n const response = await api.apps.delete<DeleteAccountResponse>(`/accounts/${id_account}`);\n\n if (response.status === 0) {\n throw new ApiError(response.message || 'Erro ao deletar conta', 'DELETE_ACCOUNT_FAILED', 400);\n }\n\n return response;\n }\n\n async createAccountUser(user: CreateAccountUserRequest): Promise<CreateAccountUserResponse> {\n const { id_account } = await getUserContext();\n const response = await api.apps.post<CreateAccountUserResponse>(\n `/accounts/${id_account}/users`,\n {\n ...user,\n photo: user.photo ? await fileToBase64(user.photo) : null,\n }\n );\n\n if (response.status === 0) {\n throw new ApiError(response.message || 'Erro ao criar usuário', 'CREATE_USER_FAILED', 400);\n }\n\n return response;\n }\n\n private async resolvePhotoField(user: UpdateAccountUserRequest): Promise<{ photo?: string | null }> {\n if (user.photo === undefined) return {};\n const photo =\n user.photo != null && typeof user.photo !== 'string'\n ? await fileToBase64(user.photo)\n : user.photo;\n return { photo };\n }\n\n async updateAccountUser(user: UpdateAccountUserRequest): Promise<UpdateAccountUserResponse> {\n const { id_account, id_user } = await getUserContext();\n const response = await api.apps.put<UpdateAccountUserResponse>(\n `/accounts/${id_account}/users/${id_user}`,\n { ...user, ...(await this.resolvePhotoField(user)) }\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao atualizar usuário',\n 'UPDATE_USER_FAILED',\n 400\n );\n }\n\n return response;\n }\n\n async updateAccountUserById(\n userId: number,\n user: UpdateAccountUserRequest\n ): Promise<UpdateAccountUserResponse> {\n const { id_account } = await getUserContext();\n const response = await api.apps.put<UpdateAccountUserResponse>(\n `/accounts/${id_account}/users/${userId}`,\n { ...user, ...(await this.resolvePhotoField(user)) }\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao atualizar usuário',\n 'UPDATE_USER_FAILED',\n 400\n );\n }\n\n return response;\n }\n\n async updateAccount(data: UpdateAccountRequest): Promise<UpdateAccountResponse> {\n const { id_account } = await getUserContext();\n const response = await api.apps.put<UpdateAccountResponse>(`/accounts/${id_account}`, data);\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao atualizar conta',\n 'UPDATE_ACCOUNT_FAILED',\n 400\n );\n }\n\n return response;\n }\n\n async requestContactReset(type: 'email' | 'phone', newContact: string, ddi?: string): Promise<void> {\n const { id_account, id_user } = await getUserContext();\n const response = await api.apps.post<{ status: number; message: string }>(\n `/accounts/${id_account}/users/${id_user}/resetContact/request`,\n { type, newContact, ...(ddi ? { ddi } : {}) }\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao solicitar alteração',\n 'REQUEST_CONTACT_RESET_FAILED',\n 400\n );\n }\n }\n\n async confirmContactReset(type: 'email' | 'phone', token: string, newContact: string, ddi?: string): Promise<void> {\n const { id_account, id_user } = await getUserContext();\n const response = await api.apps.post<{ status: number; message: string }>(\n `/accounts/${id_account}/users/${id_user}/resetContact/confirm`,\n { type, token, newContact, ...(ddi ? { ddi } : {}) }\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Código inválido ou expirado',\n 'CONFIRM_CONTACT_RESET_FAILED',\n 400\n );\n }\n }\n\n async changePassword(data: ChangePasswordRequest): Promise<ChangePasswordResponse> {\n const { id_account, id_user } = await getUserContext();\n const response = await api.apps.put<ChangePasswordResponse>(\n `/accounts/${id_account}/users/${id_user}/action/changePassword`,\n data\n );\n\n if (response.status === 0) {\n throw new ApiError(\n response.message || 'Erro ao alterar senha',\n 'CHANGE_PASSWORD_FAILED',\n 400\n );\n }\n\n return response;\n }\n}\n\nexport const accountService = new AccountService();\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,WAAW;AACpB,SAAS,gBAAgB;AACzB,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,oBAAoB;AAE7B,SAAS,uBAAuB;AAmBhC,MAAM,eAAe;AAAA,EACnB,MAAM,mBAAmB,QAA0C;AACjE,UAAM,EAAE,OAAO,WAAW,IAAI,MAAM,eAAe;AACnD,UAAM,kBAAkB,UAAU,MAAM,gBAAgB,KAAK;AAC7D,UAAM,WAAW,MAAM,IAAI,KAA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AI,KAAK;AAAA,MAC9B,aAAa,UAAU,UAAU,OAAO;AAAA,MACxC,EAAE,MAAM,OAAO,YAAY,GAAI,MAAM,EAAE,IAAI,IAAI,CAAC,EAAG;AAAA,IACrD;AAEA,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,eAAe,MAA8D;AACjF,UAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,eAAe;AACrD,UAAM,WAAW,MAAM,IAAI,KAAK;AAAA,MAC9B,aAAa,UAAU,UAAU,OAAO;AAAA,MACxC;AAAA,IACF;AAEA,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,iBAAiB,IAAI,eAAe;","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { UserProfile } from "../../users/schema";
|
|
3
|
+
import { findUserById } from "../../users/action/find-user-by-id.action";
|
|
4
|
+
import { ApiError } from "../../../infra/api/types";
|
|
5
|
+
import { assertManagementSubscription } from "./assert-management-subscription";
|
|
6
|
+
async function getCurrentUserProfile() {
|
|
7
|
+
const result = await findUserById();
|
|
8
|
+
if (!result.success || !result.data) {
|
|
9
|
+
throw new ApiError(
|
|
10
|
+
"error" in result && result.error || "N\xE3o foi poss\xEDvel identificar o usu\xE1rio autenticado",
|
|
11
|
+
"USER_CONTEXT_FAILED",
|
|
12
|
+
403
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return result.data.profile;
|
|
16
|
+
}
|
|
17
|
+
async function assertManagementPermission(permission) {
|
|
18
|
+
const profile = await getCurrentUserProfile();
|
|
19
|
+
switch (permission) {
|
|
20
|
+
case "manage_pages":
|
|
21
|
+
case "manage_domains":
|
|
22
|
+
case "manage_redirects":
|
|
23
|
+
case "manage_ab_tests":
|
|
24
|
+
case "restore_pages":
|
|
25
|
+
if (profile === UserProfile.viewer) {
|
|
26
|
+
throw new ApiError("Voc\xEA n\xE3o tem permiss\xE3o para executar esta a\xE7\xE3o", "FORBIDDEN", 403);
|
|
27
|
+
}
|
|
28
|
+
await assertManagementSubscription();
|
|
29
|
+
return;
|
|
30
|
+
default:
|
|
31
|
+
throw new ApiError("Permiss\xE3o inv\xE1lida", "INVALID_PERMISSION", 500);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
assertManagementPermission
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=assert-management-permission.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/auth/utils/assert-management-permission.ts"],"sourcesContent":["import 'server-only';\n\nimport { UserProfile } from '../../users/schema';\nimport { findUserById } from '../../users/action/find-user-by-id.action';\nimport { ApiError } from '../../../infra/api/types';\nimport { assertManagementSubscription } from './assert-management-subscription';\n\nexport type ServerManagementPermission =\n | 'manage_pages'\n | 'manage_domains'\n | 'manage_redirects'\n | 'manage_ab_tests'\n | 'restore_pages';\n\nasync function getCurrentUserProfile() {\n const result = await findUserById();\n\n if (!result.success || !result.data) {\n throw new ApiError(\n ('error' in result && result.error) || 'Não foi possível identificar o usuário autenticado',\n 'USER_CONTEXT_FAILED',\n 403\n );\n }\n\n return result.data.profile;\n}\n\nexport async function assertManagementPermission(permission: ServerManagementPermission) {\n const profile = await getCurrentUserProfile();\n\n switch (permission) {\n case 'manage_pages':\n case 'manage_domains':\n case 'manage_redirects':\n case 'manage_ab_tests':\n case 'restore_pages':\n if (profile === UserProfile.viewer) {\n throw new ApiError('Você não tem permissão para executar esta ação', 'FORBIDDEN', 403);\n }\n await assertManagementSubscription();\n return;\n default:\n throw new ApiError('Permissão inválida', 'INVALID_PERMISSION', 500);\n }\n}\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,SAAS,oCAAoC;AAS7C,eAAe,wBAAwB;AACrC,QAAM,SAAS,MAAM,aAAa;AAElC,MAAI,CAAC,OAAO,WAAW,CAAC,OAAO,MAAM;AACnC,UAAM,IAAI;AAAA,MACP,WAAW,UAAU,OAAO,SAAU;AAAA,MACvC;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SAAO,OAAO,KAAK;AACrB;AAEA,eAAsB,2BAA2B,YAAwC;AACvF,QAAM,UAAU,MAAM,sBAAsB;AAE5C,UAAQ,YAAY;AAAA,IAClB,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,UAAI,YAAY,YAAY,QAAQ;AAClC,cAAM,IAAI,SAAS,iEAAkD,aAAa,GAAG;AAAA,MACvF;AACA,YAAM,6BAA6B;AACnC;AAAA,IACF;AACE,YAAM,IAAI,SAAS,4BAAsB,sBAAsB,GAAG;AAAA,EACtE;AACF;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { ApiError } from "../../../infra/api/types";
|
|
3
|
+
import { listSubscriptionsAction } from "../../subscriptions/actions/list-subscriptions.action";
|
|
4
|
+
import { hasSubscriptionExpired } from "../../subscriptions/utils/has-subscription-expired";
|
|
5
|
+
async function assertManagementSubscription() {
|
|
6
|
+
const result = await listSubscriptionsAction({ active: true });
|
|
7
|
+
if (!result.success) {
|
|
8
|
+
throw new ApiError(
|
|
9
|
+
result.error || "N\xE3o foi poss\xEDvel validar a assinatura atual",
|
|
10
|
+
"SUBSCRIPTION_CONTEXT_FAILED",
|
|
11
|
+
403
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
const subscription = result.data?.data?.[0];
|
|
15
|
+
if (hasSubscriptionExpired(subscription?.date_due)) {
|
|
16
|
+
throw new ApiError(
|
|
17
|
+
"Sua assinatura est\xE1 vencida. Assine um novo plano para continuar.",
|
|
18
|
+
"SUBSCRIPTION_EXPIRED",
|
|
19
|
+
403
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
assertManagementSubscription
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=assert-management-subscription.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/auth/utils/assert-management-subscription.ts"],"sourcesContent":["import 'server-only';\n\nimport { ApiError } from '../../../infra/api/types';\nimport { listSubscriptionsAction } from '../../subscriptions/actions/list-subscriptions.action';\nimport { hasSubscriptionExpired } from '../../subscriptions/utils/has-subscription-expired';\n\nexport async function assertManagementSubscription() {\n const result = await listSubscriptionsAction({ active: true });\n\n if (!result.success) {\n throw new ApiError(\n result.error || 'Não foi possível validar a assinatura atual',\n 'SUBSCRIPTION_CONTEXT_FAILED',\n 403\n );\n }\n\n const subscription = result.data?.data?.[0];\n\n if (hasSubscriptionExpired(subscription?.date_due)) {\n throw new ApiError(\n 'Sua assinatura está vencida. Assine um novo plano para continuar.',\n 'SUBSCRIPTION_EXPIRED',\n 403\n );\n }\n}\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,gBAAgB;AACzB,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AAEvC,eAAsB,+BAA+B;AACnD,QAAM,SAAS,MAAM,wBAAwB,EAAE,QAAQ,KAAK,CAAC;AAE7D,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,IAAI;AAAA,MACR,OAAO,SAAS;AAAA,MAChB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,QAAM,eAAe,OAAO,MAAM,OAAO,CAAC;AAE1C,MAAI,uBAAuB,cAAc,QAAQ,GAAG;AAClD,UAAM,IAAI;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import "server-only";
|
|
2
2
|
import { findWhitelabel } from "../../whitelabel/actions/find-whitelabel.action";
|
|
3
3
|
import { whitelabelService } from "../../whitelabel/services/whitelabel.service";
|
|
4
|
-
async function
|
|
4
|
+
async function buildWlOverride(jwtWlId) {
|
|
5
5
|
try {
|
|
6
|
-
const payload = JSON.parse(atob(cookie.split(".")[1]));
|
|
7
|
-
const jwtWlId = Number(payload.id_wl);
|
|
8
6
|
const { id: hostWlId } = await findWhitelabel();
|
|
9
7
|
if (jwtWlId !== hostWlId) {
|
|
10
8
|
const wlToken = await whitelabelService.getTokenByWhitelabelId(jwtWlId);
|
|
@@ -14,7 +12,16 @@ async function buildWlOverrideFromJwt(cookie) {
|
|
|
14
12
|
}
|
|
15
13
|
return void 0;
|
|
16
14
|
}
|
|
15
|
+
async function buildWlOverrideFromJwt(cookie) {
|
|
16
|
+
try {
|
|
17
|
+
const payload = JSON.parse(atob(cookie.split(".")[1]));
|
|
18
|
+
return buildWlOverride(Number(payload.id_wl));
|
|
19
|
+
} catch {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
17
23
|
export {
|
|
24
|
+
buildWlOverride,
|
|
18
25
|
buildWlOverrideFromJwt
|
|
19
26
|
};
|
|
20
27
|
//# sourceMappingURL=build-wl-override.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/utils/build-wl-override.ts"],"sourcesContent":["import 'server-only';\n\nimport type { RequestConfig } from '../../../infra/api/client';\nimport type { JWTPayload } from '../../users/schema';\nimport { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';\nimport { whitelabelService } from '../../whitelabel/services/whitelabel.service';\n\n/**\n * Compara
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/auth/utils/build-wl-override.ts"],"sourcesContent":["import 'server-only';\n\nimport type { RequestConfig } from '../../../infra/api/client';\nimport type { JWTPayload } from '../../users/schema';\nimport { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';\nimport { whitelabelService } from '../../whitelabel/services/whitelabel.service';\n\n/**\n * Compara um `id_wl` com o whitelabel resolvido pelo hostname.\n * Se forem diferentes (ex: admin com id_wl=1 num domínio de id_wl=30),\n * retorna um RequestConfig com o override correto.\n * Se forem iguais, retorna undefined (sem custo extra).\n */\nexport async function buildWlOverride(\n jwtWlId: number,\n): Promise<RequestConfig | undefined> {\n try {\n const { id: hostWlId } = await findWhitelabel();\n\n if (jwtWlId !== hostWlId) {\n const wlToken = await whitelabelService.getTokenByWhitelabelId(jwtWlId);\n return { whiteLabelId: jwtWlId, authToken: wlToken };\n }\n } catch {\n // Fallback to default whitelabel resolution\n }\n\n return undefined;\n}\n\n/**\n * Extrai `id_wl` do JWT cookie e delega para `buildWlOverride`.\n */\nexport async function buildWlOverrideFromJwt(\n cookie: string,\n): Promise<RequestConfig | undefined> {\n try {\n const payload = JSON.parse(atob(cookie.split('.')[1])) as JWTPayload;\n return buildWlOverride(Number(payload.id_wl));\n } catch {\n return undefined;\n }\n}\n"],"mappings":"AAAA,OAAO;AAIP,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAQlC,eAAsB,gBACpB,SACoC;AACpC,MAAI;AACF,UAAM,EAAE,IAAI,SAAS,IAAI,MAAM,eAAe;AAE9C,QAAI,YAAY,UAAU;AACxB,YAAM,UAAU,MAAM,kBAAkB,uBAAuB,OAAO;AACtE,aAAO,EAAE,cAAc,SAAS,WAAW,QAAQ;AAAA,IACrD;AAAA,EACF,QAAQ;AAAA,EAER;AAEA,SAAO;AACT;AAKA,eAAsB,uBACpB,QACoC;AACpC,MAAI;AACF,UAAM,UAAU,KAAK,MAAM,KAAK,OAAO,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;AACrD,WAAO,gBAAgB,OAAO,QAAQ,KAAK,CAAC;AAAA,EAC9C,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback } from "react";
|
|
3
|
+
import { UserProfile } from "../../users/schema";
|
|
4
|
+
import { useAuth } from "../../../providers/auth.provider";
|
|
5
|
+
import { useModalManager } from "../../../store/useModalManager";
|
|
6
|
+
import { useActiveSubscription } from "./find-active-subscription.hook";
|
|
7
|
+
import { hasSubscriptionExpired } from "../utils/has-subscription-expired";
|
|
8
|
+
function useCancelledSubscriptionGuard() {
|
|
9
|
+
const { user } = useAuth();
|
|
10
|
+
const { openModal } = useModalManager();
|
|
11
|
+
const {
|
|
12
|
+
data: { data: [subscription] = [] } = {}
|
|
13
|
+
} = useActiveSubscription();
|
|
14
|
+
const isViewer = user?.profile === UserProfile.viewer;
|
|
15
|
+
const isCancelledSubscription = hasSubscriptionExpired(subscription?.date_due);
|
|
16
|
+
const shouldBlockManagementAction = !isViewer && isCancelledSubscription;
|
|
17
|
+
const guardAction = useCallback(
|
|
18
|
+
(action) => {
|
|
19
|
+
if (shouldBlockManagementAction) {
|
|
20
|
+
openModal("subscriptionExpiredModal");
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
action?.();
|
|
24
|
+
return true;
|
|
25
|
+
},
|
|
26
|
+
[openModal, shouldBlockManagementAction]
|
|
27
|
+
);
|
|
28
|
+
return {
|
|
29
|
+
isCancelledSubscription,
|
|
30
|
+
shouldBlockManagementAction,
|
|
31
|
+
guardAction
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export {
|
|
35
|
+
useCancelledSubscriptionGuard
|
|
36
|
+
};
|
|
37
|
+
//# sourceMappingURL=use-cancelled-subscription-guard.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/hooks/use-cancelled-subscription-guard.ts"],"sourcesContent":["'use client';\n\nimport { useCallback } from 'react';\nimport { UserProfile } from '../../users/schema';\nimport { useAuth } from '../../../providers/auth.provider';\nimport { useModalManager } from '../../../store/useModalManager';\nimport { useActiveSubscription } from './find-active-subscription.hook';\nimport { hasSubscriptionExpired } from '../utils/has-subscription-expired';\n\nexport function useCancelledSubscriptionGuard() {\n const { user } = useAuth();\n const { openModal } = useModalManager();\n const {\n data: { data: [subscription] = [] } = {},\n } = useActiveSubscription();\n\n const isViewer = user?.profile === UserProfile.viewer;\n const isCancelledSubscription = hasSubscriptionExpired(subscription?.date_due);\n const shouldBlockManagementAction = !isViewer && isCancelledSubscription;\n\n const guardAction = useCallback(\n (action?: () => void) => {\n if (shouldBlockManagementAction) {\n openModal('subscriptionExpiredModal');\n return false;\n }\n\n action?.();\n return true;\n },\n [openModal, shouldBlockManagementAction]\n );\n\n return {\n isCancelledSubscription,\n shouldBlockManagementAction,\n guardAction,\n };\n}\n"],"mappings":";AAEA,SAAS,mBAAmB;AAC5B,SAAS,mBAAmB;AAC5B,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,8BAA8B;AAEhC,SAAS,gCAAgC;AAC9C,QAAM,EAAE,KAAK,IAAI,QAAQ;AACzB,QAAM,EAAE,UAAU,IAAI,gBAAgB;AACtC,QAAM;AAAA,IACJ,MAAM,EAAE,MAAM,CAAC,YAAY,IAAI,CAAC,EAAE,IAAI,CAAC;AAAA,EACzC,IAAI,sBAAsB;AAE1B,QAAM,WAAW,MAAM,YAAY,YAAY;AAC/C,QAAM,0BAA0B,uBAAuB,cAAc,QAAQ;AAC7E,QAAM,8BAA8B,CAAC,YAAY;AAEjD,QAAM,cAAc;AAAA,IAClB,CAAC,WAAwB;AACvB,UAAI,6BAA6B;AAC/B,kBAAU,0BAA0B;AACpC,eAAO;AAAA,MACT;AAEA,eAAS;AACT,aAAO;AAAA,IACT;AAAA,IACA,CAAC,WAAW,2BAA2B;AAAA,EACzC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
function hasSubscriptionExpired(dateDue) {
|
|
2
|
+
if (!dateDue) return false;
|
|
3
|
+
const dueDate = new Date(dateDue);
|
|
4
|
+
dueDate.setHours(23, 59, 59, 999);
|
|
5
|
+
return Date.now() > dueDate.getTime();
|
|
6
|
+
}
|
|
7
|
+
export {
|
|
8
|
+
hasSubscriptionExpired
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=has-subscription-expired.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/subscriptions/utils/has-subscription-expired.ts"],"sourcesContent":["export function hasSubscriptionExpired(dateDue: Date | null | undefined) {\n if (!dateDue) return false;\n\n const dueDate = new Date(dateDue);\n dueDate.setHours(23, 59, 59, 999);\n\n return Date.now() > dueDate.getTime();\n}\n"],"mappings":"AAAO,SAAS,uBAAuB,SAAkC;AACvE,MAAI,CAAC,QAAS,QAAO;AAErB,QAAM,UAAU,IAAI,KAAK,OAAO;AAChC,UAAQ,SAAS,IAAI,IAAI,IAAI,GAAG;AAEhC,SAAO,KAAK,IAAI,IAAI,QAAQ,QAAQ;AACtC;","names":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { cookies } from "next/headers";
|
|
2
2
|
import { ApiError } from "../../../infra/api/types";
|
|
3
3
|
import { findWhitelabel } from "../../whitelabel/actions/find-whitelabel.action";
|
|
4
|
+
import { buildWlOverride } from "../../auth/utils/build-wl-override";
|
|
4
5
|
const AUTH_COOKIE_NAME = "greatapps";
|
|
5
6
|
const API_BASE_URL = process.env.GAPPS_R3_API_URL || "https://r3-api.greatapps.dev.br";
|
|
6
7
|
class UserService {
|
|
@@ -24,7 +25,8 @@ class UserService {
|
|
|
24
25
|
const token = await this.getAuthToken();
|
|
25
26
|
const payload = this.decodeJWT(token);
|
|
26
27
|
const { id_wl, id_account, id_user } = payload;
|
|
27
|
-
const
|
|
28
|
+
const wlOverride = overrides ? void 0 : await buildWlOverride(Number(id_wl));
|
|
29
|
+
const wlToken = overrides?.authToken ?? wlOverride?.authToken ?? (await findWhitelabel()).token;
|
|
28
30
|
const url = `${API_BASE_URL}/v1/pt-br/${id_wl}/accounts/${id_account}/users/${id_user}`;
|
|
29
31
|
const response = await fetch(url, {
|
|
30
32
|
method: "GET",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/users/services/user.service.ts"],"sourcesContent":["\r\nimport { cookies } from 'next/headers';\r\n\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { GetUserDataResponse, JWTPayload, User } from '../schema';\r\nimport { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';\r\n\r\nconst AUTH_COOKIE_NAME = 'greatapps';\r\nconst API_BASE_URL = process.env.GAPPS_R3_API_URL || 'https://r3-api.greatapps.dev.br';\r\n\r\nclass UserService {\r\n private async getAuthToken(): Promise<string> {\r\n if (process.env.DUMMY_AUTH_TOKEN) return process.env.DUMMY_AUTH_TOKEN;\r\n const cookieStore = await cookies();\r\n const token = cookieStore.get(AUTH_COOKIE_NAME)?.value;\r\n\r\n if (!token) {\r\n throw new ApiError('Não autenticado', 'NOT_AUTHENTICATED_GAT', 401);\r\n }\r\n\r\n return token;\r\n }\r\n\r\n private decodeJWT(token: string): JWTPayload {\r\n try {\r\n return JSON.parse(atob(token.split('.')[1])) as JWTPayload;\r\n } catch {\r\n throw new ApiError('Token inválido', 'INVALID_TOKEN', 401);\r\n }\r\n }\r\n\r\n async findById(overrides?: { authToken?: string }): Promise<User> {\r\n const token = await this.getAuthToken();\r\n const payload = this.decodeJWT(token);\r\n\r\n const { id_wl, id_account, id_user } = payload;\r\n const wlToken = overrides?.authToken ?? (await findWhitelabel()).token;\r\n\r\n const url = `${API_BASE_URL}/v1/pt-br/${id_wl}/accounts/${id_account}/users/${id_user}`;\r\n\r\n const response = await fetch(url, {\r\n method: 'GET',\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n authorization: wlToken,\r\n },\r\n });\r\n\r\n if (!response.ok) {\r\n throw new ApiError('Erro ao buscar dados do usuário', 'FETCH_ERROR', response.status);\r\n }\r\n\r\n const data = (await response.json()) as GetUserDataResponse;\r\n\r\n if (data.status === 0 || !data.data || data.data.length === 0) {\r\n throw new ApiError('Dados do usuário não encontrados', 'USER_NOT_FOUND', 404);\r\n }\r\n\r\n return data.data[0];\r\n }\r\n}\r\n\r\nexport const userService = new UserService();\r\n"],"mappings":"AACA,SAAS,eAAe;AAExB,SAAS,gBAAgB;AAEzB,SAAS,sBAAsB;
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/users/services/user.service.ts"],"sourcesContent":["\r\nimport { cookies } from 'next/headers';\r\n\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { GetUserDataResponse, JWTPayload, User } from '../schema';\r\nimport { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';\r\nimport { buildWlOverride } from '../../auth/utils/build-wl-override';\r\n\r\nconst AUTH_COOKIE_NAME = 'greatapps';\r\nconst API_BASE_URL = process.env.GAPPS_R3_API_URL || 'https://r3-api.greatapps.dev.br';\r\n\r\nclass UserService {\r\n private async getAuthToken(): Promise<string> {\r\n if (process.env.DUMMY_AUTH_TOKEN) return process.env.DUMMY_AUTH_TOKEN;\r\n const cookieStore = await cookies();\r\n const token = cookieStore.get(AUTH_COOKIE_NAME)?.value;\r\n\r\n if (!token) {\r\n throw new ApiError('Não autenticado', 'NOT_AUTHENTICATED_GAT', 401);\r\n }\r\n\r\n return token;\r\n }\r\n\r\n private decodeJWT(token: string): JWTPayload {\r\n try {\r\n return JSON.parse(atob(token.split('.')[1])) as JWTPayload;\r\n } catch {\r\n throw new ApiError('Token inválido', 'INVALID_TOKEN', 401);\r\n }\r\n }\r\n\r\n async findById(overrides?: { authToken?: string }): Promise<User> {\r\n const token = await this.getAuthToken();\r\n const payload = this.decodeJWT(token);\r\n\r\n const { id_wl, id_account, id_user } = payload;\r\n const wlOverride = overrides ? undefined : await buildWlOverride(Number(id_wl));\r\n const wlToken = overrides?.authToken ?? wlOverride?.authToken ?? (await findWhitelabel()).token;\r\n\r\n const url = `${API_BASE_URL}/v1/pt-br/${id_wl}/accounts/${id_account}/users/${id_user}`;\r\n\r\n const response = await fetch(url, {\r\n method: 'GET',\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n authorization: wlToken,\r\n },\r\n });\r\n\r\n if (!response.ok) {\r\n throw new ApiError('Erro ao buscar dados do usuário', 'FETCH_ERROR', response.status);\r\n }\r\n\r\n const data = (await response.json()) as GetUserDataResponse;\r\n\r\n if (data.status === 0 || !data.data || data.data.length === 0) {\r\n throw new ApiError('Dados do usuário não encontrados', 'USER_NOT_FOUND', 404);\r\n }\r\n\r\n return data.data[0];\r\n }\r\n}\r\n\r\nexport const userService = new UserService();\r\n"],"mappings":"AACA,SAAS,eAAe;AAExB,SAAS,gBAAgB;AAEzB,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAEhC,MAAM,mBAAmB;AACzB,MAAM,eAAe,QAAQ,IAAI,oBAAoB;AAErD,MAAM,YAAY;AAAA,EAChB,MAAc,eAAgC;AAC5C,QAAI,QAAQ,IAAI,iBAAkB,QAAO,QAAQ,IAAI;AACrD,UAAM,cAAc,MAAM,QAAQ;AAClC,UAAM,QAAQ,YAAY,IAAI,gBAAgB,GAAG;AAEjD,QAAI,CAAC,OAAO;AACV,YAAM,IAAI,SAAS,sBAAmB,yBAAyB,GAAG;AAAA,IACpE;AAEA,WAAO;AAAA,EACT;AAAA,EAEQ,UAAU,OAA2B;AAC3C,QAAI;AACF,aAAO,KAAK,MAAM,KAAK,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;AAAA,IAC7C,QAAQ;AACN,YAAM,IAAI,SAAS,qBAAkB,iBAAiB,GAAG;AAAA,IAC3D;AAAA,EACF;AAAA,EAEA,MAAM,SAAS,WAAmD;AAChE,UAAM,QAAQ,MAAM,KAAK,aAAa;AACtC,UAAM,UAAU,KAAK,UAAU,KAAK;AAEpC,UAAM,EAAE,OAAO,YAAY,QAAQ,IAAI;AACvC,UAAM,aAAa,YAAY,SAAY,MAAM,gBAAgB,OAAO,KAAK,CAAC;AAC9E,UAAM,UAAU,WAAW,aAAa,YAAY,cAAc,MAAM,eAAe,GAAG;AAE1F,UAAM,MAAM,GAAG,YAAY,aAAa,KAAK,aAAa,UAAU,UAAU,OAAO;AAErF,UAAM,WAAW,MAAM,MAAM,KAAK;AAAA,MAChC,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,eAAe;AAAA,MACjB;AAAA,IACF,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,IAAI,SAAS,sCAAmC,eAAe,SAAS,MAAM;AAAA,IACtF;AAEA,UAAM,OAAQ,MAAM,SAAS,KAAK;AAElC,QAAI,KAAK,WAAW,KAAK,CAAC,KAAK,QAAQ,KAAK,KAAK,WAAW,GAAG;AAC7D,YAAM,IAAI,SAAS,0CAAoC,kBAAkB,GAAG;AAAA,IAC9E;AAEA,WAAO,KAAK,KAAK,CAAC;AAAA,EACpB;AACF;AAEO,MAAM,cAAc,IAAI,YAAY;","names":[]}
|
package/dist/server.mjs
CHANGED
|
@@ -3,6 +3,8 @@ import { ApiClient, api, apiClient } from "./infra/api/client";
|
|
|
3
3
|
import { authService } from "./modules/auth/services/auth.service";
|
|
4
4
|
import { whitelabelService } from "./modules/whitelabel/services/whitelabel.service";
|
|
5
5
|
import { revalidateWhitelabelAction } from "./modules/whitelabel/actions/revalidate-whitelabel.action";
|
|
6
|
+
import { assertManagementPermission } from "./modules/auth/utils/assert-management-permission";
|
|
7
|
+
import { assertManagementSubscription } from "./modules/auth/utils/assert-management-subscription";
|
|
6
8
|
import { subscriptionsService } from "./modules/subscriptions/services/subscriptions.service";
|
|
7
9
|
import { plansService } from "./modules/plans/services/plans.service";
|
|
8
10
|
import { cardsService } from "./modules/cards/services/cards.service";
|
|
@@ -18,6 +20,7 @@ import { updateSubscriptionPlanAction } from "./modules/subscriptions/actions/up
|
|
|
18
20
|
import { listCardsAction } from "./modules/cards/actions/list-cards.action";
|
|
19
21
|
import { createCardAction } from "./modules/cards/actions/create-card.action";
|
|
20
22
|
import { resolvePlanExtrasPrices } from "./modules/subscriptions/utils/resolve-plan-extras-prices";
|
|
23
|
+
import { hasSubscriptionExpired } from "./modules/subscriptions/utils/has-subscription-expired";
|
|
21
24
|
import { listIaCreditsAction } from "./modules/ia-credits/actions/list-ia-credits.action";
|
|
22
25
|
import { projectUsersService } from "./modules/projects/services/project-users.service";
|
|
23
26
|
import { listProjectUsersAction } from "./modules/projects/actions/list-project-users.action";
|
|
@@ -52,6 +55,8 @@ export {
|
|
|
52
55
|
addProjectUserAction,
|
|
53
56
|
api,
|
|
54
57
|
apiClient,
|
|
58
|
+
assertManagementPermission,
|
|
59
|
+
assertManagementSubscription,
|
|
55
60
|
authService,
|
|
56
61
|
calculateSubscriptionAction,
|
|
57
62
|
cardsService,
|
|
@@ -71,6 +76,7 @@ export {
|
|
|
71
76
|
generateTwoFactorAction,
|
|
72
77
|
getClientInfoFromRequest,
|
|
73
78
|
getUserContext,
|
|
79
|
+
hasSubscriptionExpired,
|
|
74
80
|
iaCreditsService,
|
|
75
81
|
listAccountUsersAction,
|
|
76
82
|
listAvailableUsersAction,
|
package/dist/server.mjs.map
CHANGED
|
@@ -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';\
|
|
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';\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\nexport { revalidateWhitelabelAction } from './modules/whitelabel/actions/revalidate-whitelabel.action';\nexport { assertManagementPermission } from './modules/auth/utils/assert-management-permission';\nexport { assertManagementSubscription } from './modules/auth/utils/assert-management-subscription';\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';\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 { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';\r\nexport { findPlanByIdAction } from './modules/plans/actions/find-plan-by-id.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';\nexport { hasSubscriptionExpired } from './modules/subscriptions/utils/has-subscription-expired';\nexport { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';\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 { safeServerAction } from './utils/safeServerAction';\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,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,+BAA+B;AACxC,SAAS,0BAA0B;AACnC,SAAS,mCAAmC;AAC5C,SAAS,oCAAoC;AAC7C,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AACjC,SAAS,+BAA+B;AACxC,SAAS,8BAA8B;AACvC,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,wBAAwB;","names":[]}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -39,6 +39,7 @@ export {
|
|
|
39
39
|
export { useSubscriptions } from "./modules/subscriptions/hooks/list-subscriptions.hook";
|
|
40
40
|
export { SUBSCRIPTIONS_QUERY_KEY } from "./modules/subscriptions/constants/query-keys.constants";
|
|
41
41
|
export { useActiveSubscription } from "./modules/subscriptions/hooks/find-active-subscription.hook";
|
|
42
|
+
export { useCancelledSubscriptionGuard } from "./modules/subscriptions/hooks/use-cancelled-subscription-guard";
|
|
42
43
|
export { usePlanById } from "./modules/plans/hooks/use-plan-by-id.hook";
|
|
43
44
|
export { useHasPlanAddon } from "./modules/plans/hooks/use-has-plan-addon.hook";
|
|
44
45
|
export { useCalculateSubscription } from "./modules/subscriptions/hooks/calculate-subscription.hook";
|
|
@@ -72,6 +73,7 @@ export type {
|
|
|
72
73
|
export type { Card as PaymentCard, CreateCardRequest } from "./modules/cards/types";
|
|
73
74
|
export { CardSchema as PaymentCardSchema, CreateCardRequestSchema } from "./modules/cards/types";
|
|
74
75
|
export { buildPlanExtras } from "./modules/subscriptions/utils/build-plan-extras";
|
|
76
|
+
export { hasSubscriptionExpired } from "./modules/subscriptions/utils/has-subscription-expired";
|
|
75
77
|
export { getPriceFromCalculatedData, periodicityToBillingPeriod } from "./modules/subscriptions/utils/periodicity";
|
|
76
78
|
export { useBuyCreditsModal } from "./store/useBuyCreditsModal";
|
|
77
79
|
export { default as BuyCreditsModal } from "./components/modals/BuyCreditsModal";
|
|
@@ -6,6 +6,7 @@ import { buildQueryParams } from '../../../infra/utils/params';
|
|
|
6
6
|
import { getUserContext } from '../../auth/utils/get-user-context';
|
|
7
7
|
import { fileToBase64 } from '../../../utils/file/index';
|
|
8
8
|
import type { RequestConfig } from '../../../infra/api/client';
|
|
9
|
+
import { buildWlOverride } from '../../auth/utils/build-wl-override';
|
|
9
10
|
import type {
|
|
10
11
|
Account,
|
|
11
12
|
AccountUsersPaginationParams,
|
|
@@ -26,8 +27,9 @@ import type {
|
|
|
26
27
|
|
|
27
28
|
class AccountService {
|
|
28
29
|
async findCurrentAccount(config?: RequestConfig): Promise<Account> {
|
|
29
|
-
const { id_account } = await getUserContext();
|
|
30
|
-
const
|
|
30
|
+
const { id_wl, id_account } = await getUserContext();
|
|
31
|
+
const effectiveConfig = config ?? await buildWlOverride(id_wl);
|
|
32
|
+
const response = await api.apps.get<GetAccountDataResponse>(`/accounts/${id_account}`, effectiveConfig);
|
|
31
33
|
|
|
32
34
|
if (response.status === 0 || !response.data?.[0]) {
|
|
33
35
|
throw new ApiError(
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import { UserProfile } from '../../users/schema';
|
|
4
|
+
import { findUserById } from '../../users/action/find-user-by-id.action';
|
|
5
|
+
import { ApiError } from '../../../infra/api/types';
|
|
6
|
+
import { assertManagementSubscription } from './assert-management-subscription';
|
|
7
|
+
|
|
8
|
+
export type ServerManagementPermission =
|
|
9
|
+
| 'manage_pages'
|
|
10
|
+
| 'manage_domains'
|
|
11
|
+
| 'manage_redirects'
|
|
12
|
+
| 'manage_ab_tests'
|
|
13
|
+
| 'restore_pages';
|
|
14
|
+
|
|
15
|
+
async function getCurrentUserProfile() {
|
|
16
|
+
const result = await findUserById();
|
|
17
|
+
|
|
18
|
+
if (!result.success || !result.data) {
|
|
19
|
+
throw new ApiError(
|
|
20
|
+
('error' in result && result.error) || 'Não foi possível identificar o usuário autenticado',
|
|
21
|
+
'USER_CONTEXT_FAILED',
|
|
22
|
+
403
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return result.data.profile;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export async function assertManagementPermission(permission: ServerManagementPermission) {
|
|
30
|
+
const profile = await getCurrentUserProfile();
|
|
31
|
+
|
|
32
|
+
switch (permission) {
|
|
33
|
+
case 'manage_pages':
|
|
34
|
+
case 'manage_domains':
|
|
35
|
+
case 'manage_redirects':
|
|
36
|
+
case 'manage_ab_tests':
|
|
37
|
+
case 'restore_pages':
|
|
38
|
+
if (profile === UserProfile.viewer) {
|
|
39
|
+
throw new ApiError('Você não tem permissão para executar esta ação', 'FORBIDDEN', 403);
|
|
40
|
+
}
|
|
41
|
+
await assertManagementSubscription();
|
|
42
|
+
return;
|
|
43
|
+
default:
|
|
44
|
+
throw new ApiError('Permissão inválida', 'INVALID_PERMISSION', 500);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import { ApiError } from '../../../infra/api/types';
|
|
4
|
+
import { listSubscriptionsAction } from '../../subscriptions/actions/list-subscriptions.action';
|
|
5
|
+
import { hasSubscriptionExpired } from '../../subscriptions/utils/has-subscription-expired';
|
|
6
|
+
|
|
7
|
+
export async function assertManagementSubscription() {
|
|
8
|
+
const result = await listSubscriptionsAction({ active: true });
|
|
9
|
+
|
|
10
|
+
if (!result.success) {
|
|
11
|
+
throw new ApiError(
|
|
12
|
+
result.error || 'Não foi possível validar a assinatura atual',
|
|
13
|
+
'SUBSCRIPTION_CONTEXT_FAILED',
|
|
14
|
+
403
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const subscription = result.data?.data?.[0];
|
|
19
|
+
|
|
20
|
+
if (hasSubscriptionExpired(subscription?.date_due)) {
|
|
21
|
+
throw new ApiError(
|
|
22
|
+
'Sua assinatura está vencida. Assine um novo plano para continuar.',
|
|
23
|
+
'SUBSCRIPTION_EXPIRED',
|
|
24
|
+
403
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -6,17 +6,15 @@ import { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action'
|
|
|
6
6
|
import { whitelabelService } from '../../whitelabel/services/whitelabel.service';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Compara
|
|
10
|
-
* Se forem diferentes (ex: admin
|
|
9
|
+
* Compara um `id_wl` com o whitelabel resolvido pelo hostname.
|
|
10
|
+
* Se forem diferentes (ex: admin com id_wl=1 num domínio de id_wl=30),
|
|
11
11
|
* retorna um RequestConfig com o override correto.
|
|
12
12
|
* Se forem iguais, retorna undefined (sem custo extra).
|
|
13
13
|
*/
|
|
14
|
-
export async function
|
|
15
|
-
|
|
14
|
+
export async function buildWlOverride(
|
|
15
|
+
jwtWlId: number,
|
|
16
16
|
): Promise<RequestConfig | undefined> {
|
|
17
17
|
try {
|
|
18
|
-
const payload = JSON.parse(atob(cookie.split('.')[1])) as JWTPayload;
|
|
19
|
-
const jwtWlId = Number(payload.id_wl);
|
|
20
18
|
const { id: hostWlId } = await findWhitelabel();
|
|
21
19
|
|
|
22
20
|
if (jwtWlId !== hostWlId) {
|
|
@@ -29,3 +27,17 @@ export async function buildWlOverrideFromJwt(
|
|
|
29
27
|
|
|
30
28
|
return undefined;
|
|
31
29
|
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Extrai `id_wl` do JWT cookie e delega para `buildWlOverride`.
|
|
33
|
+
*/
|
|
34
|
+
export async function buildWlOverrideFromJwt(
|
|
35
|
+
cookie: string,
|
|
36
|
+
): Promise<RequestConfig | undefined> {
|
|
37
|
+
try {
|
|
38
|
+
const payload = JSON.parse(atob(cookie.split('.')[1])) as JWTPayload;
|
|
39
|
+
return buildWlOverride(Number(payload.id_wl));
|
|
40
|
+
} catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
import { UserProfile } from '../../users/schema';
|
|
5
|
+
import { useAuth } from '../../../providers/auth.provider';
|
|
6
|
+
import { useModalManager } from '../../../store/useModalManager';
|
|
7
|
+
import { useActiveSubscription } from './find-active-subscription.hook';
|
|
8
|
+
import { hasSubscriptionExpired } from '../utils/has-subscription-expired';
|
|
9
|
+
|
|
10
|
+
export function useCancelledSubscriptionGuard() {
|
|
11
|
+
const { user } = useAuth();
|
|
12
|
+
const { openModal } = useModalManager();
|
|
13
|
+
const {
|
|
14
|
+
data: { data: [subscription] = [] } = {},
|
|
15
|
+
} = useActiveSubscription();
|
|
16
|
+
|
|
17
|
+
const isViewer = user?.profile === UserProfile.viewer;
|
|
18
|
+
const isCancelledSubscription = hasSubscriptionExpired(subscription?.date_due);
|
|
19
|
+
const shouldBlockManagementAction = !isViewer && isCancelledSubscription;
|
|
20
|
+
|
|
21
|
+
const guardAction = useCallback(
|
|
22
|
+
(action?: () => void) => {
|
|
23
|
+
if (shouldBlockManagementAction) {
|
|
24
|
+
openModal('subscriptionExpiredModal');
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
action?.();
|
|
29
|
+
return true;
|
|
30
|
+
},
|
|
31
|
+
[openModal, shouldBlockManagementAction]
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
isCancelledSubscription,
|
|
36
|
+
shouldBlockManagementAction,
|
|
37
|
+
guardAction,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -4,6 +4,7 @@ import { cookies } from 'next/headers';
|
|
|
4
4
|
import { ApiError } from '../../../infra/api/types';
|
|
5
5
|
import { GetUserDataResponse, JWTPayload, User } from '../schema';
|
|
6
6
|
import { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';
|
|
7
|
+
import { buildWlOverride } from '../../auth/utils/build-wl-override';
|
|
7
8
|
|
|
8
9
|
const AUTH_COOKIE_NAME = 'greatapps';
|
|
9
10
|
const API_BASE_URL = process.env.GAPPS_R3_API_URL || 'https://r3-api.greatapps.dev.br';
|
|
@@ -34,7 +35,8 @@ class UserService {
|
|
|
34
35
|
const payload = this.decodeJWT(token);
|
|
35
36
|
|
|
36
37
|
const { id_wl, id_account, id_user } = payload;
|
|
37
|
-
const
|
|
38
|
+
const wlOverride = overrides ? undefined : await buildWlOverride(Number(id_wl));
|
|
39
|
+
const wlToken = overrides?.authToken ?? wlOverride?.authToken ?? (await findWhitelabel()).token;
|
|
38
40
|
|
|
39
41
|
const url = `${API_BASE_URL}/v1/pt-br/${id_wl}/accounts/${id_account}/users/${id_user}`;
|
|
40
42
|
|
package/src/server.ts
CHANGED
|
@@ -4,10 +4,12 @@ import 'server-only';
|
|
|
4
4
|
export { ApiClient, api, apiClient } from './infra/api/client';
|
|
5
5
|
|
|
6
6
|
// Services
|
|
7
|
-
export { authService } from './modules/auth/services/auth.service';
|
|
8
|
-
export { whitelabelService } from './modules/whitelabel/services/whitelabel.service';
|
|
9
|
-
export { revalidateWhitelabelAction } from './modules/whitelabel/actions/revalidate-whitelabel.action';
|
|
10
|
-
export {
|
|
7
|
+
export { authService } from './modules/auth/services/auth.service';
|
|
8
|
+
export { whitelabelService } from './modules/whitelabel/services/whitelabel.service';
|
|
9
|
+
export { revalidateWhitelabelAction } from './modules/whitelabel/actions/revalidate-whitelabel.action';
|
|
10
|
+
export { assertManagementPermission } from './modules/auth/utils/assert-management-permission';
|
|
11
|
+
export { assertManagementSubscription } from './modules/auth/utils/assert-management-subscription';
|
|
12
|
+
export { subscriptionsService } from './modules/subscriptions/services/subscriptions.service';
|
|
11
13
|
export { plansService } from './modules/plans/services/plans.service';
|
|
12
14
|
export { cardsService } from './modules/cards/services/cards.service';
|
|
13
15
|
export { iaCreditsService } from './modules/ia-credits/services/ia-credits.service';
|
|
@@ -23,8 +25,9 @@ export { calculateSubscriptionAction } from './modules/subscriptions/actions/cal
|
|
|
23
25
|
export { updateSubscriptionPlanAction } from './modules/subscriptions/actions/update-subscription-plan.action';
|
|
24
26
|
export { listCardsAction } from './modules/cards/actions/list-cards.action';
|
|
25
27
|
export { createCardAction } from './modules/cards/actions/create-card.action';
|
|
26
|
-
export { resolvePlanExtrasPrices } from './modules/subscriptions/utils/resolve-plan-extras-prices';
|
|
27
|
-
export {
|
|
28
|
+
export { resolvePlanExtrasPrices } from './modules/subscriptions/utils/resolve-plan-extras-prices';
|
|
29
|
+
export { hasSubscriptionExpired } from './modules/subscriptions/utils/has-subscription-expired';
|
|
30
|
+
export { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.action';
|
|
28
31
|
|
|
29
32
|
// Project Users Services & Actions (server-only)
|
|
30
33
|
export { projectUsersService } from './modules/projects/services/project-users.service';
|