@authenty/authapi-types 1.0.9 → 1.0.11
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/CLIENT_USAGE.md +317 -0
- package/README.md +85 -13
- package/dist/general.d.ts +5 -5
- package/dist/package.json +18 -0
- package/dist/src/index.d.ts +623 -0
- package/dist/src/index.js +425 -0
- package/dist/src/tools.d.ts +1 -0
- package/dist/src/tools.js +16 -0
- package/package.json +1 -1
- package/src/index.ts +918 -4
- package/src/tools.ts +12 -0
- package/tsconfig.json +3 -2
- package/src/admin.ts +0 -20
- package/src/cronjobs.ts +0 -9
- package/src/general.ts +0 -245
- package/src/payment-system.ts +0 -61
package/CLIENT_USAGE.md
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
# AuthAPI Client - Guia de Uso
|
|
2
|
+
|
|
3
|
+
A classe `AuthApi.Client` fornece uma interface completa e tipada para se comunicar com a API de autenticação.
|
|
4
|
+
|
|
5
|
+
## Instalação
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @authenty/authapi-types
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Uso Básico
|
|
12
|
+
|
|
13
|
+
### Frontend (React, Vue, etc.)
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { AuthApi } from '@authenty/authapi-types';
|
|
17
|
+
|
|
18
|
+
// Configurar o client com storage do navegador
|
|
19
|
+
const client = new AuthApi.Client({
|
|
20
|
+
baseURL: 'https://api.exemplo.com',
|
|
21
|
+
tokenStorage: {
|
|
22
|
+
getToken: () => localStorage.getItem('token'),
|
|
23
|
+
setToken: (token) => localStorage.setItem('token', token),
|
|
24
|
+
getPin1: () => localStorage.getItem('pin1'),
|
|
25
|
+
setPin1: (pin1) => localStorage.setItem('pin1', pin1)
|
|
26
|
+
},
|
|
27
|
+
retryAttempts: 2,
|
|
28
|
+
retryDelay: 1000
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Usar o client
|
|
32
|
+
async function fazerLogin() {
|
|
33
|
+
const result = await client.login('usuario@exemplo.com', 'senha123');
|
|
34
|
+
|
|
35
|
+
if (result.success) {
|
|
36
|
+
console.log('Usuário logado:', result.data.user);
|
|
37
|
+
} else {
|
|
38
|
+
console.error('Erro no login:', result.msg);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Backend (Node.js)
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
import { AuthApi } from '@authenty/authapi-types';
|
|
47
|
+
|
|
48
|
+
// Configurar o client sem storage (tokens gerenciados manualmente)
|
|
49
|
+
const client = new AuthApi.Client({
|
|
50
|
+
baseURL: 'https://api.exemplo.com',
|
|
51
|
+
retryAttempts: 3,
|
|
52
|
+
retryDelay: 500
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Definir token manualmente se necessário
|
|
56
|
+
client.setToken('seu-token-jwt');
|
|
57
|
+
|
|
58
|
+
// Usar o client
|
|
59
|
+
async function obterUsuario(userId: number) {
|
|
60
|
+
const result = await client.getUser(userId);
|
|
61
|
+
|
|
62
|
+
if (result.success) {
|
|
63
|
+
return result.data;
|
|
64
|
+
} else {
|
|
65
|
+
throw new Error(result.msg);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## API Completa
|
|
71
|
+
|
|
72
|
+
### Autenticação
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// Login
|
|
76
|
+
const loginResult = await client.login(email, password);
|
|
77
|
+
|
|
78
|
+
// Logout
|
|
79
|
+
const logoutResult = await client.logout();
|
|
80
|
+
|
|
81
|
+
// Verificar sessão
|
|
82
|
+
const sessionResult = await client.checkSession();
|
|
83
|
+
|
|
84
|
+
// Verificar saúde do servidor
|
|
85
|
+
const isHealthy = await client.isHealthy();
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Usuários
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
// Listar todos os usuários
|
|
92
|
+
const usersResult = await client.listUsers();
|
|
93
|
+
|
|
94
|
+
// Obter um usuário específico
|
|
95
|
+
const userResult = await client.getUser(userId, includePurchases);
|
|
96
|
+
|
|
97
|
+
// Atualizar usuário
|
|
98
|
+
const updateResult = await client.updateUser(userId, {
|
|
99
|
+
fullname: 'Novo Nome',
|
|
100
|
+
email: 'novo@email.com'
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
// Atualizar configuração
|
|
104
|
+
const configResult = await client.updateUserConfig(userId, {
|
|
105
|
+
config_ihm_showRates: true
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
// Atualizar privilégios de admin
|
|
109
|
+
const adminResult = await client.updateUserAdmin(userId, true);
|
|
110
|
+
|
|
111
|
+
// Obter informações de licença
|
|
112
|
+
const licenseResult = await client.getUserLicense(userId);
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Purchases (Compras)
|
|
116
|
+
|
|
117
|
+
```typescript
|
|
118
|
+
// Criar nova compra
|
|
119
|
+
const purchaseResult = await client.createPurchase(userId, paymentMethodId);
|
|
120
|
+
|
|
121
|
+
// Sincronizar compra com gateway
|
|
122
|
+
const syncResult = await client.syncPurchase(userId, purchaseId);
|
|
123
|
+
|
|
124
|
+
// Atualizar compra
|
|
125
|
+
const updateResult = await client.updatePurchase(userId, purchaseData);
|
|
126
|
+
|
|
127
|
+
// Cancelar compra
|
|
128
|
+
const cancelResult = await client.cancelPurchase(userId, purchaseId);
|
|
129
|
+
|
|
130
|
+
// Deletar compra
|
|
131
|
+
const deleteResult = await client.deletePurchase(userId, purchaseId);
|
|
132
|
+
|
|
133
|
+
// Listar compras
|
|
134
|
+
const listResult = await client.listPurchases(page, pageSize, userId);
|
|
135
|
+
|
|
136
|
+
// Obter compra do gateway
|
|
137
|
+
const gatewayResult = await client.getPurchaseFromGateway(userId, purchaseId);
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Produtos
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
// Listar produtos
|
|
144
|
+
const productsResult = await client.listProducts();
|
|
145
|
+
|
|
146
|
+
// Obter produto específico
|
|
147
|
+
const productResult = await client.getProduct(productId);
|
|
148
|
+
|
|
149
|
+
// Atualizar produto
|
|
150
|
+
const updateResult = await client.updateProduct(productId, productData);
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### Métodos de Pagamento
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
// Criar método de pagamento
|
|
157
|
+
const createResult = await client.createPaymentMethod(bundleId, paymentMethodData);
|
|
158
|
+
|
|
159
|
+
// Atualizar método de pagamento
|
|
160
|
+
const updateResult = await client.updatePaymentMethod(bundleId, paymentMethodId, paymentMethodData);
|
|
161
|
+
|
|
162
|
+
// Deletar método de pagamento
|
|
163
|
+
const deleteResult = await client.deletePaymentMethod(bundleId, paymentMethodId);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Logs
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// Listar logs
|
|
170
|
+
const logsResult = await client.listLogs({
|
|
171
|
+
page: 1,
|
|
172
|
+
itemsPerPage: 50,
|
|
173
|
+
search: 'termo de busca'
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
// Obter status dos logs
|
|
177
|
+
const statusResult = await client.getLogsStatus();
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### CronJobs
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
// Obter status dos cronjobs
|
|
184
|
+
const statusResult = await client.getCronJobsStatus();
|
|
185
|
+
|
|
186
|
+
// Executar cronjob manualmente
|
|
187
|
+
const runResult = await client.runCronJob('jobName');
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Auxiliares
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
// Listar países
|
|
194
|
+
const countriesResult = await client.listCountries();
|
|
195
|
+
|
|
196
|
+
// Listar estados de um país
|
|
197
|
+
const statesResult = await client.listStates(countryId);
|
|
198
|
+
|
|
199
|
+
// Listar cidades de um estado
|
|
200
|
+
const citiesResult = await client.listCities(countryId, stateId);
|
|
201
|
+
|
|
202
|
+
// Enviar relatório de erro
|
|
203
|
+
const reportResult = await client.sendReport(errorId, errorData, appVersion);
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## Configuração Avançada
|
|
207
|
+
|
|
208
|
+
### Com callbacks para atualização de tokens
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
const client = new AuthApi.Client({
|
|
212
|
+
baseURL: 'https://api.exemplo.com',
|
|
213
|
+
tokenStorage: {
|
|
214
|
+
getToken: () => localStorage.getItem('token'),
|
|
215
|
+
setToken: (token) => localStorage.setItem('token', token),
|
|
216
|
+
getPin1: () => localStorage.getItem('pin1'),
|
|
217
|
+
setPin1: (pin1) => localStorage.setItem('pin1', pin1)
|
|
218
|
+
},
|
|
219
|
+
onTokenUpdate: (token) => {
|
|
220
|
+
console.log('Token atualizado:', token);
|
|
221
|
+
// Disparar evento global, atualizar estado, etc.
|
|
222
|
+
},
|
|
223
|
+
onPin1Update: (pin1) => {
|
|
224
|
+
console.log('PIN1 atualizado:', pin1);
|
|
225
|
+
},
|
|
226
|
+
retryAttempts: 3,
|
|
227
|
+
retryDelay: 1000
|
|
228
|
+
});
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
### Gerenciamento manual de tokens
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
// Definir token
|
|
235
|
+
client.setToken('novo-token');
|
|
236
|
+
|
|
237
|
+
// Definir PIN1
|
|
238
|
+
client.setPin1('novo-pin1');
|
|
239
|
+
|
|
240
|
+
// Obter token atual
|
|
241
|
+
const currentToken = client.getToken();
|
|
242
|
+
|
|
243
|
+
// Obter PIN1 atual
|
|
244
|
+
const currentPin1 = client.getPin1();
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## Tipos de Resposta
|
|
248
|
+
|
|
249
|
+
Todas as respostas seguem o padrão `ApiResponse<T>`:
|
|
250
|
+
|
|
251
|
+
```typescript
|
|
252
|
+
type ApiResponse<T> = {
|
|
253
|
+
conex: boolean; // true se houve conexão com o servidor
|
|
254
|
+
reqStat: number; // Código de status HTTP
|
|
255
|
+
success: boolean; // true se a requisição foi bem-sucedida (200-299)
|
|
256
|
+
data: T; // Dados retornados pela API
|
|
257
|
+
msg: string; // Mensagem de erro ou sucesso
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Exemplo de tratamento de resposta:
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
const result = await client.login(email, password);
|
|
265
|
+
|
|
266
|
+
if (!result.conex) {
|
|
267
|
+
// Erro de conexão - servidor indisponível
|
|
268
|
+
console.error('Sem conexão com o servidor');
|
|
269
|
+
} else if (!result.success) {
|
|
270
|
+
// Erro da API - credenciais inválidas, etc.
|
|
271
|
+
console.error('Erro:', result.msg);
|
|
272
|
+
} else {
|
|
273
|
+
// Sucesso!
|
|
274
|
+
console.log('Usuário:', result.data.user);
|
|
275
|
+
}
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
## Tipos Disponíveis
|
|
279
|
+
|
|
280
|
+
Todos os tipos estão disponíveis através do namespace `AuthApi`:
|
|
281
|
+
|
|
282
|
+
```typescript
|
|
283
|
+
// Objetos de domínio
|
|
284
|
+
import type {
|
|
285
|
+
AuthApi.objects.User,
|
|
286
|
+
AuthApi.objects.Purchase,
|
|
287
|
+
AuthApi.objects.Product,
|
|
288
|
+
// ... etc
|
|
289
|
+
} from '@authenty/authapi-types';
|
|
290
|
+
|
|
291
|
+
// Tipos de resposta
|
|
292
|
+
import type {
|
|
293
|
+
AuthApi.responses.auth.login.post,
|
|
294
|
+
AuthApi.responses.users.list.get,
|
|
295
|
+
// ... etc
|
|
296
|
+
} from '@authenty/authapi-types';
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
## Migração do código antigo
|
|
300
|
+
|
|
301
|
+
### Antes (usando api/index.tsx):
|
|
302
|
+
|
|
303
|
+
```typescript
|
|
304
|
+
import api from '../api';
|
|
305
|
+
|
|
306
|
+
const result = await api.auth.login(email, password);
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Depois (usando AuthApi.Client):
|
|
310
|
+
|
|
311
|
+
```typescript
|
|
312
|
+
import { client } from '../config/api'; // client configurado uma vez
|
|
313
|
+
|
|
314
|
+
const result = await client.login(email, password);
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
A API é praticamente idêntica, mas agora completamente tipada e reutilizável!
|
package/README.md
CHANGED
|
@@ -1,34 +1,106 @@
|
|
|
1
1
|
# @authenty/authapi-types
|
|
2
2
|
|
|
3
|
-
Pacote de tipos compartilhados da Authenty API.
|
|
3
|
+
Pacote de tipos compartilhados e client HTTP da Authenty API.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Recursos
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- ✅ Tipos TypeScript completos para toda a API
|
|
8
|
+
- ✅ Client HTTP pronto para uso (browser e Node.js)
|
|
9
|
+
- ✅ Gerenciamento automático de tokens
|
|
10
|
+
- ✅ Retry logic configurável
|
|
11
|
+
- ✅ Totalmente tipado com autocomplete
|
|
12
|
+
|
|
13
|
+
## Instalação
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @authenty/authapi-types
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Uso Rápido
|
|
20
|
+
|
|
21
|
+
### Frontend (React, Vue, etc.)
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { AuthApi } from '@authenty/authapi-types';
|
|
25
|
+
|
|
26
|
+
// Configurar o client
|
|
27
|
+
const client = new AuthApi.Client({
|
|
28
|
+
baseURL: 'https://api.exemplo.com',
|
|
29
|
+
tokenStorage: {
|
|
30
|
+
getToken: () => localStorage.getItem('token'),
|
|
31
|
+
setToken: (token) => localStorage.setItem('token', token),
|
|
32
|
+
getPin1: () => localStorage.getItem('pin1'),
|
|
33
|
+
setPin1: (pin1) => localStorage.setItem('pin1', pin1)
|
|
34
|
+
},
|
|
35
|
+
retryAttempts: 2,
|
|
36
|
+
retryDelay: 1000
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// Usar
|
|
40
|
+
const result = await client.login('usuario@exemplo.com', 'senha123');
|
|
41
|
+
if (result.success) {
|
|
42
|
+
console.log('Usuário logado:', result.data.user);
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Backend (Node.js)
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import { AuthApi } from '@authenty/authapi-types';
|
|
50
|
+
|
|
51
|
+
const client = new AuthApi.Client({
|
|
52
|
+
baseURL: 'https://api.exemplo.com'
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
client.setToken('seu-token-jwt');
|
|
56
|
+
const user = await client.getUser(123);
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Usando apenas os tipos
|
|
60
|
+
|
|
61
|
+
```typescript
|
|
62
|
+
import type {
|
|
63
|
+
AuthApi.objects.LocalUser,
|
|
64
|
+
AuthApi.objects.Purchase,
|
|
65
|
+
AuthApi.responses.auth.login.post
|
|
66
|
+
} from '@authenty/authapi-types';
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Documentação
|
|
70
|
+
|
|
71
|
+
- [Guia Completo do Client](./CLIENT_USAGE.md) - Documentação detalhada de todos os métodos
|
|
72
|
+
|
|
73
|
+
## Publicação
|
|
74
|
+
|
|
75
|
+
1. Certifique-se de estar logado no npm:
|
|
8
76
|
```bash
|
|
9
77
|
npm login
|
|
10
78
|
```
|
|
11
79
|
|
|
12
|
-
2.
|
|
80
|
+
2. Incremente a versão (se necessário):
|
|
81
|
+
```bash
|
|
82
|
+
npm run version:increment
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
3. Faça o build do pacote:
|
|
13
86
|
```bash
|
|
14
87
|
npm run build
|
|
15
88
|
```
|
|
16
89
|
|
|
17
|
-
|
|
90
|
+
4. Publique o pacote (acesso público):
|
|
18
91
|
```bash
|
|
19
92
|
npm publish --access public
|
|
20
93
|
```
|
|
21
94
|
|
|
22
|
-
##
|
|
23
|
-
|
|
24
|
-
Instale o pacote em seu projeto:
|
|
95
|
+
## Desenvolvimento
|
|
25
96
|
|
|
26
97
|
```bash
|
|
27
|
-
|
|
28
|
-
|
|
98
|
+
# Instalar dependências
|
|
99
|
+
npm install
|
|
29
100
|
|
|
30
|
-
|
|
101
|
+
# Build
|
|
102
|
+
npm run build
|
|
31
103
|
|
|
32
|
-
|
|
33
|
-
|
|
104
|
+
# Incrementar versão
|
|
105
|
+
npm run version:increment
|
|
34
106
|
```
|
package/dist/general.d.ts
CHANGED
|
@@ -11,12 +11,12 @@ export type Product = {
|
|
|
11
11
|
title: string;
|
|
12
12
|
short: string;
|
|
13
13
|
resume: string;
|
|
14
|
-
video
|
|
15
|
-
imgUrls
|
|
14
|
+
video: string;
|
|
15
|
+
imgUrls: string | null;
|
|
16
16
|
logo: string;
|
|
17
|
-
themeImage
|
|
18
|
-
themeColor
|
|
19
|
-
themeVideo
|
|
17
|
+
themeImage: string;
|
|
18
|
+
themeColor: string;
|
|
19
|
+
themeVideo: string;
|
|
20
20
|
url: string;
|
|
21
21
|
type: number;
|
|
22
22
|
period_test: number;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@authenty/authapi-types",
|
|
3
|
+
"version": "1.0.11",
|
|
4
|
+
"description": "Shared types for Authenty API",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"prebuild": "node IncrementVersion.js",
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"dev": "tsc -w"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {
|
|
16
|
+
"typescript": "^5.0.0"
|
|
17
|
+
}
|
|
18
|
+
}
|