@first-to-fly/crm-sdk 1.10.0 → 1.11.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/README.md +217 -7
- package/dist/api.cjs +1 -1
- package/dist/api.cjs.map +1 -1
- package/dist/api.d.cts +4 -4
- package/dist/api.d.ts +4 -4
- package/dist/api.js +1 -1
- package/dist/api.js.map +1 -1
- package/dist/{crm-contracts-BiR0JbKC.d.cts → crm-contracts-BeC2pzgj.d.cts} +102 -5
- package/dist/{crm-contracts-BiR0JbKC.d.ts → crm-contracts-BeC2pzgj.d.ts} +102 -5
- package/dist/partner.cjs +1 -1
- package/dist/partner.cjs.map +1 -1
- package/dist/partner.d.cts +186 -11
- package/dist/partner.d.ts +186 -11
- package/dist/partner.js +1 -1
- package/dist/partner.js.map +1 -1
- package/package.json +6 -1
|
@@ -146,6 +146,9 @@ type Contact = {
|
|
|
146
146
|
merged_count?: number | undefined;
|
|
147
147
|
last_message_at?: (string | undefined) | null;
|
|
148
148
|
last_message_preview?: (string | undefined) | null;
|
|
149
|
+
last_message_sender?: (string | undefined) | null;
|
|
150
|
+
is_group?: boolean | undefined;
|
|
151
|
+
group_name?: (string | undefined) | null;
|
|
149
152
|
}[] | undefined;
|
|
150
153
|
email_suppression?: ({
|
|
151
154
|
id: string;
|
|
@@ -214,6 +217,9 @@ type ContactList = {
|
|
|
214
217
|
merged_count?: number | undefined;
|
|
215
218
|
last_message_at?: (string | undefined) | null;
|
|
216
219
|
last_message_preview?: (string | undefined) | null;
|
|
220
|
+
last_message_sender?: (string | undefined) | null;
|
|
221
|
+
is_group?: boolean | undefined;
|
|
222
|
+
group_name?: (string | undefined) | null;
|
|
217
223
|
}[] | undefined;
|
|
218
224
|
email_suppression?: ({
|
|
219
225
|
id: string;
|
|
@@ -303,6 +309,9 @@ type ContactRefUpsertResult = {
|
|
|
303
309
|
merged_count?: number | undefined;
|
|
304
310
|
last_message_at?: (string | undefined) | null;
|
|
305
311
|
last_message_preview?: (string | undefined) | null;
|
|
312
|
+
last_message_sender?: (string | undefined) | null;
|
|
313
|
+
is_group?: boolean | undefined;
|
|
314
|
+
group_name?: (string | undefined) | null;
|
|
306
315
|
}[] | undefined;
|
|
307
316
|
email_suppression?: ({
|
|
308
317
|
id: string;
|
|
@@ -349,11 +358,15 @@ type PartnerWorkspaceUpsertBody = {
|
|
|
349
358
|
ai_monthly_cap_credits?: (number | null) | undefined;
|
|
350
359
|
currency?: string | undefined;
|
|
351
360
|
timezone?: string | undefined;
|
|
361
|
+
partner_channel_enabled?: boolean | undefined;
|
|
362
|
+
webhook_url?: (string | null) | undefined;
|
|
352
363
|
};
|
|
353
364
|
type PartnerWorkspacePatchBody = {
|
|
354
365
|
enabled?: boolean | undefined;
|
|
355
366
|
name?: string | undefined;
|
|
356
367
|
ai_monthly_cap_credits?: (number | null) | undefined;
|
|
368
|
+
partner_channel_enabled?: boolean | undefined;
|
|
369
|
+
webhook_url?: (string | null) | undefined;
|
|
357
370
|
};
|
|
358
371
|
type PartnerWorkspaceCreated = {
|
|
359
372
|
external_ref: string;
|
|
@@ -361,6 +374,8 @@ type PartnerWorkspaceCreated = {
|
|
|
361
374
|
embed_app_id: string | null;
|
|
362
375
|
enabled: boolean;
|
|
363
376
|
ai_monthly_cap_credits: number | null;
|
|
377
|
+
partner_channel_enabled: boolean;
|
|
378
|
+
webhook_url: string | null;
|
|
364
379
|
embed_app_secret: string;
|
|
365
380
|
created: true;
|
|
366
381
|
};
|
|
@@ -370,6 +385,8 @@ type PartnerWorkspaceExisting = {
|
|
|
370
385
|
embed_app_id: string | null;
|
|
371
386
|
enabled: boolean;
|
|
372
387
|
ai_monthly_cap_credits: number | null;
|
|
388
|
+
partner_channel_enabled: boolean;
|
|
389
|
+
webhook_url: string | null;
|
|
373
390
|
created: false;
|
|
374
391
|
};
|
|
375
392
|
type PartnerWorkspaceStatus = {
|
|
@@ -378,6 +395,8 @@ type PartnerWorkspaceStatus = {
|
|
|
378
395
|
embed_app_id: string | null;
|
|
379
396
|
enabled: boolean;
|
|
380
397
|
ai_monthly_cap_credits: number | null;
|
|
398
|
+
partner_channel_enabled: boolean;
|
|
399
|
+
webhook_url: string | null;
|
|
381
400
|
};
|
|
382
401
|
type PartnerWorkspaceDetail = {
|
|
383
402
|
external_ref: string;
|
|
@@ -385,6 +404,8 @@ type PartnerWorkspaceDetail = {
|
|
|
385
404
|
embed_app_id: string | null;
|
|
386
405
|
enabled: boolean;
|
|
387
406
|
ai_monthly_cap_credits: number | null;
|
|
407
|
+
partner_channel_enabled: boolean;
|
|
408
|
+
webhook_url: string | null;
|
|
388
409
|
state: "pending" | "owner_created" | "workspace_created" | "app_installed" | "sub_app_created" | "active";
|
|
389
410
|
ai: {
|
|
390
411
|
period: string;
|
|
@@ -467,6 +488,76 @@ type PartnerContactEraseByIdentityResult = {
|
|
|
467
488
|
contact_ids: string[];
|
|
468
489
|
skipped_linked_elsewhere: number;
|
|
469
490
|
};
|
|
491
|
+
type PartnerInboundMessageBody = {
|
|
492
|
+
contact_ref: string;
|
|
493
|
+
thread_ref: string;
|
|
494
|
+
message_ref: string;
|
|
495
|
+
body: string;
|
|
496
|
+
sent_at: string;
|
|
497
|
+
title?: string | undefined;
|
|
498
|
+
team_ref?: string | undefined;
|
|
499
|
+
direction?: "inbound" | undefined;
|
|
500
|
+
};
|
|
501
|
+
type PartnerInboundMessageResult = {
|
|
502
|
+
conversation_id: string;
|
|
503
|
+
message_id: string;
|
|
504
|
+
created: boolean;
|
|
505
|
+
};
|
|
506
|
+
type PartnerThreadDeleteResult = {
|
|
507
|
+
deleted: boolean;
|
|
508
|
+
};
|
|
509
|
+
type PartnerMessageChangesQuery = {
|
|
510
|
+
cursor?: string | undefined;
|
|
511
|
+
limit?: number;
|
|
512
|
+
};
|
|
513
|
+
type PartnerMessageChange = {
|
|
514
|
+
delivery_id: string;
|
|
515
|
+
external_ref: string;
|
|
516
|
+
thread_ref: string;
|
|
517
|
+
conversation_id: string;
|
|
518
|
+
message_id: string;
|
|
519
|
+
body: string;
|
|
520
|
+
sent_at: string;
|
|
521
|
+
sender: {
|
|
522
|
+
user_ref: string | null;
|
|
523
|
+
name: string;
|
|
524
|
+
};
|
|
525
|
+
delivery_status: "pending" | "delivered" | "failed";
|
|
526
|
+
};
|
|
527
|
+
type PartnerMessageChanges = {
|
|
528
|
+
items: {
|
|
529
|
+
delivery_id: string;
|
|
530
|
+
external_ref: string;
|
|
531
|
+
thread_ref: string;
|
|
532
|
+
conversation_id: string;
|
|
533
|
+
message_id: string;
|
|
534
|
+
body: string;
|
|
535
|
+
sent_at: string;
|
|
536
|
+
sender: {
|
|
537
|
+
user_ref: string | null;
|
|
538
|
+
name: string;
|
|
539
|
+
};
|
|
540
|
+
delivery_status: "pending" | "delivered" | "failed";
|
|
541
|
+
}[];
|
|
542
|
+
next_cursor: string | null;
|
|
543
|
+
};
|
|
544
|
+
type PartnerWebhookPutBody = {
|
|
545
|
+
url: string;
|
|
546
|
+
};
|
|
547
|
+
type PartnerWebhookCreated = {
|
|
548
|
+
url: string;
|
|
549
|
+
secret: string;
|
|
550
|
+
};
|
|
551
|
+
type PartnerWebhookUpdated = {
|
|
552
|
+
url: string;
|
|
553
|
+
};
|
|
554
|
+
type PartnerWebhookGet = {
|
|
555
|
+
url: string;
|
|
556
|
+
has_secret: true;
|
|
557
|
+
};
|
|
558
|
+
type PartnerWebhookRotate = {
|
|
559
|
+
secret: string;
|
|
560
|
+
};
|
|
470
561
|
type LeadCreate = {
|
|
471
562
|
status?: string | undefined;
|
|
472
563
|
assigned_to?: (string | undefined) | null;
|
|
@@ -792,10 +883,11 @@ type ConversationQuery = {
|
|
|
792
883
|
page?: number;
|
|
793
884
|
limit?: number;
|
|
794
885
|
pageSize?: number;
|
|
886
|
+
cursor?: string | undefined;
|
|
795
887
|
search?: string | undefined;
|
|
796
888
|
assignment?: (("me" | "unassigned" | "assigned" | "others") | string) | undefined;
|
|
797
889
|
status?: string | string[];
|
|
798
|
-
channel?: ("whatsapp" | "whatsapp_web" | "messenger" | "instagram" | "email" | "sms" | "webchat" | "website_form" | "voice") | undefined;
|
|
890
|
+
channel?: ("whatsapp" | "whatsapp_web" | "messenger" | "instagram" | "email" | "sms" | "webchat" | "website_form" | "partner_app" | "voice") | undefined;
|
|
799
891
|
channel_id?: string | string[];
|
|
800
892
|
team_id?: string | string[];
|
|
801
893
|
tags?: string | undefined;
|
|
@@ -810,6 +902,9 @@ type ConversationQuery = {
|
|
|
810
902
|
exclude_groups?: boolean | undefined;
|
|
811
903
|
contact_id?: string | undefined;
|
|
812
904
|
lead_stage?: string | undefined;
|
|
905
|
+
/** A contact must belong to every selected audience */
|
|
906
|
+
audience_ids?: string;
|
|
907
|
+
audience_id?: (string | string) | undefined;
|
|
813
908
|
system_audience_id?: string | undefined;
|
|
814
909
|
};
|
|
815
910
|
type ConversationUpdate = {
|
|
@@ -841,7 +936,7 @@ type Conversation = {
|
|
|
841
936
|
metadata: {
|
|
842
937
|
conversation_status: ("active" | "blocked" | "archived" | "reopened" | "on_hold") | null;
|
|
843
938
|
statuses?: ("active" | "blocked" | "archived" | "reopened" | "on_hold")[];
|
|
844
|
-
channel: "whatsapp" | "whatsapp_web" | "sms" | "email" | "messenger" | "instagram" | "website_form" | "voice";
|
|
939
|
+
channel: "whatsapp" | "whatsapp_web" | "sms" | "email" | "messenger" | "instagram" | "website_form" | "partner_app" | "voice";
|
|
845
940
|
unread_count: number;
|
|
846
941
|
total_message_count: number;
|
|
847
942
|
is_within_24h_window: boolean;
|
|
@@ -872,6 +967,8 @@ type Conversation = {
|
|
|
872
967
|
created_at: string;
|
|
873
968
|
updated_at: string;
|
|
874
969
|
};
|
|
970
|
+
title: string | null;
|
|
971
|
+
thread_ref: string | null;
|
|
875
972
|
recipient_suppressed: boolean;
|
|
876
973
|
recipient_suppression?: ({
|
|
877
974
|
id: string;
|
|
@@ -893,7 +990,7 @@ type MessageQuery = {
|
|
|
893
990
|
};
|
|
894
991
|
type MessageCreate = {
|
|
895
992
|
message?: string | undefined;
|
|
896
|
-
channel?: ("sms" | "whatsapp" | "whatsapp_web" | "email" | "messenger" | "instagram" | "telegram" | "webchat" | "website_form") | undefined;
|
|
993
|
+
channel?: ("sms" | "whatsapp" | "whatsapp_web" | "email" | "messenger" | "instagram" | "telegram" | "webchat" | "website_form" | "partner_app") | undefined;
|
|
897
994
|
channel_id?: string | undefined;
|
|
898
995
|
target_conversation_id?: string | undefined;
|
|
899
996
|
reply_to_id?: string | undefined;
|
|
@@ -941,7 +1038,7 @@ type Message = {
|
|
|
941
1038
|
};
|
|
942
1039
|
message: string;
|
|
943
1040
|
direction: "inbound" | "outbound";
|
|
944
|
-
channel: "sms" | "whatsapp" | "email" | "messenger" | "instagram" | "website_form" | "voice";
|
|
1041
|
+
channel: "sms" | "whatsapp" | "email" | "messenger" | "instagram" | "website_form" | "partner_app" | "voice";
|
|
945
1042
|
status: "sent" | "delivered" | "read" | "failed";
|
|
946
1043
|
type: "text" | "image" | "video" | "audio" | "document" | "sticker" | "contacts" | "reaction" | "activity";
|
|
947
1044
|
message_sid?: string | undefined;
|
|
@@ -1091,4 +1188,4 @@ interface ListEnvelope<T> {
|
|
|
1091
1188
|
pageSize: number;
|
|
1092
1189
|
}
|
|
1093
1190
|
|
|
1094
|
-
export type { ContactRefUpsertResult as A, LeadCapture as B, ContactQuery as C, LeadNote as D, LeadNoteCreate as E, PartnerContactEraseByIdentityBody as F, PartnerContactEraseByIdentityResult as G, PartnerContactEraseResult as H,
|
|
1191
|
+
export type { PartnerWorkspaceSecret as $, ContactRefUpsertResult as A, LeadCapture as B, ContactQuery as C, LeadNote as D, LeadNoteCreate as E, PartnerContactEraseByIdentityBody as F, PartnerContactEraseByIdentityResult as G, PartnerContactEraseResult as H, PartnerInboundMessageBody as I, PartnerInboundMessageResult as J, PartnerMessageChange as K, LeadQuery as L, MessageQuery as M, PartnerMessageChanges as N, PartnerMessageChangesQuery as O, ProductQuery as P, PartnerThreadDeleteResult as Q, PartnerWebhookCreated as R, PartnerWebhookGet as S, TaskQuery as T, PartnerWebhookPutBody as U, PartnerWebhookRotate as V, PartnerWebhookUpdated as W, PartnerWorkspaceCreated as X, PartnerWorkspaceDetail as Y, PartnerWorkspaceExisting as Z, PartnerWorkspacePatchBody as _, ContactList as a, PartnerWorkspaceStatus as a0, PartnerWorkspaceUpsertBody as a1, PartnerWorkspaceUsage as a2, PartnerWorkspaceUsageQuery as a3, TagList as a4, Contact as b, ContactCreate as c, ContactUpdate as d, ListEnvelope as e, Lead as f, LeadCreate as g, LeadUpdate as h, Task as i, LegacyTaskUpdate as j, LegacyTask as k, Product as l, ProductCreate as m, ProductUpdate as n, ConversationQuery as o, Conversation as p, ConversationUpdate as q, Message as r, MessageCreate as s, TagQuery as t, TagWithUsage as u, TagCreate as v, Tag as w, ContactChanges as x, ContactChangesQuery as y, ContactRefUpsertBody as z };
|
|
@@ -146,6 +146,9 @@ type Contact = {
|
|
|
146
146
|
merged_count?: number | undefined;
|
|
147
147
|
last_message_at?: (string | undefined) | null;
|
|
148
148
|
last_message_preview?: (string | undefined) | null;
|
|
149
|
+
last_message_sender?: (string | undefined) | null;
|
|
150
|
+
is_group?: boolean | undefined;
|
|
151
|
+
group_name?: (string | undefined) | null;
|
|
149
152
|
}[] | undefined;
|
|
150
153
|
email_suppression?: ({
|
|
151
154
|
id: string;
|
|
@@ -214,6 +217,9 @@ type ContactList = {
|
|
|
214
217
|
merged_count?: number | undefined;
|
|
215
218
|
last_message_at?: (string | undefined) | null;
|
|
216
219
|
last_message_preview?: (string | undefined) | null;
|
|
220
|
+
last_message_sender?: (string | undefined) | null;
|
|
221
|
+
is_group?: boolean | undefined;
|
|
222
|
+
group_name?: (string | undefined) | null;
|
|
217
223
|
}[] | undefined;
|
|
218
224
|
email_suppression?: ({
|
|
219
225
|
id: string;
|
|
@@ -303,6 +309,9 @@ type ContactRefUpsertResult = {
|
|
|
303
309
|
merged_count?: number | undefined;
|
|
304
310
|
last_message_at?: (string | undefined) | null;
|
|
305
311
|
last_message_preview?: (string | undefined) | null;
|
|
312
|
+
last_message_sender?: (string | undefined) | null;
|
|
313
|
+
is_group?: boolean | undefined;
|
|
314
|
+
group_name?: (string | undefined) | null;
|
|
306
315
|
}[] | undefined;
|
|
307
316
|
email_suppression?: ({
|
|
308
317
|
id: string;
|
|
@@ -349,11 +358,15 @@ type PartnerWorkspaceUpsertBody = {
|
|
|
349
358
|
ai_monthly_cap_credits?: (number | null) | undefined;
|
|
350
359
|
currency?: string | undefined;
|
|
351
360
|
timezone?: string | undefined;
|
|
361
|
+
partner_channel_enabled?: boolean | undefined;
|
|
362
|
+
webhook_url?: (string | null) | undefined;
|
|
352
363
|
};
|
|
353
364
|
type PartnerWorkspacePatchBody = {
|
|
354
365
|
enabled?: boolean | undefined;
|
|
355
366
|
name?: string | undefined;
|
|
356
367
|
ai_monthly_cap_credits?: (number | null) | undefined;
|
|
368
|
+
partner_channel_enabled?: boolean | undefined;
|
|
369
|
+
webhook_url?: (string | null) | undefined;
|
|
357
370
|
};
|
|
358
371
|
type PartnerWorkspaceCreated = {
|
|
359
372
|
external_ref: string;
|
|
@@ -361,6 +374,8 @@ type PartnerWorkspaceCreated = {
|
|
|
361
374
|
embed_app_id: string | null;
|
|
362
375
|
enabled: boolean;
|
|
363
376
|
ai_monthly_cap_credits: number | null;
|
|
377
|
+
partner_channel_enabled: boolean;
|
|
378
|
+
webhook_url: string | null;
|
|
364
379
|
embed_app_secret: string;
|
|
365
380
|
created: true;
|
|
366
381
|
};
|
|
@@ -370,6 +385,8 @@ type PartnerWorkspaceExisting = {
|
|
|
370
385
|
embed_app_id: string | null;
|
|
371
386
|
enabled: boolean;
|
|
372
387
|
ai_monthly_cap_credits: number | null;
|
|
388
|
+
partner_channel_enabled: boolean;
|
|
389
|
+
webhook_url: string | null;
|
|
373
390
|
created: false;
|
|
374
391
|
};
|
|
375
392
|
type PartnerWorkspaceStatus = {
|
|
@@ -378,6 +395,8 @@ type PartnerWorkspaceStatus = {
|
|
|
378
395
|
embed_app_id: string | null;
|
|
379
396
|
enabled: boolean;
|
|
380
397
|
ai_monthly_cap_credits: number | null;
|
|
398
|
+
partner_channel_enabled: boolean;
|
|
399
|
+
webhook_url: string | null;
|
|
381
400
|
};
|
|
382
401
|
type PartnerWorkspaceDetail = {
|
|
383
402
|
external_ref: string;
|
|
@@ -385,6 +404,8 @@ type PartnerWorkspaceDetail = {
|
|
|
385
404
|
embed_app_id: string | null;
|
|
386
405
|
enabled: boolean;
|
|
387
406
|
ai_monthly_cap_credits: number | null;
|
|
407
|
+
partner_channel_enabled: boolean;
|
|
408
|
+
webhook_url: string | null;
|
|
388
409
|
state: "pending" | "owner_created" | "workspace_created" | "app_installed" | "sub_app_created" | "active";
|
|
389
410
|
ai: {
|
|
390
411
|
period: string;
|
|
@@ -467,6 +488,76 @@ type PartnerContactEraseByIdentityResult = {
|
|
|
467
488
|
contact_ids: string[];
|
|
468
489
|
skipped_linked_elsewhere: number;
|
|
469
490
|
};
|
|
491
|
+
type PartnerInboundMessageBody = {
|
|
492
|
+
contact_ref: string;
|
|
493
|
+
thread_ref: string;
|
|
494
|
+
message_ref: string;
|
|
495
|
+
body: string;
|
|
496
|
+
sent_at: string;
|
|
497
|
+
title?: string | undefined;
|
|
498
|
+
team_ref?: string | undefined;
|
|
499
|
+
direction?: "inbound" | undefined;
|
|
500
|
+
};
|
|
501
|
+
type PartnerInboundMessageResult = {
|
|
502
|
+
conversation_id: string;
|
|
503
|
+
message_id: string;
|
|
504
|
+
created: boolean;
|
|
505
|
+
};
|
|
506
|
+
type PartnerThreadDeleteResult = {
|
|
507
|
+
deleted: boolean;
|
|
508
|
+
};
|
|
509
|
+
type PartnerMessageChangesQuery = {
|
|
510
|
+
cursor?: string | undefined;
|
|
511
|
+
limit?: number;
|
|
512
|
+
};
|
|
513
|
+
type PartnerMessageChange = {
|
|
514
|
+
delivery_id: string;
|
|
515
|
+
external_ref: string;
|
|
516
|
+
thread_ref: string;
|
|
517
|
+
conversation_id: string;
|
|
518
|
+
message_id: string;
|
|
519
|
+
body: string;
|
|
520
|
+
sent_at: string;
|
|
521
|
+
sender: {
|
|
522
|
+
user_ref: string | null;
|
|
523
|
+
name: string;
|
|
524
|
+
};
|
|
525
|
+
delivery_status: "pending" | "delivered" | "failed";
|
|
526
|
+
};
|
|
527
|
+
type PartnerMessageChanges = {
|
|
528
|
+
items: {
|
|
529
|
+
delivery_id: string;
|
|
530
|
+
external_ref: string;
|
|
531
|
+
thread_ref: string;
|
|
532
|
+
conversation_id: string;
|
|
533
|
+
message_id: string;
|
|
534
|
+
body: string;
|
|
535
|
+
sent_at: string;
|
|
536
|
+
sender: {
|
|
537
|
+
user_ref: string | null;
|
|
538
|
+
name: string;
|
|
539
|
+
};
|
|
540
|
+
delivery_status: "pending" | "delivered" | "failed";
|
|
541
|
+
}[];
|
|
542
|
+
next_cursor: string | null;
|
|
543
|
+
};
|
|
544
|
+
type PartnerWebhookPutBody = {
|
|
545
|
+
url: string;
|
|
546
|
+
};
|
|
547
|
+
type PartnerWebhookCreated = {
|
|
548
|
+
url: string;
|
|
549
|
+
secret: string;
|
|
550
|
+
};
|
|
551
|
+
type PartnerWebhookUpdated = {
|
|
552
|
+
url: string;
|
|
553
|
+
};
|
|
554
|
+
type PartnerWebhookGet = {
|
|
555
|
+
url: string;
|
|
556
|
+
has_secret: true;
|
|
557
|
+
};
|
|
558
|
+
type PartnerWebhookRotate = {
|
|
559
|
+
secret: string;
|
|
560
|
+
};
|
|
470
561
|
type LeadCreate = {
|
|
471
562
|
status?: string | undefined;
|
|
472
563
|
assigned_to?: (string | undefined) | null;
|
|
@@ -792,10 +883,11 @@ type ConversationQuery = {
|
|
|
792
883
|
page?: number;
|
|
793
884
|
limit?: number;
|
|
794
885
|
pageSize?: number;
|
|
886
|
+
cursor?: string | undefined;
|
|
795
887
|
search?: string | undefined;
|
|
796
888
|
assignment?: (("me" | "unassigned" | "assigned" | "others") | string) | undefined;
|
|
797
889
|
status?: string | string[];
|
|
798
|
-
channel?: ("whatsapp" | "whatsapp_web" | "messenger" | "instagram" | "email" | "sms" | "webchat" | "website_form" | "voice") | undefined;
|
|
890
|
+
channel?: ("whatsapp" | "whatsapp_web" | "messenger" | "instagram" | "email" | "sms" | "webchat" | "website_form" | "partner_app" | "voice") | undefined;
|
|
799
891
|
channel_id?: string | string[];
|
|
800
892
|
team_id?: string | string[];
|
|
801
893
|
tags?: string | undefined;
|
|
@@ -810,6 +902,9 @@ type ConversationQuery = {
|
|
|
810
902
|
exclude_groups?: boolean | undefined;
|
|
811
903
|
contact_id?: string | undefined;
|
|
812
904
|
lead_stage?: string | undefined;
|
|
905
|
+
/** A contact must belong to every selected audience */
|
|
906
|
+
audience_ids?: string;
|
|
907
|
+
audience_id?: (string | string) | undefined;
|
|
813
908
|
system_audience_id?: string | undefined;
|
|
814
909
|
};
|
|
815
910
|
type ConversationUpdate = {
|
|
@@ -841,7 +936,7 @@ type Conversation = {
|
|
|
841
936
|
metadata: {
|
|
842
937
|
conversation_status: ("active" | "blocked" | "archived" | "reopened" | "on_hold") | null;
|
|
843
938
|
statuses?: ("active" | "blocked" | "archived" | "reopened" | "on_hold")[];
|
|
844
|
-
channel: "whatsapp" | "whatsapp_web" | "sms" | "email" | "messenger" | "instagram" | "website_form" | "voice";
|
|
939
|
+
channel: "whatsapp" | "whatsapp_web" | "sms" | "email" | "messenger" | "instagram" | "website_form" | "partner_app" | "voice";
|
|
845
940
|
unread_count: number;
|
|
846
941
|
total_message_count: number;
|
|
847
942
|
is_within_24h_window: boolean;
|
|
@@ -872,6 +967,8 @@ type Conversation = {
|
|
|
872
967
|
created_at: string;
|
|
873
968
|
updated_at: string;
|
|
874
969
|
};
|
|
970
|
+
title: string | null;
|
|
971
|
+
thread_ref: string | null;
|
|
875
972
|
recipient_suppressed: boolean;
|
|
876
973
|
recipient_suppression?: ({
|
|
877
974
|
id: string;
|
|
@@ -893,7 +990,7 @@ type MessageQuery = {
|
|
|
893
990
|
};
|
|
894
991
|
type MessageCreate = {
|
|
895
992
|
message?: string | undefined;
|
|
896
|
-
channel?: ("sms" | "whatsapp" | "whatsapp_web" | "email" | "messenger" | "instagram" | "telegram" | "webchat" | "website_form") | undefined;
|
|
993
|
+
channel?: ("sms" | "whatsapp" | "whatsapp_web" | "email" | "messenger" | "instagram" | "telegram" | "webchat" | "website_form" | "partner_app") | undefined;
|
|
897
994
|
channel_id?: string | undefined;
|
|
898
995
|
target_conversation_id?: string | undefined;
|
|
899
996
|
reply_to_id?: string | undefined;
|
|
@@ -941,7 +1038,7 @@ type Message = {
|
|
|
941
1038
|
};
|
|
942
1039
|
message: string;
|
|
943
1040
|
direction: "inbound" | "outbound";
|
|
944
|
-
channel: "sms" | "whatsapp" | "email" | "messenger" | "instagram" | "website_form" | "voice";
|
|
1041
|
+
channel: "sms" | "whatsapp" | "email" | "messenger" | "instagram" | "website_form" | "partner_app" | "voice";
|
|
945
1042
|
status: "sent" | "delivered" | "read" | "failed";
|
|
946
1043
|
type: "text" | "image" | "video" | "audio" | "document" | "sticker" | "contacts" | "reaction" | "activity";
|
|
947
1044
|
message_sid?: string | undefined;
|
|
@@ -1091,4 +1188,4 @@ interface ListEnvelope<T> {
|
|
|
1091
1188
|
pageSize: number;
|
|
1092
1189
|
}
|
|
1093
1190
|
|
|
1094
|
-
export type { ContactRefUpsertResult as A, LeadCapture as B, ContactQuery as C, LeadNote as D, LeadNoteCreate as E, PartnerContactEraseByIdentityBody as F, PartnerContactEraseByIdentityResult as G, PartnerContactEraseResult as H,
|
|
1191
|
+
export type { PartnerWorkspaceSecret as $, ContactRefUpsertResult as A, LeadCapture as B, ContactQuery as C, LeadNote as D, LeadNoteCreate as E, PartnerContactEraseByIdentityBody as F, PartnerContactEraseByIdentityResult as G, PartnerContactEraseResult as H, PartnerInboundMessageBody as I, PartnerInboundMessageResult as J, PartnerMessageChange as K, LeadQuery as L, MessageQuery as M, PartnerMessageChanges as N, PartnerMessageChangesQuery as O, ProductQuery as P, PartnerThreadDeleteResult as Q, PartnerWebhookCreated as R, PartnerWebhookGet as S, TaskQuery as T, PartnerWebhookPutBody as U, PartnerWebhookRotate as V, PartnerWebhookUpdated as W, PartnerWorkspaceCreated as X, PartnerWorkspaceDetail as Y, PartnerWorkspaceExisting as Z, PartnerWorkspacePatchBody as _, ContactList as a, PartnerWorkspaceStatus as a0, PartnerWorkspaceUpsertBody as a1, PartnerWorkspaceUsage as a2, PartnerWorkspaceUsageQuery as a3, TagList as a4, Contact as b, ContactCreate as c, ContactUpdate as d, ListEnvelope as e, Lead as f, LeadCreate as g, LeadUpdate as h, Task as i, LegacyTaskUpdate as j, LegacyTask as k, Product as l, ProductCreate as m, ProductUpdate as n, ConversationQuery as o, Conversation as p, ConversationUpdate as q, Message as r, MessageCreate as s, TagQuery as t, TagWithUsage as u, TagCreate as v, Tag as w, ContactChanges as x, ContactChangesQuery as y, ContactRefUpsertBody as z };
|
package/dist/partner.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var b=Object.defineProperty;var D=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var N=(e,a)=>{for(var d in a)b(e,d,{get:a[d],enumerable:!0})},F=(e,a,d,g)=>{if(a&&typeof a=="object"||typeof a=="function")for(let y of M(a))!O.call(e,y)&&y!==d&&b(e,y,{get:()=>a[y],enumerable:!(g=D(a,y))||g.enumerable});return e};var L=e=>F(b({},"__esModule",{value:!0}),e);var Z={};N(Z,{AI_MONTHLY_CAP_MAX_CREDITS:()=>j,CONTACT_CHANGES_MAX_LIMIT:()=>$,CONTACT_REF_PATTERN:()=>I,CrmPartnerError:()=>f,EXTERNAL_REF_PATTERN:()=>S,createCrmPartnerClient:()=>K});module.exports=L(Z);function R(e){return e.replace(/\/+$/,"").replace(/\/api$/,"")}function x(e,a){let d=e??globalThis.fetch;if(typeof d!="function")throw new Error(`${a}: no fetch implementation available. Pass \`fetch\` explicitly.`);return d}async function A(e,a,d,g){let y=new AbortController,c=!1,u=setTimeout(()=>{c=!0,y.abort()},a);try{let m={Accept:"application/json",...g.headers},C=g.body!==void 0;C&&(m["Content-Type"]="application/json");let s=await e(d,{method:g.method,headers:m,body:C?JSON.stringify(g.body):void 0,signal:y.signal}),n=await s.json().catch(()=>null);return c?{ok:!1,kind:"timeout"}:{ok:!0,status:s.status,json:n}}catch{return{ok:!1,kind:c?"timeout":"network"}}finally{clearTimeout(u)}}var q=/^[A-Za-z0-9_.:-]{1,60}$/;function E(e,a,d){let g=`HTTP_${a}`,y=c=>typeof c!="string"||!q.test(c)||d.some(u=>u&&c.includes(u))?null:c;if(e&&typeof e=="object"){let c=e,u=c.error;return y(c.code)??y(u)??(u&&typeof u=="object"?y(u.code):null)??g}return g}var k=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);var f=class e extends Error{constructor(a,d){super(a===0?`CRM partner API unreachable (${d})`:`CRM partner API ${a} ${d}`),this.name="CrmPartnerError",this.status=a,this.code=d,Object.setPrototypeOf(this,e.prototype)}},S=/^[A-Za-z0-9_-]{1,64}$/,I=/^[A-Za-z0-9._:-]{1,200}$/,$=200,j=1e8,w=e=>({externalRef:e.external_ref,workspaceId:e.workspace_id,embedAppId:e.embed_app_id,enabled:e.enabled,aiMonthlyCapCredits:typeof e.ai_monthly_cap_credits=="number"?e.ai_monthly_cap_credits:null}),G=/^\d{4}-\d{2}-\d{2}$/;function T(e){let a=e instanceof Date&&!Number.isNaN(e.getTime())?e.toISOString().slice(0,10):e;if(typeof a!="string"||!G.test(a)||Number.isNaN(Date.parse(`${a}T00:00:00Z`))||new Date(`${a}T00:00:00Z`).toISOString().slice(0,10)!==a)throw new f(400,"invalid_date");return a}function B(e){if(e==null)return e;if(typeof e!="number"||!Number.isInteger(e)||e<0||e>j)throw new f(400,"invalid_cap");return e}var U=e=>e===null||typeof e=="string";function W(e){return k(e)&&typeof e.external_ref=="string"&&U(e.workspace_id)&&U(e.embed_app_id)&&typeof e.enabled=="boolean"}function K(e){if(!e.crmBaseUrl)throw new Error("createCrmPartnerClient: `crmBaseUrl` is required.");if(!e.partnerKey)throw new Error("createCrmPartnerClient: `partnerKey` is required.");let a=x(e.fetch,"createCrmPartnerClient"),d=e.timeoutMs??15e3,g=`${R(e.crmBaseUrl)}/api/partner/v1/workspaces`,y=[e.partnerKey];function c(s){if(typeof s!="string"||!S.test(s))throw new f(400,"invalid_external_ref");return s}async function u(s,n,i){let t=await A(a,d,`${g}/${n}`,{method:s,headers:{Authorization:`Bearer ${e.partnerKey}`},body:i});if(!t.ok)throw new f(0,t.kind);if(t.status<200||t.status>=300)throw new f(t.status,E(t.json,t.status,y));return{status:t.status,json:t.json}}let m=s=>new f(s,"bad_response");function C(s){if(typeof s!="string"||!I.test(s))throw new f(400,"invalid_contact_ref");return s}return{async upsertWorkspace(s,n){let i=c(s),{aiMonthlyCapCredits:t,...r}=n,o=B(t),p=o===void 0?r:{...r,ai_monthly_cap_credits:o},{status:h,json:P}=await u("PUT",i,p);if(!W(P))throw m(h);let l=P;if(l.created===!0){let _=l.embed_app_secret;if(typeof _!="string"||!_)throw m(h);return{...w(l),created:!0,embedAppSecret:_}}if(l.created===!1)return{...w(l),created:!1};throw m(h)},async getWorkspace(s){let n=c(s);try{let{status:i,json:t}=await u("GET",n);if(!W(t)||typeof t.state!="string")throw m(i);let r=t.ai;return{...w(t),state:t.state,ai:k(r)&&typeof r.period=="string"&&typeof r.used_credits=="number"?{period:r.period,usedCredits:r.used_credits}:null}}catch(i){if(i instanceof f&&i.status===404)return null;throw i}},async updateWorkspace(s,n){let i=c(s),t={};n.enabled!==void 0&&(t.enabled=n.enabled),n.name!==void 0&&(t.name=n.name);let r=B(n.aiMonthlyCapCredits);r!==void 0&&(t.ai_monthly_cap_credits=r);let{status:o,json:p}=await u("PATCH",i,t);if(!W(p))throw m(o);return w(p)},async getWorkspaceUsage(s,n){let i=c(s),t=new URLSearchParams({from:T(n.from),to:T(n.to)});try{let{status:r,json:o}=await u("GET",`${i}/usage?${t.toString()}`);if(!k(o)||!k(o.totals)||!k(o.cap)||!Array.isArray(o.by_operation))throw m(r);return o}catch(r){if(r instanceof f&&r.status===404)return null;throw r}},async rotateWorkspaceSecret(s){let n=c(s),{status:i,json:t}=await u("POST",`${n}/rotate-secret`),r=t;if(!k(t)||typeof r?.embed_app_id!="string"||typeof r.embed_app_secret!="string"||!r.embed_app_secret)throw m(i);return{embedAppId:r.embed_app_id,embedAppSecret:r.embed_app_secret}},async upsertContact(s,n,i){let t=c(s),r=C(n),{status:o,json:p}=await u("PUT",`${t}/contacts/${encodeURIComponent(r)}`,i);if(!k(p)||!k(p.contact)||typeof p.created!="boolean"||typeof p.consent_applied!="boolean")throw m(o);return p},async eraseContact(s,n){let i=c(s),t=C(n);try{let{status:r,json:o}=await u("DELETE",`${i}/contacts/${encodeURIComponent(t)}`);if(!k(o)||o.erased!==!0||typeof o.contact_id!="string")throw m(r);return o}catch(r){if(r instanceof f&&r.status===404)return null;throw r}},async eraseContactsByIdentity(s,n){let i=c(s),t=typeof n?.phone=="string"?n.phone.trim():void 0,r=typeof n?.email=="string"?n.email.trim():void 0,o=t!==void 0&&/\d/.test(t),p=r!==void 0&&r.includes("@");if(n?.phone!==void 0&&!o||n?.email!==void 0&&!p||!o&&!p)throw new f(400,"invalid_identity");n.ref!==void 0&&C(n.ref);let h={};o&&(h.phone=t),p&&(h.email=r),n.ref!==void 0&&(h.ref=n.ref);try{let{status:P,json:l}=await u("POST",`${i}/contacts/erase-by-identity`,h);if(!k(l)||typeof l.erased!="number"||!Array.isArray(l.contact_ids)||typeof l.skipped_linked_elsewhere!="number")throw m(P);return l}catch(P){if(P instanceof f&&P.status===404)return null;throw P}},async listContactChanges(s,n={}){let i=c(s),{since:t,cursor:r,limit:o}=n;if(o!==void 0&&(!Number.isInteger(o)||o<1||o>$))throw new f(400,"invalid_limit");let p=new URLSearchParams;t!==void 0&&p.set("since",t),r!==void 0&&p.set("cursor",r),o!==void 0&&p.set("limit",String(o));let h=p.toString(),{status:P,json:l}=await u("GET",`${i}/contacts/changes${h?`?${h}`:""}`);if(!k(l)||!Array.isArray(l.items)||!(l.next_cursor===null||typeof l.next_cursor=="string"))throw m(P);return l}}}0&&(module.exports={AI_MONTHLY_CAP_MAX_CREDITS,CONTACT_CHANGES_MAX_LIMIT,CONTACT_REF_PATTERN,CrmPartnerError,EXTERNAL_REF_PATTERN,createCrmPartnerClient});
|
|
1
|
+
"use strict";var I=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var X=(e,n)=>{for(var c in n)I(e,c,{get:n[c],enumerable:!0})},Z=(e,n,c,f)=>{if(n&&typeof n=="object"||typeof n=="function")for(let p of z(n))!K.call(e,p)&&p!==c&&I(e,p,{get:()=>n[p],enumerable:!(f=V(n,p))||f.enumerable});return e};var J=e=>Z(I({},"__esModule",{value:!0}),e);var ce={};X(ce,{AI_MONTHLY_CAP_MAX_CREDITS:()=>H,CONTACT_CHANGES_MAX_LIMIT:()=>G,CONTACT_REF_PATTERN:()=>T,CrmPartnerError:()=>g,EXTERNAL_REF_PATTERN:()=>F,PARTNER_MESSAGE_CHANGES_MAX_LIMIT:()=>q,PartnerWebhookVerificationError:()=>_,createCrmPartnerClient:()=>ie,verifyPartnerWebhook:()=>j});module.exports=J(ce);function B(e){return e.replace(/\/+$/,"").replace(/\/api$/,"")}function M(e,n){let c=e??globalThis.fetch;if(typeof c!="function")throw new Error(`${n}: no fetch implementation available. Pass \`fetch\` explicitly.`);return c}async function $(e,n,c,f){let p=new AbortController,h=!1,u=setTimeout(()=>{h=!0,p.abort()},n);try{let m={Accept:"application/json",...f.headers},l=f.body!==void 0;l&&(m["Content-Type"]="application/json");let R=await e(c,{method:f.method,headers:m,body:l?JSON.stringify(f.body):void 0,signal:p.signal}),s=await R.json().catch(()=>null);return h?{ok:!1,kind:"timeout"}:{ok:!0,status:R.status,json:s}}catch{return{ok:!1,kind:h?"timeout":"network"}}finally{clearTimeout(u)}}var Q=/^[A-Za-z0-9_.:-]{1,60}$/;function v(e,n,c){let f=`HTTP_${n}`,p=h=>typeof h!="string"||!Q.test(h)||c.some(u=>u&&h.includes(u))?null:h;if(e&&typeof e=="object"){let h=e,u=h.error;return p(h.code)??p(u)??(u&&typeof u=="object"?p(u.code):null)??f}return f}var y=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);var W=require("crypto"),_=class e extends Error{constructor(n){super(`Partner webhook verification failed (${n})`),this.name="PartnerWebhookVerificationError",this.reason=n,Object.setPrototypeOf(this,e.prototype)}},Y=300,ee=/^[0-9a-fA-F]{64}$/,te=/^[0-9]{1,15}$/;function N(e,n){if(typeof e.get=="function")return e.get(n)||void 0;let c=e;for(let f of Object.keys(c)){if(f.toLowerCase()!==n)continue;let p=c[f],h=Array.isArray(p)?p[0]:p;if(typeof h=="string"&&h!=="")return h}}var C=e=>typeof e=="string",D=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function re(e){let n;try{n=JSON.parse(e)}catch{throw new _("bad_payload")}if(!D(n)||n.event!=="partner_message.sent")throw new _("bad_payload");let{sender:c}=n;if(!C(n.delivery_id)||!C(n.external_ref)||!C(n.thread_ref)||!C(n.conversation_id)||!C(n.message_id)||!C(n.body)||!C(n.sent_at)||!D(c)||!C(c.name)||!(c.user_ref===null||C(c.user_ref)))throw new _("bad_payload");return{event:"partner_message.sent",deliveryId:n.delivery_id,externalRef:n.external_ref,threadRef:n.thread_ref,conversationId:n.conversation_id,messageId:n.message_id,body:n.body,sentAt:n.sent_at,sender:{userRef:c.user_ref,name:c.name}}}function j(e){if(typeof e.secret!="string"||e.secret==="")throw new TypeError("verifyPartnerWebhook: secret must be a non-empty string");if(typeof e.rawBody!="string")throw new TypeError("verifyPartnerWebhook: rawBody must be a string (the body exactly as received)");if(e.toleranceSeconds!==void 0&&!(Number.isFinite(e.toleranceSeconds)&&e.toleranceSeconds>=0))throw new TypeError("verifyPartnerWebhook: toleranceSeconds must be a finite number of at least 0");let n=N(e.headers,"x-crm-timestamp"),c=N(e.headers,"x-crm-signature");if(n===void 0||c===void 0)throw new _("missing_headers");let f=e.toleranceSeconds??Y,p=(e.now??Date.now)()/1e3;if(!te.test(n)||!Number.isFinite(p)||Math.abs(p-Number(n))>f)throw new _("stale_timestamp");if(!ee.test(c))throw new _("bad_signature");let h=(0,W.createHmac)("sha256",e.secret).update(`${n}.${e.rawBody}`).digest();if(!(0,W.timingSafeEqual)(h,Buffer.from(c,"hex")))throw new _("bad_signature");return re(e.rawBody)}var g=class e extends Error{constructor(n,c){super(n===0?`CRM partner API unreachable (${c})`:`CRM partner API ${n} ${c}`),this.name="CrmPartnerError",this.status=n,this.code=c,Object.setPrototypeOf(this,e.prototype)}},F=/^[A-Za-z0-9_-]{1,64}$/,T=/^[A-Za-z0-9._:-]{1,200}$/,G=200,q=500,H=1e8,E=e=>({externalRef:e.external_ref,workspaceId:e.workspace_id,embedAppId:e.embed_app_id,enabled:e.enabled,aiMonthlyCapCredits:typeof e.ai_monthly_cap_credits=="number"?e.ai_monthly_cap_credits:null,partnerChannelEnabled:e.partner_channel_enabled===!0,webhookUrl:typeof e.webhook_url=="string"?e.webhook_url:null});function se(e){if(e instanceof Date){if(Number.isNaN(e.getTime()))throw new g(400,"invalid_date");return e.toISOString()}if(typeof e!="string")throw new g(400,"invalid_date");return e}function ae(e){return y(e)&&typeof e.delivery_id=="string"&&typeof e.external_ref=="string"&&typeof e.thread_ref=="string"&&typeof e.conversation_id=="string"&&typeof e.message_id=="string"&&typeof e.body=="string"&&typeof e.sent_at=="string"&&y(e.sender)&&U(e.sender.user_ref)&&typeof e.sender.name=="string"&&(e.delivery_status==="pending"||e.delivery_status==="delivered"||e.delivery_status==="failed")}var oe=/^\d{4}-\d{2}-\d{2}$/;function O(e){let n=e instanceof Date&&!Number.isNaN(e.getTime())?e.toISOString().slice(0,10):e;if(typeof n!="string"||!oe.test(n)||Number.isNaN(Date.parse(`${n}T00:00:00Z`))||new Date(`${n}T00:00:00Z`).toISOString().slice(0,10)!==n)throw new g(400,"invalid_date");return n}function L(e){if(e==null)return e;if(typeof e!="number"||!Number.isInteger(e)||e<0||e>H)throw new g(400,"invalid_cap");return e}var U=e=>e===null||typeof e=="string";function A(e){return y(e)&&typeof e.external_ref=="string"&&U(e.workspace_id)&&U(e.embed_app_id)&&typeof e.enabled=="boolean"}function ie(e){if(!e.crmBaseUrl)throw new Error("createCrmPartnerClient: `crmBaseUrl` is required.");if(!e.partnerKey)throw new Error("createCrmPartnerClient: `partnerKey` is required.");let n=M(e.fetch,"createCrmPartnerClient"),c=e.timeoutMs??15e3,f=`${B(e.crmBaseUrl)}/api/partner/v1`,p=`${f}/workspaces`,h=[e.partnerKey];function u(s){if(typeof s!="string"||!F.test(s))throw new g(400,"invalid_external_ref");return s}async function m(s,t,i,a=p){let r=await $(n,c,`${a}/${t}`,{method:s,headers:{Authorization:`Bearer ${e.partnerKey}`},body:i});if(!r.ok)throw new g(0,r.kind);if(r.status<200||r.status>=300)throw new g(r.status,v(r.json,r.status,h));return{status:r.status,json:r.json}}let l=s=>new g(s,"bad_response");function R(s){if(typeof s!="string"||!T.test(s))throw new g(400,"invalid_contact_ref");return s}return{async upsertWorkspace(s,t){let i=u(s),{aiMonthlyCapCredits:a,partnerChannelEnabled:r,webhookUrl:o,...d}=t,w=L(a),b={...d};w!==void 0&&(b.ai_monthly_cap_credits=w),r!==void 0&&(b.partner_channel_enabled=r),o!==void 0&&(b.webhook_url=o);let{status:P,json:x}=await m("PUT",i,b);if(!A(x))throw l(P);let k=x;if(k.created===!0){let S=k.embed_app_secret;if(typeof S!="string"||!S)throw l(P);return{...E(k),created:!0,embedAppSecret:S}}if(k.created===!1)return{...E(k),created:!1};throw l(P)},async getWorkspace(s){let t=u(s);try{let{status:i,json:a}=await m("GET",t);if(!A(a)||typeof a.state!="string")throw l(i);let r=a.ai;return{...E(a),state:a.state,ai:y(r)&&typeof r.period=="string"&&typeof r.used_credits=="number"?{period:r.period,usedCredits:r.used_credits}:null}}catch(i){if(i instanceof g&&i.status===404)return null;throw i}},async updateWorkspace(s,t){let i=u(s),a={};t.enabled!==void 0&&(a.enabled=t.enabled),t.name!==void 0&&(a.name=t.name);let r=L(t.aiMonthlyCapCredits);r!==void 0&&(a.ai_monthly_cap_credits=r),t.partnerChannelEnabled!==void 0&&(a.partner_channel_enabled=t.partnerChannelEnabled),t.webhookUrl!==void 0&&(a.webhook_url=t.webhookUrl);let{status:o,json:d}=await m("PATCH",i,a);if(!A(d))throw l(o);return E(d)},async getWorkspaceUsage(s,t){let i=u(s),a=new URLSearchParams({from:O(t.from),to:O(t.to)});try{let{status:r,json:o}=await m("GET",`${i}/usage?${a.toString()}`);if(!y(o)||!y(o.totals)||!y(o.cap)||!Array.isArray(o.by_operation))throw l(r);return o}catch(r){if(r instanceof g&&r.status===404)return null;throw r}},async rotateWorkspaceSecret(s){let t=u(s),{status:i,json:a}=await m("POST",`${t}/rotate-secret`),r=a;if(!y(a)||typeof r?.embed_app_id!="string"||typeof r.embed_app_secret!="string"||!r.embed_app_secret)throw l(i);return{embedAppId:r.embed_app_id,embedAppSecret:r.embed_app_secret}},async upsertContact(s,t,i){let a=u(s),r=R(t),{status:o,json:d}=await m("PUT",`${a}/contacts/${encodeURIComponent(r)}`,i);if(!y(d)||!y(d.contact)||typeof d.created!="boolean"||typeof d.consent_applied!="boolean")throw l(o);return d},async eraseContact(s,t){let i=u(s),a=R(t);try{let{status:r,json:o}=await m("DELETE",`${i}/contacts/${encodeURIComponent(a)}`);if(!y(o)||o.erased!==!0||typeof o.contact_id!="string")throw l(r);return o}catch(r){if(r instanceof g&&r.status===404)return null;throw r}},async eraseContactsByIdentity(s,t){let i=u(s),a=typeof t?.phone=="string"?t.phone.trim():void 0,r=typeof t?.email=="string"?t.email.trim():void 0,o=a!==void 0&&/\d/.test(a),d=r!==void 0&&r.includes("@");if(t?.phone!==void 0&&!o||t?.email!==void 0&&!d||!o&&!d)throw new g(400,"invalid_identity");t.ref!==void 0&&R(t.ref);let w={};o&&(w.phone=a),d&&(w.email=r),t.ref!==void 0&&(w.ref=t.ref);try{let{status:b,json:P}=await m("POST",`${i}/contacts/erase-by-identity`,w);if(!y(P)||typeof P.erased!="number"||!Array.isArray(P.contact_ids)||typeof P.skipped_linked_elsewhere!="number")throw l(b);return P}catch(b){if(b instanceof g&&b.status===404)return null;throw b}},async listContactChanges(s,t={}){let i=u(s),{since:a,cursor:r,limit:o}=t;if(o!==void 0&&(!Number.isInteger(o)||o<1||o>G))throw new g(400,"invalid_limit");let d=new URLSearchParams;a!==void 0&&d.set("since",a),r!==void 0&&d.set("cursor",r),o!==void 0&&d.set("limit",String(o));let w=d.toString(),{status:b,json:P}=await m("GET",`${i}/contacts/changes${w?`?${w}`:""}`);if(!y(P)||!Array.isArray(P.items)||!(P.next_cursor===null||typeof P.next_cursor=="string"))throw l(b);return P},async sendPartnerMessage(s,t){let i=u(s),a={contact_ref:R(t.contactRef),thread_ref:t.threadRef,message_ref:t.messageRef,body:t.body,sent_at:se(t.sentAt)};t.title!==void 0&&(a.title=t.title),t.teamRef!==void 0&&(a.team_ref=t.teamRef);let{status:r,json:o}=await m("POST",`${i}/messages`,a);if(!y(o)||typeof o.conversation_id!="string"||typeof o.message_id!="string"||typeof o.created!="boolean")throw l(r);let d=o;return{conversationId:d.conversation_id,messageId:d.message_id,created:d.created}},async deletePartnerConversation(s,t){let i=u(s);if(typeof t!="string"||!T.test(t)||t==="."||t==="..")throw new g(400,"invalid_thread_ref");let{status:a,json:r}=await m("DELETE",`${i}/conversations/${encodeURIComponent(t)}`);if(!y(r)||typeof r.deleted!="boolean")throw l(a);return{deleted:r.deleted}},async listPartnerMessageChanges(s,t={}){let i=u(s),{cursor:a,limit:r}=t;if(r!==void 0&&(!Number.isInteger(r)||r<1||r>q))throw new g(400,"invalid_limit");let o=new URLSearchParams;a!==void 0&&o.set("cursor",a),r!==void 0&&o.set("limit",String(r));let d=o.toString(),{status:w,json:b}=await m("GET",`${i}/messages/changes${d?`?${d}`:""}`);if(!y(b)||!Array.isArray(b.items)||!(b.next_cursor===null||typeof b.next_cursor=="string"))throw l(w);let P=b;return{items:P.items.map(k=>{if(!ae(k))throw l(w);return{deliveryId:k.delivery_id,externalRef:k.external_ref,threadRef:k.thread_ref,conversationId:k.conversation_id,messageId:k.message_id,body:k.body,sentAt:k.sent_at,sender:{userRef:k.sender.user_ref,name:k.sender.name},deliveryStatus:k.delivery_status}}),nextCursor:P.next_cursor}},async setWebhook(s){let t={url:s.url},{status:i,json:a}=await m("PUT","webhook",t,f);if(!y(a)||typeof a.url!="string")throw l(i);if(i===201){let r=a.secret;if(typeof r!="string"||!r)throw l(i);return{url:a.url,secret:r}}return{url:a.url}},async getWebhook(){try{let{status:s,json:t}=await m("GET","webhook",void 0,f);if(!y(t)||typeof t.url!="string"||t.has_secret!==!0)throw l(s);return{url:t.url,hasSecret:!0}}catch(s){if(s instanceof g&&s.status===404)return null;throw s}},async rotateWebhookSecret(){let{status:s,json:t}=await m("POST","webhook/rotate-secret",void 0,f),i=y(t)?t.secret:void 0;if(typeof i!="string"||!i)throw l(s);return{secret:i}},async deleteWebhook(){await m("DELETE","webhook",void 0,f)}}}0&&(module.exports={AI_MONTHLY_CAP_MAX_CREDITS,CONTACT_CHANGES_MAX_LIMIT,CONTACT_REF_PATTERN,CrmPartnerError,EXTERNAL_REF_PATTERN,PARTNER_MESSAGE_CHANGES_MAX_LIMIT,PartnerWebhookVerificationError,createCrmPartnerClient,verifyPartnerWebhook});
|
|
2
2
|
//# sourceMappingURL=partner.cjs.map
|