@greatapps/common 1.1.24 → 1.1.26
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 +121 -0
- package/dist/components/account/ConfigurationsMyAccountModal.mjs.map +1 -0
- package/dist/components/account/ConfirmGlobalPreferencesModal.mjs +45 -0
- package/dist/components/account/ConfirmGlobalPreferencesModal.mjs.map +1 -0
- package/dist/components/account/DisableTwoFactorAuthModal.mjs +67 -0
- package/dist/components/account/DisableTwoFactorAuthModal.mjs.map +1 -0
- package/dist/components/account/TwoFactorAuthModal.mjs +190 -0
- package/dist/components/account/TwoFactorAuthModal.mjs.map +1 -0
- package/dist/components/account/constants.mjs +32 -0
- package/dist/components/account/constants.mjs.map +1 -0
- package/dist/components/account/hooks/useChangeEmailForm.mjs +53 -0
- package/dist/components/account/hooks/useChangeEmailForm.mjs.map +1 -0
- package/dist/components/account/hooks/useChangePasswordForm.mjs +47 -0
- package/dist/components/account/hooks/useChangePasswordForm.mjs.map +1 -0
- package/dist/components/account/hooks/useChangePhoneForm.mjs +64 -0
- package/dist/components/account/hooks/useChangePhoneForm.mjs.map +1 -0
- package/dist/components/account/hooks/useConfigurationsModal.mjs +33 -0
- package/dist/components/account/hooks/useConfigurationsModal.mjs.map +1 -0
- package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs +54 -0
- package/dist/components/account/hooks/useDisableTwoFactorAuthForm.mjs.map +1 -0
- package/dist/components/account/hooks/useOtpVerification.mjs +94 -0
- package/dist/components/account/hooks/useOtpVerification.mjs.map +1 -0
- package/dist/components/account/hooks/useTwoFactorAuthForm.mjs +88 -0
- package/dist/components/account/hooks/useTwoFactorAuthForm.mjs.map +1 -0
- package/dist/components/account/sections/ChangeEmailModal.mjs +180 -0
- package/dist/components/account/sections/ChangeEmailModal.mjs.map +1 -0
- package/dist/components/account/sections/ChangePasswordSection.mjs +64 -0
- package/dist/components/account/sections/ChangePasswordSection.mjs.map +1 -0
- package/dist/components/account/sections/ChangePhoneModal.mjs +182 -0
- package/dist/components/account/sections/ChangePhoneModal.mjs.map +1 -0
- package/dist/components/account/sections/MyProfileSection.mjs +312 -0
- package/dist/components/account/sections/MyProfileSection.mjs.map +1 -0
- package/dist/components/account/sections/PreferencesSection.mjs +246 -0
- package/dist/components/account/sections/PreferencesSection.mjs.map +1 -0
- package/dist/components/account/sections/SecuritySection.mjs +147 -0
- package/dist/components/account/sections/SecuritySection.mjs.map +1 -0
- package/dist/components/ui/form/ComboboxField.mjs +130 -0
- package/dist/components/ui/form/ComboboxField.mjs.map +1 -0
- package/dist/components/ui/form/FormField.mjs +103 -0
- package/dist/components/ui/form/FormField.mjs.map +1 -0
- package/dist/components/ui/form/PhoneInput.mjs +78 -0
- package/dist/components/ui/form/PhoneInput.mjs.map +1 -0
- package/dist/components/ui/form/SelectField.mjs +80 -0
- package/dist/components/ui/form/SelectField.mjs.map +1 -0
- package/dist/components/ui/form/SwitchOptionFieldWithIcon.mjs +40 -0
- package/dist/components/ui/form/SwitchOptionFieldWithIcon.mjs.map +1 -0
- package/dist/components/ui/form/TextAreaField.mjs +56 -0
- package/dist/components/ui/form/TextAreaField.mjs.map +1 -0
- package/dist/enums/AccountSectionType.mjs +11 -0
- package/dist/enums/AccountSectionType.mjs.map +1 -0
- package/dist/hooks/useCountdownTimer.mjs +29 -0
- package/dist/hooks/useCountdownTimer.mjs.map +1 -0
- package/dist/hooks/useIsMobile.mjs +18 -0
- package/dist/hooks/useIsMobile.mjs.map +1 -0
- package/dist/hooks/usePasswordVisibility.mjs +13 -0
- package/dist/hooks/usePasswordVisibility.mjs.map +1 -0
- package/dist/index.mjs +80 -0
- package/dist/index.mjs.map +1 -1
- package/dist/modules/accounts/actions/account-management.action.mjs +163 -0
- package/dist/modules/accounts/actions/account-management.action.mjs.map +1 -0
- package/dist/modules/accounts/hooks/useAccountManagement.mjs +64 -0
- package/dist/modules/accounts/hooks/useAccountManagement.mjs.map +1 -0
- package/dist/modules/accounts/services/account.service.mjs +162 -25
- package/dist/modules/accounts/services/account.service.mjs.map +1 -1
- package/dist/modules/accounts/services/two-factor.service.mjs +77 -0
- package/dist/modules/accounts/services/two-factor.service.mjs.map +1 -0
- package/dist/modules/auth/services/auth.service.mjs +7 -4
- package/dist/modules/auth/services/auth.service.mjs.map +1 -1
- package/dist/server.mjs +36 -0
- package/dist/server.mjs.map +1 -1
- package/dist/utils/browser/clipboard.mjs +36 -0
- package/dist/utils/browser/clipboard.mjs.map +1 -0
- package/dist/utils/file/index.mjs +9 -0
- package/dist/utils/file/index.mjs.map +1 -0
- package/dist/utils/format/masks.mjs +56 -0
- package/dist/utils/format/masks.mjs.map +1 -0
- package/dist/utils/intl/locales.mjs +12 -0
- package/dist/utils/intl/locales.mjs.map +1 -0
- package/dist/utils/intl/timezones.mjs +41 -0
- package/dist/utils/intl/timezones.mjs.map +1 -0
- package/dist/utils/validators/account.mjs +26 -0
- package/dist/utils/validators/account.mjs.map +1 -0
- package/dist/utils/validators/common.mjs +47 -0
- package/dist/utils/validators/common.mjs.map +1 -0
- package/package.json +5 -1
- package/src/components/account/ConfigurationsMyAccountModal.tsx +147 -0
- package/src/components/account/ConfirmGlobalPreferencesModal.tsx +66 -0
- package/src/components/account/DisableTwoFactorAuthModal.tsx +86 -0
- package/src/components/account/TwoFactorAuthModal.tsx +221 -0
- package/src/components/account/constants.ts +29 -0
- package/src/components/account/hooks/useChangeEmailForm.tsx +56 -0
- package/src/components/account/hooks/useChangePasswordForm.tsx +59 -0
- package/src/components/account/hooks/useChangePhoneForm.tsx +69 -0
- package/src/components/account/hooks/useConfigurationsModal.ts +40 -0
- package/src/components/account/hooks/useDisableTwoFactorAuthForm.tsx +69 -0
- package/src/components/account/hooks/useOtpVerification.tsx +116 -0
- package/src/components/account/hooks/useTwoFactorAuthForm.tsx +114 -0
- package/src/components/account/sections/ChangeEmailModal.tsx +224 -0
- package/src/components/account/sections/ChangePasswordSection.tsx +64 -0
- package/src/components/account/sections/ChangePhoneModal.tsx +229 -0
- package/src/components/account/sections/MyProfileSection.tsx +337 -0
- package/src/components/account/sections/PreferencesSection.tsx +277 -0
- package/src/components/account/sections/SecuritySection.tsx +160 -0
- package/src/components/ui/form/ComboboxField.tsx +154 -0
- package/src/components/ui/form/FormField.tsx +130 -0
- package/src/components/ui/form/PhoneInput.tsx +98 -0
- package/src/components/ui/form/SelectField.tsx +118 -0
- package/src/components/ui/form/SwitchOptionFieldWithIcon.tsx +47 -0
- package/src/components/ui/form/TextAreaField.tsx +70 -0
- package/src/enums/AccountSectionType.ts +6 -0
- package/src/hooks/useCountdownTimer.ts +41 -0
- package/src/hooks/useIsMobile.ts +19 -0
- package/src/hooks/usePasswordVisibility.ts +13 -0
- package/src/index.ts +70 -0
- package/src/modules/accounts/actions/account-management.action.ts +197 -0
- package/src/modules/accounts/hooks/useAccountManagement.ts +79 -0
- package/src/modules/accounts/services/account.service.ts +229 -50
- package/src/modules/accounts/services/two-factor.service.ts +98 -0
- package/src/modules/accounts/types.ts +157 -0
- package/src/modules/auth/services/auth.service.ts +9 -5
- package/src/server.ts +21 -0
- package/src/utils/browser/clipboard.ts +34 -0
- package/src/utils/file/index.ts +5 -0
- package/src/utils/format/masks.ts +52 -0
- package/src/utils/intl/locales.ts +15 -0
- package/src/utils/intl/timezones.ts +53 -0
- package/src/utils/validators/account.ts +36 -0
- package/src/utils/validators/common.ts +43 -0
|
@@ -1,31 +1,13 @@
|
|
|
1
1
|
import "server-only";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { api } from "../../../infra/api/client";
|
|
3
|
+
import { ApiError } from "../../../infra/api/types";
|
|
4
|
+
import { buildQueryParams } from "../../../infra/utils/params";
|
|
5
|
+
import { getUserContext } from "../../auth/utils/get-user-context";
|
|
6
|
+
import { fileToBase64 } from "../../../utils/file/index";
|
|
5
7
|
class AccountService {
|
|
6
|
-
/**
|
|
7
|
-
* Obtém o contexto do usuário a partir do JWT
|
|
8
|
-
* @private
|
|
9
|
-
*/
|
|
10
|
-
async getUserContext() {
|
|
11
|
-
const cookieStore = await cookies();
|
|
12
|
-
const token = cookieStore.get("greatapps")?.value;
|
|
13
|
-
if (!token) {
|
|
14
|
-
throw new ApiError("Usu\xE1rio n\xE3o autenticado", "NOT_AUTHENTICATED", 401);
|
|
15
|
-
}
|
|
16
|
-
try {
|
|
17
|
-
const payload = JSON.parse(atob(token.split(".")[1]));
|
|
18
|
-
return {
|
|
19
|
-
id_account: payload.id_account,
|
|
20
|
-
id_user: payload.id_user
|
|
21
|
-
};
|
|
22
|
-
} catch (error) {
|
|
23
|
-
throw new ApiError("Token inv\xE1lido", "INVALID_TOKEN", 401);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
8
|
async findCurrentAccount() {
|
|
27
|
-
const { id_account } = await
|
|
28
|
-
const response = await
|
|
9
|
+
const { id_account } = await getUserContext();
|
|
10
|
+
const response = await api.apps.get(`/accounts/${id_account}`);
|
|
29
11
|
if (response.status === 0 || !response.data?.[0]) {
|
|
30
12
|
throw new ApiError(
|
|
31
13
|
response.message || "Erro ao buscar dados da conta",
|
|
@@ -35,6 +17,161 @@ class AccountService {
|
|
|
35
17
|
}
|
|
36
18
|
return response.data[0];
|
|
37
19
|
}
|
|
20
|
+
async listAccountUsers(params) {
|
|
21
|
+
const { id_account } = await getUserContext();
|
|
22
|
+
const queryParams = buildQueryParams(params);
|
|
23
|
+
const endpoint = `/accounts/${id_account}/users?${queryParams}`;
|
|
24
|
+
const response = await api.apps.get(endpoint);
|
|
25
|
+
if (response.status === 0) {
|
|
26
|
+
throw new ApiError(
|
|
27
|
+
response.message || "Erro ao listar usu\xE1rios",
|
|
28
|
+
"LIST_ACCOUNT_USERS_FAILED",
|
|
29
|
+
400
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
users: response.data || [],
|
|
34
|
+
total: response.total || 0
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
async changeUserPhoto(userId, photo) {
|
|
38
|
+
const { id_account } = await getUserContext();
|
|
39
|
+
const base64 = await fileToBase64(photo);
|
|
40
|
+
const response = await api.apps.put(
|
|
41
|
+
`/accounts/${id_account}/users/${userId}/file/photo`,
|
|
42
|
+
{ file: base64 }
|
|
43
|
+
);
|
|
44
|
+
if (response.status === 0) {
|
|
45
|
+
throw new ApiError(
|
|
46
|
+
response.message || "Erro ao mudar foto do usu\xE1rio",
|
|
47
|
+
"CHANGE_USER_PHOTO_FAILED",
|
|
48
|
+
400
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
return response;
|
|
52
|
+
}
|
|
53
|
+
async deleteAccountUser(userId) {
|
|
54
|
+
const { id_account } = await getUserContext();
|
|
55
|
+
const response = await api.apps.delete(
|
|
56
|
+
`/accounts/${id_account}/users/${userId}`
|
|
57
|
+
);
|
|
58
|
+
if (response.status === 0) {
|
|
59
|
+
throw new ApiError(response.message || "Erro ao deletar usu\xE1rio", "DELETE_USER_FAILED", 400);
|
|
60
|
+
}
|
|
61
|
+
return response;
|
|
62
|
+
}
|
|
63
|
+
async deleteAccount() {
|
|
64
|
+
const { id_account } = await getUserContext();
|
|
65
|
+
const response = await api.apps.delete(`/accounts/${id_account}`);
|
|
66
|
+
if (response.status === 0) {
|
|
67
|
+
throw new ApiError(response.message || "Erro ao deletar conta", "DELETE_ACCOUNT_FAILED", 400);
|
|
68
|
+
}
|
|
69
|
+
return response;
|
|
70
|
+
}
|
|
71
|
+
async createAccountUser(user) {
|
|
72
|
+
const { id_account } = await getUserContext();
|
|
73
|
+
const response = await api.apps.post(
|
|
74
|
+
`/accounts/${id_account}/users`,
|
|
75
|
+
{
|
|
76
|
+
...user,
|
|
77
|
+
photo: user.photo ? await fileToBase64(user.photo) : null
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
if (response.status === 0) {
|
|
81
|
+
throw new ApiError(response.message || "Erro ao criar usu\xE1rio", "CREATE_USER_FAILED", 400);
|
|
82
|
+
}
|
|
83
|
+
return response;
|
|
84
|
+
}
|
|
85
|
+
async resolvePhotoField(user) {
|
|
86
|
+
if (user.photo === void 0) return {};
|
|
87
|
+
const photo = user.photo != null && typeof user.photo !== "string" ? await fileToBase64(user.photo) : user.photo;
|
|
88
|
+
return { photo };
|
|
89
|
+
}
|
|
90
|
+
async updateAccountUser(user) {
|
|
91
|
+
const { id_account, id_user } = await getUserContext();
|
|
92
|
+
const response = await api.apps.put(
|
|
93
|
+
`/accounts/${id_account}/users/${id_user}`,
|
|
94
|
+
{ ...user, ...await this.resolvePhotoField(user) }
|
|
95
|
+
);
|
|
96
|
+
if (response.status === 0) {
|
|
97
|
+
throw new ApiError(
|
|
98
|
+
response.message || "Erro ao atualizar usu\xE1rio",
|
|
99
|
+
"UPDATE_USER_FAILED",
|
|
100
|
+
400
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return response;
|
|
104
|
+
}
|
|
105
|
+
async updateAccountUserById(userId, user) {
|
|
106
|
+
const { id_account } = await getUserContext();
|
|
107
|
+
const response = await api.apps.put(
|
|
108
|
+
`/accounts/${id_account}/users/${userId}`,
|
|
109
|
+
{ ...user, ...await this.resolvePhotoField(user) }
|
|
110
|
+
);
|
|
111
|
+
if (response.status === 0) {
|
|
112
|
+
throw new ApiError(
|
|
113
|
+
response.message || "Erro ao atualizar usu\xE1rio",
|
|
114
|
+
"UPDATE_USER_FAILED",
|
|
115
|
+
400
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return response;
|
|
119
|
+
}
|
|
120
|
+
async updateAccount(data) {
|
|
121
|
+
const { id_account } = await getUserContext();
|
|
122
|
+
const response = await api.apps.put(`/accounts/${id_account}`, data);
|
|
123
|
+
if (response.status === 0) {
|
|
124
|
+
throw new ApiError(
|
|
125
|
+
response.message || "Erro ao atualizar conta",
|
|
126
|
+
"UPDATE_ACCOUNT_FAILED",
|
|
127
|
+
400
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
return response;
|
|
131
|
+
}
|
|
132
|
+
async requestContactReset(type, newContact) {
|
|
133
|
+
const { id_account, id_user } = await getUserContext();
|
|
134
|
+
const response = await api.apps.post(
|
|
135
|
+
`/accounts/${id_account}/users/${id_user}/resetContact/request`,
|
|
136
|
+
{ type, newContact }
|
|
137
|
+
);
|
|
138
|
+
if (response.status === 0) {
|
|
139
|
+
throw new ApiError(
|
|
140
|
+
response.message || "Erro ao solicitar altera\xE7\xE3o",
|
|
141
|
+
"REQUEST_CONTACT_RESET_FAILED",
|
|
142
|
+
400
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
async confirmContactReset(type, token, newContact) {
|
|
147
|
+
const { id_account, id_user } = await getUserContext();
|
|
148
|
+
const response = await api.apps.post(
|
|
149
|
+
`/accounts/${id_account}/users/${id_user}/resetContact/confirm`,
|
|
150
|
+
{ type, token, newContact }
|
|
151
|
+
);
|
|
152
|
+
if (response.status === 0) {
|
|
153
|
+
throw new ApiError(
|
|
154
|
+
response.message || "C\xF3digo inv\xE1lido ou expirado",
|
|
155
|
+
"CONFIRM_CONTACT_RESET_FAILED",
|
|
156
|
+
400
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
async changePassword(data) {
|
|
161
|
+
const { id_account, id_user } = await getUserContext();
|
|
162
|
+
const response = await api.apps.put(
|
|
163
|
+
`/accounts/${id_account}/users/${id_user}/action/changePassword`,
|
|
164
|
+
data
|
|
165
|
+
);
|
|
166
|
+
if (response.status === 0) {
|
|
167
|
+
throw new ApiError(
|
|
168
|
+
response.message || "Erro ao alterar senha",
|
|
169
|
+
"CHANGE_PASSWORD_FAILED",
|
|
170
|
+
400
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
return response;
|
|
174
|
+
}
|
|
38
175
|
}
|
|
39
176
|
const accountService = new AccountService();
|
|
40
177
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/accounts/services/account.service.ts"],"sourcesContent":["import 'server-only';\n\nimport { cookies } from 'next/headers';\nimport { apiClient } from '@greatapps/common/server';\nimport { ApiError, JWTPayload, User, buildQueryParams } from '@greatapps/common';\nimport { Account, AccountUsersPaginationParams, GetAccountDataResponse, ListAccountUsersResponse } from '../types';\n\n/**\n * Service para gerenciar usuários da conta\n * Executado apenas no servidor (server-only)\n */\nclass AccountService {\n /**\n * Obtém o contexto do usuário a partir do JWT\n * @private\n */\n async getUserContext(): Promise<{\n id_account: number;\n id_user: number;\n }> {\n const cookieStore = await cookies();\n const token = cookieStore.get('greatapps')?.value;\n\n if (!token) {\n throw new ApiError('Usuário não autenticado', 'NOT_AUTHENTICATED', 401);\n }\n\n try {\n const payload = JSON.parse(atob(token.split('.')[1])) as JWTPayload;\n\n return {\n id_account: payload.id_account,\n id_user: payload.id_user,\n };\n } catch (error) {\n throw new ApiError('Token inválido', 'INVALID_TOKEN', 401);\n }\n }\n\n async findCurrentAccount(): Promise<Account> {\n const { id_account } = await this.getUserContext();\n\n const response = await apiClient.get<GetAccountDataResponse>(`/accounts/${id_account}`);\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\nexport const accountService = new AccountService();\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,eAAe;AACxB,SAAS,iBAAiB;AAC1B,SAAS,gBAAoD;AAO7D,MAAM,eAAe;AAAA;AAAA;AAAA;AAAA;AAAA,EAKjB,MAAM,iBAGH;AACC,UAAM,cAAc,MAAM,QAAQ;AAClC,UAAM,QAAQ,YAAY,IAAI,WAAW,GAAG;AAE5C,QAAI,CAAC,OAAO;AACR,YAAM,IAAI,SAAS,iCAA2B,qBAAqB,GAAG;AAAA,IAC1E;AAEA,QAAI;AACA,YAAM,UAAU,KAAK,MAAM,KAAK,MAAM,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC;AAEpD,aAAO;AAAA,QACH,YAAY,QAAQ;AAAA,QACpB,SAAS,QAAQ;AAAA,MACrB;AAAA,IACJ,SAAS,OAAO;AACZ,YAAM,IAAI,SAAS,qBAAkB,iBAAiB,GAAG;AAAA,IAC7D;AAAA,EACJ;AAAA,EAEA,MAAM,qBAAuC;AACzC,UAAM,EAAE,WAAW,IAAI,MAAM,KAAK,eAAe;AAEjD,UAAM,WAAW,MAAM,UAAU,IAA4B,aAAa,UAAU,EAAE;AAEtF,QAAI,SAAS,WAAW,KAAK,CAAC,SAAS,OAAO,CAAC,GAAG;AAC9C,YAAM,IAAI;AAAA,QACN,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACJ;AAAA,IACJ;AAEA,WAAO,SAAS,KAAK,CAAC;AAAA,EAC1B;AACJ;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 {\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(): Promise<Account> {\n const { id_account } = await getUserContext();\n const response = await api.apps.get<GetAccountDataResponse>(`/accounts/${id_account}`);\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): 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 }\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): 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 }\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;AAmB7B,MAAM,eAAe;AAAA,EACnB,MAAM,qBAAuC;AAC3C,UAAM,EAAE,WAAW,IAAI,MAAM,eAAe;AAC5C,UAAM,WAAW,MAAM,IAAI,KAAK,IAA4B,aAAa,UAAU,EAAE;AAErF,QAAI,SAAS,WAAW,KAAK,CAAC,SAAS,OAAO,CAAC,GAAG;AAChD,YAAM,IAAI;AAAA,QACR,SAAS,WAAW;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAEA,WAAO,SAAS,KAAK,CAAC;AAAA,EACxB;AAAA,EAEA,MAAM,iBAAiB,QAAgD;AACrE,UAAM,EAAE,WAAW,IAAI,MAAM,eAAe;AAC5C,UAAM,cAAc,iBAAiB,MAAM;AAC3C,UAAM,WAAW,aAAa,UAAU,UAAU,WAAW;AAC7D,UAAM,WAAW,MAAM,IAAI,KAAK,IAA8B,QAAQ;AAEtE,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI;AAAA,QACR,SAAS,WAAW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BAAiB,IAAI,eAAe;","names":[]}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import "server-only";
|
|
2
|
+
import { ApiError } from "../../../infra/api/types";
|
|
3
|
+
import { getUserContext } from "../../auth/utils/get-user-context";
|
|
4
|
+
import { findWhitelabel } from "../../whitelabel/actions/find-whitelabel.action";
|
|
5
|
+
const TWO_FA_BASE_URL = process.env.R2_2FA_URL || "https://r2-2fa.greatapps.dev.br";
|
|
6
|
+
class TwoFactorService {
|
|
7
|
+
async request(path, body) {
|
|
8
|
+
const { id, token } = await findWhitelabel();
|
|
9
|
+
const { id_account, id_user } = await getUserContext();
|
|
10
|
+
const url = `${TWO_FA_BASE_URL}/v1/${id}/account/${id_account}/users/${id_user}/2fa/${path}`;
|
|
11
|
+
const response = await fetch(url, {
|
|
12
|
+
method: "POST",
|
|
13
|
+
headers: {
|
|
14
|
+
"Content-Type": "application/json",
|
|
15
|
+
authorization: token
|
|
16
|
+
},
|
|
17
|
+
body: body ? JSON.stringify(body) : void 0
|
|
18
|
+
});
|
|
19
|
+
if (!response.ok) {
|
|
20
|
+
const errorData = await response.json().catch(() => ({}));
|
|
21
|
+
throw new ApiError(
|
|
22
|
+
errorData.message || `HTTP error ${response.status}`,
|
|
23
|
+
"HTTP_ERROR",
|
|
24
|
+
response.status
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return response.json();
|
|
28
|
+
}
|
|
29
|
+
async generate() {
|
|
30
|
+
const response = await this.request("generate");
|
|
31
|
+
if (response.status === 0) {
|
|
32
|
+
throw new ApiError(response.message || "Erro ao gerar QR Code", "GENERATE_2FA_FAILED", 400);
|
|
33
|
+
}
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
async confirm(code) {
|
|
37
|
+
const response = await this.request("confirm", { code });
|
|
38
|
+
if (response.status === 0) {
|
|
39
|
+
throw new ApiError(response.message || "C\xF3digo inv\xE1lido", "CONFIRM_2FA_FAILED", 400);
|
|
40
|
+
}
|
|
41
|
+
return response;
|
|
42
|
+
}
|
|
43
|
+
async verify(code) {
|
|
44
|
+
const response = await this.request("verify", { code });
|
|
45
|
+
if (response.status === 0) {
|
|
46
|
+
throw new ApiError(response.message || "C\xF3digo inv\xE1lido", "VERIFY_2FA_FAILED", 400);
|
|
47
|
+
}
|
|
48
|
+
return response;
|
|
49
|
+
}
|
|
50
|
+
async disable() {
|
|
51
|
+
const { id, token } = await findWhitelabel();
|
|
52
|
+
const { id_account, id_user } = await getUserContext();
|
|
53
|
+
const url = `${TWO_FA_BASE_URL}/v1/${id}/account/${id_account}/users/${id_user}/2fa`;
|
|
54
|
+
const response = await fetch(url, {
|
|
55
|
+
method: "DELETE",
|
|
56
|
+
headers: { authorization: token }
|
|
57
|
+
});
|
|
58
|
+
if (!response.ok) {
|
|
59
|
+
const errorData = await response.json().catch(() => ({}));
|
|
60
|
+
throw new ApiError(
|
|
61
|
+
errorData.message || `HTTP error ${response.status}`,
|
|
62
|
+
"HTTP_ERROR",
|
|
63
|
+
response.status
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
const data = await response.json();
|
|
67
|
+
if (data.status === 0) {
|
|
68
|
+
throw new ApiError(data.message || "Erro ao desabilitar 2FA", "DISABLE_2FA_FAILED", 400);
|
|
69
|
+
}
|
|
70
|
+
return data;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const twoFactorService = new TwoFactorService();
|
|
74
|
+
export {
|
|
75
|
+
twoFactorService
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=two-factor.service.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/modules/accounts/services/two-factor.service.ts"],"sourcesContent":["import 'server-only';\r\n\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { getUserContext } from '../../auth/utils/get-user-context';\r\nimport { findWhitelabel } from '../../whitelabel/actions/find-whitelabel.action';\r\nimport type { TwoFactorActionResponse, TwoFactorGenerateResponse } from '../types';\r\n\r\nconst TWO_FA_BASE_URL = process.env.R2_2FA_URL || 'https://r2-2fa.greatapps.dev.br';\r\n\r\nclass TwoFactorService {\r\n private async request<T>(path: string, body?: object): Promise<T> {\r\n const { id, token } = await findWhitelabel();\r\n const { id_account, id_user } = await getUserContext();\r\n\r\n const url = `${TWO_FA_BASE_URL}/v1/${id}/account/${id_account}/users/${id_user}/2fa/${path}`;\r\n\r\n const response = await fetch(url, {\r\n method: 'POST',\r\n headers: {\r\n 'Content-Type': 'application/json',\r\n authorization: token,\r\n },\r\n body: body ? JSON.stringify(body) : undefined,\r\n });\r\n\r\n if (!response.ok) {\r\n const errorData = await response.json().catch(() => ({})) as Record<string, unknown>;\r\n throw new ApiError(\r\n (errorData.message as string) || `HTTP error ${response.status}`,\r\n 'HTTP_ERROR',\r\n response.status\r\n );\r\n }\r\n\r\n return response.json() as Promise<T>;\r\n }\r\n\r\n async generate(): Promise<TwoFactorGenerateResponse> {\r\n const response = await this.request<TwoFactorGenerateResponse>('generate');\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'Erro ao gerar QR Code', 'GENERATE_2FA_FAILED', 400);\r\n }\r\n\r\n return response;\r\n }\r\n\r\n async confirm(code: string): Promise<TwoFactorActionResponse> {\r\n const response = await this.request<TwoFactorActionResponse>('confirm', { code });\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'Código inválido', 'CONFIRM_2FA_FAILED', 400);\r\n }\r\n\r\n return response;\r\n }\r\n\r\n async verify(code: string): Promise<TwoFactorActionResponse> {\r\n const response = await this.request<TwoFactorActionResponse>('verify', { code });\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'Código inválido', 'VERIFY_2FA_FAILED', 400);\r\n }\r\n\r\n return response;\r\n }\r\n\r\n async disable(): Promise<TwoFactorActionResponse> {\r\n const { id, token } = await findWhitelabel();\r\n const { id_account, id_user } = await getUserContext();\r\n\r\n const url = `${TWO_FA_BASE_URL}/v1/${id}/account/${id_account}/users/${id_user}/2fa`;\r\n\r\n const response = await fetch(url, {\r\n method: 'DELETE',\r\n headers: { authorization: token },\r\n });\r\n\r\n if (!response.ok) {\r\n const errorData = await response.json().catch(() => ({})) as Record<string, unknown>;\r\n throw new ApiError(\r\n (errorData.message as string) || `HTTP error ${response.status}`,\r\n 'HTTP_ERROR',\r\n response.status\r\n );\r\n }\r\n\r\n const data = await response.json() as TwoFactorActionResponse;\r\n\r\n if (data.status === 0) {\r\n throw new ApiError(data.message || 'Erro ao desabilitar 2FA', 'DISABLE_2FA_FAILED', 400);\r\n }\r\n\r\n return data;\r\n }\r\n}\r\n\r\nexport const twoFactorService = new TwoFactorService();\r\n"],"mappings":"AAAA,OAAO;AAEP,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAG/B,MAAM,kBAAkB,QAAQ,IAAI,cAAc;AAElD,MAAM,iBAAiB;AAAA,EACrB,MAAc,QAAW,MAAc,MAA2B;AAChE,UAAM,EAAE,IAAI,MAAM,IAAI,MAAM,eAAe;AAC3C,UAAM,EAAE,YAAY,QAAQ,IAAI,MAAM,eAAe;AAErD,UAAM,MAAM,GAAG,eAAe,OAAO,EAAE,YAAY,UAAU,UAAU,OAAO,QAAQ,IAAI;AAE1F,UAAM,WAAW,MAAM,MAAM,KAAK;AAAA,MAChC,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,eAAe;AAAA,MACjB;AAAA,MACA,MAAM,OAAO,KAAK,UAAU,IAAI,IAAI;AAAA,IACtC,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,YAAY,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AACxD,YAAM,IAAI;AAAA,QACP,UAAU,WAAsB,cAAc,SAAS,MAAM;AAAA,QAC9D;AAAA,QACA,SAAS;AAAA,MACX;AAAA,IACF;AAEA,WAAO,SAAS,KAAK;AAAA,EACvB;AAAA,EAEA,MAAM,WAA+C;AACnD,UAAM,WAAW,M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F;AAEA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,mBAAmB,IAAI,iBAAiB;","names":[]}
|
|
@@ -107,11 +107,14 @@ class AuthService {
|
|
|
107
107
|
agent: clientInfo.agent,
|
|
108
108
|
cookie
|
|
109
109
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
try {
|
|
111
|
+
const response = await apiClient.post("/auth/logout", payload);
|
|
112
|
+
if (response.status === 0) {
|
|
113
|
+
throw new ApiError(response.message || "Erro ao realizar logout", "LOGOUT_FAILED", 400);
|
|
114
|
+
}
|
|
115
|
+
} finally {
|
|
116
|
+
await removeAuthCookie();
|
|
113
117
|
}
|
|
114
|
-
await removeAuthCookie();
|
|
115
118
|
return {
|
|
116
119
|
success: true
|
|
117
120
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/modules/auth/services/auth.service.ts"],"sourcesContent":["\r\nimport { cookies } from 'next/headers';\r\n\r\nimport { apiClient } from '../../../infra/api/client';\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { User } from '../../users/schema';\r\nimport {\r\n ClientInfo,\r\n ForgotPasswordRequest,\r\n ForgotPasswordResponse,\r\n GeoLocation,\r\n LoginApiResponse,\r\n LoginRequest,\r\n LoginResponse,\r\n LogoutApiResponse,\r\n LogoutRequest,\r\n LogoutResponse,\r\n RegisterApiRequest,\r\n RegisterApiResponse,\r\n RegisterRequest,\r\n RegisterResponse,\r\n ResendVerificationRequest,\r\n ResendVerificationResponse,\r\n ResetPasswordRequest,\r\n ResetPasswordResponse,\r\n SessionKeepRequest,\r\n SessionKeepResponse,\r\n VerifyEmailRequest,\r\n VerifyEmailResponse,\r\n} from '../schema';\r\n\r\nconst AUTH_COOKIE_NAME = 'greatapps';\r\nconst COOKIE_MAX_AGE = 60 * 60 * 24 * 30;\r\n\r\nasync function setAuthCookie(token: string): Promise<void> {\r\n const cookieStore = await cookies();\r\n cookieStore.set(AUTH_COOKIE_NAME, token, {\r\n httpOnly: true,\r\n secure: process.env.NODE_ENV === 'production',\r\n sameSite: 'lax',\r\n maxAge: COOKIE_MAX_AGE,\r\n path: '/',\r\n domain: process.env.DOMAIN_COOKIE\r\n });\r\n}\r\n\r\nasync function removeAuthCookie(): Promise<void> {\r\n const cookieStore = await cookies();\r\n cookieStore.delete(AUTH_COOKIE_NAME);\r\n}\r\n\r\nasync function getAuthCookie(): Promise<string | undefined> {\r\n const cookieStore = await cookies();\r\n return cookieStore.get(AUTH_COOKIE_NAME)?.value;\r\n}\r\n\r\nclass AuthService {\r\n async login(credentials: LoginRequest, clientInfo: ClientInfo): Promise<LoginResponse> {\r\n const response = await apiClient.post<LoginApiResponse>('/auth/login', {\r\n email: credentials.email,\r\n password: credentials.password,\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n });\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'E-mail ou senha incorretos', 'LOGIN_FAILED', 401);\r\n }\r\n\r\n if (!response.cookie) {\r\n throw new ApiError('Resposta de autenticação inválida', 'INVALID_RESPONSE', 500);\r\n }\r\n\r\n await setAuthCookie(response.cookie);\r\n\r\n // O usuário completo será carregado pelo AuthProvider via getUserDataAction\r\n return {\r\n user: {} as User, // Placeholder, será preenchido pelo AuthProvider\r\n accessToken: response.cookie,\r\n refreshToken: '',\r\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\r\n };\r\n }\r\n\r\n async register(data: RegisterRequest): Promise<RegisterResponse> {\r\n const today = new Date();\r\n const trialEndDate = new Date(today);\r\n trialEndDate.setDate(today.getDate() + 7); // 7 dias de trial\r\n\r\n const payload: RegisterApiRequest = {\r\n name: data.accountName,\r\n bussiness_type: data.businessType,\r\n language: 'pt-br',\r\n timezone: 'America/Sao_Paulo',\r\n currency: 'BRL',\r\n user: {\r\n id_api: '',\r\n name: data.name,\r\n last_name: data.lastName || '',\r\n rg: data.rg || '',\r\n cpf: data.cpf || '',\r\n gender: data.gender,\r\n email: data.email,\r\n phone: data.phone,\r\n password: data.password,\r\n profile: 'owner',\r\n language: 'pt-br',\r\n },\r\n subscription: {\r\n type: 'trial',\r\n id_cupom: '',\r\n id_plan: 1,\r\n due_date: trialEndDate.toISOString().split('T')[0],\r\n id_product: 1,\r\n },\r\n };\r\n\r\n const response = await apiClient.post<RegisterApiResponse>('/accounts', payload);\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'Erro ao criar conta', 'REGISTER_FAILED', 400);\r\n }\r\n\r\n if (!response.data || response.data.length === 0) {\r\n throw new ApiError('Resposta de registro inválida', 'INVALID_RESPONSE', 500);\r\n }\r\n\r\n const accountData = response.data[0];\r\n\r\n // Retornar sem token pois o registro não retorna cookie diretamente\r\n // O usuário precisará fazer login após o registro\r\n // O usuário completo será carregado após o login\r\n return {\r\n user: {} as User, // Placeholder, será preenchido após login\r\n accessToken: '',\r\n refreshToken: '',\r\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\r\n requiresEmailVerification: !accountData.verified,\r\n };\r\n }\r\n\r\n async logout(clientInfo: ClientInfo): Promise<LogoutResponse> {\r\n const cookie = await getAuthCookie();\r\n\r\n if (!cookie) {\r\n throw new ApiError('Usuário não autenticado', 'NOT_AUTHENTICATED', 401);\r\n }\r\n\r\n const payload: LogoutRequest = {\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n cookie,\r\n };\r\n\r\n const response = await apiClient.post<LogoutApiResponse>('/auth/logout', payload);\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'Erro ao realizar logout', 'LOGOUT_FAILED', 400);\r\n }\r\n\r\n await removeAuthCookie();\r\n\r\n return {\r\n success: true,\r\n };\r\n }\r\n\r\n async forgotPassword(_data: ForgotPasswordRequest): Promise<ForgotPasswordResponse> {\r\n throw new ApiError('Recuperação de senha não implementada', 'NOT_IMPLEMENTED', 501);\r\n }\r\n\r\n async resetPassword(_data: ResetPasswordRequest): Promise<ResetPasswordResponse> {\r\n throw new ApiError('Redefinição de senha não implementada', 'NOT_IMPLEMENTED', 501);\r\n }\r\n\r\n async verifyEmail(_data: VerifyEmailRequest): Promise<VerifyEmailResponse> {\r\n throw new ApiError('Verificação de email não implementada', 'NOT_IMPLEMENTED', 501);\r\n }\r\n\r\n async resendVerification(_data: ResendVerificationRequest): Promise<ResendVerificationResponse> {\r\n throw new ApiError('Reenvio de verificação não implementado', 'NOT_IMPLEMENTED', 501);\r\n }\r\n\r\n async validateSession(clientInfo: ClientInfo): Promise<boolean> {\r\n const cookie = await getAuthCookie();\r\n\r\n if (!cookie) {\r\n return false;\r\n }\r\n\r\n try {\r\n const payload: SessionKeepRequest = {\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n cookie,\r\n };\r\n\r\n const response = await apiClient.post<SessionKeepResponse>('/auth/keep', payload);\r\n\r\n return response.status === 1;\r\n } catch (error) {\r\n console.error('[AuthService] validateSession error', error);\r\n return false;\r\n }\r\n }\r\n\r\n async isAuthenticated(): Promise<boolean> {\r\n const token = await getAuthCookie();\r\n return !!token;\r\n }\r\n\r\n async getToken(): Promise<string | undefined> {\r\n return getAuthCookie();\r\n }\r\n}\r\n\r\nexport const authService = new AuthService();\r\n\r\nexport type { ClientInfo, GeoLocation };\r\n"],"mappings":"AACA,SAAS,eAAe;AAExB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AA2BzB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB,KAAK,KAAK,KAAK;AAEtC,eAAe,cAAc,OAA8B;AACzD,QAAM,cAAc,MAAM,QAAQ;AAClC,cAAY,IAAI,kBAAkB,OAAO;AAAA,IACvC,UAAU;AAAA,IACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,MAAM;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r\nimport { cookies } from 'next/headers';\r\n\r\nimport { apiClient } from '../../../infra/api/client';\r\nimport { ApiError } from '../../../infra/api/types';\r\nimport { User } from '../../users/schema';\r\nimport {\r\n ClientInfo,\r\n ForgotPasswordRequest,\r\n ForgotPasswordResponse,\r\n GeoLocation,\r\n LoginApiResponse,\r\n LoginRequest,\r\n LoginResponse,\r\n LogoutApiResponse,\r\n LogoutRequest,\r\n LogoutResponse,\r\n RegisterApiRequest,\r\n RegisterApiResponse,\r\n RegisterRequest,\r\n RegisterResponse,\r\n ResendVerificationRequest,\r\n ResendVerificationResponse,\r\n ResetPasswordRequest,\r\n ResetPasswordResponse,\r\n SessionKeepRequest,\r\n SessionKeepResponse,\r\n VerifyEmailRequest,\r\n VerifyEmailResponse,\r\n} from '../schema';\r\n\r\nconst AUTH_COOKIE_NAME = 'greatapps';\r\nconst COOKIE_MAX_AGE = 60 * 60 * 24 * 30;\r\n\r\nasync function setAuthCookie(token: string): Promise<void> {\r\n const cookieStore = await cookies();\r\n cookieStore.set(AUTH_COOKIE_NAME, token, {\r\n httpOnly: true,\r\n secure: process.env.NODE_ENV === 'production',\r\n sameSite: 'lax',\r\n maxAge: COOKIE_MAX_AGE,\r\n path: '/',\r\n domain: process.env.DOMAIN_COOKIE\r\n });\r\n}\r\n\r\nasync function removeAuthCookie(): Promise<void> {\r\n const cookieStore = await cookies();\r\n cookieStore.delete(AUTH_COOKIE_NAME);\r\n}\r\n\r\nasync function getAuthCookie(): Promise<string | undefined> {\r\n const cookieStore = await cookies();\r\n return cookieStore.get(AUTH_COOKIE_NAME)?.value;\r\n}\r\n\r\nclass AuthService {\r\n async login(credentials: LoginRequest, clientInfo: ClientInfo): Promise<LoginResponse> {\r\n const response = await apiClient.post<LoginApiResponse>('/auth/login', {\r\n email: credentials.email,\r\n password: credentials.password,\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n });\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'E-mail ou senha incorretos', 'LOGIN_FAILED', 401);\r\n }\r\n\r\n if (!response.cookie) {\r\n throw new ApiError('Resposta de autenticação inválida', 'INVALID_RESPONSE', 500);\r\n }\r\n\r\n await setAuthCookie(response.cookie);\r\n\r\n // O usuário completo será carregado pelo AuthProvider via getUserDataAction\r\n return {\r\n user: {} as User, // Placeholder, será preenchido pelo AuthProvider\r\n accessToken: response.cookie,\r\n refreshToken: '',\r\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\r\n };\r\n }\r\n\r\n async register(data: RegisterRequest): Promise<RegisterResponse> {\r\n const today = new Date();\r\n const trialEndDate = new Date(today);\r\n trialEndDate.setDate(today.getDate() + 7); // 7 dias de trial\r\n\r\n const payload: RegisterApiRequest = {\r\n name: data.accountName,\r\n bussiness_type: data.businessType,\r\n language: 'pt-br',\r\n timezone: 'America/Sao_Paulo',\r\n currency: 'BRL',\r\n user: {\r\n id_api: '',\r\n name: data.name,\r\n last_name: data.lastName || '',\r\n rg: data.rg || '',\r\n cpf: data.cpf || '',\r\n gender: data.gender,\r\n email: data.email,\r\n phone: data.phone,\r\n password: data.password,\r\n profile: 'owner',\r\n language: 'pt-br',\r\n },\r\n subscription: {\r\n type: 'trial',\r\n id_cupom: '',\r\n id_plan: 1,\r\n due_date: trialEndDate.toISOString().split('T')[0],\r\n id_product: 1,\r\n },\r\n };\r\n\r\n const response = await apiClient.post<RegisterApiResponse>('/accounts', payload);\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'Erro ao criar conta', 'REGISTER_FAILED', 400);\r\n }\r\n\r\n if (!response.data || response.data.length === 0) {\r\n throw new ApiError('Resposta de registro inválida', 'INVALID_RESPONSE', 500);\r\n }\r\n\r\n const accountData = response.data[0];\r\n\r\n // Retornar sem token pois o registro não retorna cookie diretamente\r\n // O usuário precisará fazer login após o registro\r\n // O usuário completo será carregado após o login\r\n return {\r\n user: {} as User, // Placeholder, será preenchido após login\r\n accessToken: '',\r\n refreshToken: '',\r\n expiresAt: new Date(Date.now() + COOKIE_MAX_AGE * 1000).toISOString(),\r\n requiresEmailVerification: !accountData.verified,\r\n };\r\n }\r\n\r\n async logout(clientInfo: ClientInfo): Promise<LogoutResponse> {\r\n const cookie = await getAuthCookie();\r\n\r\n\r\n if (!cookie) {\r\n throw new ApiError('Usuário não autenticado', 'NOT_AUTHENTICATED', 401);\r\n }\r\n\r\n\r\n const payload: LogoutRequest = {\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n cookie,\r\n };\r\n\r\n try {\r\n const response = await apiClient.post<LogoutApiResponse>('/auth/logout', payload);\r\n\r\n if (response.status === 0) {\r\n throw new ApiError(response.message || 'Erro ao realizar logout', 'LOGOUT_FAILED', 400);\r\n }\r\n } finally {\r\n await removeAuthCookie();\r\n }\r\n\r\n return {\r\n success: true,\r\n };\r\n }\r\n\r\n async forgotPassword(_data: ForgotPasswordRequest): Promise<ForgotPasswordResponse> {\r\n throw new ApiError('Recuperação de senha não implementada', 'NOT_IMPLEMENTED', 501);\r\n }\r\n\r\n async resetPassword(_data: ResetPasswordRequest): Promise<ResetPasswordResponse> {\r\n throw new ApiError('Redefinição de senha não implementada', 'NOT_IMPLEMENTED', 501);\r\n }\r\n\r\n async verifyEmail(_data: VerifyEmailRequest): Promise<VerifyEmailResponse> {\r\n throw new ApiError('Verificação de email não implementada', 'NOT_IMPLEMENTED', 501);\r\n }\r\n\r\n async resendVerification(_data: ResendVerificationRequest): Promise<ResendVerificationResponse> {\r\n throw new ApiError('Reenvio de verificação não implementado', 'NOT_IMPLEMENTED', 501);\r\n }\r\n\r\n async validateSession(clientInfo: ClientInfo): Promise<boolean> {\r\n const cookie = await getAuthCookie();\r\n\r\n if (!cookie) {\r\n return false;\r\n }\r\n\r\n try {\r\n const payload: SessionKeepRequest = {\r\n location: clientInfo.location,\r\n ip: clientInfo.ip,\r\n timezone: clientInfo.timezone,\r\n agent: clientInfo.agent,\r\n cookie,\r\n };\r\n\r\n const response = await apiClient.post<SessionKeepResponse>('/auth/keep', payload);\r\n\r\n return response.status === 1;\r\n } catch (error) {\r\n console.error('[AuthService] validateSession error', error);\r\n return false;\r\n }\r\n }\r\n\r\n async isAuthenticated(): Promise<boolean> {\r\n const token = await getAuthCookie();\r\n return !!token;\r\n }\r\n\r\n async getToken(): Promise<string | undefined> {\r\n return getAuthCookie();\r\n }\r\n}\r\n\r\nexport const authService = new AuthService();\r\n\r\nexport type { ClientInfo, GeoLocation };\r\n"],"mappings":"AACA,SAAS,eAAe;AAExB,SAAS,iBAAiB;AAC1B,SAAS,gBAAgB;AA2BzB,MAAM,mBAAmB;AACzB,MAAM,iBAAiB,KAAK,KAAK,KAAK;AAEtC,eAAe,cAAc,OAA8B;AACzD,QAAM,cAAc,MAAM,QAAQ;AAClC,cAAY,IAAI,kBAAkB,OAAO;AAAA,IACvC,UAAU;AAAA,IACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,QAAQ;AAAA,IACR,MAAM;AAAA,IACN,QAAQ,QAAQ,IAAI;AAAA,EACtB,CAAC;AACH;AAEA,eAAe,mBAAkC;AAC/C,QAAM,cAAc,MAAM,QAAQ;AAClC,cAAY,OAAO,gBAAgB;AACrC;AAEA,eAAe,gBAA6C;AAC1D,QAAM,cAAc,MAAM,QAAQ;AAClC,SAAO,YAAY,IAAI,gBAAgB,GAAG;AAC5C;AAEA,MAAM,YAAY;AAAA,EAChB,MAAM,MAAM,aAA2B,YAAgD;AACrF,UAAM,WAAW,MAAM,UAAU,KAAuB,eAAe;AAAA,MACrE,OAAO,YAAY;AAAA,MACnB,UAAU,YAAY;AAAA,MACtB,UAAU,WAAW;AAAA,MACrB,IAAI,WAAW;AAAA,MACf,UAAU,WAAW;AAAA,MACrB,OAAO,WAAW;AAAA,IACpB,CAAC;AAED,QAAI,SAAS,WAAW,GAAG;AACzB,YAAM,IAAI,S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,oDAA2C,mBAAmB,GAAG;AAAA,EACtF;AAAA,EAEA,MAAM,gBAAgB,YAA0C;AAC9D,UAAM,SAAS,MAAM,cAAc;AAEnC,QAAI,CAAC,QAAQ;AACX,aAAO;AAAA,IACT;AAEA,QAAI;AACF,YAAM,UAA8B;AAAA,QAClC,UAAU,WAAW;AAAA,QACrB,IAAI,WAAW;AAAA,QACf,UAAU,WAAW;AAAA,QACrB,OAAO,WAAW;AAAA,QAClB;AAAA,MACF;AAEA,YAAM,WAAW,MAAM,UAAU,KAA0B,cAAc,OAAO;AAEhF,aAAO,SAAS,WAAW;AAAA,IAC7B,SAAS,OAAO;AACd,cAAQ,MAAM,uCAAuC,KAAK;AAC1D,aAAO;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,kBAAoC;AACxC,UAAM,QAAQ,MAAM,cAAc;AAClC,WAAO,CAAC,CAAC;AAAA,EACX;AAAA,EAEA,MAAM,WAAwC;AAC5C,WAAO,cAAc;AAAA,EACvB;AACF;AAEO,MAAM,cAAc,IAAI,YAAY;","names":[]}
|
package/dist/server.mjs
CHANGED
|
@@ -8,20 +8,56 @@ import { findWhitelabel } from "./modules/whitelabel/actions/find-whitelabel.act
|
|
|
8
8
|
import { validateSessionAction } from "./modules/auth/actions/validate-session.action";
|
|
9
9
|
import { listSubscriptionsAction } from "./modules/subscriptions/actions/list-subscriptions.action";
|
|
10
10
|
import { listIaCreditsAction } from "./modules/ia-credits/actions/list-ia-credits.action";
|
|
11
|
+
import { accountService } from "./modules/accounts/services/account.service";
|
|
12
|
+
import { twoFactorService } from "./modules/accounts/services/two-factor.service";
|
|
13
|
+
import {
|
|
14
|
+
listAccountUsersAction,
|
|
15
|
+
updateUserAction,
|
|
16
|
+
updateAccountAction,
|
|
17
|
+
updateAccountUserByIdAction,
|
|
18
|
+
deleteAccountUserAction,
|
|
19
|
+
deleteAccountAction,
|
|
20
|
+
createAccountUserAction,
|
|
21
|
+
changePasswordAction,
|
|
22
|
+
requestEmailChangeAction,
|
|
23
|
+
confirmEmailChangeAction,
|
|
24
|
+
requestPhoneChangeAction,
|
|
25
|
+
confirmPhoneChangeAction,
|
|
26
|
+
generateTwoFactorAction,
|
|
27
|
+
confirmTwoFactorAction,
|
|
28
|
+
disableTwoFactorAction
|
|
29
|
+
} from "./modules/accounts/actions/account-management.action";
|
|
11
30
|
import { getClientInfoFromRequest } from "./infra/utils/client-info";
|
|
12
31
|
import { getUserContext } from "./modules/auth/utils/get-user-context";
|
|
13
32
|
export {
|
|
14
33
|
ApiClient,
|
|
34
|
+
accountService,
|
|
15
35
|
api,
|
|
16
36
|
apiClient,
|
|
17
37
|
authService,
|
|
38
|
+
changePasswordAction,
|
|
39
|
+
confirmEmailChangeAction,
|
|
40
|
+
confirmPhoneChangeAction,
|
|
41
|
+
confirmTwoFactorAction,
|
|
42
|
+
createAccountUserAction,
|
|
43
|
+
deleteAccountAction,
|
|
44
|
+
deleteAccountUserAction,
|
|
45
|
+
disableTwoFactorAction,
|
|
18
46
|
findWhitelabel,
|
|
47
|
+
generateTwoFactorAction,
|
|
19
48
|
getClientInfoFromRequest,
|
|
20
49
|
getUserContext,
|
|
21
50
|
iaCreditsService,
|
|
51
|
+
listAccountUsersAction,
|
|
22
52
|
listIaCreditsAction,
|
|
23
53
|
listSubscriptionsAction,
|
|
54
|
+
requestEmailChangeAction,
|
|
55
|
+
requestPhoneChangeAction,
|
|
24
56
|
subscriptionsService,
|
|
57
|
+
twoFactorService,
|
|
58
|
+
updateAccountAction,
|
|
59
|
+
updateAccountUserByIdAction,
|
|
60
|
+
updateUserAction,
|
|
25
61
|
validateSessionAction,
|
|
26
62
|
whitelabelService
|
|
27
63
|
};
|
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';\r\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\r\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.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 { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';\r\nexport { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.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\n"],"mappings":"AAAA,OAAO;AAGP,SAAS,WAAW,KAAK,iBAAiB;AAG1C,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AACrC,SAAS,wBAAwB;AAGjC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,2BAA2B;AAGpC,SAAS,gCAAgC;AACzC,SAAS,sBAAsB;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import 'server-only';\r\n\r\n// API Client\r\nexport { ApiClient, api, apiClient } from './infra/api/client';\r\n\r\n// Services\r\nexport { authService } from './modules/auth/services/auth.service';\r\nexport { whitelabelService } from './modules/whitelabel/services/whitelabel.service';\r\nexport { subscriptionsService } from './modules/subscriptions/services/subscriptions.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 { listSubscriptionsAction } from './modules/subscriptions/actions/list-subscriptions.action';\r\nexport { listIaCreditsAction } from './modules/ia-credits/actions/list-ia-credits.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\n"],"mappings":"AAAA,OAAO;AAGP,SAAS,WAAW,KAAK,iBAAiB;AAG1C,SAAS,mBAAmB;AAC5B,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AACrC,SAAS,wBAAwB;AAGjC,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AACtC,SAAS,+BAA+B;AACxC,SAAS,2BAA2B;AAGpC,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;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const copyToClipboard = async (text) => {
|
|
2
|
+
try {
|
|
3
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
4
|
+
await navigator.clipboard.writeText(text);
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
const textArea = document.createElement("textarea");
|
|
8
|
+
textArea.value = text;
|
|
9
|
+
textArea.style.position = "fixed";
|
|
10
|
+
textArea.style.left = "-9999px";
|
|
11
|
+
textArea.style.top = "-9999px";
|
|
12
|
+
document.body.appendChild(textArea);
|
|
13
|
+
textArea.focus();
|
|
14
|
+
textArea.select();
|
|
15
|
+
const success = document.execCommand("copy");
|
|
16
|
+
document.body.removeChild(textArea);
|
|
17
|
+
return success;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error("Erro ao copiar para clipboard:", error);
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const readFromClipboard = async () => {
|
|
24
|
+
try {
|
|
25
|
+
const text = await navigator.clipboard.readText();
|
|
26
|
+
return text;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
console.error("Erro ao ler do clipboard:", error);
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
copyToClipboard,
|
|
34
|
+
readFromClipboard
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=clipboard.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/browser/clipboard.ts"],"sourcesContent":["export const copyToClipboard = async (text: string): Promise<boolean> => {\r\n try {\r\n if (navigator.clipboard && navigator.clipboard.writeText) {\r\n await navigator.clipboard.writeText(text);\r\n return true;\r\n }\r\n\r\n const textArea = document.createElement('textarea');\r\n textArea.value = text;\r\n textArea.style.position = 'fixed';\r\n textArea.style.left = '-9999px';\r\n textArea.style.top = '-9999px';\r\n document.body.appendChild(textArea);\r\n textArea.focus();\r\n textArea.select();\r\n\r\n const success = document.execCommand('copy');\r\n document.body.removeChild(textArea);\r\n return success;\r\n } catch (error) {\r\n console.error('Erro ao copiar para clipboard:', error);\r\n return false;\r\n }\r\n};\r\n\r\nexport const readFromClipboard = async (): Promise<string | null> => {\r\n try {\r\n const text = await navigator.clipboard.readText();\r\n return text;\r\n } catch (error) {\r\n console.error('Erro ao ler do clipboard:', error);\r\n return null;\r\n }\r\n};\r\n"],"mappings":"AAAO,MAAM,kBAAkB,OAAO,SAAmC;AACvE,MAAI;AACF,QAAI,UAAU,aAAa,UAAU,UAAU,WAAW;AACxD,YAAM,UAAU,UAAU,UAAU,IAAI;AACxC,aAAO;AAAA,IACT;AAEA,UAAM,WAAW,SAAS,cAAc,UAAU;AAClD,aAAS,QAAQ;AACjB,aAAS,MAAM,WAAW;AAC1B,aAAS,MAAM,OAAO;AACtB,aAAS,MAAM,MAAM;AACrB,aAAS,KAAK,YAAY,QAAQ;AAClC,aAAS,MAAM;AACf,aAAS,OAAO;AAEhB,UAAM,UAAU,SAAS,YAAY,MAAM;AAC3C,aAAS,KAAK,YAAY,QAAQ;AAClC,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,kCAAkC,KAAK;AACrD,WAAO;AAAA,EACT;AACF;AAEO,MAAM,oBAAoB,YAAoC;AACnE,MAAI;AACF,UAAM,OAAO,MAAM,UAAU,UAAU,SAAS;AAChD,WAAO;AAAA,EACT,SAAS,OAAO;AACd,YAAQ,MAAM,6BAA6B,KAAK;AAChD,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const fileToBase64 = async (file) => {
|
|
2
|
+
const buffer = Buffer.from(await file.arrayBuffer());
|
|
3
|
+
const mimeType = file.type || "application/octet-stream";
|
|
4
|
+
return `data:${mimeType};base64,${buffer.toString("base64")}`;
|
|
5
|
+
};
|
|
6
|
+
export {
|
|
7
|
+
fileToBase64
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/file/index.ts"],"sourcesContent":["export const fileToBase64 = async (file: File): Promise<string> => {\r\n const buffer = Buffer.from(await file.arrayBuffer());\r\n const mimeType = file.type || 'application/octet-stream';\r\n return `data:${mimeType};base64,${buffer.toString('base64')}`;\r\n};\r\n"],"mappings":"AAAO,MAAM,eAAe,OAAO,SAAgC;AACjE,QAAM,SAAS,OAAO,KAAK,MAAM,KAAK,YAAY,CAAC;AACnD,QAAM,WAAW,KAAK,QAAQ;AAC9B,SAAO,QAAQ,QAAQ,WAAW,OAAO,SAAS,QAAQ,CAAC;AAC7D;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function formatCardNumber(value) {
|
|
2
|
+
const numbers = value.replace(/\D/g, "");
|
|
3
|
+
const groups = numbers.match(/.{1,4}/g);
|
|
4
|
+
return groups ? groups.join(" ").substring(0, 19) : "";
|
|
5
|
+
}
|
|
6
|
+
function formatExpiry(value) {
|
|
7
|
+
const numbers = value.replace(/\D/g, "");
|
|
8
|
+
if (numbers.length >= 2) {
|
|
9
|
+
return numbers.substring(0, 2) + "/" + numbers.substring(2, 4);
|
|
10
|
+
}
|
|
11
|
+
return numbers;
|
|
12
|
+
}
|
|
13
|
+
function formatCvv(value) {
|
|
14
|
+
const numbers = value.replace(/\D/g, "");
|
|
15
|
+
return numbers.substring(0, 4);
|
|
16
|
+
}
|
|
17
|
+
function formatCPF(value) {
|
|
18
|
+
const numbers = value.replace(/\D/g, "");
|
|
19
|
+
if (numbers.length <= 3) return numbers;
|
|
20
|
+
if (numbers.length <= 6) return `${numbers.slice(0, 3)}.${numbers.slice(3)}`;
|
|
21
|
+
if (numbers.length <= 9)
|
|
22
|
+
return `${numbers.slice(0, 3)}.${numbers.slice(3, 6)}.${numbers.slice(6)}`;
|
|
23
|
+
return `${numbers.slice(0, 3)}.${numbers.slice(3, 6)}.${numbers.slice(6, 9)}-${numbers.slice(9, 11)}`;
|
|
24
|
+
}
|
|
25
|
+
function formatPostalCode(value) {
|
|
26
|
+
const numbers = value.replace(/\D/g, "");
|
|
27
|
+
if (numbers.length <= 5) return numbers;
|
|
28
|
+
return `${numbers.slice(0, 5)}-${numbers.slice(5, 8)}`;
|
|
29
|
+
}
|
|
30
|
+
function formatPhone(value) {
|
|
31
|
+
const numbers = value.replace(/\D/g, "").substring(0, 11);
|
|
32
|
+
if (numbers.length <= 2) return numbers;
|
|
33
|
+
if (numbers.length <= 6) return `(${numbers.slice(0, 2)}) ${numbers.slice(2)}`;
|
|
34
|
+
if (numbers.length <= 10)
|
|
35
|
+
return `(${numbers.slice(0, 2)}) ${numbers.slice(2, 6)}-${numbers.slice(6)}`;
|
|
36
|
+
return `(${numbers.slice(0, 2)}) ${numbers.slice(2, 3)} ${numbers.slice(3, 7)}-${numbers.slice(7)}`;
|
|
37
|
+
}
|
|
38
|
+
function formatFullName(value) {
|
|
39
|
+
return value.replace(/[^a-zA-ZÀ-ÿ\s]/g, "");
|
|
40
|
+
}
|
|
41
|
+
function formatTimer(seconds) {
|
|
42
|
+
const m = Math.floor(seconds / 60);
|
|
43
|
+
const s = seconds % 60;
|
|
44
|
+
return `${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}`;
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
formatCPF,
|
|
48
|
+
formatCardNumber,
|
|
49
|
+
formatCvv,
|
|
50
|
+
formatExpiry,
|
|
51
|
+
formatFullName,
|
|
52
|
+
formatPhone,
|
|
53
|
+
formatPostalCode,
|
|
54
|
+
formatTimer
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=masks.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/format/masks.ts"],"sourcesContent":["export function formatCardNumber(value: string): string {\r\n const numbers = value.replace(/\\D/g, '');\r\n const groups = numbers.match(/.{1,4}/g);\r\n return groups ? groups.join(' ').substring(0, 19) : '';\r\n}\r\n\r\nexport function formatExpiry(value: string): string {\r\n const numbers = value.replace(/\\D/g, '');\r\n if (numbers.length >= 2) {\r\n return numbers.substring(0, 2) + '/' + numbers.substring(2, 4);\r\n }\r\n return numbers;\r\n}\r\n\r\nexport function formatCvv(value: string): string {\r\n const numbers = value.replace(/\\D/g, '');\r\n return numbers.substring(0, 4);\r\n}\r\n\r\nexport function formatCPF(value: string): string {\r\n const numbers = value.replace(/\\D/g, '');\r\n if (numbers.length <= 3) return numbers;\r\n if (numbers.length <= 6) return `${numbers.slice(0, 3)}.${numbers.slice(3)}`;\r\n if (numbers.length <= 9)\r\n return `${numbers.slice(0, 3)}.${numbers.slice(3, 6)}.${numbers.slice(6)}`;\r\n return `${numbers.slice(0, 3)}.${numbers.slice(3, 6)}.${numbers.slice(6, 9)}-${numbers.slice(9, 11)}`;\r\n}\r\n\r\nexport function formatPostalCode(value: string): string {\r\n const numbers = value.replace(/\\D/g, '');\r\n if (numbers.length <= 5) return numbers;\r\n return `${numbers.slice(0, 5)}-${numbers.slice(5, 8)}`;\r\n}\r\n\r\nexport function formatPhone(value: string): string {\r\n const numbers = value.replace(/\\D/g, '').substring(0, 11);\r\n if (numbers.length <= 2) return numbers;\r\n if (numbers.length <= 6) return `(${numbers.slice(0, 2)}) ${numbers.slice(2)}`;\r\n if (numbers.length <= 10)\r\n return `(${numbers.slice(0, 2)}) ${numbers.slice(2, 6)}-${numbers.slice(6)}`;\r\n return `(${numbers.slice(0, 2)}) ${numbers.slice(2, 3)} ${numbers.slice(3, 7)}-${numbers.slice(7)}`;\r\n}\r\n\r\nexport function formatFullName(value: string): string {\r\n return value.replace(/[^a-zA-ZÀ-ÿ\\s]/g, '');\r\n}\r\n\r\nexport function formatTimer(seconds: number): string {\r\n const m = Math.floor(seconds / 60);\r\n const s = seconds % 60;\r\n return `${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`;\r\n}\r\n"],"mappings":"AAAO,SAAS,iBAAiB,OAAuB;AACtD,QAAM,UAAU,MAAM,QAAQ,OAAO,EAAE;AACvC,QAAM,SAAS,QAAQ,MAAM,SAAS;AACtC,SAAO,SAAS,OAAO,KAAK,GAAG,EAAE,UAAU,GAAG,EAAE,IAAI;AACtD;AAEO,SAAS,aAAa,OAAuB;AAClD,QAAM,UAAU,MAAM,QAAQ,OAAO,EAAE;AACvC,MAAI,QAAQ,UAAU,GAAG;AACvB,WAAO,QAAQ,UAAU,GAAG,CAAC,IAAI,MAAM,QAAQ,UAAU,G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AI,QAAQ,MAAM,CAAC,CAAC;AAC5E,SAAO,IAAI,QAAQ,MAAM,GAAG,CAAC,CAAC,KAAK,QAAQ,MAAM,GAAG,CAAC,CAAC,IAAI,QAAQ,MAAM,GAAG,CAAC,CAAC,IAAI,QAAQ,MAAM,CAAC,CAAC;AACnG;AAEO,SAAS,eAAe,OAAuB;AACpD,SAAO,MAAM,QAAQ,mBAAmB,EAAE;AAC5C;AAEO,SAAS,YAAY,SAAyB;AACnD,QAAM,IAAI,KAAK,MAAM,UAAU,EAAE;AACjC,QAAM,IAAI,UAAU;AACpB,SAAO,GAAG,OAAO,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC,IAAI,OAAO,CAAC,EAAE,SAAS,GAAG,GAAG,CAAC;AACpE;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const LANGUAGE_OPTIONS = [
|
|
2
|
+
{ value: "pt-BR", label: "Portugu\xEAs (Brasil)", displayValue: "Portugu\xEAs (Brasil)", apiValue: "pt-br" },
|
|
3
|
+
{ value: "en-US", label: "Ingl\xEAs (EUA)", displayValue: "Ingl\xEAs (EUA)", apiValue: "en" }
|
|
4
|
+
];
|
|
5
|
+
function buildLocaleOptions() {
|
|
6
|
+
return LANGUAGE_OPTIONS;
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
LANGUAGE_OPTIONS,
|
|
10
|
+
buildLocaleOptions
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=locales.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/intl/locales.ts"],"sourcesContent":["export type LocaleOption = {\r\n value: string;\r\n label: string;\r\n displayValue: string;\r\n apiValue: string;\r\n};\r\n\r\nexport const LANGUAGE_OPTIONS: LocaleOption[] = [\r\n { value: 'pt-BR', label: 'Português (Brasil)', displayValue: 'Português (Brasil)', apiValue: 'pt-br' },\r\n { value: 'en-US', label: 'Inglês (EUA)', displayValue: 'Inglês (EUA)', apiValue: 'en' },\r\n];\r\n\r\nexport function buildLocaleOptions(): LocaleOption[] {\r\n return LANGUAGE_OPTIONS;\r\n}\r\n"],"mappings":"AAOO,MAAM,mBAAmC;AAAA,EAC9C,EAAE,OAAO,SAAS,OAAO,yBAAsB,cAAc,yBAAsB,UAAU,QAAQ;AAAA,EACrG,EAAE,OAAO,SAAS,OAAO,mBAAgB,cAAc,mBAAgB,UAAU,KAAK;AACxF;AAEO,SAAS,qBAAqC;AACnD,SAAO;AACT;","names":[]}
|