@in.pulse-crm/sdk 2.0.2 → 2.0.3

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.
@@ -17,7 +17,7 @@ class AuthClient extends api_client_1.default {
17
17
  * @returns {Promise<DataResponse<LoginData>>} Dados de login.
18
18
  */
19
19
  async login(instance, username, password) {
20
- const response = await this.httpClient.post(`/auth/login`, { LOGIN: username, SENHA: password, instance });
20
+ const response = await this.httpClient.post(`/api/auth/login`, { LOGIN: username, SENHA: password, instance });
21
21
  return response.data;
22
22
  }
23
23
  /**
@@ -27,7 +27,7 @@ class AuthClient extends api_client_1.default {
27
27
  */
28
28
  async fetchSessionData(authToken) {
29
29
  const response = await this.httpClient
30
- .get(`/auth/session`, {
30
+ .get(`/api/auth/session`, {
31
31
  headers: {
32
32
  authorization: authToken,
33
33
  },
@@ -11,7 +11,7 @@ class CustomersClient extends api_client_1.default {
11
11
  * @returns Uma Promise que resolve para o cliente criado.
12
12
  */
13
13
  async createCustomer(data) {
14
- const response = await this.httpClient.post(`/customers`, data);
14
+ const response = await this.httpClient.post(`/api/customers`, data);
15
15
  return response.data;
16
16
  }
17
17
  /**
@@ -20,7 +20,7 @@ class CustomersClient extends api_client_1.default {
20
20
  * @returns Uma Promise que resolve para o cliente obtido.
21
21
  */
22
22
  async getCustomerById(customerId) {
23
- const response = await this.httpClient.get(`/customers/${customerId}`);
23
+ const response = await this.httpClient.get(`/api/customers/${customerId}`);
24
24
  return response.data;
25
25
  }
26
26
  /**
@@ -30,7 +30,7 @@ class CustomersClient extends api_client_1.default {
30
30
  * @returns Uma Promise que resolve para o cliente atualizado.
31
31
  */
32
32
  async updateCustomer(customerId, data) {
33
- const response = await this.httpClient.patch(`/customers/${customerId}`, data);
33
+ const response = await this.httpClient.patch(`/api/customers/${customerId}`, data);
34
34
  return response.data;
35
35
  }
36
36
  /**
@@ -41,12 +41,12 @@ class CustomersClient extends api_client_1.default {
41
41
  * @returns Uma Promise que resolve para uma lista de clientes.
42
42
  */
43
43
  async getAllCustomers(filters) {
44
- let baseUrl = `/customers`;
44
+ let baseUrl = `/api/customers`;
45
45
  const params = new URLSearchParams(filters);
46
46
  if (params.toString()) {
47
47
  baseUrl += `?${params.toString()}`;
48
48
  }
49
- const response = await this.httpClient.get(`/customers`);
49
+ const response = await this.httpClient.get(`/api/customers`);
50
50
  return response.data;
51
51
  }
52
52
  /**
@@ -11,8 +11,8 @@ class FilesClient extends api_client_1.default {
11
11
  * @returns {Promise<Buffer>} Um buffer contendo os dados do arquivo.
12
12
  */
13
13
  async fetchFile(id) {
14
- const response = await this.httpClient.get(`/files/${id}`, {
15
- responseType: "arraybuffer"
14
+ const response = await this.httpClient.get(`/api/files/${id}`, {
15
+ responseType: "arraybuffer",
16
16
  });
17
17
  const buffer = Buffer.from(response.data, "binary");
18
18
  return buffer;
@@ -23,7 +23,7 @@ class FilesClient extends api_client_1.default {
23
23
  * @returns {string} URL de download do arquivo.
24
24
  */
25
25
  getFileDownloadUrl(id) {
26
- return this.httpClient.defaults.baseURL + `/files/${id}`;
26
+ return this.httpClient.defaults.baseURL + `/api/files/${id}`;
27
27
  }
28
28
  /**
29
29
  * Faz o upload de um arquivo.
@@ -35,8 +35,8 @@ class FilesClient extends api_client_1.default {
35
35
  form.append("instance", props.instance);
36
36
  form.append("dirType", props.dirType);
37
37
  form.append("file", new Blob([props.buffer]), props.fileName);
38
- const response = await this.httpClient.post("/files", form, {
39
- headers: { "Content-Type": "multipart/form-data" }
38
+ const response = await this.httpClient.post("/api/files", form, {
39
+ headers: { "Content-Type": "multipart/form-data" },
40
40
  });
41
41
  return response.data.data;
42
42
  }
@@ -46,7 +46,7 @@ class FilesClient extends api_client_1.default {
46
46
  * @returns {Promise<void>}
47
47
  */
48
48
  async deleteFile(id) {
49
- await this.httpClient.delete(`/files/${id}`);
49
+ await this.httpClient.delete(`/api/files/${id}`);
50
50
  }
51
51
  }
52
52
  exports.default = FilesClient;
@@ -17,7 +17,7 @@ class InstancesClient extends api_client_1.default {
17
17
  */
18
18
  async executeQuery(instance, query, parameters) {
19
19
  const response = await this.httpClient
20
- .post(`/${instance}/query`, { query, parameters })
20
+ .post(`/api/instances/${instance}/query`, { query, parameters })
21
21
  .catch((error) => {
22
22
  if (error.response?.data?.message) {
23
23
  throw new Error(error.response.data.message);
@@ -6,17 +6,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const api_client_1 = __importDefault(require("./api-client"));
7
7
  class ReportsClient extends api_client_1.default {
8
8
  async getChatsReports() {
9
- const url = `/reports/chats`;
9
+ const url = `/api/reports/chats`;
10
10
  const response = await this.httpClient.get(url);
11
11
  return response.data;
12
12
  }
13
13
  async generateChatsReport(body) {
14
- const url = `/reports/chats`;
14
+ const url = `/api/reports/chats`;
15
15
  const response = await this.httpClient.post(url, body);
16
16
  return response.data;
17
17
  }
18
18
  async deleteChatsReport(chatsReportId) {
19
- const url = `/reports/chats/${chatsReportId}`;
19
+ const url = `/api/reports/chats/${chatsReportId}`;
20
20
  const response = await this.httpClient.delete(url);
21
21
  return response.data;
22
22
  }
@@ -27,8 +27,9 @@ class SocketServerApi extends api_client_1.default {
27
27
  * @returns A promise that resolves with the response from the API call.
28
28
  */
29
29
  emit = (event, room, value) => {
30
- return this.httpClient.post(`/emit/${room}/${event}`, value)
31
- .then(res => res.data);
30
+ return this.httpClient
31
+ .post(`/api/ws/emit/${room}/${event}`, value)
32
+ .then((res) => res.data);
32
33
  };
33
34
  }
34
35
  exports.default = SocketServerApi;
@@ -13,7 +13,7 @@ class UsersClient extends api_client_1.default {
13
13
  * @returns Uma resposta paginada contendo os usuários.
14
14
  */
15
15
  async getUsers() {
16
- const response = await this.httpClient.get(`/users`);
16
+ const response = await this.httpClient.get(`/api/users`);
17
17
  return response.data;
18
18
  }
19
19
  /**
@@ -22,7 +22,7 @@ class UsersClient extends api_client_1.default {
22
22
  * @returns Uma resposta contendo os dados do usuário.
23
23
  */
24
24
  async getUserById(userId) {
25
- const response = await this.httpClient.get(`/users/${userId}`);
25
+ const response = await this.httpClient.get(`/api/users/${userId}`);
26
26
  return response.data;
27
27
  }
28
28
  /**
@@ -33,7 +33,7 @@ class UsersClient extends api_client_1.default {
33
33
  */
34
34
  async createUser(data) {
35
35
  try {
36
- const response = await this.httpClient.post(`/users`, data);
36
+ const response = await this.httpClient.post(`/api/users`, data);
37
37
  return response.data;
38
38
  }
39
39
  catch (error) {
@@ -49,7 +49,7 @@ class UsersClient extends api_client_1.default {
49
49
  */
50
50
  async updateUser(userId, data) {
51
51
  try {
52
- const response = await this.httpClient.patch(`/users/${userId}`, data);
52
+ const response = await this.httpClient.patch(`/api/users/${userId}`, data);
53
53
  return response.data;
54
54
  }
55
55
  catch (error) {
@@ -62,7 +62,8 @@ class UsersClient extends api_client_1.default {
62
62
  * @param token - The authentication token to be used in the `Authorization` header.
63
63
  */
64
64
  setAuth(token) {
65
- this.httpClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
65
+ this.httpClient.defaults.headers.common["Authorization"] =
66
+ `Bearer ${token}`;
66
67
  }
67
68
  }
68
69
  exports.default = UsersClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@in.pulse-crm/sdk",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
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",
@@ -16,7 +16,7 @@ export default class AuthClient extends ApiClient {
16
16
  */
17
17
  public async login(instance: string, username: string, password: string): Promise<DataResponse<LoginData>> {
18
18
  const response = await this.httpClient.post<DataResponse<LoginData>>(
19
- `/auth/login`,
19
+ `/api/auth/login`,
20
20
  { LOGIN: username, SENHA: password, instance },
21
21
  );
22
22
 
@@ -30,7 +30,7 @@ export default class AuthClient extends ApiClient {
30
30
  */
31
31
  public async fetchSessionData(authToken: string): Promise<DataResponse<SessionData>> {
32
32
  const response = await this.httpClient
33
- .get<DataResponse<SessionData>>(`/auth/session`, {
33
+ .get<DataResponse<SessionData>>(`/api/auth/session`, {
34
34
  headers: {
35
35
  authorization: authToken,
36
36
  },
@@ -8,7 +8,7 @@ class CustomersClient extends ApiClient {
8
8
  * @returns Uma Promise que resolve para o cliente criado.
9
9
  */
10
10
  public async createCustomer(data: CreateCustomerDTO) {
11
- const response = await this.httpClient.post(`/customers`, data);
11
+ const response = await this.httpClient.post(`/api/customers`, data);
12
12
 
13
13
  return response.data;
14
14
  }
@@ -19,7 +19,7 @@ class CustomersClient extends ApiClient {
19
19
  * @returns Uma Promise que resolve para o cliente obtido.
20
20
  */
21
21
  public async getCustomerById(customerId: number) {
22
- const response = await this.httpClient.get(`/customers/${customerId}`);
22
+ const response = await this.httpClient.get(`/api/customers/${customerId}`);
23
23
  return response.data;
24
24
  }
25
25
 
@@ -30,7 +30,7 @@ class CustomersClient extends ApiClient {
30
30
  * @returns Uma Promise que resolve para o cliente atualizado.
31
31
  */
32
32
  public async updateCustomer(customerId: number, data: UpdateCustomerDTO) {
33
- const response = await this.httpClient.patch(`/customers/${customerId}`, data);
33
+ const response = await this.httpClient.patch(`/api/customers/${customerId}`, data);
34
34
  return response.data;
35
35
  }
36
36
 
@@ -42,14 +42,14 @@ class CustomersClient extends ApiClient {
42
42
  * @returns Uma Promise que resolve para uma lista de clientes.
43
43
  */
44
44
  public async getAllCustomers(filters: Record<string, string>) {
45
- let baseUrl = `/customers`;
45
+ let baseUrl = `/api/customers`;
46
46
  const params = new URLSearchParams(filters);
47
47
 
48
48
  if (params.toString()) {
49
49
  baseUrl += `?${params.toString()}`;
50
50
  }
51
51
 
52
- const response = await this.httpClient.get(`/customers`);
52
+ const response = await this.httpClient.get(`/api/customers`);
53
53
 
54
54
  return response.data;
55
55
  }
@@ -3,55 +3,59 @@ import { File, UploadFileOptions } from "./types/files.types";
3
3
  import { DataResponse } from "./types/response.types";
4
4
 
5
5
  class FilesClient extends ApiClient {
6
- /**
7
- * Busca um arquivo pelo ID.
8
- * @param {number} id - ID do arquivo.
9
- * @returns {Promise<Buffer>} Um buffer contendo os dados do arquivo.
10
- */
11
- public async fetchFile(id: number): Promise<Buffer> {
12
- const response = await this.httpClient.get(`/files/${id}`, {
13
- responseType: "arraybuffer"
14
- });
15
- const buffer = Buffer.from(response.data, "binary");
16
-
17
- return buffer;
18
- }
19
-
20
- /**
21
- * Obtém a URL de download de um arquivo.
22
- * @param {number} id - ID do arquivo.
23
- * @returns {string} URL de download do arquivo.
24
- */
25
- public getFileDownloadUrl(id: number): string {
26
- return this.httpClient.defaults.baseURL + `/files/${id}`;
27
- }
28
-
29
- /**
30
- * Faz o upload de um arquivo.
31
- * @param {UploadFileOptions} props - Opções para o upload do arquivo.
32
- * @returns {Promise<File>} Os dados do arquivo enviado.
33
- */
34
- public async uploadFile(props: UploadFileOptions): Promise<File> {
35
- const form = new FormData();
36
- form.append("instance", props.instance);
37
- form.append("dirType", props.dirType);
38
- form.append("file", new Blob([props.buffer]), props.fileName);
39
-
40
- const response = await this.httpClient.post<DataResponse<File>>("/files", form, {
41
- headers: { "Content-Type": "multipart/form-data" }
42
- });
43
-
44
- return response.data.data;
45
- }
46
-
47
- /**
48
- * Deleta um arquivo pelo ID.
49
- * @param {number} id - ID do arquivo.
50
- * @returns {Promise<void>}
51
- */
52
- public async deleteFile(id: number): Promise<void> {
53
- await this.httpClient.delete(`/files/${id}`);
54
- }
6
+ /**
7
+ * Busca um arquivo pelo ID.
8
+ * @param {number} id - ID do arquivo.
9
+ * @returns {Promise<Buffer>} Um buffer contendo os dados do arquivo.
10
+ */
11
+ public async fetchFile(id: number): Promise<Buffer> {
12
+ const response = await this.httpClient.get(`/api/files/${id}`, {
13
+ responseType: "arraybuffer",
14
+ });
15
+ const buffer = Buffer.from(response.data, "binary");
16
+
17
+ return buffer;
18
+ }
19
+
20
+ /**
21
+ * Obtém a URL de download de um arquivo.
22
+ * @param {number} id - ID do arquivo.
23
+ * @returns {string} URL de download do arquivo.
24
+ */
25
+ public getFileDownloadUrl(id: number): string {
26
+ return this.httpClient.defaults.baseURL + `/api/files/${id}`;
27
+ }
28
+
29
+ /**
30
+ * Faz o upload de um arquivo.
31
+ * @param {UploadFileOptions} props - Opções para o upload do arquivo.
32
+ * @returns {Promise<File>} Os dados do arquivo enviado.
33
+ */
34
+ public async uploadFile(props: UploadFileOptions): Promise<File> {
35
+ const form = new FormData();
36
+ form.append("instance", props.instance);
37
+ form.append("dirType", props.dirType);
38
+ form.append("file", new Blob([props.buffer]), props.fileName);
39
+
40
+ const response = await this.httpClient.post<DataResponse<File>>(
41
+ "/api/files",
42
+ form,
43
+ {
44
+ headers: { "Content-Type": "multipart/form-data" },
45
+ },
46
+ );
47
+
48
+ return response.data.data;
49
+ }
50
+
51
+ /**
52
+ * Deleta um arquivo pelo ID.
53
+ * @param {number} id - ID do arquivo.
54
+ * @returns {Promise<void>}
55
+ */
56
+ public async deleteFile(id: number): Promise<void> {
57
+ await this.httpClient.delete(`/api/files/${id}`);
58
+ }
55
59
  }
56
60
 
57
- export default FilesClient;
61
+ export default FilesClient;
@@ -20,7 +20,9 @@ class InstancesClient extends ApiClient {
20
20
  parameters: any[],
21
21
  ): Promise<T> {
22
22
  const response = await this.httpClient
23
- .post<QueryResponse<T>>(`/${instance}/query`, { query, parameters })
23
+ .post<
24
+ QueryResponse<T>
25
+ >(`/api/instances/${instance}/query`, { query, parameters })
24
26
  .catch((error) => {
25
27
  if (error.response?.data?.message) {
26
28
  throw new Error(error.response.data.message);
@@ -4,7 +4,7 @@ import { DataResponse, MessageResponse } from "./types/response.types";
4
4
 
5
5
  export default class ReportsClient extends ApiClient {
6
6
  public async getChatsReports() {
7
- const url = `/reports/chats`;
7
+ const url = `/api/reports/chats`;
8
8
  const response =
9
9
  await this.httpClient.get<DataResponse<Array<ChatsReport>>>(url);
10
10
 
@@ -12,7 +12,7 @@ export default class ReportsClient extends ApiClient {
12
12
  }
13
13
 
14
14
  public async generateChatsReport(body: GenerateChatsReportOptions) {
15
- const url = `/reports/chats`;
15
+ const url = `/api/reports/chats`;
16
16
  const response = await this.httpClient.post<DataResponse<ChatsReport>>(
17
17
  url,
18
18
  body,
@@ -22,7 +22,7 @@ export default class ReportsClient extends ApiClient {
22
22
  }
23
23
 
24
24
  public async deleteChatsReport(chatsReportId: number) {
25
- const url = `/reports/chats/${chatsReportId}`;
25
+ const url = `/api/reports/chats/${chatsReportId}`;
26
26
  const response = await this.httpClient.delete<MessageResponse>(url);
27
27
 
28
28
  return response.data;
@@ -26,7 +26,8 @@ export default class SocketServerApi extends ApiClient {
26
26
  * @returns A promise that resolves with the response from the API call.
27
27
  */
28
28
  public emit: EmitSocketEventFn = (event, room, value) => {
29
- return this.httpClient.post<MessageResponse>(`/emit/${room}/${event}`, value)
30
- .then(res => res.data);
29
+ return this.httpClient
30
+ .post<MessageResponse>(`/api/ws/emit/${room}/${event}`, value)
31
+ .then((res) => res.data);
31
32
  }
32
33
  }
@@ -6,69 +6,76 @@ import ApiClient from "./api-client";
6
6
  * SDK para operações de usuários.
7
7
  */
8
8
  export default class UsersClient extends ApiClient {
9
- /**
10
- * Obtém a lista de usuários.
11
- * @returns Uma resposta paginada contendo os usuários.
12
- */
13
- public async getUsers() {
14
- const response = await this.httpClient.get<PaginatedResponse<User>>(`/users`);
9
+ /**
10
+ * Obtém a lista de usuários.
11
+ * @returns Uma resposta paginada contendo os usuários.
12
+ */
13
+ public async getUsers() {
14
+ const response =
15
+ await this.httpClient.get<PaginatedResponse<User>>(`/api/users`);
15
16
 
16
- return response.data;
17
- }
17
+ return response.data;
18
+ }
18
19
 
19
- /**
20
- * Obtém um usuário pelo ID.
21
- * @param userId - O ID do usuário.
22
- * @returns Uma resposta contendo os dados do usuário.
23
- */
24
- public async getUserById(userId: number) {
25
- const response = await this.httpClient.get<DataResponse<User>>(`/users/${userId}`);
20
+ /**
21
+ * Obtém um usuário pelo ID.
22
+ * @param userId - O ID do usuário.
23
+ * @returns Uma resposta contendo os dados do usuário.
24
+ */
25
+ public async getUserById(userId: number) {
26
+ const response = await this.httpClient.get<DataResponse<User>>(
27
+ `/api/users/${userId}`,
28
+ );
26
29
 
27
- return response.data;
28
- }
30
+ return response.data;
31
+ }
29
32
 
30
- /**
31
- * Cria um novo usuário.
32
- * @param data - Os dados para criação do usuário.
33
- * @returns Uma resposta contendo os dados do usuário criado.
34
- * @throws Um erro se a criação do usuário falhar.
35
- */
36
- public async createUser(data: CreateUserDTO) {
37
- try {
38
- const response = await this.httpClient.post<DataResponse<User>>(`/users`, data);
33
+ /**
34
+ * Cria um novo usuário.
35
+ * @param data - Os dados para criação do usuário.
36
+ * @returns Uma resposta contendo os dados do usuário criado.
37
+ * @throws Um erro se a criação do usuário falhar.
38
+ */
39
+ public async createUser(data: CreateUserDTO) {
40
+ try {
41
+ const response = await this.httpClient.post<DataResponse<User>>(
42
+ `/api/users`,
43
+ data,
44
+ );
39
45
 
40
- return response.data;
41
- } catch (error) {
42
- throw new Error("Failed to create user", { cause: error });
43
- }
44
- }
46
+ return response.data;
47
+ } catch (error) {
48
+ throw new Error("Failed to create user", { cause: error });
49
+ }
50
+ }
45
51
 
46
- /**
47
- * Atualiza um usuário existente.
48
- * @param userId - O ID do usuário.
49
- * @param data - Os dados para atualização do usuário.
50
- * @returns Uma resposta contendo os dados do usuário atualizado.
51
- * @throws Um erro se a atualização do usuário falhar.
52
- */
53
- public async updateUser(userId: string, data: UpdateUserDTO) {
54
- try {
55
- const response = await this.httpClient.patch<DataResponse<User>>(
56
- `/users/${userId}`,
57
- data,
58
- );
52
+ /**
53
+ * Atualiza um usuário existente.
54
+ * @param userId - O ID do usuário.
55
+ * @param data - Os dados para atualização do usuário.
56
+ * @returns Uma resposta contendo os dados do usuário atualizado.
57
+ * @throws Um erro se a atualização do usuário falhar.
58
+ */
59
+ public async updateUser(userId: string, data: UpdateUserDTO) {
60
+ try {
61
+ const response = await this.httpClient.patch<DataResponse<User>>(
62
+ `/api/users/${userId}`,
63
+ data,
64
+ );
59
65
 
60
- return response.data;
61
- } catch (error) {
62
- throw new Error("Failed to update user", { cause: error });
63
- }
64
- }
66
+ return response.data;
67
+ } catch (error) {
68
+ throw new Error("Failed to update user", { cause: error });
69
+ }
70
+ }
65
71
 
66
- /**
67
- * Sets the authorization token for HTTP requests.
68
- *
69
- * @param token - The authentication token to be used in the `Authorization` header.
70
- */
71
- public setAuth(token: string) {
72
- this.httpClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
73
- }
72
+ /**
73
+ * Sets the authorization token for HTTP requests.
74
+ *
75
+ * @param token - The authentication token to be used in the `Authorization` header.
76
+ */
77
+ public setAuth(token: string) {
78
+ this.httpClient.defaults.headers.common["Authorization"] =
79
+ `Bearer ${token}`;
80
+ }
74
81
  }