@periskope/types 0.6.141 → 0.6.142

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/types.ts CHANGED
@@ -1,709 +1,584 @@
1
- import type { default as _Stripe } from 'stripe';
2
- import { Merge, OverrideProperties } from 'type-fest';
3
- import { Tables, TablesUpdate } from './supabase.types';
4
-
5
- /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
6
-
7
- /* ------------------------------ PERISKOPE TYPES ------------------------------ */
8
-
9
- export enum AllPlans {
10
- FREE_TRIAL = 'free-trial',
11
- // MONTHLY_STARTER = 'monthly-starter',
12
- // YEARLY_STARTER = 'yearly-starter',
13
- // MONTHLY_PRO = 'monthly-pro',
14
- // YEARLY_PRO = 'yearly-pro',
15
- ENTERPRISE = 'enterprise',
16
- MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
17
- YEARLY_STARTER_SINGLE = 'yearly-starter-single',
18
- MONTHLY_PRO_SINGLE = 'monthly-pro-single',
19
- YEARLY_PRO_SINGLE = 'yearly-pro-single',
20
- }
21
-
22
- export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
23
-
24
- export type Enterprise = `${string}-enterprise`;
25
-
26
- export type OrgPlanEnterprise = {
27
- subscription_id: string;
28
- plan_id: Enterprise;
29
- interval: number;
30
- frequency: Frequency;
31
- user_limit: number;
32
- phone_limit: number;
33
- current_period_start: number;
34
- current_period_end: number | null;
35
- };
36
-
37
- export type OrgPlanNonEnterprise = {
38
- subscription_id: string;
39
- plan_id: AllPlans;
40
- interval: number;
41
- frequency: Frequency;
42
- user_limit: number;
43
- phone_limit: number;
44
- current_period_end: number;
45
- current_period_start: number;
46
- };
47
-
48
- export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
49
- ? OrgPlanEnterprise
50
- : T extends AllPlans
51
- ? OrgPlanNonEnterprise
52
- : never;
53
-
54
- export type MicrosurveyData = {
55
- key: string;
56
- text: string;
57
- checked: boolean;
58
- }[];
59
-
60
- export type OrgPreferences = {
61
- disable_ai_flagging?: boolean;
62
- disable_allow_exports?: boolean;
63
- sync_phone_contacts?: boolean;
64
- mask_phone_numbers?: boolean;
65
- show_sender_names?: boolean;
66
- };
67
-
68
- type OrgPreferenceKey = keyof OrgPreferences;
69
-
70
- export type OrgPreferencesValue = {
71
- [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
72
- }[OrgPreferenceKey];
73
-
74
- export type OrgMetadata = {
75
- phone_number: string;
76
- ticket_prefix: string;
77
- referralSource?: string;
78
- surveyData?: MicrosurveyData;
79
- preferences?: OrgPreferences;
80
- hubspot_pipelines?: {
81
- id: string;
82
- label: string;
83
- default_stage: { id: string; label: string };
84
- }[];
85
- partition?: boolean;
86
- };
87
-
88
- type AccessScopes = {
89
- integrations: boolean;
90
- exports: boolean;
91
- };
92
-
93
- export type OrgType = OverrideProperties<
94
- Merge<
95
- Tables<'tbl_org'>,
96
- {
97
- user: Tables<'tbl_org_members'>;
98
- members: Tables<'tbl_org_members'>[];
99
- phones: Tables<'tbl_org_phones'>[];
100
- labels: Tables<'tbl_org_labels'>[];
101
- quick_replies: Tables<'tbl_quick_replies'>[];
102
- custom_properties: Tables<'tbl_custom_properties'>[];
103
- subscription_status: 'active' | 'inactive' | 'unpaid';
104
- is_enterprise: boolean;
105
- is_free_trial: boolean;
106
- is_hubspot_connected: boolean;
107
- is_freshdesk_connected: boolean;
108
- is_zohodesk_connected: boolean;
109
- access_scopes: AccessScopes;
110
- }
111
- >,
112
- {
113
- org_plan: OrgPlan<AllPlans | Enterprise>;
114
- stripe_customer_details: _Stripe.Customer | null;
115
- stripe_subscription_details: Array<_Stripe.Subscription> | null;
116
- stripe_customer_id: _Stripe.Customer['id'] | null;
117
- org_metadata: OrgMetadata;
118
- }
119
- >;
120
-
121
- export type ChatMemberType = Merge<
122
- Tables<'tbl_chat_participants'>,
123
- Tables<'tbl_contacts'>
124
- >;
125
-
126
- export type ChatType = Merge<
127
- Tables<'view_chats'>,
128
- {
129
- chat_id: string;
130
- latest_message: MessageType | null;
131
- latest_message_timestamp: number | null;
132
- members: { [key: string]: ChatMemberType } | null;
133
- chat_type: 'user' | 'group' | 'business' | 'unknown';
134
- chat_access: { [key: string]: boolean };
135
- label_ids: { [key: string]: boolean };
136
- chat_org_phones?: string[];
137
- message_unread_count: number | null;
138
- hubspot_metadata: {
139
- id: string;
140
- type: string;
141
- hubId: string;
142
- object_data: HubspotObjectDataType;
143
- } | null;
144
- info_admins_only: boolean;
145
- messages_admins_only: boolean;
146
- unread_count?: { [key: string]: number };
147
- active_phone: string | null;
148
- flag_count_map?: { [key: string]: number };
149
- pin?: boolean;
150
- }
151
- >;
152
-
153
- /* -------------------------------------------------------------------------- */
154
- /* MESSAGE */
155
- /* -------------------------------------------------------------------------- */
156
-
157
- export type MediaType = {
158
- path: string;
159
- mimetype?: string;
160
- filename?: string;
161
- dimensions?: { width: number; height: number; ar: number };
162
- size?: number;
163
- thumbnail?: string;
164
- };
165
-
166
- export type MessageType = Merge<
167
- OverrideProperties<
168
- Tables<'tbl_chat_messages'>,
169
- {
170
- message_id: string;
171
- org_id: string;
172
- org_phone: string;
173
- chat_id: string;
174
- message_type: (typeof SUPPORTED_TYPES)[number];
175
- media: MediaType | null;
176
- flag_metadata: MessageFlagType | null;
177
- poll_info?: PollSendType | null;
178
- poll_results?: PollResultType | null;
179
- delivery_info?: DeliveryInfoType | null;
180
- }
181
- >,
182
- {
183
- reactions?: ReactionType[];
184
- message_payload?: SingleMessagePayload;
185
- show_unread?: boolean;
186
- highlight?: number;
187
- }
188
- >;
189
-
190
- export type MessageFlagType = {
191
- status: boolean;
192
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
193
- response_id?: string;
194
- response_timestamp?: string;
195
- response_email?: string;
196
- };
197
-
198
- /* -------------------------------------------------------------------------- */
199
-
200
- export type TicketType = OverrideProperties<
201
- Tables<'tbl_chat_tickets'>,
202
- {
203
- label_ids: { [key: string]: boolean };
204
- hubspot_metadata: {
205
- id?: string;
206
- type?: string;
207
- hubId?: string;
208
- pipeline: {
209
- id: string;
210
- label: string;
211
- };
212
- object_data?: HubspotObjectDataType;
213
- } | null;
214
- freshdesk_metadata: Record<string, string>;
215
- close_ticket_metadata?:
216
- | {
217
- closed_by: string;
218
- closed_at: string;
219
- closed_message?: string | null;
220
- send_reply_message_id?: string | null;
221
- }
222
- | any;
223
- }
224
- >;
225
-
226
- export type ContactType = Merge<
227
- Tables<'tbl_contacts'>,
228
- {
229
- chats: ChatType[] | null;
230
- chat_ids?: string[];
231
- }
232
- >;
233
- export type ReactionType = Tables<'tbl_chat_reactions'>;
234
-
235
- export type NotificationType = Tables<'tbl_chat_notifications'>;
236
-
237
- export type ChatAccessType = Merge<
238
- TablesUpdate<'tbl_org_members'>,
239
- {
240
- has_access?: boolean;
241
- email: string | null;
242
- }
243
- >;
244
-
245
- /* -------------------------------- CONSTANTS ------------------------------- */
246
-
247
- export const labelColors = [
248
- '#9333EA',
249
- '#0D9488',
250
- '#DB2777',
251
- '#2563EB',
252
- '#F97316',
253
- ];
254
-
255
- export const enumChatColors = [
256
- '#B4876E',
257
- '#A5B337',
258
- '#06CF9C',
259
- '#25D366',
260
- '#02A698',
261
- '#7D9EF1',
262
- '#007BFC',
263
- '#5E47DE',
264
- '#7F66FF',
265
- '#9333EA',
266
- '#FA6533',
267
- '#C4532D',
268
- '#DC2626',
269
- '#FF2E74',
270
- '#DB2777',
271
- ] as const;
272
-
273
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
274
-
275
- export const SUPPORTED_TYPES = [
276
- 'chat',
277
- 'sticker',
278
- 'image',
279
- 'video',
280
- 'document',
281
- 'vcard',
282
- 'multi_vcard',
283
- 'audio',
284
- 'ptt',
285
- 'poll_creation',
286
- 'location',
287
- 'ciphertext',
288
- ] as const;
289
-
290
- export type SendMessageContent = {
291
- message_type?: (typeof SUPPORTED_TYPES)[number];
292
- body?: string;
293
- media?: MediaType;
294
- contact_ids?: string[];
295
- location?: {
296
- latitude: string;
297
- longitude: string;
298
- options?: { name?: string; address?: string; url?: string };
299
- };
300
- poll?: PollSendType;
301
- quoted_message_id?: string;
302
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
303
- broadcast_id?: string;
304
- performed_by?: string;
305
- };
306
-
307
- export type QuickReplyContent = Omit<
308
- SendMessageContent,
309
- 'broadcast_id' | 'variables'
310
- >;
311
-
312
- export type BroadcastVariableType = {
313
- chat_id: string;
314
- values: { [key: string]: string };
315
- };
316
-
317
- export type BroadcastMessagePayload = SendMessageContent & {
318
- chat_ids: string[];
319
- broadcast_id?: string;
320
- variables?: BroadcastVariableType[];
321
- };
322
-
323
- export type SingleMessagePayload = SendMessageContent & {
324
- chat_id: string;
325
- job_id?: string;
326
- };
327
-
328
- export type MessageAttachmentFileTypes =
329
- | 'image'
330
- | 'audio'
331
- | 'document'
332
- | 'video';
333
-
334
- export type AttachmentFileType = {
335
- result: string;
336
- file: File | null;
337
- type: MessageAttachmentFileTypes;
338
- localFileURL?: string;
339
- };
340
-
341
- export type AttachmentLinkType = {
342
- link: {
343
- url: string;
344
- type: MessageAttachmentFileTypes;
345
- name: string;
346
- mimetype?: string;
347
- };
348
- };
349
-
350
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
351
-
352
- /* -------------------------------- BROADCAST ------------------------------- */
353
-
354
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
355
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
356
- } & {
357
- chats: ChatType[];
358
- };
359
-
360
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
361
-
362
- export type ChatLogType = {
363
- log: Tables<'view_chat_logs'>;
364
- operations: Tables<'tbl_chat_logs'>[];
365
- };
366
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
367
-
368
- export type ChatParticipantOperationPayload = {
369
- participant_ids: string[];
370
- chat_ids: string[];
371
- performed_by: string;
372
- };
373
-
374
- export type ChatOperationReturn = {
375
- [participant_id: string]: {
376
- is_success: boolean;
377
- message?: string;
378
- code?: number;
379
- isInviteV4Sent?: boolean;
380
- };
381
- };
382
-
383
- /* ----------------------- BILLING - STRIPE ----------------------- */
384
-
385
- export type StripeSubscription = _Stripe.Subscription;
386
- export type StripeCustomer = _Stripe.Customer;
387
- export type StripeCoupon = _Stripe.Coupon;
388
- export type StripePrice = _Stripe.Price;
389
- export type Stripe = _Stripe;
390
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
391
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
392
-
393
- /* -------------------------------- REALTIME -------------------------------- */
394
-
395
- export type PhoneStateType = {
396
- loading: boolean;
397
- state: string;
398
- sync: number;
399
- percent: number | null;
400
- message?: string;
401
- error?: string;
402
- };
403
-
404
- /* ------------------------------- INTEGRATIONS ----------------------------- */
405
-
406
- export type ChatInfoType = Merge<
407
- ChatType,
408
- {
409
- members: {
410
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
411
- } | null;
412
- chat_labels: string | null;
413
- custom_properties: { [key: string]: string } | null;
414
- }
415
- >;
416
-
417
- export type TicketInfoType = {
418
- chat: ChatInfoType;
419
- message: {
420
- body: string;
421
- chat_id: string;
422
- org_phone: string;
423
- timestamp: string;
424
- media_path: string;
425
- message_id: string;
426
- sender_name: string;
427
- performed_by: string;
428
- sender_phone: string;
429
- };
430
- ticket: {
431
- org_id: string;
432
- status: string;
433
- subject: string;
434
- assignee: string;
435
- due_date: string;
436
- priority: 0 | 1 | 2 | 3 | 4;
437
- raised_by: string;
438
- ticket_id: string;
439
- created_at: string;
440
- assigned_by: string;
441
- ticket_labels: string;
442
- quoted_message_id: string;
443
- ticket_custom_properties: { [key: string]: string } | null;
444
- };
445
- };
446
-
447
- export type IntegrationLogObjectType =
448
- | 'chat'
449
- | 'message'
450
- | 'reaction'
451
- | 'ticket';
452
-
453
- export enum IntegrationLogType {
454
- NEW_CHAT = 'chat.created',
455
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
456
- NEW_MESSAGE = 'message.created',
457
- MESSAGE_UPDATED = 'message.updated',
458
- MESSAGE_DELETED = 'message.deleted',
459
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
460
- REACTION_CREATED = 'reaction.created',
461
- REACTION_UPDATED = 'reaction.updated',
462
- NEW_TICKET = 'ticket.created',
463
- TICKET_UPDATED = 'ticket.updated',
464
- TICKET_DELETED = 'ticket.deleted',
465
- }
466
-
467
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
468
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
469
- ? TicketInfoType
470
- : T extends IntegrationLogType.NEW_CHAT
471
- ? Tables<'tbl_chats'>
472
- : T extends
473
- | IntegrationLogType.NEW_MESSAGE
474
- | IntegrationLogType.MESSAGE_UPDATED
475
- | IntegrationLogType.MESSAGE_DELETED
476
- | IntegrationLogType.MESSAGE_ACK_UPDATED
477
- ? Tables<'tbl_chat_messages'>
478
- : T extends
479
- | IntegrationLogType.REACTION_CREATED
480
- | IntegrationLogType.REACTION_UPDATED
481
- ? Tables<'tbl_chat_reactions'>
482
- : {
483
- [key: string]: unknown;
484
- };
485
-
486
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
487
- OverrideProperties<
488
- Tables<'tbl_integration_logs'>,
489
- {
490
- integration_name: T;
491
- metadata: {
492
- event: IntegrationLogMetadataType<T> & {
493
- event_type: string;
494
- org_id: string;
495
- previous_attributes: {
496
- [key: string]: unknown;
497
- };
498
- };
499
- hook_id: string;
500
- name: string;
501
- };
502
- }
503
- >;
504
-
505
- export type APIAuthDetails = {
506
- org_details: Tables<'view_org'> | null;
507
- phone_details: Tables<'tbl_org_phones'> | null;
508
- token_details: Tables<'tbl_integration_tokens'> | null;
509
- };
510
-
511
- export type WebhookDataType = OverrideProperties<
512
- Tables<'tbl_integration_hooks'>,
513
- {
514
- integration_name: string[];
515
- }
516
- >;
517
-
518
- export type HubspotObjectDataType = {
519
- createdAt: string;
520
- archived: boolean;
521
- id: string;
522
- type: 'contacts' | 'tickets' | 'companies';
523
- properties: Record<
524
- string,
525
- {
526
- groupLabel: string;
527
- groupName: string;
528
- propertyKeyName: string;
529
- propertyKey: string;
530
- propertyInternalValue: string;
531
- propertyValue: string;
532
- propertyType: string;
533
- propertyFieldType: string;
534
- }[]
535
- >;
536
- };
537
-
538
- /* ---------------------------- USER PREFERENCES ---------------------------- */
539
-
540
- export type UserPreferences = {
541
- theme: 'light' | 'dark';
542
- language: 'en' | 'es';
543
- left_sidebar_open: boolean;
544
- right_sidepanel_open: boolean;
545
- sync_wa_unread_count: boolean;
546
- pinned_chats: string[];
547
- };
548
-
549
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
550
-
551
- export type PollSendType = {
552
- pollName: string;
553
- pollOptions: string[];
554
- options?: {
555
- allowMultipleAnswers?: boolean;
556
- messageSecret?: number[] | null;
557
- pollId?: string;
558
- };
559
- };
560
-
561
- export type PollResultType = {
562
- [name: string]: Record<string, string>;
563
- };
564
-
565
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
566
-
567
- export type CreateGroupOptions = {
568
- messagesAdminsOnly?: boolean;
569
- infoAdminsOnly?: boolean;
570
- memberAddMode?: boolean;
571
- image?: string;
572
- name?: string;
573
- description?: string;
574
- };
575
-
576
- /* ------------------------------ DELIVERY INFO ----------------------------- */
577
-
578
- export type DeliveryInfoType = {
579
- delivered: Record<string, number | undefined>;
580
- read: Record<string, number | undefined>;
581
- pending: string[];
582
- read_count: number;
583
- delivered_count: number;
584
- };
585
-
586
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
587
-
588
- export type ChatRuleInfoType = Merge<
589
- Pick<
590
- Tables<'view_chats'>,
591
- | 'assigned_to'
592
- | 'chat_id'
593
- | 'chat_name'
594
- | 'chat_type'
595
- | 'created_at'
596
- | 'group_description'
597
- | 'info_admins_only'
598
- | 'is_archived'
599
- | 'is_exited'
600
- | 'is_muted'
601
- | 'org_id'
602
- | 'org_phone'
603
- | 'chat_org_phones'
604
- | 'messages_admins_only'
605
- | 'custom_properties'
606
- >,
607
- {
608
- has_flagged_messages: boolean;
609
- labels: string[];
610
- members: SenderRuleInfoType[];
611
- custom_properties: { [key: string]: string } | null;
612
- }
613
- >;
614
-
615
- export type SenderRuleInfoType = OverrideProperties<
616
- Merge<
617
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
618
- {
619
- is_internal: boolean;
620
- labels: string[] | null;
621
- }
622
- >,
623
- {
624
- id: { [key: string]: string } | null;
625
- business_profile: { [key: string]: string } | null;
626
- label_ids: { [key: string]: boolean } | null;
627
- }
628
- >;
629
-
630
- export type MessageRuleInfoType = {
631
- chat: ChatRuleInfoType;
632
- sender: SenderRuleInfoType;
633
- message: OverrideProperties<
634
- Tables<'tbl_chat_messages'>,
635
- {
636
- delivery_info: DeliveryInfoType | null;
637
- flag_metadata: MessageFlagType | null;
638
- id: {
639
- id: string;
640
- remote: string;
641
- from_me: boolean;
642
- serialized: string;
643
- } | null;
644
- media: MediaType | null;
645
- }
646
- >;
647
- };
648
-
649
- export type ReactionRuleInfoType = {
650
- chat: ChatRuleInfoType;
651
- sender: SenderRuleInfoType;
652
- message: MessageRuleInfoType['message'];
653
- reaction: OverrideProperties<
654
- Tables<'tbl_chat_reactions'>,
655
- {
656
- id: {
657
- id: string;
658
- remote: string;
659
- from_me: boolean;
660
- serialized: string;
661
- };
662
- msg_id: {
663
- id: string;
664
- remote: string;
665
- from_me: boolean;
666
- serialized: string;
667
- };
668
- }
669
- >;
670
- };
671
-
672
- export type TicketRuleInfoType = {
673
- chat: ChatRuleInfoType;
674
- sender: SenderRuleInfoType;
675
- ticket: Merge<
676
- Pick<
677
- Tables<'tbl_chat_tickets'>,
678
- | 'org_id'
679
- | 'status'
680
- | 'chat_id'
681
- | 'subject'
682
- | 'assignee'
683
- | 'due_date'
684
- | 'priority'
685
- | 'closed_at'
686
- | 'label_ids'
687
- | 'raised_by'
688
- | 'ticket_id'
689
- | 'created_at'
690
- | 'is_deleted'
691
- | 'assigned_by'
692
- | 'response_time'
693
- | 'last_updated_at'
694
- | 'close_ticket_metadata'
695
- | 'quoted_message_id'
696
- >,
697
- {
698
- labels: string[] | null;
699
- custom_properties: { [key: string]: string } | null;
700
- close_ticket_metadata: {
701
- closed_at: string;
702
- closed_by: string;
703
- closed_message: string;
704
- send_reply_message_id: string;
705
- };
706
- }
707
- >;
708
- message: MessageRuleInfoType['message'];
709
- };
1
+ import type { default as _Stripe } from 'stripe';
2
+ import { Merge, OverrideProperties } from 'type-fest';
3
+ import { Tables, TablesUpdate } from './supabase.types';
4
+
5
+ /* ----------------------------- TYPE SHORTHANDS ---------------------------- */
6
+
7
+ /* ------------------------------ PERISKOPE TYPES ------------------------------ */
8
+
9
+ export enum AllPlans {
10
+ FREE_TRIAL = 'free-trial',
11
+ // MONTHLY_STARTER = 'monthly-starter',
12
+ // YEARLY_STARTER = 'yearly-starter',
13
+ // MONTHLY_PRO = 'monthly-pro',
14
+ // YEARLY_PRO = 'yearly-pro',
15
+ ENTERPRISE = 'enterprise',
16
+ MONTHLY_STARTER_SINGLE = 'monthly-starter-single',
17
+ YEARLY_STARTER_SINGLE = 'yearly-starter-single',
18
+ MONTHLY_PRO_SINGLE = 'monthly-pro-single',
19
+ YEARLY_PRO_SINGLE = 'yearly-pro-single',
20
+ }
21
+
22
+ export type Frequency = 'yearly' | 'monthly' | 'weekly' | 'custom';
23
+
24
+ export type Enterprise = `${string}-enterprise`;
25
+
26
+ export type OrgPlanEnterprise = {
27
+ subscription_id: string;
28
+ plan_id: Enterprise;
29
+ interval: number;
30
+ frequency: Frequency;
31
+ user_limit: number;
32
+ phone_limit: number;
33
+ current_period_start: number;
34
+ current_period_end: number | null;
35
+ };
36
+
37
+ export type OrgPlanNonEnterprise = {
38
+ subscription_id: string;
39
+ plan_id: AllPlans;
40
+ interval: number;
41
+ frequency: Frequency;
42
+ user_limit: number;
43
+ phone_limit: number;
44
+ current_period_end: number;
45
+ current_period_start: number;
46
+ };
47
+
48
+ export type OrgPlan<T extends AllPlans | Enterprise> = T extends Enterprise
49
+ ? OrgPlanEnterprise
50
+ : T extends AllPlans
51
+ ? OrgPlanNonEnterprise
52
+ : never;
53
+
54
+ export type MicrosurveyData = {
55
+ key: string;
56
+ text: string;
57
+ checked: boolean;
58
+ }[];
59
+
60
+ export type OrgPreferences = {
61
+ disable_ai_flagging?: boolean;
62
+ disable_allow_exports?: boolean;
63
+ sync_phone_contacts?: boolean;
64
+ mask_phone_numbers?: boolean;
65
+ show_sender_names?: boolean;
66
+ };
67
+
68
+ type OrgPreferenceKey = keyof OrgPreferences;
69
+
70
+ export type OrgPreferencesValue = {
71
+ [K in OrgPreferenceKey]: { key: K; value: OrgPreferences[K] };
72
+ }[OrgPreferenceKey];
73
+
74
+ export type OrgMetadata = {
75
+ phone_number: string;
76
+ ticket_prefix: string;
77
+ referralSource?: string;
78
+ surveyData?: MicrosurveyData;
79
+ preferences?: OrgPreferences;
80
+ hubspot_pipelines?: {
81
+ id: string;
82
+ label: string;
83
+ default_stage: { id: string; label: string };
84
+ }[];
85
+ partition?: boolean;
86
+ };
87
+
88
+ type AccessScopes = {
89
+ integrations: boolean;
90
+ exports: boolean;
91
+ };
92
+
93
+ export type OrgType = OverrideProperties<
94
+ Merge<
95
+ Tables<'tbl_org'>,
96
+ {
97
+ user: Tables<'tbl_org_members'>;
98
+ members: Tables<'tbl_org_members'>[];
99
+ phones: Tables<'tbl_org_phones'>[];
100
+ labels: Tables<'tbl_org_labels'>[];
101
+ quick_replies: Tables<'tbl_quick_replies'>[];
102
+ custom_properties: Tables<'tbl_custom_properties'>[];
103
+ subscription_status: 'active' | 'inactive' | 'unpaid';
104
+ is_enterprise: boolean;
105
+ is_free_trial: boolean;
106
+ is_hubspot_connected: boolean;
107
+ is_freshdesk_connected: boolean;
108
+ is_zohodesk_connected: boolean;
109
+ access_scopes: AccessScopes;
110
+ }
111
+ >,
112
+ {
113
+ org_plan: OrgPlan<AllPlans | Enterprise>;
114
+ stripe_customer_details: _Stripe.Customer | null;
115
+ stripe_subscription_details: Array<_Stripe.Subscription> | null;
116
+ stripe_customer_id: _Stripe.Customer['id'] | null;
117
+ org_metadata: OrgMetadata;
118
+ }
119
+ >;
120
+
121
+ export type ChatMemberType = Merge<
122
+ Tables<'tbl_chat_participants'>,
123
+ Tables<'tbl_contacts'>
124
+ >;
125
+
126
+ export type ChatType = Merge<
127
+ Tables<'view_chats'>,
128
+ {
129
+ chat_id: string;
130
+ latest_message: MessageType | null;
131
+ latest_message_timestamp: number | null;
132
+ members: { [key: string]: ChatMemberType } | null;
133
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
134
+ chat_access: { [key: string]: boolean };
135
+ label_ids: { [key: string]: boolean };
136
+ chat_org_phones?: string[];
137
+ message_unread_count: number | null;
138
+ hubspot_metadata: {
139
+ id: string;
140
+ type: string;
141
+ hubId: string;
142
+ object_data: HubspotObjectDataType;
143
+ } | null;
144
+ info_admins_only: boolean;
145
+ messages_admins_only: boolean;
146
+ unread_count?: { [key: string]: number };
147
+ active_phone: string | null;
148
+ flag_count_map?: { [key: string]: number };
149
+ pin?: boolean;
150
+ }
151
+ >;
152
+
153
+ /* -------------------------------------------------------------------------- */
154
+ /* MESSAGE */
155
+ /* -------------------------------------------------------------------------- */
156
+
157
+ export type MediaType = {
158
+ path: string;
159
+ mimetype?: string;
160
+ filename?: string;
161
+ dimensions?: { width: number; height: number; ar: number };
162
+ size?: number;
163
+ thumbnail?: string;
164
+ };
165
+
166
+ export type MessageType = Merge<
167
+ OverrideProperties<
168
+ Tables<'tbl_chat_messages'>,
169
+ {
170
+ message_id: string;
171
+ org_id: string;
172
+ org_phone: string;
173
+ chat_id: string;
174
+ message_type: (typeof SUPPORTED_TYPES)[number];
175
+ media: MediaType | null;
176
+ flag_metadata: MessageFlagType | null;
177
+ poll_info?: PollSendType | null;
178
+ poll_results?: PollResultType | null;
179
+ delivery_info?: DeliveryInfoType | null;
180
+ }
181
+ >,
182
+ {
183
+ reactions?: ReactionType[];
184
+ message_payload?: SingleMessagePayload;
185
+ show_unread?: boolean;
186
+ highlight?: number;
187
+ }
188
+ >;
189
+
190
+ export type MessageFlagType = {
191
+ status: boolean;
192
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
193
+ response_id?: string;
194
+ response_timestamp?: string;
195
+ response_email?: string;
196
+ };
197
+
198
+ /* -------------------------------------------------------------------------- */
199
+
200
+ export type TicketType = OverrideProperties<
201
+ Tables<'tbl_chat_tickets'>,
202
+ {
203
+ label_ids: { [key: string]: boolean };
204
+ hubspot_metadata: {
205
+ id?: string;
206
+ type?: string;
207
+ hubId?: string;
208
+ pipeline: {
209
+ id: string;
210
+ label: string;
211
+ };
212
+ object_data?: HubspotObjectDataType;
213
+ } | null;
214
+ freshdesk_metadata: Record<string, string>;
215
+ close_ticket_metadata?:
216
+ | {
217
+ closed_by: string;
218
+ closed_at: string;
219
+ closed_message?: string | null;
220
+ send_reply_message_id?: string | null;
221
+ }
222
+ | any;
223
+ }
224
+ >;
225
+
226
+ export type ContactType = Merge<
227
+ Tables<'tbl_contacts'>,
228
+ {
229
+ chats: ChatType[] | null;
230
+ chat_ids?: string[];
231
+ }
232
+ >;
233
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
234
+
235
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
236
+
237
+ export type ChatAccessType = Merge<
238
+ TablesUpdate<'tbl_org_members'>,
239
+ {
240
+ has_access?: boolean;
241
+ email: string | null;
242
+ }
243
+ >;
244
+
245
+ /* -------------------------------- CONSTANTS ------------------------------- */
246
+
247
+ export const labelColors = [
248
+ '#9333EA',
249
+ '#0D9488',
250
+ '#DB2777',
251
+ '#2563EB',
252
+ '#F97316',
253
+ ];
254
+
255
+ export const enumChatColors = [
256
+ '#B4876E',
257
+ '#A5B337',
258
+ '#06CF9C',
259
+ '#25D366',
260
+ '#02A698',
261
+ '#7D9EF1',
262
+ '#007BFC',
263
+ '#5E47DE',
264
+ '#7F66FF',
265
+ '#9333EA',
266
+ '#FA6533',
267
+ '#C4532D',
268
+ '#DC2626',
269
+ '#FF2E74',
270
+ '#DB2777',
271
+ ] as const;
272
+
273
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
274
+
275
+ export const SUPPORTED_TYPES = [
276
+ 'chat',
277
+ 'sticker',
278
+ 'image',
279
+ 'video',
280
+ 'document',
281
+ 'vcard',
282
+ 'multi_vcard',
283
+ 'audio',
284
+ 'ptt',
285
+ 'poll_creation',
286
+ 'location',
287
+ 'ciphertext',
288
+ ] as const;
289
+
290
+ export type SendMessageContent = {
291
+ message_type?: (typeof SUPPORTED_TYPES)[number];
292
+ body?: string;
293
+ media?: MediaType;
294
+ contact_ids?: string[];
295
+ location?: {
296
+ latitude: string;
297
+ longitude: string;
298
+ options?: { name?: string; address?: string; url?: string };
299
+ };
300
+ poll?: PollSendType;
301
+ quoted_message_id?: string;
302
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
303
+ broadcast_id?: string;
304
+ performed_by?: string;
305
+ };
306
+
307
+ export type QuickReplyContent = Omit<
308
+ SendMessageContent,
309
+ 'broadcast_id' | 'variables'
310
+ >;
311
+
312
+ export type BroadcastVariableType = {
313
+ chat_id: string;
314
+ values: { [key: string]: string };
315
+ };
316
+
317
+ export type BroadcastMessagePayload = SendMessageContent & {
318
+ chat_ids: string[];
319
+ broadcast_id?: string;
320
+ variables?: BroadcastVariableType[];
321
+ };
322
+
323
+ export type SingleMessagePayload = SendMessageContent & {
324
+ chat_id: string;
325
+ job_id?: string;
326
+ };
327
+
328
+ export type MessageAttachmentFileTypes =
329
+ | 'image'
330
+ | 'audio'
331
+ | 'document'
332
+ | 'video';
333
+
334
+ export type AttachmentFileType = {
335
+ result: string;
336
+ file: File | null;
337
+ type: MessageAttachmentFileTypes;
338
+ localFileURL?: string;
339
+ };
340
+
341
+ export type AttachmentLinkType = {
342
+ link: {
343
+ url: string;
344
+ type: MessageAttachmentFileTypes;
345
+ name: string;
346
+ mimetype?: string;
347
+ };
348
+ };
349
+
350
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
351
+
352
+ /* -------------------------------- BROADCAST ------------------------------- */
353
+
354
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
355
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
356
+ } & {
357
+ chats: ChatType[];
358
+ };
359
+
360
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
361
+
362
+ export type ChatLogType = {
363
+ log: Tables<'view_chat_logs'>;
364
+ operations: Tables<'tbl_chat_logs'>[];
365
+ };
366
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
367
+
368
+ export type ChatParticipantOperationPayload = {
369
+ participant_ids: string[];
370
+ chat_ids: string[];
371
+ performed_by: string;
372
+ };
373
+
374
+ export type ChatOperationReturn = {
375
+ [participant_id: string]: {
376
+ is_success: boolean;
377
+ message?: string;
378
+ code?: number;
379
+ isInviteV4Sent?: boolean;
380
+ };
381
+ };
382
+
383
+ /* ----------------------- BILLING - STRIPE ----------------------- */
384
+
385
+ export type StripeSubscription = _Stripe.Subscription;
386
+ export type StripeCustomer = _Stripe.Customer;
387
+ export type StripeCoupon = _Stripe.Coupon;
388
+ export type StripePrice = _Stripe.Price;
389
+ export type Stripe = _Stripe;
390
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
391
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
392
+
393
+ /* -------------------------------- REALTIME -------------------------------- */
394
+
395
+ export type PhoneStateType = {
396
+ loading: boolean;
397
+ state: string;
398
+ sync: number;
399
+ percent: number | null;
400
+ message?: string;
401
+ error?: string;
402
+ };
403
+
404
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
405
+
406
+ export type ChatInfoType = Merge<
407
+ ChatType,
408
+ {
409
+ members: {
410
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
411
+ } | null;
412
+ chat_labels: string | null;
413
+ custom_properties: { [key: string]: string } | null;
414
+ }
415
+ >;
416
+
417
+ export type TicketInfoType = {
418
+ chat: ChatInfoType;
419
+ message: {
420
+ body: string;
421
+ chat_id: string;
422
+ org_phone: string;
423
+ timestamp: string;
424
+ media_path: string;
425
+ message_id: string;
426
+ sender_name: string;
427
+ performed_by: string;
428
+ sender_phone: string;
429
+ };
430
+ ticket: {
431
+ org_id: string;
432
+ status: string;
433
+ subject: string;
434
+ assignee: string;
435
+ due_date: string;
436
+ priority: 0 | 1 | 2 | 3 | 4;
437
+ raised_by: string;
438
+ ticket_id: string;
439
+ created_at: string;
440
+ assigned_by: string;
441
+ ticket_labels: string;
442
+ quoted_message_id: string;
443
+ ticket_custom_properties: { [key: string]: string } | null;
444
+ };
445
+ };
446
+
447
+ export type IntegrationLogObjectType =
448
+ | 'chat'
449
+ | 'message'
450
+ | 'reaction'
451
+ | 'ticket';
452
+
453
+ export enum IntegrationLogType {
454
+ NEW_CHAT = 'chat.created',
455
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
456
+ NEW_MESSAGE = 'message.created',
457
+ MESSAGE_UPDATED = 'message.updated',
458
+ MESSAGE_DELETED = 'message.deleted',
459
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
460
+ REACTION_CREATED = 'reaction.created',
461
+ REACTION_UPDATED = 'reaction.updated',
462
+ NEW_TICKET = 'ticket.created',
463
+ TICKET_UPDATED = 'ticket.updated',
464
+ TICKET_DELETED = 'ticket.deleted',
465
+ }
466
+
467
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
468
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
469
+ ? TicketInfoType
470
+ : T extends IntegrationLogType.NEW_CHAT
471
+ ? Tables<'tbl_chats'>
472
+ : T extends
473
+ | IntegrationLogType.NEW_MESSAGE
474
+ | IntegrationLogType.MESSAGE_UPDATED
475
+ | IntegrationLogType.MESSAGE_DELETED
476
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
477
+ ? Tables<'tbl_chat_messages'>
478
+ : T extends
479
+ | IntegrationLogType.REACTION_CREATED
480
+ | IntegrationLogType.REACTION_UPDATED
481
+ ? Tables<'tbl_chat_reactions'>
482
+ : {
483
+ [key: string]: unknown;
484
+ };
485
+
486
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
487
+ OverrideProperties<
488
+ Tables<'tbl_integration_logs'>,
489
+ {
490
+ integration_name: T;
491
+ metadata: {
492
+ event: IntegrationLogMetadataType<T> & {
493
+ event_type: string;
494
+ org_id: string;
495
+ previous_attributes: {
496
+ [key: string]: unknown;
497
+ };
498
+ };
499
+ hook_id: string;
500
+ name: string;
501
+ };
502
+ }
503
+ >;
504
+
505
+ export type APIAuthDetails = {
506
+ org_details: Tables<'view_org'> | null;
507
+ phone_details: Tables<'tbl_org_phones'> | null;
508
+ token_details: Tables<'tbl_integration_tokens'> | null;
509
+ };
510
+
511
+ export type WebhookDataType = OverrideProperties<
512
+ Tables<'tbl_integration_hooks'>,
513
+ {
514
+ integration_name: string[];
515
+ }
516
+ >;
517
+
518
+ export type HubspotObjectDataType = {
519
+ createdAt: string;
520
+ archived: boolean;
521
+ id: string;
522
+ type: 'contacts' | 'tickets' | 'companies';
523
+ properties: Record<
524
+ string,
525
+ {
526
+ groupLabel: string;
527
+ groupName: string;
528
+ propertyKeyName: string;
529
+ propertyKey: string;
530
+ propertyInternalValue: string;
531
+ propertyValue: string;
532
+ propertyType: string;
533
+ propertyFieldType: string;
534
+ }[]
535
+ >;
536
+ };
537
+
538
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
539
+
540
+ export type UserPreferences = {
541
+ theme: 'light' | 'dark';
542
+ language: 'en' | 'es';
543
+ left_sidebar_open: boolean;
544
+ right_sidepanel_open: boolean;
545
+ sync_wa_unread_count: boolean;
546
+ pinned_chats: string[];
547
+ };
548
+
549
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
550
+
551
+ export type PollSendType = {
552
+ pollName: string;
553
+ pollOptions: string[];
554
+ options?: {
555
+ allowMultipleAnswers?: boolean;
556
+ messageSecret?: number[] | null;
557
+ pollId?: string;
558
+ };
559
+ };
560
+
561
+ export type PollResultType = {
562
+ [name: string]: Record<string, string>;
563
+ };
564
+
565
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
566
+
567
+ export type CreateGroupOptions = {
568
+ messagesAdminsOnly?: boolean;
569
+ infoAdminsOnly?: boolean;
570
+ memberAddMode?: boolean;
571
+ image?: string;
572
+ name?: string;
573
+ description?: string;
574
+ };
575
+
576
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
577
+
578
+ export type DeliveryInfoType = {
579
+ delivered: Record<string, number | undefined>;
580
+ read: Record<string, number | undefined>;
581
+ pending: string[];
582
+ read_count: number;
583
+ delivered_count: number;
584
+ };