@in.pulse-crm/sdk 2.0.12 → 2.1.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/.prettierrc CHANGED
@@ -1,4 +1,4 @@
1
- {
2
- "tabWidth": 4,
3
- "useTabs": true
4
- }
1
+ {
2
+ "tabWidth": 4,
3
+ "useTabs": true
4
+ }
@@ -34,4 +34,6 @@ export default class AuthClient extends ApiClient {
34
34
  * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autorizado, falso caso contrário.
35
35
  */
36
36
  isAuthorized(instanceName: string, authToken: string, authorizedRoles: string[]): Promise<boolean>;
37
+ initOnlineSession(authToken: string): Promise<void>;
38
+ finishOnlineSession(authToken: string): Promise<void>;
37
39
  }
@@ -63,11 +63,26 @@ class AuthClient extends api_client_1.default {
63
63
  async isAuthorized(instanceName, authToken, authorizedRoles) {
64
64
  try {
65
65
  const { data } = await this.fetchSessionData(authToken);
66
- return authorizedRoles.includes(data.role) && data.instance === instanceName;
66
+ return (authorizedRoles.includes(data.role) &&
67
+ data.instance === instanceName);
67
68
  }
68
69
  catch {
69
70
  return false;
70
71
  }
71
72
  }
73
+ async initOnlineSession(authToken) {
74
+ await this.httpClient.post("/api/online-sessions", {}, {
75
+ headers: {
76
+ Authorization: authToken,
77
+ },
78
+ });
79
+ }
80
+ async finishOnlineSession(authToken) {
81
+ await this.httpClient.delete("/api/online-sessions", {
82
+ headers: {
83
+ Authorization: authToken,
84
+ },
85
+ });
86
+ }
72
87
  }
73
88
  exports.default = AuthClient;
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  import ApiClient from "./api-client";
2
4
  import { File, UploadFileOptions } from "./types/files.types";
3
5
  declare class FilesClient extends ApiClient {
@@ -1,3 +1,5 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
1
3
  export interface UploadFileOptions {
2
4
  /**
3
5
  * Nome da instância onde o arquivo está armazenado.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@in.pulse-crm/sdk",
3
- "version": "2.0.12",
3
+ "version": "2.1.0",
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",
@@ -7,76 +7,108 @@ import { LoginData, SessionData } from "./types/auth.types";
7
7
  * Classe AuthSDK para interagir com a API de autenticação.
8
8
  */
9
9
  export default class AuthClient extends ApiClient {
10
- /**
11
- * Realiza o login do usuário.
12
- * @param {string} instance Nome da instância do Inpulse.
13
- * @param {string} username Nome de usuário.
14
- * @param {string} password Senha do usuário.
15
- * @returns {Promise<DataResponse<LoginData>>} Dados de login.
16
- */
17
- public async login(instance: string, username: string, password: string): Promise<DataResponse<LoginData>> {
18
- const response = await this.httpClient.post<DataResponse<LoginData>>(
19
- `/api/auth/login`,
20
- { LOGIN: username, SENHA: password, instance },
21
- );
10
+ /**
11
+ * Realiza o login do usuário.
12
+ * @param {string} instance Nome da instância do Inpulse.
13
+ * @param {string} username Nome de usuário.
14
+ * @param {string} password Senha do usuário.
15
+ * @returns {Promise<DataResponse<LoginData>>} Dados de login.
16
+ */
17
+ public async login(
18
+ instance: string,
19
+ username: string,
20
+ password: string,
21
+ ): Promise<DataResponse<LoginData>> {
22
+ const response = await this.httpClient.post<DataResponse<LoginData>>(
23
+ `/api/auth/login`,
24
+ { LOGIN: username, SENHA: password, instance },
25
+ );
22
26
 
23
- return response.data;
24
- }
27
+ return response.data;
28
+ }
25
29
 
26
- /**
27
- * Busca os dados da sessão.
28
- * @param {string} authToken Token de autenticação.
29
- * @returns {Promise<DataResponse<AuthTypes.SessionData>>} Dados da sessão.
30
- */
31
- public async fetchSessionData(authToken: string): Promise<DataResponse<SessionData>> {
32
- const response = await this.httpClient
33
- .get<DataResponse<SessionData>>(`/api/auth/session`, {
34
- headers: {
35
- authorization: authToken,
36
- },
37
- })
38
- .catch((error) => {
39
- const message = sanitizeErrorMessage(error);
40
- throw new Error("Failed to fetch session data! " + message);
41
- });
30
+ /**
31
+ * Busca os dados da sessão.
32
+ * @param {string} authToken Token de autenticação.
33
+ * @returns {Promise<DataResponse<AuthTypes.SessionData>>} Dados da sessão.
34
+ */
35
+ public async fetchSessionData(
36
+ authToken: string,
37
+ ): Promise<DataResponse<SessionData>> {
38
+ const response = await this.httpClient
39
+ .get<DataResponse<SessionData>>(`/api/auth/session`, {
40
+ headers: {
41
+ authorization: authToken,
42
+ },
43
+ })
44
+ .catch((error) => {
45
+ const message = sanitizeErrorMessage(error);
46
+ throw new Error("Failed to fetch session data! " + message);
47
+ });
42
48
 
43
- return response.data;
44
- }
49
+ return response.data;
50
+ }
45
51
 
46
- /**
47
- * Verifica se o usuário está autenticado.
48
- * @param {string} instanceName Nome da instância do Inpulse.
49
- * @param {string} authToken Token de autenticação.
50
- * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autenticado, falso caso contrário.
51
- */
52
- public async isAuthenticated(instanceName: string, authToken: string): Promise<boolean> {
53
- try {
54
- const { data } = await this.fetchSessionData(authToken);
52
+ /**
53
+ * Verifica se o usuário está autenticado.
54
+ * @param {string} instanceName Nome da instância do Inpulse.
55
+ * @param {string} authToken Token de autenticação.
56
+ * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autenticado, falso caso contrário.
57
+ */
58
+ public async isAuthenticated(
59
+ instanceName: string,
60
+ authToken: string,
61
+ ): Promise<boolean> {
62
+ try {
63
+ const { data } = await this.fetchSessionData(authToken);
55
64
 
56
- return !!data.userId && data.instance === instanceName;
57
- } catch {
58
- return false;
59
- }
60
- }
65
+ return !!data.userId && data.instance === instanceName;
66
+ } catch {
67
+ return false;
68
+ }
69
+ }
70
+
71
+ /**
72
+ * Verifica se o usuário está autorizado.
73
+ * @param {string} instanceName Nome da instância do Inpulse.
74
+ * @param {string} authToken Token de autenticação.
75
+ * @param {string[]} authorizedRoles Lista de papéis autorizados.
76
+ * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autorizado, falso caso contrário.
77
+ */
78
+ public async isAuthorized(
79
+ instanceName: string,
80
+ authToken: string,
81
+ authorizedRoles: string[],
82
+ ): Promise<boolean> {
83
+ try {
84
+ const { data } = await this.fetchSessionData(authToken);
85
+
86
+ return (
87
+ authorizedRoles.includes(data.role) &&
88
+ data.instance === instanceName
89
+ );
90
+ } catch {
91
+ return false;
92
+ }
93
+ }
61
94
 
62
- /**
63
- * Verifica se o usuário está autorizado.
64
- * @param {string} instanceName Nome da instância do Inpulse.
65
- * @param {string} authToken Token de autenticação.
66
- * @param {string[]} authorizedRoles Lista de papéis autorizados.
67
- * @returns {Promise<boolean>} Verdadeiro se o usuário estiver autorizado, falso caso contrário.
68
- */
69
- public async isAuthorized(
70
- instanceName: string,
71
- authToken: string,
72
- authorizedRoles: string[],
73
- ): Promise<boolean> {
74
- try {
75
- const { data } = await this.fetchSessionData(authToken);
95
+ public async initOnlineSession(authToken: string) {
96
+ await this.httpClient.post(
97
+ "/api/online-sessions",
98
+ {},
99
+ {
100
+ headers: {
101
+ Authorization: authToken,
102
+ },
103
+ },
104
+ );
105
+ }
76
106
 
77
- return authorizedRoles.includes(data.role) && data.instance === instanceName;
78
- } catch {
79
- return false;
80
- }
107
+ public async finishOnlineSession(authToken: string) {
108
+ await this.httpClient.delete("/api/online-sessions", {
109
+ headers: {
110
+ Authorization: authToken,
111
+ },
112
+ });
81
113
  }
82
114
  }
package/tsconfig.json CHANGED
@@ -1,17 +1,17 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
4
- "module": "commonjs" /* Specify what module code is generated. */,
5
- "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
6
- "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
7
- "strict": true /* Enable all strict type-checking options. */,
8
- "skipLibCheck": true /* Skip type checking all .d.ts files. */,
9
- "noUnusedLocals": false,
10
- "outDir": "./dist", /* Redirect output structure to the directory. */
11
- "declaration": true
12
- },
13
- "include": [
14
- "src/index.ts",
15
- "src/**/*.{ts}"
16
- ]
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
4
+ "module": "commonjs" /* Specify what module code is generated. */,
5
+ "esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
6
+ "forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
7
+ "strict": true /* Enable all strict type-checking options. */,
8
+ "skipLibCheck": true /* Skip type checking all .d.ts files. */,
9
+ "noUnusedLocals": false,
10
+ "outDir": "./dist", /* Redirect output structure to the directory. */
11
+ "declaration": true
12
+ },
13
+ "include": [
14
+ "src/index.ts",
15
+ "src/**/*.{ts}"
16
+ ]
17
17
  }