@in.pulse-crm/sdk 2.4.4 → 2.4.5

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.
@@ -1,5 +1,5 @@
1
1
  import ApiClient from "./api-client";
2
- import { RequestFilters } from "./types";
2
+ import { PaginatedResponse, RequestFilters } from "./types";
3
3
  import { CreateCustomerDTO, Customer, UpdateCustomerDTO } from "./types/customers.types";
4
4
  declare class CustomersClient extends ApiClient {
5
5
  /**
@@ -28,7 +28,7 @@ declare class CustomersClient extends ApiClient {
28
28
  * @todo Implementar tipagem para os filtros.
29
29
  * @returns Uma Promise que resolve para uma lista de clientes.
30
30
  */
31
- getCustomers(filters?: RequestFilters<Customer>): Promise<any>;
31
+ getCustomers(filters?: RequestFilters<Customer>): Promise<PaginatedResponse<Customer>>;
32
32
  /**
33
33
  * Define o token de autenticação para as requisições.
34
34
  * @param token - O token de autenticação a ser definido.
@@ -14,7 +14,7 @@ export interface PaginatedResponse<T> {
14
14
  data: Array<T>;
15
15
  page: {
16
16
  current: number;
17
- total: number;
17
+ totalRows: number;
18
18
  };
19
19
  }
20
20
  export interface QueryResponse<T> {
@@ -8,6 +8,17 @@ export interface WppContact {
8
8
  isBlocked: boolean;
9
9
  isOnlyAdmin: boolean;
10
10
  }
11
+ export interface WppContactWithCustomer {
12
+ id: number;
13
+ name: string;
14
+ phone: string;
15
+ customerId?: number;
16
+ instance: string;
17
+ isBlocked: boolean;
18
+ isOnlyAdmin: boolean;
19
+ customer: Customer | null;
20
+ chatingWith: string | null;
21
+ }
11
22
  export interface WppMessage {
12
23
  id: number;
13
24
  instance: string;
@@ -1,5 +1,5 @@
1
1
  import ApiClient from "./api-client";
2
- import { SendMessageData, WppChatsAndMessages, WppChatWithDetailsAndMessages, WppMessage, WppWallet } from "./types/whatsapp.types";
2
+ import { SendMessageData, WppChatsAndMessages, WppChatWithDetailsAndMessages, WppContact, WppContactWithCustomer, WppMessage, WppWallet } from "./types/whatsapp.types";
3
3
  export default class WhatsappClient extends ApiClient {
4
4
  getChatsBySession(token: string, messages?: boolean, contact?: boolean): Promise<WppChatsAndMessages>;
5
5
  getChatById(id: number): Promise<WppChatWithDetailsAndMessages>;
@@ -12,5 +12,10 @@ export default class WhatsappClient extends ApiClient {
12
12
  id: number;
13
13
  name: string;
14
14
  }[]>;
15
+ getCustomerContacts(customerId: number): Promise<WppContact[]>;
16
+ getContactsWithCustomer(): Promise<WppContactWithCustomer[]>;
17
+ createContact(name: string, phone: string, customerId: number): Promise<WppContact>;
18
+ updateContact(contactId: number, name: string): Promise<WppContact>;
19
+ deleteContact(contactId: number): Promise<void>;
15
20
  setAuth(token: string): void;
16
21
  }
@@ -63,6 +63,32 @@ class WhatsappClient extends api_client_1.default {
63
63
  const { data: res } = await this.httpClient.get(url);
64
64
  return res.data;
65
65
  }
66
+ async getCustomerContacts(customerId) {
67
+ const url = `/api/whatsapp/customer/${customerId}/contacts`;
68
+ const { data: res } = await this.httpClient.get(url);
69
+ return res.data;
70
+ }
71
+ async getContactsWithCustomer() {
72
+ const url = `/api/whatsapp/contacts`;
73
+ const { data: res } = await this.httpClient.get(url);
74
+ return res.data;
75
+ }
76
+ async createContact(name, phone, customerId) {
77
+ const url = `/api/whatsapp/customers/${customerId}/contacts`;
78
+ const body = { name, phone };
79
+ const { data: res } = await this.httpClient.post(url, body);
80
+ return res.data;
81
+ }
82
+ async updateContact(contactId, name) {
83
+ const url = `/api/whatsapp/contacts/${contactId}`;
84
+ const body = { name };
85
+ const { data: res } = await this.httpClient.put(url, body);
86
+ return res.data;
87
+ }
88
+ async deleteContact(contactId) {
89
+ const url = `/api/whatsapp/contacts/${contactId}`;
90
+ await this.httpClient.delete(url);
91
+ }
66
92
  setAuth(token) {
67
93
  this.httpClient.defaults.headers.common["Authorization"] =
68
94
  `Bearer ${token}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@in.pulse-crm/sdk",
3
- "version": "2.4.4",
3
+ "version": "2.4.5",
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",
@@ -1,5 +1,5 @@
1
1
  import ApiClient from "./api-client";
2
- import { RequestFilters } from "./types";
2
+ import { PaginatedResponse, RequestFilters } from "./types";
3
3
  import {
4
4
  CreateCustomerDTO,
5
5
  Customer,
@@ -59,7 +59,7 @@ class CustomersClient extends ApiClient {
59
59
  baseUrl += `?${params.toString()}`;
60
60
  }
61
61
 
62
- const response = await this.httpClient.get(baseUrl);
62
+ const response = await this.httpClient.get<PaginatedResponse<Customer>>(baseUrl);
63
63
 
64
64
  return response.data;
65
65
  }
@@ -17,7 +17,7 @@ export interface PaginatedResponse<T> {
17
17
  data: Array<T>;
18
18
  page: {
19
19
  current: number;
20
- total: number;
20
+ totalRows: number;
21
21
  };
22
22
  }
23
23
 
@@ -10,6 +10,18 @@ export interface WppContact {
10
10
  isOnlyAdmin: boolean;
11
11
  }
12
12
 
13
+ export interface WppContactWithCustomer {
14
+ id: number;
15
+ name: string;
16
+ phone: string;
17
+ customerId?: number;
18
+ instance: string;
19
+ isBlocked: boolean;
20
+ isOnlyAdmin: boolean;
21
+ customer: Customer | null;
22
+ chatingWith: string | null;
23
+ }
24
+
13
25
  export interface WppMessage {
14
26
  id: number;
15
27
  instance: string;
@@ -58,7 +70,7 @@ export interface WppWallet {
58
70
  instance: string;
59
71
  id: number;
60
72
  name: string;
61
- userIds: number[]
73
+ userIds: number[];
62
74
  }
63
75
 
64
76
  // Enums
@@ -4,6 +4,8 @@ import {
4
4
  SendMessageData,
5
5
  WppChatsAndMessages,
6
6
  WppChatWithDetailsAndMessages,
7
+ WppContact,
8
+ WppContactWithCustomer,
7
9
  WppMessage,
8
10
  WppWallet,
9
11
  } from "./types/whatsapp.types";
@@ -99,11 +101,62 @@ export default class WhatsappClient extends ApiClient {
99
101
 
100
102
  public async getResults() {
101
103
  const url = `/api/whatsapp/results`;
102
- const { data: res } = await this.httpClient.get<DataResponse<{ id: number, name: string }[]>>(url);
104
+ const { data: res } =
105
+ await this.httpClient.get<
106
+ DataResponse<{ id: number; name: string }[]>
107
+ >(url);
108
+
109
+ return res.data;
110
+ }
111
+
112
+ public async getCustomerContacts(customerId: number) {
113
+ const url = `/api/whatsapp/customer/${customerId}/contacts`;
114
+ const { data: res } =
115
+ await this.httpClient.get<DataResponse<WppContact[]>>(url);
116
+
117
+ return res.data;
118
+ }
119
+
120
+ public async getContactsWithCustomer() {
121
+ const url = `/api/whatsapp/contacts`;
122
+ const { data: res } =
123
+ await this.httpClient.get<DataResponse<WppContactWithCustomer[]>>(url);
124
+
125
+ return res.data;
126
+ }
127
+
128
+ public async createContact(
129
+ name: string,
130
+ phone: string,
131
+ customerId: number,
132
+ ) {
133
+ const url = `/api/whatsapp/customers/${customerId}/contacts`;
134
+ const body = { name, phone };
135
+
136
+ const { data: res } = await this.httpClient.post<
137
+ DataResponse<WppContact>
138
+ >(url, body);
103
139
 
104
140
  return res.data;
105
141
  }
106
142
 
143
+ public async updateContact(contactId: number, name: string) {
144
+ const url = `/api/whatsapp/contacts/${contactId}`;
145
+ const body = { name };
146
+
147
+ const { data: res } = await this.httpClient.put<
148
+ DataResponse<WppContact>
149
+ >(url, body);
150
+
151
+ return res.data;
152
+ }
153
+
154
+ public async deleteContact(contactId: number) {
155
+ const url = `/api/whatsapp/contacts/${contactId}`;
156
+
157
+ await this.httpClient.delete<MessageResponse>(url);
158
+ }
159
+
107
160
  public setAuth(token: string) {
108
161
  this.httpClient.defaults.headers.common["Authorization"] =
109
162
  `Bearer ${token}`;