@greatapps/common 1.1.23 → 1.1.25
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/Select.mjs.map +1 -1
- 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/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 +6 -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/Select.tsx +1 -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/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;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA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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,MAAM,KAAK,QAAmC,UAAU;AAEzE,QAAI,SA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M,mBAAmB,IAAI,iBAAiB;","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,GAAG,CAAC;AAAA,EAC/D;AACA,SAAO;AACT;AAEO,SAAS,UAAU,OAAuB;AAC/C,QAAM,UAAU,MAAM,QAAQ,OAAO,EAAE;AACvC,SAAO,QAAQ,UAAU,GAAG,CAAC;AAC/B;AAEO,SAAS,UAAU,OAAuB;AAC/C,QAAM,UAAU,MAAM,QAAQ,OAAO,EAAE;AACvC,MAAI,QAAQ,UAAU,EAAG,QAAO;AAChC,MAAI,QAAQ,UAAU,EAAG,QAAO,GAAG,QAAQ,MAAM,GAAG,CAAC,CAAC,IAAI,QAAQ,MAAM,CAAC,CAAC;AAC1E,MAAI,QAAQ,UAAU;AACpB,WAAO,GAAG,QAAQ,MAAM,GAAG,CAAC,CAAC,IAAI,QAAQ,MAAM,GAAG,CAAC,CAAC,IAAI,QAAQ,MAAM,CAAC,CAAC;AAC1E,SAAO,GAAG,QAAQ,MAAM,GAAG,CAAC,CAAC,IAAI,QAAQ,MAAM,GAAG,CAAC,CAAC,IAAI,QAAQ,MAAM,GAAG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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":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function parseOffsetMinutes(offsetStr) {
|
|
2
|
+
const match = offsetStr.match(/GMT([+-])(\d+)(?::(\d+))?/);
|
|
3
|
+
if (!match) return 0;
|
|
4
|
+
const sign = match[1] === "+" ? 1 : -1;
|
|
5
|
+
return sign * (parseInt(match[2], 10) * 60 + parseInt(match[3] ?? "0", 10));
|
|
6
|
+
}
|
|
7
|
+
const FALLBACK_TIMEZONES = [
|
|
8
|
+
{ value: "America/Noronha", label: "(GMT-2) America/Noronha", displayValue: "(GMT-2) Noronha" },
|
|
9
|
+
{ value: "America/Sao_Paulo", label: "(GMT-3) America/Sao Paulo", displayValue: "(GMT-3) Sao Paulo" },
|
|
10
|
+
{ value: "America/Manaus", label: "(GMT-4) America/Manaus", displayValue: "(GMT-4) Manaus" },
|
|
11
|
+
{ value: "America/Rio_Branco", label: "(GMT-5) America/Rio Branco", displayValue: "(GMT-5) Rio Branco" },
|
|
12
|
+
{ value: "America/New_York", label: "(GMT-5) America/New York", displayValue: "(GMT-5) New York" },
|
|
13
|
+
{ value: "America/Los_Angeles", label: "(GMT-8) America/Los Angeles", displayValue: "(GMT-8) Los Angeles" },
|
|
14
|
+
{ value: "Europe/London", label: "(GMT+0) Europe/London", displayValue: "(GMT+0) London" },
|
|
15
|
+
{ value: "Europe/Paris", label: "(GMT+1) Europe/Paris", displayValue: "(GMT+1) Paris" },
|
|
16
|
+
{ value: "Asia/Tokyo", label: "(GMT+9) Asia/Tokyo", displayValue: "(GMT+9) Tokyo" }
|
|
17
|
+
];
|
|
18
|
+
function buildTimezoneOptions() {
|
|
19
|
+
try {
|
|
20
|
+
const zones = Intl.supportedValuesOf("timeZone");
|
|
21
|
+
const now = /* @__PURE__ */ new Date();
|
|
22
|
+
const items = zones.map((tz) => {
|
|
23
|
+
const offsetStr = new Intl.DateTimeFormat("en", { timeZone: tz, timeZoneName: "shortOffset" }).formatToParts(now).find((p) => p.type === "timeZoneName")?.value ?? "GMT";
|
|
24
|
+
const city = tz.split("/").slice(1).join("/").replace(/_/g, " ") || tz;
|
|
25
|
+
return {
|
|
26
|
+
value: tz,
|
|
27
|
+
label: `(${offsetStr}) ${tz.replace(/_/g, " ")}`,
|
|
28
|
+
displayValue: `(${offsetStr}) ${city}`,
|
|
29
|
+
sort: parseOffsetMinutes(offsetStr)
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
items.sort((a, b) => a.sort - b.sort || a.label.localeCompare(b.label));
|
|
33
|
+
return items.map(({ value, label, displayValue }) => ({ value, label, displayValue }));
|
|
34
|
+
} catch {
|
|
35
|
+
return FALLBACK_TIMEZONES;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
buildTimezoneOptions
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=timezones.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/intl/timezones.ts"],"sourcesContent":["export type TimezoneOption = {\r\n value: string;\r\n label: string;\r\n displayValue: string;\r\n};\r\n\r\nfunction parseOffsetMinutes(offsetStr: string): number {\r\n const match = offsetStr.match(/GMT([+-])(\\d+)(?::(\\d+))?/);\r\n if (!match) return 0;\r\n const sign = match[1] === '+' ? 1 : -1;\r\n return sign * (parseInt(match[2], 10) * 60 + parseInt(match[3] ?? '0', 10));\r\n}\r\n\r\nconst FALLBACK_TIMEZONES: TimezoneOption[] = [\r\n { value: 'America/Noronha', label: '(GMT-2) America/Noronha', displayValue: '(GMT-2) Noronha' },\r\n { value: 'America/Sao_Paulo', label: '(GMT-3) America/Sao Paulo', displayValue: '(GMT-3) Sao Paulo' },\r\n { value: 'America/Manaus', label: '(GMT-4) America/Manaus', displayValue: '(GMT-4) Manaus' },\r\n { value: 'America/Rio_Branco', label: '(GMT-5) America/Rio Branco', displayValue: '(GMT-5) Rio Branco' },\r\n { value: 'America/New_York', label: '(GMT-5) America/New York', displayValue: '(GMT-5) New York' },\r\n { value: 'America/Los_Angeles', label: '(GMT-8) America/Los Angeles', displayValue: '(GMT-8) Los Angeles' },\r\n { value: 'Europe/London', label: '(GMT+0) Europe/London', displayValue: '(GMT+0) London' },\r\n { value: 'Europe/Paris', label: '(GMT+1) Europe/Paris', displayValue: '(GMT+1) Paris' },\r\n { value: 'Asia/Tokyo', label: '(GMT+9) Asia/Tokyo', displayValue: '(GMT+9) Tokyo' },\r\n];\r\n\r\nexport function buildTimezoneOptions(): TimezoneOption[] {\r\n try {\r\n const zones = Intl.supportedValuesOf('timeZone');\r\n const now = new Date();\r\n\r\n const items = zones.map((tz) => {\r\n const offsetStr =\r\n new Intl.DateTimeFormat('en', { timeZone: tz, timeZoneName: 'shortOffset' })\r\n .formatToParts(now)\r\n .find((p) => p.type === 'timeZoneName')?.value ?? 'GMT';\r\n\r\n const city = tz.split('/').slice(1).join('/').replace(/_/g, ' ') || tz;\r\n\r\n return {\r\n value: tz,\r\n label: `(${offsetStr}) ${tz.replace(/_/g, ' ')}`,\r\n displayValue: `(${offsetStr}) ${city}`,\r\n sort: parseOffsetMinutes(offsetStr),\r\n };\r\n });\r\n\r\n items.sort((a, b) => a.sort - b.sort || a.label.localeCompare(b.label));\r\n\r\n return items.map(({ value, label, displayValue }) => ({ value, label, displayValue }));\r\n } catch {\r\n return FALLBACK_TIMEZONES;\r\n }\r\n}\r\n"],"mappings":"AAMA,SAAS,mBAAmB,WAA2B;AACrD,QAAM,QAAQ,UAAU,MAAM,2BAA2B;AACzD,MAAI,CAAC,MAAO,QAAO;AACnB,QAAM,OAAO,MAAM,CAAC,MAAM,MAAM,IAAI;AACpC,SAAO,QAAQ,SAAS,MAAM,CAAC,GAAG,EAAE,IAAI,KAAK,SAAS,MAAM,CAAC,KAAK,KAAK,EAAE;AAC3E;AAEA,MAAM,qBAAuC;AAAA,EAC3C,EAAE,OAAO,mBAAmB,OAAO,2BAA2B,cAAc,kBAAkB;AAAA,EAC9F,EAAE,OAAO,qBAAqB,OAAO,6BAA6B,cAAc,oBAAoB;AAAA,EACpG,EAAE,OAAO,kBAAkB,OAAO,0BAA0B,cAAc,iBAAiB;AAAA,EAC3F,EAAE,OAAO,sBAAsB,OAAO,8BAA8B,cAAc,qBAAqB;AAAA,EACvG,EAAE,OAAO,oBAAoB,OAAO,4BAA4B,cAAc,mBAAmB;AAAA,EACjG,EAAE,OAAO,uBAAuB,OAAO,+BAA+B,cAAc,sBAAsB;AAAA,EAC1G,EAAE,OAAO,iBAAiB,OAAO,yBAAyB,cAAc,iBAAiB;AAAA,EACzF,EAAE,OAAO,gBAAgB,OAAO,wBAAwB,cAAc,gBAAgB;AAAA,EACtF,EAAE,OAAO,cAAc,OAAO,sBAAsB,cAAc,gBAAgB;AACpF;AAEO,SAAS,uBAAyC;AACvD,MAAI;AACF,UAAM,QAAQ,KAAK,kBAAkB,UAAU;AAC/C,UAAM,MAAM,oBAAI,KAAK;AAErB,UAAM,QAAQ,MAAM,IAAI,CAAC,OAAO;AAC9B,YAAM,YACJ,IAAI,KAAK,eAAe,MAAM,EAAE,UAAU,IAAI,cAAc,cAAc,CAAC,EACxE,cAAc,GAAG,EACjB,KAAK,CAAC,MAAM,EAAE,SAAS,cAAc,GAAG,SAAS;AAEtD,YAAM,OAAO,GAAG,MAAM,GAAG,EAAE,MAAM,CAAC,EAAE,KAAK,GAAG,EAAE,QAAQ,MAAM,GAAG,KAAK;AAEpE,aAAO;AAAA,QACL,OAAO;AAAA,QACP,OAAO,IAAI,SAAS,KAAK,GAAG,QAAQ,MAAM,GAAG,CAAC;AAAA,QAC9C,cAAc,IAAI,SAAS,KAAK,IAAI;AAAA,QACpC,MAAM,mBAAmB,SAAS;AAAA,MACpC;AAAA,IACF,CAAC;AAED,UAAM,KAAK,CAAC,GAAG,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,EAAE,KAAK,CAAC;AAEtE,WAAO,MAAM,IAAI,CAAC,EAAE,OAAO,OAAO,aAAa,OAAO,EAAE,OAAO,OAAO,aAAa,EAAE;AAAA,EACvF,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const myProfileSchema = z.object({
|
|
3
|
+
name: z.string().min(1, "Nome \xE9 obrigat\xF3rio"),
|
|
4
|
+
gender: z.string().optional()
|
|
5
|
+
});
|
|
6
|
+
const changePasswordSchema = z.object({
|
|
7
|
+
currentPassword: z.string().min(1, "Senha atual \xE9 obrigat\xF3ria"),
|
|
8
|
+
newPassword: z.string().min(1, "Nova senha \xE9 obrigat\xF3ria").min(8, "Nova senha deve ter no m\xEDnimo 8 caracteres")
|
|
9
|
+
});
|
|
10
|
+
const changePhoneSchema = z.object({
|
|
11
|
+
phone: z.string().min(1, "N\xFAmero de telefone \xE9 obrigat\xF3rio").regex(/^\(\d{2}\) (\d \d{4}|\d{4})-\d{4}$/, "N\xFAmero de telefone inv\xE1lido")
|
|
12
|
+
});
|
|
13
|
+
const changeEmailSchema = z.object({
|
|
14
|
+
email: z.string().min(1, "E-mail \xE9 obrigat\xF3rio").email("E-mail inv\xE1lido")
|
|
15
|
+
});
|
|
16
|
+
const OTP_CODE_LENGTH = 5;
|
|
17
|
+
const VALID_OTP_CODE = "12345";
|
|
18
|
+
export {
|
|
19
|
+
OTP_CODE_LENGTH,
|
|
20
|
+
VALID_OTP_CODE,
|
|
21
|
+
changeEmailSchema,
|
|
22
|
+
changePasswordSchema,
|
|
23
|
+
changePhoneSchema,
|
|
24
|
+
myProfileSchema
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=account.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/validators/account.ts"],"sourcesContent":["import { z } from 'zod';\r\n\r\nexport const myProfileSchema = z.object({\r\n name: z.string().min(1, 'Nome é obrigatório'),\r\n gender: z.string().optional(),\r\n});\r\n\r\nexport type MyProfileFormData = z.infer<typeof myProfileSchema>;\r\n\r\nexport const changePasswordSchema = z.object({\r\n currentPassword: z.string().min(1, 'Senha atual é obrigatória'),\r\n newPassword: z\r\n .string()\r\n .min(1, 'Nova senha é obrigatória')\r\n .min(8, 'Nova senha deve ter no mínimo 8 caracteres'),\r\n});\r\n\r\nexport type ChangePasswordFormData = z.infer<typeof changePasswordSchema>;\r\n\r\nexport const changePhoneSchema = z.object({\r\n phone: z\r\n .string()\r\n .min(1, 'Número de telefone é obrigatório')\r\n .regex(/^\\(\\d{2}\\) (\\d \\d{4}|\\d{4})-\\d{4}$/, 'Número de telefone inválido'),\r\n});\r\n\r\nexport type ChangePhoneFormData = z.infer<typeof changePhoneSchema>;\r\n\r\nexport const changeEmailSchema = z.object({\r\n email: z.string().min(1, 'E-mail é obrigatório').email('E-mail inválido'),\r\n});\r\n\r\nexport type ChangeEmailFormData = z.infer<typeof changeEmailSchema>;\r\n\r\nexport const OTP_CODE_LENGTH = 5;\r\nexport const VALID_OTP_CODE = '12345';\r\n"],"mappings":"AAAA,SAAS,SAAS;AAEX,MAAM,kBAAkB,EAAE,OAAO;AAAA,EACtC,MAAM,EAAE,OAAO,EAAE,IAAI,GAAG,0BAAoB;AAAA,EAC5C,QAAQ,EAAE,OAAO,EAAE,SAAS;AAC9B,CAAC;AAIM,MAAM,uBAAuB,EAAE,OAAO;AAAA,EAC3C,iBAAiB,EAAE,OAAO,EAAE,IAAI,GAAG,iCAA2B;AAAA,EAC9D,aAAa,EACV,OAAO,EACP,IAAI,GAAG,gCAA0B,EACjC,IAAI,GAAG,+CAA4C;AACxD,CAAC;AAIM,MAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,OAAO,EACJ,OAAO,EACP,IAAI,GAAG,2CAAkC,EACzC,MAAM,sCAAsC,mCAA6B;AAC9E,CAAC;AAIM,MAAM,oBAAoB,EAAE,OAAO;AAAA,EACxC,OAAO,EAAE,OAAO,EAAE,IAAI,GAAG,4BAAsB,EAAE,MAAM,oBAAiB;AAC1E,CAAC;AAIM,MAAM,kBAAkB;AACxB,MAAM,iBAAiB;","names":[]}
|