@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.
@@ -0,0 +1,623 @@
1
+ /**
2
+ * Namespace principal da API de autenticação
3
+ * Acesso aos tipos: AuthApi.objects.User, AuthApi.responses.auth.login.post, etc.
4
+ */
5
+ export declare namespace AuthApi {
6
+ /**
7
+ * Objetos de domínio da aplicação
8
+ */
9
+ namespace objects {
10
+ enum BundleType {
11
+ BUNDLE = 0,
12
+ SYMBOLIC_PRODUCT = 1,
13
+ SYMBOLIC_COURSE = 2,
14
+ SYMBOLIC_CONSULTANCY = 3
15
+ }
16
+ type Product = {
17
+ id: number;
18
+ title: string;
19
+ short: string;
20
+ resume: string;
21
+ video: string;
22
+ imgUrls: string | null;
23
+ logo: string;
24
+ themeImage: string;
25
+ themeColor: string;
26
+ themeVideo: string;
27
+ url: string;
28
+ type: number;
29
+ period_test: number;
30
+ created: string;
31
+ deletedAt?: string | null;
32
+ Levels?: ProductLevel[];
33
+ };
34
+ type ProductLevel = {
35
+ id: number;
36
+ productID: number;
37
+ level: number;
38
+ short: string;
39
+ Product?: Product;
40
+ store_bundles_levels?: {
41
+ id: number;
42
+ bundleID: number;
43
+ levelID: number;
44
+ quantity: number;
45
+ Bundle?: Bundle;
46
+ }[];
47
+ };
48
+ type Course = {
49
+ id: number;
50
+ type: number;
51
+ name: string;
52
+ short: string;
53
+ resume: string;
54
+ img_landscape: string;
55
+ img_square: string;
56
+ workload: number;
57
+ langID: number;
58
+ num_classes?: number;
59
+ seats: number;
60
+ url?: string;
61
+ dates: string;
62
+ local: string;
63
+ local_url: string;
64
+ date_mat_s?: string;
65
+ date_mat_e?: string;
66
+ date_ends?: string;
67
+ email_enrollment?: string;
68
+ email_before?: string;
69
+ email_after?: string;
70
+ date_c: string;
71
+ date_r?: string | null;
72
+ };
73
+ type Consultancy = {
74
+ id: number;
75
+ teacherID: number;
76
+ type: number;
77
+ name: string;
78
+ short: string;
79
+ resume: string;
80
+ img_landscape: string;
81
+ img_square: string;
82
+ workload: number;
83
+ langID: number;
84
+ url?: string;
85
+ datetime: string;
86
+ date_mat_s?: string;
87
+ date_mat_e?: string;
88
+ date_ends?: string;
89
+ email_enrollment: string;
90
+ email_before: string;
91
+ email_after: string;
92
+ date_c: string;
93
+ date_r?: string | null;
94
+ };
95
+ type Bundle = {
96
+ id: number;
97
+ type: BundleType;
98
+ title?: string;
99
+ short?: string;
100
+ resume?: string;
101
+ img: string;
102
+ themeImage: string;
103
+ themeColor: string;
104
+ shareLimit: number;
105
+ created: string;
106
+ active: boolean;
107
+ showInSite: boolean;
108
+ defaultMetaArray: string;
109
+ deletedAt?: string | null;
110
+ Levels?: {
111
+ id: number;
112
+ bundleID: number;
113
+ levelID: number;
114
+ quantity: number;
115
+ Level: ProductLevel;
116
+ }[];
117
+ Courses?: {
118
+ id: number;
119
+ bundleID: number;
120
+ courseID: number;
121
+ quantity: number;
122
+ Course: Course;
123
+ }[];
124
+ Consultancies?: {
125
+ id: number;
126
+ bundleID: number;
127
+ consultancyID: number;
128
+ quantity: number;
129
+ Consultancy: Consultancy;
130
+ }[];
131
+ store_bundles_paymethod: PaymentMethod[];
132
+ };
133
+ type PaymentMethod = {
134
+ id: number;
135
+ bundleID: number;
136
+ price: number;
137
+ fromprice: number;
138
+ period_renew: number;
139
+ period_grace: number;
140
+ gatewayHash: string;
141
+ allowBoleto: boolean;
142
+ gatewayID: number;
143
+ Bundle?: Bundle;
144
+ };
145
+ type Purchase = {
146
+ paghash: string;
147
+ id: number;
148
+ price: number;
149
+ licenseStatus: PaymentSystem.PG_PurchaseLicenseStatus;
150
+ paymentStatus: PaymentSystem.PG_PurchasePaymentStatus;
151
+ type_step: PaymentSystem.PG_PurchaseType;
152
+ PaymentMethod: PaymentMethod;
153
+ Wallet?: Wallet;
154
+ walletID: number;
155
+ createdAt: string;
156
+ paymentDueAt: string | null;
157
+ owner: string;
158
+ invoiceUrl?: string;
159
+ nfUrl?: string;
160
+ isAdmin?: boolean;
161
+ meta_data?: Record<string, any>;
162
+ PurchaseShares?: PurchaseShare[];
163
+ Levels?: {
164
+ Level: ProductLevel;
165
+ quant: number;
166
+ }[];
167
+ };
168
+ type Wallet = {
169
+ id: number;
170
+ userID: number;
171
+ balance?: number;
172
+ Purchases?: Purchase[];
173
+ };
174
+ type PurchaseShare = {
175
+ id: number;
176
+ purchaseID: number;
177
+ userID: number;
178
+ Purchase: Purchase;
179
+ };
180
+ type LocalUser = {
181
+ id: number;
182
+ fullname: string;
183
+ email: string;
184
+ lang: number;
185
+ avatar: string;
186
+ end_city?: number;
187
+ end_comp?: string;
188
+ end_country: number;
189
+ end_district?: string;
190
+ end_n?: string;
191
+ end_state?: number;
192
+ end_street?: string;
193
+ end_zip?: string;
194
+ email_verif: boolean;
195
+ fiscal_verif: boolean;
196
+ terms: boolean;
197
+ cpf?: string;
198
+ newslatter?: boolean;
199
+ allow_purchase?: boolean;
200
+ allow_license?: boolean;
201
+ date_c?: Date | string;
202
+ date_r?: Date | string | null;
203
+ Wallets?: Wallet[];
204
+ PurchasesShares?: PurchaseShare[];
205
+ Sys_admUser_config?: AdminUserConfig;
206
+ Sys_adminUser?: auxiliarTypes.PrivilegeTable;
207
+ };
208
+ type AdminUserConfig = {
209
+ campaigns_blacklist: string;
210
+ deletedAt: Date | null;
211
+ userID: number;
212
+ };
213
+ type LogEntry = {
214
+ appId: string;
215
+ logCode: number;
216
+ content: string;
217
+ timestamp?: string;
218
+ metadata?: {
219
+ requestId: string;
220
+ endpoint: string;
221
+ method: string;
222
+ userId?: number;
223
+ ip?: string;
224
+ browser?: string;
225
+ system?: string;
226
+ referer?: string;
227
+ };
228
+ };
229
+ namespace PaymentSystem {
230
+ type PG_Customer = {
231
+ id: string;
232
+ email: string;
233
+ name: string;
234
+ };
235
+ enum PG_PurchaseLicenseStatus {
236
+ UNKNOWN = 0,//Nunca será atualizado automaticamente!!
237
+ OPEN = 3,//ABERTA - Aguardando pagamento
238
+ EXPIRED = 1,//VENCEU - Era PAGAMENTO, e acabou prazo pra uso acabou
239
+ PAID = 5,//PAGA - Pagamento realizado com sucesso - é pagamento único
240
+ ACTIVE = 6,//ATIVO - Assinatura ativa e em dia
241
+ RECYCLING = 4,//RETENTANDO - Tentativa de renovação automática falhou, mas ainda está no prazo para pagar manualmente
242
+ CANCELED = 2
243
+ }
244
+ const PG_PurchaseLicenseStatus_GroupActive: PG_PurchaseLicenseStatus[];
245
+ enum PG_PurchasePaymentStatus {
246
+ UNKNOWN = 0,//pendent or unknown
247
+ ACTIVE = 1,
248
+ CANCELED = 2,
249
+ REFUNDED = 3,
250
+ REMOVED = 4,// REMOVIDO DO GATEWAY - Não há mais registro do pagamento no gateway
251
+ PENDING = 5
252
+ }
253
+ enum PG_PurchaseType {
254
+ SESSION = 0,//o registro se trata de uma sessão de compra (ex: intenção de compra preparada para redirecionar o usuário ao gateway. Ainda não é um pagamento nem uma assinatura ativa)
255
+ STANDARD = 1,//Pagamento único
256
+ RECURRENT = 2
257
+ }
258
+ type PG_Purchase = {
259
+ id: string;
260
+ amount: number;
261
+ recurrent: boolean;
262
+ type: PG_PurchaseType;
263
+ paymentStatus: PG_PurchasePaymentStatus;
264
+ url: string | null;
265
+ dueTime: Date | null;
266
+ };
267
+ enum PG_RecurrenceType {
268
+ NONE = 0,
269
+ DAILY = 1,
270
+ WEEKLY = 2,
271
+ MONTHLY = 3,
272
+ YEARLY = 4
273
+ }
274
+ }
275
+ }
276
+ namespace auxiliarTypes {
277
+ type availableSoftware = {
278
+ Level: objects.ProductLevel;
279
+ quantity: number;
280
+ purchaseId: number | null;
281
+ type: 'free' | 'own' | 'shared';
282
+ };
283
+ enum Privilege {
284
+ NONE = 0,
285
+ READ = 1,
286
+ WRITE = 2
287
+ }
288
+ type PrivilegeTable = {
289
+ users: Privilege;
290
+ products: Privilege;
291
+ courses: Privilege;
292
+ consultancies: Privilege;
293
+ bundles: Privilege;
294
+ logs: Privilege;
295
+ support: Privilege;
296
+ leads: Privilege;
297
+ paymentSystem: Privilege;
298
+ adminMaster: Privilege;
299
+ activityTrakking: Privilege;
300
+ financial: Privilege;
301
+ };
302
+ type CronJob = {
303
+ startAt: Date | null;
304
+ latestRunErrorCount: number;
305
+ latestCompletedAt: Date | null;
306
+ };
307
+ type CronjobsStatuses = {
308
+ purchasesStatusUpdate: CronJob;
309
+ };
310
+ type LogFilters = {
311
+ page: number;
312
+ itemsPerPage: number;
313
+ search: string;
314
+ logCode?: number;
315
+ appId?: string;
316
+ userId?: number;
317
+ method?: string;
318
+ startDate?: string;
319
+ endDate?: string;
320
+ };
321
+ type PaginationInfo = {
322
+ total: number;
323
+ page: number;
324
+ itemsPerPage: number;
325
+ totalPages: number;
326
+ };
327
+ }
328
+ /**
329
+ * Tipos de resposta padrão da API
330
+ */
331
+ namespace responses {
332
+ type ApiResponse<T = any> = {
333
+ conex: boolean;
334
+ reqStat: number;
335
+ success: boolean;
336
+ data: T;
337
+ msg: string;
338
+ };
339
+ namespace auth {
340
+ namespace login {
341
+ type POST = ApiResponse<{
342
+ user: objects.LocalUser;
343
+ msg?: string;
344
+ }>;
345
+ }
346
+ namespace logout {
347
+ type GET = ApiResponse<{}>;
348
+ }
349
+ namespace checkSession {
350
+ type GET = ApiResponse<{
351
+ user?: objects.LocalUser;
352
+ msg?: string;
353
+ }>;
354
+ }
355
+ }
356
+ namespace users {
357
+ type GET = ApiResponse<objects.LocalUser[]>;
358
+ }
359
+ namespace user {
360
+ type GET = ApiResponse<objects.LocalUser & {
361
+ Wallets?: objects.Wallet[];
362
+ PurchasesShares?: objects.PurchaseShare[];
363
+ }>;
364
+ type PUT = ApiResponse<objects.LocalUser>;
365
+ namespace updateConfig {
366
+ type PUT = ApiResponse<{
367
+ msg?: string;
368
+ }>;
369
+ }
370
+ namespace updateAdmin {
371
+ type PUT = ApiResponse<objects.LocalUser>;
372
+ }
373
+ namespace license {
374
+ type PUT = ApiResponse<{
375
+ availableLicenses: number;
376
+ heldLicenses: number;
377
+ usedLicenses: number;
378
+ msg?: string;
379
+ }>;
380
+ }
381
+ }
382
+ namespace purchase {
383
+ namespace create {
384
+ type POST = ApiResponse<{
385
+ msg?: string;
386
+ purchase: objects.Purchase;
387
+ url?: string;
388
+ }>;
389
+ }
390
+ namespace id {
391
+ namespace sync {
392
+ type POST = ApiResponse<objects.Purchase & {
393
+ msg?: string;
394
+ }>;
395
+ }
396
+ }
397
+ type PUT = ApiResponse<objects.Purchase | {
398
+ msg?: string;
399
+ }>;
400
+ namespace cancel {
401
+ type PUT = ApiResponse<objects.Purchase>;
402
+ }
403
+ type DELETE = ApiResponse<{
404
+ msg?: string;
405
+ }>;
406
+ namespace getFromGateway {
407
+ type GET = ApiResponse<objects.PaymentSystem.PG_Purchase>;
408
+ }
409
+ }
410
+ namespace purchases {
411
+ type post_list = ApiResponse<{
412
+ purchases: objects.Purchase[];
413
+ pagination: {
414
+ page: number;
415
+ pageSize: number;
416
+ count: number;
417
+ };
418
+ }>;
419
+ }
420
+ namespace product {
421
+ type GET = ApiResponse<objects.Product>;
422
+ type PUT = ApiResponse<objects.Product>;
423
+ }
424
+ namespace products {
425
+ type GET = ApiResponse<objects.Product[]>;
426
+ }
427
+ namespace paymentMethod {
428
+ type POST = ApiResponse<objects.PaymentMethod>;
429
+ type PUT = ApiResponse<objects.PaymentMethod>;
430
+ type DELETE = ApiResponse<{
431
+ msg?: string;
432
+ }>;
433
+ }
434
+ namespace logs {
435
+ type POST_SEARCH = ApiResponse<{
436
+ data: {
437
+ logs: objects.LogEntry[];
438
+ pagination: auxiliarTypes.PaginationInfo;
439
+ available: boolean;
440
+ };
441
+ }>;
442
+ namespace status {
443
+ type GET = ApiResponse<{
444
+ saveToFile: boolean;
445
+ logPretty: boolean;
446
+ fileExists: boolean;
447
+ filePath: string;
448
+ logLevel: string;
449
+ canListLogs: boolean;
450
+ }>;
451
+ }
452
+ }
453
+ namespace cronJobs {
454
+ namespace status {
455
+ type GET = ApiResponse<auxiliarTypes.CronjobsStatuses>;
456
+ }
457
+ namespace run {
458
+ type POST = ApiResponse<{
459
+ msg: string;
460
+ }>;
461
+ }
462
+ }
463
+ namespace aux {
464
+ namespace countries {
465
+ type GET = ApiResponse<Array<{
466
+ id: number;
467
+ nome: string;
468
+ nome_pt: string;
469
+ }>>;
470
+ }
471
+ namespace states {
472
+ type GET = ApiResponse<Array<{
473
+ id: number;
474
+ nome: string;
475
+ uf: string;
476
+ ibge: number;
477
+ pais?: number;
478
+ ddd?: string;
479
+ }>>;
480
+ }
481
+ namespace cities {
482
+ type GET = ApiResponse<Array<{
483
+ id: number;
484
+ nome: string;
485
+ uf: number;
486
+ ibge: number;
487
+ }>>;
488
+ }
489
+ }
490
+ namespace report {
491
+ type POST = ApiResponse<{
492
+ msg?: string;
493
+ }>;
494
+ }
495
+ }
496
+ /**
497
+ * Configuração do Client
498
+ */
499
+ type ClientConfig = {
500
+ baseURL: string;
501
+ tokenStorage?: {
502
+ getToken: () => string | null;
503
+ setToken: (token: string) => void;
504
+ getPin1: () => string | null;
505
+ setPin1: (pin1: string) => void;
506
+ };
507
+ onTokenUpdate?: (token: string) => void;
508
+ onPin1Update?: (pin1: string) => void;
509
+ retryAttempts?: number;
510
+ retryDelay?: number;
511
+ };
512
+ /**
513
+ * Client para comunicação com a API de autenticação
514
+ */
515
+ class Client {
516
+ private baseURL;
517
+ private bearer;
518
+ private pin1;
519
+ private tokenStorage?;
520
+ private onTokenUpdate?;
521
+ private onPin1Update?;
522
+ private retryAttempts;
523
+ private retryDelay;
524
+ private isHealth;
525
+ constructor(config: ClientConfig);
526
+ /**
527
+ * Define o token de autenticação
528
+ */
529
+ setToken(token: string): void;
530
+ /**
531
+ * Define o PIN1
532
+ */
533
+ setPin1(pin1: string): void;
534
+ /**
535
+ * Obtém o token atual
536
+ */
537
+ getToken(): string;
538
+ /**
539
+ * Obtém o PIN1 atual
540
+ */
541
+ getPin1(): string;
542
+ /**
543
+ * Verifica se o servidor está saudável
544
+ */
545
+ isHealthy(): Promise<boolean>;
546
+ /**
547
+ * Requisição base para a API
548
+ */
549
+ private request;
550
+ /**
551
+ * Constrói query string a partir de um objeto
552
+ */
553
+ private buildQueryString;
554
+ auth: {
555
+ /**
556
+ * Faz login na API
557
+ */
558
+ login: (email: string, password: string) => Promise<responses.auth.login.POST>;
559
+ /**
560
+ * Faz logout da API
561
+ */
562
+ logout: () => Promise<responses.auth.logout.GET>;
563
+ /**
564
+ * Verifica a sessão atual
565
+ */
566
+ checkSession: () => Promise<responses.auth.checkSession.GET>;
567
+ };
568
+ checkHealth(): Promise<boolean>;
569
+ user: {
570
+ list: () => Promise<responses.ApiResponse<responses.users.GET>>;
571
+ get: (userId: number, includePurchases?: boolean) => Promise<responses.ApiResponse<responses.user.GET>>;
572
+ update: (userId: number, userData: Partial<objects.LocalUser>) => Promise<responses.ApiResponse<responses.user.PUT>>;
573
+ updateConfig: (obj: {
574
+ id: number;
575
+ config_ihm_showRates?: boolean;
576
+ }) => Promise<responses.ApiResponse<responses.user.updateConfig.PUT>>;
577
+ updateAdmin: (userId: number, isAdmin: boolean) => Promise<responses.ApiResponse<responses.user.updateAdmin.PUT>>;
578
+ license: (userId: number) => Promise<responses.ApiResponse<responses.user.license.PUT>>;
579
+ };
580
+ purchase: {
581
+ new: (paymentMethodId: number, userId: number) => Promise<responses.ApiResponse<responses.purchase.create.POST>>;
582
+ sync: (purchaseId: number, userId: number, async?: boolean) => Promise<responses.ApiResponse<responses.purchase.id.sync.POST>>;
583
+ update: (userId: number, purchase: objects.Purchase) => Promise<responses.ApiResponse<responses.purchase.PUT>>;
584
+ cancel: (purchaseId: number, userId: number) => Promise<responses.ApiResponse<responses.purchase.cancel.PUT>>;
585
+ delete: (purchaseId: number, userId: number) => Promise<responses.ApiResponse<responses.purchase.DELETE>>;
586
+ list: (page?: number, pageSize?: number, userId?: number) => Promise<responses.ApiResponse<responses.purchases.post_list>>;
587
+ getFromGateway: (purchaseId: number, userId: number, async?: boolean) => Promise<responses.ApiResponse<responses.purchase.getFromGateway.GET>>;
588
+ };
589
+ products: {
590
+ list: () => Promise<responses.ApiResponse<responses.products.GET>>;
591
+ get: (productId: number) => Promise<responses.ApiResponse<responses.product.GET>>;
592
+ update: (productId: number, productData: any) => Promise<responses.ApiResponse<responses.product.PUT>>;
593
+ };
594
+ paymentMethods: {
595
+ create: (id: number, paymentMethodData: objects.PaymentMethod) => Promise<responses.ApiResponse<responses.paymentMethod.POST>>;
596
+ update: (id: number, paymentMethodId: number, paymentMethodData: objects.PaymentMethod) => Promise<responses.ApiResponse<responses.paymentMethod.PUT>>;
597
+ delete: (id: number, paymentMethodId: number) => Promise<responses.ApiResponse<responses.paymentMethod.DELETE>>;
598
+ };
599
+ aux: {
600
+ countries: () => Promise<responses.ApiResponse<responses.aux.countries.GET>>;
601
+ states: (countryId: number) => Promise<responses.ApiResponse<responses.aux.states.GET>>;
602
+ cities: (countryId: number, stateId: number) => Promise<responses.ApiResponse<responses.aux.cities.GET>>;
603
+ };
604
+ admin: {
605
+ logs: {
606
+ /**
607
+ * @param filters
608
+ * @returns
609
+ */
610
+ list: (filters?: Partial<auxiliarTypes.LogFilters>) => Promise<responses.ApiResponse<responses.logs.POST_SEARCH>>;
611
+ status: () => Promise<responses.ApiResponse<responses.logs.status.GET>>;
612
+ };
613
+ cronJobs: {
614
+ status: () => Promise<responses.ApiResponse<responses.cronJobs.status.GET>>;
615
+ run: (name: string) => Promise<responses.ApiResponse<responses.cronJobs.run.POST>>;
616
+ };
617
+ };
618
+ report: {
619
+ new: (id: string, data: any) => Promise<responses.ApiResponse<responses.report.POST>>;
620
+ };
621
+ }
622
+ }
623
+ export default AuthApi;