@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 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(instanceName: string, authToken: string): Promise<DataResponse<SessionData>>;
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(instanceName: string, authToken: string): Promise<DataResponse<User>>;
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(instanceName, authToken) {
32
+ async fetchSessionData(authToken) {
34
33
  const response = await this.httpClient
35
- .get(`/${instanceName}/auth`, {
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(instanceName, authToken) {
50
+ async fetchSessionUser(authToken) {
53
51
  const response = await this.httpClient
54
- .get(`/${instanceName}/auth/user`, {
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(instanceName, authToken);
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(instanceName, authToken);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@in.pulse-crm/sdk",
3
- "version": "1.3.7",
3
+ "version": "1.3.9",
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",
@@ -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 de socket.
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.io.emit("join", `chat:${phone}`);
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
  /**