@authenty/authapi-types 1.0.16 → 1.0.18

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/README.md CHANGED
@@ -53,7 +53,7 @@ const client = new AuthApi.Client({
53
53
  });
54
54
 
55
55
  client.setToken('seu-token-jwt');
56
- const user = await client.getUser(123);
56
+ const user = await client.users.get(123);
57
57
  ```
58
58
 
59
59
  ### Usando apenas os tipos
@@ -66,10 +66,6 @@ import type {
66
66
  } from '@authenty/authapi-types';
67
67
  ```
68
68
 
69
- ## Documentação
70
-
71
- - [Guia Completo do Client](./CLIENT_USAGE.md) - Documentação detalhada de todos os métodos
72
-
73
69
  ## Publicação
74
70
 
75
71
  1. Certifique-se de estar logado no npm:
package/dist/index.d.ts CHANGED
@@ -619,3 +619,4 @@ export declare namespace AuthApi {
619
619
  }
620
620
  }
621
621
  export default AuthApi;
622
+ export * from './simple-types';
package/dist/index.js CHANGED
@@ -1,4 +1,18 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.AuthApi = void 0;
4
18
  const tools_1 = require("./tools");
@@ -419,3 +433,4 @@ var AuthApi;
419
433
  })(AuthApi || (exports.AuthApi = AuthApi = {}));
420
434
  // Exporta o namespace como default também
421
435
  exports.default = AuthApi;
436
+ __exportStar(require("./simple-types"), exports);
@@ -0,0 +1,27 @@
1
+ import AuthApi from ".";
2
+ export declare const BundleType: typeof AuthApi.objects.BundleType;
3
+ export type Product = AuthApi.objects.Product;
4
+ export type ProductLevel = AuthApi.objects.ProductLevel;
5
+ export type Course = AuthApi.objects.Course;
6
+ export type Consultancy = AuthApi.objects.Consultancy;
7
+ export type Bundle = AuthApi.objects.Bundle;
8
+ export type PaymentMethod = AuthApi.objects.PaymentMethod;
9
+ export type Purchase = AuthApi.objects.Purchase;
10
+ export type Wallet = AuthApi.objects.Wallet;
11
+ export type PurchaseShare = AuthApi.objects.PurchaseShare;
12
+ export type LocalUser = AuthApi.objects.LocalUser;
13
+ export type AdminUserConfig = AuthApi.objects.AdminUserConfig;
14
+ export type LogEntry = AuthApi.objects.LogEntry;
15
+ export type PG_Customer = AuthApi.objects.PaymentSystem.PG_Customer;
16
+ export declare const PG_PurchaseLicenseStatus: typeof AuthApi.objects.PaymentSystem.PG_PurchaseLicenseStatus;
17
+ export declare const PG_PurchaseLicenseStatus_GroupActive: AuthApi.objects.PaymentSystem.PG_PurchaseLicenseStatus[];
18
+ export declare const PG_PurchasePaymentStatus: typeof AuthApi.objects.PaymentSystem.PG_PurchasePaymentStatus;
19
+ export declare const PG_PurchaseType: typeof AuthApi.objects.PaymentSystem.PG_PurchaseType;
20
+ export type PG_Purchase = AuthApi.objects.PaymentSystem.PG_Purchase;
21
+ export declare const PG_RecurrenceType: typeof AuthApi.objects.PaymentSystem.PG_RecurrenceType;
22
+ export type availableSoftware = AuthApi.auxiliarTypes.availableSoftware;
23
+ export declare const Privilege: typeof AuthApi.auxiliarTypes.Privilege;
24
+ export type PrivilegeTable = AuthApi.auxiliarTypes.PrivilegeTable;
25
+ export type CronJob = AuthApi.auxiliarTypes.CronJob;
26
+ export type CronjobsStatuses = AuthApi.auxiliarTypes.CronjobsStatuses;
27
+ export type LogFilters = AuthApi.auxiliarTypes.LogFilters;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ //Para facilitar a importação
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.Privilege = exports.PG_RecurrenceType = exports.PG_PurchaseType = exports.PG_PurchasePaymentStatus = exports.PG_PurchaseLicenseStatus_GroupActive = exports.PG_PurchaseLicenseStatus = exports.BundleType = void 0;
8
+ const _1 = __importDefault(require("."));
9
+ exports.BundleType = _1.default.objects.BundleType;
10
+ exports.PG_PurchaseLicenseStatus = _1.default.objects.PaymentSystem.PG_PurchaseLicenseStatus;
11
+ exports.PG_PurchaseLicenseStatus_GroupActive = _1.default.objects.PaymentSystem.PG_PurchaseLicenseStatus_GroupActive;
12
+ exports.PG_PurchasePaymentStatus = _1.default.objects.PaymentSystem.PG_PurchasePaymentStatus;
13
+ exports.PG_PurchaseType = _1.default.objects.PaymentSystem.PG_PurchaseType;
14
+ exports.PG_RecurrenceType = _1.default.objects.PaymentSystem.PG_RecurrenceType;
15
+ exports.Privilege = _1.default.auxiliarTypes.Privilege;
16
+ // export type PG_PurchasePaymentStatus = AuthApi.objects.PaymentSystem.PG_PurchasePaymentStatus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authenty/authapi-types",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "description": "Shared types for Authenty API",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -920,3 +920,5 @@ export namespace AuthApi {
920
920
 
921
921
  // Exporta o namespace como default também
922
922
  export default AuthApi;
923
+
924
+ export * from './simple-types';
@@ -0,0 +1,36 @@
1
+
2
+ //Para facilitar a importação
3
+
4
+ import AuthApi from ".";
5
+
6
+ export const BundleType = AuthApi.objects.BundleType;
7
+ export type Product = AuthApi.objects.Product;
8
+ export type ProductLevel = AuthApi.objects.ProductLevel;
9
+ export type Course = AuthApi.objects.Course;
10
+ export type Consultancy = AuthApi.objects.Consultancy;
11
+ export type Bundle = AuthApi.objects.Bundle;
12
+ export type PaymentMethod = AuthApi.objects.PaymentMethod;
13
+ export type Purchase = AuthApi.objects.Purchase;
14
+ export type Wallet = AuthApi.objects.Wallet;
15
+ export type PurchaseShare = AuthApi.objects.PurchaseShare;
16
+ export type LocalUser = AuthApi.objects.LocalUser;
17
+ export type AdminUserConfig = AuthApi.objects.AdminUserConfig;
18
+ export type LogEntry = AuthApi.objects.LogEntry;
19
+
20
+ export type PG_Customer = AuthApi.objects.PaymentSystem.PG_Customer;
21
+ export const PG_PurchaseLicenseStatus = AuthApi.objects.PaymentSystem.PG_PurchaseLicenseStatus;
22
+ export const PG_PurchaseLicenseStatus_GroupActive = AuthApi.objects.PaymentSystem.PG_PurchaseLicenseStatus_GroupActive;
23
+ export const PG_PurchasePaymentStatus = AuthApi.objects.PaymentSystem.PG_PurchasePaymentStatus;
24
+ export const PG_PurchaseType = AuthApi.objects.PaymentSystem.PG_PurchaseType;
25
+ export type PG_Purchase = AuthApi.objects.PaymentSystem.PG_Purchase;
26
+ export const PG_RecurrenceType = AuthApi.objects.PaymentSystem.PG_RecurrenceType;
27
+
28
+ export type availableSoftware = AuthApi.auxiliarTypes.availableSoftware;
29
+ export const Privilege = AuthApi.auxiliarTypes.Privilege;
30
+ export type PrivilegeTable = AuthApi.auxiliarTypes.PrivilegeTable;
31
+ export type CronJob = AuthApi.auxiliarTypes.CronJob;
32
+ export type CronjobsStatuses = AuthApi.auxiliarTypes.CronjobsStatuses;
33
+ export type LogFilters = AuthApi.auxiliarTypes.LogFilters;
34
+
35
+
36
+ // export type PG_PurchasePaymentStatus = AuthApi.objects.PaymentSystem.PG_PurchasePaymentStatus;
package/CLIENT_USAGE.md DELETED
@@ -1,317 +0,0 @@
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!