@in.pulse-crm/sdk 2.2.13 → 2.3.1

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.
@@ -1,4 +1,3 @@
1
- import { DataResponse } from "./types/response.types";
2
1
  import ApiClient from "./api-client";
3
2
  import { LoginData, SessionData, UserOnlineSession } from "./types/auth.types";
4
3
  /**
@@ -7,31 +6,31 @@ import { LoginData, SessionData, UserOnlineSession } from "./types/auth.types";
7
6
  export default class AuthClient extends ApiClient {
8
7
  /**
9
8
  * Realiza o login do usuário.
10
- * @param {string} instance Nome da instância do Inpulse.
11
- * @param {string} username Nome de usuário.
12
- * @param {string} password Senha do usuário.
13
- * @returns {Promise<DataResponse<LoginData>>} Dados de login.
9
+ * @param instance Nome da instância do Inpulse.
10
+ * @param username Nome de usuário.
11
+ * @param password Senha do usuário.
12
+ * @returns Dados de login.
14
13
  */
15
- login(instance: string, username: string, password: string): Promise<DataResponse<LoginData>>;
14
+ login(instance: string, username: string, password: string): Promise<LoginData>;
16
15
  /**
17
16
  * Busca os dados da sessão.
18
- * @param {string} authToken Token de autenticação.
19
- * @returns {Promise<DataResponse<AuthTypes.SessionData>>} Dados da sessão.
17
+ * @param authToken Token de autenticação.
18
+ * @returns Dados da sessão.
20
19
  */
21
- fetchSessionData(authToken: string): Promise<DataResponse<SessionData>>;
20
+ fetchSessionData(authToken: string): Promise<SessionData>;
22
21
  /**
23
22
  * Verifica se o usuário está autenticado.
24
- * @param {string} instanceName Nome da instância do Inpulse.
25
- * @param {string} authToken Token de autenticação.
26
- * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autenticado, falso caso contrário.
23
+ * @param instanceName Nome da instância do Inpulse.
24
+ * @param authToken Token de autenticação.
25
+ * @returns Verdadeiro se o usuário estiver autenticado, falso caso contrário.
27
26
  */
28
27
  isAuthenticated(instanceName: string, authToken: string): Promise<boolean>;
29
28
  /**
30
29
  * Verifica se o usuário está autorizado.
31
- * @param {string} instanceName Nome da instância do Inpulse.
32
- * @param {string} authToken Token de autenticação.
33
- * @param {string[]} authorizedRoles Lista de papéis autorizados.
34
- * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autorizado, falso caso contrário.
30
+ * @param instanceName Nome da instância do Inpulse.
31
+ * @param authToken Token de autenticação.
32
+ * @param authorizedRoles Lista de papéis autorizados.
33
+ * @returns Verdadeiro se o usuário estiver autorizado, falso caso contrário.
35
34
  */
36
35
  isAuthorized(instanceName: string, authToken: string, authorizedRoles: string[]): Promise<boolean>;
37
36
  getOnlineSessions(instance: string): Promise<UserOnlineSession[]>;
@@ -11,22 +11,22 @@ const api_client_1 = __importDefault(require("./api-client"));
11
11
  class AuthClient extends api_client_1.default {
12
12
  /**
13
13
  * Realiza o login do usuário.
14
- * @param {string} instance Nome da instância do Inpulse.
15
- * @param {string} username Nome de usuário.
16
- * @param {string} password Senha do usuário.
17
- * @returns {Promise<DataResponse<LoginData>>} Dados de login.
14
+ * @param instance Nome da instância do Inpulse.
15
+ * @param username Nome de usuário.
16
+ * @param password Senha do usuário.
17
+ * @returns Dados de login.
18
18
  */
19
19
  async login(instance, username, password) {
20
- const response = await this.httpClient.post(`/api/auth/login`, { LOGIN: username, SENHA: password, instance });
21
- return response.data;
20
+ const { data: res } = await this.httpClient.post(`/api/auth/login`, { LOGIN: username, SENHA: password, instance });
21
+ return res.data;
22
22
  }
23
23
  /**
24
24
  * Busca os dados da sessão.
25
- * @param {string} authToken Token de autenticação.
26
- * @returns {Promise<DataResponse<AuthTypes.SessionData>>} Dados da sessão.
25
+ * @param authToken Token de autenticação.
26
+ * @returns Dados da sessão.
27
27
  */
28
28
  async fetchSessionData(authToken) {
29
- const response = await this.httpClient
29
+ const { data: res } = await this.httpClient
30
30
  .get(`/api/auth/session`, {
31
31
  headers: {
32
32
  authorization: authToken,
@@ -36,18 +36,18 @@ class AuthClient extends api_client_1.default {
36
36
  const message = (0, utils_1.sanitizeErrorMessage)(error);
37
37
  throw new Error("Failed to fetch session data! " + message);
38
38
  });
39
- return response.data;
39
+ return res.data;
40
40
  }
41
41
  /**
42
42
  * Verifica se o usuário está autenticado.
43
- * @param {string} instanceName Nome da instância do Inpulse.
44
- * @param {string} authToken Token de autenticação.
45
- * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autenticado, falso caso contrário.
43
+ * @param instanceName Nome da instância do Inpulse.
44
+ * @param authToken Token de autenticação.
45
+ * @returns Verdadeiro se o usuário estiver autenticado, falso caso contrário.
46
46
  */
47
47
  async isAuthenticated(instanceName, authToken) {
48
48
  try {
49
- const { data } = await this.fetchSessionData(authToken);
50
- return !!data.userId && data.instance === instanceName;
49
+ const session = await this.fetchSessionData(authToken);
50
+ return !!session.userId && session.instance === instanceName;
51
51
  }
52
52
  catch {
53
53
  return false;
@@ -55,28 +55,28 @@ class AuthClient extends api_client_1.default {
55
55
  }
56
56
  /**
57
57
  * Verifica se o usuário está autorizado.
58
- * @param {string} instanceName Nome da instância do Inpulse.
59
- * @param {string} authToken Token de autenticação.
60
- * @param {string[]} authorizedRoles Lista de papéis autorizados.
61
- * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autorizado, falso caso contrário.
58
+ * @param instanceName Nome da instância do Inpulse.
59
+ * @param authToken Token de autenticação.
60
+ * @param authorizedRoles Lista de papéis autorizados.
61
+ * @returns Verdadeiro se o usuário estiver autorizado, falso caso contrário.
62
62
  */
63
63
  async isAuthorized(instanceName, authToken, authorizedRoles) {
64
64
  try {
65
- const { data } = await this.fetchSessionData(authToken);
66
- return (authorizedRoles.includes(data.role) &&
67
- data.instance === instanceName);
65
+ const session = await this.fetchSessionData(authToken);
66
+ return (authorizedRoles.includes(session.role) &&
67
+ session.instance === instanceName);
68
68
  }
69
69
  catch {
70
70
  return false;
71
71
  }
72
72
  }
73
73
  async getOnlineSessions(instance) {
74
- const response = await this.httpClient.get("/api/online-sessions", {
74
+ const { data: res } = await this.httpClient.get("/api/online-sessions", {
75
75
  params: {
76
76
  instance,
77
77
  },
78
78
  });
79
- return response.data.data;
79
+ return res.data;
80
80
  }
81
81
  async initOnlineSession(authToken) {
82
82
  await this.httpClient.post("/api/online-sessions", {}, {
@@ -1,6 +1,5 @@
1
1
  import ApiClient from "./api-client";
2
2
  import { ChatsReport, GenerateChatsReportOptions } from "./types/reports.types";
3
- import { DataResponse, MessageResponse } from "./types/response.types";
4
3
  /**
5
4
  * ReportsClient class to handle reports related API calls.
6
5
  *
@@ -13,21 +12,20 @@ export default class ReportsClient extends ApiClient {
13
12
  *
14
13
  * @returns A promise that resolves to an array of chat reports wrapped in a `DataResponse` object.
15
14
  */
16
- getChatsReports(): Promise<DataResponse<ChatsReport[]>>;
15
+ getChatsReports(): Promise<ChatsReport[]>;
17
16
  /**
18
17
  * Generates a report for chat interactions based on the provided options.
19
18
  *
20
19
  * @param body - The options for generating the chats report, including filters and parameters.
21
20
  * @returns A promise that resolves to the data of the generated chats report.
22
21
  */
23
- generateChatsReport(body: GenerateChatsReportOptions): Promise<DataResponse<ChatsReport>>;
22
+ generateChatsReport(body: GenerateChatsReportOptions): Promise<ChatsReport>;
24
23
  /**
25
24
  * Deletes a chat report by its unique identifier.
26
25
  *
27
26
  * @param chatsReportId - The unique identifier of the chat report to be deleted.
28
- * @returns A promise that resolves to a `MessageResponse` object containing the result of the deletion operation.
29
27
  */
30
- deleteChatsReport(chatsReportId: number): Promise<MessageResponse>;
28
+ deleteChatsReport(chatsReportId: number): Promise<void>;
31
29
  /**
32
30
  * Sets the authorization token for the HTTP client.
33
31
  *
@@ -18,8 +18,8 @@ class ReportsClient extends api_client_1.default {
18
18
  */
19
19
  async getChatsReports() {
20
20
  const url = `/api/reports/chats`;
21
- const response = await this.httpClient.get(url);
22
- return response.data;
21
+ const { data: res } = await this.httpClient.get(url);
22
+ return res.data;
23
23
  }
24
24
  /**
25
25
  * Generates a report for chat interactions based on the provided options.
@@ -29,19 +29,17 @@ class ReportsClient extends api_client_1.default {
29
29
  */
30
30
  async generateChatsReport(body) {
31
31
  const url = `/api/reports/chats`;
32
- const response = await this.httpClient.post(url, body);
33
- return response.data;
32
+ const { data: res } = await this.httpClient.post(url, body);
33
+ return res.data;
34
34
  }
35
35
  /**
36
36
  * Deletes a chat report by its unique identifier.
37
37
  *
38
38
  * @param chatsReportId - The unique identifier of the chat report to be deleted.
39
- * @returns A promise that resolves to a `MessageResponse` object containing the result of the deletion operation.
40
39
  */
41
40
  async deleteChatsReport(chatsReportId) {
42
41
  const url = `/api/reports/chats/${chatsReportId}`;
43
- const response = await this.httpClient.delete(url);
44
- return response.data;
42
+ await this.httpClient.delete(url);
45
43
  }
46
44
  /**
47
45
  * Sets the authorization token for the HTTP client.
@@ -26,7 +26,7 @@ export interface User {
26
26
  /** Login do usuário */
27
27
  LOGIN: string;
28
28
  /** Email do usuário */
29
- EMAIl: string;
29
+ EMAIL: string;
30
30
  /** Nível de acesso do usuário */
31
31
  NIVEL: UserRole | null;
32
32
  /** Horário de trabalho do usuário */
@@ -1,4 +1,3 @@
1
- import { DataResponse, PaginatedResponse } from "./types/response.types";
2
1
  import { CreateUserDTO, UpdateUserDTO, User } from "./types/user.types";
3
2
  import ApiClient from "./api-client";
4
3
  import { RequestFilters } from "./types";
@@ -11,20 +10,20 @@ export default class UsersClient extends ApiClient {
11
10
  * @param filters - Filtros opcionais para a query.
12
11
  * @returns Uma resposta paginada contendo os usuários.
13
12
  */
14
- getUsers(filters?: RequestFilters<User>): Promise<PaginatedResponse<User>>;
13
+ getUsers(filters?: RequestFilters<User>): Promise<User[]>;
15
14
  /**
16
15
  * Obtém um usuário pelo ID.
17
16
  * @param userId - O ID do usuário.
18
17
  * @returns Uma resposta contendo os dados do usuário.
19
18
  */
20
- getUserById(userId: number): Promise<DataResponse<User>>;
19
+ getUserById(userId: number): Promise<User>;
21
20
  /**
22
21
  * Cria um novo usuário.
23
22
  * @param data - Os dados para criação do usuário.
24
23
  * @returns Uma resposta contendo os dados do usuário criado.
25
24
  * @throws Um erro se a criação do usuário falhar.
26
25
  */
27
- createUser(data: CreateUserDTO): Promise<DataResponse<User>>;
26
+ createUser(data: CreateUserDTO): Promise<User>;
28
27
  /**
29
28
  * Atualiza um usuário existente.
30
29
  * @param userId - O ID do usuário.
@@ -32,7 +31,7 @@ export default class UsersClient extends ApiClient {
32
31
  * @returns Uma resposta contendo os dados do usuário atualizado.
33
32
  * @throws Um erro se a atualização do usuário falhar.
34
33
  */
35
- updateUser(userId: string, data: UpdateUserDTO): Promise<DataResponse<User>>;
34
+ updateUser(userId: string, data: UpdateUserDTO): Promise<User>;
36
35
  /**
37
36
  * Sets the authorization token for HTTP requests.
38
37
  *
@@ -19,8 +19,8 @@ class UsersClient extends api_client_1.default {
19
19
  if (params.toString()) {
20
20
  baseUrl += `?${params.toString()}`;
21
21
  }
22
- const response = await this.httpClient.get(`/api/users`);
23
- return response.data;
22
+ const { data: res } = await this.httpClient.get(`/api/users`);
23
+ return res.data;
24
24
  }
25
25
  /**
26
26
  * Obtém um usuário pelo ID.
@@ -28,8 +28,8 @@ class UsersClient extends api_client_1.default {
28
28
  * @returns Uma resposta contendo os dados do usuário.
29
29
  */
30
30
  async getUserById(userId) {
31
- const response = await this.httpClient.get(`/api/users/${userId}`);
32
- return response.data;
31
+ const { data: res } = await this.httpClient.get(`/api/users/${userId}`);
32
+ return res.data;
33
33
  }
34
34
  /**
35
35
  * Cria um novo usuário.
@@ -39,8 +39,8 @@ class UsersClient extends api_client_1.default {
39
39
  */
40
40
  async createUser(data) {
41
41
  try {
42
- const response = await this.httpClient.post(`/api/users`, data);
43
- return response.data;
42
+ const { data: res } = await this.httpClient.post(`/api/users`, data);
43
+ return res.data;
44
44
  }
45
45
  catch (error) {
46
46
  throw new Error("Failed to create user", { cause: error });
@@ -55,8 +55,8 @@ class UsersClient extends api_client_1.default {
55
55
  */
56
56
  async updateUser(userId, data) {
57
57
  try {
58
- const response = await this.httpClient.patch(`/api/users/${userId}`, data);
59
- return response.data;
58
+ const { data: res } = await this.httpClient.patch(`/api/users/${userId}`, data);
59
+ return res.data;
60
60
  }
61
61
  catch (error) {
62
62
  throw new Error("Failed to update user", { cause: error });
@@ -1,14 +1,10 @@
1
1
  import ApiClient from "./api-client";
2
- import { DataResponse } from "./types/response.types";
3
2
  import { WppChatsAndMessages, WppChatWithDetailsAndMessages, WppMessage, WppWallet } from "./types/whatsapp.types";
4
- type GetChatsResponse = DataResponse<WppChatsAndMessages>;
5
- type GetChatResponse = DataResponse<WppChatWithDetailsAndMessages>;
6
- type GetMessageResponse = DataResponse<WppMessage>;
7
3
  export default class WhatsappClient extends ApiClient {
8
- getChatsBySession(token: string, messages?: boolean, contact?: boolean): Promise<GetChatsResponse>;
9
- getChatById(id: number): Promise<GetChatResponse>;
10
- getMessageById(id: string): Promise<GetMessageResponse>;
11
- getUserWallets(instance: string, userId: number): Promise<DataResponse<WppWallet[]>>;
4
+ getChatsBySession(token: string, messages?: boolean, contact?: boolean): Promise<WppChatsAndMessages>;
5
+ getChatById(id: number): Promise<WppChatWithDetailsAndMessages>;
6
+ getMessageById(id: string): Promise<WppMessage>;
7
+ getUserWallets(instance: string, userId: number): Promise<WppWallet[]>;
8
+ markChatAsRead(chatId: number): Promise<WppMessage[]>;
12
9
  setAuth(token: string): void;
13
10
  }
14
- export {};
@@ -7,24 +7,30 @@ const api_client_1 = __importDefault(require("./api-client"));
7
7
  class WhatsappClient extends api_client_1.default {
8
8
  async getChatsBySession(token, messages = false, contact = false) {
9
9
  const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
10
- const { data } = await this.httpClient.get(url, {
10
+ const { data: res } = await this.httpClient.get(url, {
11
11
  headers: {
12
12
  Authorization: `Bearer ${token}`,
13
13
  },
14
14
  });
15
- return data;
15
+ return res.data;
16
16
  }
17
17
  async getChatById(id) {
18
- const { data } = await this.httpClient.get(`/api/whatsapp/chats/${id}`);
19
- return data;
18
+ const { data: res } = await this.httpClient.get(`/api/whatsapp/chats/${id}`);
19
+ return res.data;
20
20
  }
21
21
  async getMessageById(id) {
22
- const { data } = await this.httpClient.get(`/api/whatsapp/messages/${id}`);
23
- return data;
22
+ const { data: res } = await this.httpClient.get(`/api/whatsapp/messages/${id}`);
23
+ return res.data;
24
24
  }
25
25
  async getUserWallets(instance, userId) {
26
- const { data } = await this.httpClient.get(`/api/wallets?instance=${instance}&userId=${userId}`);
27
- return data;
26
+ const { data: res } = await this.httpClient.get(`/api/wallets?instance=${instance}&userId=${userId}`);
27
+ return res.data;
28
+ }
29
+ async markChatAsRead(chatId) {
30
+ const url = "/api/whatsapp/messages/mark-as-read";
31
+ const body = { chatId };
32
+ const { data: res } = await this.httpClient.post(url, body);
33
+ return res.data;
28
34
  }
29
35
  setAuth(token) {
30
36
  this.httpClient.defaults.headers.common["Authorization"] =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@in.pulse-crm/sdk",
3
- "version": "2.2.13",
3
+ "version": "2.3.1",
4
4
  "description": "SDKs for abstraction of api consumption of in.pulse-crm application",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -9,33 +9,26 @@ import { LoginData, SessionData, UserOnlineSession } from "./types/auth.types";
9
9
  export default class AuthClient extends ApiClient {
10
10
  /**
11
11
  * Realiza o login do usuário.
12
- * @param {string} instance Nome da instância do Inpulse.
13
- * @param {string} username Nome de usuário.
14
- * @param {string} password Senha do usuário.
15
- * @returns {Promise<DataResponse<LoginData>>} Dados de login.
12
+ * @param instance Nome da instância do Inpulse.
13
+ * @param username Nome de usuário.
14
+ * @param password Senha do usuário.
15
+ * @returns Dados de login.
16
16
  */
17
- public async login(
18
- instance: string,
19
- username: string,
20
- password: string,
21
- ): Promise<DataResponse<LoginData>> {
22
- const response = await this.httpClient.post<DataResponse<LoginData>>(
23
- `/api/auth/login`,
24
- { LOGIN: username, SENHA: password, instance },
25
- );
17
+ public async login(instance: string, username: string, password: string) {
18
+ const { data: res } = await this.httpClient.post<
19
+ DataResponse<LoginData>
20
+ >(`/api/auth/login`, { LOGIN: username, SENHA: password, instance });
26
21
 
27
- return response.data;
22
+ return res.data;
28
23
  }
29
24
 
30
25
  /**
31
26
  * Busca os dados da sessão.
32
- * @param {string} authToken Token de autenticação.
33
- * @returns {Promise<DataResponse<AuthTypes.SessionData>>} Dados da sessão.
27
+ * @param authToken Token de autenticação.
28
+ * @returns Dados da sessão.
34
29
  */
35
- public async fetchSessionData(
36
- authToken: string,
37
- ): Promise<DataResponse<SessionData>> {
38
- const response = await this.httpClient
30
+ public async fetchSessionData(authToken: string) {
31
+ const { data: res } = await this.httpClient
39
32
  .get<DataResponse<SessionData>>(`/api/auth/session`, {
40
33
  headers: {
41
34
  authorization: authToken,
@@ -46,23 +39,23 @@ export default class AuthClient extends ApiClient {
46
39
  throw new Error("Failed to fetch session data! " + message);
47
40
  });
48
41
 
49
- return response.data;
42
+ return res.data;
50
43
  }
51
44
 
52
45
  /**
53
46
  * Verifica se o usuário está autenticado.
54
- * @param {string} instanceName Nome da instância do Inpulse.
55
- * @param {string} authToken Token de autenticação.
56
- * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autenticado, falso caso contrário.
47
+ * @param instanceName Nome da instância do Inpulse.
48
+ * @param authToken Token de autenticação.
49
+ * @returns Verdadeiro se o usuário estiver autenticado, falso caso contrário.
57
50
  */
58
51
  public async isAuthenticated(
59
52
  instanceName: string,
60
53
  authToken: string,
61
54
  ): Promise<boolean> {
62
55
  try {
63
- const { data } = await this.fetchSessionData(authToken);
56
+ const session = await this.fetchSessionData(authToken);
64
57
 
65
- return !!data.userId && data.instance === instanceName;
58
+ return !!session.userId && session.instance === instanceName;
66
59
  } catch {
67
60
  return false;
68
61
  }
@@ -70,22 +63,22 @@ export default class AuthClient extends ApiClient {
70
63
 
71
64
  /**
72
65
  * Verifica se o usuário está autorizado.
73
- * @param {string} instanceName Nome da instância do Inpulse.
74
- * @param {string} authToken Token de autenticação.
75
- * @param {string[]} authorizedRoles Lista de papéis autorizados.
76
- * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autorizado, falso caso contrário.
66
+ * @param instanceName Nome da instância do Inpulse.
67
+ * @param authToken Token de autenticação.
68
+ * @param authorizedRoles Lista de papéis autorizados.
69
+ * @returns Verdadeiro se o usuário estiver autorizado, falso caso contrário.
77
70
  */
78
71
  public async isAuthorized(
79
72
  instanceName: string,
80
73
  authToken: string,
81
74
  authorizedRoles: string[],
82
- ): Promise<boolean> {
75
+ ) {
83
76
  try {
84
- const { data } = await this.fetchSessionData(authToken);
77
+ const session = await this.fetchSessionData(authToken);
85
78
 
86
79
  return (
87
- authorizedRoles.includes(data.role) &&
88
- data.instance === instanceName
80
+ authorizedRoles.includes(session.role) &&
81
+ session.instance === instanceName
89
82
  );
90
83
  } catch {
91
84
  return false;
@@ -93,7 +86,7 @@ export default class AuthClient extends ApiClient {
93
86
  }
94
87
 
95
88
  public async getOnlineSessions(instance: string) {
96
- const response = await this.httpClient.get<
89
+ const { data: res } = await this.httpClient.get<
97
90
  DataResponse<UserOnlineSession[]>
98
91
  >("/api/online-sessions", {
99
92
  params: {
@@ -101,7 +94,7 @@ export default class AuthClient extends ApiClient {
101
94
  },
102
95
  });
103
96
 
104
- return response.data.data;
97
+ return res.data;
105
98
  }
106
99
 
107
100
  public async initOnlineSession(authToken: string) {
@@ -16,10 +16,10 @@ export default class ReportsClient extends ApiClient {
16
16
  */
17
17
  public async getChatsReports() {
18
18
  const url = `/api/reports/chats`;
19
- const response =
19
+ const { data: res } =
20
20
  await this.httpClient.get<DataResponse<Array<ChatsReport>>>(url);
21
21
 
22
- return response.data;
22
+ return res.data;
23
23
  }
24
24
 
25
25
  /**
@@ -30,25 +30,21 @@ export default class ReportsClient extends ApiClient {
30
30
  */
31
31
  public async generateChatsReport(body: GenerateChatsReportOptions) {
32
32
  const url = `/api/reports/chats`;
33
- const response = await this.httpClient.post<DataResponse<ChatsReport>>(
34
- url,
35
- body,
36
- );
33
+ const { data: res } = await this.httpClient.post<
34
+ DataResponse<ChatsReport>
35
+ >(url, body);
37
36
 
38
- return response.data;
37
+ return res.data;
39
38
  }
40
39
 
41
40
  /**
42
41
  * Deletes a chat report by its unique identifier.
43
42
  *
44
43
  * @param chatsReportId - The unique identifier of the chat report to be deleted.
45
- * @returns A promise that resolves to a `MessageResponse` object containing the result of the deletion operation.
46
44
  */
47
45
  public async deleteChatsReport(chatsReportId: number) {
48
46
  const url = `/api/reports/chats/${chatsReportId}`;
49
- const response = await this.httpClient.delete<MessageResponse>(url);
50
-
51
- return response.data;
47
+ await this.httpClient.delete<MessageResponse>(url);
52
48
  }
53
49
 
54
50
  /**
@@ -27,7 +27,7 @@ export interface User {
27
27
  /** Login do usuário */
28
28
  LOGIN: string;
29
29
  /** Email do usuário */
30
- EMAIl: string;
30
+ EMAIL: string;
31
31
  /** Nível de acesso do usuário */
32
32
  NIVEL: UserRole | null;
33
33
  /** Horário de trabalho do usuário */
@@ -19,10 +19,10 @@ export default class UsersClient extends ApiClient {
19
19
  baseUrl += `?${params.toString()}`;
20
20
  }
21
21
 
22
- const response =
22
+ const { data: res } =
23
23
  await this.httpClient.get<PaginatedResponse<User>>(`/api/users`);
24
24
 
25
- return response.data;
25
+ return res.data;
26
26
  }
27
27
 
28
28
  /**
@@ -31,11 +31,11 @@ export default class UsersClient extends ApiClient {
31
31
  * @returns Uma resposta contendo os dados do usuário.
32
32
  */
33
33
  public async getUserById(userId: number) {
34
- const response = await this.httpClient.get<DataResponse<User>>(
34
+ const { data: res } = await this.httpClient.get<DataResponse<User>>(
35
35
  `/api/users/${userId}`,
36
36
  );
37
37
 
38
- return response.data;
38
+ return res.data;
39
39
  }
40
40
 
41
41
  /**
@@ -46,12 +46,11 @@ export default class UsersClient extends ApiClient {
46
46
  */
47
47
  public async createUser(data: CreateUserDTO) {
48
48
  try {
49
- const response = await this.httpClient.post<DataResponse<User>>(
50
- `/api/users`,
51
- data,
52
- );
49
+ const { data: res } = await this.httpClient.post<
50
+ DataResponse<User>
51
+ >(`/api/users`, data);
53
52
 
54
- return response.data;
53
+ return res.data;
55
54
  } catch (error) {
56
55
  throw new Error("Failed to create user", { cause: error });
57
56
  }
@@ -66,12 +65,11 @@ export default class UsersClient extends ApiClient {
66
65
  */
67
66
  public async updateUser(userId: string, data: UpdateUserDTO) {
68
67
  try {
69
- const response = await this.httpClient.patch<DataResponse<User>>(
70
- `/api/users/${userId}`,
71
- data,
72
- );
68
+ const { data: res } = await this.httpClient.patch<
69
+ DataResponse<User>
70
+ >(`/api/users/${userId}`, data);
73
71
 
74
- return response.data;
72
+ return res.data;
75
73
  } catch (error) {
76
74
  throw new Error("Failed to update user", { cause: error });
77
75
  }
@@ -10,6 +10,7 @@ import {
10
10
  type GetChatsResponse = DataResponse<WppChatsAndMessages>;
11
11
  type GetChatResponse = DataResponse<WppChatWithDetailsAndMessages>;
12
12
  type GetMessageResponse = DataResponse<WppMessage>;
13
+ type MarkChatAsReadResponse = DataResponse<WppMessage[]>;
13
14
 
14
15
  export default class WhatsappClient extends ApiClient {
15
16
  public async getChatsBySession(
@@ -19,37 +20,46 @@ export default class WhatsappClient extends ApiClient {
19
20
  ) {
20
21
  const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
21
22
 
22
- const { data } = await this.httpClient.get<GetChatsResponse>(url, {
23
+ const { data: res } = await this.httpClient.get<GetChatsResponse>(url, {
23
24
  headers: {
24
25
  Authorization: `Bearer ${token}`,
25
26
  },
26
27
  });
27
28
 
28
- return data;
29
+ return res.data;
29
30
  }
30
31
 
31
32
  public async getChatById(id: number) {
32
- const { data } = await this.httpClient.get<GetChatResponse>(
33
+ const { data: res } = await this.httpClient.get<GetChatResponse>(
33
34
  `/api/whatsapp/chats/${id}`,
34
35
  );
35
36
 
36
- return data;
37
+ return res.data;
37
38
  }
38
39
 
39
40
  public async getMessageById(id: string) {
40
- const { data } = await this.httpClient.get<GetMessageResponse>(
41
+ const { data: res } = await this.httpClient.get<GetMessageResponse>(
41
42
  `/api/whatsapp/messages/${id}`,
42
43
  );
43
44
 
44
- return data;
45
+ return res.data;
45
46
  }
46
47
 
47
48
  public async getUserWallets(instance: string, userId: number) {
48
- const { data } = await this.httpClient.get<DataResponse<WppWallet[]>>(
49
- `/api/wallets?instance=${instance}&userId=${userId}`,
50
- );
49
+ const { data: res } = await this.httpClient.get<
50
+ DataResponse<WppWallet[]>
51
+ >(`/api/wallets?instance=${instance}&userId=${userId}`);
52
+
53
+ return res.data;
54
+ }
55
+
56
+ public async markChatAsRead(chatId: number) {
57
+ const url = "/api/whatsapp/messages/mark-as-read";
58
+ const body = { chatId };
59
+ const { data: res } =
60
+ await this.httpClient.post<MarkChatAsReadResponse>(url, body);
51
61
 
52
- return data;
62
+ return res.data;
53
63
  }
54
64
 
55
65
  public setAuth(token: string) {