@in.pulse-crm/sdk 1.0.0 → 1.0.2

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
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const axios_1 = __importDefault(require("axios"));
9
+ class AuthSDK {
10
+ _api;
11
+ constructor(props) {
12
+ this._api = axios_1.default.create(props.axiosConfig);
13
+ }
14
+ async login(instance, login, password) {
15
+ const response = await this._api.post(`${instance}/login`, {
16
+ LOGIN: login,
17
+ SENHA: password,
18
+ });
19
+ return response.data;
20
+ }
21
+ async fetchSessionData(instance, token) {
22
+ const response = await this._api
23
+ .get(`/${instance}/auth`, {
24
+ headers: {
25
+ authorization: token,
26
+ },
27
+ })
28
+ .catch((error) => {
29
+ console.error(error.response?.data?.error);
30
+ if (error.response?.data?.message) {
31
+ throw new Error(error.response.data.message);
32
+ }
33
+ if (error.response?.status) {
34
+ throw new Error(
35
+ `Failed to authenticate, status: ${error.response.status}`,
36
+ );
37
+ }
38
+ throw new Error(error.message);
39
+ });
40
+ return response.data;
41
+ }
42
+ async isAuthenticated(instance, token) {
43
+ try {
44
+ const { data } = await this.fetchSessionData(instance, token);
45
+ return !!data.userId;
46
+ } catch {
47
+ return false;
48
+ }
49
+ }
50
+ async isAuthorized(instance, token, authorizedRoles) {
51
+ try {
52
+ const { data } = await this.fetchSessionData(instance, token);
53
+ return authorizedRoles.includes(data.role);
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
58
+ }
59
+ exports.default = AuthSDK;
package/dist/index.js CHANGED
@@ -1,18 +1,14 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
16
7
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./src/sdks"), exports);
18
- __exportStar(require("./src/types"), exports);
8
+ exports.InstanceSDK = exports.UserSDK = exports.AuthSDK = void 0;
9
+ const auth_sdk_1 = __importDefault(require("./auth.sdk"));
10
+ exports.AuthSDK = auth_sdk_1.default;
11
+ const user_sdk_1 = __importDefault(require("./user.sdk"));
12
+ exports.UserSDK = user_sdk_1.default;
13
+ const instance_sdk_1 = __importDefault(require("./instance.sdk"));
14
+ exports.InstanceSDK = instance_sdk_1.default;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const axios_1 = __importDefault(require("axios"));
9
+ class InstanceSDK {
10
+ _api;
11
+ constructor(props) {
12
+ this._api = axios_1.default.create(props.axiosConfig);
13
+ }
14
+ async executeQuery(instance, query, parameters) {
15
+ const response = await this._api
16
+ .post(`/${instance}/query`, { query, parameters })
17
+ .catch((error) => {
18
+ if (error.response?.data?.message) {
19
+ throw new Error(error.response.data.message);
20
+ }
21
+ if (error.response?.status) {
22
+ throw new Error(
23
+ `Failed to execute query, status: ${error.response.status}`,
24
+ );
25
+ }
26
+ throw new Error(error.message);
27
+ });
28
+ return response.data.result;
29
+ }
30
+ }
31
+ exports.default = InstanceSDK;
@@ -1,49 +1,52 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
5
7
  Object.defineProperty(exports, "__esModule", { value: true });
6
8
  const axios_1 = __importDefault(require("axios"));
7
9
  class AuthSDK {
8
- _api;
9
- constructor(props) {
10
- this._api = axios_1.default.create(props.axiosConfig);
11
- }
12
- async fetchSessionData(instance, token) {
13
- const response = await this._api
14
- .get(`/${instance}/auth`, {
15
- headers: {
16
- Authorization: `Bearer ${token}`,
17
- },
18
- })
19
- .catch((error) => {
20
- if (error.response?.data?.message) {
21
- throw new Error(error.response.data.message);
22
- }
23
- if (error.response?.status) {
24
- throw new Error(`Failed to authenticate, status: ${error.response.status}`);
25
- }
26
- throw new Error(error.message);
27
- });
28
- return response.data.data;
29
- }
30
- async isAuthenticated(instance, token) {
31
- try {
32
- await this.fetchSessionData(instance, token);
33
- return true;
34
- }
35
- catch {
36
- return false;
37
- }
38
- }
39
- async isAuthorized(instance, token, authorizedRoles) {
40
- try {
41
- const session = await this.fetchSessionData(instance, token);
42
- return authorizedRoles.includes(session.role);
43
- }
44
- catch {
45
- return false;
46
- }
47
- }
10
+ _api;
11
+ constructor(props) {
12
+ this._api = axios_1.default.create(props.axiosConfig);
13
+ }
14
+ async fetchSessionData(instance, token) {
15
+ const response = await this._api
16
+ .get(`/${instance}/auth`, {
17
+ headers: {
18
+ Authorization: `Bearer ${token}`,
19
+ },
20
+ })
21
+ .catch((error) => {
22
+ console.error(error);
23
+ if (error.response?.data?.message) {
24
+ throw new Error(error.response.data.message);
25
+ }
26
+ if (error.response?.status) {
27
+ throw new Error(
28
+ `Failed to authenticate, status: ${error.response.status}`,
29
+ );
30
+ }
31
+ throw new Error(error.message);
32
+ });
33
+ return response.data.data;
34
+ }
35
+ async isAuthenticated(instance, token) {
36
+ try {
37
+ await this.fetchSessionData(instance, token);
38
+ return true;
39
+ } catch {
40
+ return false;
41
+ }
42
+ }
43
+ async isAuthorized(instance, token, authorizedRoles) {
44
+ try {
45
+ const session = await this.fetchSessionData(instance, token);
46
+ return authorizedRoles.includes(session.role);
47
+ } catch {
48
+ return false;
49
+ }
50
+ }
48
51
  }
49
52
  exports.default = AuthSDK;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
5
7
  Object.defineProperty(exports, "__esModule", { value: true });
6
8
  exports.InstanceSDK = exports.AuthSDK = exports.UserSDK = void 0;
7
9
  const user_sdk_1 = __importDefault(require("./user.sdk"));
@@ -1,27 +1,31 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
5
7
  Object.defineProperty(exports, "__esModule", { value: true });
6
8
  const axios_1 = __importDefault(require("axios"));
7
9
  class InstanceSDK {
8
- _api;
9
- constructor(props) {
10
- this._api = axios_1.default.create(props.axiosConfig);
11
- }
12
- async executeQuery(instance, query, parameters) {
13
- const response = await this._api
14
- .post(`/${instance}/query`, { query, parameters })
15
- .catch((error) => {
16
- if (error.response?.data?.message) {
17
- throw new Error(error.response.data.message);
18
- }
19
- if (error.response?.status) {
20
- throw new Error(`Failed to execute query, status: ${error.response.status}`);
21
- }
22
- throw new Error(error.message);
23
- });
24
- return response.data.data;
25
- }
10
+ _api;
11
+ constructor(props) {
12
+ this._api = axios_1.default.create(props.axiosConfig);
13
+ }
14
+ async executeQuery(instance, query, parameters) {
15
+ const response = await this._api
16
+ .post(`/${instance}/query`, { query, parameters })
17
+ .catch((error) => {
18
+ if (error.response?.data?.message) {
19
+ throw new Error(error.response.data.message);
20
+ }
21
+ if (error.response?.status) {
22
+ throw new Error(
23
+ `Failed to execute query, status: ${error.response.status}`,
24
+ );
25
+ }
26
+ throw new Error(error.message);
27
+ });
28
+ return response.data.result;
29
+ }
26
30
  }
27
31
  exports.default = InstanceSDK;
@@ -1,39 +1,42 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
5
7
  Object.defineProperty(exports, "__esModule", { value: true });
6
8
  const axios_1 = __importDefault(require("axios"));
7
9
  class UserSDK {
8
- _api;
9
- constructor(props) {
10
- this._api = axios_1.default.create(props.axiosConfig);
11
- }
12
- async getUsers(instance) {
13
- const response = await this._api.get(`/${instance}/users`);
14
- return response.data;
15
- }
16
- async getUserById(instance, userId) {
17
- const response = await this._api.get(`/${instance}/users/${userId}`);
18
- return response.data;
19
- }
20
- async createUser(instance, data) {
21
- try {
22
- const response = await this._api.post(`/${instance}/users`, data);
23
- return response.data;
24
- }
25
- catch (error) {
26
- throw new Error("Failed to create user", { cause: error });
27
- }
28
- }
29
- async updateUser(instance, userId, data) {
30
- try {
31
- const response = await this._api.patch(`/${instance}/users/${userId}`, data);
32
- return response.data;
33
- }
34
- catch (error) {
35
- throw new Error("Failed to update user", { cause: error });
36
- }
37
- }
10
+ _api;
11
+ constructor(props) {
12
+ this._api = axios_1.default.create(props.axiosConfig);
13
+ }
14
+ async getUsers(instance) {
15
+ const response = await this._api.get(`/${instance}/users`);
16
+ return response.data;
17
+ }
18
+ async getUserById(instance, userId) {
19
+ const response = await this._api.get(`/${instance}/users/${userId}`);
20
+ return response.data;
21
+ }
22
+ async createUser(instance, data) {
23
+ try {
24
+ const response = await this._api.post(`/${instance}/users`, data);
25
+ return response.data;
26
+ } catch (error) {
27
+ throw new Error("Failed to create user", { cause: error });
28
+ }
29
+ }
30
+ async updateUser(instance, userId, data) {
31
+ try {
32
+ const response = await this._api.patch(
33
+ `/${instance}/users/${userId}`,
34
+ data,
35
+ );
36
+ return response.data;
37
+ } catch (error) {
38
+ throw new Error("Failed to update user", { cause: error });
39
+ }
40
+ }
38
41
  }
39
42
  exports.default = UserSDK;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod };
6
+ };
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ const axios_1 = __importDefault(require("axios"));
9
+ class UserSDK {
10
+ _api;
11
+ constructor(props) {
12
+ this._api = axios_1.default.create(props.axiosConfig);
13
+ }
14
+ async getUsers(instance) {
15
+ const response = await this._api.get(`/${instance}/users`);
16
+ return response.data;
17
+ }
18
+ async getUserById(instance, userId) {
19
+ const response = await this._api.get(`/${instance}/users/${userId}`);
20
+ return response.data;
21
+ }
22
+ async createUser(instance, data) {
23
+ try {
24
+ const response = await this._api.post(`/${instance}/users`, data);
25
+ return response.data;
26
+ } catch (error) {
27
+ throw new Error("Failed to create user", { cause: error });
28
+ }
29
+ }
30
+ async updateUser(instance, userId, data) {
31
+ try {
32
+ const response = await this._api.patch(
33
+ `/${instance}/users/${userId}`,
34
+ data,
35
+ );
36
+ return response.data;
37
+ } catch (error) {
38
+ throw new Error("Failed to update user", { cause: error });
39
+ }
40
+ }
41
+ }
42
+ exports.default = UserSDK;
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@in.pulse-crm/sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "SDKs for abstraction of api consumption of in.pulse-crm application",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
7
+ "publish": "npm publish --access public",
8
+ "build": "tsc",
9
+ "prettier": "prettier --write .",
10
+ "prettier:check": "prettier --check ."
8
11
  },
9
12
  "repository": {
10
13
  "type": "git",
@@ -0,0 +1,73 @@
1
+ import axios, { AxiosInstance, CreateAxiosDefaults } from "axios";
2
+ import { DataResponse, LoginData, SessionData } from "@in.pulse-crm/types";
3
+
4
+ interface AuthSDKOptions {
5
+ axiosConfig: CreateAxiosDefaults;
6
+ }
7
+
8
+ class AuthSDK {
9
+ private readonly _api: AxiosInstance;
10
+
11
+ constructor(props: AuthSDKOptions) {
12
+ this._api = axios.create(props.axiosConfig);
13
+ }
14
+
15
+ public async login(instance: string, login: string, password: string) {
16
+ const response = await this._api.post<DataResponse<LoginData>>(
17
+ `${instance}/login`,
18
+ { LOGIN: login, SENHA: password },
19
+ );
20
+
21
+ return response.data;
22
+ }
23
+
24
+ public async fetchSessionData(instance: string, token: string) {
25
+ const response = await this._api
26
+ .get<DataResponse<SessionData>>(`/${instance}/auth`, {
27
+ headers: {
28
+ authorization: token,
29
+ },
30
+ })
31
+ .catch((error) => {
32
+ console.error(error.response?.data?.error);
33
+
34
+ if (error.response?.data?.message) {
35
+ throw new Error(error.response.data.message);
36
+ }
37
+ if (error.response?.status) {
38
+ throw new Error(
39
+ `Failed to authenticate, status: ${error.response.status}`,
40
+ );
41
+ }
42
+ throw new Error(error.message);
43
+ });
44
+
45
+ return response.data;
46
+ }
47
+
48
+ public async isAuthenticated(instance: string, token: string) {
49
+ try {
50
+ const { data } = await this.fetchSessionData(instance, token);
51
+
52
+ return !!data.userId;
53
+ } catch {
54
+ return false;
55
+ }
56
+ }
57
+
58
+ public async isAuthorized(
59
+ instance: string,
60
+ token: string,
61
+ authorizedRoles: string[],
62
+ ) {
63
+ try {
64
+ const { data } = await this.fetchSessionData(instance, token);
65
+
66
+ return authorizedRoles.includes(data.role);
67
+ } catch {
68
+ return false;
69
+ }
70
+ }
71
+ }
72
+
73
+ export default AuthSDK;
@@ -1,5 +1,5 @@
1
- import UserSDK from "./user.sdk";
2
1
  import AuthSDK from "./auth.sdk";
2
+ import UserSDK from "./user.sdk";
3
3
  import InstanceSDK from "./instance.sdk";
4
4
 
5
- export { UserSDK, AuthSDK, InstanceSDK };
5
+ export { AuthSDK, UserSDK, InstanceSDK };
@@ -0,0 +1,38 @@
1
+ import axios, { AxiosInstance, CreateAxiosDefaults } from "axios";
2
+ import { QueryResponse } from "@in.pulse-crm/types";
3
+
4
+ interface InstanceSDKOptions {
5
+ axiosConfig: CreateAxiosDefaults;
6
+ }
7
+
8
+ class InstanceSDK {
9
+ private readonly _api: AxiosInstance;
10
+
11
+ constructor(props: InstanceSDKOptions) {
12
+ this._api = axios.create(props.axiosConfig);
13
+ }
14
+
15
+ public async executeQuery<T>(
16
+ instance: string,
17
+ query: string,
18
+ parameters: Array<any>,
19
+ ) {
20
+ const response = await this._api
21
+ .post<QueryResponse<T>>(`/${instance}/query`, { query, parameters })
22
+ .catch((error) => {
23
+ if (error.response?.data?.message) {
24
+ throw new Error(error.response.data.message);
25
+ }
26
+ if (error.response?.status) {
27
+ throw new Error(
28
+ `Failed to execute query, status: ${error.response.status}`,
29
+ );
30
+ }
31
+ throw new Error(error.message);
32
+ });
33
+
34
+ return response.data.result;
35
+ }
36
+ }
37
+
38
+ export default InstanceSDK;
@@ -1,11 +1,15 @@
1
- import axios, { AxiosInstance } from "axios";
1
+ import axios, { AxiosInstance, CreateAxiosDefaults } from "axios";
2
2
  import {
3
+ DataResponse,
4
+ PaginatedResponse,
3
5
  User,
4
- UserSDKOptions,
5
6
  CreateUserDTO,
6
7
  UpdateUserDTO,
7
- } from "../types/user.types";
8
- import { SuccessDataResponse } from "../types/response.types";
8
+ } from "@in.pulse-crm/types";
9
+
10
+ interface UserSDKOptions {
11
+ axiosConfig: CreateAxiosDefaults;
12
+ }
9
13
 
10
14
  class UserSDK {
11
15
  private readonly _api: AxiosInstance;
@@ -15,13 +19,15 @@ class UserSDK {
15
19
  }
16
20
 
17
21
  public async getUsers(instance: string) {
18
- const response = await this._api.get<Array<User>>(`/${instance}/users`);
22
+ const response = await this._api.get<PaginatedResponse<User>>(
23
+ `/${instance}/users`,
24
+ );
19
25
 
20
26
  return response.data;
21
27
  }
22
28
 
23
- public async getUserById(instance: string, userId: string) {
24
- const response = await this._api.get<User>(
29
+ public async getUserById(instance: string, userId: number) {
30
+ const response = await this._api.get<DataResponse<User>>(
25
31
  `/${instance}/users/${userId}`,
26
32
  );
27
33
 
@@ -30,7 +36,7 @@ class UserSDK {
30
36
 
31
37
  public async createUser(instance: string, data: CreateUserDTO) {
32
38
  try {
33
- const response = await this._api.post<SuccessDataResponse<User>>(
39
+ const response = await this._api.post<DataResponse<User>>(
34
40
  `/${instance}/users`,
35
41
  data,
36
42
  );
@@ -47,7 +53,7 @@ class UserSDK {
47
53
  data: UpdateUserDTO,
48
54
  ) {
49
55
  try {
50
- const response = await this._api.patch<SuccessDataResponse<User>>(
56
+ const response = await this._api.patch<DataResponse<User>>(
51
57
  `/${instance}/users/${userId}`,
52
58
  data,
53
59
  );
package/tsconfig.json CHANGED
@@ -1,16 +1,13 @@
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
- },
12
- "include": [
13
- "index.ts",
14
- "src/**/*.{ts}"
15
- ]
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
+ },
12
+ "include": ["src/index.ts", "src/**/*.{ts}"]
13
+ }
package/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./src/sdks";
2
- export * from "./src/types";
3
-
@@ -1,59 +0,0 @@
1
- import axios, { AxiosInstance } from "axios";
2
- import { AuthSDKOptions, SessionData } from "../types/auth.types";
3
- import { SuccessDataResponse } from "../types/response.types";
4
-
5
- class AuthSDK {
6
- private readonly _api: AxiosInstance;
7
-
8
- constructor(props: AuthSDKOptions) {
9
- this._api = axios.create(props.axiosConfig);
10
- }
11
-
12
- private async fetchSessionData(instance: string, token: string) {
13
- const response = await this._api
14
- .get<SuccessDataResponse<SessionData>>(`/${instance}/auth`, {
15
- headers: {
16
- Authorization: `Bearer ${token}`,
17
- },
18
- })
19
- .catch((error) => {
20
- if (error.response?.data?.message) {
21
- throw new Error(error.response.data.message);
22
- }
23
- if (error.response?.status) {
24
- throw new Error(
25
- `Failed to authenticate, status: ${error.response.status}`,
26
- );
27
- }
28
- throw new Error(error.message);
29
- });
30
-
31
- return response.data.data;
32
- }
33
-
34
- public async isAuthenticated(instance: string, token: string) {
35
- try {
36
- await this.fetchSessionData(instance, token);
37
-
38
- return true;
39
- } catch {
40
- return false;
41
- }
42
- }
43
-
44
- public async isAuthorized(
45
- instance: string,
46
- token: string,
47
- authorizedRoles: string[],
48
- ) {
49
- try {
50
- const session = await this.fetchSessionData(instance, token);
51
-
52
- return authorizedRoles.includes(session.role);
53
- } catch {
54
- return false;
55
- }
56
- }
57
- }
58
-
59
- export default AuthSDK;
@@ -1,32 +0,0 @@
1
- import axios, { AxiosInstance } from "axios";
2
- import { InstanceSDKOptions } from "../types/instance.types";
3
- import { SuccessDataResponse } from "../types/response.types";
4
-
5
- class InstanceSDK {
6
- private readonly _api: AxiosInstance;
7
-
8
- constructor(props: InstanceSDKOptions) {
9
- this._api = axios.create(props.axiosConfig);
10
- }
11
-
12
- public async executeQuery<T>(instance: string, query: string, parameters: Array<any>) {
13
- const response = await this._api
14
- .post<SuccessDataResponse<T>>(`/${instance}/query`, { query, parameters })
15
- .catch((error) => {
16
- if (error.response?.data?.message) {
17
- throw new Error(error.response.data.message);
18
- }
19
- if (error.response?.status) {
20
- throw new Error(
21
- `Failed to execute query, status: ${error.response.status}`,
22
- );
23
- }
24
- throw new Error(error.message);
25
- });
26
-
27
- return response.data.data;
28
- }
29
-
30
- }
31
-
32
- export default InstanceSDK;
@@ -1,10 +0,0 @@
1
- import { CreateAxiosDefaults } from "axios";
2
-
3
- export interface AuthSDKOptions {
4
- axiosConfig: CreateAxiosDefaults;
5
- }
6
-
7
- export interface SessionData {
8
- userId: number;
9
- role: string;
10
- }
@@ -1,4 +0,0 @@
1
- import { CreateUserDTO, User, UserSDKOptions } from "./user.types";
2
- import { AuthSDKOptions, SessionData } from "./auth.types";
3
-
4
- export { CreateUserDTO, User, UserSDKOptions, AuthSDKOptions, SessionData };
@@ -1,5 +0,0 @@
1
- import { CreateAxiosDefaults } from "axios";
2
-
3
- export interface InstanceSDKOptions {
4
- axiosConfig: CreateAxiosDefaults;
5
- }
@@ -1,4 +0,0 @@
1
- export interface SuccessDataResponse<T> {
2
- message: string;
3
- data: T;
4
- }
@@ -1,62 +0,0 @@
1
- import { CreateAxiosDefaults } from "axios";
2
-
3
- export interface User {
4
- CODIGO: number;
5
- ATIVO: "SIM" | "NAO" | null;
6
- NOME: string;
7
- LOGIN: string;
8
- EMAIl: string;
9
- NIVEL: "ATIVO" | "RECEP" | "AMBOS" | "ADMIN" | null;
10
- HORARIO: number;
11
- DATACAD: Date | null;
12
- SETOR: number;
13
- NOME_EXIBICAO: string | null;
14
- CODIGO_ERP: string;
15
- SETOR_NOME: string;
16
- SENHA?: string | null;
17
- EXPIRA_EM: Date | null;
18
- ALTERA_SENHA: "SIM" | "NAO" | null;
19
- EDITA_CONTATOS: "SIM" | "NAO" | null;
20
- VISUALIZA_COMPRAS: "SIM" | "NAO" | null;
21
- CADASTRO: "TOTAL" | "NULOS" | null;
22
- LOGADO: number | null;
23
- ULTIMO_LOGIN_INI: Date | null;
24
- ULTIMO_LOGIN_FIM: Date | null;
25
- CODTELEFONIA: string;
26
- AGENDA_LIG: "SIM" | "NAO";
27
- LIGA_REPRESENTANTE: "SIM" | "NAO";
28
- BANCO: string;
29
- FILTRA_DDD: "SIM" | "NAO";
30
- FILTRA_ESTADO: "SIM" | "NAO";
31
- ASTERISK_RAMAL: string | null;
32
- ASTERISK_USERID: string | null;
33
- ASTERISK_LOGIN: string | null;
34
- ASTERISK_SENHA: string | null;
35
- CODEC: string | null;
36
- ASSINATURA_EMAIL: string | null; // VARCHAR 255
37
- LIGA_REPRESENTANTE_DIAS: number | null;
38
- EMAILOPERADOR: string | null; // VARCHAR(100)
39
- SENHAEMAILOPERADOR: string | null; // CHAR(30)
40
- EMAIL_EXIBICAO: string | null; // VARCHAR(40)
41
- limite_diario_agendamento: number | null;
42
- OMNI: number | null;
43
- CAMINHO_DATABASE: string | null;
44
- IDCAMPANHA_WEON: string | null;
45
- }
46
-
47
- export interface UserSDKOptions {
48
- axiosConfig: CreateAxiosDefaults;
49
- }
50
-
51
- export interface CreateUserDTO {
52
- NOME: string;
53
- LOGIN: string;
54
- SENHA: string;
55
- NIVEL: "ATIVO" | "RECEP" | "AMBOS" | "ADMIN";
56
- SETOR: number;
57
- EMAIL?: string;
58
- NOME_EXIBICAO?: string;
59
- CODIGO_ERP?: string;
60
- }
61
-
62
- export type UpdateUserDTO = Partial<CreateUserDTO>;