@in.pulse-crm/sdk 1.3.6 → 1.3.7

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/auth.ts +8 -10
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.7",
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
  }