@forgepack/request 1.0.5 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +217 -86
  2. package/dist/api/client.d.ts +17 -10
  3. package/dist/api/client.d.ts.map +1 -1
  4. package/dist/api/client.js +18 -6
  5. package/dist/hooks/AuthContext.d.ts +6 -6
  6. package/dist/hooks/AuthContext.d.ts.map +1 -1
  7. package/dist/hooks/AuthContext.js +1 -1
  8. package/dist/hooks/AuthProvider.d.ts +34 -17
  9. package/dist/hooks/AuthProvider.d.ts.map +1 -1
  10. package/dist/hooks/AuthProvider.js +26 -15
  11. package/dist/hooks/useAuth.d.ts +33 -12
  12. package/dist/hooks/useAuth.d.ts.map +1 -1
  13. package/dist/hooks/useAuth.js +30 -12
  14. package/dist/hooks/useRequest.d.ts +37 -17
  15. package/dist/hooks/useRequest.d.ts.map +1 -1
  16. package/dist/hooks/useRequest.js +36 -13
  17. package/dist/index.d.ts +159 -9
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +159 -14
  20. package/dist/services/api.d.ts +37 -15
  21. package/dist/services/api.d.ts.map +1 -1
  22. package/dist/services/api.js +40 -14
  23. package/dist/services/auth.d.ts +76 -19
  24. package/dist/services/auth.d.ts.map +1 -1
  25. package/dist/services/auth.js +94 -22
  26. package/dist/services/crud.d.ts +115 -62
  27. package/dist/services/crud.d.ts.map +1 -1
  28. package/dist/services/crud.js +132 -85
  29. package/dist/services/token.d.ts +83 -26
  30. package/dist/services/token.d.ts.map +1 -1
  31. package/dist/services/token.js +141 -52
  32. package/dist/types/auth.d.ts +20 -20
  33. package/dist/types/auth.d.ts.map +1 -1
  34. package/dist/types/error.d.ts +3 -3
  35. package/dist/types/error.d.ts.map +1 -1
  36. package/dist/types/request.d.ts +8 -8
  37. package/dist/types/request.d.ts.map +1 -1
  38. package/dist/types/response.d.ts +15 -15
  39. package/dist/types/response.d.ts.map +1 -1
  40. package/dist/types/token.d.ts +15 -15
  41. package/dist/types/token.d.ts.map +1 -1
  42. package/dist/utils/constants.d.ts +7 -7
  43. package/dist/utils/constants.js +7 -7
  44. package/package.json +13 -3
@@ -1,87 +1,144 @@
1
1
  import { Auth } from '../types/auth';
2
2
  import { Header, Payload } from '../types/token';
3
3
  /**
4
- * Verifica se o token JWT atual é válido e não expirado
4
+ * Verifies if the current JWT token stored in localStorage is valid and not expired
5
5
  *
6
- * @returns true se o token for válido e não expirado, false caso contrário
6
+ * @returns {boolean} true if token exists, is valid and not expired; false otherwise
7
7
  *
8
8
  * @example
9
9
  * ```typescript
10
10
  * if (isValidToken()) {
11
- * // Usuário autenticado
11
+ * // Allow access
12
+ * console.log('User is authenticated')
12
13
  * } else {
13
- * // Redirecionar para login
14
+ * console.log('Session expired or invalid')
15
+ * window.location.href = '/login'
14
16
  * }
15
17
  * ```
16
18
  */
17
19
  export declare const isValidToken: () => boolean;
18
20
  /**
19
- * Recupera o token JWT armazenado no localStorage
21
+ * Retrieves the JWT token stored in localStorage
20
22
  *
21
- * @returns Objeto Auth com dados do token ou estado inicial se inválido
23
+ * @returns {Auth} Auth object with token data, or initialAuth if token is missing/invalid
22
24
  *
23
25
  * @example
24
26
  * ```typescript
27
+ * // Basic retrieval
25
28
  * const token = getToken()
26
- * console.log(token.accessToken)
29
+ * console.log(auth.accessToken) // JWT string
30
+ * console.log(auth.tokenType) // 'Bearer'
31
+ * console.log(auth.role) // ['USER', 'ADMIN']
27
32
  * ```
28
33
  */
29
34
  export declare const getToken: () => Auth;
30
35
  /**
31
- * Armazena o token JWT no localStorage
36
+ * Stores JWT token and authentication data in localStorage
32
37
  *
33
- * @param token - Dados de autenticação a serem armazenados
38
+ * @param {Auth} token - Authentication data to be stored
39
+ * @param {string} token.accessToken - JWT access token
40
+ * @param {string} [token.refreshToken] - Optional refresh token
41
+ * @param {string} token.tokenType - Token type (usually 'Bearer')
42
+ * @param {string[]} [token.role] - User roles/permissions
43
+ * @returns {void}
34
44
  *
35
45
  * @example
36
46
  * ```typescript
47
+ * // After successful login
48
+ * const loginResponse = await api.post('/auth/login', credentials)
49
+ *
37
50
  * setToken({
38
- * accessToken: 'jwt-token',
39
- * refreshToken: 'refresh-token',
51
+ * accessToken: loginResponse.data.accessToken,
52
+ * refreshToken: loginResponse.data.refreshToken,
40
53
  * tokenType: 'Bearer',
41
- * role: ['USER']
54
+ * role: ['USER', 'ADMIN']
42
55
  * })
43
56
  * ```
44
57
  */
45
- export declare const setToken: (token: any) => void;
58
+ export declare const setToken: (token: Auth) => void;
46
59
  /**
47
- * Remove o token JWT do localStorage
60
+ * Removes the JWT token from localStorage, effectively logging out the user
61
+ *
62
+ * @returns {void}
48
63
  *
49
64
  * @example
50
65
  * ```typescript
51
- * removeToken() // Usuário será deslogado
66
+ * // Simple logout
67
+ * removeToken()
68
+ * window.location.href = '/login'
69
+ *
70
+ * // Complete logout with backend call
71
+ * const handleLogout = async () => {
72
+ * try {
73
+ * await api.post('/auth/logout')
74
+ * } finally {
75
+ * removeToken()
76
+ * navigate('/login')
77
+ * }
78
+ * }
52
79
  * ```
53
80
  */
54
81
  export declare const removeToken: () => void;
55
82
  /**
56
- * Decodifica e retorna o payload do token JWT
83
+ * Decodes and returns the JWT token payload (claims)
57
84
  *
58
- * @returns Objeto Payload com informações do token ou estado inicial se inválido
85
+ * The payload contains user information and token metadata such as:
86
+ * - sub: Subject (user ID)
87
+ * - exp: Expiration timestamp (seconds since epoch)
88
+ * - iat: Issued at timestamp
89
+ * - Custom claims (email, name, roles, etc.)
90
+ *
91
+ * @returns {Payload} Decoded payload object, or initialPayload if token is missing/invalid
59
92
  *
60
93
  * @example
61
94
  * ```typescript
95
+ * // Get user information from token
96
+ * const payload = getPayload()
97
+ * console.log(payload.exp) // Expiration: 1735689600
98
+ * console.log(payload.iat) // Issued at: 1735603200
99
+ * // Get time until expiration
100
+ * const payload = getPayload()
101
+ * const timeLeft = payload.exp * 1000 - Date.now()
102
+ * const minutesLeft = Math.floor(timeLeft / 60000)
103
+ * console.log(`Token expires in ${minutesLeft} minutes`)
104
+ * // Access custom claims
62
105
  * const payload = getPayload()
63
- * console.log(payload.exp) // Data de expiração
64
- * console.log(payload.sub) // Subject (ID do usuário)
106
+ * const userRoles = payload.roles || []
65
107
  * ```
66
108
  */
67
109
  export declare const getPayload: () => Payload;
68
110
  /**
69
- * Decodifica o token JWT e retorna o payload como string
111
+ * Decodes the JWT token and returns the payload as a JSON string
70
112
  *
71
- * @deprecated Use getPayload() para uma abordagem mais segura
72
- * @returns String com payload decodificado ou null se inválido
113
+ * @deprecated Use getPayload() instead for type-safe access to payload data
114
+ * @returns {string | null} Decoded payload as JSON string, or null if token is invalid
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * // ❌ Deprecated approach
119
+ * const payloadString = decodeJwt()
120
+ * if (payloadString) {
121
+ * const payload = JSON.parse(payloadString)
122
+ * console.log(payload.exp)
123
+ * }
124
+ *
125
+ * // ✅ Use this instead
126
+ * const payload = getPayload()
127
+ * console.log(payload.exp)
128
+ * ```
73
129
  */
74
130
  export declare const decodeJwt: () => string | null;
75
131
  /**
76
- * Decodifica e retorna o cabeçalho do token JWT
132
+ * Decodes and returns the JWT token header
77
133
  *
78
- * @returns Objeto Header com informações do cabeçalho ou estado inicial se inválido
134
+ * @returns {Header} Decoded header object, or initialHeader if token is missing/invalid
79
135
  *
80
136
  * @example
81
137
  * ```typescript
138
+ * // Check signing algorithm
82
139
  * const header = getHeader()
83
- * console.log(header.alg) // Algoritmo usado
84
- * console.log(header.typ) // Tipo do token
140
+ * console.log(header.alg) // 'HS256'
141
+ * console.log(header.typ) // 'JWT'
85
142
  * ```
86
143
  */
87
144
  export declare const getHeader: () => Header;
@@ -1 +1 @@
1
- {"version":3,"file":"token.d.ts","sourceRoot":"","sources":["../../src/services/token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAA;AAEpC,OAAO,EAAE,MAAM,EAAE,OAAO,EAA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 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHeader = exports.decodeJwt = exports.getPayload = exports.removeToken = exports.setToken = exports.getToken = exports.isValidToken = void 0;
4
4
  const constants_1 = require("../utils/constants");
5
5
  /**
6
- * Verifica se uma string é um JSON válido
6
+ * Verifies if a string is valid JSON
7
7
  *
8
- * @param json - String a ser verificada
9
- * @returns true se for JSON válido, false caso contrário
8
+ * @param {string} json - String to be validated as JSON
9
+ * @returns {boolean} true if the string is valid JSON, false otherwise
10
+ *
11
+ * @internal This is a utility function used internally by token operations
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * isValidJSON('{"key": "value"}') // true
16
+ * isValidJSON('invalid json') // false
17
+ * isValidJSON('') // false
18
+ * ```
10
19
  */
11
20
  const isValidJSON = (json) => {
12
21
  try {
@@ -18,16 +27,18 @@ const isValidJSON = (json) => {
18
27
  }
19
28
  };
20
29
  /**
21
- * Verifica se o token JWT atual é válido e não expirado
30
+ * Verifies if the current JWT token stored in localStorage is valid and not expired
22
31
  *
23
- * @returns true se o token for válido e não expirado, false caso contrário
32
+ * @returns {boolean} true if token exists, is valid and not expired; false otherwise
24
33
  *
25
34
  * @example
26
35
  * ```typescript
27
36
  * if (isValidToken()) {
28
- * // Usuário autenticado
37
+ * // Allow access
38
+ * console.log('User is authenticated')
29
39
  * } else {
30
- * // Redirecionar para login
40
+ * console.log('Session expired or invalid')
41
+ * window.location.href = '/login'
31
42
  * }
32
43
  * ```
33
44
  */
@@ -39,6 +50,7 @@ const isValidToken = () => {
39
50
  const { exp } = (0, exports.getPayload)();
40
51
  if (typeof exp !== 'number')
41
52
  return false;
53
+ /** exp is in seconds, Date.now() is in milliseconds */
42
54
  return exp * 1000 > Date.now();
43
55
  }
44
56
  catch {
@@ -47,14 +59,17 @@ const isValidToken = () => {
47
59
  };
48
60
  exports.isValidToken = isValidToken;
49
61
  /**
50
- * Recupera o token JWT armazenado no localStorage
62
+ * Retrieves the JWT token stored in localStorage
51
63
  *
52
- * @returns Objeto Auth com dados do token ou estado inicial se inválido
64
+ * @returns {Auth} Auth object with token data, or initialAuth if token is missing/invalid
53
65
  *
54
66
  * @example
55
67
  * ```typescript
68
+ * // Basic retrieval
56
69
  * const token = getToken()
57
- * console.log(token.accessToken)
70
+ * console.log(auth.accessToken) // JWT string
71
+ * console.log(auth.tokenType) // 'Bearer'
72
+ * console.log(auth.role) // ['USER', 'ADMIN']
58
73
  * ```
59
74
  */
60
75
  const getToken = () => {
@@ -63,17 +78,25 @@ const getToken = () => {
63
78
  };
64
79
  exports.getToken = getToken;
65
80
  /**
66
- * Armazena o token JWT no localStorage
81
+ * Stores JWT token and authentication data in localStorage
67
82
  *
68
- * @param token - Dados de autenticação a serem armazenados
83
+ * @param {Auth} token - Authentication data to be stored
84
+ * @param {string} token.accessToken - JWT access token
85
+ * @param {string} [token.refreshToken] - Optional refresh token
86
+ * @param {string} token.tokenType - Token type (usually 'Bearer')
87
+ * @param {string[]} [token.role] - User roles/permissions
88
+ * @returns {void}
69
89
  *
70
90
  * @example
71
91
  * ```typescript
92
+ * // After successful login
93
+ * const loginResponse = await api.post('/auth/login', credentials)
94
+ *
72
95
  * setToken({
73
- * accessToken: 'jwt-token',
74
- * refreshToken: 'refresh-token',
96
+ * accessToken: loginResponse.data.accessToken,
97
+ * refreshToken: loginResponse.data.refreshToken,
75
98
  * tokenType: 'Bearer',
76
- * role: ['USER']
99
+ * role: ['USER', 'ADMIN']
77
100
  * })
78
101
  * ```
79
102
  */
@@ -82,11 +105,25 @@ const setToken = (token) => {
82
105
  };
83
106
  exports.setToken = setToken;
84
107
  /**
85
- * Remove o token JWT do localStorage
108
+ * Removes the JWT token from localStorage, effectively logging out the user
109
+ *
110
+ * @returns {void}
86
111
  *
87
112
  * @example
88
113
  * ```typescript
89
- * removeToken() // Usuário será deslogado
114
+ * // Simple logout
115
+ * removeToken()
116
+ * window.location.href = '/login'
117
+ *
118
+ * // Complete logout with backend call
119
+ * const handleLogout = async () => {
120
+ * try {
121
+ * await api.post('/auth/logout')
122
+ * } finally {
123
+ * removeToken()
124
+ * navigate('/login')
125
+ * }
126
+ * }
90
127
  * ```
91
128
  */
92
129
  const removeToken = () => {
@@ -94,43 +131,104 @@ const removeToken = () => {
94
131
  };
95
132
  exports.removeToken = removeToken;
96
133
  /**
97
- * Decodifica e retorna o payload do token JWT
134
+ * Decodes a Base64URL-encoded JWT segment (header or payload)
135
+ *
136
+ * Handles the complete decoding process:
137
+ * 1. Converts Base64URL to standard Base64
138
+ * 2. Decodes Base64 to binary
139
+ * 3. Properly handles Unicode characters via percent-encoding
140
+ * 4. Parses JSON if valid
98
141
  *
99
- * @returns Objeto Payload com informações do token ou estado inicial se inválido
142
+ * @template T - Type of the decoded object (Header or Payload)
143
+ * @param {string} segment - Base64URL-encoded JWT segment
144
+ * @param {T} fallback - Fallback value if decoding fails
145
+ * @returns {T} Decoded and parsed object, or fallback if invalid
146
+ *
147
+ * @internal This is a utility function used internally by getHeader and getPayload
100
148
  *
101
149
  * @example
102
150
  * ```typescript
103
- * const payload = getPayload()
104
- * console.log(payload.exp) // Data de expiração
105
- * console.log(payload.sub) // Subject (ID do usuário)
151
+ * const header = decodeJwtSegment(token.split('.')[0], initialHeader)
152
+ * const payload = decodeJwtSegment(token.split('.')[1], initialPayload)
106
153
  * ```
107
154
  */
108
- const getPayload = () => {
155
+ const decodeJwtSegment = (segment, fallback) => {
109
156
  try {
110
- const token = (0, exports.getToken)();
111
- if (!(token === null || token === void 0 ? void 0 : token.accessToken))
112
- return constants_1.initialPayload;
113
- const base64 = token.accessToken.split('.')[1]
157
+ /** Convert Base64URL to Base64 */
158
+ const base64 = segment
114
159
  .replace(/-/g, '+')
115
160
  .replace(/_/g, '/');
116
- const payload = decodeURIComponent(atob(base64)
161
+ /** Decode Base64 and handle Unicode characters properly */
162
+ const decoded = decodeURIComponent(atob(base64)
117
163
  .split('')
118
164
  .map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
119
165
  .join(''));
120
- return isValidJSON(payload) ? JSON.parse(payload) : constants_1.initialPayload;
166
+ return isValidJSON(decoded) ? JSON.parse(decoded) : fallback;
121
167
  }
122
168
  catch {
123
- return constants_1.initialPayload;
169
+ return fallback;
124
170
  }
125
171
  };
172
+ /**
173
+ * Decodes and returns the JWT token payload (claims)
174
+ *
175
+ * The payload contains user information and token metadata such as:
176
+ * - sub: Subject (user ID)
177
+ * - exp: Expiration timestamp (seconds since epoch)
178
+ * - iat: Issued at timestamp
179
+ * - Custom claims (email, name, roles, etc.)
180
+ *
181
+ * @returns {Payload} Decoded payload object, or initialPayload if token is missing/invalid
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * // Get user information from token
186
+ * const payload = getPayload()
187
+ * console.log(payload.exp) // Expiration: 1735689600
188
+ * console.log(payload.iat) // Issued at: 1735603200
189
+ * // Get time until expiration
190
+ * const payload = getPayload()
191
+ * const timeLeft = payload.exp * 1000 - Date.now()
192
+ * const minutesLeft = Math.floor(timeLeft / 60000)
193
+ * console.log(`Token expires in ${minutesLeft} minutes`)
194
+ * // Access custom claims
195
+ * const payload = getPayload()
196
+ * const userRoles = payload.roles || []
197
+ * ```
198
+ */
199
+ const getPayload = () => {
200
+ const token = (0, exports.getToken)();
201
+ if (!(token === null || token === void 0 ? void 0 : token.accessToken))
202
+ return constants_1.initialPayload;
203
+ /** Extract the payload part of the JWT */
204
+ const payloadSegment = token.accessToken.split('.')[1];
205
+ return decodeJwtSegment(payloadSegment, constants_1.initialPayload);
206
+ };
126
207
  exports.getPayload = getPayload;
127
208
  /**
128
- * Decodifica o token JWT e retorna o payload como string
209
+ * Decodes the JWT token and returns the payload as a JSON string
210
+ *
211
+ * @deprecated Use getPayload() instead for type-safe access to payload data
212
+ * @returns {string | null} Decoded payload as JSON string, or null if token is invalid
129
213
  *
130
- * @deprecated Use getPayload() para uma abordagem mais segura
131
- * @returns String com payload decodificado ou null se inválido
214
+ * @example
215
+ * ```typescript
216
+ * // ❌ Deprecated approach
217
+ * const payloadString = decodeJwt()
218
+ * if (payloadString) {
219
+ * const payload = JSON.parse(payloadString)
220
+ * console.log(payload.exp)
221
+ * }
222
+ *
223
+ * // ✅ Use this instead
224
+ * const payload = getPayload()
225
+ * console.log(payload.exp)
226
+ * ```
132
227
  */
133
228
  const decodeJwt = () => {
229
+ const token = (0, exports.getToken)();
230
+ if (!(token === null || token === void 0 ? void 0 : token.accessToken))
231
+ return null;
134
232
  if ((0, exports.getToken)() !== null) {
135
233
  var base64Url = (0, exports.getToken)().accessToken.split('.')[1];
136
234
  var base64 = decodeURIComponent(atob(base64Url).split('').map((c) => {
@@ -144,33 +242,24 @@ const decodeJwt = () => {
144
242
  };
145
243
  exports.decodeJwt = decodeJwt;
146
244
  /**
147
- * Decodifica e retorna o cabeçalho do token JWT
245
+ * Decodes and returns the JWT token header
148
246
  *
149
- * @returns Objeto Header com informações do cabeçalho ou estado inicial se inválido
247
+ * @returns {Header} Decoded header object, or initialHeader if token is missing/invalid
150
248
  *
151
249
  * @example
152
250
  * ```typescript
251
+ * // Check signing algorithm
153
252
  * const header = getHeader()
154
- * console.log(header.alg) // Algoritmo usado
155
- * console.log(header.typ) // Tipo do token
253
+ * console.log(header.alg) // 'HS256'
254
+ * console.log(header.typ) // 'JWT'
156
255
  * ```
157
256
  */
158
257
  const getHeader = () => {
159
- try {
160
- const token = (0, exports.getToken)();
161
- if (!(token === null || token === void 0 ? void 0 : token.accessToken))
162
- return constants_1.initialHeader;
163
- const base64 = token.accessToken.split('.')[0]
164
- .replace(/-/g, '+')
165
- .replace(/_/g, '/');
166
- const header = decodeURIComponent(atob(base64)
167
- .split('')
168
- .map(c => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
169
- .join(''));
170
- return isValidJSON(header) ? JSON.parse(header) : constants_1.initialHeader;
171
- }
172
- catch {
258
+ const token = (0, exports.getToken)();
259
+ if (!(token === null || token === void 0 ? void 0 : token.accessToken))
173
260
  return constants_1.initialHeader;
174
- }
261
+ /** Extract the header part of the JWT */
262
+ const headerSegment = token.accessToken.split('.')[0];
263
+ return decodeJwtSegment(headerSegment, constants_1.initialHeader);
175
264
  };
176
265
  exports.getHeader = getHeader;
@@ -1,64 +1,64 @@
1
1
  /**
2
- * Interface que representa os dados de autenticação do usuário
2
+ * Interface representing user authentication data
3
3
  * @interface Auth
4
4
  */
5
5
  export interface Auth {
6
- /** Token de acesso JWT para autenticação */
6
+ /** JWT access token for authentication */
7
7
  readonly accessToken: string;
8
- /** Token para renovação da sessão */
8
+ /** Token for session renewal */
9
9
  refreshToken: string;
10
- /** Tipo do token (geralmente "Bearer") */
10
+ /** Token type (usually "Bearer") */
11
11
  tokenType: string;
12
- /** Lista de roles/permissões do usuário */
12
+ /** List of user roles/permissions */
13
13
  role: string[];
14
14
  }
15
15
  /**
16
- * Interface para credenciais de login
16
+ * Interface for login credentials
17
17
  * @interface LoginCredentials
18
18
  */
19
19
  export interface LoginCredentials {
20
- /** Nome de usuário ou email */
20
+ /** Username or email */
21
21
  username: string;
22
- /** Senha do usuário */
22
+ /** User password */
23
23
  password: string;
24
24
  }
25
25
  /**
26
- * Interface para resposta de login
26
+ * Interface for login response
27
27
  * @interface LoginResponse
28
28
  */
29
29
  export interface LoginResponse {
30
- /** Indica se o login foi bem-sucedido */
30
+ /** Indicates if login was successful */
31
31
  success: boolean;
32
- /** Dados de autenticação (se sucesso) */
32
+ /** Authentication data (if successful) */
33
33
  data?: Auth;
34
- /** Erros de validação (se falha) */
34
+ /** Validation errors (if failed) */
35
35
  errors?: Array<{
36
36
  field: string;
37
37
  message: string;
38
38
  }>;
39
39
  }
40
40
  /**
41
- * Interface para alteração de senha
41
+ * Interface for password change
42
42
  * @interface ChangePasswordData
43
43
  */
44
44
  export interface ChangePasswordData {
45
- /** Senha atual */
45
+ /** Current password */
46
46
  currentPassword: string;
47
- /** Nova senha */
47
+ /** New password */
48
48
  newPassword: string;
49
- /** Confirmação da nova senha */
49
+ /** New password confirmation */
50
50
  confirmPassword?: string;
51
51
  }
52
52
  /**
53
- * Interface genérica para reset de senha
53
+ * Generic interface for password reset
54
54
  * @interface ResetPasswordData
55
55
  */
56
56
  export interface ResetPasswordData {
57
- /** Email para reset */
57
+ /** Email for reset */
58
58
  email?: string;
59
- /** Token de reset */
59
+ /** Reset token */
60
60
  token?: string;
61
- /** Nova senha */
61
+ /** New password */
62
62
  newPassword?: string;
63
63
  }
64
64
  //# sourceMappingURL=auth.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,IAAI;IACjB,4CAA4C;IAC5C,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,qCAAqC;IACxC,YAAY,EAAE,MAAM,CAAC;IAClB,0CAA0C;IAC7C,SAAS,EAAE,MAAM,CAAC;IACf,2CAA2C;IAC9C,IAAI,EAAE,MAAM,EAAE,CAAA;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC7B,+BAA+B;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,uBAAuB;IACvB,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC1B,yCAAyC;IACzC,OAAO,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,oCAAoC;IACpC,MAAM,CAAC,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACrD;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAC/B,kBAAkB;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,gCAAgC;IAChC,eAAe,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAC9B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,MAAM,CAAA;CACvB"}
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Interface que representa uma mensagem de erro de validação
2
+ * Interface representing a validation error message
3
3
  * @interface ErrorMessage
4
4
  */
5
5
  export interface ErrorMessage {
6
- /** Nome do campo que contém o erro */
6
+ /** Name of the field containing the error */
7
7
  field: string;
8
- /** Mensagem descritiva do erro */
8
+ /** Descriptive error message */
9
9
  message: string;
10
10
  }
11
11
  //# sourceMappingURL=error.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/types/error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,kCAAkC;IAClC,OAAO,EAAE,MAAM,CAAA;CAClB"}
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/types/error.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB,6CAA6C;IAC7C,KAAK,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,OAAO,EAAE,MAAM,CAAA;CAClB"}
@@ -1,25 +1,25 @@
1
1
  /**
2
- * Interface que define os parâmetros de ordenação
2
+ * Interface defining sort parameters
3
3
  * @interface Sort
4
4
  */
5
5
  export interface Sort {
6
- /** Campo pelo qual ordenar */
6
+ /** Field to sort by */
7
7
  key: string;
8
- /** Direção da ordenação */
8
+ /** Sort direction */
9
9
  order: 'ASC' | 'DESC';
10
10
  }
11
11
  /**
12
- * Interface que define os parâmetros de busca e paginação
12
+ * Interface defining search and pagination parameters
13
13
  * @interface Search
14
14
  */
15
15
  export interface Search {
16
- /** Termo de busca/filtro */
16
+ /** Search/filter term */
17
17
  value?: string;
18
- /** Número da página (baseado em zero) */
18
+ /** Page number (zero-based) */
19
19
  page?: number;
20
- /** Quantidade de itens por página */
20
+ /** Number of items per page */
21
21
  size?: number;
22
- /** Configuração de ordenação */
22
+ /** Sort configuration */
23
23
  sort?: Sort;
24
24
  }
25
25
  //# sourceMappingURL=request.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/types/request.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,IAAI;IACjB,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,2BAA2B;IAC3B,KAAK,EAAE,KAAK,GAAG,MAAM,CAAA;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,MAAM;IACnB,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qCAAqC;IACrC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gCAAgC;IAChC,IAAI,CAAC,EAAE,IAAI,CAAA;CACd"}
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../src/types/request.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,WAAW,IAAI;IACjB,uBAAuB;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,qBAAqB;IACrB,KAAK,EAAE,KAAK,GAAG,MAAM,CAAA;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,MAAM;IACnB,yBAAyB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,+BAA+B;IAC/B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,IAAI,CAAC,EAAE,IAAI,CAAA;CACd"}