@first-to-fly/crm-sdk 1.1.0 → 1.3.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/dist/api.d.ts ADDED
@@ -0,0 +1,842 @@
1
+ /**
2
+ * GENERATED from crm-be zod contracts by scripts/gen-sdk-contracts.ts — do not edit by hand.
3
+ *
4
+ * These types are derived directly from the CRM backend's zod request/response
5
+ * schemas so the SDK's typed API client cannot drift from the server. To
6
+ * regenerate after a contract change, run `bun run gen:sdk-contracts` in crm-be.
7
+ *
8
+ * This file is fully self-contained: it has no runtime imports and no dependency
9
+ * on crm-be or zod.
10
+ */
11
+ type ContactCreate = {
12
+ name: string;
13
+ display_name?: (string | undefined) | null;
14
+ email?: (string | undefined) | "";
15
+ phone?: (string | "") | undefined;
16
+ notes?: (string | undefined) | null;
17
+ avatar_url?: (string | undefined) | null;
18
+ position?: (string | undefined) | null;
19
+ company_name?: (string | undefined) | null;
20
+ mobile?: (string | undefined) | null;
21
+ city?: (string | undefined) | null;
22
+ country?: (string | undefined) | null;
23
+ timezone?: (string | undefined) | null;
24
+ communication_preference?: (("email" | "phone" | "whatsapp") | undefined) | null;
25
+ tags?: (string[] | undefined) | null;
26
+ priority?: (("low" | "medium" | "high" | "vip") | undefined) | null;
27
+ department?: (string | undefined) | null;
28
+ industry?: (string | undefined) | null;
29
+ assigned_to?: (string | undefined) | null;
30
+ metadata?: {
31
+ [x: string]: unknown;
32
+ } | undefined;
33
+ custom_fields?: ({
34
+ [x: string]: unknown;
35
+ } | undefined) | null;
36
+ };
37
+ type ContactUpdate = {
38
+ name?: string | undefined;
39
+ display_name?: ((string | undefined) | null) | undefined;
40
+ email?: ((string | undefined) | "") | undefined;
41
+ phone?: ((string | "") | undefined) | undefined;
42
+ notes?: ((string | undefined) | null) | undefined;
43
+ avatar_url?: ((string | undefined) | null) | undefined;
44
+ position?: ((string | undefined) | null) | undefined;
45
+ company_name?: ((string | undefined) | null) | undefined;
46
+ mobile?: ((string | undefined) | null) | undefined;
47
+ city?: ((string | undefined) | null) | undefined;
48
+ country?: ((string | undefined) | null) | undefined;
49
+ timezone?: ((string | undefined) | null) | undefined;
50
+ communication_preference?: ((("email" | "phone" | "whatsapp") | undefined) | null) | undefined;
51
+ tags?: ((string[] | undefined) | null) | undefined;
52
+ priority?: ((("low" | "medium" | "high" | "vip") | undefined) | null) | undefined;
53
+ department?: ((string | undefined) | null) | undefined;
54
+ industry?: ((string | undefined) | null) | undefined;
55
+ assigned_to?: ((string | undefined) | null) | undefined;
56
+ metadata?: ({
57
+ [x: string]: unknown;
58
+ } | undefined) | undefined;
59
+ custom_fields?: (({
60
+ [x: string]: unknown;
61
+ } | undefined) | null) | undefined;
62
+ };
63
+ type ContactQuery = {
64
+ page?: number;
65
+ pageSize?: number;
66
+ search?: string | undefined;
67
+ name?: string | undefined;
68
+ email?: string | undefined;
69
+ phone?: string | undefined;
70
+ status?: ("active" | "blocked") | undefined;
71
+ company_name?: string | undefined;
72
+ priority?: ("low" | "medium" | "high" | "vip") | undefined;
73
+ department?: string | undefined;
74
+ industry?: string | undefined;
75
+ communication_preference?: ("email" | "phone" | "whatsapp") | undefined;
76
+ assigned_to?: string | undefined;
77
+ tags?: string | undefined;
78
+ tag_filter?: ("and" | "or");
79
+ include_tags?: boolean;
80
+ };
81
+ type Contact = {
82
+ id: string;
83
+ name: string;
84
+ display_name?: (string | undefined) | null;
85
+ email?: string | undefined;
86
+ phone?: (string | undefined) | null;
87
+ notes?: string | undefined;
88
+ status: "active" | "blocked";
89
+ assigned_to?: (string | undefined) | null;
90
+ assignment: {
91
+ assigned_to?: (string | undefined) | null;
92
+ assigned_user_name?: (string | undefined) | null;
93
+ assigned_user_email?: (string | undefined) | null;
94
+ assigned_user_avatar?: (string | undefined) | null;
95
+ };
96
+ user_id: string;
97
+ workspace_id: string;
98
+ created_at: string;
99
+ updated_at: string;
100
+ deleted_at?: (string | undefined) | null;
101
+ avatar_url?: (string | undefined) | null;
102
+ position?: (string | undefined) | null;
103
+ company_name?: (string | undefined) | null;
104
+ mobile?: (string | undefined) | null;
105
+ city?: (string | undefined) | null;
106
+ country?: (string | undefined) | null;
107
+ timezone?: (string | undefined) | null;
108
+ communication_preference?: (("email" | "phone" | "whatsapp") | undefined) | null;
109
+ tags?: (string[] | undefined) | null;
110
+ priority?: (("low" | "medium" | "high" | "vip") | undefined) | null;
111
+ department?: (string | undefined) | null;
112
+ industry?: (string | undefined) | null;
113
+ metadata?: {
114
+ [x: string]: unknown;
115
+ } | undefined;
116
+ custom_fields?: ({
117
+ [x: string]: unknown;
118
+ } | undefined) | null;
119
+ tag_objects?: {
120
+ [x: string]: unknown;
121
+ }[] | undefined;
122
+ conversations?: {
123
+ id: string;
124
+ channel: "whatsapp" | "whatsapp_web" | "messenger" | "instagram" | "email" | "sms" | "webchat";
125
+ channel_id?: (string | undefined) | null;
126
+ merge_group_id?: (string | undefined) | null;
127
+ merged_count?: number | undefined;
128
+ }[] | undefined;
129
+ email_suppression?: ({
130
+ id: string;
131
+ reason: "hard_bounce" | "complaint_reply" | "manual";
132
+ reason_detail: string | null;
133
+ created_at: string;
134
+ } | null) | undefined;
135
+ };
136
+ type ContactList = {
137
+ items: {
138
+ id: string;
139
+ name: string;
140
+ display_name?: (string | undefined) | null;
141
+ email?: string | undefined;
142
+ phone?: (string | undefined) | null;
143
+ notes?: string | undefined;
144
+ status: "active" | "blocked";
145
+ assigned_to?: (string | undefined) | null;
146
+ assignment: {
147
+ assigned_to?: (string | undefined) | null;
148
+ assigned_user_name?: (string | undefined) | null;
149
+ assigned_user_email?: (string | undefined) | null;
150
+ assigned_user_avatar?: (string | undefined) | null;
151
+ };
152
+ user_id: string;
153
+ workspace_id: string;
154
+ created_at: string;
155
+ updated_at: string;
156
+ deleted_at?: (string | undefined) | null;
157
+ avatar_url?: (string | undefined) | null;
158
+ position?: (string | undefined) | null;
159
+ company_name?: (string | undefined) | null;
160
+ mobile?: (string | undefined) | null;
161
+ city?: (string | undefined) | null;
162
+ country?: (string | undefined) | null;
163
+ timezone?: (string | undefined) | null;
164
+ communication_preference?: (("email" | "phone" | "whatsapp") | undefined) | null;
165
+ tags?: (string[] | undefined) | null;
166
+ priority?: (("low" | "medium" | "high" | "vip") | undefined) | null;
167
+ department?: (string | undefined) | null;
168
+ industry?: (string | undefined) | null;
169
+ metadata?: {
170
+ [x: string]: unknown;
171
+ } | undefined;
172
+ custom_fields?: ({
173
+ [x: string]: unknown;
174
+ } | undefined) | null;
175
+ tag_objects?: {
176
+ [x: string]: unknown;
177
+ }[] | undefined;
178
+ conversations?: {
179
+ id: string;
180
+ channel: "whatsapp" | "whatsapp_web" | "messenger" | "instagram" | "email" | "sms" | "webchat";
181
+ channel_id?: (string | undefined) | null;
182
+ merge_group_id?: (string | undefined) | null;
183
+ merged_count?: number | undefined;
184
+ }[] | undefined;
185
+ email_suppression?: ({
186
+ id: string;
187
+ reason: "hard_bounce" | "complaint_reply" | "manual";
188
+ reason_detail: string | null;
189
+ created_at: string;
190
+ } | null) | undefined;
191
+ }[];
192
+ totalCount: number;
193
+ pageCount: number;
194
+ currentPage: number;
195
+ pageSize: number;
196
+ };
197
+ type LeadCreate = {
198
+ name: string;
199
+ email?: ((string | undefined) | null) | "";
200
+ phone?: (string | "") | undefined;
201
+ avatar_url?: (string | undefined) | null;
202
+ status?: string;
203
+ assigned_to?: (string | undefined) | null;
204
+ company_name?: (string | undefined) | null;
205
+ position?: (string | undefined) | null;
206
+ industry?: (string | undefined) | null;
207
+ department?: (string | undefined) | null;
208
+ mobile?: (string | undefined) | null;
209
+ city?: (string | undefined) | null;
210
+ country?: (string | undefined) | null;
211
+ timezone?: (string | undefined) | null;
212
+ priority?: (("low" | "medium" | "high" | "vip") | null) | undefined;
213
+ communication_preference?: (("email" | "phone" | "whatsapp") | null) | undefined;
214
+ tags?: (string[] | undefined) | null;
215
+ notes?: (string | undefined) | null;
216
+ source?: (string | undefined) | null;
217
+ budget?: (number | undefined) | null;
218
+ expected_close_date?: (string | undefined) | null;
219
+ close_outcome?: (("won" | "lost") | undefined) | null;
220
+ close_reason?: (string | undefined) | null;
221
+ close_value?: (number | undefined) | null;
222
+ channel_id?: (string | undefined) | null;
223
+ team_id?: (string | undefined) | null;
224
+ assignment_source?: (("manual" | "auto_round_robin" | "auto_regional" | "workflow_automation") | undefined) | null;
225
+ source_identifier_type?: (("phone" | "email" | "messenger_user_id" | "instagram_user_id" | "whatsapp_phone" | "whatsapp_lid" | "telegram_user_id") | undefined) | null;
226
+ source_identifier_value?: (string | undefined) | null;
227
+ has_potential_duplicates?: boolean | undefined;
228
+ custom_fields?: ({
229
+ [x: string]: unknown;
230
+ } | undefined) | null;
231
+ };
232
+ type LeadUpdate = {
233
+ name?: string | undefined;
234
+ email?: (((string | undefined) | null) | "") | undefined;
235
+ phone?: ((string | "") | undefined) | undefined;
236
+ avatar_url?: ((string | undefined) | null) | undefined;
237
+ status?: string | undefined;
238
+ assigned_to?: ((string | undefined) | null) | undefined;
239
+ company_name?: ((string | undefined) | null) | undefined;
240
+ position?: ((string | undefined) | null) | undefined;
241
+ industry?: ((string | undefined) | null) | undefined;
242
+ department?: ((string | undefined) | null) | undefined;
243
+ mobile?: ((string | undefined) | null) | undefined;
244
+ city?: ((string | undefined) | null) | undefined;
245
+ country?: ((string | undefined) | null) | undefined;
246
+ timezone?: ((string | undefined) | null) | undefined;
247
+ priority?: ((("low" | "medium" | "high" | "vip") | null) | undefined) | undefined;
248
+ communication_preference?: ((("email" | "phone" | "whatsapp") | null) | undefined) | undefined;
249
+ tags?: ((string[] | undefined) | null) | undefined;
250
+ notes?: ((string | undefined) | null) | undefined;
251
+ source?: ((string | undefined) | null) | undefined;
252
+ budget?: ((number | undefined) | null) | undefined;
253
+ expected_close_date?: ((string | undefined) | null) | undefined;
254
+ close_outcome?: ((("won" | "lost") | undefined) | null) | undefined;
255
+ close_reason?: ((string | undefined) | null) | undefined;
256
+ close_value?: ((number | undefined) | null) | undefined;
257
+ channel_id?: ((string | undefined) | null) | undefined;
258
+ team_id?: ((string | undefined) | null) | undefined;
259
+ assignment_source?: ((("manual" | "auto_round_robin" | "auto_regional" | "workflow_automation") | undefined) | null) | undefined;
260
+ source_identifier_type?: ((("phone" | "email" | "messenger_user_id" | "instagram_user_id" | "whatsapp_phone" | "whatsapp_lid" | "telegram_user_id") | undefined) | null) | undefined;
261
+ source_identifier_value?: ((string | undefined) | null) | undefined;
262
+ has_potential_duplicates?: (boolean | undefined) | undefined;
263
+ custom_fields?: (({
264
+ [x: string]: unknown;
265
+ } | undefined) | null) | undefined;
266
+ };
267
+ type LeadQuery = {
268
+ page?: number;
269
+ pageSize?: number;
270
+ search?: string | undefined;
271
+ name?: string | undefined;
272
+ email?: string | undefined;
273
+ phone?: string | undefined;
274
+ assigned_to?: string | undefined;
275
+ status?: string | undefined;
276
+ company_name?: string | undefined;
277
+ industry?: string | undefined;
278
+ priority?: ("low" | "medium" | "high" | "vip") | undefined;
279
+ source?: string | undefined;
280
+ tags?: string | undefined;
281
+ tag_filter?: ("and" | "or");
282
+ include_tags?: boolean;
283
+ include_stage_logs?: boolean;
284
+ include_task_summary?: boolean;
285
+ team_id?: string | undefined;
286
+ task_status?: ("pending" | "due_today" | "overdue" | "completed") | undefined;
287
+ };
288
+ type Lead = {
289
+ id: string;
290
+ name: string;
291
+ email: string;
292
+ phone: string;
293
+ channel_id?: (string | undefined) | null;
294
+ status: string;
295
+ assigned_to?: (string | undefined) | null;
296
+ assigned_user_name?: (string | undefined) | null;
297
+ assigned_user_email?: (string | undefined) | null;
298
+ user_id: string;
299
+ company_id: string;
300
+ created_at: string;
301
+ updated_at: string;
302
+ company_name?: (string | undefined) | null;
303
+ position?: (string | undefined) | null;
304
+ industry?: (string | undefined) | null;
305
+ department?: (string | undefined) | null;
306
+ mobile?: (string | undefined) | null;
307
+ city?: (string | undefined) | null;
308
+ country?: (string | undefined) | null;
309
+ timezone?: (string | undefined) | null;
310
+ priority?: (("low" | "medium" | "high" | "vip") | undefined) | null;
311
+ communication_preference?: (("email" | "phone" | "whatsapp") | undefined) | null;
312
+ tags?: (string[] | undefined) | null;
313
+ notes?: (string | undefined) | null;
314
+ source?: (string | undefined) | null;
315
+ budget?: (number | undefined) | null;
316
+ probability?: (number | undefined) | null;
317
+ expected_close_date?: (string | undefined) | null;
318
+ recent_stage_logs?: {
319
+ id: string;
320
+ lead_id: string;
321
+ previous_stage: string;
322
+ new_stage: string;
323
+ changed_by: string;
324
+ changed_at: string;
325
+ metadata?: {
326
+ [x: string]: any;
327
+ } | undefined;
328
+ changed_by_user?: ({
329
+ id: string;
330
+ full_name?: (string | null) | undefined;
331
+ email?: (string | null) | undefined;
332
+ avatar_url?: (string | null) | undefined;
333
+ } | null) | undefined;
334
+ }[] | undefined;
335
+ has_overdue_tasks?: boolean | undefined;
336
+ avatar_url?: (string | undefined) | null;
337
+ close_outcome?: (("won" | "lost") | undefined) | null;
338
+ close_reason?: (string | undefined) | null;
339
+ close_value?: (number | undefined) | null;
340
+ assignment_source?: (("manual" | "auto_round_robin" | "auto_regional" | "workflow_automation") | undefined) | null;
341
+ team_id?: (string | undefined) | null;
342
+ };
343
+ type LeadNoteCreate = {
344
+ body: string;
345
+ mentions?: string[];
346
+ };
347
+ type LeadNote = {
348
+ id: string;
349
+ lead_id: string;
350
+ body: string;
351
+ created_by: string;
352
+ created_at: string;
353
+ updated_at: string;
354
+ author: {
355
+ id: string;
356
+ full_name?: (string | null) | undefined;
357
+ email?: (string | null) | undefined;
358
+ avatar_url?: (string | null) | undefined;
359
+ } | null;
360
+ };
361
+ type TaskCreate = {
362
+ title: string;
363
+ description?: (string | undefined) | null;
364
+ due_at: string;
365
+ assigned_to?: (string | undefined) | null;
366
+ };
367
+ type TaskUpdate = {
368
+ title?: string | undefined;
369
+ description?: (string | undefined) | null;
370
+ due_at?: string | undefined;
371
+ status?: ("pending" | "completed") | undefined;
372
+ assigned_to?: (string | undefined) | null;
373
+ };
374
+ type TaskQuery = {
375
+ page?: number;
376
+ pageSize?: number;
377
+ search?: string | undefined;
378
+ status?: ("pending" | "completed") | undefined;
379
+ due_filter?: ("today" | "upcoming" | "overdue") | undefined;
380
+ assigned_to?: string | undefined;
381
+ };
382
+ type Task = {
383
+ id: string;
384
+ lead_id: string;
385
+ title: string;
386
+ description?: (string | null) | undefined;
387
+ due_at: string;
388
+ status: "pending" | "completed";
389
+ created_by: string;
390
+ assigned_to?: (string | null) | undefined;
391
+ created_at: string;
392
+ updated_at: string;
393
+ completed_at?: (string | null) | undefined;
394
+ metadata?: {
395
+ [x: string]: any;
396
+ } | undefined;
397
+ created_by_user: {
398
+ id: string;
399
+ full_name?: (string | null) | undefined;
400
+ email?: (string | null) | undefined;
401
+ avatar_url?: (string | null) | undefined;
402
+ } | null;
403
+ assigned_user: {
404
+ id: string;
405
+ full_name?: (string | null) | undefined;
406
+ email?: (string | null) | undefined;
407
+ avatar_url?: (string | null) | undefined;
408
+ } | null;
409
+ is_overdue: boolean;
410
+ is_due_today: boolean;
411
+ };
412
+ type ConversationQuery = {
413
+ page?: number;
414
+ limit?: number;
415
+ pageSize?: number;
416
+ search?: string | undefined;
417
+ assignment?: (("me" | "unassigned" | "assigned" | "others") | string) | undefined;
418
+ status?: string | string[];
419
+ channel?: ("whatsapp" | "whatsapp_web" | "messenger" | "instagram" | "email" | "sms" | "webchat" | "website_form") | undefined;
420
+ channel_id?: string | string[];
421
+ team_id?: string | string[];
422
+ tags?: string | undefined;
423
+ created_from?: string | undefined;
424
+ created_to?: string | undefined;
425
+ message_from?: string | undefined;
426
+ message_to?: string | undefined;
427
+ unread?: boolean | undefined;
428
+ needs_human_reply?: boolean | undefined;
429
+ exclude_merged?: boolean | undefined;
430
+ exclude_email?: boolean | undefined;
431
+ exclude_groups?: boolean | undefined;
432
+ contact_id?: string | undefined;
433
+ lead_stage?: string | undefined;
434
+ system_audience_id?: string | undefined;
435
+ };
436
+ type ConversationUpdate = {
437
+ assigned_to?: (string | undefined) | null;
438
+ notes?: (string | undefined) | null;
439
+ };
440
+ type Conversation = {
441
+ id: string;
442
+ contact: {
443
+ id: string;
444
+ name: string;
445
+ phone: string;
446
+ email?: string | undefined;
447
+ status: "active" | "blocked";
448
+ };
449
+ last_message: {
450
+ content?: string | undefined;
451
+ timestamp?: string | undefined;
452
+ direction?: ("inbound" | "outbound") | undefined;
453
+ status?: ("sent" | "delivered" | "read" | "failed") | undefined;
454
+ };
455
+ assignment: {
456
+ assigned_to?: string | undefined;
457
+ assigned_user_name?: string | undefined;
458
+ assigned_user_email?: string | undefined;
459
+ };
460
+ metadata: {
461
+ conversation_status: ("active" | "blocked" | "archived" | "reopened" | "on_hold") | null;
462
+ statuses?: ("active" | "blocked" | "archived" | "reopened" | "on_hold")[];
463
+ channel: "whatsapp" | "whatsapp_web" | "sms" | "email" | "messenger" | "instagram" | "website_form";
464
+ unread_count: number;
465
+ total_message_count: number;
466
+ is_within_24h_window: boolean;
467
+ has_messages: boolean;
468
+ is_new_contact: boolean;
469
+ conversation_type: "active" | "new" | "archived" | "reopened" | "on_hold";
470
+ notes?: string | undefined;
471
+ };
472
+ channel_info: {
473
+ last_inbound_message_at?: string | undefined;
474
+ last_inbound_message_at_channels: {
475
+ [x: string]: string;
476
+ };
477
+ channel_windows: {
478
+ [x: string]: boolean;
479
+ };
480
+ };
481
+ human_agent_state: {
482
+ is_enabled: boolean;
483
+ activated_at: string | null;
484
+ };
485
+ ai_handoff_state: {
486
+ needs_human_reply: boolean;
487
+ reason: string | null;
488
+ since: string | null;
489
+ };
490
+ timestamps: {
491
+ created_at: string;
492
+ updated_at: string;
493
+ };
494
+ recipient_suppressed: boolean;
495
+ recipient_suppression?: ({
496
+ id: string;
497
+ reason: "hard_bounce" | "complaint_reply" | "manual";
498
+ reason_detail: string | null;
499
+ created_at: string;
500
+ } | null) | undefined;
501
+ };
502
+ type MessageQuery = {
503
+ page?: number;
504
+ pageSize?: number;
505
+ direction?: ("inbound" | "outbound") | undefined;
506
+ channel_id?: string | undefined;
507
+ status?: ("sent" | "delivered" | "read" | "failed") | undefined;
508
+ before?: string | undefined;
509
+ after?: string | undefined;
510
+ };
511
+ type MessageCreate = {
512
+ message?: string | undefined;
513
+ channel?: ("sms" | "whatsapp" | "whatsapp_web" | "email" | "messenger" | "instagram" | "telegram" | "webchat" | "website_form") | undefined;
514
+ channel_id?: string | undefined;
515
+ target_conversation_id?: string | undefined;
516
+ reply_to_id?: string | undefined;
517
+ metadata?: {
518
+ [x: string]: any;
519
+ } | undefined;
520
+ template_id?: string | undefined;
521
+ system_template_id?: string | undefined;
522
+ template_variables?: {
523
+ [x: string]: string;
524
+ } | undefined;
525
+ language_code?: string;
526
+ is_first_message?: boolean | undefined;
527
+ subject?: string | undefined;
528
+ cc?: string[] | undefined;
529
+ bcc?: string[] | undefined;
530
+ htmlContent?: string | undefined;
531
+ inlineImages?: {
532
+ id: string;
533
+ fileName: string;
534
+ mimeType: string;
535
+ }[] | undefined;
536
+ tag?: ("HUMAN_AGENT") | undefined;
537
+ messaging_type?: ("MESSAGE_TAG") | undefined;
538
+ };
539
+ type Message = {
540
+ id: string;
541
+ contact: {
542
+ id: string;
543
+ name?: string | undefined;
544
+ phone?: string | undefined;
545
+ avatar?: string | undefined;
546
+ };
547
+ sender: {
548
+ user_id?: string | undefined;
549
+ name?: string | undefined;
550
+ email?: string | undefined;
551
+ avatar?: string | undefined;
552
+ };
553
+ reply: {
554
+ reply_to_id?: string | undefined;
555
+ reply_to_message?: string | undefined;
556
+ reply_to_sender?: string | undefined;
557
+ };
558
+ message: string;
559
+ direction: "inbound" | "outbound";
560
+ channel: "sms" | "whatsapp" | "email" | "messenger" | "instagram" | "website_form";
561
+ status: "sent" | "delivered" | "read" | "failed";
562
+ type: "text" | "image" | "video" | "audio" | "document" | "sticker" | "contacts" | "reaction" | "activity";
563
+ message_sid?: string | undefined;
564
+ metadata?: {
565
+ [x: string]: any;
566
+ } | undefined;
567
+ delivered_at?: string | undefined;
568
+ sent_at?: string | undefined;
569
+ failed_at?: string | undefined;
570
+ read_at?: string | undefined;
571
+ failure_reason?: {
572
+ [x: string]: any;
573
+ } | undefined;
574
+ created_at: string;
575
+ updated_at: string;
576
+ reactions?: {
577
+ id: string;
578
+ message_id: string;
579
+ user_id: string;
580
+ emoji: string;
581
+ metadata?: {
582
+ [x: string]: any;
583
+ } | undefined;
584
+ created_at: string;
585
+ user_name?: string | undefined;
586
+ user_email?: string | undefined;
587
+ }[];
588
+ media_files?: {
589
+ id: string;
590
+ original_filename: string;
591
+ file_size: number;
592
+ mime_type: string;
593
+ collection_name: string;
594
+ signed_url: string;
595
+ created_at?: any;
596
+ }[];
597
+ activity?: {
598
+ id: string;
599
+ entity_type: string;
600
+ entity_id: string;
601
+ activity_type: string;
602
+ actor_id?: string | undefined;
603
+ actor?: {
604
+ id: string;
605
+ full_name?: string | undefined;
606
+ email?: string | undefined;
607
+ avatar_url?: string | undefined;
608
+ } | undefined;
609
+ body?: {
610
+ [x: string]: any;
611
+ } | undefined;
612
+ created_at?: string | undefined;
613
+ } | undefined;
614
+ activity_id?: string | undefined;
615
+ };
616
+ type ProductCreate = {
617
+ name: string;
618
+ description?: string | undefined;
619
+ price: number;
620
+ };
621
+ type ProductUpdate = {
622
+ name?: string | undefined;
623
+ description?: (string | undefined) | undefined;
624
+ price?: number | undefined;
625
+ };
626
+ type ProductQuery = {
627
+ page?: string | undefined;
628
+ limit?: string | undefined;
629
+ search?: string | undefined;
630
+ name?: string | undefined;
631
+ price_min?: string | undefined;
632
+ price_max?: string | undefined;
633
+ };
634
+ type Product = {
635
+ id: string;
636
+ name: string;
637
+ description?: string | undefined;
638
+ price: number;
639
+ user_id: string;
640
+ company_id: string;
641
+ created_at: string;
642
+ updated_at: string;
643
+ };
644
+ type TagCreate = {
645
+ name: string;
646
+ color?: string;
647
+ description?: string | undefined;
648
+ entity_type: "contact" | "lead" | "conversation";
649
+ };
650
+ type TagQuery = {
651
+ page?: string | number;
652
+ limit?: string | number;
653
+ search?: string | undefined;
654
+ sort_by?: ("name" | "created_at" | "usage_count") | undefined;
655
+ order?: ("asc" | "desc") | undefined;
656
+ entity_type?: ("contact" | "lead" | "conversation") | undefined;
657
+ };
658
+ type Tag = {
659
+ id: string;
660
+ name: string;
661
+ color: string;
662
+ description?: (string | undefined) | null;
663
+ entity_type: "contact" | "lead" | "conversation";
664
+ created_by: string;
665
+ updated_by?: (string | undefined) | null;
666
+ created_at: string;
667
+ updated_at: string;
668
+ deleted_at?: (string | undefined) | null;
669
+ };
670
+ type TagWithUsage = {
671
+ id: string;
672
+ name: string;
673
+ color: string;
674
+ description?: (string | undefined) | null;
675
+ entity_type: "contact" | "lead" | "conversation";
676
+ created_by: string;
677
+ updated_by?: (string | undefined) | null;
678
+ created_at: string;
679
+ updated_at: string;
680
+ deleted_at?: (string | undefined) | null;
681
+ usage_count: number;
682
+ };
683
+ type TagList = {
684
+ items: {
685
+ id: string;
686
+ name: string;
687
+ color: string;
688
+ description?: (string | undefined) | null;
689
+ entity_type: "contact" | "lead" | "conversation";
690
+ created_by: string;
691
+ updated_by?: (string | undefined) | null;
692
+ created_at: string;
693
+ updated_at: string;
694
+ deleted_at?: (string | undefined) | null;
695
+ usage_count: number;
696
+ }[];
697
+ totalCount: number;
698
+ pageCount: number;
699
+ currentPage: number;
700
+ pageSize: number;
701
+ };
702
+ interface ListEnvelope<T> {
703
+ items: T[];
704
+ totalCount: number;
705
+ pageCount: number;
706
+ currentPage: number;
707
+ pageSize: number;
708
+ }
709
+
710
+ /**
711
+ * Typed CRM REST API client for SaaS backends.
712
+ *
713
+ * Construct with `createCrmApiClient({ crmBaseUrl, accessToken | apiKey })` and
714
+ * call typed resource methods (contacts, leads, conversations, messages, tasks,
715
+ * products, tags) or the generic `request<T>()` escape hatch. Every method
716
+ * returns the UNWRAPPED `data` from the CRM's `{ success, data }` envelope.
717
+ *
718
+ * Auth:
719
+ * - `accessToken` (from `createEmbedSessionWithKey().data.access_token`) is
720
+ * sent as `Authorization: Bearer <token>` and covers the full API surface.
721
+ * The typed resource methods below hit `/api/*` routes that require this
722
+ * **Bearer** token.
723
+ * - `apiKey` (`crm_live_...`) is sent as `X-API-Key` and today only guards
724
+ * `/api/public/*`. An `apiKey` client should use the generic `request()`
725
+ * against those `/public/*` endpoints, NOT the typed resource methods.
726
+ *
727
+ * Error handling — every failure is thrown as a {@link CrmApiError} so callers
728
+ * can `catch (e) { if (e instanceof CrmApiError) ... }`:
729
+ * - non-2xx responses, AND 2xx responses the server mislabels with an
730
+ * `{ success: false }` envelope, throw with the HTTP `status` and a code
731
+ * derived from the body.
732
+ * - network / DNS / connection failures throw with `status: 0` and
733
+ * `code: 'NETWORK_ERROR'`.
734
+ * - a request that exceeds `timeoutMs` (via `AbortController`) throws with
735
+ * `status: 0` and `code: 'TIMEOUT'`.
736
+ *
737
+ * Timeouts — pass `timeoutMs` on the client (default for all requests) and/or
738
+ * per request. If unset there is no timeout.
739
+ *
740
+ * @packageDocumentation
741
+ */
742
+
743
+ type FetchLike = typeof fetch;
744
+ /** Options for {@link createCrmApiClient}. Exactly one of accessToken / apiKey. */
745
+ interface CrmApiClientOptions {
746
+ /** Base URL of the CRM, e.g. `https://crm.example.com` (no trailing `/api`). */
747
+ crmBaseUrl: string;
748
+ /** Bearer token from `createEmbedSessionWithKey` — full API surface. */
749
+ accessToken?: string;
750
+ /** Server-to-server API key (`crm_live_...`) — `/api/public/*` only today. */
751
+ apiKey?: string;
752
+ /** Custom fetch implementation (e.g. for Node < 18 or testing). */
753
+ fetch?: FetchLike;
754
+ /**
755
+ * Default per-request timeout in milliseconds, enforced via `AbortController`.
756
+ * On timeout the request throws a {@link CrmApiError} (`status: 0`,
757
+ * `code: 'TIMEOUT'`). If unset (default), requests have no timeout.
758
+ */
759
+ timeoutMs?: number;
760
+ }
761
+ type QueryPrimitive = string | number | boolean;
762
+ type QueryValue = QueryPrimitive | Array<QueryPrimitive> | undefined | null;
763
+ type QueryParams = Record<string, QueryValue>;
764
+ interface RequestOptions {
765
+ query?: QueryParams;
766
+ body?: unknown;
767
+ /**
768
+ * Per-request timeout in milliseconds (overrides the client `timeoutMs`).
769
+ * On timeout the request throws a {@link CrmApiError} (`status: 0`,
770
+ * `code: 'TIMEOUT'`).
771
+ */
772
+ timeoutMs?: number;
773
+ }
774
+ /**
775
+ * Error thrown for any failed CRM request:
776
+ * - a non-2xx HTTP response,
777
+ * - a 2xx response carrying an `{ success: false }` envelope (server mislabel),
778
+ * - a network/DNS/connection failure (`status: 0`, `code: 'NETWORK_ERROR'`),
779
+ * - a timeout / abort (`status: 0`, `code: 'TIMEOUT'`).
780
+ */
781
+ declare class CrmApiError extends Error {
782
+ /** HTTP status code (0 for network errors / timeouts). */
783
+ readonly status: number;
784
+ /**
785
+ * Machine-readable code. For envelope errors: the object `error.code`, else
786
+ * the string `error`, else `HTTP_<status>`. For transport failures:
787
+ * `NETWORK_ERROR` or `TIMEOUT`.
788
+ */
789
+ readonly code: string;
790
+ /** Parsed response body, or the underlying error for transport failures. */
791
+ readonly body: unknown;
792
+ constructor(status: number, code: string, message: string, body: unknown, options?: {
793
+ cause?: unknown;
794
+ });
795
+ }
796
+ /** The client returned by {@link createCrmApiClient}. */
797
+ interface CrmApiClient {
798
+ contacts: {
799
+ list(query?: ContactQuery): Promise<ContactList>;
800
+ get(id: string): Promise<Contact>;
801
+ create(body: ContactCreate): Promise<Contact>;
802
+ update(id: string, body: ContactUpdate): Promise<Contact>;
803
+ delete(id: string): Promise<void>;
804
+ };
805
+ leads: {
806
+ list(query?: LeadQuery): Promise<ListEnvelope<Lead>>;
807
+ get(id: string): Promise<Lead>;
808
+ create(body: LeadCreate): Promise<Lead>;
809
+ update(id: string, body: LeadUpdate): Promise<Lead>;
810
+ delete(id: string): Promise<void>;
811
+ };
812
+ tasks: {
813
+ list(query?: TaskQuery): Promise<ListEnvelope<Task>>;
814
+ create(leadId: string, body: TaskCreate): Promise<Task>;
815
+ update(leadId: string, taskId: string, body: TaskUpdate): Promise<Task>;
816
+ };
817
+ products: {
818
+ list(query?: ProductQuery): Promise<ListEnvelope<Product>>;
819
+ get(id: string): Promise<Product>;
820
+ create(body: ProductCreate): Promise<Product>;
821
+ update(id: string, body: ProductUpdate): Promise<Product>;
822
+ delete(id: string): Promise<void>;
823
+ };
824
+ conversations: {
825
+ list(query?: ConversationQuery): Promise<ListEnvelope<Conversation>>;
826
+ get(id: string): Promise<Conversation>;
827
+ update(id: string, body: ConversationUpdate): Promise<Conversation>;
828
+ messages: {
829
+ list(conversationId: string, query?: MessageQuery): Promise<ListEnvelope<Message>>;
830
+ send(conversationId: string, body: MessageCreate): Promise<Message>;
831
+ };
832
+ };
833
+ tags: {
834
+ list(query?: TagQuery): Promise<ListEnvelope<TagWithUsage>>;
835
+ create(body: TagCreate): Promise<Tag>;
836
+ };
837
+ /** Generic escape hatch — returns the unwrapped `data` typed as `T`. */
838
+ request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
839
+ }
840
+ declare function createCrmApiClient(opts: CrmApiClientOptions): CrmApiClient;
841
+
842
+ export { type Contact, type ContactCreate, type ContactList, type ContactQuery, type ContactUpdate, type Conversation, type ConversationQuery, type ConversationUpdate, type CrmApiClient, type CrmApiClientOptions, CrmApiError, type Lead, type LeadCreate, type LeadNote, type LeadNoteCreate, type LeadQuery, type LeadUpdate, type ListEnvelope, type Message, type MessageCreate, type MessageQuery, type Product, type ProductCreate, type ProductQuery, type ProductUpdate, type Tag, type TagCreate, type TagList, type TagQuery, type TagWithUsage, type Task, type TaskCreate, type TaskQuery, type TaskUpdate, createCrmApiClient, createCrmApiClient as default };