@hipnation-truth/sdk 0.26.19 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.d.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import { FunctionReference } from 'convex/server';
1
2
  import * as react from 'react';
2
3
  import { ReactNode } from 'react';
3
4
  import * as convex_browser from 'convex/browser';
4
5
  import { ConvexHttpClient } from 'convex/browser';
6
+ import { z } from 'zod';
5
7
 
6
8
  /**
7
9
  * React hooks for Truth SDK — reactive conversation + message data.
@@ -106,6 +108,12 @@ interface ConversationListItem {
106
108
  /** ISO timestamp of when the caller last marked the conversation read. */
107
109
  lastReadAt: string | null;
108
110
  }
111
+ /** Row from `conversations:listUrgentForUser` (Urgent tab). */
112
+ interface UrgentConversationListItem extends ConversationListItem {
113
+ isUrgent: true;
114
+ urgentSetAt: string | null;
115
+ urgentSetBy: string | null;
116
+ }
109
117
  /**
110
118
  * Raw `conversations` table row — what `getByPhonePair` returns. No
111
119
  * unread / read joining; for that, prefer `useConversations`.
@@ -120,6 +128,10 @@ interface ConversationRow {
120
128
  lastEventId: string | null;
121
129
  lastMessageAt: string;
122
130
  createdAt: string;
131
+ /** Manual Urgent flag; absent/false = not urgent. */
132
+ isUrgent?: boolean;
133
+ urgentSetAt?: string;
134
+ urgentSetBy?: string;
123
135
  }
124
136
  /**
125
137
  * Message row returned by `conversationMessages:getByConversationId` —
@@ -146,6 +158,43 @@ interface ConversationNoteRow {
146
158
  type: string | null;
147
159
  createdAt: string;
148
160
  updatedAt: string;
161
+ /**
162
+ * ISO timestamp of the FIRST successful send to Elation; null if never sent.
163
+ * Never overwritten by a resend.
164
+ */
165
+ elationSentAt: string | null;
166
+ /** Actor (Clerk user id) of the first send; null if never sent. */
167
+ elationSentBy: string | null;
168
+ /** Convex id of the `elationSyncEvents` audit row for the first send. */
169
+ elationSyncEventId: string | null;
170
+ /** ISO timestamp of the most recent resend; null if never resent. */
171
+ elationLastResentAt: string | null;
172
+ /** Actor (Clerk user id) of the most recent resend; null if never resent. */
173
+ elationLastResentBy: string | null;
174
+ /** `elationSyncEvents` audit row id of the most recent resend. */
175
+ elationLastResentSyncEventId: string | null;
176
+ /** Number of resends after the first send; 0 if never resent. */
177
+ elationResendCount: number;
178
+ }
179
+ /**
180
+ * One task history entry (comhub#374): a task was completed or reopened.
181
+ * Append-only; written server-side on a real status transition.
182
+ */
183
+ interface TaskEventRow {
184
+ id: string;
185
+ /** Convex id of the task (`conversationTasks` or standalone `tasks` row). */
186
+ taskId: string;
187
+ taskSource: "conversation" | "standalone";
188
+ /** Set for conversation tasks; null for standalone tasks. */
189
+ conversationId: string | null;
190
+ action: "completed" | "reopened";
191
+ /** Email of the user who made the change ("unknown" if not supplied). */
192
+ actor: string;
193
+ /** Resolved display name for `actor`, or null (fall back to `actor`). */
194
+ actorName: string | null;
195
+ /** Task title/description snapshot, for the link text. */
196
+ taskTitle: string | null;
197
+ occurredAt: string;
149
198
  }
150
199
  /**
151
200
  * Conversation task row — single entry shown in the right-panel tasks
@@ -289,6 +338,10 @@ interface UseMessagesOptions {
289
338
  * resolves (`userId === undefined`); not an error, just a skip.
290
339
  */
291
340
  declare function useConversations(filters: UseConversationsFilters): UseQueryResult<ConversationListItem[]>;
341
+ /**
342
+ * Subscribe to the user's Urgent conversations (Urgent tab), newest first.
343
+ */
344
+ declare function useUrgentConversations(filters: Pick<UseConversationsFilters, "userId" | "limit">): UseQueryResult<UrgentConversationListItem[]>;
292
345
  /**
293
346
  * Look up a single conversation by its normalized phonePair (sorted
294
347
  * digit-pair, e.g. `"5125550123|6505551234"`). Returns `null` if no
@@ -358,6 +411,20 @@ declare function useConversationTasksForUser(userId: string | null | undefined,
358
411
  limit?: number;
359
412
  }): UseQueryResult<ConversationTaskForUserRow[]>;
360
413
  declare function useConversationTasksByPhonePair(phonePair: string | null | undefined): UseQueryResult<ConversationTaskRow[]>;
414
+ /**
415
+ * History (completed/reopened) of one task, oldest first. Returns the newest
416
+ * `limit` events (server default 200, max 500).
417
+ */
418
+ declare function useTaskHistory(taskId: string | null | undefined, options?: {
419
+ limit?: number;
420
+ }): UseQueryResult<TaskEventRow[]>;
421
+ /**
422
+ * Task history entries for a conversation thread, oldest first. Returns the
423
+ * newest `limit` events (server default 200, max 500).
424
+ */
425
+ declare function useConversationTaskHistory(conversationId: string | null | undefined, options?: {
426
+ limit?: number;
427
+ }): UseQueryResult<TaskEventRow[]>;
361
428
 
362
429
  /**
363
430
  * React hooks for Dialpad call events — replaces CommHub's Hasura
@@ -417,6 +484,17 @@ interface DialpadCallRow {
417
484
  voicemailLink: string | null;
418
485
  voicemailDurationSec: number | null;
419
486
  transcript: unknown | null;
487
+ /** Dialpad AI Recap — arrives via a separate `recap_summary` event after hangup. */
488
+ recapSummary: string | null;
489
+ /**
490
+ * User-authored call summary (#454) — distinct from `recapSummary`
491
+ * above; the user creates/edits this via `useSaveCallSummary`. Never
492
+ * written by the Dialpad webhook.
493
+ */
494
+ userSummary: string | null;
495
+ /** Email/Clerk id of whoever last saved `userSummary`. */
496
+ userSummaryBy: string | null;
497
+ userSummaryUpdatedAt: string | null;
420
498
  duration: number | null;
421
499
  occurredAt: string;
422
500
  updatedAt: string;
@@ -461,6 +539,664 @@ declare function useDialpadCallByCallId(callId: string | null | undefined): UseQ
461
539
  declare function useDialpadCallLog(callId: string | null | undefined, options?: {
462
540
  limit?: number;
463
541
  }): UseQueryResult<DialpadCallLogRow[]>;
542
+ /**
543
+ * Returns a stable `saveCallSummary(callId, userSummary, updatedBy)`
544
+ * callback backed by the `dialpadCallEvents:setUserSummary` Convex
545
+ * mutation. Writes the USER-authored call summary (#454) — separate from
546
+ * the Dialpad AI `recapSummary` surfaced read-only above; this never
547
+ * touches that field. Mirrors `useConversationTaskMarkSeen` in
548
+ * `./tasks.ts`: plain `useMutation` + `useCallback`, not a live
549
+ * subscription.
550
+ *
551
+ * @example
552
+ * ```tsx
553
+ * const saveCallSummary = useSaveCallSummary();
554
+ *
555
+ * async function onSave() {
556
+ * await saveCallSummary(call.callId, notes, currentUser.email);
557
+ * }
558
+ * ```
559
+ */
560
+ declare function useSaveCallSummary(): (callId: string, userSummary: string, updatedBy: string) => Promise<{
561
+ ok: true;
562
+ }>;
563
+
564
+ /**
565
+ * Configuration interfaces for the Truth SDK.
566
+ */
567
+ /**
568
+ * Environment options for the Truth platform.
569
+ */
570
+ declare const ENVIRONMENTS: {
571
+ readonly local: "local";
572
+ readonly staging: "staging";
573
+ readonly stg: "stg";
574
+ readonly sandbox: "sandbox";
575
+ readonly uat: "uat";
576
+ readonly production: "production";
577
+ };
578
+ type Environment = (typeof ENVIRONMENTS)[keyof typeof ENVIRONMENTS];
579
+ /**
580
+ * Fetches a user-identity JWT for Convex calls. Return the token from
581
+ * your identity provider's Clerk JWT template named "convex"
582
+ * (e.g. `getToken({ template: "convex" })` from `@clerk/expo`), or
583
+ * `null` when no user is signed in.
584
+ *
585
+ * Convex invokes this with `{ forceRefreshToken: true }` when the cached
586
+ * token has expired — forward it to your provider (e.g. Clerk's
587
+ * `getToken({ template: "convex", skipCache: opts?.forceRefreshToken })`)
588
+ * so the refresh returns a fresh token rather than a stale cached one.
589
+ */
590
+ type AuthTokenFetcher = (opts?: {
591
+ forceRefreshToken?: boolean;
592
+ }) => Promise<string | null | undefined>;
593
+ /**
594
+ * Configuration for initializing a TruthClient.
595
+ */
596
+ interface TruthClientConfig {
597
+ /** API key for authenticating with the Truth platform (e.g. "hn_live_...") */
598
+ apiKey: string;
599
+ /**
600
+ * Per-call Clerk JWT fetcher for Convex data access. When provided,
601
+ * every Convex query/mutation/action carries the caller's identity;
602
+ * Convex deployments with `CLERK_AUTH_REQUIRED` enabled reject calls
603
+ * without it. Omit for service contexts that don't act as a user.
604
+ */
605
+ getAuthToken?: AuthTokenFetcher;
606
+ /** Target environment */
607
+ environment: Environment;
608
+ /** Override the default Convex URL for data access */
609
+ convexUrl?: string;
610
+ /** Event source identifier (e.g. "communication-hub.backend") */
611
+ source?: string;
612
+ /** Git SHA or version string for event source versioning */
613
+ sourceVersion?: string;
614
+ /** Default tenant (organization) ID for events */
615
+ tenantId?: string;
616
+ /** Number of events to buffer before flushing (default: 25) */
617
+ batchSize?: number;
618
+ /** Interval in milliseconds between automatic flushes (default: 5000) */
619
+ flushIntervalMs?: number;
620
+ /** Base URL for the Truth API (overrides environment-based default) */
621
+ apiBaseUrl?: string;
622
+ /**
623
+ * Auto-register the service worker and subscribe to web push on init.
624
+ * Only applies in browser environments with Push API support.
625
+ * Default: true.
626
+ */
627
+ autoInitServiceWorker?: boolean;
628
+ /** Path to the service worker file. Default: "/truth-sw.js" */
629
+ serviceWorkerPath?: string;
630
+ }
631
+ /**
632
+ * Actor context attached to tracked events.
633
+ */
634
+ interface ActorContext {
635
+ actorId: string;
636
+ actorType: "user" | "system" | "webhook";
637
+ }
638
+ /**
639
+ * Paginated result wrapper for list operations.
640
+ */
641
+ interface PaginatedResult<T> {
642
+ data: T[];
643
+ cursor: string | null;
644
+ hasMore: boolean;
645
+ }
646
+
647
+ /**
648
+ * CareInboxResource — care-team shared-mailbox email (T12).
649
+ *
650
+ * Writes go through the Truth oRPC `careInbox` router (all
651
+ * `verifiedUserProcedure`, so every call REQUIRES the user JWT):
652
+ * - `linkMessage` POST /api/care-inbox/link
653
+ * - `unlinkMessage` POST /api/care-inbox/unlink
654
+ * - `replyToThread` POST /api/care-inbox/outbound/thread-reply
655
+ * - `composeEmail` POST /api/care-inbox/outbound/compose
656
+ * Reads are Convex queries; use the hooks in `@hipnation-truth/sdk/react`
657
+ * (`useEmailThreads`, …) or `createCareInboxSource`. Nothing here is
658
+ * persisted offline.
659
+ *
660
+ * Two type layers:
661
+ * - `*View` types are the raw Convex query payloads (nullable where the
662
+ * stored row can lack a value).
663
+ * - The contract types (`EmailMessage`, `EmailThreadSummary`, `ThreadPage`,
664
+ * …) mirror comhub's `lib/email/careInboxSource.ts` exactly. `to*`
665
+ * projections turn views into contract shapes: a missing string becomes
666
+ * "" and a missing participant `{ address: "", name: null }` because the
667
+ * contract declares those fields non-null.
668
+ *
669
+ * Errors: every rejection is a `CareInboxError` whose `code` is the comhub
670
+ * `CareInboxErrorCode`, so it satisfies comhub's `Error & { code }` contract
671
+ * as-is. `status` (0 = no HTTP response), `rpcCode` (oRPC / transport code),
672
+ * `reason` and `detail` carry the server detail. `toCareInboxError()` maps
673
+ * anything thrown — including a Convex `ConvexError` from a hook — onto it.
674
+ */
675
+
676
+ type EmailDirection = "inbound" | "outbound";
677
+ /**
678
+ * Thread-list filter. "unlinked" is served only to triage callers (threads
679
+ * with at least one unlinked message); others get forbidden/not_triage.
680
+ */
681
+ type ThreadListFilter = "all" | "unread" | "unlinked";
682
+ interface EmailMailbox {
683
+ id: string;
684
+ /** Shared mailbox address. "" for non-triage callers (server-redacted). */
685
+ address: string;
686
+ displayName: string;
687
+ }
688
+ interface MailboxAccess {
689
+ mailboxes: EmailMailbox[];
690
+ /** May see Unlinked and link/unlink (admin-only until G-TRIAGE). */
691
+ canTriage: boolean;
692
+ }
693
+ interface EmailParticipant {
694
+ address: string;
695
+ name: string | null;
696
+ }
697
+ interface EmailMessage {
698
+ id: string;
699
+ threadId: string;
700
+ mailboxId: string;
701
+ direction: EmailDirection;
702
+ from: EmailParticipant;
703
+ to: EmailParticipant[];
704
+ subject: string;
705
+ /** Epoch milliseconds. */
706
+ sentAt: number;
707
+ hasAttachments: boolean;
708
+ linkedPatientId: string | null;
709
+ linkedPatientName: string | null;
710
+ /** Always null in build 1 (metadata only). */
711
+ bodyText: string | null;
712
+ }
713
+ interface EmailThreadSummary {
714
+ id: string;
715
+ mailboxId: string;
716
+ subject: string;
717
+ /** Epoch milliseconds of the newest message. */
718
+ lastMessageAt: number;
719
+ lastDirection: EmailDirection;
720
+ counterpart: EmailParticipant;
721
+ messageCount: number;
722
+ unreadCount: number;
723
+ /** Triage callers only; always 0 for staff. */
724
+ unlinkedCount: number;
725
+ linkedPatientName: string | null;
726
+ hasAttachments: boolean;
727
+ }
728
+ interface LinkedPatientContact {
729
+ patientId: string;
730
+ name: string;
731
+ email: string | null;
732
+ phone: string | null;
733
+ office: string | null;
734
+ }
735
+ interface EmailThreadDetail {
736
+ summary: EmailThreadSummary;
737
+ mailbox: EmailMailbox;
738
+ /** Oldest first. */
739
+ messages: EmailMessage[];
740
+ /** Not provided in build 1 (always null). */
741
+ patientContact?: LinkedPatientContact | null;
742
+ }
743
+ interface ListThreadsArgs {
744
+ mailboxId?: string;
745
+ filter?: ThreadListFilter;
746
+ cursor?: string | null;
747
+ /** Server default 25, max 50. */
748
+ limit?: number;
749
+ }
750
+ interface ThreadPage {
751
+ threads: EmailThreadSummary[];
752
+ /** A mailbox-filtered page can be short; keep paging while non-null. */
753
+ nextCursor: string | null;
754
+ }
755
+ interface PatientLinkCandidate {
756
+ patientId: string;
757
+ displayName: string;
758
+ /** Office name when known; never an email address. */
759
+ detail: string | null;
760
+ }
761
+ interface LinkMessageArgs {
762
+ messageId: string;
763
+ patientId: string;
764
+ /**
765
+ * Client idempotency key (8-128 chars of `[A-Za-z0-9_:.-]`). A key the
766
+ * server already recorded for the message is a no-op that returns the
767
+ * current state, so a late retry can never undo a newer unlink.
768
+ */
769
+ requestId: string;
770
+ }
771
+ interface UnlinkMessageArgs {
772
+ messageId: string;
773
+ /** Client idempotency key; see `LinkMessageArgs.requestId`. */
774
+ requestId: string;
775
+ }
776
+ interface LinkResult {
777
+ message: EmailMessage;
778
+ }
779
+ interface SendReplyArgs {
780
+ threadId: string;
781
+ body: string;
782
+ clientRequestId: string;
783
+ }
784
+ interface SendEmailArgs {
785
+ to: string;
786
+ subject: string;
787
+ body: string;
788
+ patientId?: string;
789
+ mailboxId: string;
790
+ clientRequestId: string;
791
+ }
792
+ /** Send is disabled in this build (always rejects forbidden/send_disabled). */
793
+ interface SendResult {
794
+ message: EmailMessage;
795
+ thread: EmailThreadSummary;
796
+ }
797
+ interface MarkReadArgs {
798
+ threadId: string;
799
+ }
800
+ interface MarkReadResult {
801
+ thread: EmailThreadSummary;
802
+ }
803
+ /** comhub `CareInboxErrorCode`. */
804
+ type CareInboxErrorCode = "forbidden" | "not_found" | "offline" | "unavailable" | "validation" | "unknown";
805
+ /** `EmailMailbox` plus the server-derived switches. */
806
+ interface CareInboxMailbox extends EmailMailbox {
807
+ mode: "mirror" | "live";
808
+ /** Live mailbox AND send enabled on the deployment. */
809
+ canSend: boolean;
810
+ /** bodyVisibility !== "none" (bodies still need openThreadBodies). */
811
+ bodyVisible: boolean;
812
+ }
813
+ interface CareInboxMailboxAccess extends MailboxAccess {
814
+ mailboxes: CareInboxMailbox[];
815
+ }
816
+ interface CareInboxThreadDetail extends EmailThreadDetail {
817
+ mailbox: CareInboxMailbox;
818
+ /** Whether `openThreadBodies` would serve bodies to this caller. */
819
+ bodyVisible: boolean;
820
+ patientContact: null;
821
+ }
822
+ /** Triage-only unlinked message page (`listUnlinked`). */
823
+ interface UnlinkedMessagePage {
824
+ messages: EmailMessage[];
825
+ nextCursor: string | null;
826
+ }
827
+ /** Back-compat aliases (T12 names). */
828
+ type CareInboxEmailMessage = EmailMessage;
829
+ type CareInboxEmailThreadSummary = EmailThreadSummary;
830
+ type CareInboxLinkResult = LinkResult;
831
+ type CareInboxSendResult = SendResult;
832
+ /**
833
+ * SDK call input: the contract args with `requestId` optional. Omit it and
834
+ * the SDK generates one for this call; pass your own to make retries across
835
+ * calls idempotent.
836
+ */
837
+ type LinkEmailMessageInput = Omit<LinkMessageArgs, "requestId"> & Partial<Pick<LinkMessageArgs, "requestId">>;
838
+ type UnlinkEmailMessageInput = Omit<UnlinkMessageArgs, "requestId"> & Partial<Pick<UnlinkMessageArgs, "requestId">>;
839
+ type ReplyToEmailThreadInput = SendReplyArgs;
840
+ type ComposeEmailInput = SendEmailArgs;
841
+ type EmailParticipantView = EmailParticipant;
842
+ /** `careInboxQueries` message row. `bodyText` is always null from queries. */
843
+ interface EmailMessageView {
844
+ id: string;
845
+ threadId: string | null;
846
+ mailboxId: string;
847
+ direction: EmailDirection;
848
+ from: EmailParticipantView | null;
849
+ to: EmailParticipantView[];
850
+ subject: string | null;
851
+ sentAt: number;
852
+ hasAttachments: boolean;
853
+ linkedPatientId: string | null;
854
+ linkedPatientName: string | null;
855
+ bodyText: null;
856
+ }
857
+ interface EmailThreadSummaryView {
858
+ id: string;
859
+ mailboxId: string;
860
+ subject: string | null;
861
+ lastMessageAt: number;
862
+ lastDirection: EmailDirection | null;
863
+ counterpart: EmailParticipantView | null;
864
+ messageCount: number;
865
+ unreadCount: number;
866
+ unlinkedCount: number;
867
+ linkedPatientId: string | null;
868
+ linkedPatientName: string | null;
869
+ hasAttachments: boolean;
870
+ }
871
+ interface EmailMailboxView {
872
+ id: string;
873
+ displayName: string;
874
+ mode: "mirror" | "live";
875
+ canSend: boolean;
876
+ bodyVisible: boolean;
877
+ /** Present only when the caller can triage. */
878
+ address?: string;
879
+ }
880
+ interface EmailMailboxAccessView {
881
+ mailboxes: EmailMailboxView[];
882
+ canTriage: boolean;
883
+ }
884
+ /** Filters `listThreadsForUser` serves ("unlinked": triage only). */
885
+ type EmailThreadListFilter = ThreadListFilter;
886
+ interface EmailThreadPageView {
887
+ threads: EmailThreadSummaryView[];
888
+ nextCursor: string | null;
889
+ }
890
+ interface EmailThreadDetailView {
891
+ summary: EmailThreadSummaryView;
892
+ mailbox: EmailMailboxView;
893
+ /** Oldest first. Staff: linked only; triage: linked + unlinked. */
894
+ messages: EmailMessageView[];
895
+ bodyVisible: boolean;
896
+ patientContact: null;
897
+ }
898
+ interface UnlinkedEmailPageView {
899
+ messages: EmailMessageView[];
900
+ nextCursor: string | null;
901
+ }
902
+ type PatientLinkCandidateView = PatientLinkCandidate;
903
+ interface MarkEmailThreadReadResult {
904
+ thread: EmailThreadSummaryView;
905
+ }
906
+ interface EmailThreadBodiesView {
907
+ messages: {
908
+ id: string;
909
+ bodyText: string | null;
910
+ }[];
911
+ }
912
+ declare function toEmailMessage(m: EmailMessageView): EmailMessage;
913
+ /**
914
+ * `lastDirection` is null only for a thread with no visible message (it
915
+ * cannot happen for a summary the server lists; kept defensive). Projects to
916
+ * "inbound".
917
+ */
918
+ declare function toEmailThreadSummary(t: EmailThreadSummaryView): EmailThreadSummary;
919
+ declare function toEmailMailbox(m: EmailMailboxView): CareInboxMailbox;
920
+ declare function toMailboxAccess(a: EmailMailboxAccessView): CareInboxMailboxAccess;
921
+ declare function toEmailThreadDetail(d: EmailThreadDetailView): CareInboxThreadDetail;
922
+ declare function toThreadPage(p: EmailThreadPageView): ThreadPage;
923
+ declare function toUnlinkedMessagePage(p: UnlinkedEmailPageView): UnlinkedMessagePage;
924
+ declare function toMarkReadResult(r: MarkEmailThreadReadResult): MarkReadResult;
925
+ /**
926
+ * Machine-readable sub-code. Server-sent: `send_disabled` | `not_triage` |
927
+ * `body_gated` | `unauthenticated` (Convex: no identity). SDK-derived:
928
+ * `unauthenticated` (no user JWT, or HTTP 401). The contract has no auth
929
+ * code, so `unauthenticated` surfaces as `forbidden` on every path.
930
+ */
931
+ type CareInboxErrorReason = "send_disabled" | "not_triage" | "body_gated" | "unauthenticated";
932
+ interface CareInboxErrorFields {
933
+ /** HTTP status; 0 when there was no HTTP response (incl. Convex errors). */
934
+ status?: number;
935
+ /**
936
+ * oRPC code (`FORBIDDEN`, `NOT_FOUND`, …) or, for status 0, `TRANSPORT`
937
+ * (fetch threw), `TIMEOUT`, `NO_API_KEY`, `NO_USER_TOKEN`.
938
+ */
939
+ rpcCode?: string | null;
940
+ reason?: CareInboxErrorReason | null;
941
+ /** Fixed server marker (e.g. `PATIENT_HAS_NO_OFFICE`), when present. */
942
+ detail?: string | null;
943
+ }
944
+ /**
945
+ * The single care-inbox error. `code` is the comhub `CareInboxErrorCode`, so
946
+ * an instance satisfies comhub's `CareInboxError` (`Error & { code }`). The
947
+ * message never carries content, addresses or ids.
948
+ */
949
+ declare class CareInboxError extends Error {
950
+ readonly code: CareInboxErrorCode;
951
+ readonly status: number;
952
+ readonly rpcCode: string | null;
953
+ readonly reason: CareInboxErrorReason | null;
954
+ readonly detail: string | null;
955
+ constructor(code: CareInboxErrorCode, fields?: CareInboxErrorFields);
956
+ }
957
+ /** True for any value carrying a contract `code` (comhub `isCareInboxError`). */
958
+ declare function isCareInboxError(value: unknown): value is Error & {
959
+ code: CareInboxErrorCode;
960
+ };
961
+ /**
962
+ * Coerce anything thrown by the resource, a care-inbox Convex function
963
+ * (`ConvexError({ code, reason? })`, payload on `.data`) or a comhub-style
964
+ * error into a `CareInboxError`. Never throws; unrecognised → `unknown`.
965
+ */
966
+ declare function toCareInboxError(value: unknown): CareInboxError;
967
+ interface CareInboxErrorInfo {
968
+ code: CareInboxErrorCode;
969
+ reason: CareInboxErrorReason | null;
970
+ }
971
+ /** `{ code, reason }` of anything thrown (see `toCareInboxError`). */
972
+ declare function careInboxErrorInfo(err: unknown): CareInboxErrorInfo;
973
+ declare class CareInboxResource {
974
+ /** 30s upstream timeout — matches ConversationsResource. */
975
+ private static readonly REQUEST_TIMEOUT_MS;
976
+ private readonly baseUrl;
977
+ private readonly auth;
978
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
979
+ /** Link one message to a patient (triage only). */
980
+ linkMessage(input: LinkEmailMessageInput): Promise<LinkResult>;
981
+ /** Undo a manual link (triage only). */
982
+ unlinkMessage(input: UnlinkEmailMessageInput): Promise<LinkResult>;
983
+ /** Reply into a thread. This build always rejects 403 `send_disabled`. */
984
+ replyToThread(input: SendReplyArgs): Promise<SendResult>;
985
+ /** Start a new email. This build always rejects 403 `send_disabled`. */
986
+ composeEmail(input: SendEmailArgs): Promise<SendResult>;
987
+ private post;
988
+ }
989
+
990
+ /**
991
+ * `createCareInboxSource` — a promise-based object with exactly the method
992
+ * set of comhub's `CareInboxSource` (lib/email/careInboxSource.ts), so the
993
+ * comhub adapter is a pass-through. Reads are one-shot Convex queries
994
+ * (never persisted); link/unlink/send go through `CareInboxResource`.
995
+ *
996
+ * Every rejection is a `CareInboxError` (`Error & { code }` with the comhub
997
+ * code set). `getThread` rejects `unavailable` when the feature flag is off
998
+ * (the query returns null then). In React use `useCareInboxSource()` from
999
+ * `@hipnation-truth/sdk/react`, which rebuilds the source when Convex auth
1000
+ * flips so comhub's query hooks refetch.
1001
+ */
1002
+
1003
+ declare const careInboxRefs: {
1004
+ listThreadsForUser: FunctionReference<"query", "public", {
1005
+ mailboxId?: string;
1006
+ filter?: ThreadListFilter;
1007
+ cursor?: string | null;
1008
+ limit?: number;
1009
+ }, EmailThreadPageView, string | undefined>;
1010
+ getThread: FunctionReference<"query", "public", {
1011
+ threadId: string;
1012
+ }, EmailThreadDetailView | null, string | undefined>;
1013
+ listUnlinked: FunctionReference<"query", "public", {
1014
+ mailboxId: string;
1015
+ cursor?: string | null;
1016
+ limit?: number;
1017
+ }, UnlinkedEmailPageView, string | undefined>;
1018
+ unreadEmailCount: FunctionReference<"query", "public", {
1019
+ mailboxId?: string;
1020
+ }, number, string | undefined>;
1021
+ listMailboxesForUser: FunctionReference<"query", "public", Record<string, never>, EmailMailboxAccessView, string | undefined>;
1022
+ searchPatientsForLink: FunctionReference<"query", "public", {
1023
+ q: string;
1024
+ }, PatientLinkCandidate[], string | undefined>;
1025
+ markRead: FunctionReference<"mutation", "public", {
1026
+ threadId: string;
1027
+ }, MarkEmailThreadReadResult, string | undefined>;
1028
+ openThreadBodies: FunctionReference<"mutation", "public", {
1029
+ threadId: string;
1030
+ }, EmailThreadBodiesView, string | undefined>;
1031
+ };
1032
+ /** The Convex surface the source needs (`ConvexReactClient` satisfies it). */
1033
+ interface CareInboxConvexClient {
1034
+ query(ref: FunctionReference<"query">, args: Record<string, unknown>): Promise<unknown>;
1035
+ mutation(ref: FunctionReference<"mutation">, args: Record<string, unknown>): Promise<unknown>;
1036
+ }
1037
+ interface CareInboxSourceDeps {
1038
+ convex: CareInboxConvexClient;
1039
+ careInbox: Pick<CareInboxResource, "linkMessage" | "unlinkMessage" | "replyToThread" | "composeEmail">;
1040
+ }
1041
+ /** Method set of comhub's `CareInboxSource` (minus optional `subscribe`). */
1042
+ interface CareInboxSdkSource {
1043
+ listThreads(args?: ListThreadsArgs): Promise<ThreadPage>;
1044
+ getUnreadCount(args?: {
1045
+ mailboxId?: string;
1046
+ }): Promise<number>;
1047
+ getThread(threadId: string): Promise<CareInboxThreadDetail>;
1048
+ listMailboxesForUser(): Promise<CareInboxMailboxAccess>;
1049
+ searchPatientsForLink(query: string): Promise<PatientLinkCandidate[]>;
1050
+ linkMessage(args: LinkMessageArgs): Promise<LinkResult>;
1051
+ unlinkMessage(args: UnlinkMessageArgs): Promise<LinkResult>;
1052
+ sendReply(args: SendReplyArgs): Promise<SendResult>;
1053
+ sendEmail(args: SendEmailArgs): Promise<SendResult>;
1054
+ markRead(args: MarkReadArgs): Promise<MarkReadResult>;
1055
+ }
1056
+ declare function createCareInboxSource({ convex, careInbox, }: CareInboxSourceDeps): CareInboxSdkSource;
1057
+
1058
+ /**
1059
+ * React hooks for the care-team email inbox (T12).
1060
+ *
1061
+ * Reads are LIVE Convex subscriptions via `useQuery` from `convex/react` —
1062
+ * deliberately NOT the offline persisted mirror: email metadata is never
1063
+ * written to device storage. Do not route these through
1064
+ * `usePersistentQuery` or anything under `./offline/`.
1065
+ *
1066
+ * Every Convex function here derives the caller from the auth identity and
1067
+ * throws `forbidden` without one, so all queries skip until Convex reports
1068
+ * the websocket authenticated (`useConvexAuth`).
1069
+ *
1070
+ * Query hooks return `{ data, loading, error }` (see `UseQueryResult`) with
1071
+ * `data` projected onto comhub's contract types (`ThreadPage`,
1072
+ * `EmailThreadDetail`, …). `data` is `undefined` while loading or skipped;
1073
+ * `error` is SDK-side (a `CareInboxError`). Convex errors
1074
+ * (`ConvexError({code, reason?})`) throw into the nearest error boundary —
1075
+ * map them with `toCareInboxError`.
1076
+ *
1077
+ * Triage-only hooks (`useUnlinkedEmails`, `useSearchPatientsForLink`, and
1078
+ * the thread-list hooks with `filter: "unlinked"`) read `canTriage`
1079
+ * themselves and, for a non-triage caller, skip the query and report
1080
+ * `error: CareInboxError("forbidden", reason "not_triage")` — the contract's
1081
+ * "not available" state. No `enabled: canTriage` wiring needed.
1082
+ *
1083
+ * `useCareInboxSource()` returns a promise-based object with comhub's
1084
+ * `CareInboxSource` method set for the comhub adapter.
1085
+ */
1086
+
1087
+ interface UseEmailThreadsOptions {
1088
+ mailboxId?: string;
1089
+ /**
1090
+ * "all" (default), "unread", or "unlinked" (triage only: threads holding
1091
+ * unlinked mail; non-triage callers skip with forbidden/not_triage).
1092
+ */
1093
+ filter?: EmailThreadListFilter;
1094
+ /** Page cursor from a previous page's `nextCursor`. */
1095
+ cursor?: string | null;
1096
+ /** Page size (server default 25, max 50). */
1097
+ limit?: number;
1098
+ /** Pass false to skip. Default true. */
1099
+ enabled?: boolean;
1100
+ }
1101
+ /**
1102
+ * One page of the caller's email threads, newest first. A filtered page can
1103
+ * be short; keep paging while `nextCursor` is non-null (or use
1104
+ * `usePaginatedEmailThreads`). `filter: "unlinked"` is triage-only: it waits
1105
+ * for `canTriage`, and a non-triage caller skips with forbidden/not_triage.
1106
+ */
1107
+ declare function useEmailThreads(options?: UseEmailThreadsOptions): UseQueryResult<ThreadPage>;
1108
+ interface UsePaginatedEmailThreadsOptions {
1109
+ mailboxId?: string;
1110
+ /** As `UseEmailThreadsOptions.filter` ("unlinked" is triage-only). */
1111
+ filter?: EmailThreadListFilter;
1112
+ /** Page size per load (server default 25, max 50). */
1113
+ limit?: number;
1114
+ enabled?: boolean;
1115
+ }
1116
+ interface UsePaginatedEmailThreadsResult {
1117
+ /** Every loaded page, newest first, de-duplicated by id. */
1118
+ data: EmailThreadSummary[] | undefined;
1119
+ /** True while the first page loads. */
1120
+ loading: boolean;
1121
+ /** True while a page after the first loads. */
1122
+ loadingMore: boolean;
1123
+ /** A page's Convex error, as a `CareInboxError`. */
1124
+ error: CareInboxError | undefined;
1125
+ /** False once the last loaded page had `nextCursor: null`. */
1126
+ hasMore: boolean;
1127
+ /** Load the next page. No-op while loading or when `hasMore` is false. */
1128
+ loadMore: () => void;
1129
+ }
1130
+ /**
1131
+ * Load-more over `listThreadsForUser`'s cursor pages: every loaded page stays
1132
+ * a live subscription and the results are concatenated. Changing
1133
+ * `mailboxId` / `filter` / `limit` resets to the first page.
1134
+ * `filter: "unlinked"` waits for `canTriage` (`loading`), and a non-triage
1135
+ * caller skips with `error` forbidden/not_triage.
1136
+ */
1137
+ declare function usePaginatedEmailThreads(options?: UsePaginatedEmailThreadsOptions): UsePaginatedEmailThreadsResult;
1138
+ /**
1139
+ * One thread. Staff get linked messages only; triage callers also get the
1140
+ * unlinked ones (`linkedPatientId` null). Skips while `threadId` is empty.
1141
+ * `data` is null when the feature flag is off.
1142
+ */
1143
+ declare function useEmailThread(threadId: string | null | undefined): UseQueryResult<CareInboxThreadDetail | null>;
1144
+ interface UseUnlinkedEmailsOptions {
1145
+ /** Required; the query skips without it. */
1146
+ mailboxId: string | null | undefined;
1147
+ cursor?: string | null;
1148
+ limit?: number;
1149
+ /** Pass false to skip. Default true. Non-triage callers skip on their own. */
1150
+ enabled?: boolean;
1151
+ }
1152
+ /**
1153
+ * Triage only: a mailbox's unlinked messages, newest first. For a
1154
+ * non-triage caller it skips and returns `error` forbidden/not_triage.
1155
+ */
1156
+ declare function useUnlinkedEmails(options: UseUnlinkedEmailsOptions): UseQueryResult<UnlinkedMessagePage>;
1157
+ /** Number of the caller's threads with unread > 0 (tab badge). */
1158
+ declare function useEmailUnreadCount(options?: {
1159
+ mailboxId?: string;
1160
+ enabled?: boolean;
1161
+ }): UseQueryResult<number>;
1162
+ /** Mailboxes the caller can see, plus `canTriage`. */
1163
+ declare function useMailboxes(options?: {
1164
+ enabled?: boolean;
1165
+ }): UseQueryResult<CareInboxMailboxAccess>;
1166
+ interface UseSearchPatientsForLinkOptions {
1167
+ /** Pass false to skip. Default true. Non-triage callers skip on their own. */
1168
+ enabled?: boolean;
1169
+ /** Minimum trimmed length before searching. Default 2. */
1170
+ minLength?: number;
1171
+ }
1172
+ /**
1173
+ * Triage only: patient candidates for linking (≤ 20). Not persisted. Skips
1174
+ * while the trimmed query is shorter than `minLength`; for a non-triage
1175
+ * caller it skips and returns `error` forbidden/not_triage.
1176
+ */
1177
+ declare function useSearchPatientsForLink(q: string | null | undefined, options?: UseSearchPatientsForLinkOptions): UseQueryResult<PatientLinkCandidate[]>;
1178
+ /** `link(input)` → oRPC `POST /api/care-inbox/link`. Throws `CareInboxError`. */
1179
+ declare function useLinkEmailMessage(): (input: LinkMessageArgs) => Promise<LinkResult>;
1180
+ /** `unlink(input)` → oRPC `POST /api/care-inbox/unlink`. */
1181
+ declare function useUnlinkEmailMessage(): (input: UnlinkMessageArgs) => Promise<LinkResult>;
1182
+ /**
1183
+ * `markRead(threadId)` → Convex `careInboxReads:markRead`. Rejects with a
1184
+ * `CareInboxError` (`unavailable` when the feature flag is off).
1185
+ */
1186
+ declare function useMarkEmailThreadRead(): (threadId: string) => Promise<MarkReadResult>;
1187
+ /**
1188
+ * `openBodies(threadId)` → Convex `careInboxReads:openThreadBodies`. Every
1189
+ * call writes a body-view audit row; rejects `CareInboxError` forbidden with
1190
+ * reason `body_gated` when the mailbox does not allow bodies for this caller.
1191
+ */
1192
+ declare function useOpenEmailThreadBodies(): (threadId: string) => Promise<EmailThreadBodiesView>;
1193
+ /**
1194
+ * comhub's `CareInboxSource` over this SDK. Until Convex reports the socket
1195
+ * authenticated, Convex-backed methods reject forbidden/unauthenticated; the
1196
+ * returned object changes identity when auth flips, so consumers keyed on
1197
+ * the source refetch.
1198
+ */
1199
+ declare function useCareInboxSource(): CareInboxSdkSource;
464
1200
 
465
1201
  /**
466
1202
  * React hook for a single conversation lookup by Convex id — Truth SDK.
@@ -1255,89 +1991,6 @@ interface AppointmentListOptions {
1255
1991
  cursor?: string;
1256
1992
  }
1257
1993
 
1258
- /**
1259
- * Configuration interfaces for the Truth SDK.
1260
- */
1261
- /**
1262
- * Environment options for the Truth platform.
1263
- */
1264
- declare const ENVIRONMENTS: {
1265
- readonly local: "local";
1266
- readonly staging: "staging";
1267
- readonly stg: "stg";
1268
- readonly sandbox: "sandbox";
1269
- readonly uat: "uat";
1270
- readonly production: "production";
1271
- };
1272
- type Environment = (typeof ENVIRONMENTS)[keyof typeof ENVIRONMENTS];
1273
- /**
1274
- * Fetches a user-identity JWT for Convex calls. Return the token from
1275
- * your identity provider's Clerk JWT template named "convex"
1276
- * (e.g. `getToken({ template: "convex" })` from `@clerk/expo`), or
1277
- * `null` when no user is signed in.
1278
- *
1279
- * Convex invokes this with `{ forceRefreshToken: true }` when the cached
1280
- * token has expired — forward it to your provider (e.g. Clerk's
1281
- * `getToken({ template: "convex", skipCache: opts?.forceRefreshToken })`)
1282
- * so the refresh returns a fresh token rather than a stale cached one.
1283
- */
1284
- type AuthTokenFetcher = (opts?: {
1285
- forceRefreshToken?: boolean;
1286
- }) => Promise<string | null | undefined>;
1287
- /**
1288
- * Configuration for initializing a TruthClient.
1289
- */
1290
- interface TruthClientConfig {
1291
- /** API key for authenticating with the Truth platform (e.g. "hn_live_...") */
1292
- apiKey: string;
1293
- /**
1294
- * Per-call Clerk JWT fetcher for Convex data access. When provided,
1295
- * every Convex query/mutation/action carries the caller's identity;
1296
- * Convex deployments with `CLERK_AUTH_REQUIRED` enabled reject calls
1297
- * without it. Omit for service contexts that don't act as a user.
1298
- */
1299
- getAuthToken?: AuthTokenFetcher;
1300
- /** Target environment */
1301
- environment: Environment;
1302
- /** Override the default Convex URL for data access */
1303
- convexUrl?: string;
1304
- /** Event source identifier (e.g. "communication-hub.backend") */
1305
- source?: string;
1306
- /** Git SHA or version string for event source versioning */
1307
- sourceVersion?: string;
1308
- /** Default tenant (organization) ID for events */
1309
- tenantId?: string;
1310
- /** Number of events to buffer before flushing (default: 25) */
1311
- batchSize?: number;
1312
- /** Interval in milliseconds between automatic flushes (default: 5000) */
1313
- flushIntervalMs?: number;
1314
- /** Base URL for the Truth API (overrides environment-based default) */
1315
- apiBaseUrl?: string;
1316
- /**
1317
- * Auto-register the service worker and subscribe to web push on init.
1318
- * Only applies in browser environments with Push API support.
1319
- * Default: true.
1320
- */
1321
- autoInitServiceWorker?: boolean;
1322
- /** Path to the service worker file. Default: "/truth-sw.js" */
1323
- serviceWorkerPath?: string;
1324
- }
1325
- /**
1326
- * Actor context attached to tracked events.
1327
- */
1328
- interface ActorContext {
1329
- actorId: string;
1330
- actorType: "user" | "system" | "webhook";
1331
- }
1332
- /**
1333
- * Paginated result wrapper for list operations.
1334
- */
1335
- interface PaginatedResult<T> {
1336
- data: T[];
1337
- cursor: string | null;
1338
- hasMore: boolean;
1339
- }
1340
-
1341
1994
  /**
1342
1995
  * AppointmentResource provides data access to normalized appointment records
1343
1996
  * backed by Convex.
@@ -1402,7 +2055,6 @@ interface Attachment {
1402
2055
  }
1403
2056
  declare class AttachmentsResource {
1404
2057
  private readonly baseUrl;
1405
- private readonly apiKey;
1406
2058
  private readonly auth;
1407
2059
  private readonly convex;
1408
2060
  constructor(apiBaseUrl: string, apiKey: string, convexClient: ConvexHttpClient, getAuthToken?: AuthTokenFetcher);
@@ -1593,6 +2245,19 @@ declare class ConversationsResource {
1593
2245
  }): Promise<{
1594
2246
  updated: true;
1595
2247
  }>;
2248
+ /**
2249
+ * Mark / unmark a conversation Urgent (conversation-level, shared by
2250
+ * participants). Refused if `userId` is not a participant.
2251
+ */
2252
+ setUrgent(input: {
2253
+ conversationId: string;
2254
+ userId: string;
2255
+ isUrgent: boolean;
2256
+ }): Promise<{
2257
+ updated: true;
2258
+ isUrgent: boolean;
2259
+ changed: boolean;
2260
+ }>;
1596
2261
  /**
1597
2262
  * Zero unread on every conversation the user has reads for, except
1598
2263
  * those whose `providerPhone` is in `excludedProviderPhones`.
@@ -1658,7 +2323,6 @@ interface DialpadNumberInfo {
1658
2323
  }
1659
2324
  declare class DialpadResource {
1660
2325
  private readonly baseUrl;
1661
- private readonly apiKey;
1662
2326
  private readonly auth;
1663
2327
  constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
1664
2328
  /**
@@ -1724,7 +2388,6 @@ declare class DialpadResource {
1724
2388
  declare class MessagesResource {
1725
2389
  readonly dialpad: DialpadResource;
1726
2390
  private readonly baseUrl;
1727
- private readonly apiKey;
1728
2391
  private readonly auth;
1729
2392
  constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
1730
2393
  /**
@@ -1808,6 +2471,16 @@ declare class EhrResource {
1808
2471
  * Caller assembles the note body (text + bullets). Truth owns the Elation
1809
2472
  * OAuth token and the HTTP call so applications can drop Elation
1810
2473
  * credentials from their own config.
2474
+ *
2475
+ * BREAKING — 0.26.20, `pushConversationToElation`:
2476
+ * - AUTH CLASS CHANGED. The server route moved from `applicationProcedure`
2477
+ * to `verifiedUserProcedure`, so an API key alone (including a secret
2478
+ * `hn_sk_*` or legacy `hn_live_*` key) now gets 401. Callers MUST supply
2479
+ * `getAuthToken` on the client so a verified Clerk JWT accompanies the
2480
+ * request; this resource already sends it with `requireUserToken: true`.
2481
+ * - `input.initiatedBy` is DEPRECATED and ignored server-side. The audit
2482
+ * row's actor is the JWT `sub`. Passing a differing value is logged as a
2483
+ * warning server-side and will be removed in a future major.
1811
2484
  */
1812
2485
 
1813
2486
  interface NonVisitNoteBullet {
@@ -1834,14 +2507,27 @@ interface PushConversationToElationInput {
1834
2507
  /** One-of: conversationId (Convex) or phonePair. */
1835
2508
  conversationId?: string;
1836
2509
  phonePair?: string;
1837
- /** Actor user id — recorded on the audit row. */
1838
- initiatedBy: string;
2510
+ /**
2511
+ * @deprecated Ignored by the server; the actor recorded on the audit row is
2512
+ * derived from the verified Clerk JWT (`sub`). Supplying a value has no
2513
+ * effect and will be removed in a future major.
2514
+ */
2515
+ initiatedBy?: string;
1839
2516
  /** Pre-assembled note body (transcript-style text). */
1840
2517
  noteText: string;
1841
2518
  bullets?: NonVisitNoteBullet[];
1842
2519
  notesPushed?: number;
1843
2520
  messagesPushed?: number;
1844
2521
  tasksPushed?: number;
2522
+ /**
2523
+ * Convex ids of the `conversationNotes` rows included in this push. When
2524
+ * set, Truth rejects the call with 409 CONFLICT if any is already marked
2525
+ * sent (unless `resend`), rejects ids that are not in this conversation with
2526
+ * 404, and stamps each note sent on success (never on failure).
2527
+ */
2528
+ noteIds?: string[];
2529
+ /** Explicitly allow re-sending notes already marked sent. Default false. */
2530
+ resend?: boolean;
1845
2531
  }
1846
2532
  interface PushConversationToElationResult {
1847
2533
  success: true;
@@ -1850,10 +2536,11 @@ interface PushConversationToElationResult {
1850
2536
  notesPushed: number;
1851
2537
  messagesPushed: number;
1852
2538
  tasksPushed: number;
2539
+ /** Notes stamped sent by this call (empty when no `noteIds` were supplied). */
2540
+ sentNoteIds: string[];
1853
2541
  }
1854
2542
  declare class NotesResource {
1855
2543
  private readonly baseUrl;
1856
- private readonly apiKey;
1857
2544
  private readonly auth;
1858
2545
  constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
1859
2546
  /** 30s upstream timeout — Elation API has occasional slow hops; we
@@ -1872,6 +2559,11 @@ declare class NotesResource {
1872
2559
  * physician/practice in Elation, posts the note, and writes an audit
1873
2560
  * row to `elationSyncEvents`. Replaces CommHub's `pushNotesToElation`
1874
2561
  * Hasura action.
2562
+ *
2563
+ * Auth: requires a user token. The server runs this route under
2564
+ * `verifiedUserProcedure`, so the API key alone is rejected with 401 —
2565
+ * configure `getAuthToken` on the client. `input.initiatedBy` is ignored;
2566
+ * the audit row's actor is the verified JWT `sub`.
1875
2567
  */
1876
2568
  pushConversationToElation(input: PushConversationToElationInput): Promise<PushConversationToElationResult>;
1877
2569
  }
@@ -1995,7 +2687,6 @@ interface PushEventPayload {
1995
2687
  }
1996
2688
  declare class NotificationsResource {
1997
2689
  private readonly baseUrl;
1998
- private readonly apiKey;
1999
2690
  private readonly auth;
2000
2691
  constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
2001
2692
  private post;
@@ -2077,7 +2768,6 @@ interface PatientMedicalDetailsResult {
2077
2768
  }
2078
2769
  declare class PatientDetailsResource {
2079
2770
  private readonly baseUrl;
2080
- private readonly apiKey;
2081
2771
  private readonly auth;
2082
2772
  constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
2083
2773
  private post;
@@ -2231,6 +2921,116 @@ declare class RemindersResource {
2231
2921
  listByConversation(conversationId: string): Promise<Reminder[]>;
2232
2922
  }
2233
2923
 
2924
+ /**
2925
+ * ReportsResource — member activation report from truth.
2926
+ *
2927
+ * Accesses the Truth API at GET /reports/member-activation,
2928
+ * authenticated with X-API-Key + user JWT (verifiedUserProcedure).
2929
+ *
2930
+ * Replaces the broker pattern: frontend calls truth directly via SDK,
2931
+ * no comhub hop.
2932
+ */
2933
+
2934
+ declare const reportSchema: z.ZodObject<{
2935
+ synthetic: z.ZodBoolean;
2936
+ generatedAt: z.ZodString;
2937
+ employers: z.ZodArray<z.ZodObject<{
2938
+ id: z.ZodString;
2939
+ name: z.ZodString;
2940
+ activeMembers: z.ZodNumber;
2941
+ }, z.core.$strip>>;
2942
+ selected: z.ZodNullable<z.ZodObject<{
2943
+ employerId: z.ZodString;
2944
+ employerName: z.ZodString;
2945
+ kpis: z.ZodObject<{
2946
+ active: z.ZodNumber;
2947
+ linked: z.ZodNumber;
2948
+ activated: z.ZodNumber;
2949
+ needsOutreach: z.ZodNumber;
2950
+ scheduled: z.ZodNumber;
2951
+ needsReview: z.ZodNumber;
2952
+ dataIssue: z.ZodNumber;
2953
+ activationRate: z.ZodNumber;
2954
+ }, z.core.$strip>;
2955
+ coverage: z.ZodObject<{
2956
+ active: z.ZodNumber;
2957
+ linked: z.ZodNumber;
2958
+ unlinked: z.ZodNumber;
2959
+ pct: z.ZodNumber;
2960
+ }, z.core.$strip>;
2961
+ breakdown: z.ZodArray<z.ZodObject<{
2962
+ status: z.ZodEnum<{
2963
+ data: "data";
2964
+ activated: "activated";
2965
+ outreach: "outreach";
2966
+ scheduled: "scheduled";
2967
+ review: "review";
2968
+ }>;
2969
+ label: z.ZodString;
2970
+ count: z.ZodNumber;
2971
+ pct: z.ZodNumber;
2972
+ }, z.core.$strip>>;
2973
+ aging: z.ZodArray<z.ZodObject<{
2974
+ bucket: z.ZodString;
2975
+ total: z.ZodNumber;
2976
+ outreach: z.ZodNumber;
2977
+ scheduled: z.ZodNumber;
2978
+ review: z.ZodNumber;
2979
+ }, z.core.$strip>>;
2980
+ doctors: z.ZodArray<z.ZodObject<{
2981
+ name: z.ZodString;
2982
+ counts: z.ZodObject<{
2983
+ outreach: z.ZodNumber;
2984
+ scheduled: z.ZodNumber;
2985
+ review: z.ZodNumber;
2986
+ data: z.ZodNumber;
2987
+ }, z.core.$strip>;
2988
+ members: z.ZodArray<z.ZodObject<{
2989
+ elationId: z.ZodString;
2990
+ name: z.ZodString;
2991
+ lastName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2992
+ firstName: z.ZodOptional<z.ZodNullable<z.ZodString>>;
2993
+ doctor: z.ZodNullable<z.ZodString>;
2994
+ status: z.ZodEnum<{
2995
+ data: "data";
2996
+ activated: "activated";
2997
+ outreach: "outreach";
2998
+ scheduled: "scheduled";
2999
+ review: "review";
3000
+ }>;
3001
+ membershipStart: z.ZodString;
3002
+ daysSinceMembershipStart: z.ZodNumber;
3003
+ activationDate: z.ZodNullable<z.ZodString>;
3004
+ futureApptDate: z.ZodNullable<z.ZodString>;
3005
+ reason: z.ZodNullable<z.ZodString>;
3006
+ hasLink: z.ZodBoolean;
3007
+ }, z.core.$strip>>;
3008
+ }, z.core.$strip>>;
3009
+ }, z.core.$strip>>;
3010
+ pending: z.ZodBoolean;
3011
+ }, z.core.$strip>;
3012
+ type MemberActivationReport = z.infer<typeof reportSchema>;
3013
+ declare class ReportsResource {
3014
+ private readonly baseUrl;
3015
+ private readonly auth;
3016
+ /**
3017
+ * Captures the Truth API base URL and the auth inputs (API key + optional
3018
+ * user-token fetcher) needed to authenticate every request this resource
3019
+ * makes.
3020
+ */
3021
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
3022
+ /**
3023
+ * Fetches the member activation report from GET /reports/member-activation,
3024
+ * optionally scoped to a single employer. Requires the user JWT (not just
3025
+ * the API key) since the server hardens this route to
3026
+ * `verifiedUserProcedure` for PHI access — throws via `ReportsError` on a
3027
+ * non-OK response, including the response body (truncated) when present.
3028
+ */
3029
+ memberActivation(params?: {
3030
+ employerId?: string;
3031
+ }): Promise<MemberActivationReport>;
3032
+ }
3033
+
2234
3034
  type TaskStatus = "open" | "in_progress" | "resolved" | "cancelled";
2235
3035
  interface Task {
2236
3036
  _id: string;
@@ -2349,7 +3149,6 @@ interface TranslateBatchInput {
2349
3149
 
2350
3150
  declare class TranslationResource {
2351
3151
  private readonly baseUrl;
2352
- private readonly apiKey;
2353
3152
  private readonly auth;
2354
3153
  constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
2355
3154
  private post;
@@ -2711,6 +3510,8 @@ declare class TruthClient {
2711
3510
  readonly patientDetails: PatientDetailsResource;
2712
3511
  /** Attachments — presigned S3 upload/download + Convex metadata */
2713
3512
  readonly attachments: AttachmentsResource;
3513
+ /** Reports — member activation report (Truth API) */
3514
+ readonly reports: ReportsResource;
2714
3515
  /** Notes — push formatted notes to Elation */
2715
3516
  readonly notes: NotesResource;
2716
3517
  /** Physicians (Convex-backed cache from Elation) */
@@ -2719,6 +3520,8 @@ declare class TruthClient {
2719
3520
  readonly notifications: NotificationsResource;
2720
3521
  /** Conversation-tied writes — notes, tasks, outbound messages. */
2721
3522
  readonly conversations: ConversationsResource;
3523
+ /** Care-team email inbox — link/unlink and (gated) send via oRPC. */
3524
+ readonly careInbox: CareInboxResource;
2722
3525
  /** User settings — notification preferences (Convex-backed) */
2723
3526
  readonly userSettings: UserSettingsResource;
2724
3527
  private readonly convex;
@@ -2727,8 +3530,18 @@ declare class TruthClient {
2727
3530
  private _vapidPublicKey;
2728
3531
  private _webPushReady;
2729
3532
  private readonly _serviceWorkerPath;
3533
+ /**
3534
+ * Builds the Convex client and event tracker from `config`, then wires up
3535
+ * every resource (patients, appointments, EHR proxy, reports, etc.) so
3536
+ * each shares the same Convex connection / API base URL / auth token
3537
+ * fetcher. When running in a browser that supports web push and the
3538
+ * caller hasn't opted out, kicks off best-effort service-worker
3539
+ * registration and push subscription in the background.
3540
+ */
2730
3541
  constructor(config: TruthClientConfig);
3542
+ /** The VAPID public key fetched during web-push init, or `null` until `webPushReady` resolves (or if push is unsupported/disabled). */
2731
3543
  get vapidPublicKey(): string | null;
3544
+ /** Resolves once background web-push initialization (service worker registration + subscription) finishes; `null` if it was never started (SSR, unsupported browser, or opted out via config). */
2732
3545
  get webPushReady(): Promise<void> | null;
2733
3546
  /**
2734
3547
  * When a Clerk token fetcher is configured (publishable-key clients),
@@ -2738,6 +3551,14 @@ declare class TruthClient {
2738
3551
  * → resolve immediately (secret-key path is unaffected).
2739
3552
  */
2740
3553
  private waitForAuthToken;
3554
+ /**
3555
+ * Best-effort web-push bootstrap: waits for auth (if configured), fetches
3556
+ * the VAPID key, registers the service worker, subscribes to push, and
3557
+ * registers the device with a placeholder `__pending__` userId (the
3558
+ * backend reconciles this once the real user is known). Any failure
3559
+ * along the way is swallowed — push notifications are opportunistic and
3560
+ * must never break client construction.
3561
+ */
2741
3562
  private initWebPush;
2742
3563
  /**
2743
3564
  * The resolved Truth API base URL for this environment.
@@ -3133,4 +3954,4 @@ interface UseVoicemailUrlResult {
3133
3954
  */
3134
3955
  declare function useVoicemailUrl(client: TruthClient): UseVoicemailUrlResult;
3135
3956
 
3136
- export { ACTIVE_CALL_STATES, API_BASE_URLS, type Appointment, type AppointmentListOptions, CONNECTED_CALL_STATES, CONVEX_URLS, type ConversationListItem, type ConversationMessage, type ConversationMessageRow, type ConversationNoteRow, type ConversationRow, type ConversationTaskForUserRow, type ConversationTaskRow, type DialpadCallLogRow, type DialpadCallRow, DialpadCallState, type EventPayloadMap, type EventType, type FamilyMemberRow, NoopStore, type OfflineStore, type Patient, type PatientListOptions, type PatientSearchResult, type PermissionStatus, type Physician$1 as Physician, RINGING_CALL_STATES, TERMINAL_CALL_STATES, type TrackOptions, TruthProvider, type TruthProviderProps, type TruthTrackingContextValue, TruthTrackingProvider, type TruthTrackingProviderProps, type UseActiveCallsOptions, type UseAppointmentListOptions, type UseConversationMessagesOptions, type UseConversationsFilters, type UseMessagesOptions, type UseNotificationsActions, type UseNotificationsOptions, type UseNotificationsResult, type UsePatientBasicOptions, type UsePatientBasicResult, type UsePatientFamilyMembersInput, type UsePatientListOptions, type UsePatientMedicalOptions, type UsePatientPhotoOptions, type UsePatientSearchOptions, type UseQueryResult, type UseUserSyncInput, type UseUserSyncResult, getTruthClient, readPersistedSavedAt, resolveApiBaseUrl, resolveConvexUrl, useActiveCalls, useAppointment, useAppointmentByElationId, useAppointments, useConversationById, useConversationByPhonePair, useConversationMessages, useConversationNotes, useConversationNotesByPhonePair, useConversationTaskMarkSeen, useConversationTasks, useConversationTasksByPhonePair, useConversationTasksForUser, useConversations, useDialpadCallByCallId, useDialpadCallLog, useDialpadCallsForConversation, useMessages, useNotifications, useNotificationsActions, useOfflineEnabled, useOfflineStore, usePatient, usePatientBasic, usePatientByElationId, usePatientByHintId, usePatientFamilyMembers, usePatientMedical, usePatientPhoto, usePatientSearch, usePatients, usePatientsByIds, usePatientsByPhones, usePharmacyByNcpdpId, usePhysicianByElationId, usePhysiciansByElationIds, useRemindersForConversations, useTruth, useTruthClient, useTruthSdkContext, useUnreadAggregate, useUnreadCount, useUserSettings, useUserSync, useVoicemailUrl };
3957
+ export { ACTIVE_CALL_STATES, API_BASE_URLS, type Appointment, type AppointmentListOptions, CONNECTED_CALL_STATES, CONVEX_URLS, type CareInboxConvexClient, type CareInboxEmailMessage, type CareInboxEmailThreadSummary, CareInboxError, type CareInboxErrorCode, type CareInboxErrorFields, type CareInboxErrorInfo, type CareInboxErrorReason, type CareInboxLinkResult, type CareInboxMailbox, type CareInboxMailboxAccess, type CareInboxSdkSource, type CareInboxSendResult, type CareInboxSourceDeps, type CareInboxThreadDetail, type ComposeEmailInput, type ConversationListItem, type ConversationMessage, type ConversationMessageRow, type ConversationNoteRow, type ConversationRow, type ConversationTaskForUserRow, type ConversationTaskRow, type DialpadCallLogRow, type DialpadCallRow, DialpadCallState, type EmailDirection, type EmailMailbox, type EmailMailboxAccessView, type EmailMailboxView, type EmailMessage, type EmailMessageView, type EmailParticipant, type EmailParticipantView, type EmailThreadBodiesView, type EmailThreadDetail, type EmailThreadDetailView, type EmailThreadListFilter, type EmailThreadPageView, type EmailThreadSummary, type EmailThreadSummaryView, type EventPayloadMap, type EventType, type FamilyMemberRow, type LinkEmailMessageInput, type LinkMessageArgs, type LinkResult, type LinkedPatientContact, type ListThreadsArgs, type MailboxAccess, type MarkEmailThreadReadResult, type MarkReadArgs, type MarkReadResult, NoopStore, type OfflineStore, type Patient, type PatientLinkCandidate, type PatientLinkCandidateView, type PatientListOptions, type PatientSearchResult, type PermissionStatus, type Physician$1 as Physician, RINGING_CALL_STATES, type ReplyToEmailThreadInput, type SendEmailArgs, type SendReplyArgs, type SendResult, TERMINAL_CALL_STATES, type TaskEventRow, type ThreadListFilter, type ThreadPage, type TrackOptions, TruthProvider, type TruthProviderProps, type TruthTrackingContextValue, TruthTrackingProvider, type TruthTrackingProviderProps, type UnlinkEmailMessageInput, type UnlinkMessageArgs, type UnlinkedEmailPageView, type UnlinkedMessagePage, type UrgentConversationListItem, type UseActiveCallsOptions, type UseAppointmentListOptions, type UseConversationMessagesOptions, type UseConversationsFilters, type UseEmailThreadsOptions, type UseMessagesOptions, type UseNotificationsActions, type UseNotificationsOptions, type UseNotificationsResult, type UsePaginatedEmailThreadsOptions, type UsePaginatedEmailThreadsResult, type UsePatientBasicOptions, type UsePatientBasicResult, type UsePatientFamilyMembersInput, type UsePatientListOptions, type UsePatientMedicalOptions, type UsePatientPhotoOptions, type UsePatientSearchOptions, type UseQueryResult, type UseSearchPatientsForLinkOptions, type UseUnlinkedEmailsOptions, type UseUserSyncInput, type UseUserSyncResult, careInboxErrorInfo, careInboxRefs, createCareInboxSource, getTruthClient, isCareInboxError, readPersistedSavedAt, resolveApiBaseUrl, resolveConvexUrl, toCareInboxError, toEmailMailbox, toEmailMessage, toEmailThreadDetail, toEmailThreadSummary, toMailboxAccess, toMarkReadResult, toThreadPage, toUnlinkedMessagePage, useActiveCalls, useAppointment, useAppointmentByElationId, useAppointments, useCareInboxSource, useConversationById, useConversationByPhonePair, useConversationMessages, useConversationNotes, useConversationNotesByPhonePair, useConversationTaskHistory, useConversationTaskMarkSeen, useConversationTasks, useConversationTasksByPhonePair, useConversationTasksForUser, useConversations, useDialpadCallByCallId, useDialpadCallLog, useDialpadCallsForConversation, useEmailThread, useEmailThreads, useEmailUnreadCount, useLinkEmailMessage, useMailboxes, useMarkEmailThreadRead, useMessages, useNotifications, useNotificationsActions, useOfflineEnabled, useOfflineStore, useOpenEmailThreadBodies, usePaginatedEmailThreads, usePatient, usePatientBasic, usePatientByElationId, usePatientByHintId, usePatientFamilyMembers, usePatientMedical, usePatientPhoto, usePatientSearch, usePatients, usePatientsByIds, usePatientsByPhones, usePharmacyByNcpdpId, usePhysicianByElationId, usePhysiciansByElationIds, useRemindersForConversations, useSaveCallSummary, useSearchPatientsForLink, useTaskHistory, useTruth, useTruthClient, useTruthSdkContext, useUnlinkEmailMessage, useUnlinkedEmails, useUnreadAggregate, useUnreadCount, useUrgentConversations, useUserSettings, useUserSync, useVoicemailUrl };