@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 +4 -4
- package/dist/auth.client.d.ts +2 -0
- package/dist/auth.client.js +16 -1
- package/dist/files.client.d.ts +2 -0
- package/dist/types/files.types.d.ts +2 -0
- package/package.json +1 -1
- package/src/auth.client.ts +96 -64
- package/tsconfig.json +16 -16
package/.prettierrc
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
{
|
|
2
|
-
"tabWidth": 4,
|
|
3
|
-
"useTabs": true
|
|
4
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"tabWidth": 4,
|
|
3
|
+
"useTabs": true
|
|
4
|
+
}
|
package/dist/auth.client.d.ts
CHANGED
|
@@ -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
|
}
|
package/dist/auth.client.js
CHANGED
|
@@ -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) &&
|
|
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;
|
package/dist/files.client.d.ts
CHANGED
package/package.json
CHANGED
package/src/auth.client.ts
CHANGED
|
@@ -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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
24
|
-
|
|
27
|
+
return response.data;
|
|
28
|
+
}
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
44
|
-
|
|
49
|
+
return response.data;
|
|
50
|
+
}
|
|
45
51
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
}
|