@periskope/types 0.6.150 → 0.6.151

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,763 +1,617 @@
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
- tickets: {
87
- prefix?: string;
88
- emoji_ticketing: {
89
- is_enabled?: boolean;
90
- is_message_enabled?: boolean;
91
- message_template?: string;
92
- }
93
- }
94
- };
95
-
96
- type AccessScopes = {
97
- feature_flags: Record<string, boolean>;
98
- integrations: boolean;
99
- exports: boolean;
100
- };
101
-
102
- export type OrgType = OverrideProperties<
103
- Merge<
104
- Tables<'tbl_org'>,
105
- {
106
- user: Tables<'tbl_org_members'>;
107
- members: Tables<'tbl_org_members'>[];
108
- phones: Tables<'tbl_org_phones'>[];
109
- labels: Tables<'tbl_org_labels'>[];
110
- quick_replies: Tables<'tbl_quick_replies'>[];
111
- custom_properties: Tables<'tbl_custom_properties'>[];
112
- subscription_status: 'active' | 'inactive' | 'unpaid';
113
- is_enterprise: boolean;
114
- is_free_trial: boolean;
115
- is_hubspot_connected: boolean;
116
- is_freshdesk_connected: boolean;
117
- is_zohodesk_connected: boolean;
118
- access_scopes: AccessScopes;
119
- }
120
- >,
121
- {
122
- org_plan: OrgPlan<AllPlans | Enterprise>;
123
- stripe_customer_details: _Stripe.Customer | null;
124
- stripe_subscription_details: Array<_Stripe.Subscription> | null;
125
- stripe_customer_id: _Stripe.Customer['id'] | null;
126
- org_metadata: OrgMetadata;
127
- }
128
- >;
129
-
130
- export type ChatMemberType = Merge<
131
- Tables<'tbl_chat_participants'>,
132
- Tables<'tbl_contacts'>
133
- >;
134
-
135
- export type ChatType = Merge<
136
- Tables<'view_chats'>,
137
- {
138
- chat_id: string;
139
- latest_message: MessageType | null;
140
- latest_message_timestamp: number | null;
141
- members: { [key: string]: ChatMemberType } | null;
142
- chat_type: 'user' | 'group' | 'business' | 'unknown';
143
- chat_access: { [key: string]: boolean };
144
- label_ids: { [key: string]: boolean };
145
- chat_org_phones?: string[];
146
- message_unread_count: number | null;
147
- hubspot_metadata: {
148
- id: string;
149
- type: string;
150
- hubId: string;
151
- object_data: HubspotObjectDataType;
152
- } | null;
153
- info_admins_only: boolean;
154
- messages_admins_only: boolean;
155
- unread_count?: { [key: string]: number };
156
- active_phone: string | null;
157
- flag_count_map?: { [key: string]: number };
158
- is_archived?: boolean;
159
- is_pinned?: boolean;
160
- closed_at?: number;
161
- }
162
- >;
163
-
164
- /* -------------------------------------------------------------------------- */
165
- /* MESSAGE */
166
- /* -------------------------------------------------------------------------- */
167
-
168
- export type MediaType = {
169
- path: string;
170
- mimetype?: string;
171
- filename?: string;
172
- dimensions?: { width: number; height: number; ar: number };
173
- size?: number;
174
- thumbnail?: string;
175
- };
176
-
177
- export type MessageType = Merge<
178
- OverrideProperties<
179
- Tables<'tbl_chat_messages'>,
180
- {
181
- message_id: string;
182
- org_id: string;
183
- org_phone: string;
184
- chat_id: string;
185
- message_type: (typeof SUPPORTED_TYPES)[number];
186
- media: MediaType | null;
187
- flag_metadata: MessageFlagType | null;
188
- poll_info?: PollSendType | null;
189
- poll_results?: PollResultType | null;
190
- delivery_info?: DeliveryInfoType | null;
191
- }
192
- >,
193
- {
194
- reactions?: ReactionType[];
195
- message_payload?: SingleMessagePayload;
196
- show_unread?: boolean;
197
- highlight?: number;
198
- }
199
- >;
200
-
201
- export type MessageFlagType = {
202
- status: boolean;
203
- response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
204
- response_id?: string;
205
- response_timestamp?: string;
206
- response_email?: string;
207
- };
208
-
209
- /* -------------------------------------------------------------------------- */
210
-
211
- export type TicketType = OverrideProperties<
212
- Tables<'tbl_chat_tickets'>,
213
- {
214
- label_ids: { [key: string]: boolean };
215
- hubspot_metadata: {
216
- id?: string;
217
- type?: string;
218
- hubId?: string;
219
- pipeline: {
220
- id: string;
221
- label: string;
222
- };
223
- object_data?: HubspotObjectDataType;
224
- } | null;
225
- freshdesk_metadata: Record<string, string>;
226
- close_ticket_metadata?:
227
- | {
228
- closed_by: string;
229
- closed_at: string;
230
- closed_message?: string | null;
231
- send_reply_message_id?: string | null;
232
- }
233
- | any;
234
- }
235
- >;
236
-
237
- export type ContactType = Merge<
238
- Tables<'tbl_contacts'>,
239
- {
240
- chats: ChatType[] | null;
241
- chat_ids?: string[];
242
- }
243
- >;
244
- export type ReactionType = Tables<'tbl_chat_reactions'>;
245
-
246
- export type NotificationType = Tables<'tbl_chat_notifications'>;
247
-
248
- export type ChatAccessType = Merge<
249
- TablesUpdate<'tbl_org_members'>,
250
- {
251
- has_access?: boolean;
252
- email: string | null;
253
- }
254
- >;
255
-
256
- /* -------------------------------- CONSTANTS ------------------------------- */
257
-
258
- export const labelColors = [
259
- '#9333EA',
260
- '#0D9488',
261
- '#DB2777',
262
- '#2563EB',
263
- '#F97316',
264
- ];
265
-
266
- export const enumChatColors = [
267
- '#B4876E',
268
- '#A5B337',
269
- '#06CF9C',
270
- '#25D366',
271
- '#02A698',
272
- '#7D9EF1',
273
- '#007BFC',
274
- '#5E47DE',
275
- '#7F66FF',
276
- '#9333EA',
277
- '#FA6533',
278
- '#C4532D',
279
- '#DC2626',
280
- '#FF2E74',
281
- '#DB2777',
282
- ] as const;
283
-
284
- /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
285
-
286
- export const SUPPORTED_TYPES = [
287
- 'chat',
288
- 'sticker',
289
- 'image',
290
- 'video',
291
- 'document',
292
- 'vcard',
293
- 'multi_vcard',
294
- 'audio',
295
- 'ptt',
296
- 'poll_creation',
297
- 'location',
298
- 'ciphertext',
299
- ] as const;
300
-
301
- export type SendMessageContent = {
302
- message_type?: (typeof SUPPORTED_TYPES)[number];
303
- body?: string;
304
- media?: MediaType;
305
- contact_ids?: string[];
306
- location?: {
307
- latitude: string;
308
- longitude: string;
309
- options?: { name?: string; address?: string; url?: string };
310
- };
311
- poll?: PollSendType;
312
- quoted_message_id?: string;
313
- quoted_message_type?: 'reply' | 'forward' | 'reply_private';
314
- broadcast_id?: string;
315
- performed_by?: string;
316
- };
317
-
318
- export type QuickReplyContent = Omit<
319
- SendMessageContent,
320
- 'broadcast_id' | 'variables'
321
- >;
322
-
323
- export type BroadcastVariableType = {
324
- chat_id: string;
325
- values: { [key: string]: string };
326
- };
327
-
328
- export type BroadcastMessagePayload = SendMessageContent & {
329
- chat_ids: string[];
330
- broadcast_id?: string;
331
- variables?: BroadcastVariableType[];
332
- delay?: number;
333
- };
334
-
335
- export type SingleMessagePayload = SendMessageContent & {
336
- chat_id: string;
337
- job_id?: string;
338
- };
339
-
340
- export type MessageAttachmentFileTypes =
341
- | 'image'
342
- | 'audio'
343
- | 'document'
344
- | 'video';
345
-
346
- export type AttachmentFileType = {
347
- result: string;
348
- file: File | null;
349
- type: MessageAttachmentFileTypes;
350
- localFileURL?: string;
351
- };
352
-
353
- export type AttachmentLinkType = {
354
- link: {
355
- url: string;
356
- type: MessageAttachmentFileTypes;
357
- name: string;
358
- mimetype?: string;
359
- };
360
- };
361
-
362
- export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
363
-
364
- /* -------------------------------- BROADCAST ------------------------------- */
365
-
366
- export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
367
- logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
368
- } & {
369
- chats: ChatType[];
370
- };
371
-
372
- /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
373
-
374
- export type ChatLogType = {
375
- log: Tables<'view_chat_logs'>;
376
- operations: Tables<'tbl_chat_logs'>[];
377
- };
378
- export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
379
-
380
- export type ChatParticipantOperationPayload = {
381
- participant_ids: string[];
382
- chat_ids: string[];
383
- performed_by: string;
384
- };
385
-
386
- export type ChatOperationReturn = {
387
- [participant_id: string]: {
388
- is_success: boolean;
389
- message?: string;
390
- code?: number;
391
- isInviteV4Sent?: boolean;
392
- };
393
- };
394
-
395
- /* ----------------------- BILLING - STRIPE ----------------------- */
396
-
397
- export type StripeSubscription = _Stripe.Subscription;
398
- export type StripeCustomer = _Stripe.Customer;
399
- export type StripeCoupon = _Stripe.Coupon;
400
- export type StripePrice = _Stripe.Price;
401
- export type Stripe = _Stripe;
402
- export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
403
- export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
404
-
405
- /* -------------------------------- REALTIME -------------------------------- */
406
-
407
- export type PhoneStateType = {
408
- loading: boolean;
409
- state: string;
410
- sync: number;
411
- percent: number | null;
412
- message?: string;
413
- error?: string;
414
- };
415
-
416
- /* ------------------------------- INTEGRATIONS ----------------------------- */
417
-
418
- export type ChatInfoType = Merge<
419
- ChatType,
420
- {
421
- members: {
422
- [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
423
- } | null;
424
- chat_labels: string | null;
425
- custom_properties: { [key: string]: string } | null;
426
- }
427
- >;
428
-
429
- export type TicketInfoType = {
430
- chat: ChatInfoType;
431
- message: {
432
- body: string;
433
- chat_id: string;
434
- org_phone: string;
435
- timestamp: string;
436
- media_path: string;
437
- message_id: string;
438
- sender_name: string;
439
- performed_by: string;
440
- sender_phone: string;
441
- };
442
- ticket: {
443
- org_id: string;
444
- status: string;
445
- subject: string;
446
- assignee: string;
447
- due_date: string;
448
- priority: 0 | 1 | 2 | 3 | 4;
449
- raised_by: string;
450
- ticket_id: string;
451
- created_at: string;
452
- assigned_by: string;
453
- ticket_labels: string;
454
- quoted_message_id: string;
455
- ticket_custom_properties: { [key: string]: string } | null;
456
- };
457
- };
458
-
459
- export type IntegrationLogObjectType =
460
- | 'chat'
461
- | 'message'
462
- | 'reaction'
463
- | 'ticket';
464
-
465
- export enum IntegrationLogType {
466
- NEW_CHAT = 'chat.created',
467
- NEW_CHAT_NOTIFICATION = 'chat.notification.created',
468
- NEW_MESSAGE = 'message.created',
469
- MESSAGE_UPDATED = 'message.updated',
470
- MESSAGE_DELETED = 'message.deleted',
471
- MESSAGE_ACK_UPDATED = 'message.ack.updated',
472
- REACTION_CREATED = 'reaction.created',
473
- REACTION_UPDATED = 'reaction.updated',
474
- NEW_TICKET = 'ticket.created',
475
- TICKET_UPDATED = 'ticket.updated',
476
- TICKET_DELETED = 'ticket.deleted',
477
- MESSAGE_FLAGGED = 'message.flagged',
478
- MESSAGE_UNFLAGGED = 'message.unflagged',
479
- }
480
-
481
- export type IntegrationLogMetadataType<T extends IntegrationLogType> =
482
- T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
483
- ? TicketInfoType
484
- : T extends IntegrationLogType.NEW_CHAT
485
- ? Tables<'tbl_chats'>
486
- : T extends
487
- | IntegrationLogType.NEW_MESSAGE
488
- | IntegrationLogType.MESSAGE_UPDATED
489
- | IntegrationLogType.MESSAGE_DELETED
490
- | IntegrationLogType.MESSAGE_ACK_UPDATED
491
- | IntegrationLogType.MESSAGE_FLAGGED
492
- | IntegrationLogType.MESSAGE_UNFLAGGED
493
- ? Tables<'tbl_chat_messages'>
494
- : T extends
495
- | IntegrationLogType.REACTION_CREATED
496
- | IntegrationLogType.REACTION_UPDATED
497
- ? Tables<'tbl_chat_reactions'>
498
- : {
499
- [key: string]: unknown;
500
- };
501
-
502
- export type IntegrationLogDetailsType<T extends IntegrationLogType> =
503
- OverrideProperties<
504
- Tables<'tbl_integration_logs'>,
505
- {
506
- integration_name: T;
507
- metadata: {
508
- event: IntegrationLogMetadataType<T> & {
509
- event_type: string;
510
- org_id: string;
511
- previous_attributes: {
512
- [key: string]: unknown;
513
- };
514
- };
515
- hook_id: string;
516
- name: string;
517
- };
518
- }
519
- >;
520
-
521
- export type APIAuthDetails = {
522
- org_details: Tables<'view_org'> | null;
523
- phone_details: Tables<'tbl_org_phones'> | null;
524
- token_details: Tables<'tbl_integration_tokens'> | null;
525
- };
526
-
527
- export type WebhookDataType = OverrideProperties<
528
- Tables<'tbl_integration_hooks'>,
529
- {
530
- integration_name: string[];
531
- }
532
- >;
533
-
534
- export type HubspotObjectDataType = {
535
- createdAt: string;
536
- archived: boolean;
537
- id: string;
538
- type: 'contacts' | 'tickets' | 'companies';
539
- properties: Record<
540
- string,
541
- {
542
- groupLabel: string;
543
- groupName: string;
544
- propertyKeyName: string;
545
- propertyKey: string;
546
- propertyInternalValue: string;
547
- propertyValue: string;
548
- propertyType: string;
549
- propertyFieldType: string;
550
- }[]
551
- >;
552
- };
553
-
554
- /* ---------------------------- USER PREFERENCES ---------------------------- */
555
-
556
- export type UserPreferences = {
557
- theme: 'light' | 'dark';
558
- language: 'en' | 'es';
559
- left_sidebar_open: boolean;
560
- right_sidepanel_open: boolean;
561
- sync_wa_unread_count: boolean;
562
- pinned_chats: string[];
563
- archived_chats: string[];
564
- closed_chats: Record<string, number>;
565
- periskope_chat_limit: number;
566
- };
567
-
568
- /* ----------------------------- POLL VOTE INFO ----------------------------- */
569
-
570
- export type PollSendType = {
571
- pollName: string;
572
- pollOptions: string[];
573
- options?: {
574
- allowMultipleAnswers?: boolean;
575
- messageSecret?: number[] | null;
576
- pollId?: string;
577
- };
578
- };
579
-
580
- export type PollResultType = {
581
- [name: string]: Record<string, string>;
582
- };
583
-
584
- /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
585
-
586
- export type CreateGroupOptions = {
587
- messagesAdminsOnly?: boolean;
588
- infoAdminsOnly?: boolean;
589
- memberAddMode?: boolean;
590
- image?: string;
591
- name?: string;
592
- description?: string;
593
- };
594
-
595
- /* ------------------------------ DELIVERY INFO ----------------------------- */
596
-
597
- export type DeliveryInfoType = {
598
- delivered: Record<string, number | undefined>;
599
- read: Record<string, number | undefined>;
600
- pending: string[];
601
- read_count: number;
602
- delivered_count: number;
603
- };
604
-
605
- /* ---------------------------- CREDITS SYSTEM ---------------------------- */
606
-
607
- export type OrgCreditsType = {
608
- org_id: string;
609
- recurring_allowance: number; // recurring credits replenished every month
610
- recurring_balance: number; // recurring credits remaining in current month
611
- topup_balance: number; // topup credits remaining
612
- total_credits_used: number; // total credits used in current month
613
- next_renewal_date: string;
614
- };
615
-
616
- /* --------------------------------- RULE INFO TYPE -------------------------------- */
617
-
618
- export type ChatRuleInfoType = Merge<
619
- Pick<
620
- Tables<'view_chats'>,
621
- | 'assigned_to'
622
- | 'chat_id'
623
- | 'chat_name'
624
- | 'chat_type'
625
- | 'created_at'
626
- | 'group_description'
627
- | 'info_admins_only'
628
- | 'is_exited'
629
- | 'is_muted'
630
- | 'org_id'
631
- | 'org_phone'
632
- | 'chat_org_phones'
633
- | 'messages_admins_only'
634
- | 'custom_properties'
635
- >,
636
- {
637
- has_flagged_messages: boolean;
638
- labels: string[];
639
- members: string[];
640
- custom_properties: { [key: string]: string } | null;
641
- }
642
- >;
643
-
644
- export type SenderRuleInfoType = Merge<
645
- Omit<
646
- Merge<Tables<'tbl_contacts'>, Tables<'tbl_chat_participants'>>,
647
- | 'verified_name'
648
- | 'verified_level'
649
- | 'updated_at'
650
- | 'short_name'
651
- | 'pushname'
652
- | 'periskope_name'
653
- | 'org_phone'
654
- | 'number'
655
- | 'name'
656
- | 'label_ids'
657
- | 'is_wa_contact'
658
- | 'is_user'
659
- | 'is_my_contact'
660
- | 'is_me'
661
- | 'is_imported'
662
- | 'is_group'
663
- | 'is_blocked'
664
- | 'contact_color'
665
- | 'business_profile'
666
- | 'id'
667
- | 'contact_image'
668
- | 'contact_type'
669
- | 'chat_id'
670
- >,
671
- {
672
- is_internal: boolean;
673
- labels: string[] | null;
674
- }
675
- >;
676
-
677
- export type MessageRuleInfoType = {
678
- chat: ChatRuleInfoType;
679
- sender: SenderRuleInfoType;
680
- message: OverrideProperties<
681
- Omit<
682
- Tables<'tbl_chat_messages'>,
683
- | 'vcards'
684
- | 'updated_at'
685
- | 'unique_id'
686
- | 'token'
687
- | 'to'
688
- | 'sent_message_id'
689
- | 'raw_data'
690
- | 'delivery_info'
691
- | 'poll_results'
692
- | 'poll_info'
693
- | 'order_id'
694
- | 'mentioned_ids'
695
- | 'media_key'
696
- | 'location'
697
- | 'links'
698
- | 'is_status'
699
- | 'is_starred'
700
- | 'is_gif'
701
- | 'is_forwarded'
702
- | 'is_ephemeral'
703
- | 'is_deleted'
704
- | 'fts'
705
- | 'quoted_message_id'
706
- | 'invite_v4'
707
- | 'id'
708
- | 'has_reaction'
709
- | 'has_media'
710
- | 'duration'
711
- | 'broadcast'
712
- | 'broadcast_id'
713
- | 'device_type'
714
- | 'forwarding_score'
715
- | 'from'
716
- | 'from_me'
717
- | 'message_ticket_id'
718
- | 'prev_body'
719
- | 'flag_response_time'
720
- | 'flag_metadata'
721
- >,
722
- {
723
- media: MediaType | null;
724
- }
725
- >;
726
- };
727
-
728
- export type ReactionRuleInfoType = {
729
- chat: ChatRuleInfoType;
730
- sender: SenderRuleInfoType;
731
- message: MessageRuleInfoType['message'];
732
- reaction: Pick<
733
- Tables<'tbl_chat_reactions'>,
734
- 'reaction' | 'sender_id' | 'message_id' | 'chat_id' | 'reaction_id'
735
- >;
736
- };
737
-
738
- export type TicketRuleInfoType = {
739
- chat: ChatRuleInfoType;
740
- sender: SenderRuleInfoType;
741
- ticket: Merge<
742
- Pick<
743
- Tables<'tbl_chat_tickets'>,
744
- | 'org_id'
745
- | 'status'
746
- | 'chat_id'
747
- | 'subject'
748
- | 'assignee'
749
- | 'due_date'
750
- | 'priority'
751
- | 'raised_by'
752
- | 'ticket_id'
753
- | 'created_at'
754
- | 'is_deleted'
755
- >,
756
- {
757
- labels: string[] | null;
758
- custom_properties: { [key: string]: string } | null;
759
- }
760
- >;
761
- message: MessageRuleInfoType['message'];
762
- };
763
- export type FeatureFlagReturnType = Record<string, boolean>;
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
+ tickets: {
87
+ prefix?: string;
88
+ emoji_ticketing: {
89
+ is_enabled?: boolean;
90
+ is_message_enabled?: boolean;
91
+ message_template?: string;
92
+ }
93
+ }
94
+ };
95
+
96
+ type AccessScopes = {
97
+ feature_flags: Record<string, boolean>;
98
+ integrations: boolean;
99
+ exports: boolean;
100
+ };
101
+
102
+ export type OrgType = OverrideProperties<
103
+ Merge<
104
+ Tables<'tbl_org'>,
105
+ {
106
+ user: Tables<'tbl_org_members'>;
107
+ members: Tables<'tbl_org_members'>[];
108
+ phones: Tables<'tbl_org_phones'>[];
109
+ labels: Tables<'tbl_org_labels'>[];
110
+ quick_replies: Tables<'tbl_quick_replies'>[];
111
+ custom_properties: Tables<'tbl_custom_properties'>[];
112
+ subscription_status: 'active' | 'inactive' | 'unpaid';
113
+ is_enterprise: boolean;
114
+ is_free_trial: boolean;
115
+ is_hubspot_connected: boolean;
116
+ is_freshdesk_connected: boolean;
117
+ is_zohodesk_connected: boolean;
118
+ access_scopes: AccessScopes;
119
+ }
120
+ >,
121
+ {
122
+ org_plan: OrgPlan<AllPlans | Enterprise>;
123
+ stripe_customer_details: _Stripe.Customer | null;
124
+ stripe_subscription_details: Array<_Stripe.Subscription> | null;
125
+ stripe_customer_id: _Stripe.Customer['id'] | null;
126
+ org_metadata: OrgMetadata;
127
+ }
128
+ >;
129
+
130
+ export type ChatMemberType = Merge<
131
+ Tables<'tbl_chat_participants'>,
132
+ Tables<'tbl_contacts'>
133
+ >;
134
+
135
+ export type ChatType = Merge<
136
+ Tables<'view_chats'>,
137
+ {
138
+ chat_id: string;
139
+ latest_message: MessageType | null;
140
+ latest_message_timestamp: number | null;
141
+ members: { [key: string]: ChatMemberType } | null;
142
+ chat_type: 'user' | 'group' | 'business' | 'unknown';
143
+ chat_access: { [key: string]: boolean };
144
+ label_ids: { [key: string]: boolean };
145
+ chat_org_phones?: string[];
146
+ message_unread_count: number | null;
147
+ hubspot_metadata: {
148
+ id: string;
149
+ type: string;
150
+ hubId: string;
151
+ object_data: HubspotObjectDataType;
152
+ } | null;
153
+ info_admins_only: boolean;
154
+ messages_admins_only: boolean;
155
+ unread_count?: { [key: string]: number };
156
+ active_phone: string | null;
157
+ flag_count_map?: { [key: string]: number };
158
+ is_archived?: boolean;
159
+ is_pinned?: boolean;
160
+ closed_at?: number;
161
+ common_chats?: string[];
162
+ }
163
+ >;
164
+
165
+ /* -------------------------------------------------------------------------- */
166
+ /* MESSAGE */
167
+ /* -------------------------------------------------------------------------- */
168
+
169
+ export type MediaType = {
170
+ path: string;
171
+ mimetype?: string;
172
+ filename?: string;
173
+ dimensions?: { width: number; height: number; ar: number };
174
+ size?: number;
175
+ thumbnail?: string;
176
+ };
177
+
178
+ export type MessageType = Merge<
179
+ OverrideProperties<
180
+ Tables<'tbl_chat_messages'>,
181
+ {
182
+ message_id: string;
183
+ org_id: string;
184
+ org_phone: string;
185
+ chat_id: string;
186
+ message_type: (typeof SUPPORTED_TYPES)[number];
187
+ media: MediaType | null;
188
+ flag_metadata: MessageFlagType | null;
189
+ poll_info?: PollSendType | null;
190
+ poll_results?: PollResultType | null;
191
+ delivery_info?: DeliveryInfoType | null;
192
+ }
193
+ >,
194
+ {
195
+ reactions?: ReactionType[];
196
+ message_payload?: SingleMessagePayload;
197
+ show_unread?: number;
198
+ highlight?: number;
199
+ }
200
+ >;
201
+
202
+ export type MessageFlagType = {
203
+ status: boolean;
204
+ response_type?: 'message' | 'reaction' | 'ticket' | 'manual';
205
+ response_id?: string;
206
+ response_timestamp?: string;
207
+ response_email?: string;
208
+ };
209
+
210
+ /* -------------------------------------------------------------------------- */
211
+
212
+ export type TicketType = OverrideProperties<
213
+ Tables<'tbl_chat_tickets'>,
214
+ {
215
+ label_ids: { [key: string]: boolean };
216
+ hubspot_metadata: {
217
+ id?: string;
218
+ type?: string;
219
+ hubId?: string;
220
+ pipeline: {
221
+ id: string;
222
+ label: string;
223
+ };
224
+ object_data?: HubspotObjectDataType;
225
+ } | null;
226
+ freshdesk_metadata: Record<string, string>;
227
+ close_ticket_metadata?:
228
+ | {
229
+ closed_by: string;
230
+ closed_at: string;
231
+ closed_message?: string | null;
232
+ send_reply_message_id?: string | null;
233
+ }
234
+ | any;
235
+ }
236
+ >;
237
+
238
+ export type ContactType = Merge<
239
+ Tables<'tbl_contacts'>,
240
+ {
241
+ chats: ChatType[] | null;
242
+ chat_ids?: string[];
243
+ }
244
+ >;
245
+ export type ReactionType = Tables<'tbl_chat_reactions'>;
246
+
247
+ export type NotificationType = Tables<'tbl_chat_notifications'>;
248
+
249
+ export type ChatAccessType = Merge<
250
+ TablesUpdate<'tbl_org_members'>,
251
+ {
252
+ has_access?: boolean;
253
+ email: string | null;
254
+ }
255
+ >;
256
+
257
+ /* -------------------------------- CONSTANTS ------------------------------- */
258
+
259
+ export const labelColors = [
260
+ '#9333EA',
261
+ '#0D9488',
262
+ '#DB2777',
263
+ '#2563EB',
264
+ '#F97316',
265
+ ];
266
+
267
+ export const enumChatColors = [
268
+ '#B4876E',
269
+ '#A5B337',
270
+ '#06CF9C',
271
+ '#25D366',
272
+ '#02A698',
273
+ '#7D9EF1',
274
+ '#007BFC',
275
+ '#5E47DE',
276
+ '#7F66FF',
277
+ '#9333EA',
278
+ '#FA6533',
279
+ '#C4532D',
280
+ '#DC2626',
281
+ '#FF2E74',
282
+ '#DB2777',
283
+ ] as const;
284
+
285
+ /* -------------------------- SEND MESSAGE PAYLOAD -------------------------- */
286
+
287
+ export const SUPPORTED_TYPES = [
288
+ 'chat',
289
+ 'sticker',
290
+ 'image',
291
+ 'video',
292
+ 'document',
293
+ 'vcard',
294
+ 'multi_vcard',
295
+ 'audio',
296
+ 'ptt',
297
+ 'poll_creation',
298
+ 'location',
299
+ 'ciphertext',
300
+ ] as const;
301
+
302
+ export type SendMessageContent = {
303
+ message_type?: (typeof SUPPORTED_TYPES)[number];
304
+ body?: string;
305
+ media?: MediaType;
306
+ contact_ids?: string[];
307
+ location?: {
308
+ latitude: string;
309
+ longitude: string;
310
+ options?: { name?: string; address?: string; url?: string };
311
+ };
312
+ poll?: PollSendType;
313
+ quoted_message_id?: string;
314
+ quoted_message_type?: 'reply' | 'forward' | 'reply_private';
315
+ broadcast_id?: string;
316
+ performed_by?: string;
317
+ };
318
+
319
+ export type QuickReplyContent = Omit<
320
+ SendMessageContent,
321
+ 'broadcast_id' | 'variables'
322
+ >;
323
+
324
+ export type BroadcastVariableType = {
325
+ chat_id: string;
326
+ values: { [key: string]: string };
327
+ };
328
+
329
+ export type BroadcastMessagePayload = SendMessageContent & {
330
+ chat_ids: string[];
331
+ broadcast_id?: string;
332
+ variables?: BroadcastVariableType[];
333
+ delay?: number;
334
+ };
335
+
336
+ export type SingleMessagePayload = SendMessageContent & {
337
+ chat_id: string;
338
+ job_id?: string;
339
+ priority?: number;
340
+ };
341
+
342
+ export type MessageAttachmentFileTypes =
343
+ | 'image'
344
+ | 'audio'
345
+ | 'document'
346
+ | 'video';
347
+
348
+ export type AttachmentFileType = {
349
+ result: string;
350
+ file: File | null;
351
+ type: MessageAttachmentFileTypes;
352
+ localFileURL?: string;
353
+ };
354
+
355
+ export type AttachmentLinkType = {
356
+ link: {
357
+ url: string;
358
+ type: MessageAttachmentFileTypes;
359
+ name: string;
360
+ mimetype?: string;
361
+ };
362
+ };
363
+
364
+ export type AttachmentTypeProps = AttachmentFileType | AttachmentLinkType;
365
+
366
+ /* -------------------------------- BROADCAST ------------------------------- */
367
+
368
+ export type BroadcastLogType = Tables<'view_broadcast_logs'> & {
369
+ logs: (Tables<'tbl_broadcast_logs'> & Partial<ChatType>)[];
370
+ } & {
371
+ chats: ChatType[];
372
+ };
373
+
374
+ /* ----------------------- CHAT PARTICIPANT OPERATION ----------------------- */
375
+
376
+ export type ChatLogType = {
377
+ log: Tables<'view_chat_logs'>;
378
+ operations: Tables<'tbl_chat_logs'>[];
379
+ };
380
+ export type ChatOperationsType = 'ADD' | 'REMOVE' | 'PROMOTE' | 'DEMOTE';
381
+
382
+ export type ChatParticipantOperationPayload = {
383
+ participant_ids: string[];
384
+ chat_ids: string[];
385
+ performed_by: string;
386
+ };
387
+
388
+ export type ChatOperationReturn = {
389
+ [participant_id: string]: {
390
+ is_success: boolean;
391
+ message?: string;
392
+ code?: number;
393
+ isInviteV4Sent?: boolean;
394
+ };
395
+ };
396
+
397
+ /* ----------------------- BILLING - STRIPE ----------------------- */
398
+
399
+ export type StripeSubscription = _Stripe.Subscription;
400
+ export type StripeCustomer = _Stripe.Customer;
401
+ export type StripeCoupon = _Stripe.Coupon;
402
+ export type StripePrice = _Stripe.Price;
403
+ export type Stripe = _Stripe;
404
+ export type StripeUpcomingInvoice = _Stripe.UpcomingInvoice;
405
+ export type StripeLineItem = _Stripe.Checkout.SessionCreateParams.LineItem;
406
+
407
+ /* -------------------------------- REALTIME -------------------------------- */
408
+
409
+ export type PhoneStateType = {
410
+ loading: boolean;
411
+ state: string;
412
+ sync: number;
413
+ percent: number | null;
414
+ message?: string;
415
+ error?: string;
416
+ };
417
+
418
+ /* ------------------------------- INTEGRATIONS ----------------------------- */
419
+
420
+ export type ChatInfoType = Merge<
421
+ ChatType,
422
+ {
423
+ members: {
424
+ [key: string]: Merge<ChatMemberType, { contact_labels: string }>;
425
+ } | null;
426
+ chat_labels: string | null;
427
+ custom_properties: { [key: string]: string } | null;
428
+ }
429
+ >;
430
+
431
+ export type TicketInfoType = {
432
+ chat: ChatInfoType;
433
+ message: {
434
+ body: string;
435
+ chat_id: string;
436
+ org_phone: string;
437
+ timestamp: string;
438
+ media_path: string;
439
+ message_id: string;
440
+ sender_name: string;
441
+ performed_by: string;
442
+ sender_phone: string;
443
+ };
444
+ ticket: {
445
+ org_id: string;
446
+ status: string;
447
+ subject: string;
448
+ assignee: string;
449
+ due_date: string;
450
+ priority: 0 | 1 | 2 | 3 | 4;
451
+ raised_by: string;
452
+ ticket_id: string;
453
+ created_at: string;
454
+ assigned_by: string;
455
+ ticket_labels: string;
456
+ quoted_message_id: string;
457
+ ticket_custom_properties: { [key: string]: string } | null;
458
+ };
459
+ };
460
+
461
+ export type IntegrationLogObjectType =
462
+ | 'chat'
463
+ | 'message'
464
+ | 'reaction'
465
+ | 'ticket';
466
+
467
+ export enum IntegrationLogType {
468
+ NEW_CHAT = 'chat.created',
469
+ NEW_CHAT_NOTIFICATION = 'chat.notification.created',
470
+ NEW_MESSAGE = 'message.created',
471
+ MESSAGE_UPDATED = 'message.updated',
472
+ MESSAGE_DELETED = 'message.deleted',
473
+ MESSAGE_ACK_UPDATED = 'message.ack.updated',
474
+ REACTION_CREATED = 'reaction.created',
475
+ REACTION_UPDATED = 'reaction.updated',
476
+ NEW_TICKET = 'ticket.created',
477
+ TICKET_UPDATED = 'ticket.updated',
478
+ TICKET_DELETED = 'ticket.deleted',
479
+ MESSAGE_FLAGGED = 'message.flagged',
480
+ MESSAGE_UNFLAGGED = 'message.unflagged',
481
+ }
482
+
483
+ export type IntegrationLogMetadataType<T extends IntegrationLogType> =
484
+ T extends IntegrationLogType.NEW_TICKET | IntegrationLogType.TICKET_UPDATED
485
+ ? TicketInfoType
486
+ : T extends IntegrationLogType.NEW_CHAT
487
+ ? Tables<'tbl_chats'>
488
+ : T extends
489
+ | IntegrationLogType.NEW_MESSAGE
490
+ | IntegrationLogType.MESSAGE_UPDATED
491
+ | IntegrationLogType.MESSAGE_DELETED
492
+ | IntegrationLogType.MESSAGE_ACK_UPDATED
493
+ | IntegrationLogType.MESSAGE_FLAGGED
494
+ | IntegrationLogType.MESSAGE_UNFLAGGED
495
+ ? Tables<'tbl_chat_messages'>
496
+ : T extends
497
+ | IntegrationLogType.REACTION_CREATED
498
+ | IntegrationLogType.REACTION_UPDATED
499
+ ? Tables<'tbl_chat_reactions'>
500
+ : {
501
+ [key: string]: unknown;
502
+ };
503
+
504
+ export type IntegrationLogDetailsType<T extends IntegrationLogType> =
505
+ OverrideProperties<
506
+ Tables<'tbl_integration_logs'>,
507
+ {
508
+ integration_name: T;
509
+ metadata: {
510
+ event: IntegrationLogMetadataType<T> & {
511
+ event_type: string;
512
+ org_id: string;
513
+ previous_attributes: {
514
+ [key: string]: unknown;
515
+ };
516
+ };
517
+ hook_id: string;
518
+ name: string;
519
+ };
520
+ }
521
+ >;
522
+
523
+ export type APIAuthDetails = {
524
+ org_details: Tables<'view_org'> | null;
525
+ phone_details: Tables<'tbl_org_phones'> | null;
526
+ token_details: Tables<'tbl_integration_tokens'> | null;
527
+ };
528
+
529
+ export type WebhookDataType = OverrideProperties<
530
+ Tables<'tbl_integration_hooks'>,
531
+ {
532
+ integration_name: string[];
533
+ }
534
+ >;
535
+
536
+ export type HubspotObjectDataType = {
537
+ createdAt: string;
538
+ archived: boolean;
539
+ id: string;
540
+ type: 'contacts' | 'tickets' | 'companies';
541
+ properties: Record<
542
+ string,
543
+ {
544
+ groupLabel: string;
545
+ groupName: string;
546
+ propertyKeyName: string;
547
+ propertyKey: string;
548
+ propertyInternalValue: string;
549
+ propertyValue: string;
550
+ propertyType: string;
551
+ propertyFieldType: string;
552
+ }[]
553
+ >;
554
+ };
555
+
556
+ /* ---------------------------- USER PREFERENCES ---------------------------- */
557
+
558
+ export type UserPreferences = {
559
+ theme: 'light' | 'dark';
560
+ language: 'en' | 'es';
561
+ left_sidebar_open: boolean;
562
+ right_sidepanel_open: boolean;
563
+ sync_wa_unread_count: boolean;
564
+ pinned_chats: string[];
565
+ archived_chats: string[];
566
+ closed_chats: Record<string, number>;
567
+ periskope_chat_limit: number;
568
+ };
569
+
570
+ /* ----------------------------- POLL VOTE INFO ----------------------------- */
571
+
572
+ export type PollSendType = {
573
+ pollName: string;
574
+ pollOptions: string[];
575
+ options?: {
576
+ allowMultipleAnswers?: boolean;
577
+ messageSecret?: number[] | null;
578
+ pollId?: string;
579
+ };
580
+ };
581
+
582
+ export type PollResultType = {
583
+ [name: string]: Record<string, string>;
584
+ };
585
+
586
+ /* -------------------------- CREATE GROUP OPTIONS -------------------------- */
587
+
588
+ export type CreateGroupOptions = {
589
+ messagesAdminsOnly?: boolean;
590
+ infoAdminsOnly?: boolean;
591
+ memberAddMode?: boolean;
592
+ image?: string;
593
+ name?: string;
594
+ description?: string;
595
+ };
596
+
597
+ /* ------------------------------ DELIVERY INFO ----------------------------- */
598
+
599
+ export type DeliveryInfoType = {
600
+ delivered: Record<string, number | undefined>;
601
+ read: Record<string, number | undefined>;
602
+ pending: string[];
603
+ read_count: number;
604
+ delivered_count: number;
605
+ };
606
+
607
+ /* ---------------------------- CREDITS SYSTEM ---------------------------- */
608
+
609
+ export type OrgCreditsType = {
610
+ org_id: string;
611
+ recurring_allowance: number; // recurring credits replenished every month
612
+ recurring_balance: number; // recurring credits remaining in current month
613
+ topup_balance: number; // topup credits remaining
614
+ total_credits_used: number; // total credits used in current month
615
+ next_renewal_date: string;
616
+ };
617
+