@in.pulse-crm/sdk 2.11.3 → 2.11.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,232 +1,245 @@
1
- import { Customer } from "./customers.types";
2
-
3
- export interface WppContact {
4
- id: number;
5
- name: string;
6
- phone: string;
7
- customerId?: number;
8
- avatarUrl?: string;
9
- instance: string;
10
- isBlocked: boolean;
11
- isOnlyAdmin: boolean;
12
- lastOutOfHoursReplySentAt?: Date | null;
13
- }
14
-
15
- export interface WppContactWithCustomer {
16
- id: number;
17
- name: string;
18
- phone: string;
19
- customerId?: number;
20
- avatarUrl?: string;
21
- instance: string;
22
- isBlocked: boolean;
23
- isOnlyAdmin: boolean;
24
- customer: Customer | null;
25
- chatingWith: string | null;
26
- lastOutOfHoursReplySentAt?: Date | null;
27
- }
28
-
29
- export interface WppMessage {
30
- id: number;
31
- instance: string;
32
- wwebjsId: string | null;
33
- wabaId: string | null;
34
- gupshupId: string | null;
35
- gupshupRequestId: string | null;
36
- from: string;
37
- to: string;
38
- type: string;
39
- quotedId: number | null;
40
- chatId: number | null;
41
- contactId: number | null;
42
- body: string;
43
- timestamp: string;
44
- status: WppMessageStatus;
45
- isForwarded: boolean;
46
- isEdited: boolean;
47
- fileId: number | null;
48
- fileName: string | null;
49
- fileType: string | null;
50
- fileSize: string | null;
51
- wwebjsIdStanza: string | null;
52
- sentAt: Date;
53
- userId: number | null;
54
- billingCategory: string | null;
55
- }
56
- export interface ForwardMessagesData {
57
- sourceType: "whatsapp" | "internal";
58
- messageIds: number[];
59
- whatsappTargets?: Array<{ id: string; isGroup: boolean }>;
60
- internalTargets?: Array<{ id: number }>;
61
- }
62
-
63
- export interface WppChat {
64
- id: number;
65
- instance: string;
66
- contactId?: number;
67
- userId?: number;
68
- userName?: string;
69
- walletId?: number;
70
- botId?: number;
71
- resultId?: number;
72
- sectorId?: number;
73
- type: WppChatType;
74
- priority: WppChatPriority;
75
- avatarUrl?: string;
76
- isFinished: boolean;
77
- startedAt: Date;
78
- finishedAt?: Date | null;
79
- finishedBy?: number | null;
80
- isSchedule: boolean;
81
- }
82
-
83
- export interface WppSector {
84
- id: number;
85
- name: string;
86
- instanceName: string;
87
- wppInstanceId?: number;
88
- startChats: boolean;
89
- receiveChats: boolean;
90
- }
91
-
92
- export interface WppWallet {
93
- instance: string;
94
- id: number;
95
- name: string;
96
- userIds: number[];
97
- }
98
-
99
- // Enums
100
- export type WppMessageStatus =
101
- | "PENDING"
102
- | "SENT"
103
- | "RECEIVED"
104
- | "READ"
105
- | "DOWNLOADED"
106
- | "ERROR"
107
- | "REVOKED";
108
-
109
- export enum WppChatType {
110
- RECEPTIVE = "RECEPTIVE",
111
- ACTIVE = "ACTIVE",
112
- }
113
-
114
- export enum WppChatPriority {
115
- LOW = "LOW",
116
- NORMAL = "NORMAL",
117
- HIGH = "HIGH",
118
- VERY_HIGH = "VERY_HIGH",
119
- URGENCY = "URGENCY",
120
- }
121
-
122
- export type WppChatWithDetails = WppChat & {
123
- contact: WppContact | null;
124
- customer: Customer | null;
125
- schedule: WppSchedule | null;
126
- };
127
- export type WppChatsAndMessages = {
128
- chats: WppChatWithDetails[];
129
- messages: WppMessage[];
130
- };
131
- export type WppChatWithDetailsAndMessages = WppChatWithDetails & {
132
- messages: WppMessage[];
133
- };
134
-
135
- export interface SendMessageData {
136
- sendAsChatOwner?: boolean;
137
- sendAsAudio?: boolean;
138
- sendAsDocument?: boolean;
139
- contactId: number;
140
- quotedId?: number | null;
141
- chatId?: number | null;
142
- text?: string | null;
143
- file?: File;
144
- fileId?: number;
145
- }
146
- export interface MonitorChat {
147
- id: string;
148
- erpCode: string;
149
- companyName: string;
150
- contactName: string;
151
- whatsappNumber: string;
152
- sectorName: string;
153
- attendantName: string;
154
- startDate: string;
155
- endDate: string;
156
- result: string;
157
- }
158
-
159
- export interface CreateScheduleDTO {
160
- contactId: number;
161
- date: Date;
162
- scheduledFor: number;
163
- sectorId: number;
164
- }
165
-
166
- export interface WppSchedule {
167
- id: number;
168
- instance: string;
169
- sectorId: number;
170
- description: string | null;
171
- contactId: number;
172
- scheduleDate: string;
173
- scheduledBy: number;
174
- scheduledFor: number;
175
- scheduledAt: string;
176
- chatId: number | null;
177
- contact: WppContact;
178
- }
179
- export type NotificationType =
180
- | "CHAT_AUTO_FINISHED"
181
- | "CHAT_TRANSFERRED"
182
- | "CHAT_REASSIGNED"
183
- | "ALERT"
184
- | "INFO"
185
- | "WARNING"
186
- | "ERROR";
187
-
188
- export interface AppNotification {
189
- id: number;
190
- title: string;
191
- description: string;
192
- read: boolean;
193
- instance: string;
194
- userId: number | null;
195
- chatId: number | null;
196
- type: NotificationType;
197
- createdAt: string;
198
- }
199
-
200
- export interface PaginatedNotificationsResponse {
201
- notifications: AppNotification[];
202
- totalCount: number;
203
- }
204
- export interface AutomaticResponseSchedule {
205
- id?: number;
206
- dayOfWeek: number;
207
- startTime: string;
208
- endTime: string;
209
- }
210
-
211
- export interface AutomaticResponseRule {
212
- id: number;
213
- name: string;
214
- message: string;
215
- isEnabled: boolean;
216
- isGlobal: boolean;
217
- cooldownSeconds: number;
218
- fileId: number | null;
219
- schedules: AutomaticResponseSchedule[];
220
- userAssignments: { userId: number }[];
221
- }
222
-
223
- export interface AutomaticResponseRuleDTO {
224
- name: string;
225
- message: string;
226
- isEnabled: boolean;
227
- isGlobal: boolean;
228
- cooldownSeconds: number;
229
- fileId?: number | null;
230
- userIds: number[];
231
- schedules: Omit<AutomaticResponseSchedule, "id">[];
232
- }
1
+ import { Customer } from "./customers.types";
2
+
3
+ export interface WppContact {
4
+ id: number;
5
+ name: string;
6
+ phone: string;
7
+ customerId?: number;
8
+ avatarUrl?: string;
9
+ instance: string;
10
+ isBlocked: boolean;
11
+ isOnlyAdmin: boolean;
12
+ lastOutOfHoursReplySentAt?: Date | null;
13
+ }
14
+
15
+ export interface WppContactWithCustomer {
16
+ id: number;
17
+ name: string;
18
+ phone: string;
19
+ customerId?: number;
20
+ avatarUrl?: string;
21
+ instance: string;
22
+ isBlocked: boolean;
23
+ isOnlyAdmin: boolean;
24
+ customer: Customer | null;
25
+ chatingWith: string | null;
26
+ lastOutOfHoursReplySentAt?: Date | null;
27
+ }
28
+
29
+ export interface WppMessage {
30
+ id: number;
31
+ instance: string;
32
+ wwebjsId: string | null;
33
+ wabaId: string | null;
34
+ gupshupId: string | null;
35
+ gupshupRequestId: string | null;
36
+ from: string;
37
+ to: string;
38
+ type: string;
39
+ quotedId: number | null;
40
+ chatId: number | null;
41
+ contactId: number | null;
42
+ body: string;
43
+ timestamp: string;
44
+ status: WppMessageStatus;
45
+ isForwarded: boolean;
46
+ isEdited: boolean;
47
+ fileId: number | null;
48
+ fileName: string | null;
49
+ fileType: string | null;
50
+ fileSize: string | null;
51
+ wwebjsIdStanza: string | null;
52
+ sentAt: Date;
53
+ userId: number | null;
54
+ billingCategory: string | null;
55
+ }
56
+ export interface ForwardMessagesData {
57
+ sourceType: "whatsapp" | "internal";
58
+ messageIds: number[];
59
+ whatsappTargets?: Array<{ id: string; isGroup: boolean }>;
60
+ internalTargets?: Array<{ id: number }>;
61
+ }
62
+
63
+ export interface WppChat {
64
+ id: number;
65
+ instance: string;
66
+ contactId?: number;
67
+ userId?: number;
68
+ userName?: string;
69
+ walletId?: number;
70
+ botId?: number;
71
+ resultId?: number;
72
+ sectorId?: number;
73
+ type: WppChatType;
74
+ priority: WppChatPriority;
75
+ avatarUrl?: string;
76
+ isFinished: boolean;
77
+ startedAt: Date;
78
+ finishedAt?: Date | null;
79
+ finishedBy?: number | null;
80
+ isSchedule: boolean;
81
+ }
82
+
83
+ export interface WppSector {
84
+ id: number;
85
+ name: string;
86
+ instanceName: string;
87
+ wppInstanceId?: number;
88
+ startChats: boolean;
89
+ receiveChats: boolean;
90
+ }
91
+
92
+ export interface WppWallet {
93
+ instance: string;
94
+ id: number;
95
+ name: string;
96
+ userIds: number[];
97
+ }
98
+
99
+ // Enums
100
+ export type WppMessageStatus =
101
+ | "PENDING"
102
+ | "SENT"
103
+ | "RECEIVED"
104
+ | "READ"
105
+ | "DOWNLOADED"
106
+ | "ERROR"
107
+ | "REVOKED";
108
+
109
+ export enum WppChatType {
110
+ RECEPTIVE = "RECEPTIVE",
111
+ ACTIVE = "ACTIVE",
112
+ }
113
+
114
+ export enum WppChatPriority {
115
+ LOW = "LOW",
116
+ NORMAL = "NORMAL",
117
+ HIGH = "HIGH",
118
+ VERY_HIGH = "VERY_HIGH",
119
+ URGENCY = "URGENCY",
120
+ }
121
+
122
+ export type WppChatWithDetails = WppChat & {
123
+ contact: WppContact | null;
124
+ customer: Customer | null;
125
+ schedule: WppSchedule | null;
126
+ };
127
+ export type WppChatsAndMessages = {
128
+ chats: WppChatWithDetails[];
129
+ messages: WppMessage[];
130
+ };
131
+ export type WppChatWithDetailsAndMessages = WppChatWithDetails & {
132
+ messages: WppMessage[];
133
+ };
134
+
135
+ export interface SendMessageData {
136
+ sendAsChatOwner?: boolean;
137
+ sendAsAudio?: boolean;
138
+ sendAsDocument?: boolean;
139
+ contactId: number;
140
+ quotedId?: number | null;
141
+ chatId?: number | null;
142
+ text?: string | null;
143
+ file?: File;
144
+ fileId?: number;
145
+ }
146
+ export interface MonitorChat {
147
+ id: string;
148
+ erpCode: string;
149
+ companyName: string;
150
+ contactName: string;
151
+ whatsappNumber: string;
152
+ sectorName: string;
153
+ attendantName: string;
154
+ startDate: string;
155
+ endDate: string;
156
+ result: string;
157
+ }
158
+
159
+ export interface CreateScheduleDTO {
160
+ contactId: number;
161
+ date: Date;
162
+ scheduledFor: number;
163
+ sectorId: number;
164
+ }
165
+
166
+ export interface WppSchedule {
167
+ id: number;
168
+ instance: string;
169
+ sectorId: number;
170
+ description: string | null;
171
+ contactId: number;
172
+ scheduleDate: string;
173
+ scheduledBy: number;
174
+ scheduledFor: number;
175
+ scheduledAt: string;
176
+ chatId: number | null;
177
+ contact: WppContact;
178
+ }
179
+ export type NotificationType =
180
+ | "CHAT_AUTO_FINISHED"
181
+ | "CHAT_TRANSFERRED"
182
+ | "CHAT_REASSIGNED"
183
+ | "ALERT"
184
+ | "INFO"
185
+ | "WARNING"
186
+ | "ERROR";
187
+
188
+ export interface AppNotification {
189
+ id: number;
190
+ title: string;
191
+ description: string;
192
+ read: boolean;
193
+ instance: string;
194
+ userId: number | null;
195
+ chatId: number | null;
196
+ type: NotificationType;
197
+ createdAt: string;
198
+ }
199
+
200
+ export interface PaginatedNotificationsResponse {
201
+ notifications: AppNotification[];
202
+ totalCount: number;
203
+ }
204
+ export type Frequency = 'ONCE' | 'DAILY' | 'WEEKLY' | 'MONTHLY' | 'YEARLY';
205
+
206
+ export interface AutomaticResponseSchedule {
207
+ id?: number;
208
+
209
+ frequency: Frequency;
210
+ daysOfWeek?: number[] | null;
211
+ dayOfMonth?: number | null;
212
+ month?: number | null;
213
+
214
+ startDate?: string | null;
215
+ endDate?: string | null;
216
+
217
+ startTime: string;
218
+ endTime: string;
219
+ timezone?: string | null;
220
+
221
+ dayOfWeek?: number | null;
222
+ }
223
+
224
+ export interface AutomaticResponseRule {
225
+ id: number;
226
+ name: string;
227
+ message: string;
228
+ isEnabled: boolean;
229
+ isGlobal: boolean;
230
+ cooldownSeconds: number;
231
+ fileId: number | null;
232
+ schedules: AutomaticResponseSchedule[];
233
+ userAssignments: { userId: number }[];
234
+ }
235
+
236
+ export interface AutomaticResponseRuleDTO {
237
+ name: string;
238
+ message: string;
239
+ isEnabled: boolean;
240
+ isGlobal: boolean;
241
+ cooldownSeconds: number;
242
+ fileId?: number | null;
243
+ userIds: number[];
244
+ schedules: Omit<AutomaticResponseSchedule, "id">[];
245
+ }
@@ -1,88 +1,88 @@
1
- import { DataResponse, PaginatedResponse } from "./types/response.types";
2
- import { CreateUserDTO, UpdateUserDTO, User } from "./types/user.types";
3
- import ApiClient from "./api-client";
4
- import { RequestFilters } from "./types";
5
-
6
- /**
7
- * SDK para operações de usuários.
8
- */
9
- export default class UsersClient extends ApiClient {
10
- /**
11
- * Obtém a lista de usuários.
12
- * @param filters - Filtros opcionais para a query.
13
- * @returns Uma resposta paginada contendo os usuários.
14
- */
15
- public async getUsers(filters?: RequestFilters<User>) {
16
- let baseUrl = `/api/users`;
17
-
18
- if (filters) {
19
- const params = new URLSearchParams(filters);
20
- baseUrl += `?${params.toString()}`;
21
- }
22
-
23
- const response =
24
- await this.ax.get<PaginatedResponse<User>>(baseUrl);
25
-
26
- return response.data;
27
- }
28
-
29
- /**
30
- * Obtém um usuário pelo ID.
31
- * @param userId - O ID do usuário.
32
- * @returns Uma resposta contendo os dados do usuário.
33
- */
34
- public async getUserById(userId: number) {
35
- const { data: res } = await this.ax.get<DataResponse<User>>(
36
- `/api/users/${userId}`,
37
- );
38
-
39
- return res.data;
40
- }
41
-
42
- /**
43
- * Cria um novo usuário.
44
- * @param data - Os dados para criação do usuário.
45
- * @returns Uma resposta contendo os dados do usuário criado.
46
- * @throws Um erro se a criação do usuário falhar.
47
- */
48
- public async createUser(data: CreateUserDTO) {
49
- try {
50
- const { data: res } = await this.ax.post<
51
- DataResponse<User>
52
- >(`/api/users`, data);
53
-
54
- return res.data;
55
- } catch (error) {
56
- throw new Error("Failed to create user", { cause: error });
57
- }
58
- }
59
-
60
- /**
61
- * Atualiza um usuário existente.
62
- * @param userId - O ID do usuário.
63
- * @param data - Os dados para atualização do usuário.
64
- * @returns Uma resposta contendo os dados do usuário atualizado.
65
- * @throws Um erro se a atualização do usuário falhar.
66
- */
67
- public async updateUser(userId: string, data: UpdateUserDTO) {
68
- try {
69
- const { data: res } = await this.ax.patch<
70
- DataResponse<User>
71
- >(`/api/users/${userId}`, data);
72
-
73
- return res.data;
74
- } catch (error) {
75
- throw new Error("Failed to update user", { cause: error });
76
- }
77
- }
78
-
79
- /**
80
- * Sets the authorization token for HTTP requests.
81
- *
82
- * @param token - The authentication token to be used in the `Authorization` header.
83
- */
84
- public setAuth(token: string) {
85
- this.ax.defaults.headers.common["Authorization"] =
86
- `Bearer ${token}`;
87
- }
88
- }
1
+ import { DataResponse, PaginatedResponse } from "./types/response.types";
2
+ import { CreateUserDTO, UpdateUserDTO, User } from "./types/user.types";
3
+ import ApiClient from "./api-client";
4
+ import { RequestFilters } from "./types";
5
+
6
+ /**
7
+ * SDK para operações de usuários.
8
+ */
9
+ export default class UsersClient extends ApiClient {
10
+ /**
11
+ * Obtém a lista de usuários.
12
+ * @param filters - Filtros opcionais para a query.
13
+ * @returns Uma resposta paginada contendo os usuários.
14
+ */
15
+ public async getUsers(filters?: RequestFilters<User>) {
16
+ let baseUrl = `/api/users`;
17
+
18
+ if (filters) {
19
+ const params = new URLSearchParams(filters);
20
+ baseUrl += `?${params.toString()}`;
21
+ }
22
+
23
+ const response =
24
+ await this.ax.get<PaginatedResponse<User>>(baseUrl);
25
+
26
+ return response.data;
27
+ }
28
+
29
+ /**
30
+ * Obtém um usuário pelo ID.
31
+ * @param userId - O ID do usuário.
32
+ * @returns Uma resposta contendo os dados do usuário.
33
+ */
34
+ public async getUserById(userId: number) {
35
+ const { data: res } = await this.ax.get<DataResponse<User>>(
36
+ `/api/users/${userId}`,
37
+ );
38
+
39
+ return res.data;
40
+ }
41
+
42
+ /**
43
+ * Cria um novo usuário.
44
+ * @param data - Os dados para criação do usuário.
45
+ * @returns Uma resposta contendo os dados do usuário criado.
46
+ * @throws Um erro se a criação do usuário falhar.
47
+ */
48
+ public async createUser(data: CreateUserDTO) {
49
+ try {
50
+ const { data: res } = await this.ax.post<
51
+ DataResponse<User>
52
+ >(`/api/users`, data);
53
+
54
+ return res.data;
55
+ } catch (error) {
56
+ throw new Error("Failed to create user", { cause: error });
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Atualiza um usuário existente.
62
+ * @param userId - O ID do usuário.
63
+ * @param data - Os dados para atualização do usuário.
64
+ * @returns Uma resposta contendo os dados do usuário atualizado.
65
+ * @throws Um erro se a atualização do usuário falhar.
66
+ */
67
+ public async updateUser(userId: string, data: UpdateUserDTO) {
68
+ try {
69
+ const { data: res } = await this.ax.patch<
70
+ DataResponse<User>
71
+ >(`/api/users/${userId}`, data);
72
+
73
+ return res.data;
74
+ } catch (error) {
75
+ throw new Error("Failed to update user", { cause: error });
76
+ }
77
+ }
78
+
79
+ /**
80
+ * Sets the authorization token for HTTP requests.
81
+ *
82
+ * @param token - The authentication token to be used in the `Authorization` header.
83
+ */
84
+ public setAuth(token: string) {
85
+ this.ax.defaults.headers.common["Authorization"] =
86
+ `Bearer ${token}`;
87
+ }
88
+ }