@in.pulse-crm/sdk 2.2.12 → 2.3.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.
- package/dist/auth.client.d.ts +15 -16
- package/dist/auth.client.js +24 -24
- package/dist/reports.client.d.ts +3 -5
- package/dist/reports.client.js +5 -7
- package/dist/users.client.d.ts +4 -5
- package/dist/users.client.js +8 -8
- package/dist/whatsapp.client.d.ts +6 -9
- package/dist/whatsapp.client.js +16 -6
- package/package.json +1 -1
- package/src/auth.client.ts +29 -36
- package/src/reports.client.ts +7 -11
- package/src/users.client.ts +12 -14
- package/src/whatsapp.client.ts +25 -6
package/dist/auth.client.d.ts
CHANGED
|
@@ -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
|
|
11
|
-
* @param
|
|
12
|
-
* @param
|
|
13
|
-
* @returns
|
|
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<
|
|
14
|
+
login(instance: string, username: string, password: string): Promise<LoginData>;
|
|
16
15
|
/**
|
|
17
16
|
* Busca os dados da sessão.
|
|
18
|
-
* @param
|
|
19
|
-
* @returns
|
|
17
|
+
* @param authToken Token de autenticação.
|
|
18
|
+
* @returns Dados da sessão.
|
|
20
19
|
*/
|
|
21
|
-
fetchSessionData(authToken: string): Promise<
|
|
20
|
+
fetchSessionData(authToken: string): Promise<SessionData>;
|
|
22
21
|
/**
|
|
23
22
|
* Verifica se o usuário está autenticado.
|
|
24
|
-
* @param
|
|
25
|
-
* @param
|
|
26
|
-
* @returns
|
|
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
|
|
32
|
-
* @param
|
|
33
|
-
* @param
|
|
34
|
-
* @returns
|
|
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[]>;
|
package/dist/auth.client.js
CHANGED
|
@@ -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
|
|
15
|
-
* @param
|
|
16
|
-
* @param
|
|
17
|
-
* @returns
|
|
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
|
|
21
|
-
return
|
|
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
|
|
26
|
-
* @returns
|
|
25
|
+
* @param authToken Token de autenticação.
|
|
26
|
+
* @returns Dados da sessão.
|
|
27
27
|
*/
|
|
28
28
|
async fetchSessionData(authToken) {
|
|
29
|
-
const
|
|
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
|
|
39
|
+
return res.data;
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
42
|
* Verifica se o usuário está autenticado.
|
|
43
|
-
* @param
|
|
44
|
-
* @param
|
|
45
|
-
* @returns
|
|
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
|
|
50
|
-
return !!
|
|
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
|
|
59
|
-
* @param
|
|
60
|
-
* @param
|
|
61
|
-
* @returns
|
|
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
|
|
66
|
-
return (authorizedRoles.includes(
|
|
67
|
-
|
|
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
|
|
74
|
+
const { data: res } = await this.httpClient.get("/api/online-sessions", {
|
|
75
75
|
params: {
|
|
76
76
|
instance,
|
|
77
77
|
},
|
|
78
78
|
});
|
|
79
|
-
return
|
|
79
|
+
return res.data;
|
|
80
80
|
}
|
|
81
81
|
async initOnlineSession(authToken) {
|
|
82
82
|
await this.httpClient.post("/api/online-sessions", {}, {
|
package/dist/reports.client.d.ts
CHANGED
|
@@ -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<
|
|
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<
|
|
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<
|
|
28
|
+
deleteChatsReport(chatsReportId: number): Promise<void>;
|
|
31
29
|
/**
|
|
32
30
|
* Sets the authorization token for the HTTP client.
|
|
33
31
|
*
|
package/dist/reports.client.js
CHANGED
|
@@ -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
|
|
22
|
-
return
|
|
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
|
|
33
|
-
return
|
|
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
|
-
|
|
44
|
-
return response.data;
|
|
42
|
+
await this.httpClient.delete(url);
|
|
45
43
|
}
|
|
46
44
|
/**
|
|
47
45
|
* Sets the authorization token for the HTTP client.
|
package/dist/users.client.d.ts
CHANGED
|
@@ -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<
|
|
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<
|
|
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<
|
|
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<
|
|
34
|
+
updateUser(userId: string, data: UpdateUserDTO): Promise<User>;
|
|
36
35
|
/**
|
|
37
36
|
* Sets the authorization token for HTTP requests.
|
|
38
37
|
*
|
package/dist/users.client.js
CHANGED
|
@@ -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
|
|
23
|
-
return
|
|
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
|
|
32
|
-
return
|
|
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
|
|
43
|
-
return
|
|
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
|
|
59
|
-
return
|
|
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,13 +1,10 @@
|
|
|
1
1
|
import ApiClient from "./api-client";
|
|
2
|
-
import {
|
|
3
|
-
import { WppChatsAndMessages, WppChatWithDetailsAndMessages, WppMessage } from "./types/whatsapp.types";
|
|
4
|
-
type GetChatsResponse = DataResponse<WppChatsAndMessages>;
|
|
5
|
-
type GetChatResponse = DataResponse<WppChatWithDetailsAndMessages>;
|
|
6
|
-
type GetMessageResponse = DataResponse<WppMessage>;
|
|
2
|
+
import { WppChatsAndMessages, WppChatWithDetailsAndMessages, WppMessage, WppWallet } from "./types/whatsapp.types";
|
|
7
3
|
export default class WhatsappClient extends ApiClient {
|
|
8
|
-
getChatsBySession(token: string, messages?: boolean, contact?: boolean): Promise<
|
|
9
|
-
getChatById(id: number): Promise<
|
|
10
|
-
getMessageById(id: string): Promise<
|
|
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[]>;
|
|
11
9
|
setAuth(token: string): void;
|
|
12
10
|
}
|
|
13
|
-
export {};
|
package/dist/whatsapp.client.js
CHANGED
|
@@ -7,20 +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
|
+
}
|
|
25
|
+
async getUserWallets(instance, userId) {
|
|
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;
|
|
24
34
|
}
|
|
25
35
|
setAuth(token) {
|
|
26
36
|
this.httpClient.defaults.headers.common["Authorization"] =
|
package/package.json
CHANGED
package/src/auth.client.ts
CHANGED
|
@@ -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
|
|
13
|
-
* @param
|
|
14
|
-
* @param
|
|
15
|
-
* @returns
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
|
22
|
+
return res.data;
|
|
28
23
|
}
|
|
29
24
|
|
|
30
25
|
/**
|
|
31
26
|
* Busca os dados da sessão.
|
|
32
|
-
* @param
|
|
33
|
-
* @returns
|
|
27
|
+
* @param authToken Token de autenticação.
|
|
28
|
+
* @returns Dados da sessão.
|
|
34
29
|
*/
|
|
35
|
-
public async fetchSessionData(
|
|
36
|
-
|
|
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
|
|
42
|
+
return res.data;
|
|
50
43
|
}
|
|
51
44
|
|
|
52
45
|
/**
|
|
53
46
|
* Verifica se o usuário está autenticado.
|
|
54
|
-
* @param
|
|
55
|
-
* @param
|
|
56
|
-
* @returns
|
|
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
|
|
56
|
+
const session = await this.fetchSessionData(authToken);
|
|
64
57
|
|
|
65
|
-
return !!
|
|
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
|
|
74
|
-
* @param
|
|
75
|
-
* @param
|
|
76
|
-
* @returns
|
|
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
|
-
)
|
|
75
|
+
) {
|
|
83
76
|
try {
|
|
84
|
-
const
|
|
77
|
+
const session = await this.fetchSessionData(authToken);
|
|
85
78
|
|
|
86
79
|
return (
|
|
87
|
-
authorizedRoles.includes(
|
|
88
|
-
|
|
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
|
|
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
|
|
97
|
+
return res.data;
|
|
105
98
|
}
|
|
106
99
|
|
|
107
100
|
public async initOnlineSession(authToken: string) {
|
package/src/reports.client.ts
CHANGED
|
@@ -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
|
|
19
|
+
const { data: res } =
|
|
20
20
|
await this.httpClient.get<DataResponse<Array<ChatsReport>>>(url);
|
|
21
21
|
|
|
22
|
-
return
|
|
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
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
);
|
|
33
|
+
const { data: res } = await this.httpClient.post<
|
|
34
|
+
DataResponse<ChatsReport>
|
|
35
|
+
>(url, body);
|
|
37
36
|
|
|
38
|
-
return
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
return response.data;
|
|
47
|
+
await this.httpClient.delete<MessageResponse>(url);
|
|
52
48
|
}
|
|
53
49
|
|
|
54
50
|
/**
|
package/src/users.client.ts
CHANGED
|
@@ -19,10 +19,10 @@ export default class UsersClient extends ApiClient {
|
|
|
19
19
|
baseUrl += `?${params.toString()}`;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const
|
|
22
|
+
const { data: res } =
|
|
23
23
|
await this.httpClient.get<PaginatedResponse<User>>(`/api/users`);
|
|
24
24
|
|
|
25
|
-
return
|
|
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
|
|
34
|
+
const { data: res } = await this.httpClient.get<DataResponse<User>>(
|
|
35
35
|
`/api/users/${userId}`,
|
|
36
36
|
);
|
|
37
37
|
|
|
38
|
-
return
|
|
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
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
);
|
|
49
|
+
const { data: res } = await this.httpClient.post<
|
|
50
|
+
DataResponse<User>
|
|
51
|
+
>(`/api/users`, data);
|
|
53
52
|
|
|
54
|
-
return
|
|
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
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
);
|
|
68
|
+
const { data: res } = await this.httpClient.patch<
|
|
69
|
+
DataResponse<User>
|
|
70
|
+
>(`/api/users/${userId}`, data);
|
|
73
71
|
|
|
74
|
-
return
|
|
72
|
+
return res.data;
|
|
75
73
|
} catch (error) {
|
|
76
74
|
throw new Error("Failed to update user", { cause: error });
|
|
77
75
|
}
|
package/src/whatsapp.client.ts
CHANGED
|
@@ -4,11 +4,13 @@ import {
|
|
|
4
4
|
WppChatsAndMessages,
|
|
5
5
|
WppChatWithDetailsAndMessages,
|
|
6
6
|
WppMessage,
|
|
7
|
+
WppWallet,
|
|
7
8
|
} from "./types/whatsapp.types";
|
|
8
9
|
|
|
9
10
|
type GetChatsResponse = DataResponse<WppChatsAndMessages>;
|
|
10
11
|
type GetChatResponse = DataResponse<WppChatWithDetailsAndMessages>;
|
|
11
12
|
type GetMessageResponse = DataResponse<WppMessage>;
|
|
13
|
+
type MarkChatAsReadResponse = DataResponse<WppMessage[]>;
|
|
12
14
|
|
|
13
15
|
export default class WhatsappClient extends ApiClient {
|
|
14
16
|
public async getChatsBySession(
|
|
@@ -18,29 +20,46 @@ export default class WhatsappClient extends ApiClient {
|
|
|
18
20
|
) {
|
|
19
21
|
const url = `/api/whatsapp/session/chats?messages=${messages}&contact=${contact}`;
|
|
20
22
|
|
|
21
|
-
const { data } = await this.httpClient.get<GetChatsResponse>(url, {
|
|
23
|
+
const { data: res } = await this.httpClient.get<GetChatsResponse>(url, {
|
|
22
24
|
headers: {
|
|
23
25
|
Authorization: `Bearer ${token}`,
|
|
24
26
|
},
|
|
25
27
|
});
|
|
26
28
|
|
|
27
|
-
return data;
|
|
29
|
+
return res.data;
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
public async getChatById(id: number) {
|
|
31
|
-
const { data } = await this.httpClient.get<GetChatResponse>(
|
|
33
|
+
const { data: res } = await this.httpClient.get<GetChatResponse>(
|
|
32
34
|
`/api/whatsapp/chats/${id}`,
|
|
33
35
|
);
|
|
34
36
|
|
|
35
|
-
return data;
|
|
37
|
+
return res.data;
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
public async getMessageById(id: string) {
|
|
39
|
-
const { data } = await this.httpClient.get<GetMessageResponse>(
|
|
41
|
+
const { data: res } = await this.httpClient.get<GetMessageResponse>(
|
|
40
42
|
`/api/whatsapp/messages/${id}`,
|
|
41
43
|
);
|
|
42
44
|
|
|
43
|
-
return data;
|
|
45
|
+
return res.data;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public async getUserWallets(instance: string, userId: number) {
|
|
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);
|
|
61
|
+
|
|
62
|
+
return res.data;
|
|
44
63
|
}
|
|
45
64
|
|
|
46
65
|
public setAuth(token: string) {
|