@in.pulse-crm/sdk 1.3.6 → 1.3.8

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.6",
3
+ "version": "1.3.8",
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",
package/src/auth.ts CHANGED
@@ -60,13 +60,12 @@ export default class AuthSDK {
60
60
 
61
61
  /**
62
62
  * Busca os dados da sessão.
63
- * @param {string} instanceName Nome da instância do Inpulse.
64
63
  * @param {string} authToken Token de autenticação.
65
64
  * @returns {Promise<DataResponse<AuthTypes.SessionData>>} Dados da sessão.
66
65
  */
67
- public async fetchSessionData(instanceName: string, authToken: string): Promise<DataResponse<SessionData>> {
66
+ public async fetchSessionData(authToken: string): Promise<DataResponse<SessionData>> {
68
67
  const response = await this.httpClient
69
- .get<DataResponse<SessionData>>(`/${instanceName}/auth`, {
68
+ .get<DataResponse<SessionData>>(`/auth`, {
70
69
  headers: {
71
70
  authorization: authToken,
72
71
  },
@@ -81,13 +80,12 @@ export default class AuthSDK {
81
80
 
82
81
  /**
83
82
  * Busca os dados do usuário da sessão.
84
- * @param {string} instanceName Nome da instância do Inpulse.
85
83
  * @param {string} authToken Token de autenticação.
86
84
  * @returns {Promise<DataResponse<AuthTypes.User>>} Dados do usuário.
87
85
  */
88
- public async fetchSessionUser(instanceName: string, authToken: string): Promise<DataResponse<User>> {
86
+ public async fetchSessionUser(authToken: string): Promise<DataResponse<User>> {
89
87
  const response = await this.httpClient
90
- .get<DataResponse<User>>(`/${instanceName}/auth/user`, {
88
+ .get<DataResponse<User>>(`/auth/user`, {
91
89
  headers: {
92
90
  authorization: authToken,
93
91
  },
@@ -108,9 +106,9 @@ export default class AuthSDK {
108
106
  */
109
107
  public async isAuthenticated(instanceName: string, authToken: string): Promise<boolean> {
110
108
  try {
111
- const { data } = await this.fetchSessionData(instanceName, authToken);
109
+ const { data } = await this.fetchSessionData(authToken);
112
110
 
113
- return !!data.userId;
111
+ return !!data.userId && data.instance === instanceName;
114
112
  } catch {
115
113
  return false;
116
114
  }
@@ -129,9 +127,9 @@ export default class AuthSDK {
129
127
  authorizedRoles: string[],
130
128
  ): Promise<boolean> {
131
129
  try {
132
- const { data } = await this.fetchSessionData(instanceName, authToken);
130
+ const { data } = await this.fetchSessionData(authToken);
133
131
 
134
- return authorizedRoles.includes(data.role);
132
+ return authorizedRoles.includes(data.role) && data.instance === instanceName;
135
133
  } catch {
136
134
  return false;
137
135
  }