@in.pulse-crm/sdk 1.6.1 → 2.0.0

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 (84) hide show
  1. package/dist/api-client.d.ts +9 -0
  2. package/dist/api-client.js +29 -0
  3. package/dist/{auth.d.ts → auth.client.d.ts} +4 -38
  4. package/dist/{auth.js → auth.client.js} +6 -10
  5. package/dist/customers.client.d.ts +37 -0
  6. package/dist/{customer.js → customers.client.js} +6 -10
  7. package/dist/files.client.d.ts +31 -0
  8. package/dist/{file.js → files.client.js} +6 -26
  9. package/dist/index.d.ts +9 -12
  10. package/dist/index.js +21 -41
  11. package/dist/{instance.d.ts → instance.client.d.ts} +3 -9
  12. package/dist/{instance.js → instance.client.js} +6 -10
  13. package/dist/reports.client.d.ts +9 -0
  14. package/dist/{report.js → reports.client.js} +6 -6
  15. package/dist/socket-server.client.d.ts +24 -0
  16. package/dist/socket-server.client.js +34 -0
  17. package/dist/socket.client.d.ts +49 -0
  18. package/dist/socket.client.js +74 -0
  19. package/dist/types/auth.types.d.ts +29 -0
  20. package/dist/{customer.d.ts → types/customers.types.d.ts} +0 -42
  21. package/dist/{file.d.ts → types/files.types.d.ts} +3 -38
  22. package/dist/types/files.types.js +15 -0
  23. package/dist/types/index.d.ts +7 -0
  24. package/dist/types/index.js +23 -0
  25. package/dist/{report.d.ts → types/reports.types.d.ts} +0 -10
  26. package/dist/types/socket-events.types.d.ts +72 -0
  27. package/dist/types/socket-events.types.js +19 -0
  28. package/dist/types/socket-rooms.types.d.ts +15 -0
  29. package/dist/{user.d.ts → types/user.types.d.ts} +0 -41
  30. package/dist/types/user.types.js +19 -0
  31. package/dist/users.client.d.ts +40 -0
  32. package/dist/{user.js → users.client.js} +11 -27
  33. package/package.json +1 -1
  34. package/src/api-client.ts +33 -0
  35. package/src/{auth.ts → auth.client.ts} +4 -43
  36. package/src/customers.client.ts +66 -0
  37. package/src/files.client.ts +57 -0
  38. package/src/index.ts +9 -87
  39. package/src/{instance.ts → instance.client.ts} +4 -8
  40. package/src/reports.client.ts +34 -0
  41. package/src/socket-server.client.ts +32 -0
  42. package/src/socket.client.ts +78 -0
  43. package/src/types/auth.types.ts +31 -0
  44. package/src/types/customers.types.ts +68 -0
  45. package/src/types/files.types.ts +78 -0
  46. package/src/types/index.ts +7 -0
  47. package/src/types/reports.types.ts +24 -0
  48. package/src/types/socket-events.types.ts +76 -0
  49. package/src/types/socket-rooms.types.ts +31 -0
  50. package/src/{user.ts → types/user.types.ts} +1 -78
  51. package/src/users.client.ts +74 -0
  52. package/dist/auth.sdk.d.ts +0 -15
  53. package/dist/auth.sdk.js +0 -62
  54. package/dist/instance.sdk.d.ts +0 -10
  55. package/dist/instance.sdk.js +0 -27
  56. package/dist/socket-client.d.ts +0 -57
  57. package/dist/socket-client.js +0 -74
  58. package/dist/socket-server.d.ts +0 -17
  59. package/dist/socket-server.js +0 -22
  60. package/dist/src/sdks/auth.sdk.js +0 -52
  61. package/dist/src/sdks/index.js +0 -14
  62. package/dist/src/sdks/instance.sdk.js +0 -31
  63. package/dist/src/sdks/user.sdk.js +0 -42
  64. package/dist/src/types/user.types.js +0 -2
  65. package/dist/types/socket-client.types.d.ts +0 -97
  66. package/dist/types/socket-client.types.js +0 -2
  67. package/dist/types/socket-server.types.d.ts +0 -120
  68. package/dist/types/socket-server.types.js +0 -2
  69. package/dist/user.sdk.d.ts +0 -14
  70. package/dist/user.sdk.js +0 -39
  71. package/src/customer.ts +0 -140
  72. package/src/file.ts +0 -145
  73. package/src/report.ts +0 -60
  74. package/src/socket-client.ts +0 -78
  75. package/src/socket-server.ts +0 -20
  76. package/src/types/socket-client.types.ts +0 -114
  77. package/src/types/socket-server.types.ts +0 -171
  78. /package/dist/{src/types → types}/auth.types.js +0 -0
  79. /package/dist/{response.js → types/customers.types.js} +0 -0
  80. /package/dist/{src/types/index.js → types/reports.types.js} +0 -0
  81. /package/dist/{response.d.ts → types/response.types.d.ts} +0 -0
  82. /package/dist/{src/types → types}/response.types.js +0 -0
  83. /package/dist/{src/types/instance.types.js → types/socket-rooms.types.js} +0 -0
  84. /package/src/{response.ts → types/response.types.ts} +0 -0
package/src/index.ts CHANGED
@@ -1,87 +1,9 @@
1
- import AuthSDK, { LoginData, SessionData } from "./auth";
2
- import FileSDK, { File, FileDirType } from "./file";
3
- import InstanceSDK from "./instance";
4
- import UserSDK, { CreateUserDTO, UpdateUserDTO, User, UserRole } from "./user";
5
- import CustomerSDK, { Customer, CreateCustomerDTO, UpdateCustomerDTO } from "./customer";
6
- import { DataResponse, ErrorResponse, PaginatedResponse, QueryResponse } from "./response";
7
- import ReportSDK, { ChatsReport, ChatsReportFormat, GenerateChatsReportOptions } from "./report";
8
- import SocketClientSDK from "./socket-client";
9
- import SocketServerSDK from "./socket-server";
10
- import {
11
- EmitFunction,
12
- ChatsReportStatusData,
13
- SocketServerAdminRoom,
14
- SocketServerMonitorRoom,
15
- SocketServerReportsRoom,
16
- SocketServerRoom,
17
- ChatId,
18
- QRCode,
19
- SocketEventType,
20
- } from "./types/socket-server.types";
21
- import {
22
- SocketClientChatRoom,
23
- SocketClientAdminRoom,
24
- SocketClientMonitorRoom,
25
- SocketClientReportsRoom,
26
- SocketClientRoom,
27
- } from "./types/socket-client.types";
28
-
29
- export {
30
- // Auth
31
- AuthSDK,
32
- LoginData,
33
- SessionData,
34
-
35
- // File
36
- FileSDK,
37
- File,
38
- FileDirType,
39
-
40
- // Instance
41
- InstanceSDK,
42
-
43
- // User
44
- UserSDK,
45
- CreateUserDTO,
46
- UpdateUserDTO,
47
- User,
48
- UserRole,
49
-
50
- // Customer
51
- CustomerSDK,
52
- Customer,
53
- CreateCustomerDTO,
54
- UpdateCustomerDTO,
55
-
56
- // Response
57
- DataResponse,
58
- ErrorResponse,
59
- PaginatedResponse,
60
- QueryResponse,
61
-
62
- // Report
63
- ReportSDK,
64
- ChatsReport,
65
- ChatsReportFormat as ChatsReportFileFormat,
66
- GenerateChatsReportOptions,
67
-
68
- // Socket Client
69
- SocketClientSDK,
70
- SocketClientChatRoom as SocketChatRoom,
71
- SocketClientAdminRoom,
72
- SocketClientMonitorRoom,
73
- SocketClientReportsRoom,
74
- SocketClientRoom,
75
-
76
- // Socket Server
77
- SocketServerSDK,
78
- EmitFunction,
79
- SocketEventType,
80
- ChatsReportStatusData,
81
- SocketServerAdminRoom,
82
- SocketServerMonitorRoom,
83
- SocketServerReportsRoom,
84
- SocketServerRoom,
85
- ChatId,
86
- QRCode,
87
- };
1
+ export * from "./types";
2
+ export { default as AuthClient } from "./auth.client";
3
+ export { default as CustomersClient } from "./customers.client";
4
+ export { default as FilesClient } from "./files.client";
5
+ export { default as InstancesClient } from "./instance.client";
6
+ export { default as ReportsClient } from "./reports.client";
7
+ export { default as SocketServerClient } from "./socket-server.client";
8
+ export { default as SocketClient } from "./socket.client";
9
+ export { default as UsersClient } from "./users.client";
@@ -1,15 +1,11 @@
1
1
  import { AxiosInstance } from "axios";
2
- import { QueryResponse } from "./response";
2
+ import { QueryResponse } from "./types/response.types";
3
+ import ApiClient from "./api-client";
3
4
 
4
5
  /**
5
6
  * Classe InstanceSDK para interagir com a API de instâncias.
6
7
  */
7
- class InstanceSDK {
8
- /**
9
- * Cria uma instância do SDK de instância.
10
- * @param {AxiosInstance} httpClient A instância do cliente HTTP a ser usada para fazer requisições à API.
11
- */
12
- constructor(private readonly httpClient: AxiosInstance) { }
8
+ class InstancesClient extends ApiClient {
13
9
 
14
10
  /**
15
11
  * Executa uma consulta na instância especificada.
@@ -41,4 +37,4 @@ class InstanceSDK {
41
37
  }
42
38
  }
43
39
 
44
- export default InstanceSDK;
40
+ export default InstancesClient;
@@ -0,0 +1,34 @@
1
+ import ApiClient from "./api-client";
2
+ import { ChatsReport, GenerateChatsReportOptions } from "./types/reports.types";
3
+ import { DataResponse, MessageResponse } from "./types/response.types";
4
+
5
+ export default class ReportsClient extends ApiClient {
6
+ public async getChatsReports() {
7
+ const url = `/reports/chats`;
8
+ const response =
9
+ await this.httpClient.get<DataResponse<Array<ChatsReport>>>(url);
10
+
11
+ return response.data;
12
+ }
13
+
14
+ public async generateChatsReport(body: GenerateChatsReportOptions) {
15
+ const url = `/reports/chats`;
16
+ const response = await this.httpClient.post<DataResponse<ChatsReport>>(
17
+ url,
18
+ body,
19
+ );
20
+
21
+ return response.data;
22
+ }
23
+
24
+ public async deleteChatsReport(chatsReportId: number) {
25
+ const url = `/reports/chats/${chatsReportId}`;
26
+ const response = await this.httpClient.delete<MessageResponse>(url);
27
+
28
+ return response.data;
29
+ }
30
+
31
+ public setAuth(token: string) {
32
+ this.httpClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
33
+ }
34
+ }
@@ -0,0 +1,32 @@
1
+ import { EmitSocketEventFn } from "./types/socket-events.types";
2
+ import ApiClient from "./api-client";
3
+ import { MessageResponse } from "./types/response.types";
4
+
5
+ /**
6
+ * A client for interacting with a socket server API.
7
+ * Extends the `ApiClient` class to provide http functionality
8
+ * for emitting events to specific rooms on the server.
9
+ */
10
+ export default class SocketServerApi extends ApiClient {
11
+ /**
12
+ * Creates an instance of the SocketServerApiClient.
13
+ *
14
+ * @param baseUrl - The base URL for the socket server API.
15
+ */
16
+ constructor(baseUrl: string) {
17
+ super(baseUrl);
18
+ }
19
+
20
+ /**
21
+ * Emits a socket event to a specified room with a given event name and value.
22
+ *
23
+ * @param event - The name of the event to emit.
24
+ * @param room - The name of the room to which the event should be emitted.
25
+ * @param value - The payload or data to send with the event.
26
+ * @returns A promise that resolves with the response from the API call.
27
+ */
28
+ public emit: EmitSocketEventFn = (event, room, value) => {
29
+ return this.httpClient.post<MessageResponse>(`/emit/${room}/${event}`, value)
30
+ .then(res => res.data);
31
+ }
32
+ }
@@ -0,0 +1,78 @@
1
+ import { io, Socket } from "socket.io-client";
2
+ import { ListenSocketEventFn, SocketEventType, UnlistenSocketEventFn } from "./types/socket-events.types";
3
+
4
+ /**
5
+ * A client for interacting with a WebSocket server.
6
+ * This class provides methods to connect to the server, listen for events,
7
+ * and manage WebSocket connections.
8
+ */
9
+ export default class SocketClient {
10
+ private readonly ws: Socket;
11
+ private readonly listeners: Map<SocketEventType, any> = new Map();
12
+
13
+ /**
14
+ * Initializes a new instance of the socket client.
15
+ *
16
+ * @param baseUrl - The base URL of the WebSocket server to connect to.
17
+ * This URL is used to establish the WebSocket connection.
18
+ *
19
+ * The WebSocket client is configured with the following options:
20
+ * - `autoConnect`: Disabled by default to allow manual connection control.
21
+ * - `transports`: Uses the 'websocket' transport protocol exclusively.
22
+ */
23
+ constructor(baseUrl: string) {
24
+ this.ws = io(baseUrl, {
25
+ autoConnect: false,
26
+ transports: ['websocket'],
27
+ });
28
+ }
29
+
30
+ /**
31
+ * Establishes a WebSocket connection using the provided authentication token.
32
+ *
33
+ * @param token - The authentication token to be used for the WebSocket connection.
34
+ * This token is sent as part of the WebSocket authentication payload.
35
+ */
36
+ public connect(token: string) {
37
+ this.ws.auth = { token };
38
+ this.ws.connect();
39
+ }
40
+
41
+ /**
42
+ * Disconnects the WebSocket client from the server.
43
+ * This method terminates the current WebSocket connection
44
+ * by invoking the `disconnect` method on the WebSocket instance.
45
+ */
46
+ public disconnect() {
47
+ this.ws.disconnect();
48
+ }
49
+
50
+ /**
51
+ * Registers an event listener for a specified WebSocket event and provides a way to remove it.
52
+ *
53
+ * @param event - The name of the WebSocket event to listen for.
54
+ * @param callback - A function to be executed when the event is triggered. The function receives the event data as its argument.
55
+ * @returns A function that, when called, removes the event listener for the specified event.
56
+ */
57
+ public on: ListenSocketEventFn = (event, callback) => {
58
+ if (!this.listeners.get(event)) {
59
+ this.ws.on(event, (data) => {
60
+ callback(data);
61
+ });
62
+
63
+ this.listeners.set(event, callback);
64
+ }
65
+ }
66
+
67
+ /**
68
+ * Removes a previously registered event listener from the WebSocket connection.
69
+ *
70
+ * @param event - The name of the event to stop listening for.
71
+ * @param callback - The callback function that was previously registered for the event.
72
+ */
73
+ public off: UnlistenSocketEventFn = (event) => {
74
+ const listener = this.listeners.get(event);
75
+ if (!listener) return;
76
+ this.ws.off(event, listener);
77
+ }
78
+ }
@@ -0,0 +1,31 @@
1
+ import { User } from "./user.types";
2
+
3
+ export interface LoginData {
4
+ /**
5
+ * Token de autenticação.
6
+ */
7
+ token: string;
8
+ /**
9
+ * Dados do usuário.
10
+ */
11
+ user: User;
12
+ }
13
+
14
+ export interface SessionData {
15
+ /**
16
+ * ID do usuário.
17
+ */
18
+ userId: number;
19
+ /**
20
+ * ID do setor do usuário.
21
+ */
22
+ sectorId: number
23
+ /**
24
+ * Papel do usuário.
25
+ */
26
+ role: string;
27
+ /**
28
+ * Nome da instância.
29
+ */
30
+ instance: string;
31
+ }
@@ -0,0 +1,68 @@
1
+ export interface Customer {
2
+ CODIGO: number;
3
+ RAZAO: string;
4
+ FANTASIA: string;
5
+ PESSOA: 'FIS' | 'JUR' | null;
6
+ ATIVO: 'SIM' | 'NAO' | null;
7
+ CPF_CNPJ: string;
8
+ IE_RG: string;
9
+ GRUPO: number;
10
+ END_RUA: string;
11
+ CIDADE: string;
12
+ BAIRRO: string;
13
+ ESTADO: string;
14
+ CEP: string;
15
+ COMPLEMENTO: string;
16
+ AREA1: number;
17
+ AREA2: number;
18
+ AREA3: number;
19
+ AREAFAX: number;
20
+ FONE1: string;
21
+ FONE2: string;
22
+ FONE3: string;
23
+ FAX: string;
24
+ DESC_FONE1: string;
25
+ DESC_FONE2: string;
26
+ DESC_FONE3: string;
27
+ DESCFAX: string;
28
+ EMAIL: string;
29
+ WEBSITE: string;
30
+ DATACAD: Date;
31
+ STATUS_CAD: string;
32
+ OBS_ADMIN: string;
33
+ OBS_OPERADOR: string;
34
+ ORIGEM: number;
35
+ OPERADOR: number;
36
+ COD_MIDIA: number;
37
+ COD_ERP: string;
38
+ BLOCK_COMPRAS: 'SIM' | 'NAO' | null;
39
+ COD_UNIDADE: number;
40
+ SALDO_DISPONIVEL: number;
41
+ SALDO_LIMITE: number;
42
+ POTENCIAL: number;
43
+ DATA_ULT_COMPRA: Date;
44
+ SEGMENTO: number;
45
+ ULTI_RESULTADO: Date;
46
+ DT_AGENDAMENTO: Date;
47
+ COD_CAMPANHA: number;
48
+ COD_RESULTADO: number;
49
+ CONTATO_MAIL: string;
50
+ ATUALIZADOR: 'CADASTRO' | 'ATUALIZAÇÃO' | null;
51
+ OPERADOR_LOGIN: string;
52
+ OBS_FONE1: string;
53
+ OBS_FONE2: string;
54
+ OBS_FONE3: string;
55
+ NR_FUNCIONARIOS: number;
56
+ EMAIL2: string;
57
+ OBS_CLIENTES: string;
58
+ VENCIMENTO_LIMITE_CREDITO: Date;
59
+ PERIODO_RECOMPRA: number;
60
+ DT_ULTIMO_ORCAMENTO_VENDA: Date;
61
+ POSSUI_ORCAMENTO: 'S' | 'N' | null;
62
+ POSSUI_VENDA: 'S' | 'N' | null;
63
+ CODIGOPRINCIPAL: number;
64
+ SETOR: number;
65
+ }
66
+
67
+ export type CreateCustomerDTO = Pick<Customer, "RAZAO" | "FANTASIA" | "CPF_CNPJ" | "PESSOA" | "CIDADE" | "ESTADO" | "COD_ERP">;
68
+ export type UpdateCustomerDTO = Partial<CreateCustomerDTO>;
@@ -0,0 +1,78 @@
1
+ export interface UploadFileOptions {
2
+ /**
3
+ * Nome da instância onde o arquivo está armazenado.
4
+ */
5
+ instance: string;
6
+
7
+ /**
8
+ * Tipo de diretório onde o arquivo está armazenado.
9
+ */
10
+ dirType: FileDirType;
11
+
12
+ /**
13
+ * Nome do arquivo.
14
+ */
15
+ fileName: string;
16
+
17
+ /**
18
+ * Buffer com o conteúdo do arquivo.
19
+ */
20
+ buffer: Buffer;
21
+ }
22
+
23
+ /**
24
+ * Enum que representa os tipos de diretórios de arquivos.
25
+ *
26
+ * @enum {string}
27
+ * @property {string} PUBLIC - Representa o diretório público.
28
+ * @property {string} MODELS - Representa o diretório de modelos.
29
+ */
30
+ export enum FileDirType {
31
+ PUBLIC = "public",
32
+ MODELS = "models",
33
+ }
34
+
35
+ /**
36
+ * Representa um arquivo no sistema.
37
+ */
38
+ export interface File {
39
+ /**
40
+ * Identificador único para o arquivo.
41
+ */
42
+ id: number;
43
+
44
+ /**
45
+ * Identificador único para o arquivo no armazenamento.
46
+ */
47
+ id_storage: string;
48
+
49
+ /**
50
+ * Identificador único para o armazenamento.
51
+ */
52
+ storage_id: number;
53
+
54
+ /**
55
+ * Nome do arquivo.
56
+ */
57
+ name: string;
58
+
59
+ /**
60
+ * Tipo MIME do arquivo.
61
+ */
62
+ mime_type: string;
63
+
64
+ /**
65
+ * Tamanho do arquivo em bytes.
66
+ */
67
+ size: number;
68
+
69
+ /**
70
+ * Tipo de diretório onde o arquivo está armazenado.
71
+ */
72
+ dir_type: FileDirType;
73
+
74
+ /**
75
+ * Data e hora em que o arquivo foi criado.
76
+ */
77
+ created_at: Date;
78
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./response.types";
2
+ export * from "./socket-events.types";
3
+ export * from "./socket-rooms.types";
4
+ export * from "./auth.types";
5
+ export * from "./user.types";
6
+ export * from "./customers.types";
7
+ export * from "./files.types";
@@ -0,0 +1,24 @@
1
+ export type ReportType = "chats";
2
+ export type ChatsReportFormat = "txt" | "csv" | "pdf";
3
+ export type ChatsReportStatus = "pending" | "completed" | "failed";
4
+
5
+ export interface ChatsReport {
6
+ id: number;
7
+ userId: string;
8
+ fileId: number;
9
+ instance: string;
10
+ startDate: string;
11
+ endDate: string;
12
+ exportDate: string;
13
+ chats: number;
14
+ messages: number;
15
+ format: ChatsReportFormat;
16
+ status: ChatsReportStatus;
17
+ }
18
+
19
+ export interface GenerateChatsReportOptions {
20
+ userId: string;
21
+ format: ChatsReportFormat;
22
+ startDate: string;
23
+ endDate: string;
24
+ }
@@ -0,0 +1,76 @@
1
+ import { SocketServerAdminRoom, SocketServerChatRoom, SocketServerReportsRoom, SocketServerRoom } from "./socket-rooms.types";
2
+ import { MessageResponse } from "./response.types";
3
+
4
+ export enum SocketEventType {
5
+ WppChatStarted = "wpp_chat_started",
6
+ WppChatFinished = "wpp_chat_finished",
7
+ WppMessage = "wpp_message",
8
+ WppMessageStatus = "wpp_message_status",
9
+ WppMessageReaction = "wpp_message_reaction",
10
+ WwebjsQr = "wwebjs_qr",
11
+ WwebjsAuth = "wwebjs_auth",
12
+ ReportStatus = "report_status"
13
+ }
14
+
15
+ export interface EmitSocketEventFn {
16
+ (type: SocketEventType.WwebjsQr, room: SocketServerAdminRoom, data: WWEBJSQrEventData): Promise<MessageResponse>;
17
+ (type: SocketEventType.WwebjsAuth, room: SocketServerAdminRoom, data: WWEBJSAuthEventData): Promise<MessageResponse>;
18
+ (type: SocketEventType.WppChatStarted, room: SocketServerRoom, data: WppChatStartedEventData): Promise<MessageResponse>;
19
+ (type: SocketEventType.WppChatFinished, room: SocketServerRoom, data: WppChatFinishedEventData): Promise<MessageResponse>;
20
+ (type: SocketEventType.WppMessage, room: SocketServerChatRoom, data: WppMessageEventData): Promise<MessageResponse>;
21
+ (type: SocketEventType.WppMessageStatus, room: SocketServerChatRoom, data: WppMessageStatusEventData): Promise<MessageResponse>;
22
+ (type: SocketEventType.WppMessageReaction, room: SocketServerChatRoom, data: WppMessageReactionEventData): Promise<MessageResponse>;
23
+ (type: SocketEventType.ReportStatus, room: SocketServerReportsRoom, data: ReportStatusEventData): Promise<MessageResponse>;
24
+ }
25
+
26
+ export interface ListenSocketEventFn {
27
+ (type: SocketEventType.WwebjsQr, callback: (data: WWEBJSQrEventData) => void): void;
28
+ (type: SocketEventType.WwebjsAuth, callback: (data: WWEBJSAuthEventData) => void): void;
29
+ (type: SocketEventType.WppChatStarted, callback: (data: WppChatStartedEventData) => void): void;
30
+ (type: SocketEventType.WppChatFinished, callback: (data: WppChatFinishedEventData) => void): void;
31
+ (type: SocketEventType.WppMessage, callback: (data: WppMessageEventData) => void): void;
32
+ (type: SocketEventType.WppMessageStatus, callback: (data: WppMessageStatusEventData) => void): void;
33
+ (type: SocketEventType.WppMessageReaction, callback: (data: WppMessageReactionEventData) => void): void;
34
+ (type: SocketEventType.ReportStatus, callback: (data: ReportStatusEventData) => void): void;
35
+ }
36
+
37
+ export interface UnlistenSocketEventFn {
38
+ (type: SocketEventType): void;
39
+ }
40
+
41
+ // EventData
42
+ export interface WWEBJSQrEventData {
43
+ qr: string;
44
+ phone: string;
45
+ }
46
+
47
+ export interface WWEBJSAuthEventData {
48
+ phone: string;
49
+ success: boolean;
50
+ message?: string;
51
+ }
52
+
53
+ export interface WppChatStartedEventData { };
54
+ export interface WppChatFinishedEventData { };
55
+ export interface WppMessageEventData { };
56
+ export interface WppMessageStatusEventData { };
57
+ export interface WppMessageReactionEventData { };
58
+
59
+ export type ReportStatusEventData = {
60
+ id: number;
61
+ type: string;
62
+ } & ({
63
+ isCompleted: true;
64
+ isFailed: false;
65
+ fileId: number;
66
+ chats: number;
67
+ messages: number;
68
+ } | {
69
+ isCompleted: false;
70
+ isFailed: true;
71
+ error: string;
72
+ } | {
73
+ isCompleted: false;
74
+ isFailed: false;
75
+ progress: number;
76
+ });
@@ -0,0 +1,31 @@
1
+ type ReportType = "chats";
2
+ type PhoneNumber = string;
3
+
4
+ /*
5
+ Salas de Socket do lado do cliente;
6
+ Essas salas omitem o nome da instancia e/ou id do setor,
7
+ pois isso é controlado pelo servidor;
8
+ */
9
+ export type SocketClientChatRoom = `chat:${PhoneNumber}`;
10
+ export type SocketClientAdminRoom = "admin";
11
+ export type SocketClientMonitorRoom = `monitor`;
12
+ export type SocketClientReportsRoom = `reports:${ReportType}`;
13
+ export type SocketClientRoom = SocketClientChatRoom | SocketClientAdminRoom | SocketClientReportsRoom | SocketClientMonitorRoom;
14
+
15
+ // Interface que incluí o nome da instancia na sala de socket;
16
+ type SocketRoomWithInstance<T extends string> = `${string}:${T}`;
17
+
18
+ // Interface que incluí o nome da instancia e o id do setor na sala de socket;
19
+ type SocketRoomWithSector<T extends string> = SocketRoomWithInstance<`${number}:${T}`>;
20
+
21
+ /*
22
+ Salas de Socket do lado do servidor;
23
+ Essas salas incluem o nome da instancia e o id do setor,
24
+ Permitindo que cada instancia consiga ver apenas o que lhe
25
+ pertence, e não as salas de outras instancias.
26
+ */
27
+ export type SocketServerAdminRoom = SocketRoomWithSector<SocketClientAdminRoom>;
28
+ export type SocketServerMonitorRoom = SocketRoomWithSector<SocketClientMonitorRoom>;
29
+ export type SocketServerReportsRoom = SocketRoomWithSector<SocketClientReportsRoom>;
30
+ export type SocketServerChatRoom = SocketRoomWithInstance<SocketClientChatRoom>;
31
+ export type SocketServerRoom = SocketServerChatRoom | SocketServerAdminRoom | SocketServerMonitorRoom | SocketServerReportsRoom;
@@ -1,6 +1,3 @@
1
- import { AxiosInstance } from "axios";
2
- import { DataResponse, PaginatedResponse } from "./response";
3
-
4
1
  /**
5
2
  * Enum que representa os diferentes papéis de usuário dentro do sistema.
6
3
  *
@@ -158,78 +155,4 @@ export interface CreateUserDTO {
158
155
  /**
159
156
  * Interface que representa o objeto de transferência de dados para atualizar um usuário.
160
157
  */
161
- export type UpdateUserDTO = Partial<CreateUserDTO>;
162
-
163
- /**
164
- * SDK para operações de usuários.
165
- */
166
- class UserSDK {
167
- /**
168
- * Cria uma instância do SDK de usuários.
169
- * @param httpClient - A instância do cliente HTTP a ser usada para fazer requisições à API.
170
- */
171
- constructor(private readonly httpClient: AxiosInstance) { }
172
-
173
- /**
174
- * Obtém a lista de usuários.
175
- * @returns Uma resposta paginada contendo os usuários.
176
- */
177
- public async getUsers() {
178
- const response = await this.httpClient.get<PaginatedResponse<User>>(`/users`);
179
-
180
- return response.data;
181
- }
182
-
183
- /**
184
- * Obtém um usuário pelo ID.
185
- * @param userId - O ID do usuário.
186
- * @returns Uma resposta contendo os dados do usuário.
187
- */
188
- public async getUserById(userId: number) {
189
- const response = await this.httpClient.get<DataResponse<User>>(`/users/${userId}`);
190
-
191
- return response.data;
192
- }
193
-
194
- /**
195
- * Cria um novo usuário.
196
- * @param data - Os dados para criação do usuário.
197
- * @returns Uma resposta contendo os dados do usuário criado.
198
- * @throws Um erro se a criação do usuário falhar.
199
- */
200
- public async createUser(data: CreateUserDTO) {
201
- try {
202
- const response = await this.httpClient.post<DataResponse<User>>(`/users`, data);
203
-
204
- return response.data;
205
- } catch (error) {
206
- throw new Error("Failed to create user", { cause: error });
207
- }
208
- }
209
-
210
- /**
211
- * Atualiza um usuário existente.
212
- * @param userId - O ID do usuário.
213
- * @param data - Os dados para atualização do usuário.
214
- * @returns Uma resposta contendo os dados do usuário atualizado.
215
- * @throws Um erro se a atualização do usuário falhar.
216
- */
217
- public async updateUser(userId: string, data: UpdateUserDTO) {
218
- try {
219
- const response = await this.httpClient.patch<DataResponse<User>>(
220
- `/users/${userId}`,
221
- data,
222
- );
223
-
224
- return response.data;
225
- } catch (error) {
226
- throw new Error("Failed to update user", { cause: error });
227
- }
228
- }
229
-
230
- public setAuth(token: string) {
231
- this.httpClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
232
- }
233
- }
234
-
235
- export default UserSDK;
158
+ export type UpdateUserDTO = Partial<CreateUserDTO>;