@in.pulse-crm/sdk 1.3.7 → 1.3.9
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.d.ts +2 -4
- package/dist/auth.js +8 -10
- package/package.json +1 -1
- package/src/socket-client.ts +27 -3
package/dist/auth.d.ts
CHANGED
|
@@ -45,18 +45,16 @@ export default class AuthSDK {
|
|
|
45
45
|
login(instanceName: string, username: string, password: string): Promise<DataResponse<LoginData>>;
|
|
46
46
|
/**
|
|
47
47
|
* Busca os dados da sessão.
|
|
48
|
-
* @param {string} instanceName Nome da instância do Inpulse.
|
|
49
48
|
* @param {string} authToken Token de autenticação.
|
|
50
49
|
* @returns {Promise<DataResponse<AuthTypes.SessionData>>} Dados da sessão.
|
|
51
50
|
*/
|
|
52
|
-
fetchSessionData(
|
|
51
|
+
fetchSessionData(authToken: string): Promise<DataResponse<SessionData>>;
|
|
53
52
|
/**
|
|
54
53
|
* Busca os dados do usuário da sessão.
|
|
55
|
-
* @param {string} instanceName Nome da instância do Inpulse.
|
|
56
54
|
* @param {string} authToken Token de autenticação.
|
|
57
55
|
* @returns {Promise<DataResponse<AuthTypes.User>>} Dados do usuário.
|
|
58
56
|
*/
|
|
59
|
-
fetchSessionUser(
|
|
57
|
+
fetchSessionUser(authToken: string): Promise<DataResponse<User>>;
|
|
60
58
|
/**
|
|
61
59
|
* Verifica se o usuário está autenticado.
|
|
62
60
|
* @param {string} instanceName Nome da instância do Inpulse.
|
package/dist/auth.js
CHANGED
|
@@ -26,13 +26,12 @@ class AuthSDK {
|
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Busca os dados da sessão.
|
|
29
|
-
* @param {string} instanceName Nome da instância do Inpulse.
|
|
30
29
|
* @param {string} authToken Token de autenticação.
|
|
31
30
|
* @returns {Promise<DataResponse<AuthTypes.SessionData>>} Dados da sessão.
|
|
32
31
|
*/
|
|
33
|
-
async fetchSessionData(
|
|
32
|
+
async fetchSessionData(authToken) {
|
|
34
33
|
const response = await this.httpClient
|
|
35
|
-
.get(
|
|
34
|
+
.get(`/auth`, {
|
|
36
35
|
headers: {
|
|
37
36
|
authorization: authToken,
|
|
38
37
|
},
|
|
@@ -45,13 +44,12 @@ class AuthSDK {
|
|
|
45
44
|
}
|
|
46
45
|
/**
|
|
47
46
|
* Busca os dados do usuário da sessão.
|
|
48
|
-
* @param {string} instanceName Nome da instância do Inpulse.
|
|
49
47
|
* @param {string} authToken Token de autenticação.
|
|
50
48
|
* @returns {Promise<DataResponse<AuthTypes.User>>} Dados do usuário.
|
|
51
49
|
*/
|
|
52
|
-
async fetchSessionUser(
|
|
50
|
+
async fetchSessionUser(authToken) {
|
|
53
51
|
const response = await this.httpClient
|
|
54
|
-
.get(
|
|
52
|
+
.get(`/auth/user`, {
|
|
55
53
|
headers: {
|
|
56
54
|
authorization: authToken,
|
|
57
55
|
},
|
|
@@ -70,8 +68,8 @@ class AuthSDK {
|
|
|
70
68
|
*/
|
|
71
69
|
async isAuthenticated(instanceName, authToken) {
|
|
72
70
|
try {
|
|
73
|
-
const { data } = await this.fetchSessionData(
|
|
74
|
-
return !!data.userId;
|
|
71
|
+
const { data } = await this.fetchSessionData(authToken);
|
|
72
|
+
return !!data.userId && data.instance === instanceName;
|
|
75
73
|
}
|
|
76
74
|
catch {
|
|
77
75
|
return false;
|
|
@@ -86,8 +84,8 @@ class AuthSDK {
|
|
|
86
84
|
*/
|
|
87
85
|
async isAuthorized(instanceName, authToken, authorizedRoles) {
|
|
88
86
|
try {
|
|
89
|
-
const { data } = await this.fetchSessionData(
|
|
90
|
-
return authorizedRoles.includes(data.role);
|
|
87
|
+
const { data } = await this.fetchSessionData(authToken);
|
|
88
|
+
return authorizedRoles.includes(data.role) && data.instance === instanceName;
|
|
91
89
|
}
|
|
92
90
|
catch {
|
|
93
91
|
return false;
|
package/package.json
CHANGED
package/src/socket-client.ts
CHANGED
|
@@ -16,6 +16,14 @@ export type JoinChatFunction = {
|
|
|
16
16
|
(phone: PhoneNumber): void;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
export type LeaveRoomFunction = {
|
|
20
|
+
(room: SocketRoomType): void;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type LeaveChatFunction = {
|
|
24
|
+
(phone: PhoneNumber): void;
|
|
25
|
+
};
|
|
26
|
+
|
|
19
27
|
/**
|
|
20
28
|
* Função para escutar eventos de socket.
|
|
21
29
|
*/
|
|
@@ -101,16 +109,32 @@ export default class SocketClientSDK {
|
|
|
101
109
|
* @param room - O tipo de sala a ser ingressada.
|
|
102
110
|
*/
|
|
103
111
|
public joinRoom: JoinRoomFunction = (room) => {
|
|
104
|
-
this.io.emit("join", `${room}`);
|
|
112
|
+
this.io.emit("join-room", `${room}`);
|
|
105
113
|
}
|
|
106
114
|
|
|
107
115
|
/**
|
|
108
|
-
* Entra em um chat
|
|
116
|
+
* Entra em um chat.
|
|
109
117
|
*
|
|
110
118
|
* @param phone - O número de telefone do chat a ser ingressado.
|
|
111
119
|
*/
|
|
112
120
|
public joinChat: JoinChatFunction = (phone) => {
|
|
113
|
-
this.
|
|
121
|
+
this.joinRoom(`chat:${phone}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Sai de uma sala de socket.
|
|
126
|
+
* @param room - O tipo de sala a ser deixada.
|
|
127
|
+
*/
|
|
128
|
+
public leaveRoom: LeaveRoomFunction = (room) => {
|
|
129
|
+
this.io.emit("leave-room", `${room}`);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Sai de um chat.
|
|
134
|
+
* @param phone - O número de telefone do chat a ser deixado.
|
|
135
|
+
*/
|
|
136
|
+
public leaveChat: LeaveChatFunction = (phone) => {
|
|
137
|
+
this.leaveRoom(`chat:${phone}`);
|
|
114
138
|
}
|
|
115
139
|
|
|
116
140
|
/**
|