@greatapps/common 1.1.542 → 1.1.546
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/components/account/ConfigurationsMyAccountModal.mjs +1 -1
- package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +1 -1
- package/dist/components/account/ConfirmDeleteAccountModal.mjs +12 -10
- package/dist/components/account/ConfirmDeleteAccountModal.mjs.map +1 -1
- package/dist/components/account/DeleteAccountModal.mjs +21 -5
- package/dist/components/account/DeleteAccountModal.mjs.map +1 -1
- package/dist/components/account/sections/MyProfileSection.mjs +3 -61
- package/dist/components/account/sections/MyProfileSection.mjs.map +1 -1
- package/dist/components/navigation/CancelledSubscriptionBanner.mjs +5 -4
- package/dist/components/navigation/CancelledSubscriptionBanner.mjs.map +1 -1
- package/dist/modules/accounts/actions/account-management.action.mjs +16 -15
- package/dist/modules/accounts/actions/account-management.action.mjs.map +1 -1
- package/dist/modules/accounts/hooks/useAccountManagement.mjs.map +1 -1
- package/dist/modules/accounts/services/account.service.mjs +5 -2
- package/dist/modules/accounts/services/account.service.mjs.map +1 -1
- package/dist/modules/auth/hooks/useUserQuery.mjs +1 -1
- package/dist/modules/auth/hooks/useUserQuery.mjs.map +1 -1
- package/dist/modules/auth/utils/require-valid-session.mjs +17 -0
- package/dist/modules/auth/utils/require-valid-session.mjs.map +1 -0
- package/dist/modules/cards/actions/create-card.action.mjs +2 -2
- package/dist/modules/cards/actions/create-card.action.mjs.map +1 -1
- package/dist/modules/cards/actions/delete-card.action.mjs +2 -2
- package/dist/modules/cards/actions/delete-card.action.mjs.map +1 -1
- package/dist/modules/cards/actions/set-default-card.action.mjs +2 -2
- package/dist/modules/cards/actions/set-default-card.action.mjs.map +1 -1
- package/dist/modules/cards/types.mjs +13 -12
- package/dist/modules/cards/types.mjs.map +1 -1
- package/dist/modules/plans/utils/map-api-plan-to-ui.mjs +1 -1
- package/dist/modules/plans/utils/map-api-plan-to-ui.mjs.map +1 -1
- package/dist/modules/projects/actions/add-project-user.action.mjs +2 -2
- package/dist/modules/projects/actions/add-project-user.action.mjs.map +1 -1
- package/dist/modules/projects/actions/create-project.action.mjs +2 -2
- package/dist/modules/projects/actions/create-project.action.mjs.map +1 -1
- package/dist/modules/projects/actions/delete-project.action.mjs +2 -2
- package/dist/modules/projects/actions/delete-project.action.mjs.map +1 -1
- package/dist/modules/projects/actions/remove-project-user.action.mjs +2 -2
- package/dist/modules/projects/actions/remove-project-user.action.mjs.map +1 -1
- package/dist/modules/projects/actions/update-project.action.mjs +2 -2
- package/dist/modules/projects/actions/update-project.action.mjs.map +1 -1
- package/dist/modules/subscriptions/actions/update-subscription-plan.action.mjs +2 -2
- package/dist/modules/subscriptions/actions/update-subscription-plan.action.mjs.map +1 -1
- package/dist/modules/subscriptions/types/subscription.type.mjs +2 -1
- package/dist/modules/subscriptions/types/subscription.type.mjs.map +1 -1
- package/dist/modules/users/action/mark-all-messages-as-read.action.mjs +2 -2
- package/dist/modules/users/action/mark-all-messages-as-read.action.mjs.map +1 -1
- package/dist/modules/users/action/mark-message-as-read.action.mjs +2 -2
- package/dist/modules/users/action/mark-message-as-read.action.mjs.map +1 -1
- package/dist/server.mjs +4 -0
- package/dist/server.mjs.map +1 -1
- package/dist/store/useAccountModals.mjs +25 -4
- package/dist/store/useAccountModals.mjs.map +1 -1
- package/dist/utils/safeMutationAction.mjs +13 -0
- package/dist/utils/safeMutationAction.mjs.map +1 -0
- package/package.json +1 -1
- package/src/components/account/ConfigurationsMyAccountModal.tsx +1 -0
- package/src/components/account/ConfirmDeleteAccountModal.tsx +16 -7
- package/src/components/account/DeleteAccountModal.tsx +24 -4
- package/src/components/account/sections/MyProfileSection.tsx +2 -68
- package/src/components/navigation/CancelledSubscriptionBanner.tsx +7 -4
- package/src/modules/accounts/actions/account-management.action.ts +17 -15
- package/src/modules/accounts/hooks/useAccountManagement.ts +2 -1
- package/src/modules/accounts/services/account.service.ts +6 -2
- package/src/modules/accounts/types.ts +4 -0
- package/src/modules/auth/hooks/useUserQuery.ts +1 -1
- package/src/modules/auth/utils/require-valid-session.ts +35 -0
- package/src/modules/cards/actions/create-card.action.ts +2 -2
- package/src/modules/cards/actions/delete-card.action.ts +2 -2
- package/src/modules/cards/actions/set-default-card.action.ts +2 -2
- package/src/modules/cards/types.ts +14 -12
- package/src/modules/plans/utils/map-api-plan-to-ui.ts +1 -1
- package/src/modules/projects/actions/add-project-user.action.ts +2 -2
- package/src/modules/projects/actions/create-project.action.ts +2 -2
- package/src/modules/projects/actions/delete-project.action.ts +2 -2
- package/src/modules/projects/actions/remove-project-user.action.ts +2 -2
- package/src/modules/projects/actions/update-project.action.ts +2 -2
- package/src/modules/subscriptions/actions/update-subscription-plan.action.ts +2 -2
- package/src/modules/subscriptions/types/subscription.type.ts +2 -1
- package/src/modules/users/action/mark-all-messages-as-read.action.ts +2 -2
- package/src/modules/users/action/mark-message-as-read.action.ts +2 -2
- package/src/server.ts +2 -0
- package/src/store/useAccountModals.ts +41 -8
- package/src/utils/safeMutationAction.ts +30 -0
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import z from 'zod';
|
|
2
2
|
|
|
3
|
+
import {
|
|
4
|
+
PaginationParamsSchema,
|
|
5
|
+
SearchParamsSchema,
|
|
6
|
+
SortParamsSchema,
|
|
7
|
+
} from '../../infra/api/types';
|
|
8
|
+
|
|
3
9
|
export const CardSchema = z.object({
|
|
4
10
|
id: z.union([z.number(), z.string()]),
|
|
5
|
-
id_wl: z.number()
|
|
6
|
-
id_account: z.union([z.number(), z.string()])
|
|
11
|
+
id_wl: z.number(),
|
|
12
|
+
id_account: z.union([z.number(), z.string()]),
|
|
7
13
|
id_gateway: z.union([z.number(), z.string()]).optional(),
|
|
8
|
-
gateway_account: z.string()
|
|
9
|
-
gateway_card: z.string()
|
|
14
|
+
gateway_account: z.string(),
|
|
15
|
+
gateway_card: z.string(),
|
|
10
16
|
brand: z.string(),
|
|
11
17
|
name: z.string(),
|
|
12
18
|
number: z.string().nullable(),
|
|
13
|
-
date: z.string().nullable()
|
|
19
|
+
date: z.string().nullable(),
|
|
14
20
|
deleted: z
|
|
15
21
|
.number()
|
|
16
22
|
.transform((val) => val === 1)
|
|
@@ -31,12 +37,8 @@ export const CreateCardRequestSchema = z.object({
|
|
|
31
37
|
|
|
32
38
|
export type CreateCardRequest = z.infer<typeof CreateCardRequestSchema>;
|
|
33
39
|
|
|
34
|
-
export const FindCardsParamsSchema =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
search: z.string().optional(),
|
|
38
|
-
sort: z.string().optional(),
|
|
39
|
-
order: z.enum(['asc', 'desc']).optional(),
|
|
40
|
-
});
|
|
40
|
+
export const FindCardsParamsSchema = PaginationParamsSchema.extend(SearchParamsSchema.shape).extend(
|
|
41
|
+
SortParamsSchema.shape
|
|
42
|
+
);
|
|
41
43
|
|
|
42
44
|
export type FindCardsParams = z.infer<typeof FindCardsParamsSchema>;
|
|
@@ -16,7 +16,7 @@ const BASE_FEATURES: PlanFeature[] = [
|
|
|
16
16
|
{ icon: "check", text: "Compartilhar páginas", tooltip: "sharePages" },
|
|
17
17
|
{ icon: "check", text: "Hospedagem inclusa" },
|
|
18
18
|
{ icon: "check", text: "SSL (HTTPS) + CDN" },
|
|
19
|
-
{ icon: "check", text: "Templates
|
|
19
|
+
{ icon: "check", text: "Templates gratuitos" },
|
|
20
20
|
];
|
|
21
21
|
|
|
22
22
|
function buildMainFeaturesFromItems(items: Plan["items"]): PlanMainFeatures {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { safeMutationAction } from '../../../utils/safeMutationAction';
|
|
4
4
|
import { projectUsersService } from '../services/project-users.service';
|
|
5
5
|
import type { AddRemoveProjectUsersParams } from '../types';
|
|
6
6
|
|
|
7
7
|
export async function addProjectUserAction(params: AddRemoveProjectUsersParams) {
|
|
8
|
-
return
|
|
8
|
+
return safeMutationAction(() => projectUsersService.addToProject(params));
|
|
9
9
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { safeMutationAction } from '../../../utils/safeMutationAction';
|
|
4
4
|
import { projectsService } from '../services/projects.service';
|
|
5
5
|
import type { CreateProjectRequest } from '../types';
|
|
6
6
|
|
|
7
7
|
export async function createProjectAction(data: CreateProjectRequest) {
|
|
8
|
-
return
|
|
8
|
+
return safeMutationAction(() => projectsService.create(data));
|
|
9
9
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { safeMutationAction } from '../../../utils/safeMutationAction';
|
|
4
4
|
import { projectsService } from '../services/projects.service';
|
|
5
5
|
|
|
6
6
|
export async function deleteProjectAction(projectId: number, moveToProjectId: number) {
|
|
7
|
-
return
|
|
7
|
+
return safeMutationAction(() => projectsService.delete(projectId, moveToProjectId));
|
|
8
8
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { safeMutationAction } from '../../../utils/safeMutationAction';
|
|
4
4
|
import { projectUsersService } from '../services/project-users.service';
|
|
5
5
|
import type { AddRemoveProjectUsersParams } from '../types';
|
|
6
6
|
|
|
7
7
|
export async function removeProjectUserAction(params: AddRemoveProjectUsersParams) {
|
|
8
|
-
return
|
|
8
|
+
return safeMutationAction(() => projectUsersService.removeFromProject(params));
|
|
9
9
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { safeMutationAction } from '../../../utils/safeMutationAction';
|
|
4
4
|
import { projectsService } from '../services/projects.service';
|
|
5
5
|
import type { UpdateProjectRequest } from '../types';
|
|
6
6
|
|
|
7
7
|
export async function updateProjectAction(projectId: number, data: UpdateProjectRequest) {
|
|
8
|
-
return
|
|
8
|
+
return safeMutationAction(() => projectsService.update(projectId, data));
|
|
9
9
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use server";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { safeMutationAction } from "../../../utils/safeMutationAction";
|
|
4
4
|
import type { UpdateSubscriptionPlanRequest } from "../types/calculate-subscription.type";
|
|
5
5
|
import { subscriptionsService } from "../services/subscriptions.service";
|
|
6
6
|
|
|
@@ -8,7 +8,7 @@ export async function updateSubscriptionPlanAction(
|
|
|
8
8
|
subscriptionId: number | string,
|
|
9
9
|
data: UpdateSubscriptionPlanRequest,
|
|
10
10
|
) {
|
|
11
|
-
return
|
|
11
|
+
return safeMutationAction(async () => {
|
|
12
12
|
return subscriptionsService.updateSubscriptionPlan(subscriptionId, data);
|
|
13
13
|
});
|
|
14
14
|
}
|
|
@@ -41,7 +41,7 @@ export const SubscriptionSchema = z.object({
|
|
|
41
41
|
id_gateway: z.union([z.number(), z.string()]).nullable(),
|
|
42
42
|
gateway_account: z.string().nullable(),
|
|
43
43
|
date_hiring: z.coerce.date().nullable(),
|
|
44
|
-
date_due: z.coerce.date(),
|
|
44
|
+
date_due: z.coerce.date().nullable(),
|
|
45
45
|
date_cancellation: z.coerce.date().nullable(),
|
|
46
46
|
date_verification: z.coerce.date().nullable(),
|
|
47
47
|
cancellation_reason: z.string().nullable(),
|
|
@@ -52,6 +52,7 @@ export const SubscriptionSchema = z.object({
|
|
|
52
52
|
card_name: z.string().nullable().optional(),
|
|
53
53
|
card_brand: z.string().nullable().optional(),
|
|
54
54
|
card_number: z.string().nullable().optional(),
|
|
55
|
+
card: z.record(z.string(), z.unknown()).nullable().optional(),
|
|
55
56
|
items: z.array(SubscriptionItemSchema),
|
|
56
57
|
pending_change: z.object({
|
|
57
58
|
schedule_id: z.string(),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { safeMutationAction } from '../../../utils/safeMutationAction';
|
|
4
4
|
import { messagesService } from '../services/messages.service';
|
|
5
5
|
|
|
6
6
|
export async function markAllMessagesAsReadAction() {
|
|
7
|
-
return
|
|
7
|
+
return safeMutationAction(() => messagesService.markAllAsRead());
|
|
8
8
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use server';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { safeMutationAction } from '../../../utils/safeMutationAction';
|
|
4
4
|
import { messagesService } from '../services/messages.service';
|
|
5
5
|
|
|
6
6
|
export async function markMessageAsReadAction(messageId: string) {
|
|
7
|
-
return
|
|
7
|
+
return safeMutationAction(() => messagesService.markAsRead(messageId));
|
|
8
8
|
}
|
package/src/server.ts
CHANGED
|
@@ -73,8 +73,10 @@ export {
|
|
|
73
73
|
// Server Utils
|
|
74
74
|
export { getClientInfoFromRequest } from './infra/utils/client-info';
|
|
75
75
|
export { getUserContext } from './modules/auth/utils/get-user-context';
|
|
76
|
+
export { requireValidSession } from './modules/auth/utils/require-valid-session';
|
|
76
77
|
export { buildWlOverride, buildWlOverrideFromJwt } from './modules/auth/utils/build-wl-override';
|
|
77
78
|
export { safeServerAction } from './utils/safeServerAction';
|
|
79
|
+
export { safeMutationAction } from './utils/safeMutationAction';
|
|
78
80
|
|
|
79
81
|
// Image Processing (server-side)
|
|
80
82
|
export { processImageAction } from './modules/images/actions/process-image.action';
|
|
@@ -13,18 +13,29 @@ export interface AccountModalsConfig {
|
|
|
13
13
|
onGoToSubscription?: () => void;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
interface DeleteAccountPayload {
|
|
17
|
+
password: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
16
20
|
interface AccountModalsState {
|
|
17
21
|
activeModal: AccountModalType | null;
|
|
18
22
|
config: AccountModalsConfig;
|
|
19
23
|
initialSection?: AccountSectionType;
|
|
20
24
|
|
|
25
|
+
/** Payload coletado no DeleteAccountModal, consumido pelo ConfirmDeleteAccountModal. */
|
|
26
|
+
deleteAccountPayload: DeleteAccountPayload | null;
|
|
27
|
+
/** Mensagem de erro do backend quando o delete falha (ex.: senha inválida).
|
|
28
|
+
* Mostrada no DeleteAccountModal quando o usuário é mandado de volta. */
|
|
29
|
+
deleteAccountError: string | null;
|
|
30
|
+
|
|
21
31
|
/** Called by <AccountModals> to keep app-level config in sync */
|
|
22
32
|
updateConfig: (config: AccountModalsConfig) => void;
|
|
23
33
|
|
|
24
34
|
openConfigurations: (initialSection?: AccountSectionType) => void;
|
|
25
|
-
openDeleteAccount: () => void;
|
|
35
|
+
openDeleteAccount: (error?: string) => void;
|
|
26
36
|
openIsntPossibleDelete: () => void;
|
|
27
|
-
openConfirmDelete: () => void;
|
|
37
|
+
openConfirmDelete: (payload: DeleteAccountPayload) => void;
|
|
38
|
+
clearDeleteAccountError: () => void;
|
|
28
39
|
close: () => void;
|
|
29
40
|
}
|
|
30
41
|
|
|
@@ -32,21 +43,43 @@ export const useAccountModals = create<AccountModalsState>((set) => ({
|
|
|
32
43
|
activeModal: null,
|
|
33
44
|
config: {},
|
|
34
45
|
initialSection: undefined,
|
|
46
|
+
deleteAccountPayload: null,
|
|
47
|
+
deleteAccountError: null,
|
|
35
48
|
|
|
36
49
|
updateConfig: (config) => set({ config }),
|
|
37
50
|
|
|
38
51
|
openConfigurations: (initialSection) =>
|
|
39
|
-
set({
|
|
52
|
+
set({
|
|
53
|
+
activeModal: 'configurations',
|
|
54
|
+
initialSection,
|
|
55
|
+
deleteAccountPayload: null,
|
|
56
|
+
deleteAccountError: null,
|
|
57
|
+
}),
|
|
40
58
|
|
|
41
|
-
openDeleteAccount: () =>
|
|
42
|
-
set({
|
|
59
|
+
openDeleteAccount: (error) =>
|
|
60
|
+
set({
|
|
61
|
+
activeModal: 'deleteAccount',
|
|
62
|
+
deleteAccountPayload: null,
|
|
63
|
+
deleteAccountError: error ?? null,
|
|
64
|
+
}),
|
|
43
65
|
|
|
44
66
|
openIsntPossibleDelete: () =>
|
|
45
67
|
set({ activeModal: 'isntPossibleDelete' }),
|
|
46
68
|
|
|
47
|
-
openConfirmDelete: () =>
|
|
48
|
-
set({
|
|
69
|
+
openConfirmDelete: (payload) =>
|
|
70
|
+
set({
|
|
71
|
+
activeModal: 'confirmDelete',
|
|
72
|
+
deleteAccountPayload: payload,
|
|
73
|
+
deleteAccountError: null,
|
|
74
|
+
}),
|
|
75
|
+
|
|
76
|
+
clearDeleteAccountError: () => set({ deleteAccountError: null }),
|
|
49
77
|
|
|
50
78
|
close: () =>
|
|
51
|
-
set({
|
|
79
|
+
set({
|
|
80
|
+
activeModal: null,
|
|
81
|
+
initialSection: undefined,
|
|
82
|
+
deleteAccountPayload: null,
|
|
83
|
+
deleteAccountError: null,
|
|
84
|
+
}),
|
|
52
85
|
}));
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import 'server-only';
|
|
2
|
+
|
|
3
|
+
import type { ActionResult } from '../infra/api/types';
|
|
4
|
+
import { requireValidSession } from '../modules/auth/utils/require-valid-session';
|
|
5
|
+
import { safeServerAction } from './safeServerAction';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Wrapper para server actions que mutam estado (delete/update/create/publish/
|
|
9
|
+
* billing/etc.). Faz validação de sessão contra o backend (`POST /auth/keep`)
|
|
10
|
+
* antes de executar a ação e roteia erros via `safeServerAction`.
|
|
11
|
+
*
|
|
12
|
+
* A validação é deduplicada por request — múltiplas actions sensíveis que
|
|
13
|
+
* rodem dentro de uma mesma request pagam 1 round-trip ao backend, não N.
|
|
14
|
+
*
|
|
15
|
+
* Motivação (resumo): o backend confia no par `(whitelabel-token, id_account
|
|
16
|
+
* no path)` nos endpoints de CRUD; o Next.js deriva `id_account` de
|
|
17
|
+
* `atob(cookie)` sem verificar assinatura. Chamar `requireValidSession`
|
|
18
|
+
* aqui garante que o cookie corresponde a uma sessão real no banco antes
|
|
19
|
+
* de qualquer mutação.
|
|
20
|
+
*
|
|
21
|
+
* Para reads não-sensíveis, continue usando `safeServerAction` direto.
|
|
22
|
+
*/
|
|
23
|
+
export async function safeMutationAction<T>(
|
|
24
|
+
fn: () => Promise<T>
|
|
25
|
+
): Promise<ActionResult<T>> {
|
|
26
|
+
return safeServerAction(async () => {
|
|
27
|
+
await requireValidSession();
|
|
28
|
+
return fn();
|
|
29
|
+
});
|
|
30
|
+
}
|