@hipnation-truth/sdk 0.29.0 → 0.30.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/index.d.mts +46 -1
- package/dist/index.d.ts +46 -1
- package/dist/index.js +55 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +55 -1
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.ts +45 -0
- package/dist/react.js +55 -1
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/auth-convex-client.ts","../src/resources/appointments.ts","../src/resources/rest-auth.ts","../src/resources/attachments.ts","../src/resources/care-inbox.ts","../src/resources/conversations.ts","../src/resources/dialpad.ts","../src/resources/ehr.ts","../src/resources/notes.ts","../src/resources/notifications.ts","../src/resources/patient-details.ts","../src/react/elation-id.ts","../src/resources/patients.ts","../src/resources/physicians.ts","../src/resources/reminders.ts","../src/resources/reports.ts","../src/resources/tasks.ts","../src/resources/translation.ts","../src/resources/user-settings.ts","../src/tracking/tracker.ts","../src/web-push.ts","../src/client.ts","../src/resources/care-inbox-source.ts","../src/tracking/events.ts","../src/types/config.ts"],"sourcesContent":["/**\n * AuthAwareConvexHttpClient — ConvexHttpClient that refreshes the\n * caller's identity token before every call.\n *\n * `ConvexHttpClient.setAuth()` takes a static JWT, but Clerk's \"convex\"\n * template tokens are short-lived (60s). This subclass asks the\n * injected {@link AuthTokenFetcher} for a current token immediately\n * before each query/mutation/action — identity-provider SDKs (Clerk)\n * cache tokens internally and refresh on expiry, so this is cheap.\n *\n * With no fetcher configured it behaves exactly like the base client.\n */\nimport { ConvexHttpClient, type HttpMutationOptions } from \"convex/browser\";\nimport type {\n ArgsAndOptions,\n FunctionReference,\n FunctionReturnType,\n OptionalRestArgs,\n} from \"convex/server\";\nimport type { AuthTokenFetcher } from \"./types/config\";\n\nexport class AuthAwareConvexHttpClient extends ConvexHttpClient {\n private readonly getAuthToken?: AuthTokenFetcher;\n\n constructor(address: string, getAuthToken?: AuthTokenFetcher) {\n super(address);\n this.getAuthToken = getAuthToken;\n }\n\n /**\n * Pull a fresh token from the fetcher and apply it. A fetcher error\n * keeps the previously-applied token rather than dropping auth\n * mid-session.\n */\n private async syncAuth(): Promise<void> {\n if (!this.getAuthToken) {\n return;\n }\n try {\n const token = await this.getAuthToken();\n if (token) {\n this.setAuth(token);\n } else {\n this.clearAuth();\n }\n } catch {\n /* keep last known token */\n }\n }\n\n override async query<Query extends FunctionReference<\"query\">>(\n query: Query,\n ...args: OptionalRestArgs<Query>\n ): Promise<FunctionReturnType<Query>> {\n await this.syncAuth();\n return super.query(query, ...args);\n }\n\n override async mutation<Mutation extends FunctionReference<\"mutation\">>(\n mutation: Mutation,\n ...args: ArgsAndOptions<Mutation, HttpMutationOptions>\n ): Promise<FunctionReturnType<Mutation>> {\n await this.syncAuth();\n return super.mutation(mutation, ...args);\n }\n\n override async action<Action extends FunctionReference<\"action\">>(\n action: Action,\n ...args: OptionalRestArgs<Action>\n ): Promise<FunctionReturnType<Action>> {\n await this.syncAuth();\n return super.action(action, ...args);\n }\n}\n","/**\n * AppointmentResource provides data access to normalized appointment records\n * backed by Convex.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport type { Appointment, AppointmentListOptions } from \"../types/appointment\";\nimport type { PaginatedResult } from \"../types/config\";\n\nclass AppointmentResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convexClient: ConvexHttpClient) {\n this.convex = convexClient;\n }\n\n /**\n * Get an appointment by its Truth platform ID.\n */\n async get(id: string): Promise<Appointment | null> {\n try {\n const result = await this.convex.query(\n \"appointments:getById\" as never,\n { id } as never,\n );\n return (result as Appointment) ?? null;\n } catch {\n return null;\n }\n }\n\n /**\n * List appointments with optional filters, pagination, and limit.\n */\n async list(\n options?: AppointmentListOptions,\n ): Promise<PaginatedResult<Appointment>> {\n try {\n const result = await this.convex.query(\n \"appointments:list\" as never,\n {\n patientId: options?.patientId,\n startDate: options?.startDate,\n endDate: options?.endDate,\n status: options?.status,\n limit: options?.limit,\n cursor: options?.cursor,\n } as never,\n );\n\n const typed = result as PaginatedResult<Appointment> | undefined;\n\n return typed ?? { data: [], cursor: null, hasMore: false };\n } catch {\n return { data: [], cursor: null, hasMore: false };\n }\n }\n}\n\nexport { AppointmentResource };\n","/**\n * Shared auth-header builder for the HTTP-backed SDK resources.\n *\n * Every Truth REST/RPC call carries `X-API-Key`. When the host app wired\n * a `getAuthToken` (Clerk JWT fetcher), the caller's bearer token rides\n * alongside it — required once the application uses a publishable key\n * (`hn_pk_*`), which the API gate accepts only with a verified user JWT.\n */\nimport type { AuthTokenFetcher } from \"../types/config\";\n\nexport interface RestAuth {\n apiKey: string;\n getAuthToken?: AuthTokenFetcher;\n}\n\nexport interface BuildAuthHeadersOptions {\n json?: boolean;\n accept?: boolean;\n /**\n * When set, the route is JWT-gated (e.g. a `verifiedUserProcedure` like\n * the conversations send path). Silently degrading to key-only would 401\n * at the server and surface as a confusing \"error\" status in the UI, so\n * we instead retry token resolution with a short bounded backoff and\n * throw a clear auth error if no token can be obtained.\n */\n requireUserToken?: boolean;\n}\n\n/**\n * How many times `buildAuthHeaders` re-attempts token resolution when\n * `requireUserToken` is set and the first attempt yields null. The token\n * fetcher is transiently null on cold web loads, so a few short retries\n * cover the Clerk hydration gap without stalling the request.\n */\nconst REQUIRE_TOKEN_MAX_ATTEMPTS = 4;\n/** Base delay between token-resolution retries; grows linearly per attempt. */\nconst REQUIRE_TOKEN_RETRY_DELAY_MS = 150;\n\nfunction delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Custom header carrying the user's `Bearer <jwt>`, mirrored alongside the\n * standard `Authorization` header.\n *\n * The Truth API is fronted by CloudFront with an OAC that SigV4-signs every\n * origin request to the IAM-protected Lambda function URL — that signing\n * OVERWRITES the viewer's `Authorization` header, so a `Bearer <jwt>` sent\n * there never reaches the handler (the server then sees no user token and a\n * `verifiedUserProcedure` like the SMS-send path 401s). A custom header is\n * forwarded untouched (same reason `X-API-Key` works), so we carry the JWT\n * here too; the API gate reads this first and falls back to `Authorization`.\n */\nconst USER_TOKEN_HEADER = \"X-Truth-Authorization\";\n\n/** Attach the user JWT to both the standard and CloudFront-safe headers. */\nfunction setUserToken(headers: Record<string, string>, token: string): void {\n headers.Authorization = `Bearer ${token}`;\n headers[USER_TOKEN_HEADER] = `Bearer ${token}`;\n}\n\n/**\n * Resolve the user JWT, swallowing fetcher errors as null. Used by both the\n * best-effort and required token paths.\n */\nasync function resolveAuthToken(\n getAuthToken: AuthTokenFetcher,\n): Promise<string | null> {\n try {\n const token = await getAuthToken();\n return token ?? null;\n } catch {\n return null;\n }\n}\n\n/**\n * Build request headers: `X-API-Key` always, `Authorization: Bearer\n * <jwt>` when a token is available, and `Content-Type: application/json`\n * when `json` is set.\n *\n * For best-effort routes a token-fetcher error (or null token) degrades to\n * key-only rather than failing the request. For `requireUserToken` routes\n * a null token is retried with a bounded backoff and, if still null, throws\n * so the caller surfaces a real auth error instead of a silent server 401.\n */\nexport async function buildAuthHeaders(\n auth: RestAuth,\n options?: BuildAuthHeadersOptions,\n): Promise<Record<string, string>> {\n const headers: Record<string, string> = {\n \"X-API-Key\": auth.apiKey,\n };\n if (options?.accept !== false) {\n headers.Accept = \"application/json\";\n }\n if (options?.json) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n\n if (options?.requireUserToken) {\n if (!auth.getAuthToken) {\n throw new Error(\n \"User authentication required to send a message, but no auth token provider is configured\",\n );\n }\n for (let attempt = 0; attempt < REQUIRE_TOKEN_MAX_ATTEMPTS; attempt++) {\n const token = await resolveAuthToken(auth.getAuthToken);\n if (token) {\n setUserToken(headers, token);\n return headers;\n }\n if (attempt < REQUIRE_TOKEN_MAX_ATTEMPTS - 1) {\n await delay(REQUIRE_TOKEN_RETRY_DELAY_MS * (attempt + 1));\n }\n }\n throw new Error(\n \"User authentication required to send a message — no auth token available\",\n );\n }\n\n if (auth.getAuthToken) {\n const token = await resolveAuthToken(auth.getAuthToken);\n if (token) {\n setUserToken(headers, token);\n }\n }\n return headers;\n}\n","/**\n * AttachmentsResource — presigned S3 upload/download + Convex metadata.\n *\n * Replaces CommHub's base64-in-Postgres attachment flow:\n * 1. client.attachments.createUploadUrl(...) → presigned PUT URL\n * 2. Client PUTs bytes directly to S3\n * 3. client.attachments.record(...) → writes Convex metadata\n * 4. client.attachments.getDownloadUrl(s3Key) → presigned GET URL\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\nexport interface CreateUploadUrlInput {\n fileName: string;\n mimeType: string;\n size: number;\n conversationId?: string;\n}\n\nexport interface CreateUploadUrlResult {\n uploadUrl: string;\n s3Key: string;\n expiresIn: number;\n applicationId: string | null;\n}\n\nexport interface GetDownloadUrlResult {\n url: string;\n expiresIn: number;\n}\n\nexport interface RecordAttachmentInput {\n s3Key: string;\n fileName: string;\n mimeType: string;\n size: number;\n conversationId?: string;\n uploadedBy: string;\n}\n\nexport interface Attachment {\n _id: string;\n s3Key: string;\n fileName: string;\n mimeType: string;\n size: number;\n conversationId?: string;\n uploadedBy: string;\n createdAt: string;\n}\n\nclass AttachmentsError extends Error {\n readonly status: number;\n\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Attachment ${operation} failed (HTTP ${status})`);\n this.name = \"AttachmentsError\";\n this.status = status;\n }\n}\n\nclass AttachmentsResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n private readonly convex: ConvexHttpClient;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n convexClient: ConvexHttpClient,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n this.convex = convexClient;\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n // PHI (patient photos / MMS media) — REQUIRE the user JWT. The server\n // hardens these routes to `verifiedUserProcedure`, so degrading to\n // key-only would 401. `requireUserToken` retries across the Clerk-\n // hydration gap and throws rather than silently sending key-only.\n headers: await buildAuthHeaders(this.auth, {\n json: true,\n requireUserToken: true,\n }),\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new AttachmentsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n async createUploadUrl(\n input: CreateUploadUrlInput,\n ): Promise<CreateUploadUrlResult> {\n return await this.post<CreateUploadUrlResult>(\n \"/attachments/upload-url\",\n input,\n );\n }\n\n async getDownloadUrl(\n s3Key: string,\n expiresIn?: number,\n ): Promise<GetDownloadUrlResult> {\n return await this.post<GetDownloadUrlResult>(\"/attachments/download-url\", {\n s3Key,\n expiresIn,\n });\n }\n\n async record(\n input: RecordAttachmentInput,\n ): Promise<{ attachmentId: string; s3Key: string }> {\n return (await this.convex.mutation(\n \"attachments:record\" as never,\n input as never,\n )) as { attachmentId: string; s3Key: string };\n }\n\n async get(attachmentId: string): Promise<Attachment | null> {\n try {\n const row = (await this.convex.query(\n \"attachments:getById\" as never,\n { attachmentId } as never,\n )) as Attachment | null;\n return row ?? null;\n } catch {\n return null;\n }\n }\n\n async listByConversation(conversationId: string): Promise<Attachment[]> {\n try {\n const rows = (await this.convex.query(\n \"attachments:listByConversation\" as never,\n { conversationId } as never,\n )) as Attachment[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n\n /**\n * One-shot upload: presign → PUT to S3 → record in Convex → return a\n * 7-day signed download URL ready to embed in an outbound SMS. Caller\n * passes the resulting `downloadUrl` to `messages.dialpad.sendSms` (or\n * the new `messages.sendAttachmentMessage`) to actually deliver it.\n *\n * Replaces CommHub's NestJS `/send-attachment` controller in a single\n * SDK call — no base64 round-trip, no legacy `/attachments/:id/download`\n * REST endpoint required.\n */\n async upload(input: {\n file: Blob | ArrayBuffer | Uint8Array;\n fileName: string;\n mimeType: string;\n size: number;\n conversationId?: string;\n uploadedBy: string;\n /** Download URL TTL in seconds. Default 7 days. */\n downloadExpiresIn?: number;\n }): Promise<{\n attachmentId: string;\n s3Key: string;\n downloadUrl: string;\n }> {\n const presigned = await this.createUploadUrl({\n fileName: input.fileName,\n mimeType: input.mimeType,\n size: input.size,\n conversationId: input.conversationId,\n });\n\n // Cast through `BodyInit` — Uint8Array is accepted by undici/fetch\n // at runtime but the lib.dom types only declare BufferSource so TS\n // doesn't see the overload. Same trick the AttachmentsResource\n // already uses elsewhere.\n const body: BodyInit =\n input.file instanceof Blob\n ? input.file\n : input.file instanceof Uint8Array\n ? (input.file as unknown as BodyInit)\n : (new Uint8Array(input.file) as unknown as BodyInit);\n\n // 30s timeout matches the legacy NestJS handler so a stuck S3 PUT\n // can't hang the calling UI thread indefinitely.\n const abort = new AbortController();\n const timer = setTimeout(() => abort.abort(), 30_000);\n let putRes: Response;\n try {\n putRes = await fetch(presigned.uploadUrl, {\n method: \"PUT\",\n headers: { \"Content-Type\": input.mimeType },\n body,\n signal: abort.signal,\n });\n } catch (err) {\n // AbortController fires DOMException(\"AbortError\"); rewrap as a\n // typed AttachmentsError(0, …) so callers' `instanceof\n // AttachmentsError` checks catch the timeout consistently with\n // every other failure mode here.\n const isAbort =\n err instanceof Error &&\n (err.name === \"AbortError\" || err.name === \"TimeoutError\");\n if (isAbort) {\n throw new AttachmentsError(\n \"s3-put\",\n 0,\n \"S3 upload timed out after 30s\",\n );\n }\n throw err;\n } finally {\n clearTimeout(timer);\n }\n if (!putRes.ok) {\n throw new AttachmentsError(\n \"s3-put\",\n putRes.status,\n `S3 PUT ${putRes.status} for ${presigned.s3Key}`,\n );\n }\n\n const recorded = await this.record({\n s3Key: presigned.s3Key,\n fileName: input.fileName,\n mimeType: input.mimeType,\n size: input.size,\n conversationId: input.conversationId,\n uploadedBy: input.uploadedBy,\n });\n\n const signed = await this.getDownloadUrl(\n presigned.s3Key,\n input.downloadExpiresIn ?? 7 * 24 * 3600,\n );\n\n return {\n attachmentId: recorded.attachmentId,\n s3Key: presigned.s3Key,\n downloadUrl: signed.url,\n };\n }\n}\n\nexport { AttachmentsResource, AttachmentsError };\n","/**\n * CareInboxResource — care-team shared-mailbox email (T12).\n *\n * Writes go through the Truth oRPC `careInbox` router (all\n * `verifiedUserProcedure`, so every call REQUIRES the user JWT):\n * - `linkMessage` POST /api/care-inbox/link\n * - `unlinkMessage` POST /api/care-inbox/unlink\n * - `replyToThread` POST /api/care-inbox/outbound/thread-reply\n * - `composeEmail` POST /api/care-inbox/outbound/compose\n * Reads are Convex queries; use the hooks in `@hipnation-truth/sdk/react`\n * (`useEmailThreads`, …) or `createCareInboxSource`. Nothing here is\n * persisted offline.\n *\n * Two type layers:\n * - `*View` types are the raw Convex query payloads (nullable where the\n * stored row can lack a value).\n * - The contract types (`EmailMessage`, `EmailThreadSummary`, `ThreadPage`,\n * …) mirror comhub's `lib/email/careInboxSource.ts` exactly. `to*`\n * projections turn views into contract shapes: a missing string becomes\n * \"\" and a missing participant `{ address: \"\", name: null }` because the\n * contract declares those fields non-null.\n *\n * Errors: every rejection is a `CareInboxError` whose `code` is the comhub\n * `CareInboxErrorCode`, so it satisfies comhub's `Error & { code }` contract\n * as-is. `status` (0 = no HTTP response), `rpcCode` (oRPC / transport code),\n * `reason` and `detail` carry the server detail. `toCareInboxError()` maps\n * anything thrown — including a Convex `ConvexError` from a hook — onto it.\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\n// ---------------------------------------------------------------------------\n// Contract types (comhub lib/email/careInboxSource.ts; times epoch ms)\n// ---------------------------------------------------------------------------\n\nexport type EmailDirection = \"inbound\" | \"outbound\";\n\n/**\n * Thread-list filter. \"unlinked\" is served only to triage callers (threads\n * with at least one unlinked message); others get forbidden/not_triage.\n */\nexport type ThreadListFilter = \"all\" | \"unread\" | \"unlinked\";\n\nexport interface EmailMailbox {\n id: string;\n /** Shared mailbox address. \"\" for non-triage callers (server-redacted). */\n address: string;\n displayName: string;\n}\n\nexport interface MailboxAccess {\n mailboxes: EmailMailbox[];\n /** May see Unlinked and link/unlink (admin-only until G-TRIAGE). */\n canTriage: boolean;\n}\n\nexport interface EmailParticipant {\n address: string;\n name: string | null;\n}\n\nexport interface EmailMessage {\n id: string;\n threadId: string;\n mailboxId: string;\n direction: EmailDirection;\n from: EmailParticipant;\n to: EmailParticipant[];\n subject: string;\n /** Epoch milliseconds. */\n sentAt: number;\n hasAttachments: boolean;\n linkedPatientId: string | null;\n linkedPatientName: string | null;\n /** Always null in build 1 (metadata only). */\n bodyText: string | null;\n}\n\nexport interface EmailThreadSummary {\n id: string;\n mailboxId: string;\n subject: string;\n /** Epoch milliseconds of the newest message. */\n lastMessageAt: number;\n lastDirection: EmailDirection;\n counterpart: EmailParticipant;\n messageCount: number;\n unreadCount: number;\n /** Triage callers only; always 0 for staff. */\n unlinkedCount: number;\n linkedPatientName: string | null;\n hasAttachments: boolean;\n}\n\nexport interface LinkedPatientContact {\n patientId: string;\n name: string;\n email: string | null;\n phone: string | null;\n office: string | null;\n}\n\nexport interface EmailThreadDetail {\n summary: EmailThreadSummary;\n mailbox: EmailMailbox;\n /** Oldest first. */\n messages: EmailMessage[];\n /** Not provided in build 1 (always null). */\n patientContact?: LinkedPatientContact | null;\n}\n\nexport interface ListThreadsArgs {\n mailboxId?: string;\n filter?: ThreadListFilter;\n cursor?: string | null;\n /** Server default 25, max 50. */\n limit?: number;\n}\n\nexport interface ThreadPage {\n threads: EmailThreadSummary[];\n /** A mailbox-filtered page can be short; keep paging while non-null. */\n nextCursor: string | null;\n}\n\nexport interface PatientLinkCandidate {\n patientId: string;\n displayName: string;\n /** Office name when known; never an email address. */\n detail: string | null;\n}\n\nexport interface LinkMessageArgs {\n messageId: string;\n patientId: string;\n /**\n * Client idempotency key (8-128 chars of `[A-Za-z0-9_:.-]`). A key the\n * server already recorded for the message is a no-op that returns the\n * current state, so a late retry can never undo a newer unlink.\n */\n requestId: string;\n}\n\nexport interface UnlinkMessageArgs {\n messageId: string;\n /** Client idempotency key; see `LinkMessageArgs.requestId`. */\n requestId: string;\n}\n\nexport interface LinkResult {\n message: EmailMessage;\n}\n\nexport interface SendReplyArgs {\n threadId: string;\n body: string;\n clientRequestId: string;\n}\n\nexport interface SendEmailArgs {\n to: string;\n subject: string;\n body: string;\n patientId?: string;\n mailboxId: string;\n clientRequestId: string;\n}\n\n/** Send is disabled in this build (always rejects forbidden/send_disabled). */\nexport interface SendResult {\n message: EmailMessage;\n thread: EmailThreadSummary;\n}\n\nexport interface MarkReadArgs {\n threadId: string;\n}\n\nexport interface MarkReadResult {\n thread: EmailThreadSummary;\n}\n\n/** comhub `CareInboxErrorCode`. */\nexport type CareInboxErrorCode =\n | \"forbidden\"\n | \"not_found\"\n | \"offline\"\n | \"unavailable\"\n | \"validation\"\n | \"unknown\";\n\n// --- SDK extensions of the contract (extra fields only; still assignable) ---\n\n/** `EmailMailbox` plus the server-derived switches. */\nexport interface CareInboxMailbox extends EmailMailbox {\n mode: \"mirror\" | \"live\";\n /** Live mailbox AND send enabled on the deployment. */\n canSend: boolean;\n /** bodyVisibility !== \"none\" (bodies still need openThreadBodies). */\n bodyVisible: boolean;\n}\n\nexport interface CareInboxMailboxAccess extends MailboxAccess {\n mailboxes: CareInboxMailbox[];\n}\n\nexport interface CareInboxThreadDetail extends EmailThreadDetail {\n mailbox: CareInboxMailbox;\n /** Whether `openThreadBodies` would serve bodies to this caller. */\n bodyVisible: boolean;\n patientContact: null;\n}\n\n/** Triage-only unlinked message page (`listUnlinked`). */\nexport interface UnlinkedMessagePage {\n messages: EmailMessage[];\n nextCursor: string | null;\n}\n\n/** Back-compat aliases (T12 names). */\nexport type CareInboxEmailMessage = EmailMessage;\nexport type CareInboxEmailThreadSummary = EmailThreadSummary;\nexport type CareInboxLinkResult = LinkResult;\nexport type CareInboxSendResult = SendResult;\n/**\n * SDK call input: the contract args with `requestId` optional. Omit it and\n * the SDK generates one for this call; pass your own to make retries across\n * calls idempotent.\n */\nexport type LinkEmailMessageInput = Omit<LinkMessageArgs, \"requestId\"> &\n Partial<Pick<LinkMessageArgs, \"requestId\">>;\nexport type UnlinkEmailMessageInput = Omit<UnlinkMessageArgs, \"requestId\"> &\n Partial<Pick<UnlinkMessageArgs, \"requestId\">>;\nexport type ReplyToEmailThreadInput = SendReplyArgs;\nexport type ComposeEmailInput = SendEmailArgs;\n\n// ---------------------------------------------------------------------------\n// Raw view types (Convex `careInboxQueries` / `careInboxReads` payloads)\n// ---------------------------------------------------------------------------\n\nexport type EmailParticipantView = EmailParticipant;\n\n/** `careInboxQueries` message row. `bodyText` is always null from queries. */\nexport interface EmailMessageView {\n id: string;\n threadId: string | null;\n mailboxId: string;\n direction: EmailDirection;\n from: EmailParticipantView | null;\n to: EmailParticipantView[];\n subject: string | null;\n sentAt: number;\n hasAttachments: boolean;\n linkedPatientId: string | null;\n linkedPatientName: string | null;\n bodyText: null;\n}\n\nexport interface EmailThreadSummaryView {\n id: string;\n mailboxId: string;\n subject: string | null;\n lastMessageAt: number;\n lastDirection: EmailDirection | null;\n counterpart: EmailParticipantView | null;\n messageCount: number;\n unreadCount: number;\n unlinkedCount: number;\n linkedPatientId: string | null;\n linkedPatientName: string | null;\n hasAttachments: boolean;\n}\n\nexport interface EmailMailboxView {\n id: string;\n displayName: string;\n mode: \"mirror\" | \"live\";\n canSend: boolean;\n bodyVisible: boolean;\n /** Present only when the caller can triage. */\n address?: string;\n}\n\nexport interface EmailMailboxAccessView {\n mailboxes: EmailMailboxView[];\n canTriage: boolean;\n}\n\n/** Filters `listThreadsForUser` serves (\"unlinked\": triage only). */\nexport type EmailThreadListFilter = ThreadListFilter;\n\nexport interface EmailThreadPageView {\n threads: EmailThreadSummaryView[];\n nextCursor: string | null;\n}\n\nexport interface EmailThreadDetailView {\n summary: EmailThreadSummaryView;\n mailbox: EmailMailboxView;\n /** Oldest first. Staff: linked only; triage: linked + unlinked. */\n messages: EmailMessageView[];\n bodyVisible: boolean;\n patientContact: null;\n}\n\nexport interface UnlinkedEmailPageView {\n messages: EmailMessageView[];\n nextCursor: string | null;\n}\n\nexport type PatientLinkCandidateView = PatientLinkCandidate;\n\nexport interface MarkEmailThreadReadResult {\n thread: EmailThreadSummaryView;\n}\n\nexport interface EmailThreadBodiesView {\n messages: { id: string; bodyText: string | null }[];\n}\n\n// ---------------------------------------------------------------------------\n// Projections (view → contract)\n// ---------------------------------------------------------------------------\n\nconst NO_PARTICIPANT: EmailParticipant = { address: \"\", name: null };\n\nfunction participant(p: EmailParticipantView | null): EmailParticipant {\n return p ? { address: p.address, name: p.name } : { ...NO_PARTICIPANT };\n}\n\nfunction toEmailMessage(m: EmailMessageView): EmailMessage {\n return {\n id: m.id,\n threadId: m.threadId ?? \"\",\n mailboxId: m.mailboxId,\n direction: m.direction,\n from: participant(m.from),\n to: m.to.map(participant),\n subject: m.subject ?? \"\",\n sentAt: m.sentAt,\n hasAttachments: m.hasAttachments,\n linkedPatientId: m.linkedPatientId,\n linkedPatientName: m.linkedPatientName,\n bodyText: m.bodyText,\n };\n}\n\n/**\n * `lastDirection` is null only for a thread with no visible message (it\n * cannot happen for a summary the server lists; kept defensive). Projects to\n * \"inbound\".\n */\nfunction toEmailThreadSummary(t: EmailThreadSummaryView): EmailThreadSummary {\n return {\n id: t.id,\n mailboxId: t.mailboxId,\n subject: t.subject ?? \"\",\n lastMessageAt: t.lastMessageAt,\n lastDirection: t.lastDirection ?? \"inbound\",\n counterpart: participant(t.counterpart),\n messageCount: t.messageCount,\n unreadCount: t.unreadCount,\n unlinkedCount: t.unlinkedCount,\n linkedPatientName: t.linkedPatientName,\n hasAttachments: t.hasAttachments,\n };\n}\n\nfunction toEmailMailbox(m: EmailMailboxView): CareInboxMailbox {\n return {\n id: m.id,\n address: m.address ?? \"\",\n displayName: m.displayName,\n mode: m.mode,\n canSend: m.canSend,\n bodyVisible: m.bodyVisible,\n };\n}\n\nfunction toMailboxAccess(a: EmailMailboxAccessView): CareInboxMailboxAccess {\n return { mailboxes: a.mailboxes.map(toEmailMailbox), canTriage: a.canTriage };\n}\n\nfunction toEmailThreadDetail(d: EmailThreadDetailView): CareInboxThreadDetail {\n return {\n summary: toEmailThreadSummary(d.summary),\n mailbox: toEmailMailbox(d.mailbox),\n messages: d.messages.map(toEmailMessage),\n bodyVisible: d.bodyVisible,\n patientContact: null,\n };\n}\n\nfunction toThreadPage(p: EmailThreadPageView): ThreadPage {\n return {\n threads: p.threads.map(toEmailThreadSummary),\n nextCursor: p.nextCursor,\n };\n}\n\nfunction toUnlinkedMessagePage(p: UnlinkedEmailPageView): UnlinkedMessagePage {\n return {\n messages: p.messages.map(toEmailMessage),\n nextCursor: p.nextCursor,\n };\n}\n\nfunction toMarkReadResult(r: MarkEmailThreadReadResult): MarkReadResult {\n return { thread: toEmailThreadSummary(r.thread) };\n}\n\n// ---------------------------------------------------------------------------\n// Errors\n// ---------------------------------------------------------------------------\n\n/**\n * Machine-readable sub-code. Server-sent: `send_disabled` | `not_triage` |\n * `body_gated` | `unauthenticated` (Convex: no identity). SDK-derived:\n * `unauthenticated` (no user JWT, or HTTP 401). The contract has no auth\n * code, so `unauthenticated` surfaces as `forbidden` on every path.\n */\nexport type CareInboxErrorReason =\n | \"send_disabled\"\n | \"not_triage\"\n | \"body_gated\"\n | \"unauthenticated\";\n\nconst REASONS: readonly CareInboxErrorReason[] = [\n \"send_disabled\",\n \"not_triage\",\n \"body_gated\",\n \"unauthenticated\",\n];\n\nconst CODES: readonly CareInboxErrorCode[] = [\n \"forbidden\",\n \"not_found\",\n \"offline\",\n \"unavailable\",\n \"validation\",\n \"unknown\",\n];\n\nfunction asReason(value: unknown): CareInboxErrorReason | null {\n return REASONS.includes(value as CareInboxErrorReason)\n ? (value as CareInboxErrorReason)\n : null;\n}\n\nfunction asCode(value: unknown): CareInboxErrorCode | null {\n return CODES.includes(value as CareInboxErrorCode)\n ? (value as CareInboxErrorCode)\n : null;\n}\n\nexport interface CareInboxErrorFields {\n /** HTTP status; 0 when there was no HTTP response (incl. Convex errors). */\n status?: number;\n /**\n * oRPC code (`FORBIDDEN`, `NOT_FOUND`, …) or, for status 0, `TRANSPORT`\n * (fetch threw), `TIMEOUT`, `NO_API_KEY`, `NO_USER_TOKEN`.\n */\n rpcCode?: string | null;\n reason?: CareInboxErrorReason | null;\n /** Fixed server marker (e.g. `PATIENT_HAS_NO_OFFICE`), when present. */\n detail?: string | null;\n}\n\n/**\n * The single care-inbox error. `code` is the comhub `CareInboxErrorCode`, so\n * an instance satisfies comhub's `CareInboxError` (`Error & { code }`). The\n * message never carries content, addresses or ids.\n */\nclass CareInboxError extends Error {\n readonly code: CareInboxErrorCode;\n readonly status: number;\n readonly rpcCode: string | null;\n readonly reason: CareInboxErrorReason | null;\n readonly detail: string | null;\n\n constructor(code: CareInboxErrorCode, fields: CareInboxErrorFields = {}) {\n const reason = fields.reason ?? null;\n const status = fields.status ?? 0;\n super(\n `Care inbox request failed: ${code}${reason ? ` (${reason})` : \"\"}${status ? ` HTTP ${status}` : \"\"}`,\n );\n this.name = \"CareInboxError\";\n this.code = code;\n this.status = status;\n this.rpcCode = fields.rpcCode ?? null;\n this.reason = reason;\n this.detail = fields.detail ?? null;\n }\n}\n\nfunction codeForStatus(status: number, rpcCode: string | null) {\n if (status === 0) {\n if (rpcCode === \"TRANSPORT\" || rpcCode === \"TIMEOUT\") {\n return \"offline\";\n }\n if (rpcCode === \"NO_USER_TOKEN\") {\n return \"forbidden\";\n }\n return \"unknown\";\n }\n if (status === 400) {\n return \"validation\";\n }\n if (status === 401 || status === 403) {\n return \"forbidden\";\n }\n if (status === 404) {\n return \"not_found\";\n }\n if (status === 503) {\n return \"unavailable\";\n }\n return \"unknown\";\n}\n\nfunction httpError(fields: Required<CareInboxErrorFields>): CareInboxError {\n const unauthenticated =\n fields.status === 401 || fields.rpcCode === \"NO_USER_TOKEN\";\n return new CareInboxError(codeForStatus(fields.status, fields.rpcCode), {\n ...fields,\n reason: fields.reason ?? (unauthenticated ? \"unauthenticated\" : null),\n });\n}\n\n/** True for any value carrying a contract `code` (comhub `isCareInboxError`). */\nfunction isCareInboxError(\n value: unknown,\n): value is Error & { code: CareInboxErrorCode } {\n return (\n value instanceof Error &&\n asCode((value as { code?: unknown }).code) !== null\n );\n}\n\n/**\n * Coerce anything thrown by the resource, a care-inbox Convex function\n * (`ConvexError({ code, reason? })`, payload on `.data`) or a comhub-style\n * error into a `CareInboxError`. Never throws; unrecognised → `unknown`.\n */\nfunction toCareInboxError(value: unknown): CareInboxError {\n if (value instanceof CareInboxError) {\n return value;\n }\n const data =\n value && typeof value === \"object\"\n ? (value as { data?: unknown }).data\n : undefined;\n if (data && typeof data === \"object\") {\n const { code, reason } = data as { code?: unknown; reason?: unknown };\n const known = asCode(code);\n if (known) {\n return new CareInboxError(known, { reason: asReason(reason) });\n }\n }\n if (isCareInboxError(value)) {\n // Duck-typed: e.g. a CareInboxError from another copy of the SDK, where\n // instanceof fails. Keep every typed field, not just code/reason.\n const v = value as {\n status?: unknown;\n rpcCode?: unknown;\n reason?: unknown;\n detail?: unknown;\n };\n return new CareInboxError(value.code, {\n status:\n typeof v.status === \"number\" &&\n Number.isInteger(v.status) &&\n v.status >= 0\n ? v.status\n : 0,\n rpcCode: typeof v.rpcCode === \"string\" ? v.rpcCode : null,\n reason: asReason(v.reason),\n detail: typeof v.detail === \"string\" ? v.detail : null,\n });\n }\n return new CareInboxError(\"unknown\");\n}\n\nexport interface CareInboxErrorInfo {\n code: CareInboxErrorCode;\n reason: CareInboxErrorReason | null;\n}\n\n/** `{ code, reason }` of anything thrown (see `toCareInboxError`). */\nfunction careInboxErrorInfo(err: unknown): CareInboxErrorInfo {\n const e = toCareInboxError(err);\n return { code: e.code, reason: e.reason };\n}\n\n// ---------------------------------------------------------------------------\n// Resource\n// ---------------------------------------------------------------------------\n\n/**\n * A fresh link/unlink idempotency key (a v4 UUID). Generated once per call:\n * the request body is built once, so anything that re-sends that body reuses\n * the key.\n */\nfunction newRequestId(): string {\n const c = globalThis.crypto;\n if (c && typeof c.randomUUID === \"function\") {\n return c.randomUUID();\n }\n const bytes = new Uint8Array(16);\n if (c && typeof c.getRandomValues === \"function\") {\n c.getRandomValues(bytes);\n } else {\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Math.floor(Math.random() * 256);\n }\n }\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\n \"\",\n );\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\nclass CareInboxResource {\n /** 30s upstream timeout — matches ConversationsResource. */\n private static readonly REQUEST_TIMEOUT_MS = 30_000;\n\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n /** Link one message to a patient (triage only). */\n async linkMessage(input: LinkEmailMessageInput): Promise<LinkResult> {\n return this.post<LinkResult>(\"/care-inbox/link\", {\n messageId: input.messageId,\n patientId: input.patientId,\n requestId: input.requestId ?? newRequestId(),\n });\n }\n\n /** Undo a manual link (triage only). */\n async unlinkMessage(input: UnlinkEmailMessageInput): Promise<LinkResult> {\n return this.post<LinkResult>(\"/care-inbox/unlink\", {\n messageId: input.messageId,\n requestId: input.requestId ?? newRequestId(),\n });\n }\n\n /** Reply into a thread. This build always rejects 403 `send_disabled`. */\n async replyToThread(input: SendReplyArgs): Promise<SendResult> {\n return this.post<SendResult>(\"/care-inbox/outbound/thread-reply\", {\n threadId: input.threadId,\n body: input.body,\n clientRequestId: input.clientRequestId,\n });\n }\n\n /** Start a new email. This build always rejects 403 `send_disabled`. */\n async composeEmail(input: SendEmailArgs): Promise<SendResult> {\n return this.post<SendResult>(\"/care-inbox/outbound/compose\", {\n to: input.to,\n subject: input.subject,\n body: input.body,\n ...(input.patientId !== undefined ? { patientId: input.patientId } : {}),\n mailboxId: input.mailboxId,\n clientRequestId: input.clientRequestId,\n });\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const fail = (rpcCode: string) =>\n httpError({ status: 0, rpcCode, reason: null, detail: null });\n if (!this.auth.apiKey) {\n throw fail(\"NO_API_KEY\");\n }\n let headers: Record<string, string>;\n try {\n // Every careInbox route is a verifiedUserProcedure: require the JWT.\n headers = await buildAuthHeaders(this.auth, {\n json: true,\n requireUserToken: true,\n });\n } catch {\n throw fail(\"NO_USER_TOKEN\");\n }\n\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n CareInboxResource.REQUEST_TIMEOUT_MS,\n );\n let res: Response;\n try {\n res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n headers,\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n const isAbort =\n err instanceof Error &&\n (err.name === \"AbortError\" || err.name === \"TimeoutError\");\n throw fail(isAbort ? \"TIMEOUT\" : \"TRANSPORT\");\n } finally {\n clearTimeout(timeout);\n }\n\n if (!res.ok) {\n // oRPC error body: { code, status, message, data?: { reason } }.\n let parsed: { code?: unknown; message?: unknown; data?: unknown } = {};\n try {\n parsed = (await res.json()) as typeof parsed;\n } catch {\n // Non-JSON body (gateway error): status alone is the signal.\n }\n const data =\n parsed.data && typeof parsed.data === \"object\"\n ? (parsed.data as { reason?: unknown })\n : {};\n throw httpError({\n status: res.status,\n rpcCode: typeof parsed.code === \"string\" ? parsed.code : null,\n reason: asReason(data.reason),\n detail:\n typeof parsed.message === \"string\"\n ? parsed.message.slice(0, 200)\n : null,\n });\n }\n return (await res.json()) as T;\n }\n}\n\nexport {\n CareInboxError,\n CareInboxResource,\n careInboxErrorInfo,\n isCareInboxError,\n toCareInboxError,\n toEmailMailbox,\n toEmailMessage,\n toEmailThreadDetail,\n toEmailThreadSummary,\n toMailboxAccess,\n toMarkReadResult,\n toThreadPage,\n toUnlinkedMessagePage,\n};\n","/**\n * ConversationsResource — write methods that hang off a specific\n * conversation: notes, tasks, outbound messages.\n *\n * Replaces CommHub's `truthConversationApi.ts` raw-fetch wrappers so\n * the frontend goes through a typed SDK surface instead of building\n * URLs by hand.\n *\n * All methods proxy the matching oRPC procedures (`/conversations/*`)\n * via Truth's application-key auth. Errors surface as\n * `ConversationsError` with a status code so callers can distinguish\n * transport failures (status=0) from API rejections (status>=400).\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/** Address a conversation by either Convex `_id` or the phonePair. */\nexport interface ConversationAddress {\n conversationId?: string;\n phonePair?: string;\n}\n\nexport type ConversationTaskStatus = \"pending\" | \"completed\";\nexport type ConversationTaskPriority = \"high\" | \"medium\" | \"low\";\n\nexport interface CreateConversationNoteInput extends ConversationAddress {\n eventId?: string;\n author: string;\n content: string;\n status?: string;\n type?: string;\n}\n\nexport interface CreateConversationTaskInput extends ConversationAddress {\n eventId?: string;\n author: string;\n /** Optional short headline, distinct from `description`. */\n title?: string;\n description: string;\n status?: ConversationTaskStatus;\n priority?: ConversationTaskPriority;\n assignee?: string;\n type?: string;\n}\n\nexport interface SetConversationTaskStatusInput {\n taskId: string;\n status: ConversationTaskStatus;\n resolvedBy?: string;\n /**\n * Email of the user performing the action. Truth excludes the actor\n * from the task-action push fan-out (legacy parity) — omit it and the\n * actor notifies themselves.\n */\n actor?: string;\n}\n\nexport interface UpdateConversationTaskInput {\n taskId: string;\n /** Conversation the task belongs to. Truth requires this on PATCH. */\n conversationId: string;\n /** Required by the Truth task router — see `messages/procedures/tasks.ts`. */\n author: string;\n description: string;\n /** Optional patch fields — pass only the ones you want to change. */\n title?: string;\n priority?: ConversationTaskPriority;\n status?: ConversationTaskStatus;\n assignee?: string;\n type?: string;\n /**\n * Email of the user performing the action. Truth excludes the actor\n * from the task-action push fan-out (legacy parity) — omit it and the\n * actor notifies themselves.\n */\n actor?: string;\n}\n\nexport interface SetConversationTaskArchivedInput {\n taskId: string;\n archived: boolean;\n /** Email of the acting user — excluded from the archive push fan-out. */\n actor?: string;\n}\n\nexport interface SendConversationMessageInput {\n fromNumber: string;\n toNumber: string;\n message?: string;\n media?: string;\n}\n\nexport interface SendConversationMessageResult {\n id: number;\n messageStatus: string;\n direction: string;\n}\n\nexport class ConversationsError extends Error {\n readonly status: number;\n\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Conversations ${operation} failed (HTTP ${status})`);\n this.name = \"ConversationsError\";\n this.status = status;\n }\n}\n\n/**\n * Guard: a conversation must be addressed by either `conversationId` or\n * `phonePair`. Reject locally so callers get an actionable error\n * instead of an avoidable server round-trip.\n */\nfunction assertConversationAddress(\n operation: string,\n input: ConversationAddress,\n): void {\n if (!input.conversationId && !input.phonePair) {\n throw new ConversationsError(\n operation,\n 0,\n \"Either `conversationId` or `phonePair` is required\",\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Subresources\n// ---------------------------------------------------------------------------\n\nclass ConversationNotesSubresource {\n constructor(\n private readonly post: <T>(path: string, body: unknown) => Promise<T>,\n ) {}\n\n /** Create a note on a conversation (addressed by id or phonePair). */\n async create(input: CreateConversationNoteInput): Promise<{ id: string }> {\n assertConversationAddress(\"notes.create\", input);\n return this.post<{ id: string }>(\"/conversations/notes\", input);\n }\n}\n\nclass ConversationTasksSubresource {\n constructor(\n private readonly post: <T>(path: string, body: unknown) => Promise<T>,\n private readonly patch: <T>(path: string, body: unknown) => Promise<T>,\n ) {}\n\n /** Create a task on a conversation. */\n async create(input: CreateConversationTaskInput): Promise<{ id: string }> {\n assertConversationAddress(\"tasks.create\", input);\n return this.post<{ id: string }>(\"/conversations/tasks\", input);\n }\n\n /** Mark a task pending or completed. */\n async setStatus(input: SetConversationTaskStatusInput): Promise<{\n ok: true;\n }> {\n return this.post<{ ok: true }>(\n `/conversations/tasks/${encodeURIComponent(input.taskId)}/status`,\n {\n id: input.taskId,\n status: input.status,\n ...(input.resolvedBy ? { resolvedBy: input.resolvedBy } : {}),\n ...(input.actor ? { actor: input.actor } : {}),\n },\n );\n }\n\n /** Archive or un-archive a task (hides it from My Tasks without deleting). */\n async setArchived(input: SetConversationTaskArchivedInput): Promise<{\n ok: true;\n changed: boolean;\n }> {\n return this.post<{ ok: true; changed: boolean }>(\n `/conversations/tasks/${encodeURIComponent(input.taskId)}/archive`,\n {\n id: input.taskId,\n archived: input.archived,\n ...(input.actor ? { actor: input.actor } : {}),\n },\n );\n }\n\n /**\n * Update task fields (priority, assignee, description, type). Wraps\n * `PATCH /api/conversations/tasks/{id}` so CommHub doesn't have to\n * direct-fetch for non-status field edits.\n */\n async update(input: UpdateConversationTaskInput): Promise<{ ok: true }> {\n return this.patch<{ ok: true }>(\n `/conversations/tasks/${encodeURIComponent(input.taskId)}`,\n {\n id: input.taskId,\n conversationId: input.conversationId,\n author: input.author,\n description: input.description,\n ...(input.title !== undefined ? { title: input.title } : {}),\n ...(input.priority ? { priority: input.priority } : {}),\n ...(input.status ? { status: input.status } : {}),\n ...(input.assignee !== undefined ? { assignee: input.assignee } : {}),\n ...(input.type !== undefined ? { type: input.type } : {}),\n ...(input.actor ? { actor: input.actor } : {}),\n },\n );\n }\n}\n\nclass ConversationMessagesSubresource {\n constructor(\n private readonly post: <T>(\n path: string,\n body: unknown,\n options?: { requireUserToken?: boolean },\n ) => Promise<T>,\n ) {}\n\n /**\n * Send an outbound SMS / MMS via the typed `sendMessage` oRPC procedure.\n *\n * Prefer this over the generic Dialpad proxy (`messages.dialpad.sendSms`)\n * — this hits the validated Truth route and consistently surfaces\n * `ConversationsError` on failure.\n */\n async send(\n input: SendConversationMessageInput,\n ): Promise<SendConversationMessageResult> {\n if (!input.message && !input.media) {\n throw new ConversationsError(\n \"messages.send\",\n 0,\n \"send requires `message` or `media`\",\n );\n }\n // The send route is a `verifiedUserProcedure` — it always requires a\n // Clerk JWT. Force the auth-header builder to resolve (and, if needed,\n // retry) the user token rather than silently degrading to key-only,\n // which would 401 and surface as a stuck \"error\" status in the UI.\n return this.post<SendConversationMessageResult>(\n \"/conversations/messages\",\n input,\n { requireUserToken: true },\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// ConversationsResource\n// ---------------------------------------------------------------------------\n\nexport class ConversationsResource {\n readonly notes: ConversationNotesSubresource;\n readonly tasks: ConversationTasksSubresource;\n readonly messages: ConversationMessagesSubresource;\n\n /** 30s upstream timeout — matches NotesResource for consistency. */\n private static readonly REQUEST_TIMEOUT_MS = 30_000;\n\n private readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly auth: RestAuth;\n private readonly convex: import(\"convex/browser\").ConvexHttpClient | null;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n convex?: import(\"convex/browser\").ConvexHttpClient,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.apiKey = apiKey;\n this.auth = { apiKey, getAuthToken };\n this.convex = convex ?? null;\n const post = <T>(\n path: string,\n body: unknown,\n options?: { requireUserToken?: boolean },\n ) => this.postRequest<T>(path, body, options);\n const patch = <T>(path: string, body: unknown) =>\n this.patchRequest<T>(path, body);\n this.notes = new ConversationNotesSubresource(post);\n this.tasks = new ConversationTasksSubresource(post, patch);\n this.messages = new ConversationMessagesSubresource(post);\n }\n\n /**\n * Mark a conversation read for the calling user (zeroes unreadCount,\n * stamps `lastReadAt`). Calls the public Convex `markRead` mutation\n * which enforces self-tenancy on the auth identity.\n */\n async markRead(input: {\n conversationId: string;\n userId: string;\n }): Promise<{ ok: true }> {\n if (!this.convex) {\n throw new ConversationsError(\n \"/markRead\",\n 0,\n \"ConversationsResource missing Convex client\",\n );\n }\n return (await this.convex.mutation(\n \"conversations:markRead\" as never,\n input as never,\n )) as { ok: true };\n }\n\n /**\n * Mark a conversation unread for the calling user (sets unreadCount=1).\n */\n async markUnread(input: {\n conversationId: string;\n userId: string;\n }): Promise<{ updated: true }> {\n if (!this.convex) {\n throw new ConversationsError(\n \"/markUnread\",\n 0,\n \"ConversationsResource missing Convex client\",\n );\n }\n return (await this.convex.mutation(\n \"conversations:markUnread\" as never,\n input as never,\n )) as { updated: true };\n }\n\n /**\n * Mark / unmark a conversation Urgent (conversation-level, shared by\n * participants). Refused if `userId` is not a participant.\n */\n async setUrgent(input: {\n conversationId: string;\n userId: string;\n isUrgent: boolean;\n }): Promise<{ updated: true; isUrgent: boolean; changed: boolean }> {\n if (!this.convex) {\n throw new ConversationsError(\n \"/setUrgent\",\n 0,\n \"ConversationsResource missing Convex client\",\n );\n }\n return (await this.convex.mutation(\n \"conversations:setUrgent\" as never,\n input as never,\n )) as { updated: true; isUrgent: boolean; changed: boolean };\n }\n\n /**\n * Zero unread on every conversation the user has reads for, except\n * those whose `providerPhone` is in `excludedProviderPhones`.\n */\n async clearAllUnread(input: {\n userId: string;\n excludedProviderPhones?: string[];\n }): Promise<{ cleared: number }> {\n if (!this.convex) {\n throw new ConversationsError(\n \"/clearAllUnread\",\n 0,\n \"ConversationsResource missing Convex client\",\n );\n }\n return (await this.convex.mutation(\n \"conversations:clearAllUnread\" as never,\n input as never,\n )) as { cleared: number };\n }\n\n private async postRequest<T>(\n path: string,\n body: unknown,\n options?: { requireUserToken?: boolean },\n ): Promise<T> {\n if (!this.apiKey) {\n throw new ConversationsError(\n path,\n 0,\n \"Truth API key not configured — request blocked\",\n );\n }\n\n // Build headers before arming the abort timer. For `requireUserToken`\n // routes this may retry token resolution (and throw a clear auth error\n // if none is available) — surface that directly rather than letting it\n // masquerade as a generic \"request failed before response\".\n let headers: Record<string, string>;\n try {\n headers = await buildAuthHeaders(this.auth, {\n json: true,\n requireUserToken: options?.requireUserToken,\n });\n } catch (err) {\n throw new ConversationsError(\n path,\n 0,\n err instanceof Error ? err.message : \"Failed to build auth headers\",\n );\n }\n\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n ConversationsResource.REQUEST_TIMEOUT_MS,\n );\n\n let res: Response;\n try {\n res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n headers,\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n const isAbort =\n err instanceof Error &&\n (err.name === \"AbortError\" || err.name === \"TimeoutError\");\n const message = isAbort\n ? `Conversations ${path} timed out after ${ConversationsResource.REQUEST_TIMEOUT_MS}ms`\n : err instanceof Error\n ? err.message\n : \"Conversations request failed before response\";\n throw new ConversationsError(path, 0, message);\n } finally {\n clearTimeout(timeout);\n }\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ConversationsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n /**\n * PATCH variant of `postRequest`. Mirrors the timeout + API-key\n * handling so callers like `tasks.update()` don't need to roll their\n * own fetch. The Truth task router treats unknown methods as 405, so\n * a dedicated PATCH path is required.\n */\n private async patchRequest<T>(path: string, body: unknown): Promise<T> {\n if (!this.apiKey) {\n throw new ConversationsError(\n path,\n 0,\n \"Truth API key not configured — request blocked\",\n );\n }\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n ConversationsResource.REQUEST_TIMEOUT_MS,\n );\n let res: Response;\n try {\n res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"PATCH\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n const isAbort =\n err instanceof Error &&\n (err.name === \"AbortError\" || err.name === \"TimeoutError\");\n const message = isAbort\n ? `Conversations ${path} timed out after ${ConversationsResource.REQUEST_TIMEOUT_MS}ms`\n : err instanceof Error\n ? err.message\n : String(err);\n throw new ConversationsError(path, 0, message);\n } finally {\n clearTimeout(timeout);\n }\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ConversationsError(\n path,\n res.status,\n `Conversations ${path} failed: ${text.slice(0, 200)}`,\n );\n }\n return (await res.json()) as T;\n }\n}\n","/**\n * Dialpad resource — typed access to Truth's Dialpad proxy endpoints.\n *\n * @example\n * ```ts\n * const sms = await truth.messages.dialpad.sendSms({ from_number, to_number, message });\n * const call = await truth.messages.dialpad.initiateCall(userId, phoneNumber);\n * await truth.messages.dialpad.hangupCall(callId);\n * const url = await truth.messages.dialpad.authenticateVoicemail(voicemailLink);\n * ```\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\ninterface SendSmsParams {\n from_number: string;\n to_number: string;\n message?: string;\n media?: string | string[];\n}\n\ninterface SendSmsResponse {\n id: string;\n message_status: string;\n [key: string]: unknown;\n}\n\ninterface InitiateCallResponse {\n call_id: number;\n [key: string]: unknown;\n}\n\ninterface CallStatusResponse {\n state: string;\n [key: string]: unknown;\n}\n\ninterface DialpadUser {\n id: number;\n emails: string[];\n first_name?: string;\n last_name?: string;\n [key: string]: unknown;\n}\n\ninterface DialpadUserListResponse {\n items: DialpadUser[];\n}\n\ninterface DialpadNumberInfo {\n user_id?: number;\n type?: string;\n [key: string]: unknown;\n}\n\ninterface VoicemailAuthResponse {\n success: boolean;\n authenticated_url: string | null;\n error?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Dialpad Resource\n// ---------------------------------------------------------------------------\n\nclass DialpadResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n /**\n * Send an SMS or MMS message via Dialpad.\n */\n async sendSms(params: SendSmsParams): Promise<SendSmsResponse> {\n const body = {\n to_numbers: [params.to_number],\n from_number: params.from_number,\n infer_country_code: false,\n ...(params.message ? { text: params.message } : {}),\n ...(params.media ? { media: params.media } : {}),\n };\n\n return this.post<SendSmsResponse>(\"/sms\", body);\n }\n\n /**\n * Initiate an outbound call from a Dialpad user to a phone number.\n */\n async initiateCall(\n userId: number,\n phoneNumber: string,\n ): Promise<InitiateCallResponse> {\n return this.post<InitiateCallResponse>(`/users/${userId}/initiate_call`, {\n phone_number: phoneNumber,\n });\n }\n\n /**\n * Hang up an active call.\n */\n async hangupCall(callId: number): Promise<void> {\n await this.put(`/call/${callId}/actions/hangup`);\n }\n\n /**\n * Alias for `hangupCall` — mirrors the CommHub `endCall` action name so\n * the SDK swap is a direct rename.\n */\n async endCall(callId: number): Promise<void> {\n await this.hangupCall(callId);\n }\n\n /**\n * Send an MMS with a pre-uploaded attachment. Takes the S3 key returned\n * by `client.attachments.createUploadUrl(...)` + PUT, fetches a short-\n * lived download URL, and hands it to Dialpad as `media[]`.\n *\n * Replaces CommHub's `sendAttachment` Hasura Action (which stored bytes\n * as base64 in Postgres and served them through a GET endpoint).\n */\n async sendAttachmentWithUrl(params: {\n from_number: string;\n to_number: string;\n mediaUrl: string;\n message?: string;\n }): Promise<SendSmsResponse> {\n return this.sendSms({\n from_number: params.from_number,\n to_number: params.to_number,\n message: params.message,\n media: [params.mediaUrl],\n });\n }\n\n /**\n * Get the status of a call.\n */\n async getCallStatus(callId: number): Promise<CallStatusResponse | null> {\n try {\n return await this.get<CallStatusResponse>(`/call/${callId}`);\n } catch (error) {\n if (error instanceof DialpadProxyError && error.status === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Get a Dialpad user by their user ID.\n */\n async getUser(userId: string | number): Promise<DialpadUser | null> {\n try {\n return await this.get<DialpadUser>(`/users/${userId}`);\n } catch (error) {\n if (error instanceof DialpadProxyError && error.status === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Find a Dialpad user by email.\n */\n async getUserByEmail(email: string): Promise<DialpadUser | null> {\n const result = await this.get<DialpadUserListResponse>(\"/users\", {\n email,\n });\n return result.items?.[0] ?? null;\n }\n\n /**\n * Find a Dialpad user by phone number.\n */\n async getUserByPhoneNumber(phoneNumber: string): Promise<DialpadUser | null> {\n const result = await this.get<DialpadUserListResponse>(\"/users\", {\n number: phoneNumber,\n });\n return result.items?.[0] ?? null;\n }\n\n /**\n * Get information about a Dialpad phone number.\n */\n async getNumberInfo(phoneNumber: string): Promise<DialpadNumberInfo | null> {\n try {\n const cleanNumber = phoneNumber.replace(/[^\\d+]/g, \"\");\n return await this.get<DialpadNumberInfo>(\n `/numbers/${encodeURIComponent(cleanNumber)}`,\n );\n } catch (error) {\n if (error instanceof DialpadProxyError && error.status === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Authenticate a voicemail download URL. Truth appends the Dialpad API key,\n * follows redirects, and returns the clean URL for client-side playback.\n */\n async authenticateVoicemail(voicemailLink: string): Promise<string | null> {\n const url = `${this.baseUrl}/api/messages/dialpad/voicemail/authenticate`;\n\n const response = await fetch(url, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true, accept: false }),\n body: JSON.stringify({ voicemail_link: voicemailLink }),\n });\n\n const result = (await response.json()) as VoicemailAuthResponse;\n\n if (!response.ok || !result.success) {\n return null;\n }\n\n return result.authenticated_url;\n }\n\n // -----------------------------------------------------------------------\n // Internal HTTP helpers\n // -----------------------------------------------------------------------\n\n private async get<T>(\n path: string,\n params?: Record<string, unknown>,\n ): Promise<T> {\n const url = new URL(`/api/messages/dialpad${path}`, this.baseUrl);\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n const response = await fetch(url.toString(), {\n method: \"GET\",\n headers: await buildAuthHeaders(this.auth),\n });\n\n if (!response.ok) {\n throw new DialpadProxyError(\"GET\", path, response.status);\n }\n\n return (await response.json()) as T;\n }\n\n private async post<T>(path: string, body?: unknown): Promise<T> {\n const url = `${this.baseUrl}/api/messages/dialpad${path}`;\n\n const response = await fetch(url, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n throw new DialpadProxyError(\"POST\", path, response.status);\n }\n\n return (await response.json()) as T;\n }\n\n private async put<T = void>(path: string, body?: unknown): Promise<T> {\n const url = `${this.baseUrl}/api/messages/dialpad${path}`;\n\n const response = await fetch(url, {\n method: \"PUT\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n throw new DialpadProxyError(\"PUT\", path, response.status);\n }\n\n if (response.headers.get(\"content-type\")?.includes(\"json\")) {\n return (await response.json()) as T;\n }\n\n return undefined as T;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Messages Resource — namespace for messaging providers\n// ---------------------------------------------------------------------------\n\nclass MessagesResource {\n readonly dialpad: DialpadResource;\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.dialpad = new DialpadResource(apiBaseUrl, apiKey, getAuthToken);\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n /**\n * Get an authenticated URL for a Dialpad voicemail recording.\n *\n * Replaces CommHub's `getAuthenticatedVoicemailUrl` Hasura mutation\n * (which proxied to the legacy NestJS backend). Truth appends the\n * Dialpad API key, follows redirects, strips the key from the final\n * URL, and returns it for client-side audio playback.\n *\n * @param voicemailLink The raw Dialpad voicemail download URL (value\n * of the `voicemail_link` field on the call event row).\n * @returns An object with `url` (clean playback URL) and `expiresAt`\n * (ISO-8601 timestamp, ~5 min from request time, informational only).\n */\n async getVoicemailUrl(voicemailLink: string): Promise<{\n url: string;\n expiresAt: string;\n }> {\n const res = await fetch(`${this.baseUrl}/api/conversations/voicemail/url`, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: JSON.stringify({ voicemailLink }),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new Error(\n `messages.getVoicemailUrl failed (HTTP ${res.status}): ${text.slice(0, 200)}`,\n );\n }\n return (await res.json()) as { url: string; expiresAt: string };\n }\n\n /**\n * End a Dialpad call via the typed oRPC procedure (POST hangup, with\n * 404→`alreadyEnded` so the UI doesn't flash an error on a natural\n * race). Replaces CommHub's `useEndCallMutation` Hasura action.\n *\n * Prefer this over `messages.dialpad.endCall` which goes through the\n * generic proxy (PUT, no 404 handling).\n */\n async endCall(callId: number | string): Promise<{\n ok: true;\n alreadyEnded: boolean;\n }> {\n const res = await fetch(`${this.baseUrl}/api/conversations/calls/end`, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: JSON.stringify({ callId }),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new Error(\n `messages.endCall failed (HTTP ${res.status}): ${text.slice(0, 200)}`,\n );\n }\n return (await res.json()) as { ok: true; alreadyEnded: boolean };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Error\n// ---------------------------------------------------------------------------\n\nclass DialpadProxyError extends Error {\n readonly method: string;\n readonly path: string;\n readonly status: number;\n\n constructor(method: string, path: string, status: number) {\n super(\n `Dialpad proxy error: ${method} /api/messages/dialpad${path} returned ${status}`,\n );\n this.name = \"DialpadProxyError\";\n this.method = method;\n this.path = path;\n this.status = status;\n }\n}\n\nexport { DialpadResource, DialpadProxyError, MessagesResource };\nexport type {\n SendSmsParams,\n SendSmsResponse,\n InitiateCallResponse,\n CallStatusResponse,\n DialpadUser,\n DialpadNumberInfo,\n VoicemailAuthResponse,\n};\n","/**\n * EHR proxy resource — typed access to Truth's EHR proxy endpoints.\n *\n * Provides per-provider proxy methods so consumers never construct\n * proxy URLs manually. Every request carries the application's\n * `X-API-Key` — Truth's API gate rejects unauthenticated callers.\n *\n * @example\n * ```ts\n * const patient = await truth.ehr.elation.get('/patients/123/');\n * const notes = await truth.ehr.elation.post('/non_visit_notes/', noteData);\n * const hintPatient = await truth.ehr.hint.get('/provider/patients/456');\n * ```\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\n// ---------------------------------------------------------------------------\n// Provider proxy\n// ---------------------------------------------------------------------------\n\nclass EhrProviderProxy {\n private readonly baseUrl: string;\n private readonly provider: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n provider: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.provider = provider;\n this.auth = { apiKey, getAuthToken };\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: unknown,\n params?: Record<string, unknown>,\n ): Promise<T> {\n const url = new URL(`/api/ehr/${this.provider}${path}`, this.baseUrl);\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n const response = await fetch(url.toString(), {\n method,\n // PHI (EHR/Elation proxy) — REQUIRE the user JWT. The server hardens the\n // EHR proxy routes to `verifiedUserProcedure`, so degrading to key-only\n // would 401.\n headers: await buildAuthHeaders(this.auth, {\n json: body !== undefined,\n requireUserToken: true,\n }),\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n throw new EhrProxyError(this.provider, method, path, response.status);\n }\n\n return (await response.json()) as T;\n }\n\n /**\n * GET request to the EHR proxy.\n * @param path — path relative to the provider root (e.g., \"/patients/123/\")\n * @param params — optional query parameters\n */\n async get<T = unknown>(\n path: string,\n params?: Record<string, unknown>,\n ): Promise<T> {\n return this.request<T>(\"GET\", path, undefined, params);\n }\n\n /** POST request to the EHR proxy. */\n async post<T = unknown>(path: string, body?: unknown): Promise<T> {\n return this.request<T>(\"POST\", path, body);\n }\n\n /** PUT request to the EHR proxy. */\n async put<T = unknown>(path: string, body?: unknown): Promise<T> {\n return this.request<T>(\"PUT\", path, body);\n }\n\n /** PATCH request to the EHR proxy. */\n async patch<T = unknown>(path: string, body?: unknown): Promise<T> {\n return this.request<T>(\"PATCH\", path, body);\n }\n\n /** DELETE request to the EHR proxy. */\n async delete<T = unknown>(path: string): Promise<T> {\n return this.request<T>(\"DELETE\", path);\n }\n}\n\n// ---------------------------------------------------------------------------\n// EHR Resource — exposes per-provider proxies\n// ---------------------------------------------------------------------------\n\nclass EhrResource {\n /** Elation EHR proxy */\n readonly elation: EhrProviderProxy;\n\n /** Hint Health proxy */\n readonly hint: EhrProviderProxy;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.elation = new EhrProviderProxy(\n apiBaseUrl,\n \"elation\",\n apiKey,\n getAuthToken,\n );\n this.hint = new EhrProviderProxy(apiBaseUrl, \"hint\", apiKey, getAuthToken);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Error\n// ---------------------------------------------------------------------------\n\nclass EhrProxyError extends Error {\n readonly provider: string;\n readonly method: string;\n readonly path: string;\n readonly status: number;\n\n constructor(provider: string, method: string, path: string, status: number) {\n super(\n `EHR proxy error: ${method} /api/ehr/${provider}${path} returned ${status}`,\n );\n this.name = \"EhrProxyError\";\n this.provider = provider;\n this.method = method;\n this.path = path;\n this.status = status;\n }\n}\n\nexport { EhrResource, EhrProviderProxy, EhrProxyError };\n","/**\n * NotesResource — push formatted notes to Elation.\n *\n * Caller assembles the note body (text + bullets). Truth owns the Elation\n * OAuth token and the HTTP call so applications can drop Elation\n * credentials from their own config.\n *\n * BREAKING — 0.26.20, `pushConversationToElation`:\n * - AUTH CLASS CHANGED. The server route moved from `applicationProcedure`\n * to `verifiedUserProcedure`, so an API key alone (including a secret\n * `hn_sk_*` or legacy `hn_live_*` key) now gets 401. Callers MUST supply\n * `getAuthToken` on the client so a verified Clerk JWT accompanies the\n * request; this resource already sends it with `requireUserToken: true`.\n * - `input.initiatedBy` is DEPRECATED and ignored server-side. The audit\n * row's actor is the JWT `sub`. Passing a differing value is logged as a\n * warning server-side and will be removed in a future major.\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\nexport interface NonVisitNoteBullet {\n text: string;\n category?: string;\n}\n\nexport interface PushNoteToElationInput {\n patient: number;\n physician: number;\n practice: number;\n note: { text: string; type?: string };\n document_date?: string;\n chart_date?: string;\n bullets?: NonVisitNoteBullet[];\n}\n\nexport interface PushNoteToElationResult {\n success: boolean;\n elationNoteId: number | null;\n}\n\nclass NotesError extends Error {\n readonly status: number;\n\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Notes ${operation} failed (HTTP ${status})`);\n this.name = \"NotesError\";\n this.status = status;\n }\n}\n\nexport interface PushConversationToElationInput {\n /** One-of: conversationId (Convex) or phonePair. */\n conversationId?: string;\n phonePair?: string;\n /**\n * @deprecated Ignored by the server; the actor recorded on the audit row is\n * derived from the verified Clerk JWT (`sub`). Supplying a value has no\n * effect and will be removed in a future major.\n */\n initiatedBy?: string;\n /** Pre-assembled note body (transcript-style text). */\n noteText: string;\n bullets?: NonVisitNoteBullet[];\n notesPushed?: number;\n messagesPushed?: number;\n tasksPushed?: number;\n /**\n * Convex ids of the `conversationNotes` rows included in this push. When\n * set, Truth rejects the call with 409 CONFLICT if any is already marked\n * sent (unless `resend`), rejects ids that are not in this conversation with\n * 404, and stamps each note sent on success (never on failure).\n */\n noteIds?: string[];\n /** Explicitly allow re-sending notes already marked sent. Default false. */\n resend?: boolean;\n}\n\nexport interface PushConversationToElationResult {\n success: true;\n batchId: string;\n elationNoteId: number | null;\n notesPushed: number;\n messagesPushed: number;\n tasksPushed: number;\n /** Notes stamped sent by this call (empty when no `noteIds` were supplied). */\n sentNoteIds: string[];\n}\n\nclass NotesResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n /** 30s upstream timeout — Elation API has occasional slow hops; we\n * don't want a pending mutation to hold the UI thread indefinitely. */\n private static readonly REQUEST_TIMEOUT_MS = 30_000;\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n NotesResource.REQUEST_TIMEOUT_MS,\n );\n\n let res: Response;\n try {\n res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n // PHI (clinical notes) — REQUIRE the user JWT. The server hardens these\n // routes to `verifiedUserProcedure`, so degrading to key-only would 401.\n headers: await buildAuthHeaders(this.auth, {\n json: true,\n requireUserToken: true,\n }),\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n // Transport failures (DNS, TCP, TLS, AbortError) become typed\n // NotesError so consumers don't have to special-case raw fetch\n // exceptions. status=0 signals \"never made it to the server\".\n const isAbort =\n err instanceof Error &&\n (err.name === \"AbortError\" || err.name === \"TimeoutError\");\n const message = isAbort\n ? `Notes ${path} timed out after ${NotesResource.REQUEST_TIMEOUT_MS}ms`\n : err instanceof Error\n ? err.message\n : \"Notes request failed before response\";\n throw new NotesError(path, 0, message);\n } finally {\n clearTimeout(timeout);\n }\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new NotesError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n /**\n * Low-level — caller has already resolved Elation patient / physician\n * / practice. Use `pushConversationToElation` if you only have a\n * conversation handle.\n */\n async pushToElation(\n input: PushNoteToElationInput,\n ): Promise<PushNoteToElationResult> {\n return await this.post<PushNoteToElationResult>(\n \"/notes/push-to-elation\",\n input,\n );\n }\n\n /**\n * Orchestrator — pass a conversation handle + pre-assembled note text.\n * Truth resolves the linked patient via Convex, looks up\n * physician/practice in Elation, posts the note, and writes an audit\n * row to `elationSyncEvents`. Replaces CommHub's `pushNotesToElation`\n * Hasura action.\n *\n * Auth: requires a user token. The server runs this route under\n * `verifiedUserProcedure`, so the API key alone is rejected with 401 —\n * configure `getAuthToken` on the client. `input.initiatedBy` is ignored;\n * the audit row's actor is the verified JWT `sub`.\n */\n async pushConversationToElation(\n input: PushConversationToElationInput,\n ): Promise<PushConversationToElationResult> {\n return await this.post<PushConversationToElationResult>(\n \"/notes/push-conversation-to-elation\",\n input,\n );\n }\n}\n\nexport { NotesResource, NotesError };\n","/**\n * NotificationsResource — wraps Truth's /api/notifications/* endpoints.\n *\n * Server-side use (for example from a CommHub backend job or\n * another service): `truth.notifications.send({ userId, title, body })`.\n *\n * Client-side React usage lives in `@hipnation-truth/sdk/react` via\n * the `useNotifications` hook which mirrors `expo-notifications`.\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\nexport type NotificationPlatform = \"ios\" | \"android\" | \"web\";\n\nexport interface RegisterDeviceInput {\n userId: string;\n platform: NotificationPlatform;\n nativeToken?: string;\n webPushSubscription?: {\n endpoint: string;\n keys: { p256dh: string; auth: string };\n };\n appVersion?: string;\n osVersion?: string;\n locale?: string;\n timezone?: string;\n /**\n * iOS only — which APNs endpoint the `nativeToken` was issued\n * against. The token bytes don't carry this; it's determined by\n * the build's `aps-environment` entitlement\n * (`development` ⇒ sandbox, `production` ⇒ production). When the\n * consumer is an Expo app, detect via\n * `Application.getIosPushNotificationServiceEnvironmentAsync()`\n * from `expo-application` and pass the normalised value here.\n * Omitting this falls back to the application's default\n * `pushConfig.ios.environment` server-side.\n */\n apnsEnvironment?: \"sandbox\" | \"production\";\n}\n\nexport interface RegisterDeviceResult {\n deviceId: string;\n action: \"inserted\" | \"updated\";\n snsEndpointArn?: string;\n}\n\nexport interface UnregisterDeviceInput {\n nativeToken?: string;\n deviceId?: string;\n}\n\nexport interface SendNotificationInput {\n userId: string;\n title: string;\n body: string;\n data?: Record<string, unknown>;\n badge?: number;\n sound?: string;\n}\n\nexport interface SendNotificationResult {\n delivered: number;\n failed?: number;\n suppressed?: boolean;\n suppressionReason?: string;\n}\n\nexport interface NotificationPreferences {\n channels: { sms: boolean; push: boolean; email: boolean; inApp: boolean };\n quietHours?: {\n enabled: boolean;\n start: string;\n end: string;\n timezone: string;\n };\n doNotDisturbUntil?: string;\n updatedAt: string;\n}\n\nexport interface UpdatePreferencesInput {\n userId: string;\n channels?: NotificationPreferences[\"channels\"];\n quietHours?: NotificationPreferences[\"quietHours\"];\n doNotDisturbUntil?: string | null;\n}\n\nexport interface ScheduleNotificationInput extends SendNotificationInput {\n /** ISO 8601 timestamp; must be strictly in the future. */\n scheduledAt: string;\n}\n\nexport interface ScheduleNotificationResult {\n jobId: string;\n scheduledAt: string;\n}\n\nexport interface CancelScheduledNotificationResult {\n cancelled: boolean;\n reason?: string;\n status?: string;\n}\n\nexport type ScheduledJobStatus =\n | \"pending\"\n | \"executed\"\n | \"cancelled\"\n | \"failed\";\n\nexport interface ScheduledNotification {\n jobId: string;\n userId: string;\n title: string;\n body: string;\n data?: unknown;\n badge?: number;\n sound?: string;\n scheduledAt: string;\n status: ScheduledJobStatus;\n resultHistoryId?: string;\n errorMessage?: string;\n createdAt: string;\n}\n\nexport interface PushEventPayload {\n title: string;\n body: string;\n data?: unknown;\n}\n\nclass NotificationsError extends Error {\n readonly status: number;\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Notifications ${operation} failed (HTTP ${status})`);\n this.name = \"NotificationsError\";\n this.status = status;\n }\n}\n\nclass NotificationsResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new NotificationsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n private async get<T>(\n path: string,\n params: Record<string, string>,\n ): Promise<T> {\n const url = new URL(`${this.baseUrl}/api${path}`);\n for (const [k, v] of Object.entries(params)) {\n url.searchParams.set(k, v);\n }\n const res = await fetch(url.toString(), {\n method: \"GET\",\n headers: await buildAuthHeaders(this.auth),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new NotificationsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n private async delete<T>(path: string): Promise<T> {\n const res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"DELETE\",\n headers: await buildAuthHeaders(this.auth),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new NotificationsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n /**\n * Register a device (or refresh its metadata) for push delivery.\n * Safe to call repeatedly — the server dedupes by native token.\n */\n async registerDevice(\n input: RegisterDeviceInput,\n ): Promise<RegisterDeviceResult> {\n return this.post(\"/notifications/devices/register\", input);\n }\n\n /** Revoke a device — on sign-out or when the OS reports an invalid token. */\n async unregisterDevice(\n input: UnregisterDeviceInput,\n ): Promise<{ revoked: boolean }> {\n return this.post(\"/notifications/devices/unregister\", input);\n }\n\n /**\n * Send a push notification to every active device belonging to\n * `userId`. Honors the user's notificationPreferences (quiet hours,\n * DND, channel off) before publishing.\n */\n async send(input: SendNotificationInput): Promise<SendNotificationResult> {\n return this.post(\"/notifications/send\", input);\n }\n\n /** Read a user's notification preferences. Returns defaults when no row exists. */\n async getPreferences(userId: string): Promise<NotificationPreferences> {\n return this.get(\"/notifications/preferences\", { userId });\n }\n\n async updatePreferences(\n input: UpdatePreferencesInput,\n ): Promise<{ ok: boolean }> {\n return this.post(\"/notifications/preferences\", input);\n }\n\n /**\n * Schedule a future push notification. Convex's native scheduler\n * fires the send at `scheduledAt` and runs the same delivery\n * pipeline as `send()` (preferences, devices, history audit).\n *\n * Throws `NotificationsError` with status 400 if `scheduledAt` is\n * not strictly in the future.\n */\n async schedule(\n input: ScheduleNotificationInput,\n ): Promise<ScheduleNotificationResult> {\n return this.post(\"/notifications/schedule\", input);\n }\n\n /**\n * Cancel a pending scheduled notification. Returns `cancelled: false`\n * (no error) if the job has already executed, was previously\n * cancelled, or no longer exists — `reason` describes which case.\n */\n async cancelScheduled(\n jobId: string,\n ): Promise<CancelScheduledNotificationResult> {\n return this.delete(`/notifications/schedule/${encodeURIComponent(jobId)}`);\n }\n\n /**\n * List scheduled notifications for a user — pending, executed,\n * cancelled, or failed. Most-recent first. Default limit 100.\n */\n async listScheduled(\n userId: string,\n options?: { limit?: number },\n ): Promise<ScheduledNotification[]> {\n const params: Record<string, string> = { userId };\n if (options?.limit !== undefined) {\n params.limit = String(options.limit);\n }\n return this.get(\"/notifications/schedule\", params);\n }\n\n async getVapidKey(): Promise<string | null> {\n try {\n const result = await this.get<{ vapidPublicKey: string | null }>(\n \"/notifications/vapid-key\",\n {},\n );\n return result.vapidPublicKey;\n } catch {\n return null;\n }\n }\n\n onPushReceived(callback: (payload: PushEventPayload) => void): () => void {\n if (typeof navigator === \"undefined\" || !(\"serviceWorker\" in navigator)) {\n return () => {};\n }\n const handler = (event: MessageEvent) => {\n if (event.data?.type === \"TRUTH_PUSH_RECEIVED\") {\n callback(event.data.payload);\n }\n };\n navigator.serviceWorker.addEventListener(\"message\", handler);\n return () =>\n navigator.serviceWorker.removeEventListener(\"message\", handler);\n }\n\n onPushTapped(callback: (payload: PushEventPayload) => void): () => void {\n if (typeof navigator === \"undefined\" || !(\"serviceWorker\" in navigator)) {\n return () => {};\n }\n const handler = (event: MessageEvent) => {\n if (event.data?.type === \"TRUTH_PUSH_TAPPED\") {\n callback(event.data.payload);\n }\n };\n navigator.serviceWorker.addEventListener(\"message\", handler);\n return () =>\n navigator.serviceWorker.removeEventListener(\"message\", handler);\n }\n}\n\nexport { NotificationsResource, NotificationsError };\n","/**\n * PatientDetailsResource — merged Hint + Elation patient lookups.\n *\n * Backed by the Truth API at /api/patients/details/*, authenticated with\n * X-API-Key. Replaces CommHub's getPatientDetails / getPatientBasicDetails\n * / getPatientMedicalDetails actions.\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\nexport interface PatientDetailsInput {\n hintId?: string;\n elationId?: string;\n}\n\nexport interface PatientDetailsResult {\n hint: unknown | null;\n elation: unknown | null;\n resolvedElationId: string | null;\n}\n\nexport interface PatientBasicDetailsResult {\n hint: unknown | null;\n elationId: string | null;\n}\n\nexport interface PatientMedicalDetailsResult {\n problems: unknown | null;\n medications: unknown | null;\n allergies: unknown | null;\n appointments: unknown | null;\n}\n\nclass PatientDetailsError extends Error {\n readonly status: number;\n\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Patient ${operation} failed (HTTP ${status})`);\n this.name = \"PatientDetailsError\";\n this.status = status;\n }\n}\n\nclass PatientDetailsResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n // PHI (patient chart) — REQUIRE the user JWT. The server hardens these\n // routes to `verifiedUserProcedure`, so degrading to key-only would 401.\n // `requireUserToken` retries token resolution across the Clerk-hydration\n // gap and throws a clear auth error if none is obtainable, rather than\n // silently sending key-only.\n headers: await buildAuthHeaders(this.auth, {\n json: true,\n requireUserToken: true,\n }),\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new PatientDetailsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n async get(input: PatientDetailsInput): Promise<PatientDetailsResult> {\n return await this.post<PatientDetailsResult>(\"/patients/details\", input);\n }\n\n async getBasic(\n input: PatientDetailsInput,\n ): Promise<PatientBasicDetailsResult> {\n return await this.post<PatientBasicDetailsResult>(\n \"/patients/details/basic\",\n input,\n );\n }\n\n async getMedical(elationId: string): Promise<PatientMedicalDetailsResult> {\n return await this.post<PatientMedicalDetailsResult>(\n \"/patients/details/medical\",\n { elationId },\n );\n }\n\n /**\n * Trigger a server-side refresh of the patient's Elation medical\n * records (medications, problems, allergies, appointments) into the\n * Convex cache. Fire-and-forget — the UI should read via the Convex-\n * reactive `usePatientMedical` hook.\n */\n async refreshMedical(elationId: number): Promise<{\n totals: {\n medications: number;\n problems: number;\n allergies: number;\n appointments: number;\n };\n }> {\n return await this.post<{\n totals: {\n medications: number;\n problems: number;\n allergies: number;\n appointments: number;\n };\n }>(\"/patients/medical/refresh\", { elationId });\n }\n}\n\nexport { PatientDetailsResource, PatientDetailsError };\n","/**\n * Coerce a patient elationId to a 64-bit integer (`bigint`) for Convex queries.\n *\n * Elation ids are `long(64)` and originate as Hasura bigints, which serialize\n * as **strings** (e.g. \"140754874499075\") and can exceed 2^53 — so a JS\n * `number` (`v.float64()`) would silently lose precision. The Convex patient\n * validators are being normalized to `v.int64()`, which over the wire is a JS\n * `bigint`. We coerce here — at the single boundary between the patient hooks\n * and the Convex validators — so every caller (web admin panel + mobile app,\n * any build) passes a precision-exact `bigint` regardless of whether it happened\n * to receive the id as a string, a number, or a bigint.\n *\n * Returns `undefined` for null/empty/non-numeric input so the hook can pass\n * `\"skip\"`. A numeric string is converted with `BigInt(str)` (exact); a number\n * with `BigInt(Math.trunc(n))` when finite + integer.\n */\nexport function toBigIntElationId(value: unknown): bigint | undefined {\n if (value === undefined || value === null || value === \"\") {\n return undefined;\n }\n if (typeof value === \"bigint\") {\n return value;\n }\n if (typeof value === \"number\") {\n if (!Number.isFinite(value) || !Number.isInteger(value)) {\n return undefined;\n }\n return BigInt(Math.trunc(value));\n }\n if (typeof value === \"string\") {\n const trimmed = value.trim();\n if (!/^\\d+$/.test(trimmed)) {\n return undefined;\n }\n try {\n return BigInt(trimmed);\n } catch {\n return undefined;\n }\n }\n return undefined;\n}\n\n/**\n * Coerce a patient elationId to a finite `number`, or `undefined` for\n * null/empty/non-numeric input.\n *\n * Still used for the `elationPatientId` args of the medical-record and photo\n * queries, whose Convex validators remain `v.number()` (those tables are not\n * part of the int64 normalization). For the patient / elationPatients basic\n * lookups (now `v.int64()`), use `toBigIntElationId` instead.\n */\nexport function toFiniteElationId(value: unknown): number | undefined {\n if (value === undefined || value === null || value === \"\") {\n return undefined;\n }\n const n = typeof value === \"number\" ? value : Number(value);\n return Number.isFinite(n) ? n : undefined;\n}\n","/**\n * PatientResource provides data access to normalized patient records\n * backed by Convex.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport { toBigIntElationId } from \"../react/elation-id\";\nimport type { PaginatedResult } from \"../types/config\";\nimport type { Patient, PatientListOptions } from \"../types/patient\";\n\nclass PatientResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convexClient: ConvexHttpClient) {\n this.convex = convexClient;\n }\n\n /**\n * Get a patient by their Truth platform ID.\n */\n async get(id: string): Promise<Patient | null> {\n try {\n const result = await this.convex.query(\n \"patients:getById\" as never,\n {\n id,\n } as never,\n );\n return (result as Patient) ?? null;\n } catch {\n return null;\n }\n }\n\n /**\n * Get a patient by their Elation EHR ID.\n *\n * Accepts the id in any form (string/number/bigint) and coerces it to a\n * `bigint` (int64) for the now-int64 Convex `patients:getByElationId` arg.\n * Returns `null` for a non-numeric / absent id.\n */\n async getByElationId(\n elationId: string | number | bigint,\n ): Promise<Patient | null> {\n const id = toBigIntElationId(elationId);\n if (id === undefined) {\n return null;\n }\n try {\n const result = await this.convex.query(\n \"patients:getByElationId\" as never,\n { elationId: id } as never,\n );\n return (result as Patient) ?? null;\n } catch {\n return null;\n }\n }\n\n /**\n * Get a patient by their Hint EHR ID.\n */\n async getByHintId(hintId: string): Promise<Patient | null> {\n try {\n const result = await this.convex.query(\n \"patients:getByHintId\" as never,\n {\n hintId,\n } as never,\n );\n return (result as Patient) ?? null;\n } catch {\n return null;\n }\n }\n\n /**\n * List patients with optional search, pagination, and limit.\n */\n async list(options?: PatientListOptions): Promise<PaginatedResult<Patient>> {\n try {\n const result = await this.convex.query(\n \"patients:list\" as never,\n {\n search: options?.search,\n limit: options?.limit,\n cursor: options?.cursor,\n } as never,\n );\n\n const typed = result as PaginatedResult<Patient> | undefined;\n\n return typed ?? { data: [], cursor: null, hasMore: false };\n } catch {\n return { data: [], cursor: null, hasMore: false };\n }\n }\n}\n\nexport { PatientResource };\n","/**\n * PhysiciansResource — Convex-backed physician lookups.\n *\n * Populated from Elation by Truth's daily PhysiciansBackfillCron. Replaces\n * per-physician Elation HTTP hops with a single Convex batch query.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\n\nexport interface Physician {\n _id: string;\n elationId: number;\n firstName?: string;\n lastName?: string;\n npi?: string;\n credentials?: string;\n specialties?: string[];\n practice?: number;\n email?: string;\n phone?: string;\n lastSyncedAt: string;\n}\n\nclass PhysiciansResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convex: ConvexHttpClient) {\n this.convex = convex;\n }\n\n /**\n * Resolve a batch of physicians by Elation IDs. Missing ids are dropped.\n */\n async getByElationIds(ids: number[]): Promise<Physician[]> {\n if (ids.length === 0) {\n return [];\n }\n try {\n const rows = (await this.convex.query(\n \"physicians:getByElationIds\" as never,\n { ids } as never,\n )) as Physician[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n\n async getByElationId(id: number): Promise<Physician | null> {\n try {\n const row = (await this.convex.query(\n \"physicians:getByElationId\" as never,\n { id } as never,\n )) as Physician | null;\n return row ?? null;\n } catch {\n return null;\n }\n }\n\n async listByPractice(practice: number, limit?: number): Promise<Physician[]> {\n try {\n const rows = (await this.convex.query(\n \"physicians:listByPractice\" as never,\n { practice, limit } as never,\n )) as Physician[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n}\n\nexport { PhysiciansResource };\n","/**\n * RemindersResource — schedule, cancel, and list conversation reminders.\n *\n * Backed by Convex mutations/queries (durable scheduled functions) — replaces\n * the in-memory setTimeout scheduler that used to live in CommHub's NestJS\n * backend.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport type {\n Reminder,\n ScheduleReminderInput,\n ScheduleReminderResult,\n} from \"../types/reminder\";\n\nclass RemindersResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convexClient: ConvexHttpClient) {\n this.convex = convexClient;\n }\n\n /**\n * Schedule a reminder to fire at `remindAt`. Returns the reminder id,\n * which callers should store if they may want to cancel it later.\n */\n async schedule(\n input: ScheduleReminderInput,\n ): Promise<ScheduleReminderResult> {\n const remindAt =\n input.remindAt instanceof Date\n ? input.remindAt.toISOString()\n : input.remindAt;\n\n const result = (await this.convex.mutation(\n \"reminders:schedule\" as never,\n {\n conversationId: input.conversationId,\n remindAt,\n note: input.note,\n createdBy: input.createdBy,\n createdByClerkId: input.createdByClerkId,\n } as never,\n )) as ScheduleReminderResult;\n\n return result;\n }\n\n /**\n * Cancel a pending reminder. No-op if the reminder has already fired or\n * been cancelled.\n */\n async cancel(\n reminderId: string,\n cancelledBy: string,\n ): Promise<{ reminderId: string; status: string }> {\n return (await this.convex.mutation(\n \"reminders:cancel\" as never,\n { reminderId, cancelledBy } as never,\n )) as { reminderId: string; status: string };\n }\n\n /**\n * List reminders for a conversation (most recent first).\n */\n async listByConversation(conversationId: string): Promise<Reminder[]> {\n try {\n const rows = (await this.convex.query(\n \"reminders:listByConversation\" as never,\n { conversationId } as never,\n )) as Reminder[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n}\n\nexport { RemindersResource };\n","/**\n * ReportsResource — member activation report from truth.\n *\n * Accesses the Truth API at GET /reports/member-activation,\n * authenticated with X-API-Key + user JWT (verifiedUserProcedure).\n *\n * Replaces the broker pattern: frontend calls truth directly via SDK,\n * no comhub hop.\n */\n\nimport { z } from \"zod\";\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\n// ---- Schema (mirrors truth's reportSchema) ----\n\nconst memberSchema = z.object({\n elationId: z.string(),\n name: z.string(),\n // T6: mirrors truth's member-activation-report.ts memberSchema (T5).\n // Optional/nullable so a comhub build against an older/newer server\n // payload still parses either way.\n lastName: z.string().nullable().optional(),\n firstName: z.string().nullable().optional(),\n doctor: z.string().nullable(),\n status: z.enum([\"activated\", \"outreach\", \"scheduled\", \"review\", \"data\"]),\n membershipStart: z.string(),\n daysSinceMembershipStart: z.number(),\n activationDate: z.string().nullable(),\n futureApptDate: z.string().nullable(),\n reason: z.string().nullable(),\n hasLink: z.boolean(),\n});\n\nexport const reportSchema = z.object({\n synthetic: z.boolean(),\n generatedAt: z.string(),\n employers: z.array(\n z.object({ id: z.string(), name: z.string(), activeMembers: z.number() }),\n ),\n selected: z\n .object({\n employerId: z.string(),\n employerName: z.string(),\n kpis: z.object({\n active: z.number(),\n linked: z.number(),\n activated: z.number(),\n needsOutreach: z.number(),\n scheduled: z.number(),\n needsReview: z.number(),\n dataIssue: z.number(),\n activationRate: z.number(),\n }),\n coverage: z.object({\n active: z.number(),\n linked: z.number(),\n unlinked: z.number(),\n pct: z.number(),\n }),\n breakdown: z.array(\n z.object({\n status: z.enum([\n \"activated\",\n \"outreach\",\n \"scheduled\",\n \"review\",\n \"data\",\n ]),\n label: z.string(),\n count: z.number(),\n pct: z.number(),\n }),\n ),\n aging: z.array(\n z.object({\n bucket: z.string(),\n total: z.number(),\n outreach: z.number(),\n scheduled: z.number(),\n review: z.number(),\n }),\n ),\n doctors: z.array(\n z.object({\n name: z.string(),\n counts: z.object({\n outreach: z.number(),\n scheduled: z.number(),\n review: z.number(),\n data: z.number(),\n }),\n members: z.array(memberSchema),\n }),\n ),\n })\n .nullable(),\n // True when the requested employer has no materialized report row yet\n // (ehr-sync's dailyHandler has not run for it). `selected` is null in that\n // case — the caller sees the employer roster but no report data to render.\n pending: z.boolean(),\n});\n\nexport type MemberActivationReport = z.infer<typeof reportSchema>;\n\nclass ReportsError extends Error {\n readonly status: number;\n\n /**\n * Wraps a failed reports HTTP call with the operation name and status\n * code so callers can branch on `status` without re-parsing the message.\n * Falls back to a generated message when the server response body is\n * empty or unreadable.\n */\n constructor(operation: string, status: number, message?: string) {\n const trimmedMessage = message?.trim();\n super(trimmedMessage || `Reports ${operation} failed (HTTP ${status})`);\n this.name = \"ReportsError\";\n this.status = status;\n }\n}\n\nclass ReportsResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n /**\n * Captures the Truth API base URL and the auth inputs (API key + optional\n * user-token fetcher) needed to authenticate every request this resource\n * makes.\n */\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n /**\n * Fetches the member activation report from GET /reports/member-activation,\n * optionally scoped to a single employer. Requires the user JWT (not just\n * the API key) since the server hardens this route to\n * `verifiedUserProcedure` for PHI access — throws via `ReportsError` on a\n * non-OK response, including the response body (truncated) when present.\n */\n async memberActivation(params?: {\n employerId?: string;\n }): Promise<MemberActivationReport> {\n const url = new URL(`${this.baseUrl}/api/reports/member-activation`);\n if (params?.employerId) {\n url.searchParams.set(\"employerId\", params.employerId);\n }\n\n const res = await fetch(url.toString(), {\n method: \"GET\",\n // PHI (member activation report) — REQUIRE the user JWT. The server\n // hardens this route to `verifiedUserProcedure`, so degrading to\n // key-only would 401. `requireUserToken` retries across the Clerk-\n // hydration gap and throws rather than silently sending key-only.\n headers: await buildAuthHeaders(this.auth, {\n requireUserToken: true,\n }),\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ReportsError(\n \"member-activation\",\n res.status,\n text.slice(0, 200),\n );\n }\n\n return (await res.json()) as MemberActivationReport;\n }\n}\n\nexport { ReportsResource, ReportsError };\n","/**\n * TasksResource — create, update status, list, get tasks.\n *\n * Backed by Convex. Replaces CommHub's createTaskWithNotification +\n * updateTaskStatusWithNotification actions. The push notification side-effect\n * is NOT emitted via Kinesis: the Convex task mutation enqueues a\n * `notificationJobs` row and schedules `notificationScheduler.runJob`, which\n * HTTP-fetches the Truth Lambda push endpoint (Truth API → Convex scheduler →\n * push). See apps/web/convex/lib/taskPush.ts.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport type {\n ConversationTaskMarkSeenInput,\n CreateTaskInput,\n Task,\n TaskStatus,\n UpdateTaskStatusInput,\n} from \"../types/task\";\n\nclass TasksResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convexClient: ConvexHttpClient) {\n this.convex = convexClient;\n }\n\n async create(\n input: CreateTaskInput,\n ): Promise<{ taskId: string; status: TaskStatus }> {\n return (await this.convex.mutation(\n \"tasks:create\" as never,\n input as never,\n )) as { taskId: string; status: TaskStatus };\n }\n\n async updateStatus(input: UpdateTaskStatusInput): Promise<{\n taskId: string;\n status: TaskStatus;\n previousStatus: TaskStatus;\n }> {\n return (await this.convex.mutation(\n \"tasks:updateStatus\" as never,\n input as never,\n )) as {\n taskId: string;\n status: TaskStatus;\n previousStatus: TaskStatus;\n };\n }\n\n async get(taskId: string): Promise<Task | null> {\n try {\n const row = (await this.convex.query(\n \"tasks:get\" as never,\n { taskId } as never,\n )) as Task | null;\n return row ?? null;\n } catch {\n return null;\n }\n }\n\n async listByAssignee(\n assignedTo: string,\n options?: { status?: TaskStatus; limit?: number },\n ): Promise<Task[]> {\n try {\n const rows = (await this.convex.query(\n \"tasks:listByAssignee\" as never,\n {\n assignedTo,\n status: options?.status,\n limit: options?.limit,\n } as never,\n )) as Task[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n\n async listOpen(limit?: number): Promise<Task[]> {\n try {\n const rows = (await this.convex.query(\n \"tasks:listOpen\" as never,\n { limit } as never,\n )) as Task[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n\n /**\n * Mark a conversation task as seen by the given user. Appends `userId`\n * to the `seenBy` array on the `conversationTasks` row if not already\n * present. Replaces CommHub's `useMark_Event_Activity_SeenMutation`.\n *\n * @returns `{ ok: true }` on success.\n * @throws if the task does not exist in Convex.\n */\n async markSeen(input: ConversationTaskMarkSeenInput): Promise<{ ok: true }> {\n return (await this.convex.mutation(\n \"conversationTasks:markSeen\" as never,\n input as never,\n )) as { ok: true };\n }\n}\n\nexport { TasksResource };\n","/**\n * TranslationResource — Azure Translator proxy through Truth API.\n *\n * All three operations are HTTP calls to Truth's oRPC endpoints at\n * `/api/translation/*`, authenticated with the same X-API-Key as the\n * event tracker.\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport type {\n DetectionResult,\n TranslateBatchInput,\n TranslateTextInput,\n TranslationResult,\n} from \"../types/translation\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\nclass TranslationError extends Error {\n readonly status: number;\n readonly operation: string;\n\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Translation ${operation} failed (HTTP ${status})`);\n this.name = \"TranslationError\";\n this.status = status;\n this.operation = operation;\n }\n}\n\nclass TranslationResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const url = `${this.baseUrl}/api${path}`;\n const res = await fetch(url, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new TranslationError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n async translate(input: TranslateTextInput): Promise<TranslationResult> {\n return await this.post<TranslationResult>(\"/translation/translate\", input);\n }\n\n async translateBatch(\n input: TranslateBatchInput,\n ): Promise<TranslationResult[]> {\n const response = await this.post<{ results: TranslationResult[] }>(\n \"/translation/translate-batch\",\n input,\n );\n return response.results;\n }\n\n async detect(text: string): Promise<DetectionResult> {\n return await this.post<DetectionResult>(\"/translation/detect\", { text });\n }\n}\n\nexport { TranslationResource, TranslationError };\n","/**\n * UserSettingsResource — typed client for the Truth `userSettings` Convex\n * table. Exposes the one mutation CommHub's Settings screen needs:\n * `updateNotifications({ userId, notificationsEnabled })`.\n *\n * Server-side / imperative use:\n * truth.userSettings.updateNotifications({ userId, notificationsEnabled: true })\n *\n * Reactive React use lives in `@hipnation-truth/sdk/react` via\n * `useUserSettings`.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport { makeFunctionReference } from \"convex/server\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface UserSettings {\n _id: string;\n userId: string;\n notificationsEnabled: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface UpdateNotificationsInput {\n userId: string;\n notificationsEnabled: boolean;\n}\n\nexport interface UpdateNotificationsResult {\n action: \"inserted\" | \"updated\";\n id: string;\n}\n\n// ---------------------------------------------------------------------------\n// Convex function references (string-based, SDK stays decoupled from codegen)\n// ---------------------------------------------------------------------------\n\nconst upsertNotificationsRef = makeFunctionReference<\n \"mutation\",\n { userId: string; notificationsEnabled: boolean },\n UpdateNotificationsResult\n>(\"userSettings:upsertNotifications\");\n\n// ---------------------------------------------------------------------------\n// Resource\n// ---------------------------------------------------------------------------\n\nclass UserSettingsResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convex: ConvexHttpClient) {\n this.convex = convex;\n }\n\n /**\n * Upsert notification preferences for a user. Creates the row if it\n * doesn't exist; patches `notificationsEnabled` + `updatedAt` otherwise.\n */\n async updateNotifications(\n input: UpdateNotificationsInput,\n ): Promise<UpdateNotificationsResult> {\n return this.convex.mutation(upsertNotificationsRef, input);\n }\n}\n\nexport { UserSettingsResource };\n","/**\n * Event tracker with batching, retry, and flush support.\n *\n * Buffers events in an internal queue and flushes them to the Truth API\n * endpoint. Flushes occur when the buffer reaches `batchSize` or every\n * `flushIntervalMs` milliseconds, whichever comes first.\n */\n\nimport type { ActorContext } from \"../types/config\";\nimport type {\n EventEnvelope,\n EventPayloadMap,\n EventType,\n TrackOptions,\n} from \"./events\";\n\n// ---------------------------------------------------------------------------\n// UUID v7 helper (no external dependency)\n// ---------------------------------------------------------------------------\n\n/**\n * Generates a UUID v7 string. Uses crypto.randomUUID where available,\n * falling back to a timestamp + random bytes implementation.\n *\n * UUID v7 layout (RFC 9562):\n * 48 bits - unix timestamp (ms)\n * 4 bits - version (0b0111)\n * 12 bits - random\n * 2 bits - variant (0b10)\n * 62 bits - random\n */\nfunction generateUuidV7(): string {\n const now = Date.now();\n\n // 6 bytes of timestamp\n const timeBytes = new Uint8Array(6);\n let ts = now;\n for (let i = 5; i >= 0; i--) {\n timeBytes[i] = ts & 0xff;\n ts = Math.floor(ts / 256);\n }\n\n // 10 bytes of random\n const randomBytes = new Uint8Array(10);\n if (\n typeof globalThis.crypto !== \"undefined\" &&\n globalThis.crypto.getRandomValues\n ) {\n globalThis.crypto.getRandomValues(randomBytes);\n } else {\n for (let i = 0; i < 10; i++) {\n randomBytes[i] = Math.floor(Math.random() * 256);\n }\n }\n\n // Assemble 16 bytes\n const bytes = new Uint8Array(16);\n bytes.set(timeBytes, 0);\n bytes.set(randomBytes, 6);\n\n // Set version (bits 48-51 to 0b0111)\n bytes[6] = (bytes[6] & 0x0f) | 0x70;\n\n // Set variant (bits 64-65 to 0b10)\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n\n // Format as hex string with dashes\n const hex = Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n\n return [\n hex.slice(0, 8),\n hex.slice(8, 12),\n hex.slice(12, 16),\n hex.slice(16, 20),\n hex.slice(20, 32),\n ].join(\"-\");\n}\n\n// ---------------------------------------------------------------------------\n// Environment-based API URL resolution\n// ---------------------------------------------------------------------------\n\n// Environment → Truth API base URL.\n//\n// Topology:\n// local / staging / stg / sandbox → sandbox Truth (app.sandbox.*)\n// uat / production → production Truth (app.truth.*)\n//\n// UAT shares production resources (same Fly Postgres + Hasura + Truth +\n// Convex + EHR tokens as prod). Staging is the isolated sandbox env.\nconst API_URLS: Record<string, string> = {\n local: \"http://localhost:3000\",\n staging: \"https://app.sandbox.communication-hub.com\",\n stg: \"https://app.sandbox.communication-hub.com\",\n sandbox: \"https://app.sandbox.communication-hub.com\",\n uat: \"https://app.truth.communication-hub.com\",\n production: \"https://app.truth.communication-hub.com\",\n};\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_BATCH_SIZE = 25;\nconst DEFAULT_FLUSH_INTERVAL_MS = 5_000;\nconst MAX_RETRIES = 3;\nconst BASE_RETRY_DELAY_MS = 500;\n\n// ---------------------------------------------------------------------------\n// Tracker configuration\n// ---------------------------------------------------------------------------\n\ninterface TrackerConfig {\n apiKey: string;\n environment: string;\n source: string;\n sourceVersion: string;\n tenantId: string;\n batchSize: number;\n flushIntervalMs: number;\n apiBaseUrl?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Tracker class\n// ---------------------------------------------------------------------------\n\nclass Tracker {\n private readonly config: TrackerConfig;\n readonly apiUrl: string;\n private queue: EventEnvelope[] = [];\n private flushTimer: ReturnType<typeof setInterval> | null = null;\n private defaultActor: ActorContext | undefined;\n private isFlushing = false;\n private isShutdown = false;\n\n constructor(config: TrackerConfig) {\n this.config = config;\n this.apiUrl =\n config.apiBaseUrl ?? API_URLS[config.environment] ?? API_URLS.local;\n\n this.startFlushInterval();\n this.registerShutdownHooks();\n }\n\n /**\n * Set the default actor context for subsequent events.\n */\n setActor(actor: ActorContext): void {\n this.defaultActor = actor;\n }\n\n /**\n * Enqueue a typed event for delivery. This is fire-and-forget from\n * the caller's perspective -- events are buffered and flushed in batches.\n */\n track<T extends EventType>(\n eventType: T,\n payload: EventPayloadMap[T],\n options?: TrackOptions,\n ): void {\n if (this.isShutdown) {\n return;\n }\n\n const now = new Date().toISOString();\n\n const envelope: EventEnvelope = {\n event_id: generateUuidV7(),\n event_type: eventType,\n schema_version: 1,\n occurred_at: options?.occurredAt ?? now,\n received_at: now,\n source: this.config.source,\n source_version: this.config.sourceVersion,\n tenant_id: options?.tenantId ?? this.config.tenantId,\n actor:\n options?.actor ??\n (this.defaultActor\n ? {\n actor_id: this.defaultActor.actorId,\n actor_type: this.defaultActor.actorType,\n }\n : undefined),\n subject: options?.subject,\n compliance: options?.compliance,\n payload: payload as unknown as Record<string, unknown>,\n };\n\n this.queue.push(envelope);\n\n if (this.queue.length >= this.config.batchSize) {\n void this.flush();\n }\n }\n\n /**\n * Force an immediate flush of all buffered events.\n * Returns a promise that resolves when the flush completes.\n */\n async flush(): Promise<void> {\n if (this.queue.length === 0 || this.isFlushing) {\n return;\n }\n\n this.isFlushing = true;\n const batch = this.queue.splice(0, this.config.batchSize);\n\n try {\n await this.sendBatch(batch);\n } catch {\n // Re-queue events that failed to send (prepend to maintain ordering)\n this.queue.unshift(...batch);\n } finally {\n this.isFlushing = false;\n }\n\n // If there are still events in the queue, flush again\n if (this.queue.length >= this.config.batchSize) {\n await this.flush();\n }\n }\n\n /**\n * Gracefully shut down the tracker. Flushes remaining events and\n * clears the flush interval.\n */\n async shutdown(): Promise<void> {\n this.isShutdown = true;\n this.stopFlushInterval();\n await this.flush();\n }\n\n /**\n * Send a batch of events to the Truth API with exponential backoff retry.\n */\n private async sendBatch(batch: EventEnvelope[]): Promise<void> {\n let lastError: unknown;\n\n for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {\n try {\n const response = await fetch(`${this.apiUrl}/api/events/ingest`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": this.config.apiKey,\n },\n body: JSON.stringify({ events: batch }),\n });\n\n if (response.ok) {\n return;\n }\n\n // Don't retry 4xx client errors (except 429)\n if (\n response.status >= 400 &&\n response.status < 500 &&\n response.status !== 429\n ) {\n return;\n }\n\n lastError = new Error(\n `HTTP ${response.status}: ${response.statusText}`,\n );\n } catch (error) {\n lastError = error;\n }\n\n // Exponential backoff with jitter\n if (attempt < MAX_RETRIES) {\n const delay = BASE_RETRY_DELAY_MS * 2 ** attempt;\n const jitter = Math.random() * delay * 0.5;\n await sleep(delay + jitter);\n }\n }\n\n throw lastError;\n }\n\n private startFlushInterval(): void {\n if (this.config.flushIntervalMs > 0) {\n this.flushTimer = setInterval(() => {\n void this.flush();\n }, this.config.flushIntervalMs);\n\n // Unref the timer so it doesn't prevent Node.js from exiting\n if (typeof this.flushTimer === \"object\" && \"unref\" in this.flushTimer) {\n this.flushTimer.unref();\n }\n }\n }\n\n private stopFlushInterval(): void {\n if (this.flushTimer !== null) {\n clearInterval(this.flushTimer);\n this.flushTimer = null;\n }\n }\n\n private registerShutdownHooks(): void {\n // Only register in Node.js environments\n if (typeof globalThis.process !== \"undefined\" && globalThis.process.on) {\n const shutdownHandler = () => {\n void this.shutdown();\n };\n\n globalThis.process.on(\"beforeExit\", shutdownHandler);\n globalThis.process.on(\"SIGTERM\", shutdownHandler);\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport {\n Tracker,\n generateUuidV7,\n DEFAULT_BATCH_SIZE,\n DEFAULT_FLUSH_INTERVAL_MS,\n};\nexport type { TrackerConfig };\n","/**\n * Web Push helpers for browser environments.\n *\n * Handles service worker registration, VAPID push subscription, and\n * message forwarding from the service worker to the main thread.\n */\n\nexport interface WebPushConfig {\n vapidPublicKey: string;\n serviceWorkerPath?: string;\n}\n\nexport function isWebPushSupported(): boolean {\n return (\n typeof window !== \"undefined\" &&\n \"serviceWorker\" in navigator &&\n \"PushManager\" in window\n );\n}\n\nexport async function registerServiceWorker(\n path = \"/truth-sw.js\",\n): Promise<ServiceWorkerRegistration> {\n return navigator.serviceWorker.register(path);\n}\n\nexport async function subscribeToPush(\n registration: ServiceWorkerRegistration,\n vapidPublicKey: string,\n): Promise<PushSubscription> {\n const existing = await registration.pushManager.getSubscription();\n if (existing) {\n return existing;\n }\n\n return registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: urlBase64ToUint8Array(\n vapidPublicKey,\n ) as unknown as ArrayBuffer,\n });\n}\n\nexport function subscriptionToJSON(sub: PushSubscription): {\n endpoint: string;\n keys: { p256dh: string; auth: string };\n} {\n const json = sub.toJSON();\n return {\n endpoint: sub.endpoint,\n keys: {\n p256dh: json.keys?.p256dh ?? \"\",\n auth: json.keys?.auth ?? \"\",\n },\n };\n}\n\nfunction urlBase64ToUint8Array(base64String: string): Uint8Array {\n const padding = \"=\".repeat((4 - (base64String.length % 4)) % 4);\n const base64 = (base64String + padding).replace(/-/g, \"+\").replace(/_/g, \"/\");\n const rawData = atob(base64);\n const outputArray = new Uint8Array(rawData.length);\n for (let i = 0; i < rawData.length; ++i) {\n outputArray[i] = rawData.charCodeAt(i);\n }\n return outputArray;\n}\n\nexport function onServiceWorkerMessage(\n type: string,\n callback: (payload: unknown) => void,\n): () => void {\n if (typeof navigator === \"undefined\" || !(\"serviceWorker\" in navigator)) {\n return () => {};\n }\n const handler = (event: MessageEvent) => {\n if (event.data?.type === type) {\n callback(event.data.payload);\n }\n };\n navigator.serviceWorker.addEventListener(\"message\", handler);\n return () => navigator.serviceWorker.removeEventListener(\"message\", handler);\n}\n","/**\n * TruthClient -- main entry point for the @hipnation-truth/sdk package.\n *\n * Provides:\n * - `.patients` Resource-based patient data access (Convex-backed)\n * - `.appointments` Resource-based appointment data access (Convex-backed)\n * - `.ehr` EHR proxy access (Elation, Hint)\n * - `.messages` Messaging proxy access (Dialpad)\n * - `.track()` Fire-and-forget event tracking (batched HTTP -> Truth API)\n * - `.identify()` Set default actor context for subsequent events\n * - `.flush()` Force flush of buffered events (for graceful shutdown)\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport { AuthAwareConvexHttpClient } from \"./auth-convex-client\";\nimport { AppointmentResource } from \"./resources/appointments\";\nimport { AttachmentsResource } from \"./resources/attachments\";\nimport { CareInboxResource } from \"./resources/care-inbox\";\nimport { ConversationsResource } from \"./resources/conversations\";\nimport { MessagesResource } from \"./resources/dialpad\";\nimport { EhrResource } from \"./resources/ehr\";\nimport { NotesResource } from \"./resources/notes\";\nimport { NotificationsResource } from \"./resources/notifications\";\nimport { PatientDetailsResource } from \"./resources/patient-details\";\nimport { PatientResource } from \"./resources/patients\";\nimport { PhysiciansResource } from \"./resources/physicians\";\nimport { RemindersResource } from \"./resources/reminders\";\nimport { ReportsResource } from \"./resources/reports\";\nimport { TasksResource } from \"./resources/tasks\";\nimport { TranslationResource } from \"./resources/translation\";\nimport { UserSettingsResource } from \"./resources/user-settings\";\nimport type {\n EventPayloadMap,\n EventType,\n TrackOptions,\n} from \"./tracking/events\";\nimport {\n DEFAULT_BATCH_SIZE,\n DEFAULT_FLUSH_INTERVAL_MS,\n Tracker,\n} from \"./tracking/tracker\";\nimport type { ActorContext, TruthClientConfig } from \"./types/config\";\nimport {\n isWebPushSupported,\n registerServiceWorker,\n subscribeToPush,\n subscriptionToJSON,\n} from \"./web-push\";\n\n// ---------------------------------------------------------------------------\n// Environment -> Convex URL mapping\n// ---------------------------------------------------------------------------\n\n// Environment → Convex deployment URL.\n//\n// Topology mirrors API_URLS in tracker.ts:\n// local / staging / stg / sandbox → sandbox Convex (courteous-duck-623)\n// uat / production → production Convex (gallant-gecko-217)\n//\n// UAT shares production resources. Staging is the isolated sandbox env.\nconst CONVEX_URLS: Record<string, string> = {\n local: \"https://courteous-duck-623.convex.cloud\",\n staging: \"https://courteous-duck-623.convex.cloud\",\n stg: \"https://courteous-duck-623.convex.cloud\",\n sandbox: \"https://courteous-duck-623.convex.cloud\",\n uat: \"https://gallant-gecko-217.convex.cloud\",\n production: \"https://gallant-gecko-217.convex.cloud\",\n};\n\n// ---------------------------------------------------------------------------\n// TruthClient\n// ---------------------------------------------------------------------------\n\nclass TruthClient {\n /** Patient data resource (Convex-backed) */\n readonly patients: PatientResource;\n\n /** Appointment data resource (Convex-backed) */\n readonly appointments: AppointmentResource;\n\n /** EHR proxy — typed access to Elation and Hint APIs through Truth */\n readonly ehr: EhrResource;\n\n /** Messaging proxy — typed access to Dialpad APIs through Truth */\n readonly messages: MessagesResource;\n\n /** Conversation reminders (Convex-backed, durable scheduler) */\n readonly reminders: RemindersResource;\n\n /** Translation (Azure Translator proxy) */\n readonly translation: TranslationResource;\n\n /** Tasks (Convex-backed) */\n readonly tasks: TasksResource;\n\n /** Patient details — merged Hint + Elation lookups via Truth API */\n readonly patientDetails: PatientDetailsResource;\n\n /** Attachments — presigned S3 upload/download + Convex metadata */\n readonly attachments: AttachmentsResource;\n\n /** Reports — member activation report (Truth API) */\n readonly reports: ReportsResource;\n\n /** Notes — push formatted notes to Elation */\n readonly notes: NotesResource;\n\n /** Physicians (Convex-backed cache from Elation) */\n readonly physicians: PhysiciansResource;\n\n /** Push / web notifications (AWS End User Messaging) */\n readonly notifications: NotificationsResource;\n\n /** Conversation-tied writes — notes, tasks, outbound messages. */\n readonly conversations: ConversationsResource;\n\n /** Care-team email inbox — link/unlink and (gated) send via oRPC. */\n readonly careInbox: CareInboxResource;\n\n /** User settings — notification preferences (Convex-backed) */\n readonly userSettings: UserSettingsResource;\n\n private readonly convex: ConvexHttpClient;\n private readonly tracker: Tracker;\n private readonly _getAuthToken?: TruthClientConfig[\"getAuthToken\"];\n private _vapidPublicKey: string | null = null;\n private _webPushReady: Promise<void> | null = null;\n private readonly _serviceWorkerPath: string;\n\n /**\n * Builds the Convex client and event tracker from `config`, then wires up\n * every resource (patients, appointments, EHR proxy, reports, etc.) so\n * each shares the same Convex connection / API base URL / auth token\n * fetcher. When running in a browser that supports web push and the\n * caller hasn't opted out, kicks off best-effort service-worker\n * registration and push subscription in the background.\n */\n constructor(config: TruthClientConfig) {\n // Resolve Convex URL\n const convexUrl =\n config.convexUrl ?? CONVEX_URLS[config.environment] ?? CONVEX_URLS.local;\n\n // Initialize Convex HTTP client for data access. When the host app\n // injects `getAuthToken`, every call carries the user's Clerk JWT\n // (refreshed per call — see AuthAwareConvexHttpClient).\n this.convex = new AuthAwareConvexHttpClient(convexUrl, config.getAuthToken);\n\n // Initialize event tracker\n this.tracker = new Tracker({\n apiKey: config.apiKey,\n environment: config.environment,\n source: config.source ?? \"unknown\",\n sourceVersion: config.sourceVersion ?? \"unknown\",\n tenantId: config.tenantId ?? \"\",\n batchSize: config.batchSize ?? DEFAULT_BATCH_SIZE,\n flushIntervalMs: config.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS,\n apiBaseUrl: config.apiBaseUrl,\n });\n\n const apiUrl = this.tracker.apiUrl;\n\n // Initialize resources\n this.patients = new PatientResource(this.convex);\n this.appointments = new AppointmentResource(this.convex);\n this.ehr = new EhrResource(apiUrl, config.apiKey, config.getAuthToken);\n this.messages = new MessagesResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.reminders = new RemindersResource(this.convex);\n this.translation = new TranslationResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.tasks = new TasksResource(this.convex);\n this.patientDetails = new PatientDetailsResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.attachments = new AttachmentsResource(\n apiUrl,\n config.apiKey,\n this.convex,\n config.getAuthToken,\n );\n this.reports = new ReportsResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.notes = new NotesResource(apiUrl, config.apiKey, config.getAuthToken);\n this.physicians = new PhysiciansResource(this.convex);\n this.notifications = new NotificationsResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.conversations = new ConversationsResource(\n apiUrl,\n config.apiKey,\n this.convex,\n config.getAuthToken,\n );\n this.careInbox = new CareInboxResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.userSettings = new UserSettingsResource(this.convex);\n this._getAuthToken = config.getAuthToken;\n this._serviceWorkerPath = config.serviceWorkerPath ?? \"/truth-sw.js\";\n\n if (\n typeof window !== \"undefined\" &&\n isWebPushSupported() &&\n config.autoInitServiceWorker !== false\n ) {\n this._webPushReady = this.initWebPush();\n }\n }\n\n /** The VAPID public key fetched during web-push init, or `null` until `webPushReady` resolves (or if push is unsupported/disabled). */\n get vapidPublicKey(): string | null {\n return this._vapidPublicKey;\n }\n\n /** 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). */\n get webPushReady(): Promise<void> | null {\n return this._webPushReady;\n }\n\n /**\n * When a Clerk token fetcher is configured (publishable-key clients),\n * the VAPID endpoint is auth-gated — calling it before the session has\n * hydrated 401s and strands web-push in the \"no key\" path. Wait\n * (briefly, bounded) for a token to become available first. No fetcher\n * → resolve immediately (secret-key path is unaffected).\n */\n private async waitForAuthToken(): Promise<void> {\n if (!this._getAuthToken) {\n return;\n }\n for (let attempt = 0; attempt < 20; attempt++) {\n try {\n if (await this._getAuthToken()) {\n return;\n }\n } catch {\n /* keep waiting */\n }\n await new Promise((resolve) => setTimeout(resolve, 500));\n }\n }\n\n /**\n * Best-effort web-push bootstrap: waits for auth (if configured), fetches\n * the VAPID key, registers the service worker, subscribes to push, and\n * registers the device with a placeholder `__pending__` userId (the\n * backend reconciles this once the real user is known). Any failure\n * along the way is swallowed — push notifications are opportunistic and\n * must never break client construction.\n */\n private async initWebPush(): Promise<void> {\n try {\n await this.waitForAuthToken();\n const key = await this.notifications.getVapidKey();\n if (!key) {\n return;\n }\n this._vapidPublicKey = key;\n\n const registration = await registerServiceWorker(this._serviceWorkerPath);\n await navigator.serviceWorker.ready;\n const subscription = await subscribeToPush(registration, key);\n const subJSON = subscriptionToJSON(subscription);\n\n await this.notifications.registerDevice({\n userId: \"__pending__\",\n platform: \"web\",\n webPushSubscription: subJSON,\n locale: navigator.language,\n timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n });\n } catch {\n // Web push init is best-effort — don't break the client.\n }\n }\n\n /**\n * The resolved Truth API base URL for this environment.\n * Use this when making HTTP calls to Truth's proxy endpoints\n * (e.g., EHR proxy, messages proxy).\n *\n * @example\n * ```ts\n * const url = `${truth.apiBaseUrl}/api/ehr/elation/patients/123`;\n * ```\n */\n get apiBaseUrl(): string {\n return this.tracker.apiUrl;\n }\n\n /**\n * Track an event. Fire-and-forget -- the event is buffered internally\n * and flushed in batches to the Truth API.\n *\n * @example\n * ```ts\n * truth.track('conversation.message_sent.v1', {\n * channel: 'sms',\n * direction: 'outbound',\n * message_chars: 140,\n * has_attachment: false,\n * provider_system: 'dialpad',\n * });\n * ```\n */\n track<T extends EventType>(\n eventType: T,\n payload: EventPayloadMap[T],\n options?: TrackOptions,\n ): void {\n this.tracker.track(eventType, payload, options);\n }\n\n /**\n * Set the default actor context for all subsequent tracked events.\n * Can be overridden per-event via TrackOptions.\n *\n * @example\n * ```ts\n * truth.identify('user_123', 'user');\n * ```\n */\n identify(actorId: string, actorType: ActorContext[\"actorType\"]): void {\n this.tracker.setActor({ actorId, actorType });\n }\n\n /**\n * Flush all buffered events immediately. Returns a Promise that resolves\n * when the flush completes. Use this for graceful shutdown.\n *\n * @example\n * ```ts\n * process.on('SIGTERM', async () => {\n * await truth.flush();\n * process.exit(0);\n * });\n * ```\n */\n async flush(): Promise<void> {\n await this.tracker.flush();\n }\n\n /**\n * Gracefully shut down the client. Flushes all pending events and\n * releases resources.\n */\n async destroy(): Promise<void> {\n await this.tracker.shutdown();\n }\n}\n\nexport { TruthClient };\n","/**\n * `createCareInboxSource` — a promise-based object with exactly the method\n * set of comhub's `CareInboxSource` (lib/email/careInboxSource.ts), so the\n * comhub adapter is a pass-through. Reads are one-shot Convex queries\n * (never persisted); link/unlink/send go through `CareInboxResource`.\n *\n * Every rejection is a `CareInboxError` (`Error & { code }` with the comhub\n * code set). `getThread` rejects `unavailable` when the feature flag is off\n * (the query returns null then). In React use `useCareInboxSource()` from\n * `@hipnation-truth/sdk/react`, which rebuilds the source when Convex auth\n * flips so comhub's query hooks refetch.\n */\n\nimport type { FunctionReference } from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\nimport {\n CareInboxError,\n type CareInboxMailboxAccess,\n type CareInboxResource,\n type CareInboxThreadDetail,\n type EmailMailboxAccessView,\n type EmailThreadBodiesView,\n type EmailThreadDetailView,\n type EmailThreadPageView,\n type LinkMessageArgs,\n type LinkResult,\n type ListThreadsArgs,\n type MarkEmailThreadReadResult,\n type MarkReadArgs,\n type MarkReadResult,\n type PatientLinkCandidate,\n type SendEmailArgs,\n type SendReplyArgs,\n type SendResult,\n type ThreadListFilter,\n type ThreadPage,\n toCareInboxError,\n toEmailThreadDetail,\n toMailboxAccess,\n toMarkReadResult,\n toThreadPage,\n type UnlinkedEmailPageView,\n type UnlinkMessageArgs,\n} from \"./care-inbox\";\n\n// ---------------------------------------------------------------------------\n// Convex function references (shared with the React hooks)\n// ---------------------------------------------------------------------------\n\nexport const careInboxRefs = {\n listThreadsForUser: makeFunctionReference<\n \"query\",\n {\n mailboxId?: string;\n filter?: ThreadListFilter;\n cursor?: string | null;\n limit?: number;\n },\n EmailThreadPageView\n >(\"careInboxQueries:listThreadsForUser\"),\n getThread: makeFunctionReference<\n \"query\",\n { threadId: string },\n EmailThreadDetailView | null\n >(\"careInboxQueries:getThread\"),\n listUnlinked: makeFunctionReference<\n \"query\",\n { mailboxId: string; cursor?: string | null; limit?: number },\n UnlinkedEmailPageView\n >(\"careInboxQueries:listUnlinked\"),\n unreadEmailCount: makeFunctionReference<\n \"query\",\n { mailboxId?: string },\n number\n >(\"careInboxQueries:unreadEmailCount\"),\n listMailboxesForUser: makeFunctionReference<\n \"query\",\n Record<string, never>,\n EmailMailboxAccessView\n >(\"careInboxQueries:listMailboxesForUser\"),\n searchPatientsForLink: makeFunctionReference<\n \"query\",\n { q: string },\n PatientLinkCandidate[]\n >(\"careInboxQueries:searchPatientsForLink\"),\n markRead: makeFunctionReference<\n \"mutation\",\n { threadId: string },\n MarkEmailThreadReadResult\n >(\"careInboxReads:markRead\"),\n openThreadBodies: makeFunctionReference<\n \"mutation\",\n { threadId: string },\n EmailThreadBodiesView\n >(\"careInboxReads:openThreadBodies\"),\n};\n\n/** Optional args, minus keys whose value is undefined (Convex rejects them). */\nexport function compactArgs<T extends Record<string, unknown>>(args: T): T {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(args)) {\n if (v !== undefined) {\n out[k] = v;\n }\n }\n return out as T;\n}\n\n// ---------------------------------------------------------------------------\n// Source\n// ---------------------------------------------------------------------------\n\n/** The Convex surface the source needs (`ConvexReactClient` satisfies it). */\nexport interface CareInboxConvexClient {\n query(\n ref: FunctionReference<\"query\">,\n args: Record<string, unknown>,\n ): Promise<unknown>;\n mutation(\n ref: FunctionReference<\"mutation\">,\n args: Record<string, unknown>,\n ): Promise<unknown>;\n}\n\nexport interface CareInboxSourceDeps {\n convex: CareInboxConvexClient;\n careInbox: Pick<\n CareInboxResource,\n \"linkMessage\" | \"unlinkMessage\" | \"replyToThread\" | \"composeEmail\"\n >;\n}\n\n/** Method set of comhub's `CareInboxSource` (minus optional `subscribe`). */\nexport interface CareInboxSdkSource {\n listThreads(args?: ListThreadsArgs): Promise<ThreadPage>;\n getUnreadCount(args?: { mailboxId?: string }): Promise<number>;\n getThread(threadId: string): Promise<CareInboxThreadDetail>;\n listMailboxesForUser(): Promise<CareInboxMailboxAccess>;\n searchPatientsForLink(query: string): Promise<PatientLinkCandidate[]>;\n linkMessage(args: LinkMessageArgs): Promise<LinkResult>;\n unlinkMessage(args: UnlinkMessageArgs): Promise<LinkResult>;\n sendReply(args: SendReplyArgs): Promise<SendResult>;\n sendEmail(args: SendEmailArgs): Promise<SendResult>;\n markRead(args: MarkReadArgs): Promise<MarkReadResult>;\n}\n\nasync function guarded<T>(run: () => Promise<T>): Promise<T> {\n try {\n return await run();\n } catch (err) {\n throw toCareInboxError(err);\n }\n}\n\nexport function createCareInboxSource({\n convex,\n careInbox,\n}: CareInboxSourceDeps): CareInboxSdkSource {\n const q = <T>(ref: FunctionReference<\"query\">, args: object) =>\n convex.query(\n ref,\n compactArgs(args as Record<string, unknown>),\n ) as Promise<T>;\n\n return {\n listThreads: (args = {}) =>\n guarded(async () =>\n toThreadPage(\n await q<EmailThreadPageView>(careInboxRefs.listThreadsForUser, {\n mailboxId: args.mailboxId,\n filter: args.filter,\n cursor: args.cursor,\n limit: args.limit,\n }),\n ),\n ),\n getUnreadCount: (args = {}) =>\n guarded(() =>\n q<number>(careInboxRefs.unreadEmailCount, {\n mailboxId: args.mailboxId,\n }),\n ),\n getThread: (threadId) =>\n guarded(async () => {\n const detail = await q<EmailThreadDetailView | null>(\n careInboxRefs.getThread,\n { threadId },\n );\n if (!detail) {\n throw new CareInboxError(\"unavailable\");\n }\n return toEmailThreadDetail(detail);\n }),\n listMailboxesForUser: () =>\n guarded(async () =>\n toMailboxAccess(\n await q<EmailMailboxAccessView>(\n careInboxRefs.listMailboxesForUser,\n {},\n ),\n ),\n ),\n searchPatientsForLink: (query) =>\n guarded(() =>\n q<PatientLinkCandidate[]>(careInboxRefs.searchPatientsForLink, {\n q: query,\n }),\n ),\n linkMessage: (args) => guarded(() => careInbox.linkMessage(args)),\n unlinkMessage: (args) => guarded(() => careInbox.unlinkMessage(args)),\n sendReply: (args) => guarded(() => careInbox.replyToThread(args)),\n sendEmail: (args) => guarded(() => careInbox.composeEmail(args)),\n markRead: ({ threadId }) =>\n guarded(async () =>\n toMarkReadResult(\n (await convex.mutation(careInboxRefs.markRead, {\n threadId,\n })) as MarkEmailThreadReadResult,\n ),\n ),\n };\n}\n","/**\n * Typed event definitions for the Truth Platform event store.\n *\n * All 26 event types from the Communication Hub -> Truth Event Store Contract.\n * Events are grouped by domain and include typed payload interfaces.\n */\n\n// ---------------------------------------------------------------------------\n// Event type constants\n// ---------------------------------------------------------------------------\n\nconst CONVERSATION_EVENTS = {\n created: \"conversation.created.v1\",\n messageSent: \"conversation.message_sent.v1\",\n messageReceived: \"conversation.message_received.v1\",\n markedRead: \"conversation.marked_read.v1\",\n attachmentUploaded: \"conversation.attachment_uploaded.v1\",\n attachmentDownloaded: \"conversation.attachment_downloaded.v1\",\n} as const;\n\nconst CALL_EVENTS = {\n initiated: \"call.initiated.v1\",\n connected: \"call.connected.v1\",\n ended: \"call.ended.v1\",\n missed: \"call.missed.v1\",\n} as const;\n\nconst TASK_EVENTS = {\n created: \"task.created.v1\",\n assigned: \"task.assigned.v1\",\n statusChanged: \"task.status_changed.v1\",\n} as const;\n\nconst REMINDER_EVENTS = {\n scheduled: \"reminder.scheduled.v1\",\n triggered: \"reminder.triggered.v1\",\n} as const;\n\nconst TRANSLATION_EVENTS = {\n requested: \"translation.requested.v1\",\n completed: \"translation.completed.v1\",\n} as const;\n\nconst NOTIFICATION_EVENTS = {\n sent: \"notification.sent.v1\",\n delivered: \"notification.delivered.v1\",\n opened: \"notification.opened.v1\",\n} as const;\n\nconst PROVIDER_EVENTS = {\n syncStarted: \"provider.sync_started.v1\",\n syncSucceeded: \"provider.sync_succeeded.v1\",\n syncFailed: \"provider.sync_failed.v1\",\n} as const;\n\nconst AUTH_EVENTS = {\n loginSucceeded: \"auth.login_succeeded.v1\",\n loginFailed: \"auth.login_failed.v1\",\n} as const;\n\nconst SECURITY_EVENTS = {\n accessDenied: \"security.access_denied.v1\",\n} as const;\n\n/**\n * All event type constants grouped by domain.\n */\nconst EVENT_TYPES = {\n conversation: CONVERSATION_EVENTS,\n call: CALL_EVENTS,\n task: TASK_EVENTS,\n reminder: REMINDER_EVENTS,\n translation: TRANSLATION_EVENTS,\n notification: NOTIFICATION_EVENTS,\n provider: PROVIDER_EVENTS,\n auth: AUTH_EVENTS,\n security: SECURITY_EVENTS,\n} as const;\n\n// ---------------------------------------------------------------------------\n// Event type union\n// ---------------------------------------------------------------------------\n\ntype ConversationEventType =\n (typeof CONVERSATION_EVENTS)[keyof typeof CONVERSATION_EVENTS];\ntype CallEventType = (typeof CALL_EVENTS)[keyof typeof CALL_EVENTS];\ntype TaskEventType = (typeof TASK_EVENTS)[keyof typeof TASK_EVENTS];\ntype ReminderEventType = (typeof REMINDER_EVENTS)[keyof typeof REMINDER_EVENTS];\ntype TranslationEventType =\n (typeof TRANSLATION_EVENTS)[keyof typeof TRANSLATION_EVENTS];\ntype NotificationEventType =\n (typeof NOTIFICATION_EVENTS)[keyof typeof NOTIFICATION_EVENTS];\ntype ProviderEventType = (typeof PROVIDER_EVENTS)[keyof typeof PROVIDER_EVENTS];\ntype AuthEventType = (typeof AUTH_EVENTS)[keyof typeof AUTH_EVENTS];\ntype SecurityEventType = (typeof SECURITY_EVENTS)[keyof typeof SECURITY_EVENTS];\n\n/**\n * Union of all 26 registered event type strings.\n */\ntype EventType =\n | ConversationEventType\n | CallEventType\n | TaskEventType\n | ReminderEventType\n | TranslationEventType\n | NotificationEventType\n | ProviderEventType\n | AuthEventType\n | SecurityEventType;\n\n// ---------------------------------------------------------------------------\n// Payload interfaces (per the contract doc)\n// ---------------------------------------------------------------------------\n\ninterface ConversationCreatedPayload {\n channel: string;\n origin_system: string;\n participant_count: number;\n}\n\ninterface ConversationMessageSentPayload {\n channel: string;\n direction: string;\n message_chars: number;\n has_attachment: boolean;\n provider_system: string;\n}\n\ninterface ConversationMessageReceivedPayload {\n channel: string;\n direction: string;\n message_chars: number;\n provider_system: string;\n}\n\ninterface ConversationMarkedReadPayload {\n read_by_actor_id: string;\n unread_count_before: number;\n unread_count_after: number;\n}\n\ninterface ConversationAttachmentUploadedPayload {\n attachment_id: string;\n mime_type: string;\n size_bytes: number;\n storage_class: string;\n}\n\ninterface ConversationAttachmentDownloadedPayload {\n attachment_id: string;\n download_actor_type: string;\n access_path: string;\n}\n\ninterface CallInitiatedPayload {\n direction: string;\n provider_system: string;\n from_number_ref: string;\n to_number_ref: string;\n}\n\ninterface CallConnectedPayload {\n provider_system: string;\n ring_duration_ms: number;\n}\n\ninterface CallEndedPayload {\n provider_system: string;\n duration_ms: number;\n end_reason: string;\n disposition: string;\n}\n\ninterface CallMissedPayload {\n provider_system: string;\n miss_reason: string;\n}\n\ninterface TaskCreatedPayload {\n task_id: string;\n created_by: string;\n assigned_to: string;\n priority: string;\n due_at: string;\n}\n\ninterface TaskAssignedPayload {\n task_id: string;\n assigned_to: string;\n assigned_by: string;\n}\n\ninterface TaskStatusChangedPayload {\n task_id: string;\n status_from: string;\n status_to: string;\n changed_by: string;\n}\n\ninterface ReminderScheduledPayload {\n reminder_id: string;\n conversation_id: string;\n scheduled_for: string;\n scheduled_by: string;\n}\n\ninterface ReminderTriggeredPayload {\n reminder_id: string;\n trigger_result: string;\n notification_attempted: boolean;\n}\n\ninterface TranslationRequestedPayload {\n target_language: string;\n source_language: string;\n char_count: number;\n mode: string;\n}\n\ninterface TranslationCompletedPayload {\n target_language: string;\n provider: string;\n latency_ms: number;\n success: boolean;\n error_code?: string;\n}\n\ninterface NotificationSentPayload {\n notification_id: string;\n channel: string;\n platform: string;\n recipient_ref: string;\n success: boolean;\n}\n\ninterface NotificationDeliveredPayload {\n notification_id: string;\n platform: string;\n delivered_at: string;\n}\n\ninterface NotificationOpenedPayload {\n notification_id: string;\n platform: string;\n opened_at: string;\n}\n\ninterface ProviderSyncStartedPayload {\n provider_system: string;\n operation: string;\n scope: string;\n batch_id: string;\n}\n\ninterface ProviderSyncSucceededPayload {\n provider_system: string;\n operation: string;\n batch_id: string;\n records_processed: number;\n duration_ms: number;\n}\n\ninterface ProviderSyncFailedPayload {\n provider_system: string;\n operation: string;\n batch_id: string;\n error_code: string;\n retryable: boolean;\n}\n\ninterface AuthLoginSucceededPayload {\n auth_provider: string;\n platform: string;\n session_ref: string;\n}\n\ninterface AuthLoginFailedPayload {\n auth_provider: string;\n platform: string;\n failure_code: string;\n}\n\ninterface SecurityAccessDeniedPayload {\n resource: string;\n policy: string;\n reason_code: string;\n actor_id: string;\n}\n\n// ---------------------------------------------------------------------------\n// Event type -> payload mapping\n// ---------------------------------------------------------------------------\n\n/**\n * Maps each event type string to its required payload interface.\n */\ninterface EventPayloadMap {\n \"conversation.created.v1\": ConversationCreatedPayload;\n \"conversation.message_sent.v1\": ConversationMessageSentPayload;\n \"conversation.message_received.v1\": ConversationMessageReceivedPayload;\n \"conversation.marked_read.v1\": ConversationMarkedReadPayload;\n \"conversation.attachment_uploaded.v1\": ConversationAttachmentUploadedPayload;\n \"conversation.attachment_downloaded.v1\": ConversationAttachmentDownloadedPayload;\n \"call.initiated.v1\": CallInitiatedPayload;\n \"call.connected.v1\": CallConnectedPayload;\n \"call.ended.v1\": CallEndedPayload;\n \"call.missed.v1\": CallMissedPayload;\n \"task.created.v1\": TaskCreatedPayload;\n \"task.assigned.v1\": TaskAssignedPayload;\n \"task.status_changed.v1\": TaskStatusChangedPayload;\n \"reminder.scheduled.v1\": ReminderScheduledPayload;\n \"reminder.triggered.v1\": ReminderTriggeredPayload;\n \"translation.requested.v1\": TranslationRequestedPayload;\n \"translation.completed.v1\": TranslationCompletedPayload;\n \"notification.sent.v1\": NotificationSentPayload;\n \"notification.delivered.v1\": NotificationDeliveredPayload;\n \"notification.opened.v1\": NotificationOpenedPayload;\n \"provider.sync_started.v1\": ProviderSyncStartedPayload;\n \"provider.sync_succeeded.v1\": ProviderSyncSucceededPayload;\n \"provider.sync_failed.v1\": ProviderSyncFailedPayload;\n \"auth.login_succeeded.v1\": AuthLoginSucceededPayload;\n \"auth.login_failed.v1\": AuthLoginFailedPayload;\n \"security.access_denied.v1\": SecurityAccessDeniedPayload;\n}\n\n// ---------------------------------------------------------------------------\n// Event envelope\n// ---------------------------------------------------------------------------\n\n/**\n * Subject references for the event. Uses tokenized references only -- no PHI.\n */\ninterface EventSubject {\n patient_ref?: string;\n conversation_id?: string;\n task_id?: string;\n call_id?: string;\n}\n\n/**\n * Actor who triggered the event.\n */\ninterface EventActor {\n actor_id: string;\n actor_type: \"user\" | \"system\" | \"webhook\";\n}\n\n/**\n * Compliance metadata for the event.\n */\ninterface EventCompliance {\n pii_level: \"none\" | \"limited\" | \"full\";\n contains_phi: boolean;\n consent_context: string;\n retention_class: string;\n}\n\n/**\n * Canonical event envelope. Every tracked event is wrapped in this structure\n * before being sent to the Truth API.\n */\ninterface EventEnvelope {\n event_id: string;\n event_type: string;\n schema_version: number;\n occurred_at: string;\n received_at: string;\n source: string;\n source_version: string;\n tenant_id: string;\n actor?: EventActor;\n subject?: EventSubject;\n compliance?: EventCompliance;\n payload: Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Track options (per-call overrides)\n// ---------------------------------------------------------------------------\n\n/**\n * Optional overrides when calling truth.track().\n */\ninterface TrackOptions {\n /** Override the default actor for this event */\n actor?: EventActor;\n\n /** Subject references for this event */\n subject?: EventSubject;\n\n /** Compliance metadata for this event */\n compliance?: EventCompliance;\n\n /** Override the default tenant ID for this event */\n tenantId?: string;\n\n /** Override the occurred_at timestamp (ISO 8601) */\n occurredAt?: string;\n}\n\nexport {\n EVENT_TYPES,\n CONVERSATION_EVENTS,\n CALL_EVENTS,\n TASK_EVENTS,\n REMINDER_EVENTS,\n TRANSLATION_EVENTS,\n NOTIFICATION_EVENTS,\n PROVIDER_EVENTS,\n AUTH_EVENTS,\n SECURITY_EVENTS,\n};\n\nexport type {\n EventType,\n ConversationEventType,\n CallEventType,\n TaskEventType,\n ReminderEventType,\n TranslationEventType,\n NotificationEventType,\n ProviderEventType,\n AuthEventType,\n SecurityEventType,\n EventPayloadMap,\n EventEnvelope,\n EventActor,\n EventSubject,\n EventCompliance,\n TrackOptions,\n ConversationCreatedPayload,\n ConversationMessageSentPayload,\n ConversationMessageReceivedPayload,\n ConversationMarkedReadPayload,\n ConversationAttachmentUploadedPayload,\n ConversationAttachmentDownloadedPayload,\n CallInitiatedPayload,\n CallConnectedPayload,\n CallEndedPayload,\n CallMissedPayload,\n TaskCreatedPayload,\n TaskAssignedPayload,\n TaskStatusChangedPayload,\n ReminderScheduledPayload,\n ReminderTriggeredPayload,\n TranslationRequestedPayload,\n TranslationCompletedPayload,\n NotificationSentPayload,\n NotificationDeliveredPayload,\n NotificationOpenedPayload,\n ProviderSyncStartedPayload,\n ProviderSyncSucceededPayload,\n ProviderSyncFailedPayload,\n AuthLoginSucceededPayload,\n AuthLoginFailedPayload,\n SecurityAccessDeniedPayload,\n};\n","/**\n * Configuration interfaces for the Truth SDK.\n */\n\n/**\n * Environment options for the Truth platform.\n */\nconst ENVIRONMENTS = {\n local: \"local\",\n staging: \"staging\",\n stg: \"stg\",\n sandbox: \"sandbox\",\n uat: \"uat\",\n production: \"production\",\n} as const;\n\ntype Environment = (typeof ENVIRONMENTS)[keyof typeof ENVIRONMENTS];\n\n/**\n * Fetches a user-identity JWT for Convex calls. Return the token from\n * your identity provider's Clerk JWT template named \"convex\"\n * (e.g. `getToken({ template: \"convex\" })` from `@clerk/expo`), or\n * `null` when no user is signed in.\n *\n * Convex invokes this with `{ forceRefreshToken: true }` when the cached\n * token has expired — forward it to your provider (e.g. Clerk's\n * `getToken({ template: \"convex\", skipCache: opts?.forceRefreshToken })`)\n * so the refresh returns a fresh token rather than a stale cached one.\n */\ntype AuthTokenFetcher = (opts?: {\n forceRefreshToken?: boolean;\n}) => Promise<string | null | undefined>;\n\n/**\n * Configuration for initializing a TruthClient.\n */\ninterface TruthClientConfig {\n /** API key for authenticating with the Truth platform (e.g. \"hn_live_...\") */\n apiKey: string;\n\n /**\n * Per-call Clerk JWT fetcher for Convex data access. When provided,\n * every Convex query/mutation/action carries the caller's identity;\n * Convex deployments with `CLERK_AUTH_REQUIRED` enabled reject calls\n * without it. Omit for service contexts that don't act as a user.\n */\n getAuthToken?: AuthTokenFetcher;\n\n /** Target environment */\n environment: Environment;\n\n /** Override the default Convex URL for data access */\n convexUrl?: string;\n\n /** Event source identifier (e.g. \"communication-hub.backend\") */\n source?: string;\n\n /** Git SHA or version string for event source versioning */\n sourceVersion?: string;\n\n /** Default tenant (organization) ID for events */\n tenantId?: string;\n\n /** Number of events to buffer before flushing (default: 25) */\n batchSize?: number;\n\n /** Interval in milliseconds between automatic flushes (default: 5000) */\n flushIntervalMs?: number;\n\n /** Base URL for the Truth API (overrides environment-based default) */\n apiBaseUrl?: string;\n\n /**\n * Auto-register the service worker and subscribe to web push on init.\n * Only applies in browser environments with Push API support.\n * Default: true.\n */\n autoInitServiceWorker?: boolean;\n\n /** Path to the service worker file. Default: \"/truth-sw.js\" */\n serviceWorkerPath?: string;\n}\n\n/**\n * Actor context attached to tracked events.\n */\ninterface ActorContext {\n actorId: string;\n actorType: \"user\" | \"system\" | \"webhook\";\n}\n\n/**\n * Paginated result wrapper for list operations.\n */\ninterface PaginatedResult<T> {\n data: T[];\n cursor: string | null;\n hasMore: boolean;\n}\n\nexport { ENVIRONMENTS };\nexport type {\n AuthTokenFetcher,\n Environment,\n TruthClientConfig,\n ActorContext,\n PaginatedResult,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,SAAS,wBAAkD;AASpD,IAAM,4BAAN,MAAM,mCAAkC,iBAAiB;AAAA,EAG9D,YAAY,SAAiB,cAAiC;AAC5D,UAAM,OAAO;AACb,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOc,WAA0B;AAAA;AACtC,UAAI,CAAC,KAAK,cAAc;AACtB;AAAA,MACF;AACA,UAAI;AACF,cAAM,QAAQ,MAAM,KAAK,aAAa;AACtC,YAAI,OAAO;AACT,eAAK,QAAQ,KAAK;AAAA,QACpB,OAAO;AACL,eAAK,UAAU;AAAA,QACjB;AAAA,MACF,SAAQ;AAAA,MAER;AAAA,IACF;AAAA;AAAA,EAEe,MACb,UACG,MACiC;AAAA;AACpC,YAAM,KAAK,SAAS;AACpB,aAAO,uDAAM,cAAN,MAAY,OAAO,GAAG,IAAI;AAAA,IACnC;AAAA;AAAA,EAEe,SACb,aACG,MACoC;AAAA;AACvC,YAAM,KAAK,SAAS;AACpB,aAAO,uDAAM,iBAAN,MAAe,UAAU,GAAG,IAAI;AAAA,IACzC;AAAA;AAAA,EAEe,OACb,WACG,MACkC;AAAA;AACrC,YAAM,KAAK,SAAS;AACpB,aAAO,u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AAEA,IAAM,cAAc;AAAA,EAClB,WAAW;AAAA,EACX,WAAW;AAAA,EACX,OAAO;AAAA,EACP,QAAQ;AACV;AAEA,IAAM,cAAc;AAAA,EAClB,SAAS;AAAA,EACT,UAAU;AAAA,EACV,eAAe;AACjB;AAEA,IAAM,kBAAkB;AAAA,EACtB,WAAW;AAAA,EACX,WAAW;AACb;AAEA,IAAM,qBAAqB;AAAA,EACzB,WAAW;AAAA,EACX,WAAW;AACb;AAEA,IAAM,sBAAsB;AAAA,EAC1B,MAAM;AAAA,EACN,WAAW;AAAA,EACX,QAAQ;AACV;AAEA,IAAM,kBAAkB;AAAA,EACtB,aAAa;AAAA,EACb,eAAe;AAAA,EACf,YAAY;AACd;AAEA,IAAM,cAAc;AAAA,EAClB,gBAAgB;AAAA,EAChB,aAAa;AACf;AAEA,IAAM,kBAAkB;AAAA,EACtB,cAAc;AAChB;AAKA,IAAM,cAAc;AAAA,EAClB,cAAc;AAAA,EACd,MAAM;AAAA,EACN,MAAM;AAAA,EACN,UAAU;AAAA,EACV,aAAa;AAAA,EACb,cAAc;AAAA,EACd,UAAU;AAAA,EACV,MAAM;AAAA,EACN,UAAU;AACZ;;;ACtEA,IAAM,eAAe;AAAA,EACnB,OAAO;AAAA,EACP,SAAS;AAAA,EACT,KAAK;AAAA,EACL,SAAS;AAAA,EACT,KAAK;AAAA,EACL,YAAY;AACd;","names":["delay","makeFunctionReference","makeFunctionReference"]}
|
|
1
|
+
{"version":3,"sources":["../src/auth-convex-client.ts","../src/resources/appointments.ts","../src/resources/rest-auth.ts","../src/resources/attachments.ts","../src/resources/care-inbox.ts","../src/resources/conversations.ts","../src/resources/dialpad.ts","../src/resources/ehr.ts","../src/resources/notes.ts","../src/resources/notifications.ts","../src/resources/patient-details.ts","../src/react/elation-id.ts","../src/resources/patients.ts","../src/resources/physicians.ts","../src/resources/reminders.ts","../src/resources/reports.ts","../src/resources/tasks.ts","../src/resources/translation.ts","../src/resources/user-settings.ts","../src/tracking/tracker.ts","../src/web-push.ts","../src/client.ts","../src/resources/care-inbox-source.ts","../src/tracking/events.ts","../src/types/config.ts"],"sourcesContent":["/**\n * AuthAwareConvexHttpClient — ConvexHttpClient that refreshes the\n * caller's identity token before every call.\n *\n * `ConvexHttpClient.setAuth()` takes a static JWT, but Clerk's \"convex\"\n * template tokens are short-lived (60s). This subclass asks the\n * injected {@link AuthTokenFetcher} for a current token immediately\n * before each query/mutation/action — identity-provider SDKs (Clerk)\n * cache tokens internally and refresh on expiry, so this is cheap.\n *\n * With no fetcher configured it behaves exactly like the base client.\n */\nimport { ConvexHttpClient, type HttpMutationOptions } from \"convex/browser\";\nimport type {\n ArgsAndOptions,\n FunctionReference,\n FunctionReturnType,\n OptionalRestArgs,\n} from \"convex/server\";\nimport type { AuthTokenFetcher } from \"./types/config\";\n\nexport class AuthAwareConvexHttpClient extends ConvexHttpClient {\n private readonly getAuthToken?: AuthTokenFetcher;\n\n constructor(address: string, getAuthToken?: AuthTokenFetcher) {\n super(address);\n this.getAuthToken = getAuthToken;\n }\n\n /**\n * Pull a fresh token from the fetcher and apply it. A fetcher error\n * keeps the previously-applied token rather than dropping auth\n * mid-session.\n */\n private async syncAuth(): Promise<void> {\n if (!this.getAuthToken) {\n return;\n }\n try {\n const token = await this.getAuthToken();\n if (token) {\n this.setAuth(token);\n } else {\n this.clearAuth();\n }\n } catch {\n /* keep last known token */\n }\n }\n\n override async query<Query extends FunctionReference<\"query\">>(\n query: Query,\n ...args: OptionalRestArgs<Query>\n ): Promise<FunctionReturnType<Query>> {\n await this.syncAuth();\n return super.query(query, ...args);\n }\n\n override async mutation<Mutation extends FunctionReference<\"mutation\">>(\n mutation: Mutation,\n ...args: ArgsAndOptions<Mutation, HttpMutationOptions>\n ): Promise<FunctionReturnType<Mutation>> {\n await this.syncAuth();\n return super.mutation(mutation, ...args);\n }\n\n override async action<Action extends FunctionReference<\"action\">>(\n action: Action,\n ...args: OptionalRestArgs<Action>\n ): Promise<FunctionReturnType<Action>> {\n await this.syncAuth();\n return super.action(action, ...args);\n }\n}\n","/**\n * AppointmentResource provides data access to normalized appointment records\n * backed by Convex.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport type { Appointment, AppointmentListOptions } from \"../types/appointment\";\nimport type { PaginatedResult } from \"../types/config\";\n\nclass AppointmentResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convexClient: ConvexHttpClient) {\n this.convex = convexClient;\n }\n\n /**\n * Get an appointment by its Truth platform ID.\n */\n async get(id: string): Promise<Appointment | null> {\n try {\n const result = await this.convex.query(\n \"appointments:getById\" as never,\n { id } as never,\n );\n return (result as Appointment) ?? null;\n } catch {\n return null;\n }\n }\n\n /**\n * List appointments with optional filters, pagination, and limit.\n */\n async list(\n options?: AppointmentListOptions,\n ): Promise<PaginatedResult<Appointment>> {\n try {\n const result = await this.convex.query(\n \"appointments:list\" as never,\n {\n patientId: options?.patientId,\n startDate: options?.startDate,\n endDate: options?.endDate,\n status: options?.status,\n limit: options?.limit,\n cursor: options?.cursor,\n } as never,\n );\n\n const typed = result as PaginatedResult<Appointment> | undefined;\n\n return typed ?? { data: [], cursor: null, hasMore: false };\n } catch {\n return { data: [], cursor: null, hasMore: false };\n }\n }\n}\n\nexport { AppointmentResource };\n","/**\n * Shared auth-header builder for the HTTP-backed SDK resources.\n *\n * Every Truth REST/RPC call carries `X-API-Key`. When the host app wired\n * a `getAuthToken` (Clerk JWT fetcher), the caller's bearer token rides\n * alongside it — required once the application uses a publishable key\n * (`hn_pk_*`), which the API gate accepts only with a verified user JWT.\n */\nimport type { AuthTokenFetcher } from \"../types/config\";\n\nexport interface RestAuth {\n apiKey: string;\n getAuthToken?: AuthTokenFetcher;\n}\n\nexport interface BuildAuthHeadersOptions {\n json?: boolean;\n accept?: boolean;\n /**\n * When set, the route is JWT-gated (e.g. a `verifiedUserProcedure` like\n * the conversations send path). Silently degrading to key-only would 401\n * at the server and surface as a confusing \"error\" status in the UI, so\n * we instead retry token resolution with a short bounded backoff and\n * throw a clear auth error if no token can be obtained.\n */\n requireUserToken?: boolean;\n}\n\n/**\n * How many times `buildAuthHeaders` re-attempts token resolution when\n * `requireUserToken` is set and the first attempt yields null. The token\n * fetcher is transiently null on cold web loads, so a few short retries\n * cover the Clerk hydration gap without stalling the request.\n */\nconst REQUIRE_TOKEN_MAX_ATTEMPTS = 4;\n/** Base delay between token-resolution retries; grows linearly per attempt. */\nconst REQUIRE_TOKEN_RETRY_DELAY_MS = 150;\n\nfunction delay(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\n/**\n * Custom header carrying the user's `Bearer <jwt>`, mirrored alongside the\n * standard `Authorization` header.\n *\n * The Truth API is fronted by CloudFront with an OAC that SigV4-signs every\n * origin request to the IAM-protected Lambda function URL — that signing\n * OVERWRITES the viewer's `Authorization` header, so a `Bearer <jwt>` sent\n * there never reaches the handler (the server then sees no user token and a\n * `verifiedUserProcedure` like the SMS-send path 401s). A custom header is\n * forwarded untouched (same reason `X-API-Key` works), so we carry the JWT\n * here too; the API gate reads this first and falls back to `Authorization`.\n */\nconst USER_TOKEN_HEADER = \"X-Truth-Authorization\";\n\n/** Attach the user JWT to both the standard and CloudFront-safe headers. */\nfunction setUserToken(headers: Record<string, string>, token: string): void {\n headers.Authorization = `Bearer ${token}`;\n headers[USER_TOKEN_HEADER] = `Bearer ${token}`;\n}\n\n/**\n * Resolve the user JWT, swallowing fetcher errors as null. Used by both the\n * best-effort and required token paths.\n */\nasync function resolveAuthToken(\n getAuthToken: AuthTokenFetcher,\n): Promise<string | null> {\n try {\n const token = await getAuthToken();\n return token ?? null;\n } catch {\n return null;\n }\n}\n\n/**\n * Build request headers: `X-API-Key` always, `Authorization: Bearer\n * <jwt>` when a token is available, and `Content-Type: application/json`\n * when `json` is set.\n *\n * For best-effort routes a token-fetcher error (or null token) degrades to\n * key-only rather than failing the request. For `requireUserToken` routes\n * a null token is retried with a bounded backoff and, if still null, throws\n * so the caller surfaces a real auth error instead of a silent server 401.\n */\nexport async function buildAuthHeaders(\n auth: RestAuth,\n options?: BuildAuthHeadersOptions,\n): Promise<Record<string, string>> {\n const headers: Record<string, string> = {\n \"X-API-Key\": auth.apiKey,\n };\n if (options?.accept !== false) {\n headers.Accept = \"application/json\";\n }\n if (options?.json) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n\n if (options?.requireUserToken) {\n if (!auth.getAuthToken) {\n throw new Error(\n \"User authentication required to send a message, but no auth token provider is configured\",\n );\n }\n for (let attempt = 0; attempt < REQUIRE_TOKEN_MAX_ATTEMPTS; attempt++) {\n const token = await resolveAuthToken(auth.getAuthToken);\n if (token) {\n setUserToken(headers, token);\n return headers;\n }\n if (attempt < REQUIRE_TOKEN_MAX_ATTEMPTS - 1) {\n await delay(REQUIRE_TOKEN_RETRY_DELAY_MS * (attempt + 1));\n }\n }\n throw new Error(\n \"User authentication required to send a message — no auth token available\",\n );\n }\n\n if (auth.getAuthToken) {\n const token = await resolveAuthToken(auth.getAuthToken);\n if (token) {\n setUserToken(headers, token);\n }\n }\n return headers;\n}\n","/**\n * AttachmentsResource — presigned S3 upload/download + Convex metadata.\n *\n * Replaces CommHub's base64-in-Postgres attachment flow:\n * 1. client.attachments.createUploadUrl(...) → presigned PUT URL\n * 2. Client PUTs bytes directly to S3\n * 3. client.attachments.record(...) → writes Convex metadata\n * 4. client.attachments.getDownloadUrl(s3Key) → presigned GET URL\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\nexport interface CreateUploadUrlInput {\n fileName: string;\n mimeType: string;\n size: number;\n conversationId?: string;\n}\n\nexport interface CreateUploadUrlResult {\n uploadUrl: string;\n s3Key: string;\n expiresIn: number;\n applicationId: string | null;\n}\n\nexport interface GetDownloadUrlResult {\n url: string;\n expiresIn: number;\n}\n\nexport interface RecordAttachmentInput {\n s3Key: string;\n fileName: string;\n mimeType: string;\n size: number;\n conversationId?: string;\n uploadedBy: string;\n}\n\nexport interface Attachment {\n _id: string;\n s3Key: string;\n fileName: string;\n mimeType: string;\n size: number;\n conversationId?: string;\n uploadedBy: string;\n createdAt: string;\n}\n\nclass AttachmentsError extends Error {\n readonly status: number;\n\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Attachment ${operation} failed (HTTP ${status})`);\n this.name = \"AttachmentsError\";\n this.status = status;\n }\n}\n\nclass AttachmentsResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n private readonly convex: ConvexHttpClient;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n convexClient: ConvexHttpClient,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n this.convex = convexClient;\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n // PHI (patient photos / MMS media) — REQUIRE the user JWT. The server\n // hardens these routes to `verifiedUserProcedure`, so degrading to\n // key-only would 401. `requireUserToken` retries across the Clerk-\n // hydration gap and throws rather than silently sending key-only.\n headers: await buildAuthHeaders(this.auth, {\n json: true,\n requireUserToken: true,\n }),\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new AttachmentsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n async createUploadUrl(\n input: CreateUploadUrlInput,\n ): Promise<CreateUploadUrlResult> {\n return await this.post<CreateUploadUrlResult>(\n \"/attachments/upload-url\",\n input,\n );\n }\n\n async getDownloadUrl(\n s3Key: string,\n expiresIn?: number,\n ): Promise<GetDownloadUrlResult> {\n return await this.post<GetDownloadUrlResult>(\"/attachments/download-url\", {\n s3Key,\n expiresIn,\n });\n }\n\n async record(\n input: RecordAttachmentInput,\n ): Promise<{ attachmentId: string; s3Key: string }> {\n return (await this.convex.mutation(\n \"attachments:record\" as never,\n input as never,\n )) as { attachmentId: string; s3Key: string };\n }\n\n async get(attachmentId: string): Promise<Attachment | null> {\n try {\n const row = (await this.convex.query(\n \"attachments:getById\" as never,\n { attachmentId } as never,\n )) as Attachment | null;\n return row ?? null;\n } catch {\n return null;\n }\n }\n\n async listByConversation(conversationId: string): Promise<Attachment[]> {\n try {\n const rows = (await this.convex.query(\n \"attachments:listByConversation\" as never,\n { conversationId } as never,\n )) as Attachment[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n\n /**\n * One-shot upload: presign → PUT to S3 → record in Convex → return a\n * 7-day signed download URL ready to embed in an outbound SMS. Caller\n * passes the resulting `downloadUrl` to `messages.dialpad.sendSms` (or\n * the new `messages.sendAttachmentMessage`) to actually deliver it.\n *\n * Replaces CommHub's NestJS `/send-attachment` controller in a single\n * SDK call — no base64 round-trip, no legacy `/attachments/:id/download`\n * REST endpoint required.\n */\n async upload(input: {\n file: Blob | ArrayBuffer | Uint8Array;\n fileName: string;\n mimeType: string;\n size: number;\n conversationId?: string;\n uploadedBy: string;\n /** Download URL TTL in seconds. Default 7 days. */\n downloadExpiresIn?: number;\n }): Promise<{\n attachmentId: string;\n s3Key: string;\n downloadUrl: string;\n }> {\n const presigned = await this.createUploadUrl({\n fileName: input.fileName,\n mimeType: input.mimeType,\n size: input.size,\n conversationId: input.conversationId,\n });\n\n // Cast through `BodyInit` — Uint8Array is accepted by undici/fetch\n // at runtime but the lib.dom types only declare BufferSource so TS\n // doesn't see the overload. Same trick the AttachmentsResource\n // already uses elsewhere.\n const body: BodyInit =\n input.file instanceof Blob\n ? input.file\n : input.file instanceof Uint8Array\n ? (input.file as unknown as BodyInit)\n : (new Uint8Array(input.file) as unknown as BodyInit);\n\n // 30s timeout matches the legacy NestJS handler so a stuck S3 PUT\n // can't hang the calling UI thread indefinitely.\n const abort = new AbortController();\n const timer = setTimeout(() => abort.abort(), 30_000);\n let putRes: Response;\n try {\n putRes = await fetch(presigned.uploadUrl, {\n method: \"PUT\",\n headers: { \"Content-Type\": input.mimeType },\n body,\n signal: abort.signal,\n });\n } catch (err) {\n // AbortController fires DOMException(\"AbortError\"); rewrap as a\n // typed AttachmentsError(0, …) so callers' `instanceof\n // AttachmentsError` checks catch the timeout consistently with\n // every other failure mode here.\n const isAbort =\n err instanceof Error &&\n (err.name === \"AbortError\" || err.name === \"TimeoutError\");\n if (isAbort) {\n throw new AttachmentsError(\n \"s3-put\",\n 0,\n \"S3 upload timed out after 30s\",\n );\n }\n throw err;\n } finally {\n clearTimeout(timer);\n }\n if (!putRes.ok) {\n throw new AttachmentsError(\n \"s3-put\",\n putRes.status,\n `S3 PUT ${putRes.status} for ${presigned.s3Key}`,\n );\n }\n\n const recorded = await this.record({\n s3Key: presigned.s3Key,\n fileName: input.fileName,\n mimeType: input.mimeType,\n size: input.size,\n conversationId: input.conversationId,\n uploadedBy: input.uploadedBy,\n });\n\n const signed = await this.getDownloadUrl(\n presigned.s3Key,\n input.downloadExpiresIn ?? 7 * 24 * 3600,\n );\n\n return {\n attachmentId: recorded.attachmentId,\n s3Key: presigned.s3Key,\n downloadUrl: signed.url,\n };\n }\n}\n\nexport { AttachmentsResource, AttachmentsError };\n","/**\n * CareInboxResource — care-team shared-mailbox email (T12).\n *\n * Writes go through the Truth oRPC `careInbox` router (all\n * `verifiedUserProcedure`, so every call REQUIRES the user JWT):\n * - `linkMessage` POST /api/care-inbox/link\n * - `unlinkMessage` POST /api/care-inbox/unlink\n * - `replyToThread` POST /api/care-inbox/outbound/thread-reply\n * - `composeEmail` POST /api/care-inbox/outbound/compose\n * Reads are Convex queries; use the hooks in `@hipnation-truth/sdk/react`\n * (`useEmailThreads`, …) or `createCareInboxSource`. Nothing here is\n * persisted offline.\n *\n * Two type layers:\n * - `*View` types are the raw Convex query payloads (nullable where the\n * stored row can lack a value).\n * - The contract types (`EmailMessage`, `EmailThreadSummary`, `ThreadPage`,\n * …) mirror comhub's `lib/email/careInboxSource.ts` exactly. `to*`\n * projections turn views into contract shapes: a missing string becomes\n * \"\" and a missing participant `{ address: \"\", name: null }` because the\n * contract declares those fields non-null.\n *\n * Errors: every rejection is a `CareInboxError` whose `code` is the comhub\n * `CareInboxErrorCode`, so it satisfies comhub's `Error & { code }` contract\n * as-is. `status` (0 = no HTTP response), `rpcCode` (oRPC / transport code),\n * `reason` and `detail` carry the server detail. `toCareInboxError()` maps\n * anything thrown — including a Convex `ConvexError` from a hook — onto it.\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\n// ---------------------------------------------------------------------------\n// Contract types (comhub lib/email/careInboxSource.ts; times epoch ms)\n// ---------------------------------------------------------------------------\n\nexport type EmailDirection = \"inbound\" | \"outbound\";\n\n/**\n * Thread-list filter. \"unlinked\" is served only to triage callers (threads\n * with at least one unlinked message); others get forbidden/not_triage.\n */\nexport type ThreadListFilter = \"all\" | \"unread\" | \"unlinked\";\n\nexport interface EmailMailbox {\n id: string;\n /** Shared mailbox address. \"\" for non-triage callers (server-redacted). */\n address: string;\n displayName: string;\n}\n\nexport interface MailboxAccess {\n mailboxes: EmailMailbox[];\n /** May see Unlinked and link/unlink (admin-only until G-TRIAGE). */\n canTriage: boolean;\n}\n\nexport interface EmailParticipant {\n address: string;\n name: string | null;\n}\n\nexport interface EmailMessage {\n id: string;\n threadId: string;\n mailboxId: string;\n direction: EmailDirection;\n from: EmailParticipant;\n to: EmailParticipant[];\n subject: string;\n /** Epoch milliseconds. */\n sentAt: number;\n hasAttachments: boolean;\n linkedPatientId: string | null;\n linkedPatientName: string | null;\n /** Always null in build 1 (metadata only). */\n bodyText: string | null;\n}\n\nexport interface EmailThreadSummary {\n id: string;\n mailboxId: string;\n subject: string;\n /** Epoch milliseconds of the newest message. */\n lastMessageAt: number;\n lastDirection: EmailDirection;\n counterpart: EmailParticipant;\n messageCount: number;\n unreadCount: number;\n /** Triage callers only; always 0 for staff. */\n unlinkedCount: number;\n linkedPatientName: string | null;\n hasAttachments: boolean;\n}\n\nexport interface LinkedPatientContact {\n patientId: string;\n name: string;\n email: string | null;\n phone: string | null;\n office: string | null;\n}\n\nexport interface EmailThreadDetail {\n summary: EmailThreadSummary;\n mailbox: EmailMailbox;\n /** Oldest first. */\n messages: EmailMessage[];\n /** Not provided in build 1 (always null). */\n patientContact?: LinkedPatientContact | null;\n}\n\nexport interface ListThreadsArgs {\n mailboxId?: string;\n filter?: ThreadListFilter;\n cursor?: string | null;\n /** Server default 25, max 50. */\n limit?: number;\n}\n\nexport interface ThreadPage {\n threads: EmailThreadSummary[];\n /** A mailbox-filtered page can be short; keep paging while non-null. */\n nextCursor: string | null;\n}\n\nexport interface PatientLinkCandidate {\n patientId: string;\n displayName: string;\n /** Office name when known; never an email address. */\n detail: string | null;\n}\n\nexport interface LinkMessageArgs {\n messageId: string;\n patientId: string;\n /**\n * Client idempotency key (8-128 chars of `[A-Za-z0-9_:.-]`). A key the\n * server already recorded for the message is a no-op that returns the\n * current state, so a late retry can never undo a newer unlink.\n */\n requestId: string;\n}\n\nexport interface UnlinkMessageArgs {\n messageId: string;\n /** Client idempotency key; see `LinkMessageArgs.requestId`. */\n requestId: string;\n}\n\nexport interface LinkResult {\n message: EmailMessage;\n}\n\nexport interface SendReplyArgs {\n threadId: string;\n body: string;\n clientRequestId: string;\n}\n\nexport interface SendEmailArgs {\n to: string;\n subject: string;\n body: string;\n patientId?: string;\n mailboxId: string;\n clientRequestId: string;\n}\n\n/** Send is disabled in this build (always rejects forbidden/send_disabled). */\nexport interface SendResult {\n message: EmailMessage;\n thread: EmailThreadSummary;\n}\n\nexport interface MarkReadArgs {\n threadId: string;\n}\n\nexport interface MarkReadResult {\n thread: EmailThreadSummary;\n}\n\n/** comhub `CareInboxErrorCode`. */\nexport type CareInboxErrorCode =\n | \"forbidden\"\n | \"not_found\"\n | \"offline\"\n | \"unavailable\"\n | \"validation\"\n | \"unknown\";\n\n// --- SDK extensions of the contract (extra fields only; still assignable) ---\n\n/** `EmailMailbox` plus the server-derived switches. */\nexport interface CareInboxMailbox extends EmailMailbox {\n mode: \"mirror\" | \"live\";\n /** Live mailbox AND send enabled on the deployment. */\n canSend: boolean;\n /** bodyVisibility !== \"none\" (bodies still need openThreadBodies). */\n bodyVisible: boolean;\n}\n\nexport interface CareInboxMailboxAccess extends MailboxAccess {\n mailboxes: CareInboxMailbox[];\n}\n\nexport interface CareInboxThreadDetail extends EmailThreadDetail {\n mailbox: CareInboxMailbox;\n /** Whether `openThreadBodies` would serve bodies to this caller. */\n bodyVisible: boolean;\n patientContact: null;\n}\n\n/** Triage-only unlinked message page (`listUnlinked`). */\nexport interface UnlinkedMessagePage {\n messages: EmailMessage[];\n nextCursor: string | null;\n}\n\n/** Back-compat aliases (T12 names). */\nexport type CareInboxEmailMessage = EmailMessage;\nexport type CareInboxEmailThreadSummary = EmailThreadSummary;\nexport type CareInboxLinkResult = LinkResult;\nexport type CareInboxSendResult = SendResult;\n/**\n * SDK call input: the contract args with `requestId` optional. Omit it and\n * the SDK generates one for this call; pass your own to make retries across\n * calls idempotent.\n */\nexport type LinkEmailMessageInput = Omit<LinkMessageArgs, \"requestId\"> &\n Partial<Pick<LinkMessageArgs, \"requestId\">>;\nexport type UnlinkEmailMessageInput = Omit<UnlinkMessageArgs, \"requestId\"> &\n Partial<Pick<UnlinkMessageArgs, \"requestId\">>;\nexport type ReplyToEmailThreadInput = SendReplyArgs;\nexport type ComposeEmailInput = SendEmailArgs;\n\n// ---------------------------------------------------------------------------\n// Raw view types (Convex `careInboxQueries` / `careInboxReads` payloads)\n// ---------------------------------------------------------------------------\n\nexport type EmailParticipantView = EmailParticipant;\n\n/** `careInboxQueries` message row. `bodyText` is always null from queries. */\nexport interface EmailMessageView {\n id: string;\n threadId: string | null;\n mailboxId: string;\n direction: EmailDirection;\n from: EmailParticipantView | null;\n to: EmailParticipantView[];\n subject: string | null;\n sentAt: number;\n hasAttachments: boolean;\n linkedPatientId: string | null;\n linkedPatientName: string | null;\n bodyText: null;\n}\n\nexport interface EmailThreadSummaryView {\n id: string;\n mailboxId: string;\n subject: string | null;\n lastMessageAt: number;\n lastDirection: EmailDirection | null;\n counterpart: EmailParticipantView | null;\n messageCount: number;\n unreadCount: number;\n unlinkedCount: number;\n linkedPatientId: string | null;\n linkedPatientName: string | null;\n hasAttachments: boolean;\n}\n\nexport interface EmailMailboxView {\n id: string;\n displayName: string;\n mode: \"mirror\" | \"live\";\n canSend: boolean;\n bodyVisible: boolean;\n /** Present only when the caller can triage. */\n address?: string;\n}\n\nexport interface EmailMailboxAccessView {\n mailboxes: EmailMailboxView[];\n canTriage: boolean;\n}\n\n/** Filters `listThreadsForUser` serves (\"unlinked\": triage only). */\nexport type EmailThreadListFilter = ThreadListFilter;\n\nexport interface EmailThreadPageView {\n threads: EmailThreadSummaryView[];\n nextCursor: string | null;\n}\n\nexport interface EmailThreadDetailView {\n summary: EmailThreadSummaryView;\n mailbox: EmailMailboxView;\n /** Oldest first. Staff: linked only; triage: linked + unlinked. */\n messages: EmailMessageView[];\n bodyVisible: boolean;\n patientContact: null;\n}\n\nexport interface UnlinkedEmailPageView {\n messages: EmailMessageView[];\n nextCursor: string | null;\n}\n\nexport type PatientLinkCandidateView = PatientLinkCandidate;\n\nexport interface MarkEmailThreadReadResult {\n thread: EmailThreadSummaryView;\n}\n\nexport interface EmailThreadBodiesView {\n messages: { id: string; bodyText: string | null }[];\n}\n\n// ---------------------------------------------------------------------------\n// Projections (view → contract)\n// ---------------------------------------------------------------------------\n\nconst NO_PARTICIPANT: EmailParticipant = { address: \"\", name: null };\n\nfunction participant(p: EmailParticipantView | null): EmailParticipant {\n return p ? { address: p.address, name: p.name } : { ...NO_PARTICIPANT };\n}\n\nfunction toEmailMessage(m: EmailMessageView): EmailMessage {\n return {\n id: m.id,\n threadId: m.threadId ?? \"\",\n mailboxId: m.mailboxId,\n direction: m.direction,\n from: participant(m.from),\n to: m.to.map(participant),\n subject: m.subject ?? \"\",\n sentAt: m.sentAt,\n hasAttachments: m.hasAttachments,\n linkedPatientId: m.linkedPatientId,\n linkedPatientName: m.linkedPatientName,\n bodyText: m.bodyText,\n };\n}\n\n/**\n * `lastDirection` is null only for a thread with no visible message (it\n * cannot happen for a summary the server lists; kept defensive). Projects to\n * \"inbound\".\n */\nfunction toEmailThreadSummary(t: EmailThreadSummaryView): EmailThreadSummary {\n return {\n id: t.id,\n mailboxId: t.mailboxId,\n subject: t.subject ?? \"\",\n lastMessageAt: t.lastMessageAt,\n lastDirection: t.lastDirection ?? \"inbound\",\n counterpart: participant(t.counterpart),\n messageCount: t.messageCount,\n unreadCount: t.unreadCount,\n unlinkedCount: t.unlinkedCount,\n linkedPatientName: t.linkedPatientName,\n hasAttachments: t.hasAttachments,\n };\n}\n\nfunction toEmailMailbox(m: EmailMailboxView): CareInboxMailbox {\n return {\n id: m.id,\n address: m.address ?? \"\",\n displayName: m.displayName,\n mode: m.mode,\n canSend: m.canSend,\n bodyVisible: m.bodyVisible,\n };\n}\n\nfunction toMailboxAccess(a: EmailMailboxAccessView): CareInboxMailboxAccess {\n return { mailboxes: a.mailboxes.map(toEmailMailbox), canTriage: a.canTriage };\n}\n\nfunction toEmailThreadDetail(d: EmailThreadDetailView): CareInboxThreadDetail {\n return {\n summary: toEmailThreadSummary(d.summary),\n mailbox: toEmailMailbox(d.mailbox),\n messages: d.messages.map(toEmailMessage),\n bodyVisible: d.bodyVisible,\n patientContact: null,\n };\n}\n\nfunction toThreadPage(p: EmailThreadPageView): ThreadPage {\n return {\n threads: p.threads.map(toEmailThreadSummary),\n nextCursor: p.nextCursor,\n };\n}\n\nfunction toUnlinkedMessagePage(p: UnlinkedEmailPageView): UnlinkedMessagePage {\n return {\n messages: p.messages.map(toEmailMessage),\n nextCursor: p.nextCursor,\n };\n}\n\nfunction toMarkReadResult(r: MarkEmailThreadReadResult): MarkReadResult {\n return { thread: toEmailThreadSummary(r.thread) };\n}\n\n// ---------------------------------------------------------------------------\n// Errors\n// ---------------------------------------------------------------------------\n\n/**\n * Machine-readable sub-code. Server-sent: `send_disabled` | `not_triage` |\n * `body_gated` | `unauthenticated` (Convex: no identity). SDK-derived:\n * `unauthenticated` (no user JWT, or HTTP 401). The contract has no auth\n * code, so `unauthenticated` surfaces as `forbidden` on every path.\n */\nexport type CareInboxErrorReason =\n | \"send_disabled\"\n | \"not_triage\"\n | \"body_gated\"\n | \"unauthenticated\";\n\nconst REASONS: readonly CareInboxErrorReason[] = [\n \"send_disabled\",\n \"not_triage\",\n \"body_gated\",\n \"unauthenticated\",\n];\n\nconst CODES: readonly CareInboxErrorCode[] = [\n \"forbidden\",\n \"not_found\",\n \"offline\",\n \"unavailable\",\n \"validation\",\n \"unknown\",\n];\n\nfunction asReason(value: unknown): CareInboxErrorReason | null {\n return REASONS.includes(value as CareInboxErrorReason)\n ? (value as CareInboxErrorReason)\n : null;\n}\n\nfunction asCode(value: unknown): CareInboxErrorCode | null {\n return CODES.includes(value as CareInboxErrorCode)\n ? (value as CareInboxErrorCode)\n : null;\n}\n\nexport interface CareInboxErrorFields {\n /** HTTP status; 0 when there was no HTTP response (incl. Convex errors). */\n status?: number;\n /**\n * oRPC code (`FORBIDDEN`, `NOT_FOUND`, …) or, for status 0, `TRANSPORT`\n * (fetch threw), `TIMEOUT`, `NO_API_KEY`, `NO_USER_TOKEN`.\n */\n rpcCode?: string | null;\n reason?: CareInboxErrorReason | null;\n /** Fixed server marker (e.g. `PATIENT_HAS_NO_OFFICE`), when present. */\n detail?: string | null;\n}\n\n/**\n * The single care-inbox error. `code` is the comhub `CareInboxErrorCode`, so\n * an instance satisfies comhub's `CareInboxError` (`Error & { code }`). The\n * message never carries content, addresses or ids.\n */\nclass CareInboxError extends Error {\n readonly code: CareInboxErrorCode;\n readonly status: number;\n readonly rpcCode: string | null;\n readonly reason: CareInboxErrorReason | null;\n readonly detail: string | null;\n\n constructor(code: CareInboxErrorCode, fields: CareInboxErrorFields = {}) {\n const reason = fields.reason ?? null;\n const status = fields.status ?? 0;\n super(\n `Care inbox request failed: ${code}${reason ? ` (${reason})` : \"\"}${status ? ` HTTP ${status}` : \"\"}`,\n );\n this.name = \"CareInboxError\";\n this.code = code;\n this.status = status;\n this.rpcCode = fields.rpcCode ?? null;\n this.reason = reason;\n this.detail = fields.detail ?? null;\n }\n}\n\nfunction codeForStatus(status: number, rpcCode: string | null) {\n if (status === 0) {\n if (rpcCode === \"TRANSPORT\" || rpcCode === \"TIMEOUT\") {\n return \"offline\";\n }\n if (rpcCode === \"NO_USER_TOKEN\") {\n return \"forbidden\";\n }\n return \"unknown\";\n }\n if (status === 400) {\n return \"validation\";\n }\n if (status === 401 || status === 403) {\n return \"forbidden\";\n }\n if (status === 404) {\n return \"not_found\";\n }\n if (status === 503) {\n return \"unavailable\";\n }\n return \"unknown\";\n}\n\nfunction httpError(fields: Required<CareInboxErrorFields>): CareInboxError {\n const unauthenticated =\n fields.status === 401 || fields.rpcCode === \"NO_USER_TOKEN\";\n return new CareInboxError(codeForStatus(fields.status, fields.rpcCode), {\n ...fields,\n reason: fields.reason ?? (unauthenticated ? \"unauthenticated\" : null),\n });\n}\n\n/** True for any value carrying a contract `code` (comhub `isCareInboxError`). */\nfunction isCareInboxError(\n value: unknown,\n): value is Error & { code: CareInboxErrorCode } {\n return (\n value instanceof Error &&\n asCode((value as { code?: unknown }).code) !== null\n );\n}\n\n/**\n * Coerce anything thrown by the resource, a care-inbox Convex function\n * (`ConvexError({ code, reason? })`, payload on `.data`) or a comhub-style\n * error into a `CareInboxError`. Never throws; unrecognised → `unknown`.\n */\nfunction toCareInboxError(value: unknown): CareInboxError {\n if (value instanceof CareInboxError) {\n return value;\n }\n const data =\n value && typeof value === \"object\"\n ? (value as { data?: unknown }).data\n : undefined;\n if (data && typeof data === \"object\") {\n const { code, reason } = data as { code?: unknown; reason?: unknown };\n const known = asCode(code);\n if (known) {\n return new CareInboxError(known, { reason: asReason(reason) });\n }\n }\n if (isCareInboxError(value)) {\n // Duck-typed: e.g. a CareInboxError from another copy of the SDK, where\n // instanceof fails. Keep every typed field, not just code/reason.\n const v = value as {\n status?: unknown;\n rpcCode?: unknown;\n reason?: unknown;\n detail?: unknown;\n };\n return new CareInboxError(value.code, {\n status:\n typeof v.status === \"number\" &&\n Number.isInteger(v.status) &&\n v.status >= 0\n ? v.status\n : 0,\n rpcCode: typeof v.rpcCode === \"string\" ? v.rpcCode : null,\n reason: asReason(v.reason),\n detail: typeof v.detail === \"string\" ? v.detail : null,\n });\n }\n return new CareInboxError(\"unknown\");\n}\n\nexport interface CareInboxErrorInfo {\n code: CareInboxErrorCode;\n reason: CareInboxErrorReason | null;\n}\n\n/** `{ code, reason }` of anything thrown (see `toCareInboxError`). */\nfunction careInboxErrorInfo(err: unknown): CareInboxErrorInfo {\n const e = toCareInboxError(err);\n return { code: e.code, reason: e.reason };\n}\n\n// ---------------------------------------------------------------------------\n// Resource\n// ---------------------------------------------------------------------------\n\n/**\n * A fresh link/unlink idempotency key (a v4 UUID). Generated once per call:\n * the request body is built once, so anything that re-sends that body reuses\n * the key.\n */\nfunction newRequestId(): string {\n const c = globalThis.crypto;\n if (c && typeof c.randomUUID === \"function\") {\n return c.randomUUID();\n }\n const bytes = new Uint8Array(16);\n if (c && typeof c.getRandomValues === \"function\") {\n c.getRandomValues(bytes);\n } else {\n for (let i = 0; i < bytes.length; i++) {\n bytes[i] = Math.floor(Math.random() * 256);\n }\n }\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, \"0\")).join(\n \"\",\n );\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\nclass CareInboxResource {\n /** 30s upstream timeout — matches ConversationsResource. */\n private static readonly REQUEST_TIMEOUT_MS = 30_000;\n\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n /** Link one message to a patient (triage only). */\n async linkMessage(input: LinkEmailMessageInput): Promise<LinkResult> {\n return this.post<LinkResult>(\"/care-inbox/link\", {\n messageId: input.messageId,\n patientId: input.patientId,\n requestId: input.requestId ?? newRequestId(),\n });\n }\n\n /** Undo a manual link (triage only). */\n async unlinkMessage(input: UnlinkEmailMessageInput): Promise<LinkResult> {\n return this.post<LinkResult>(\"/care-inbox/unlink\", {\n messageId: input.messageId,\n requestId: input.requestId ?? newRequestId(),\n });\n }\n\n /** Reply into a thread. This build always rejects 403 `send_disabled`. */\n async replyToThread(input: SendReplyArgs): Promise<SendResult> {\n return this.post<SendResult>(\"/care-inbox/outbound/thread-reply\", {\n threadId: input.threadId,\n body: input.body,\n clientRequestId: input.clientRequestId,\n });\n }\n\n /** Start a new email. This build always rejects 403 `send_disabled`. */\n async composeEmail(input: SendEmailArgs): Promise<SendResult> {\n return this.post<SendResult>(\"/care-inbox/outbound/compose\", {\n to: input.to,\n subject: input.subject,\n body: input.body,\n ...(input.patientId !== undefined ? { patientId: input.patientId } : {}),\n mailboxId: input.mailboxId,\n clientRequestId: input.clientRequestId,\n });\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const fail = (rpcCode: string) =>\n httpError({ status: 0, rpcCode, reason: null, detail: null });\n if (!this.auth.apiKey) {\n throw fail(\"NO_API_KEY\");\n }\n let headers: Record<string, string>;\n try {\n // Every careInbox route is a verifiedUserProcedure: require the JWT.\n headers = await buildAuthHeaders(this.auth, {\n json: true,\n requireUserToken: true,\n });\n } catch {\n throw fail(\"NO_USER_TOKEN\");\n }\n\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n CareInboxResource.REQUEST_TIMEOUT_MS,\n );\n let res: Response;\n try {\n res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n headers,\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n const isAbort =\n err instanceof Error &&\n (err.name === \"AbortError\" || err.name === \"TimeoutError\");\n throw fail(isAbort ? \"TIMEOUT\" : \"TRANSPORT\");\n } finally {\n clearTimeout(timeout);\n }\n\n if (!res.ok) {\n // oRPC error body: { code, status, message, data?: { reason } }.\n let parsed: { code?: unknown; message?: unknown; data?: unknown } = {};\n try {\n parsed = (await res.json()) as typeof parsed;\n } catch {\n // Non-JSON body (gateway error): status alone is the signal.\n }\n const data =\n parsed.data && typeof parsed.data === \"object\"\n ? (parsed.data as { reason?: unknown })\n : {};\n throw httpError({\n status: res.status,\n rpcCode: typeof parsed.code === \"string\" ? parsed.code : null,\n reason: asReason(data.reason),\n detail:\n typeof parsed.message === \"string\"\n ? parsed.message.slice(0, 200)\n : null,\n });\n }\n return (await res.json()) as T;\n }\n}\n\nexport {\n CareInboxError,\n CareInboxResource,\n careInboxErrorInfo,\n isCareInboxError,\n toCareInboxError,\n toEmailMailbox,\n toEmailMessage,\n toEmailThreadDetail,\n toEmailThreadSummary,\n toMailboxAccess,\n toMarkReadResult,\n toThreadPage,\n toUnlinkedMessagePage,\n};\n","/**\n * ConversationsResource — write methods that hang off a specific\n * conversation: notes, tasks, outbound messages.\n *\n * Replaces CommHub's `truthConversationApi.ts` raw-fetch wrappers so\n * the frontend goes through a typed SDK surface instead of building\n * URLs by hand.\n *\n * All methods proxy the matching oRPC procedures (`/conversations/*`)\n * via Truth's application-key auth. Errors surface as\n * `ConversationsError` with a status code so callers can distinguish\n * transport failures (status=0) from API rejections (status>=400).\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/** Address a conversation by either Convex `_id` or the phonePair. */\nexport interface ConversationAddress {\n conversationId?: string;\n phonePair?: string;\n}\n\nexport type ConversationTaskStatus = \"pending\" | \"completed\";\nexport type ConversationTaskPriority = \"high\" | \"medium\" | \"low\";\n\nexport interface CreateConversationNoteInput extends ConversationAddress {\n eventId?: string;\n author: string;\n content: string;\n status?: string;\n type?: string;\n}\n\nexport interface CreateConversationTaskInput extends ConversationAddress {\n eventId?: string;\n author: string;\n /** Optional short headline, distinct from `description`. */\n title?: string;\n description: string;\n status?: ConversationTaskStatus;\n priority?: ConversationTaskPriority;\n assignee?: string;\n type?: string;\n}\n\nexport interface SetConversationTaskStatusInput {\n taskId: string;\n status: ConversationTaskStatus;\n resolvedBy?: string;\n /**\n * Email of the user performing the action. Truth excludes the actor\n * from the task-action push fan-out (legacy parity) — omit it and the\n * actor notifies themselves.\n */\n actor?: string;\n}\n\nexport interface UpdateConversationTaskInput {\n taskId: string;\n /** Conversation the task belongs to. Truth requires this on PATCH. */\n conversationId: string;\n /** Required by the Truth task router — see `messages/procedures/tasks.ts`. */\n author: string;\n description: string;\n /** Optional patch fields — pass only the ones you want to change. */\n title?: string;\n priority?: ConversationTaskPriority;\n status?: ConversationTaskStatus;\n assignee?: string;\n type?: string;\n /**\n * Email of the user performing the action. Truth excludes the actor\n * from the task-action push fan-out (legacy parity) — omit it and the\n * actor notifies themselves.\n */\n actor?: string;\n}\n\nexport interface SetConversationTaskArchivedInput {\n taskId: string;\n archived: boolean;\n /** Email of the acting user — excluded from the archive push fan-out. */\n actor?: string;\n}\n\nexport interface SendConversationMessageInput {\n fromNumber: string;\n toNumber: string;\n message?: string;\n media?: string;\n}\n\nexport interface SendConversationMessageResult {\n id: number;\n messageStatus: string;\n direction: string;\n}\n\nexport class ConversationsError extends Error {\n readonly status: number;\n\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Conversations ${operation} failed (HTTP ${status})`);\n this.name = \"ConversationsError\";\n this.status = status;\n }\n}\n\n/**\n * Guard: a conversation must be addressed by either `conversationId` or\n * `phonePair`. Reject locally so callers get an actionable error\n * instead of an avoidable server round-trip.\n */\nfunction assertConversationAddress(\n operation: string,\n input: ConversationAddress,\n): void {\n if (!input.conversationId && !input.phonePair) {\n throw new ConversationsError(\n operation,\n 0,\n \"Either `conversationId` or `phonePair` is required\",\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// Subresources\n// ---------------------------------------------------------------------------\n\nclass ConversationNotesSubresource {\n constructor(\n private readonly post: <T>(path: string, body: unknown) => Promise<T>,\n ) {}\n\n /** Create a note on a conversation (addressed by id or phonePair). */\n async create(input: CreateConversationNoteInput): Promise<{ id: string }> {\n assertConversationAddress(\"notes.create\", input);\n return this.post<{ id: string }>(\"/conversations/notes\", input);\n }\n}\n\nclass ConversationTasksSubresource {\n constructor(\n private readonly post: <T>(path: string, body: unknown) => Promise<T>,\n private readonly patch: <T>(path: string, body: unknown) => Promise<T>,\n ) {}\n\n /** Create a task on a conversation. */\n async create(input: CreateConversationTaskInput): Promise<{ id: string }> {\n assertConversationAddress(\"tasks.create\", input);\n return this.post<{ id: string }>(\"/conversations/tasks\", input);\n }\n\n /** Mark a task pending or completed. */\n async setStatus(input: SetConversationTaskStatusInput): Promise<{\n ok: true;\n }> {\n return this.post<{ ok: true }>(\n `/conversations/tasks/${encodeURIComponent(input.taskId)}/status`,\n {\n id: input.taskId,\n status: input.status,\n ...(input.resolvedBy ? { resolvedBy: input.resolvedBy } : {}),\n ...(input.actor ? { actor: input.actor } : {}),\n },\n );\n }\n\n /** Archive or un-archive a task (hides it from My Tasks without deleting). */\n async setArchived(input: SetConversationTaskArchivedInput): Promise<{\n ok: true;\n changed: boolean;\n }> {\n return this.post<{ ok: true; changed: boolean }>(\n `/conversations/tasks/${encodeURIComponent(input.taskId)}/archive`,\n {\n id: input.taskId,\n archived: input.archived,\n ...(input.actor ? { actor: input.actor } : {}),\n },\n );\n }\n\n /**\n * Update task fields (priority, assignee, description, type). Wraps\n * `PATCH /api/conversations/tasks/{id}` so CommHub doesn't have to\n * direct-fetch for non-status field edits.\n */\n async update(input: UpdateConversationTaskInput): Promise<{ ok: true }> {\n return this.patch<{ ok: true }>(\n `/conversations/tasks/${encodeURIComponent(input.taskId)}`,\n {\n id: input.taskId,\n conversationId: input.conversationId,\n author: input.author,\n description: input.description,\n ...(input.title !== undefined ? { title: input.title } : {}),\n ...(input.priority ? { priority: input.priority } : {}),\n ...(input.status ? { status: input.status } : {}),\n ...(input.assignee !== undefined ? { assignee: input.assignee } : {}),\n ...(input.type !== undefined ? { type: input.type } : {}),\n ...(input.actor ? { actor: input.actor } : {}),\n },\n );\n }\n}\n\nclass ConversationMessagesSubresource {\n constructor(\n private readonly post: <T>(\n path: string,\n body: unknown,\n options?: { requireUserToken?: boolean },\n ) => Promise<T>,\n ) {}\n\n /**\n * Send an outbound SMS / MMS via the typed `sendMessage` oRPC procedure.\n *\n * Prefer this over the generic Dialpad proxy (`messages.dialpad.sendSms`)\n * — this hits the validated Truth route and consistently surfaces\n * `ConversationsError` on failure.\n */\n async send(\n input: SendConversationMessageInput,\n ): Promise<SendConversationMessageResult> {\n if (!input.message && !input.media) {\n throw new ConversationsError(\n \"messages.send\",\n 0,\n \"send requires `message` or `media`\",\n );\n }\n // The send route is a `verifiedUserProcedure` — it always requires a\n // Clerk JWT. Force the auth-header builder to resolve (and, if needed,\n // retry) the user token rather than silently degrading to key-only,\n // which would 401 and surface as a stuck \"error\" status in the UI.\n return this.post<SendConversationMessageResult>(\n \"/conversations/messages\",\n input,\n { requireUserToken: true },\n );\n }\n}\n\n// ---------------------------------------------------------------------------\n// ConversationsResource\n// ---------------------------------------------------------------------------\n\nexport class ConversationsResource {\n readonly notes: ConversationNotesSubresource;\n readonly tasks: ConversationTasksSubresource;\n readonly messages: ConversationMessagesSubresource;\n\n /** 30s upstream timeout — matches NotesResource for consistency. */\n private static readonly REQUEST_TIMEOUT_MS = 30_000;\n\n private readonly baseUrl: string;\n private readonly apiKey: string;\n private readonly auth: RestAuth;\n private readonly convex: import(\"convex/browser\").ConvexHttpClient | null;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n convex?: import(\"convex/browser\").ConvexHttpClient,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.apiKey = apiKey;\n this.auth = { apiKey, getAuthToken };\n this.convex = convex ?? null;\n const post = <T>(\n path: string,\n body: unknown,\n options?: { requireUserToken?: boolean },\n ) => this.postRequest<T>(path, body, options);\n const patch = <T>(path: string, body: unknown) =>\n this.patchRequest<T>(path, body);\n this.notes = new ConversationNotesSubresource(post);\n this.tasks = new ConversationTasksSubresource(post, patch);\n this.messages = new ConversationMessagesSubresource(post);\n }\n\n /**\n * Mark a conversation read for the calling user (zeroes unreadCount,\n * stamps `lastReadAt`). Calls the public Convex `markRead` mutation\n * which enforces self-tenancy on the auth identity.\n */\n async markRead(input: {\n conversationId: string;\n userId: string;\n }): Promise<{ ok: true }> {\n if (!this.convex) {\n throw new ConversationsError(\n \"/markRead\",\n 0,\n \"ConversationsResource missing Convex client\",\n );\n }\n return (await this.convex.mutation(\n \"conversations:markRead\" as never,\n input as never,\n )) as { ok: true };\n }\n\n /**\n * Mark a conversation unread for the calling user (sets unreadCount=1).\n */\n async markUnread(input: {\n conversationId: string;\n userId: string;\n }): Promise<{ updated: true }> {\n if (!this.convex) {\n throw new ConversationsError(\n \"/markUnread\",\n 0,\n \"ConversationsResource missing Convex client\",\n );\n }\n return (await this.convex.mutation(\n \"conversations:markUnread\" as never,\n input as never,\n )) as { updated: true };\n }\n\n /**\n * Mark / unmark a conversation Urgent (conversation-level, shared by\n * participants). Refused if `userId` is not a participant.\n */\n async setUrgent(input: {\n conversationId: string;\n userId: string;\n isUrgent: boolean;\n }): Promise<{ updated: true; isUrgent: boolean; changed: boolean }> {\n if (!this.convex) {\n throw new ConversationsError(\n \"/setUrgent\",\n 0,\n \"ConversationsResource missing Convex client\",\n );\n }\n return (await this.convex.mutation(\n \"conversations:setUrgent\" as never,\n input as never,\n )) as { updated: true; isUrgent: boolean; changed: boolean };\n }\n\n /**\n * Zero unread on every conversation the user has reads for, except\n * those whose `providerPhone` is in `excludedProviderPhones`.\n */\n async clearAllUnread(input: {\n userId: string;\n excludedProviderPhones?: string[];\n }): Promise<{ cleared: number }> {\n if (!this.convex) {\n throw new ConversationsError(\n \"/clearAllUnread\",\n 0,\n \"ConversationsResource missing Convex client\",\n );\n }\n return (await this.convex.mutation(\n \"conversations:clearAllUnread\" as never,\n input as never,\n )) as { cleared: number };\n }\n\n private async postRequest<T>(\n path: string,\n body: unknown,\n options?: { requireUserToken?: boolean },\n ): Promise<T> {\n if (!this.apiKey) {\n throw new ConversationsError(\n path,\n 0,\n \"Truth API key not configured — request blocked\",\n );\n }\n\n // Build headers before arming the abort timer. For `requireUserToken`\n // routes this may retry token resolution (and throw a clear auth error\n // if none is available) — surface that directly rather than letting it\n // masquerade as a generic \"request failed before response\".\n let headers: Record<string, string>;\n try {\n headers = await buildAuthHeaders(this.auth, {\n json: true,\n requireUserToken: options?.requireUserToken,\n });\n } catch (err) {\n throw new ConversationsError(\n path,\n 0,\n err instanceof Error ? err.message : \"Failed to build auth headers\",\n );\n }\n\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n ConversationsResource.REQUEST_TIMEOUT_MS,\n );\n\n let res: Response;\n try {\n res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n headers,\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n const isAbort =\n err instanceof Error &&\n (err.name === \"AbortError\" || err.name === \"TimeoutError\");\n const message = isAbort\n ? `Conversations ${path} timed out after ${ConversationsResource.REQUEST_TIMEOUT_MS}ms`\n : err instanceof Error\n ? err.message\n : \"Conversations request failed before response\";\n throw new ConversationsError(path, 0, message);\n } finally {\n clearTimeout(timeout);\n }\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ConversationsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n /**\n * PATCH variant of `postRequest`. Mirrors the timeout + API-key\n * handling so callers like `tasks.update()` don't need to roll their\n * own fetch. The Truth task router treats unknown methods as 405, so\n * a dedicated PATCH path is required.\n */\n private async patchRequest<T>(path: string, body: unknown): Promise<T> {\n if (!this.apiKey) {\n throw new ConversationsError(\n path,\n 0,\n \"Truth API key not configured — request blocked\",\n );\n }\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n ConversationsResource.REQUEST_TIMEOUT_MS,\n );\n let res: Response;\n try {\n res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"PATCH\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n const isAbort =\n err instanceof Error &&\n (err.name === \"AbortError\" || err.name === \"TimeoutError\");\n const message = isAbort\n ? `Conversations ${path} timed out after ${ConversationsResource.REQUEST_TIMEOUT_MS}ms`\n : err instanceof Error\n ? err.message\n : String(err);\n throw new ConversationsError(path, 0, message);\n } finally {\n clearTimeout(timeout);\n }\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ConversationsError(\n path,\n res.status,\n `Conversations ${path} failed: ${text.slice(0, 200)}`,\n );\n }\n return (await res.json()) as T;\n }\n}\n","/**\n * Dialpad resource — typed access to Truth's Dialpad proxy endpoints.\n *\n * @example\n * ```ts\n * const sms = await truth.messages.dialpad.sendSms({ from_number, to_number, message });\n * const call = await truth.messages.dialpad.initiateCall(userId, phoneNumber);\n * await truth.messages.dialpad.hangupCall(callId);\n * const url = await truth.messages.dialpad.authenticateVoicemail(voicemailLink);\n * ```\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\ninterface SendSmsParams {\n from_number: string;\n to_number: string;\n message?: string;\n media?: string | string[];\n}\n\ninterface SendSmsResponse {\n id: string;\n message_status: string;\n [key: string]: unknown;\n}\n\ninterface InitiateCallResponse {\n call_id: number;\n [key: string]: unknown;\n}\n\ninterface CallStatusResponse {\n state: string;\n [key: string]: unknown;\n}\n\ninterface DialpadUser {\n id: number;\n emails: string[];\n first_name?: string;\n last_name?: string;\n [key: string]: unknown;\n}\n\ninterface DialpadUserListResponse {\n items: DialpadUser[];\n}\n\ninterface DialpadNumberInfo {\n user_id?: number;\n type?: string;\n [key: string]: unknown;\n}\n\ninterface VoicemailAuthResponse {\n success: boolean;\n authenticated_url: string | null;\n error?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Dialpad Resource\n// ---------------------------------------------------------------------------\n\nclass DialpadResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n /**\n * Send an SMS or MMS message via Dialpad.\n */\n async sendSms(params: SendSmsParams): Promise<SendSmsResponse> {\n const body = {\n to_numbers: [params.to_number],\n from_number: params.from_number,\n infer_country_code: false,\n ...(params.message ? { text: params.message } : {}),\n ...(params.media ? { media: params.media } : {}),\n };\n\n return this.post<SendSmsResponse>(\"/sms\", body);\n }\n\n /**\n * Initiate an outbound call from a Dialpad user to a phone number.\n */\n async initiateCall(\n userId: number,\n phoneNumber: string,\n ): Promise<InitiateCallResponse> {\n return this.post<InitiateCallResponse>(`/users/${userId}/initiate_call`, {\n phone_number: phoneNumber,\n });\n }\n\n /**\n * Hang up an active call.\n */\n async hangupCall(callId: number): Promise<void> {\n await this.put(`/call/${callId}/actions/hangup`);\n }\n\n /**\n * Alias for `hangupCall` — mirrors the CommHub `endCall` action name so\n * the SDK swap is a direct rename.\n */\n async endCall(callId: number): Promise<void> {\n await this.hangupCall(callId);\n }\n\n /**\n * Send an MMS with a pre-uploaded attachment. Takes the S3 key returned\n * by `client.attachments.createUploadUrl(...)` + PUT, fetches a short-\n * lived download URL, and hands it to Dialpad as `media[]`.\n *\n * Replaces CommHub's `sendAttachment` Hasura Action (which stored bytes\n * as base64 in Postgres and served them through a GET endpoint).\n */\n async sendAttachmentWithUrl(params: {\n from_number: string;\n to_number: string;\n mediaUrl: string;\n message?: string;\n }): Promise<SendSmsResponse> {\n return this.sendSms({\n from_number: params.from_number,\n to_number: params.to_number,\n message: params.message,\n media: [params.mediaUrl],\n });\n }\n\n /**\n * Get the status of a call.\n */\n async getCallStatus(callId: number): Promise<CallStatusResponse | null> {\n try {\n return await this.get<CallStatusResponse>(`/call/${callId}`);\n } catch (error) {\n if (error instanceof DialpadProxyError && error.status === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Get a Dialpad user by their user ID.\n */\n async getUser(userId: string | number): Promise<DialpadUser | null> {\n try {\n return await this.get<DialpadUser>(`/users/${userId}`);\n } catch (error) {\n if (error instanceof DialpadProxyError && error.status === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Find a Dialpad user by email.\n */\n async getUserByEmail(email: string): Promise<DialpadUser | null> {\n const result = await this.get<DialpadUserListResponse>(\"/users\", {\n email,\n });\n return result.items?.[0] ?? null;\n }\n\n /**\n * Find a Dialpad user by phone number.\n */\n async getUserByPhoneNumber(phoneNumber: string): Promise<DialpadUser | null> {\n const result = await this.get<DialpadUserListResponse>(\"/users\", {\n number: phoneNumber,\n });\n return result.items?.[0] ?? null;\n }\n\n /**\n * Get information about a Dialpad phone number.\n */\n async getNumberInfo(phoneNumber: string): Promise<DialpadNumberInfo | null> {\n try {\n const cleanNumber = phoneNumber.replace(/[^\\d+]/g, \"\");\n return await this.get<DialpadNumberInfo>(\n `/numbers/${encodeURIComponent(cleanNumber)}`,\n );\n } catch (error) {\n if (error instanceof DialpadProxyError && error.status === 404) {\n return null;\n }\n throw error;\n }\n }\n\n /**\n * Authenticate a voicemail download URL. Truth appends the Dialpad API key,\n * follows redirects, and returns the clean URL for client-side playback.\n */\n async authenticateVoicemail(voicemailLink: string): Promise<string | null> {\n const url = `${this.baseUrl}/api/messages/dialpad/voicemail/authenticate`;\n\n const response = await fetch(url, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true, accept: false }),\n body: JSON.stringify({ voicemail_link: voicemailLink }),\n });\n\n const result = (await response.json()) as VoicemailAuthResponse;\n\n if (!response.ok || !result.success) {\n return null;\n }\n\n return result.authenticated_url;\n }\n\n // -----------------------------------------------------------------------\n // Internal HTTP helpers\n // -----------------------------------------------------------------------\n\n private async get<T>(\n path: string,\n params?: Record<string, unknown>,\n ): Promise<T> {\n const url = new URL(`/api/messages/dialpad${path}`, this.baseUrl);\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n const response = await fetch(url.toString(), {\n method: \"GET\",\n headers: await buildAuthHeaders(this.auth),\n });\n\n if (!response.ok) {\n throw new DialpadProxyError(\"GET\", path, response.status);\n }\n\n return (await response.json()) as T;\n }\n\n private async post<T>(path: string, body?: unknown): Promise<T> {\n const url = `${this.baseUrl}/api/messages/dialpad${path}`;\n\n const response = await fetch(url, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n throw new DialpadProxyError(\"POST\", path, response.status);\n }\n\n return (await response.json()) as T;\n }\n\n private async put<T = void>(path: string, body?: unknown): Promise<T> {\n const url = `${this.baseUrl}/api/messages/dialpad${path}`;\n\n const response = await fetch(url, {\n method: \"PUT\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n throw new DialpadProxyError(\"PUT\", path, response.status);\n }\n\n if (response.headers.get(\"content-type\")?.includes(\"json\")) {\n return (await response.json()) as T;\n }\n\n return undefined as T;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Messages Resource — namespace for messaging providers\n// ---------------------------------------------------------------------------\n\nclass MessagesResource {\n readonly dialpad: DialpadResource;\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.dialpad = new DialpadResource(apiBaseUrl, apiKey, getAuthToken);\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n /**\n * Get an authenticated URL for a Dialpad voicemail recording.\n *\n * Replaces CommHub's `getAuthenticatedVoicemailUrl` Hasura mutation\n * (which proxied to the legacy NestJS backend). Truth appends the\n * Dialpad API key, follows redirects, strips the key from the final\n * URL, and returns it for client-side audio playback.\n *\n * @param voicemailLink The raw Dialpad voicemail download URL (value\n * of the `voicemail_link` field on the call event row).\n * @returns An object with `url` (clean playback URL) and `expiresAt`\n * (ISO-8601 timestamp, ~5 min from request time, informational only).\n */\n async getVoicemailUrl(voicemailLink: string): Promise<{\n url: string;\n expiresAt: string;\n }> {\n const res = await fetch(`${this.baseUrl}/api/conversations/voicemail/url`, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: JSON.stringify({ voicemailLink }),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new Error(\n `messages.getVoicemailUrl failed (HTTP ${res.status}): ${text.slice(0, 200)}`,\n );\n }\n return (await res.json()) as { url: string; expiresAt: string };\n }\n\n /**\n * End a Dialpad call via the typed oRPC procedure (POST hangup, with\n * 404→`alreadyEnded` so the UI doesn't flash an error on a natural\n * race). Replaces CommHub's `useEndCallMutation` Hasura action.\n *\n * Prefer this over `messages.dialpad.endCall` which goes through the\n * generic proxy (PUT, no 404 handling).\n */\n async endCall(callId: number | string): Promise<{\n ok: true;\n alreadyEnded: boolean;\n }> {\n const res = await fetch(`${this.baseUrl}/api/conversations/calls/end`, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: JSON.stringify({ callId }),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new Error(\n `messages.endCall failed (HTTP ${res.status}): ${text.slice(0, 200)}`,\n );\n }\n return (await res.json()) as { ok: true; alreadyEnded: boolean };\n }\n}\n\n// ---------------------------------------------------------------------------\n// Error\n// ---------------------------------------------------------------------------\n\nclass DialpadProxyError extends Error {\n readonly method: string;\n readonly path: string;\n readonly status: number;\n\n constructor(method: string, path: string, status: number) {\n super(\n `Dialpad proxy error: ${method} /api/messages/dialpad${path} returned ${status}`,\n );\n this.name = \"DialpadProxyError\";\n this.method = method;\n this.path = path;\n this.status = status;\n }\n}\n\nexport { DialpadResource, DialpadProxyError, MessagesResource };\nexport type {\n SendSmsParams,\n SendSmsResponse,\n InitiateCallResponse,\n CallStatusResponse,\n DialpadUser,\n DialpadNumberInfo,\n VoicemailAuthResponse,\n};\n","/**\n * EHR proxy resource — typed access to Truth's EHR proxy endpoints.\n *\n * Provides per-provider proxy methods so consumers never construct\n * proxy URLs manually. Every request carries the application's\n * `X-API-Key` — Truth's API gate rejects unauthenticated callers.\n *\n * @example\n * ```ts\n * const patient = await truth.ehr.elation.get('/patients/123/');\n * const notes = await truth.ehr.elation.post('/non_visit_notes/', noteData);\n * const hintPatient = await truth.ehr.hint.get('/provider/patients/456');\n * ```\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\n// ---------------------------------------------------------------------------\n// Provider proxy\n// ---------------------------------------------------------------------------\n\nclass EhrProviderProxy {\n private readonly baseUrl: string;\n private readonly provider: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n provider: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.provider = provider;\n this.auth = { apiKey, getAuthToken };\n }\n\n private async request<T>(\n method: string,\n path: string,\n body?: unknown,\n params?: Record<string, unknown>,\n ): Promise<T> {\n const url = new URL(`/api/ehr/${this.provider}${path}`, this.baseUrl);\n if (params) {\n for (const [key, value] of Object.entries(params)) {\n if (value !== undefined) {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n const response = await fetch(url.toString(), {\n method,\n // PHI (EHR/Elation proxy) — REQUIRE the user JWT. The server hardens the\n // EHR proxy routes to `verifiedUserProcedure`, so degrading to key-only\n // would 401.\n headers: await buildAuthHeaders(this.auth, {\n json: body !== undefined,\n requireUserToken: true,\n }),\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n\n if (!response.ok) {\n throw new EhrProxyError(this.provider, method, path, response.status);\n }\n\n return (await response.json()) as T;\n }\n\n /**\n * GET request to the EHR proxy.\n * @param path — path relative to the provider root (e.g., \"/patients/123/\")\n * @param params — optional query parameters\n */\n async get<T = unknown>(\n path: string,\n params?: Record<string, unknown>,\n ): Promise<T> {\n return this.request<T>(\"GET\", path, undefined, params);\n }\n\n /** POST request to the EHR proxy. */\n async post<T = unknown>(path: string, body?: unknown): Promise<T> {\n return this.request<T>(\"POST\", path, body);\n }\n\n /** PUT request to the EHR proxy. */\n async put<T = unknown>(path: string, body?: unknown): Promise<T> {\n return this.request<T>(\"PUT\", path, body);\n }\n\n /** PATCH request to the EHR proxy. */\n async patch<T = unknown>(path: string, body?: unknown): Promise<T> {\n return this.request<T>(\"PATCH\", path, body);\n }\n\n /** DELETE request to the EHR proxy. */\n async delete<T = unknown>(path: string): Promise<T> {\n return this.request<T>(\"DELETE\", path);\n }\n}\n\n// ---------------------------------------------------------------------------\n// EHR Resource — exposes per-provider proxies\n// ---------------------------------------------------------------------------\n\nclass EhrResource {\n /** Elation EHR proxy */\n readonly elation: EhrProviderProxy;\n\n /** Hint Health proxy */\n readonly hint: EhrProviderProxy;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.elation = new EhrProviderProxy(\n apiBaseUrl,\n \"elation\",\n apiKey,\n getAuthToken,\n );\n this.hint = new EhrProviderProxy(apiBaseUrl, \"hint\", apiKey, getAuthToken);\n }\n}\n\n// ---------------------------------------------------------------------------\n// Error\n// ---------------------------------------------------------------------------\n\nclass EhrProxyError extends Error {\n readonly provider: string;\n readonly method: string;\n readonly path: string;\n readonly status: number;\n\n constructor(provider: string, method: string, path: string, status: number) {\n super(\n `EHR proxy error: ${method} /api/ehr/${provider}${path} returned ${status}`,\n );\n this.name = \"EhrProxyError\";\n this.provider = provider;\n this.method = method;\n this.path = path;\n this.status = status;\n }\n}\n\nexport { EhrResource, EhrProviderProxy, EhrProxyError };\n","/**\n * NotesResource — push formatted notes to Elation.\n *\n * Caller assembles the note body (text + bullets). Truth owns the Elation\n * OAuth token and the HTTP call so applications can drop Elation\n * credentials from their own config.\n *\n * BREAKING — 0.26.20, `pushConversationToElation`:\n * - AUTH CLASS CHANGED. The server route moved from `applicationProcedure`\n * to `verifiedUserProcedure`, so an API key alone (including a secret\n * `hn_sk_*` or legacy `hn_live_*` key) now gets 401. Callers MUST supply\n * `getAuthToken` on the client so a verified Clerk JWT accompanies the\n * request; this resource already sends it with `requireUserToken: true`.\n * - `input.initiatedBy` is DEPRECATED and ignored server-side. The audit\n * row's actor is the JWT `sub`. Passing a differing value is logged as a\n * warning server-side and will be removed in a future major.\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\nexport interface NonVisitNoteBullet {\n text: string;\n category?: string;\n}\n\nexport interface PushNoteToElationInput {\n patient: number;\n physician: number;\n practice: number;\n note: { text: string; type?: string };\n document_date?: string;\n chart_date?: string;\n bullets?: NonVisitNoteBullet[];\n}\n\nexport interface PushNoteToElationResult {\n success: boolean;\n elationNoteId: number | null;\n}\n\nclass NotesError extends Error {\n readonly status: number;\n\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Notes ${operation} failed (HTTP ${status})`);\n this.name = \"NotesError\";\n this.status = status;\n }\n}\n\nexport interface PushConversationToElationInput {\n /** One-of: conversationId (Convex) or phonePair. */\n conversationId?: string;\n phonePair?: string;\n /**\n * @deprecated Ignored by the server; the actor recorded on the audit row is\n * derived from the verified Clerk JWT (`sub`). Supplying a value has no\n * effect and will be removed in a future major.\n */\n initiatedBy?: string;\n /** Pre-assembled note body (transcript-style text). */\n noteText: string;\n bullets?: NonVisitNoteBullet[];\n notesPushed?: number;\n messagesPushed?: number;\n tasksPushed?: number;\n /**\n * Convex ids of the `conversationNotes` rows included in this push. When\n * set, Truth rejects the call with 409 CONFLICT if any is already marked\n * sent (unless `resend`), rejects ids that are not in this conversation with\n * 404, and stamps each note sent on success (never on failure).\n */\n noteIds?: string[];\n /** Explicitly allow re-sending notes already marked sent. Default false. */\n resend?: boolean;\n}\n\nexport interface PushConversationToElationResult {\n success: true;\n batchId: string;\n elationNoteId: number | null;\n notesPushed: number;\n messagesPushed: number;\n tasksPushed: number;\n /** Notes stamped sent by this call (empty when no `noteIds` were supplied). */\n sentNoteIds: string[];\n}\n\nclass NotesResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n /** 30s upstream timeout — Elation API has occasional slow hops; we\n * don't want a pending mutation to hold the UI thread indefinitely. */\n private static readonly REQUEST_TIMEOUT_MS = 30_000;\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const controller = new AbortController();\n const timeout = setTimeout(\n () => controller.abort(),\n NotesResource.REQUEST_TIMEOUT_MS,\n );\n\n let res: Response;\n try {\n res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n // PHI (clinical notes) — REQUIRE the user JWT. The server hardens these\n // routes to `verifiedUserProcedure`, so degrading to key-only would 401.\n headers: await buildAuthHeaders(this.auth, {\n json: true,\n requireUserToken: true,\n }),\n body: JSON.stringify(body),\n signal: controller.signal,\n });\n } catch (err) {\n // Transport failures (DNS, TCP, TLS, AbortError) become typed\n // NotesError so consumers don't have to special-case raw fetch\n // exceptions. status=0 signals \"never made it to the server\".\n const isAbort =\n err instanceof Error &&\n (err.name === \"AbortError\" || err.name === \"TimeoutError\");\n const message = isAbort\n ? `Notes ${path} timed out after ${NotesResource.REQUEST_TIMEOUT_MS}ms`\n : err instanceof Error\n ? err.message\n : \"Notes request failed before response\";\n throw new NotesError(path, 0, message);\n } finally {\n clearTimeout(timeout);\n }\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new NotesError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n /**\n * Low-level — caller has already resolved Elation patient / physician\n * / practice. Use `pushConversationToElation` if you only have a\n * conversation handle.\n */\n async pushToElation(\n input: PushNoteToElationInput,\n ): Promise<PushNoteToElationResult> {\n return await this.post<PushNoteToElationResult>(\n \"/notes/push-to-elation\",\n input,\n );\n }\n\n /**\n * Orchestrator — pass a conversation handle + pre-assembled note text.\n * Truth resolves the linked patient via Convex, looks up\n * physician/practice in Elation, posts the note, and writes an audit\n * row to `elationSyncEvents`. Replaces CommHub's `pushNotesToElation`\n * Hasura action.\n *\n * Auth: requires a user token. The server runs this route under\n * `verifiedUserProcedure`, so the API key alone is rejected with 401 —\n * configure `getAuthToken` on the client. `input.initiatedBy` is ignored;\n * the audit row's actor is the verified JWT `sub`.\n */\n async pushConversationToElation(\n input: PushConversationToElationInput,\n ): Promise<PushConversationToElationResult> {\n return await this.post<PushConversationToElationResult>(\n \"/notes/push-conversation-to-elation\",\n input,\n );\n }\n}\n\nexport { NotesResource, NotesError };\n","/**\n * NotificationsResource — wraps Truth's /api/notifications/* endpoints.\n *\n * Server-side use (for example from a CommHub backend job or\n * another service): `truth.notifications.send({ userId, title, body })`.\n *\n * Client-side React usage lives in `@hipnation-truth/sdk/react` via\n * the `useNotifications` hook which mirrors `expo-notifications`.\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\nexport type NotificationPlatform = \"ios\" | \"android\" | \"web\";\n\nexport interface RegisterDeviceInput {\n userId: string;\n platform: NotificationPlatform;\n nativeToken?: string;\n webPushSubscription?: {\n endpoint: string;\n keys: { p256dh: string; auth: string };\n };\n appVersion?: string;\n osVersion?: string;\n locale?: string;\n timezone?: string;\n /**\n * iOS only — which APNs endpoint the `nativeToken` was issued\n * against. The token bytes don't carry this; it's determined by\n * the build's `aps-environment` entitlement\n * (`development` ⇒ sandbox, `production` ⇒ production). When the\n * consumer is an Expo app, detect via\n * `Application.getIosPushNotificationServiceEnvironmentAsync()`\n * from `expo-application` and pass the normalised value here.\n * Omitting this falls back to the application's default\n * `pushConfig.ios.environment` server-side.\n */\n apnsEnvironment?: \"sandbox\" | \"production\";\n}\n\nexport interface RegisterDeviceResult {\n deviceId: string;\n action: \"inserted\" | \"updated\";\n snsEndpointArn?: string;\n}\n\nexport interface UnregisterDeviceInput {\n nativeToken?: string;\n deviceId?: string;\n}\n\nexport interface SendNotificationInput {\n userId: string;\n title: string;\n body: string;\n data?: Record<string, unknown>;\n badge?: number;\n sound?: string;\n}\n\nexport interface SendNotificationResult {\n delivered: number;\n failed?: number;\n suppressed?: boolean;\n suppressionReason?: string;\n}\n\nexport interface NotificationPreferences {\n channels: { sms: boolean; push: boolean; email: boolean; inApp: boolean };\n quietHours?: {\n enabled: boolean;\n start: string;\n end: string;\n timezone: string;\n };\n doNotDisturbUntil?: string;\n updatedAt: string;\n}\n\nexport interface UpdatePreferencesInput {\n userId: string;\n channels?: NotificationPreferences[\"channels\"];\n quietHours?: NotificationPreferences[\"quietHours\"];\n doNotDisturbUntil?: string | null;\n}\n\nexport interface ScheduleNotificationInput extends SendNotificationInput {\n /** ISO 8601 timestamp; must be strictly in the future. */\n scheduledAt: string;\n}\n\nexport interface ScheduleNotificationResult {\n jobId: string;\n scheduledAt: string;\n}\n\nexport interface CancelScheduledNotificationResult {\n cancelled: boolean;\n reason?: string;\n status?: string;\n}\n\nexport type ScheduledJobStatus =\n | \"pending\"\n | \"executed\"\n | \"cancelled\"\n | \"failed\";\n\nexport interface ScheduledNotification {\n jobId: string;\n userId: string;\n title: string;\n body: string;\n data?: unknown;\n badge?: number;\n sound?: string;\n scheduledAt: string;\n status: ScheduledJobStatus;\n resultHistoryId?: string;\n errorMessage?: string;\n createdAt: string;\n}\n\nexport interface PushEventPayload {\n title: string;\n body: string;\n data?: unknown;\n}\n\nclass NotificationsError extends Error {\n readonly status: number;\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Notifications ${operation} failed (HTTP ${status})`);\n this.name = \"NotificationsError\";\n this.status = status;\n }\n}\n\nclass NotificationsResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new NotificationsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n private async get<T>(\n path: string,\n params: Record<string, string>,\n ): Promise<T> {\n const url = new URL(`${this.baseUrl}/api${path}`);\n for (const [k, v] of Object.entries(params)) {\n url.searchParams.set(k, v);\n }\n const res = await fetch(url.toString(), {\n method: \"GET\",\n headers: await buildAuthHeaders(this.auth),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new NotificationsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n private async delete<T>(path: string): Promise<T> {\n const res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"DELETE\",\n headers: await buildAuthHeaders(this.auth),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new NotificationsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n /**\n * Register a device (or refresh its metadata) for push delivery.\n * Safe to call repeatedly — the server dedupes by native token.\n */\n async registerDevice(\n input: RegisterDeviceInput,\n ): Promise<RegisterDeviceResult> {\n return this.post(\"/notifications/devices/register\", input);\n }\n\n /** Revoke a device — on sign-out or when the OS reports an invalid token. */\n async unregisterDevice(\n input: UnregisterDeviceInput,\n ): Promise<{ revoked: boolean }> {\n return this.post(\"/notifications/devices/unregister\", input);\n }\n\n /**\n * Send a push notification to every active device belonging to\n * `userId`. Honors the user's notificationPreferences (quiet hours,\n * DND, channel off) before publishing.\n */\n async send(input: SendNotificationInput): Promise<SendNotificationResult> {\n return this.post(\"/notifications/send\", input);\n }\n\n /** Read a user's notification preferences. Returns defaults when no row exists. */\n async getPreferences(userId: string): Promise<NotificationPreferences> {\n return this.get(\"/notifications/preferences\", { userId });\n }\n\n async updatePreferences(\n input: UpdatePreferencesInput,\n ): Promise<{ ok: boolean }> {\n return this.post(\"/notifications/preferences\", input);\n }\n\n /**\n * Schedule a future push notification. Convex's native scheduler\n * fires the send at `scheduledAt` and runs the same delivery\n * pipeline as `send()` (preferences, devices, history audit).\n *\n * Throws `NotificationsError` with status 400 if `scheduledAt` is\n * not strictly in the future.\n */\n async schedule(\n input: ScheduleNotificationInput,\n ): Promise<ScheduleNotificationResult> {\n return this.post(\"/notifications/schedule\", input);\n }\n\n /**\n * Cancel a pending scheduled notification. Returns `cancelled: false`\n * (no error) if the job has already executed, was previously\n * cancelled, or no longer exists — `reason` describes which case.\n */\n async cancelScheduled(\n jobId: string,\n ): Promise<CancelScheduledNotificationResult> {\n return this.delete(`/notifications/schedule/${encodeURIComponent(jobId)}`);\n }\n\n /**\n * List scheduled notifications for a user — pending, executed,\n * cancelled, or failed. Most-recent first. Default limit 100.\n */\n async listScheduled(\n userId: string,\n options?: { limit?: number },\n ): Promise<ScheduledNotification[]> {\n const params: Record<string, string> = { userId };\n if (options?.limit !== undefined) {\n params.limit = String(options.limit);\n }\n return this.get(\"/notifications/schedule\", params);\n }\n\n async getVapidKey(): Promise<string | null> {\n try {\n const result = await this.get<{ vapidPublicKey: string | null }>(\n \"/notifications/vapid-key\",\n {},\n );\n return result.vapidPublicKey;\n } catch {\n return null;\n }\n }\n\n onPushReceived(callback: (payload: PushEventPayload) => void): () => void {\n if (typeof navigator === \"undefined\" || !(\"serviceWorker\" in navigator)) {\n return () => {};\n }\n const handler = (event: MessageEvent) => {\n if (event.data?.type === \"TRUTH_PUSH_RECEIVED\") {\n callback(event.data.payload);\n }\n };\n navigator.serviceWorker.addEventListener(\"message\", handler);\n return () =>\n navigator.serviceWorker.removeEventListener(\"message\", handler);\n }\n\n onPushTapped(callback: (payload: PushEventPayload) => void): () => void {\n if (typeof navigator === \"undefined\" || !(\"serviceWorker\" in navigator)) {\n return () => {};\n }\n const handler = (event: MessageEvent) => {\n if (event.data?.type === \"TRUTH_PUSH_TAPPED\") {\n callback(event.data.payload);\n }\n };\n navigator.serviceWorker.addEventListener(\"message\", handler);\n return () =>\n navigator.serviceWorker.removeEventListener(\"message\", handler);\n }\n}\n\nexport { NotificationsResource, NotificationsError };\n","/**\n * PatientDetailsResource — merged Hint + Elation patient lookups.\n *\n * Backed by the Truth API at /api/patients/details/*, authenticated with\n * X-API-Key. Replaces CommHub's getPatientDetails / getPatientBasicDetails\n * / getPatientMedicalDetails actions.\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\nexport interface PatientDetailsInput {\n hintId?: string;\n elationId?: string;\n}\n\nexport interface PatientDetailsResult {\n hint: unknown | null;\n elation: unknown | null;\n resolvedElationId: string | null;\n}\n\nexport interface PatientBasicDetailsResult {\n hint: unknown | null;\n elationId: string | null;\n}\n\nexport interface PatientMedicalDetailsResult {\n problems: unknown | null;\n medications: unknown | null;\n allergies: unknown | null;\n appointments: unknown | null;\n}\n\nclass PatientDetailsError extends Error {\n readonly status: number;\n\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Patient ${operation} failed (HTTP ${status})`);\n this.name = \"PatientDetailsError\";\n this.status = status;\n }\n}\n\nclass PatientDetailsResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const res = await fetch(`${this.baseUrl}/api${path}`, {\n method: \"POST\",\n // PHI (patient chart) — REQUIRE the user JWT. The server hardens these\n // routes to `verifiedUserProcedure`, so degrading to key-only would 401.\n // `requireUserToken` retries token resolution across the Clerk-hydration\n // gap and throws a clear auth error if none is obtainable, rather than\n // silently sending key-only.\n headers: await buildAuthHeaders(this.auth, {\n json: true,\n requireUserToken: true,\n }),\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new PatientDetailsError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n async get(input: PatientDetailsInput): Promise<PatientDetailsResult> {\n return await this.post<PatientDetailsResult>(\"/patients/details\", input);\n }\n\n async getBasic(\n input: PatientDetailsInput,\n ): Promise<PatientBasicDetailsResult> {\n return await this.post<PatientBasicDetailsResult>(\n \"/patients/details/basic\",\n input,\n );\n }\n\n async getMedical(elationId: string): Promise<PatientMedicalDetailsResult> {\n return await this.post<PatientMedicalDetailsResult>(\n \"/patients/details/medical\",\n { elationId },\n );\n }\n\n /**\n * Trigger a server-side refresh of the patient's Elation medical\n * records (medications, problems, allergies, appointments) into the\n * Convex cache. Fire-and-forget — the UI should read via the Convex-\n * reactive `usePatientMedical` hook.\n */\n async refreshMedical(elationId: number): Promise<{\n totals: {\n medications: number;\n problems: number;\n allergies: number;\n appointments: number;\n };\n }> {\n return await this.post<{\n totals: {\n medications: number;\n problems: number;\n allergies: number;\n appointments: number;\n };\n }>(\"/patients/medical/refresh\", { elationId });\n }\n}\n\nexport { PatientDetailsResource, PatientDetailsError };\n","/**\n * Coerce a patient elationId to a 64-bit integer (`bigint`) for Convex queries.\n *\n * Elation ids are `long(64)` and originate as Hasura bigints, which serialize\n * as **strings** (e.g. \"140754874499075\") and can exceed 2^53 — so a JS\n * `number` (`v.float64()`) would silently lose precision. The Convex patient\n * validators are being normalized to `v.int64()`, which over the wire is a JS\n * `bigint`. We coerce here — at the single boundary between the patient hooks\n * and the Convex validators — so every caller (web admin panel + mobile app,\n * any build) passes a precision-exact `bigint` regardless of whether it happened\n * to receive the id as a string, a number, or a bigint.\n *\n * Returns `undefined` for null/empty/non-numeric input so the hook can pass\n * `\"skip\"`. A numeric string is converted with `BigInt(str)` (exact); a number\n * with `BigInt(Math.trunc(n))` when finite + integer.\n */\nexport function toBigIntElationId(value: unknown): bigint | undefined {\n if (value === undefined || value === null || value === \"\") {\n return undefined;\n }\n if (typeof value === \"bigint\") {\n return value;\n }\n if (typeof value === \"number\") {\n if (!Number.isFinite(value) || !Number.isInteger(value)) {\n return undefined;\n }\n return BigInt(Math.trunc(value));\n }\n if (typeof value === \"string\") {\n const trimmed = value.trim();\n if (!/^\\d+$/.test(trimmed)) {\n return undefined;\n }\n try {\n return BigInt(trimmed);\n } catch {\n return undefined;\n }\n }\n return undefined;\n}\n\n/**\n * Coerce a patient elationId to a finite `number`, or `undefined` for\n * null/empty/non-numeric input.\n *\n * Still used for the `elationPatientId` args of the medical-record and photo\n * queries, whose Convex validators remain `v.number()` (those tables are not\n * part of the int64 normalization). For the patient / elationPatients basic\n * lookups (now `v.int64()`), use `toBigIntElationId` instead.\n */\nexport function toFiniteElationId(value: unknown): number | undefined {\n if (value === undefined || value === null || value === \"\") {\n return undefined;\n }\n const n = typeof value === \"number\" ? value : Number(value);\n return Number.isFinite(n) ? n : undefined;\n}\n","/**\n * PatientResource provides data access to normalized patient records\n * backed by Convex.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport { toBigIntElationId } from \"../react/elation-id\";\nimport type { PaginatedResult } from \"../types/config\";\nimport type { Patient, PatientListOptions } from \"../types/patient\";\n\nclass PatientResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convexClient: ConvexHttpClient) {\n this.convex = convexClient;\n }\n\n /**\n * Get a patient by their Truth platform ID.\n */\n async get(id: string): Promise<Patient | null> {\n try {\n const result = await this.convex.query(\n \"patients:getById\" as never,\n {\n id,\n } as never,\n );\n return (result as Patient) ?? null;\n } catch {\n return null;\n }\n }\n\n /**\n * Get a patient by their Elation EHR ID.\n *\n * Accepts the id in any form (string/number/bigint) and coerces it to a\n * `bigint` (int64) for the now-int64 Convex `patients:getByElationId` arg.\n * Returns `null` for a non-numeric / absent id.\n */\n async getByElationId(\n elationId: string | number | bigint,\n ): Promise<Patient | null> {\n const id = toBigIntElationId(elationId);\n if (id === undefined) {\n return null;\n }\n try {\n const result = await this.convex.query(\n \"patients:getByElationId\" as never,\n { elationId: id } as never,\n );\n return (result as Patient) ?? null;\n } catch {\n return null;\n }\n }\n\n /**\n * Get a patient by their Hint EHR ID.\n */\n async getByHintId(hintId: string): Promise<Patient | null> {\n try {\n const result = await this.convex.query(\n \"patients:getByHintId\" as never,\n {\n hintId,\n } as never,\n );\n return (result as Patient) ?? null;\n } catch {\n return null;\n }\n }\n\n /**\n * List patients with optional search, pagination, and limit.\n */\n async list(options?: PatientListOptions): Promise<PaginatedResult<Patient>> {\n try {\n const result = await this.convex.query(\n \"patients:list\" as never,\n {\n search: options?.search,\n limit: options?.limit,\n cursor: options?.cursor,\n } as never,\n );\n\n const typed = result as PaginatedResult<Patient> | undefined;\n\n return typed ?? { data: [], cursor: null, hasMore: false };\n } catch {\n return { data: [], cursor: null, hasMore: false };\n }\n }\n}\n\nexport { PatientResource };\n","/**\n * PhysiciansResource — Convex-backed physician lookups.\n *\n * Populated from Elation by Truth's daily PhysiciansBackfillCron. Replaces\n * per-physician Elation HTTP hops with a single Convex batch query.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\n\nexport interface Physician {\n _id: string;\n elationId: number;\n firstName?: string;\n lastName?: string;\n npi?: string;\n credentials?: string;\n specialties?: string[];\n practice?: number;\n email?: string;\n phone?: string;\n lastSyncedAt: string;\n}\n\nclass PhysiciansResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convex: ConvexHttpClient) {\n this.convex = convex;\n }\n\n /**\n * Resolve a batch of physicians by Elation IDs. Missing ids are dropped.\n */\n async getByElationIds(ids: number[]): Promise<Physician[]> {\n if (ids.length === 0) {\n return [];\n }\n try {\n const rows = (await this.convex.query(\n \"physicians:getByElationIds\" as never,\n { ids } as never,\n )) as Physician[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n\n async getByElationId(id: number): Promise<Physician | null> {\n try {\n const row = (await this.convex.query(\n \"physicians:getByElationId\" as never,\n { id } as never,\n )) as Physician | null;\n return row ?? null;\n } catch {\n return null;\n }\n }\n\n async listByPractice(practice: number, limit?: number): Promise<Physician[]> {\n try {\n const rows = (await this.convex.query(\n \"physicians:listByPractice\" as never,\n { practice, limit } as never,\n )) as Physician[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n}\n\nexport { PhysiciansResource };\n","/**\n * RemindersResource — schedule, cancel, and list conversation reminders.\n *\n * Backed by Convex mutations/queries (durable scheduled functions) — replaces\n * the in-memory setTimeout scheduler that used to live in CommHub's NestJS\n * backend.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport type {\n Reminder,\n ScheduleReminderInput,\n ScheduleReminderResult,\n} from \"../types/reminder\";\n\nclass RemindersResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convexClient: ConvexHttpClient) {\n this.convex = convexClient;\n }\n\n /**\n * Schedule a reminder to fire at `remindAt`. Returns the reminder id,\n * which callers should store if they may want to cancel it later.\n */\n async schedule(\n input: ScheduleReminderInput,\n ): Promise<ScheduleReminderResult> {\n const remindAt =\n input.remindAt instanceof Date\n ? input.remindAt.toISOString()\n : input.remindAt;\n\n const result = (await this.convex.mutation(\n \"reminders:schedule\" as never,\n {\n conversationId: input.conversationId,\n remindAt,\n note: input.note,\n createdBy: input.createdBy,\n createdByClerkId: input.createdByClerkId,\n } as never,\n )) as ScheduleReminderResult;\n\n return result;\n }\n\n /**\n * Cancel a pending reminder. No-op if the reminder has already fired or\n * been cancelled.\n */\n async cancel(\n reminderId: string,\n cancelledBy: string,\n ): Promise<{ reminderId: string; status: string }> {\n return (await this.convex.mutation(\n \"reminders:cancel\" as never,\n { reminderId, cancelledBy } as never,\n )) as { reminderId: string; status: string };\n }\n\n /**\n * List reminders for a conversation (most recent first).\n */\n async listByConversation(conversationId: string): Promise<Reminder[]> {\n try {\n const rows = (await this.convex.query(\n \"reminders:listByConversation\" as never,\n { conversationId } as never,\n )) as Reminder[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n}\n\nexport { RemindersResource };\n","/**\n * ReportsResource — member activation report from truth.\n *\n * Accesses the Truth API at GET /reports/member-activation,\n * authenticated with X-API-Key + user JWT (verifiedUserProcedure).\n *\n * Replaces the broker pattern: frontend calls truth directly via SDK,\n * no comhub hop.\n */\n\nimport { z } from \"zod\";\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\n// ---- Schema (mirrors truth's reportSchema) ----\n\nconst memberSchema = z.object({\n elationId: z.string(),\n name: z.string(),\n // T6: mirrors truth's member-activation-report.ts memberSchema (T5).\n // Optional/nullable so a comhub build against an older/newer server\n // payload still parses either way.\n lastName: z.string().nullable().optional(),\n firstName: z.string().nullable().optional(),\n doctor: z.string().nullable(),\n status: z.enum([\"activated\", \"outreach\", \"scheduled\", \"review\", \"data\"]),\n membershipStart: z.string(),\n daysSinceMembershipStart: z.number(),\n activationDate: z.string().nullable(),\n futureApptDate: z.string().nullable(),\n reason: z.string().nullable(),\n hasLink: z.boolean(),\n});\n\nexport const reportSchema = z.object({\n synthetic: z.boolean(),\n generatedAt: z.string(),\n employers: z.array(\n z.object({ id: z.string(), name: z.string(), activeMembers: z.number() }),\n ),\n selected: z\n .object({\n employerId: z.string(),\n employerName: z.string(),\n kpis: z.object({\n active: z.number(),\n linked: z.number(),\n activated: z.number(),\n needsOutreach: z.number(),\n scheduled: z.number(),\n needsReview: z.number(),\n dataIssue: z.number(),\n activationRate: z.number(),\n }),\n coverage: z.object({\n active: z.number(),\n linked: z.number(),\n unlinked: z.number(),\n pct: z.number(),\n }),\n breakdown: z.array(\n z.object({\n status: z.enum([\n \"activated\",\n \"outreach\",\n \"scheduled\",\n \"review\",\n \"data\",\n ]),\n label: z.string(),\n count: z.number(),\n pct: z.number(),\n }),\n ),\n aging: z.array(\n z.object({\n bucket: z.string(),\n total: z.number(),\n outreach: z.number(),\n scheduled: z.number(),\n review: z.number(),\n }),\n ),\n doctors: z.array(\n z.object({\n name: z.string(),\n counts: z.object({\n outreach: z.number(),\n scheduled: z.number(),\n review: z.number(),\n data: z.number(),\n }),\n members: z.array(memberSchema),\n }),\n ),\n })\n .nullable(),\n // True when the requested employer has no materialized report row yet\n // (ehr-sync's dailyHandler has not run for it). `selected` is null in that\n // case — the caller sees the employer roster but no report data to render.\n pending: z.boolean(),\n // #249: every distinct doctor across all stored employer reports (deduped\n // server-side by normalized name). Optional: older servers omit it, and\n // the server omits it when the roster query fails.\n doctorRoster: z.array(z.string()).optional(),\n});\n\nexport type MemberActivationReport = z.infer<typeof reportSchema>;\n\n// #249: GET /reports/member-activation/by-doctor. Members carry no\n// lastName/firstName and there is no activatedMembers list (server-side\n// redaction pending staff-only access).\nexport const memberActivationByDoctorSchema = z.object({\n doctor: z.string(),\n // Oldest generatedAt of the stored employer reports used; null when no\n // employer matched.\n generatedAt: z.string().nullable(),\n employers: z.array(\n z.object({\n employerId: z.string(),\n employerName: z.string(),\n counts: z.object({\n outreach: z.number(),\n scheduled: z.number(),\n review: z.number(),\n data: z.number(),\n }),\n members: z.array(memberSchema.omit({ lastName: true, firstName: true })),\n }),\n ),\n});\n\nexport type MemberActivationByDoctor = z.infer<\n typeof memberActivationByDoctorSchema\n>;\n\nclass ReportsError extends Error {\n readonly status: number;\n\n /**\n * Wraps a failed reports HTTP call with the operation name and status\n * code so callers can branch on `status` without re-parsing the message.\n * Falls back to a generated message when the server response body is\n * empty or unreadable.\n */\n constructor(operation: string, status: number, message?: string) {\n const trimmedMessage = message?.trim();\n super(trimmedMessage || `Reports ${operation} failed (HTTP ${status})`);\n this.name = \"ReportsError\";\n this.status = status;\n }\n}\n\nclass ReportsResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n /**\n * Captures the Truth API base URL and the auth inputs (API key + optional\n * user-token fetcher) needed to authenticate every request this resource\n * makes.\n */\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n /**\n * Fetches the member activation report from GET /reports/member-activation,\n * optionally scoped to a single employer. Requires the user JWT (not just\n * the API key) since the server hardens this route to\n * `verifiedUserProcedure` for PHI access — throws via `ReportsError` on a\n * non-OK response, including the response body (truncated) when present.\n */\n async memberActivation(params?: {\n employerId?: string;\n }): Promise<MemberActivationReport> {\n const url = new URL(`${this.baseUrl}/api/reports/member-activation`);\n if (params?.employerId) {\n url.searchParams.set(\"employerId\", params.employerId);\n }\n\n const res = await fetch(url.toString(), {\n method: \"GET\",\n // PHI (member activation report) — REQUIRE the user JWT. The server\n // hardens this route to `verifiedUserProcedure`, so degrading to\n // key-only would 401. `requireUserToken` retries across the Clerk-\n // hydration gap and throws rather than silently sending key-only.\n headers: await buildAuthHeaders(this.auth, {\n requireUserToken: true,\n }),\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ReportsError(\n \"member-activation\",\n res.status,\n text.slice(0, 200),\n );\n }\n\n return (await res.json()) as MemberActivationReport;\n }\n\n /**\n * Fetches one doctor's non-activated members across every employer from\n * GET /reports/member-activation/by-doctor. The server matches names\n * ignoring case, spacing, punctuation and Dr./MD/DO, so \"Dr. Marie Curie\"\n * and \"Marie Curie, MD\" return the same employers. An unknown doctor\n * returns `employers: []`, not an error. Requires the user JWT (same as\n * `memberActivation`); throws `ReportsError` on a non-OK response.\n */\n async memberActivationByDoctor(params: {\n doctor: string;\n }): Promise<MemberActivationByDoctor> {\n const url = new URL(\n `${this.baseUrl}/api/reports/member-activation/by-doctor`,\n );\n url.searchParams.set(\"doctor\", params.doctor);\n\n const res = await fetch(url.toString(), {\n method: \"GET\",\n headers: await buildAuthHeaders(this.auth, {\n requireUserToken: true,\n }),\n });\n\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new ReportsError(\n \"member-activation-by-doctor\",\n res.status,\n text.slice(0, 200),\n );\n }\n\n return (await res.json()) as MemberActivationByDoctor;\n }\n}\n\nexport { ReportsResource, ReportsError };\n","/**\n * TasksResource — create, update status, list, get tasks.\n *\n * Backed by Convex. Replaces CommHub's createTaskWithNotification +\n * updateTaskStatusWithNotification actions. The push notification side-effect\n * is NOT emitted via Kinesis: the Convex task mutation enqueues a\n * `notificationJobs` row and schedules `notificationScheduler.runJob`, which\n * HTTP-fetches the Truth Lambda push endpoint (Truth API → Convex scheduler →\n * push). See apps/web/convex/lib/taskPush.ts.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport type {\n ConversationTaskMarkSeenInput,\n CreateTaskInput,\n Task,\n TaskStatus,\n UpdateTaskStatusInput,\n} from \"../types/task\";\n\nclass TasksResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convexClient: ConvexHttpClient) {\n this.convex = convexClient;\n }\n\n async create(\n input: CreateTaskInput,\n ): Promise<{ taskId: string; status: TaskStatus }> {\n return (await this.convex.mutation(\n \"tasks:create\" as never,\n input as never,\n )) as { taskId: string; status: TaskStatus };\n }\n\n async updateStatus(input: UpdateTaskStatusInput): Promise<{\n taskId: string;\n status: TaskStatus;\n previousStatus: TaskStatus;\n }> {\n return (await this.convex.mutation(\n \"tasks:updateStatus\" as never,\n input as never,\n )) as {\n taskId: string;\n status: TaskStatus;\n previousStatus: TaskStatus;\n };\n }\n\n async get(taskId: string): Promise<Task | null> {\n try {\n const row = (await this.convex.query(\n \"tasks:get\" as never,\n { taskId } as never,\n )) as Task | null;\n return row ?? null;\n } catch {\n return null;\n }\n }\n\n async listByAssignee(\n assignedTo: string,\n options?: { status?: TaskStatus; limit?: number },\n ): Promise<Task[]> {\n try {\n const rows = (await this.convex.query(\n \"tasks:listByAssignee\" as never,\n {\n assignedTo,\n status: options?.status,\n limit: options?.limit,\n } as never,\n )) as Task[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n\n async listOpen(limit?: number): Promise<Task[]> {\n try {\n const rows = (await this.convex.query(\n \"tasks:listOpen\" as never,\n { limit } as never,\n )) as Task[] | null;\n return rows ?? [];\n } catch {\n return [];\n }\n }\n\n /**\n * Mark a conversation task as seen by the given user. Appends `userId`\n * to the `seenBy` array on the `conversationTasks` row if not already\n * present. Replaces CommHub's `useMark_Event_Activity_SeenMutation`.\n *\n * @returns `{ ok: true }` on success.\n * @throws if the task does not exist in Convex.\n */\n async markSeen(input: ConversationTaskMarkSeenInput): Promise<{ ok: true }> {\n return (await this.convex.mutation(\n \"conversationTasks:markSeen\" as never,\n input as never,\n )) as { ok: true };\n }\n}\n\nexport { TasksResource };\n","/**\n * TranslationResource — Azure Translator proxy through Truth API.\n *\n * All three operations are HTTP calls to Truth's oRPC endpoints at\n * `/api/translation/*`, authenticated with the same X-API-Key as the\n * event tracker.\n */\n\nimport type { AuthTokenFetcher } from \"../types/config\";\nimport type {\n DetectionResult,\n TranslateBatchInput,\n TranslateTextInput,\n TranslationResult,\n} from \"../types/translation\";\nimport { buildAuthHeaders, type RestAuth } from \"./rest-auth\";\n\nclass TranslationError extends Error {\n readonly status: number;\n readonly operation: string;\n\n constructor(operation: string, status: number, message?: string) {\n super(message ?? `Translation ${operation} failed (HTTP ${status})`);\n this.name = \"TranslationError\";\n this.status = status;\n this.operation = operation;\n }\n}\n\nclass TranslationResource {\n private readonly baseUrl: string;\n private readonly auth: RestAuth;\n\n constructor(\n apiBaseUrl: string,\n apiKey: string,\n getAuthToken?: AuthTokenFetcher,\n ) {\n this.baseUrl = apiBaseUrl;\n this.auth = { apiKey, getAuthToken };\n }\n\n private async post<T>(path: string, body: unknown): Promise<T> {\n const url = `${this.baseUrl}/api${path}`;\n const res = await fetch(url, {\n method: \"POST\",\n headers: await buildAuthHeaders(this.auth, { json: true }),\n body: JSON.stringify(body),\n });\n if (!res.ok) {\n const text = await res.text().catch(() => \"\");\n throw new TranslationError(path, res.status, text.slice(0, 200));\n }\n return (await res.json()) as T;\n }\n\n async translate(input: TranslateTextInput): Promise<TranslationResult> {\n return await this.post<TranslationResult>(\"/translation/translate\", input);\n }\n\n async translateBatch(\n input: TranslateBatchInput,\n ): Promise<TranslationResult[]> {\n const response = await this.post<{ results: TranslationResult[] }>(\n \"/translation/translate-batch\",\n input,\n );\n return response.results;\n }\n\n async detect(text: string): Promise<DetectionResult> {\n return await this.post<DetectionResult>(\"/translation/detect\", { text });\n }\n}\n\nexport { TranslationResource, TranslationError };\n","/**\n * UserSettingsResource — typed client for the Truth `userSettings` Convex\n * table. Exposes the one mutation CommHub's Settings screen needs:\n * `updateNotifications({ userId, notificationsEnabled })`.\n *\n * Server-side / imperative use:\n * truth.userSettings.updateNotifications({ userId, notificationsEnabled: true })\n *\n * Reactive React use lives in `@hipnation-truth/sdk/react` via\n * `useUserSettings`.\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport { makeFunctionReference } from \"convex/server\";\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\nexport interface UserSettings {\n _id: string;\n userId: string;\n notificationsEnabled: boolean;\n createdAt: string;\n updatedAt: string;\n}\n\nexport interface UpdateNotificationsInput {\n userId: string;\n notificationsEnabled: boolean;\n}\n\nexport interface UpdateNotificationsResult {\n action: \"inserted\" | \"updated\";\n id: string;\n}\n\n// ---------------------------------------------------------------------------\n// Convex function references (string-based, SDK stays decoupled from codegen)\n// ---------------------------------------------------------------------------\n\nconst upsertNotificationsRef = makeFunctionReference<\n \"mutation\",\n { userId: string; notificationsEnabled: boolean },\n UpdateNotificationsResult\n>(\"userSettings:upsertNotifications\");\n\n// ---------------------------------------------------------------------------\n// Resource\n// ---------------------------------------------------------------------------\n\nclass UserSettingsResource {\n private readonly convex: ConvexHttpClient;\n\n constructor(convex: ConvexHttpClient) {\n this.convex = convex;\n }\n\n /**\n * Upsert notification preferences for a user. Creates the row if it\n * doesn't exist; patches `notificationsEnabled` + `updatedAt` otherwise.\n */\n async updateNotifications(\n input: UpdateNotificationsInput,\n ): Promise<UpdateNotificationsResult> {\n return this.convex.mutation(upsertNotificationsRef, input);\n }\n}\n\nexport { UserSettingsResource };\n","/**\n * Event tracker with batching, retry, and flush support.\n *\n * Buffers events in an internal queue and flushes them to the Truth API\n * endpoint. Flushes occur when the buffer reaches `batchSize` or every\n * `flushIntervalMs` milliseconds, whichever comes first.\n */\n\nimport type { ActorContext } from \"../types/config\";\nimport type {\n EventEnvelope,\n EventPayloadMap,\n EventType,\n TrackOptions,\n} from \"./events\";\n\n// ---------------------------------------------------------------------------\n// UUID v7 helper (no external dependency)\n// ---------------------------------------------------------------------------\n\n/**\n * Generates a UUID v7 string. Uses crypto.randomUUID where available,\n * falling back to a timestamp + random bytes implementation.\n *\n * UUID v7 layout (RFC 9562):\n * 48 bits - unix timestamp (ms)\n * 4 bits - version (0b0111)\n * 12 bits - random\n * 2 bits - variant (0b10)\n * 62 bits - random\n */\nfunction generateUuidV7(): string {\n const now = Date.now();\n\n // 6 bytes of timestamp\n const timeBytes = new Uint8Array(6);\n let ts = now;\n for (let i = 5; i >= 0; i--) {\n timeBytes[i] = ts & 0xff;\n ts = Math.floor(ts / 256);\n }\n\n // 10 bytes of random\n const randomBytes = new Uint8Array(10);\n if (\n typeof globalThis.crypto !== \"undefined\" &&\n globalThis.crypto.getRandomValues\n ) {\n globalThis.crypto.getRandomValues(randomBytes);\n } else {\n for (let i = 0; i < 10; i++) {\n randomBytes[i] = Math.floor(Math.random() * 256);\n }\n }\n\n // Assemble 16 bytes\n const bytes = new Uint8Array(16);\n bytes.set(timeBytes, 0);\n bytes.set(randomBytes, 6);\n\n // Set version (bits 48-51 to 0b0111)\n bytes[6] = (bytes[6] & 0x0f) | 0x70;\n\n // Set variant (bits 64-65 to 0b10)\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n\n // Format as hex string with dashes\n const hex = Array.from(bytes)\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n\n return [\n hex.slice(0, 8),\n hex.slice(8, 12),\n hex.slice(12, 16),\n hex.slice(16, 20),\n hex.slice(20, 32),\n ].join(\"-\");\n}\n\n// ---------------------------------------------------------------------------\n// Environment-based API URL resolution\n// ---------------------------------------------------------------------------\n\n// Environment → Truth API base URL.\n//\n// Topology:\n// local / staging / stg / sandbox → sandbox Truth (app.sandbox.*)\n// uat / production → production Truth (app.truth.*)\n//\n// UAT shares production resources (same Fly Postgres + Hasura + Truth +\n// Convex + EHR tokens as prod). Staging is the isolated sandbox env.\nconst API_URLS: Record<string, string> = {\n local: \"http://localhost:3000\",\n staging: \"https://app.sandbox.communication-hub.com\",\n stg: \"https://app.sandbox.communication-hub.com\",\n sandbox: \"https://app.sandbox.communication-hub.com\",\n uat: \"https://app.truth.communication-hub.com\",\n production: \"https://app.truth.communication-hub.com\",\n};\n\n// ---------------------------------------------------------------------------\n// Constants\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_BATCH_SIZE = 25;\nconst DEFAULT_FLUSH_INTERVAL_MS = 5_000;\nconst MAX_RETRIES = 3;\nconst BASE_RETRY_DELAY_MS = 500;\n\n// ---------------------------------------------------------------------------\n// Tracker configuration\n// ---------------------------------------------------------------------------\n\ninterface TrackerConfig {\n apiKey: string;\n environment: string;\n source: string;\n sourceVersion: string;\n tenantId: string;\n batchSize: number;\n flushIntervalMs: number;\n apiBaseUrl?: string;\n}\n\n// ---------------------------------------------------------------------------\n// Tracker class\n// ---------------------------------------------------------------------------\n\nclass Tracker {\n private readonly config: TrackerConfig;\n readonly apiUrl: string;\n private queue: EventEnvelope[] = [];\n private flushTimer: ReturnType<typeof setInterval> | null = null;\n private defaultActor: ActorContext | undefined;\n private isFlushing = false;\n private isShutdown = false;\n\n constructor(config: TrackerConfig) {\n this.config = config;\n this.apiUrl =\n config.apiBaseUrl ?? API_URLS[config.environment] ?? API_URLS.local;\n\n this.startFlushInterval();\n this.registerShutdownHooks();\n }\n\n /**\n * Set the default actor context for subsequent events.\n */\n setActor(actor: ActorContext): void {\n this.defaultActor = actor;\n }\n\n /**\n * Enqueue a typed event for delivery. This is fire-and-forget from\n * the caller's perspective -- events are buffered and flushed in batches.\n */\n track<T extends EventType>(\n eventType: T,\n payload: EventPayloadMap[T],\n options?: TrackOptions,\n ): void {\n if (this.isShutdown) {\n return;\n }\n\n const now = new Date().toISOString();\n\n const envelope: EventEnvelope = {\n event_id: generateUuidV7(),\n event_type: eventType,\n schema_version: 1,\n occurred_at: options?.occurredAt ?? now,\n received_at: now,\n source: this.config.source,\n source_version: this.config.sourceVersion,\n tenant_id: options?.tenantId ?? this.config.tenantId,\n actor:\n options?.actor ??\n (this.defaultActor\n ? {\n actor_id: this.defaultActor.actorId,\n actor_type: this.defaultActor.actorType,\n }\n : undefined),\n subject: options?.subject,\n compliance: options?.compliance,\n payload: payload as unknown as Record<string, unknown>,\n };\n\n this.queue.push(envelope);\n\n if (this.queue.length >= this.config.batchSize) {\n void this.flush();\n }\n }\n\n /**\n * Force an immediate flush of all buffered events.\n * Returns a promise that resolves when the flush completes.\n */\n async flush(): Promise<void> {\n if (this.queue.length === 0 || this.isFlushing) {\n return;\n }\n\n this.isFlushing = true;\n const batch = this.queue.splice(0, this.config.batchSize);\n\n try {\n await this.sendBatch(batch);\n } catch {\n // Re-queue events that failed to send (prepend to maintain ordering)\n this.queue.unshift(...batch);\n } finally {\n this.isFlushing = false;\n }\n\n // If there are still events in the queue, flush again\n if (this.queue.length >= this.config.batchSize) {\n await this.flush();\n }\n }\n\n /**\n * Gracefully shut down the tracker. Flushes remaining events and\n * clears the flush interval.\n */\n async shutdown(): Promise<void> {\n this.isShutdown = true;\n this.stopFlushInterval();\n await this.flush();\n }\n\n /**\n * Send a batch of events to the Truth API with exponential backoff retry.\n */\n private async sendBatch(batch: EventEnvelope[]): Promise<void> {\n let lastError: unknown;\n\n for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {\n try {\n const response = await fetch(`${this.apiUrl}/api/events/ingest`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": this.config.apiKey,\n },\n body: JSON.stringify({ events: batch }),\n });\n\n if (response.ok) {\n return;\n }\n\n // Don't retry 4xx client errors (except 429)\n if (\n response.status >= 400 &&\n response.status < 500 &&\n response.status !== 429\n ) {\n return;\n }\n\n lastError = new Error(\n `HTTP ${response.status}: ${response.statusText}`,\n );\n } catch (error) {\n lastError = error;\n }\n\n // Exponential backoff with jitter\n if (attempt < MAX_RETRIES) {\n const delay = BASE_RETRY_DELAY_MS * 2 ** attempt;\n const jitter = Math.random() * delay * 0.5;\n await sleep(delay + jitter);\n }\n }\n\n throw lastError;\n }\n\n private startFlushInterval(): void {\n if (this.config.flushIntervalMs > 0) {\n this.flushTimer = setInterval(() => {\n void this.flush();\n }, this.config.flushIntervalMs);\n\n // Unref the timer so it doesn't prevent Node.js from exiting\n if (typeof this.flushTimer === \"object\" && \"unref\" in this.flushTimer) {\n this.flushTimer.unref();\n }\n }\n }\n\n private stopFlushInterval(): void {\n if (this.flushTimer !== null) {\n clearInterval(this.flushTimer);\n this.flushTimer = null;\n }\n }\n\n private registerShutdownHooks(): void {\n // Only register in Node.js environments\n if (typeof globalThis.process !== \"undefined\" && globalThis.process.on) {\n const shutdownHandler = () => {\n void this.shutdown();\n };\n\n globalThis.process.on(\"beforeExit\", shutdownHandler);\n globalThis.process.on(\"SIGTERM\", shutdownHandler);\n }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Helpers\n// ---------------------------------------------------------------------------\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n}\n\nexport {\n Tracker,\n generateUuidV7,\n DEFAULT_BATCH_SIZE,\n DEFAULT_FLUSH_INTERVAL_MS,\n};\nexport type { TrackerConfig };\n","/**\n * Web Push helpers for browser environments.\n *\n * Handles service worker registration, VAPID push subscription, and\n * message forwarding from the service worker to the main thread.\n */\n\nexport interface WebPushConfig {\n vapidPublicKey: string;\n serviceWorkerPath?: string;\n}\n\nexport function isWebPushSupported(): boolean {\n return (\n typeof window !== \"undefined\" &&\n \"serviceWorker\" in navigator &&\n \"PushManager\" in window\n );\n}\n\nexport async function registerServiceWorker(\n path = \"/truth-sw.js\",\n): Promise<ServiceWorkerRegistration> {\n return navigator.serviceWorker.register(path);\n}\n\nexport async function subscribeToPush(\n registration: ServiceWorkerRegistration,\n vapidPublicKey: string,\n): Promise<PushSubscription> {\n const existing = await registration.pushManager.getSubscription();\n if (existing) {\n return existing;\n }\n\n return registration.pushManager.subscribe({\n userVisibleOnly: true,\n applicationServerKey: urlBase64ToUint8Array(\n vapidPublicKey,\n ) as unknown as ArrayBuffer,\n });\n}\n\nexport function subscriptionToJSON(sub: PushSubscription): {\n endpoint: string;\n keys: { p256dh: string; auth: string };\n} {\n const json = sub.toJSON();\n return {\n endpoint: sub.endpoint,\n keys: {\n p256dh: json.keys?.p256dh ?? \"\",\n auth: json.keys?.auth ?? \"\",\n },\n };\n}\n\nfunction urlBase64ToUint8Array(base64String: string): Uint8Array {\n const padding = \"=\".repeat((4 - (base64String.length % 4)) % 4);\n const base64 = (base64String + padding).replace(/-/g, \"+\").replace(/_/g, \"/\");\n const rawData = atob(base64);\n const outputArray = new Uint8Array(rawData.length);\n for (let i = 0; i < rawData.length; ++i) {\n outputArray[i] = rawData.charCodeAt(i);\n }\n return outputArray;\n}\n\nexport function onServiceWorkerMessage(\n type: string,\n callback: (payload: unknown) => void,\n): () => void {\n if (typeof navigator === \"undefined\" || !(\"serviceWorker\" in navigator)) {\n return () => {};\n }\n const handler = (event: MessageEvent) => {\n if (event.data?.type === type) {\n callback(event.data.payload);\n }\n };\n navigator.serviceWorker.addEventListener(\"message\", handler);\n return () => navigator.serviceWorker.removeEventListener(\"message\", handler);\n}\n","/**\n * TruthClient -- main entry point for the @hipnation-truth/sdk package.\n *\n * Provides:\n * - `.patients` Resource-based patient data access (Convex-backed)\n * - `.appointments` Resource-based appointment data access (Convex-backed)\n * - `.ehr` EHR proxy access (Elation, Hint)\n * - `.messages` Messaging proxy access (Dialpad)\n * - `.track()` Fire-and-forget event tracking (batched HTTP -> Truth API)\n * - `.identify()` Set default actor context for subsequent events\n * - `.flush()` Force flush of buffered events (for graceful shutdown)\n */\n\nimport type { ConvexHttpClient } from \"convex/browser\";\nimport { AuthAwareConvexHttpClient } from \"./auth-convex-client\";\nimport { AppointmentResource } from \"./resources/appointments\";\nimport { AttachmentsResource } from \"./resources/attachments\";\nimport { CareInboxResource } from \"./resources/care-inbox\";\nimport { ConversationsResource } from \"./resources/conversations\";\nimport { MessagesResource } from \"./resources/dialpad\";\nimport { EhrResource } from \"./resources/ehr\";\nimport { NotesResource } from \"./resources/notes\";\nimport { NotificationsResource } from \"./resources/notifications\";\nimport { PatientDetailsResource } from \"./resources/patient-details\";\nimport { PatientResource } from \"./resources/patients\";\nimport { PhysiciansResource } from \"./resources/physicians\";\nimport { RemindersResource } from \"./resources/reminders\";\nimport { ReportsResource } from \"./resources/reports\";\nimport { TasksResource } from \"./resources/tasks\";\nimport { TranslationResource } from \"./resources/translation\";\nimport { UserSettingsResource } from \"./resources/user-settings\";\nimport type {\n EventPayloadMap,\n EventType,\n TrackOptions,\n} from \"./tracking/events\";\nimport {\n DEFAULT_BATCH_SIZE,\n DEFAULT_FLUSH_INTERVAL_MS,\n Tracker,\n} from \"./tracking/tracker\";\nimport type { ActorContext, TruthClientConfig } from \"./types/config\";\nimport {\n isWebPushSupported,\n registerServiceWorker,\n subscribeToPush,\n subscriptionToJSON,\n} from \"./web-push\";\n\n// ---------------------------------------------------------------------------\n// Environment -> Convex URL mapping\n// ---------------------------------------------------------------------------\n\n// Environment → Convex deployment URL.\n//\n// Topology mirrors API_URLS in tracker.ts:\n// local / staging / stg / sandbox → sandbox Convex (courteous-duck-623)\n// uat / production → production Convex (gallant-gecko-217)\n//\n// UAT shares production resources. Staging is the isolated sandbox env.\nconst CONVEX_URLS: Record<string, string> = {\n local: \"https://courteous-duck-623.convex.cloud\",\n staging: \"https://courteous-duck-623.convex.cloud\",\n stg: \"https://courteous-duck-623.convex.cloud\",\n sandbox: \"https://courteous-duck-623.convex.cloud\",\n uat: \"https://gallant-gecko-217.convex.cloud\",\n production: \"https://gallant-gecko-217.convex.cloud\",\n};\n\n// ---------------------------------------------------------------------------\n// TruthClient\n// ---------------------------------------------------------------------------\n\nclass TruthClient {\n /** Patient data resource (Convex-backed) */\n readonly patients: PatientResource;\n\n /** Appointment data resource (Convex-backed) */\n readonly appointments: AppointmentResource;\n\n /** EHR proxy — typed access to Elation and Hint APIs through Truth */\n readonly ehr: EhrResource;\n\n /** Messaging proxy — typed access to Dialpad APIs through Truth */\n readonly messages: MessagesResource;\n\n /** Conversation reminders (Convex-backed, durable scheduler) */\n readonly reminders: RemindersResource;\n\n /** Translation (Azure Translator proxy) */\n readonly translation: TranslationResource;\n\n /** Tasks (Convex-backed) */\n readonly tasks: TasksResource;\n\n /** Patient details — merged Hint + Elation lookups via Truth API */\n readonly patientDetails: PatientDetailsResource;\n\n /** Attachments — presigned S3 upload/download + Convex metadata */\n readonly attachments: AttachmentsResource;\n\n /** Reports — member activation report (Truth API) */\n readonly reports: ReportsResource;\n\n /** Notes — push formatted notes to Elation */\n readonly notes: NotesResource;\n\n /** Physicians (Convex-backed cache from Elation) */\n readonly physicians: PhysiciansResource;\n\n /** Push / web notifications (AWS End User Messaging) */\n readonly notifications: NotificationsResource;\n\n /** Conversation-tied writes — notes, tasks, outbound messages. */\n readonly conversations: ConversationsResource;\n\n /** Care-team email inbox — link/unlink and (gated) send via oRPC. */\n readonly careInbox: CareInboxResource;\n\n /** User settings — notification preferences (Convex-backed) */\n readonly userSettings: UserSettingsResource;\n\n private readonly convex: ConvexHttpClient;\n private readonly tracker: Tracker;\n private readonly _getAuthToken?: TruthClientConfig[\"getAuthToken\"];\n private _vapidPublicKey: string | null = null;\n private _webPushReady: Promise<void> | null = null;\n private readonly _serviceWorkerPath: string;\n\n /**\n * Builds the Convex client and event tracker from `config`, then wires up\n * every resource (patients, appointments, EHR proxy, reports, etc.) so\n * each shares the same Convex connection / API base URL / auth token\n * fetcher. When running in a browser that supports web push and the\n * caller hasn't opted out, kicks off best-effort service-worker\n * registration and push subscription in the background.\n */\n constructor(config: TruthClientConfig) {\n // Resolve Convex URL\n const convexUrl =\n config.convexUrl ?? CONVEX_URLS[config.environment] ?? CONVEX_URLS.local;\n\n // Initialize Convex HTTP client for data access. When the host app\n // injects `getAuthToken`, every call carries the user's Clerk JWT\n // (refreshed per call — see AuthAwareConvexHttpClient).\n this.convex = new AuthAwareConvexHttpClient(convexUrl, config.getAuthToken);\n\n // Initialize event tracker\n this.tracker = new Tracker({\n apiKey: config.apiKey,\n environment: config.environment,\n source: config.source ?? \"unknown\",\n sourceVersion: config.sourceVersion ?? \"unknown\",\n tenantId: config.tenantId ?? \"\",\n batchSize: config.batchSize ?? DEFAULT_BATCH_SIZE,\n flushIntervalMs: config.flushIntervalMs ?? DEFAULT_FLUSH_INTERVAL_MS,\n apiBaseUrl: config.apiBaseUrl,\n });\n\n const apiUrl = this.tracker.apiUrl;\n\n // Initialize resources\n this.patients = new PatientResource(this.convex);\n this.appointments = new AppointmentResource(this.convex);\n this.ehr = new EhrResource(apiUrl, config.apiKey, config.getAuthToken);\n this.messages = new MessagesResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.reminders = new RemindersResource(this.convex);\n this.translation = new TranslationResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.tasks = new TasksResource(this.convex);\n this.patientDetails = new PatientDetailsResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.attachments = new AttachmentsResource(\n apiUrl,\n config.apiKey,\n this.convex,\n config.getAuthToken,\n );\n this.reports = new ReportsResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.notes = new NotesResource(apiUrl, config.apiKey, config.getAuthToken);\n this.physicians = new PhysiciansResource(this.convex);\n this.notifications = new NotificationsResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.conversations = new ConversationsResource(\n apiUrl,\n config.apiKey,\n this.convex,\n config.getAuthToken,\n );\n this.careInbox = new CareInboxResource(\n apiUrl,\n config.apiKey,\n config.getAuthToken,\n );\n this.userSettings = new UserSettingsResource(this.convex);\n this._getAuthToken = config.getAuthToken;\n this._serviceWorkerPath = config.serviceWorkerPath ?? \"/truth-sw.js\";\n\n if (\n typeof window !== \"undefined\" &&\n isWebPushSupported() &&\n config.autoInitServiceWorker !== false\n ) {\n this._webPushReady = this.initWebPush();\n }\n }\n\n /** The VAPID public key fetched during web-push init, or `null` until `webPushReady` resolves (or if push is unsupported/disabled). */\n get vapidPublicKey(): string | null {\n return this._vapidPublicKey;\n }\n\n /** 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). */\n get webPushReady(): Promise<void> | null {\n return this._webPushReady;\n }\n\n /**\n * When a Clerk token fetcher is configured (publishable-key clients),\n * the VAPID endpoint is auth-gated — calling it before the session has\n * hydrated 401s and strands web-push in the \"no key\" path. Wait\n * (briefly, bounded) for a token to become available first. No fetcher\n * → resolve immediately (secret-key path is unaffected).\n */\n private async waitForAuthToken(): Promise<void> {\n if (!this._getAuthToken) {\n return;\n }\n for (let attempt = 0; attempt < 20; attempt++) {\n try {\n if (await this._getAuthToken()) {\n return;\n }\n } catch {\n /* keep waiting */\n }\n await new Promise((resolve) => setTimeout(resolve, 500));\n }\n }\n\n /**\n * Best-effort web-push bootstrap: waits for auth (if configured), fetches\n * the VAPID key, registers the service worker, subscribes to push, and\n * registers the device with a placeholder `__pending__` userId (the\n * backend reconciles this once the real user is known). Any failure\n * along the way is swallowed — push notifications are opportunistic and\n * must never break client construction.\n */\n private async initWebPush(): Promise<void> {\n try {\n await this.waitForAuthToken();\n const key = await this.notifications.getVapidKey();\n if (!key) {\n return;\n }\n this._vapidPublicKey = key;\n\n const registration = await registerServiceWorker(this._serviceWorkerPath);\n await navigator.serviceWorker.ready;\n const subscription = await subscribeToPush(registration, key);\n const subJSON = subscriptionToJSON(subscription);\n\n await this.notifications.registerDevice({\n userId: \"__pending__\",\n platform: \"web\",\n webPushSubscription: subJSON,\n locale: navigator.language,\n timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,\n });\n } catch {\n // Web push init is best-effort — don't break the client.\n }\n }\n\n /**\n * The resolved Truth API base URL for this environment.\n * Use this when making HTTP calls to Truth's proxy endpoints\n * (e.g., EHR proxy, messages proxy).\n *\n * @example\n * ```ts\n * const url = `${truth.apiBaseUrl}/api/ehr/elation/patients/123`;\n * ```\n */\n get apiBaseUrl(): string {\n return this.tracker.apiUrl;\n }\n\n /**\n * Track an event. Fire-and-forget -- the event is buffered internally\n * and flushed in batches to the Truth API.\n *\n * @example\n * ```ts\n * truth.track('conversation.message_sent.v1', {\n * channel: 'sms',\n * direction: 'outbound',\n * message_chars: 140,\n * has_attachment: false,\n * provider_system: 'dialpad',\n * });\n * ```\n */\n track<T extends EventType>(\n eventType: T,\n payload: EventPayloadMap[T],\n options?: TrackOptions,\n ): void {\n this.tracker.track(eventType, payload, options);\n }\n\n /**\n * Set the default actor context for all subsequent tracked events.\n * Can be overridden per-event via TrackOptions.\n *\n * @example\n * ```ts\n * truth.identify('user_123', 'user');\n * ```\n */\n identify(actorId: string, actorType: ActorContext[\"actorType\"]): void {\n this.tracker.setActor({ actorId, actorType });\n }\n\n /**\n * Flush all buffered events immediately. Returns a Promise that resolves\n * when the flush completes. Use this for graceful shutdown.\n *\n * @example\n * ```ts\n * process.on('SIGTERM', async () => {\n * await truth.flush();\n * process.exit(0);\n * });\n * ```\n */\n async flush(): Promise<void> {\n await this.tracker.flush();\n }\n\n /**\n * Gracefully shut down the client. Flushes all pending events and\n * releases resources.\n */\n async destroy(): Promise<void> {\n await this.tracker.shutdown();\n }\n}\n\nexport { TruthClient };\n","/**\n * `createCareInboxSource` — a promise-based object with exactly the method\n * set of comhub's `CareInboxSource` (lib/email/careInboxSource.ts), so the\n * comhub adapter is a pass-through. Reads are one-shot Convex queries\n * (never persisted); link/unlink/send go through `CareInboxResource`.\n *\n * Every rejection is a `CareInboxError` (`Error & { code }` with the comhub\n * code set). `getThread` rejects `unavailable` when the feature flag is off\n * (the query returns null then). In React use `useCareInboxSource()` from\n * `@hipnation-truth/sdk/react`, which rebuilds the source when Convex auth\n * flips so comhub's query hooks refetch.\n */\n\nimport type { FunctionReference } from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\nimport {\n CareInboxError,\n type CareInboxMailboxAccess,\n type CareInboxResource,\n type CareInboxThreadDetail,\n type EmailMailboxAccessView,\n type EmailThreadBodiesView,\n type EmailThreadDetailView,\n type EmailThreadPageView,\n type LinkMessageArgs,\n type LinkResult,\n type ListThreadsArgs,\n type MarkEmailThreadReadResult,\n type MarkReadArgs,\n type MarkReadResult,\n type PatientLinkCandidate,\n type SendEmailArgs,\n type SendReplyArgs,\n type SendResult,\n type ThreadListFilter,\n type ThreadPage,\n toCareInboxError,\n toEmailThreadDetail,\n toMailboxAccess,\n toMarkReadResult,\n toThreadPage,\n type UnlinkedEmailPageView,\n type UnlinkMessageArgs,\n} from \"./care-inbox\";\n\n// ---------------------------------------------------------------------------\n// Convex function references (shared with the React hooks)\n// ---------------------------------------------------------------------------\n\nexport const careInboxRefs = {\n listThreadsForUser: makeFunctionReference<\n \"query\",\n {\n mailboxId?: string;\n filter?: ThreadListFilter;\n cursor?: string | null;\n limit?: number;\n },\n EmailThreadPageView\n >(\"careInboxQueries:listThreadsForUser\"),\n getThread: makeFunctionReference<\n \"query\",\n { threadId: string },\n EmailThreadDetailView | null\n >(\"careInboxQueries:getThread\"),\n listUnlinked: makeFunctionReference<\n \"query\",\n { mailboxId: string; cursor?: string | null; limit?: number },\n UnlinkedEmailPageView\n >(\"careInboxQueries:listUnlinked\"),\n unreadEmailCount: makeFunctionReference<\n \"query\",\n { mailboxId?: string },\n number\n >(\"careInboxQueries:unreadEmailCount\"),\n listMailboxesForUser: makeFunctionReference<\n \"query\",\n Record<string, never>,\n EmailMailboxAccessView\n >(\"careInboxQueries:listMailboxesForUser\"),\n searchPatientsForLink: makeFunctionReference<\n \"query\",\n { q: string },\n PatientLinkCandidate[]\n >(\"careInboxQueries:searchPatientsForLink\"),\n markRead: makeFunctionReference<\n \"mutation\",\n { threadId: string },\n MarkEmailThreadReadResult\n >(\"careInboxReads:markRead\"),\n openThreadBodies: makeFunctionReference<\n \"mutation\",\n { threadId: string },\n EmailThreadBodiesView\n >(\"careInboxReads:openThreadBodies\"),\n};\n\n/** Optional args, minus keys whose value is undefined (Convex rejects them). */\nexport function compactArgs<T extends Record<string, unknown>>(args: T): T {\n const out: Record<string, unknown> = {};\n for (const [k, v] of Object.entries(args)) {\n if (v !== undefined) {\n out[k] = v;\n }\n }\n return out as T;\n}\n\n// ---------------------------------------------------------------------------\n// Source\n// ---------------------------------------------------------------------------\n\n/** The Convex surface the source needs (`ConvexReactClient` satisfies it). */\nexport interface CareInboxConvexClient {\n query(\n ref: FunctionReference<\"query\">,\n args: Record<string, unknown>,\n ): Promise<unknown>;\n mutation(\n ref: FunctionReference<\"mutation\">,\n args: Record<string, unknown>,\n ): Promise<unknown>;\n}\n\nexport interface CareInboxSourceDeps {\n convex: CareInboxConvexClient;\n careInbox: Pick<\n CareInboxResource,\n \"linkMessage\" | \"unlinkMessage\" | \"replyToThread\" | \"composeEmail\"\n >;\n}\n\n/** Method set of comhub's `CareInboxSource` (minus optional `subscribe`). */\nexport interface CareInboxSdkSource {\n listThreads(args?: ListThreadsArgs): Promise<ThreadPage>;\n getUnreadCount(args?: { mailboxId?: string }): Promise<number>;\n getThread(threadId: string): Promise<CareInboxThreadDetail>;\n listMailboxesForUser(): Promise<CareInboxMailboxAccess>;\n searchPatientsForLink(query: string): Promise<PatientLinkCandidate[]>;\n linkMessage(args: LinkMessageArgs): Promise<LinkResult>;\n unlinkMessage(args: UnlinkMessageArgs): Promise<LinkResult>;\n sendReply(args: SendReplyArgs): Promise<SendResult>;\n sendEmail(args: SendEmailArgs): Promise<SendResult>;\n markRead(args: MarkReadArgs): Promise<MarkReadResult>;\n}\n\nasync function guarded<T>(run: () => Promise<T>): Promise<T> {\n try {\n return await run();\n } catch (err) {\n throw toCareInboxError(err);\n }\n}\n\nexport function createCareInboxSource({\n convex,\n careInbox,\n}: CareInboxSourceDeps): CareInboxSdkSource {\n const q = <T>(ref: FunctionReference<\"query\">, args: object) =>\n convex.query(\n ref,\n compactArgs(args as Record<string, unknown>),\n ) as Promise<T>;\n\n return {\n listThreads: (args = {}) =>\n guarded(async () =>\n toThreadPage(\n await q<EmailThreadPageView>(careInboxRefs.listThreadsForUser, {\n mailboxId: args.mailboxId,\n filter: args.filter,\n cursor: args.cursor,\n limit: args.limit,\n }),\n ),\n ),\n getUnreadCount: (args = {}) =>\n guarded(() =>\n q<number>(careInboxRefs.unreadEmailCount, {\n mailboxId: args.mailboxId,\n }),\n ),\n getThread: (threadId) =>\n guarded(async () => {\n const detail = await q<EmailThreadDetailView | null>(\n careInboxRefs.getThread,\n { threadId },\n );\n if (!detail) {\n throw new CareInboxError(\"unavailable\");\n }\n return toEmailThreadDetail(detail);\n }),\n listMailboxesForUser: () =>\n guarded(async () =>\n toMailboxAccess(\n await q<EmailMailboxAccessView>(\n careInboxRefs.listMailboxesForUser,\n {},\n ),\n ),\n ),\n searchPatientsForLink: (query) =>\n guarded(() =>\n q<PatientLinkCandidate[]>(careInboxRefs.searchPatientsForLink, {\n q: query,\n }),\n ),\n linkMessage: (args) => guarded(() => careInbox.linkMessage(args)),\n unlinkMessage: (args) => guarded(() => careInbox.unlinkMessage(args)),\n sendReply: (args) => guarded(() => careInbox.replyToThread(args)),\n sendEmail: (args) => guarded(() => careInbox.composeEmail(args)),\n markRead: ({ threadId }) =>\n guarded(async () =>\n toMarkReadResult(\n (await convex.mutation(careInboxRefs.markRead, {\n threadId,\n })) as MarkEmailThreadReadResult,\n ),\n ),\n };\n}\n","/**\n * Typed event definitions for the Truth Platform event store.\n *\n * All 26 event types from the Communication Hub -> Truth Event Store Contract.\n * Events are grouped by domain and include typed payload interfaces.\n */\n\n// ---------------------------------------------------------------------------\n// Event type constants\n// ---------------------------------------------------------------------------\n\nconst CONVERSATION_EVENTS = {\n created: \"conversation.created.v1\",\n messageSent: \"conversation.message_sent.v1\",\n messageReceived: \"conversation.message_received.v1\",\n markedRead: \"conversation.marked_read.v1\",\n attachmentUploaded: \"conversation.attachment_uploaded.v1\",\n attachmentDownloaded: \"conversation.attachment_downloaded.v1\",\n} as const;\n\nconst CALL_EVENTS = {\n initiated: \"call.initiated.v1\",\n connected: \"call.connected.v1\",\n ended: \"call.ended.v1\",\n missed: \"call.missed.v1\",\n} as const;\n\nconst TASK_EVENTS = {\n created: \"task.created.v1\",\n assigned: \"task.assigned.v1\",\n statusChanged: \"task.status_changed.v1\",\n} as const;\n\nconst REMINDER_EVENTS = {\n scheduled: \"reminder.scheduled.v1\",\n triggered: \"reminder.triggered.v1\",\n} as const;\n\nconst TRANSLATION_EVENTS = {\n requested: \"translation.requested.v1\",\n completed: \"translation.completed.v1\",\n} as const;\n\nconst NOTIFICATION_EVENTS = {\n sent: \"notification.sent.v1\",\n delivered: \"notification.delivered.v1\",\n opened: \"notification.opened.v1\",\n} as const;\n\nconst PROVIDER_EVENTS = {\n syncStarted: \"provider.sync_started.v1\",\n syncSucceeded: \"provider.sync_succeeded.v1\",\n syncFailed: \"provider.sync_failed.v1\",\n} as const;\n\nconst AUTH_EVENTS = {\n loginSucceeded: \"auth.login_succeeded.v1\",\n loginFailed: \"auth.login_failed.v1\",\n} as const;\n\nconst SECURITY_EVENTS = {\n accessDenied: \"security.access_denied.v1\",\n} as const;\n\n/**\n * All event type constants grouped by domain.\n */\nconst EVENT_TYPES = {\n conversation: CONVERSATION_EVENTS,\n call: CALL_EVENTS,\n task: TASK_EVENTS,\n reminder: REMINDER_EVENTS,\n translation: TRANSLATION_EVENTS,\n notification: NOTIFICATION_EVENTS,\n provider: PROVIDER_EVENTS,\n auth: AUTH_EVENTS,\n security: SECURITY_EVENTS,\n} as const;\n\n// ---------------------------------------------------------------------------\n// Event type union\n// ---------------------------------------------------------------------------\n\ntype ConversationEventType =\n (typeof CONVERSATION_EVENTS)[keyof typeof CONVERSATION_EVENTS];\ntype CallEventType = (typeof CALL_EVENTS)[keyof typeof CALL_EVENTS];\ntype TaskEventType = (typeof TASK_EVENTS)[keyof typeof TASK_EVENTS];\ntype ReminderEventType = (typeof REMINDER_EVENTS)[keyof typeof REMINDER_EVENTS];\ntype TranslationEventType =\n (typeof TRANSLATION_EVENTS)[keyof typeof TRANSLATION_EVENTS];\ntype NotificationEventType =\n (typeof NOTIFICATION_EVENTS)[keyof typeof NOTIFICATION_EVENTS];\ntype ProviderEventType = (typeof PROVIDER_EVENTS)[keyof typeof PROVIDER_EVENTS];\ntype AuthEventType = (typeof AUTH_EVENTS)[keyof typeof AUTH_EVENTS];\ntype SecurityEventType = (typeof SECURITY_EVENTS)[keyof typeof SECURITY_EVENTS];\n\n/**\n * Union of all 26 registered event type strings.\n */\ntype EventType =\n | ConversationEventType\n | CallEventType\n | TaskEventType\n | ReminderEventType\n | TranslationEventType\n | NotificationEventType\n | ProviderEventType\n | AuthEventType\n | SecurityEventType;\n\n// ---------------------------------------------------------------------------\n// Payload interfaces (per the contract doc)\n// ---------------------------------------------------------------------------\n\ninterface ConversationCreatedPayload {\n channel: string;\n origin_system: string;\n participant_count: number;\n}\n\ninterface ConversationMessageSentPayload {\n channel: string;\n direction: string;\n message_chars: number;\n has_attachment: boolean;\n provider_system: string;\n}\n\ninterface ConversationMessageReceivedPayload {\n channel: string;\n direction: string;\n message_chars: number;\n provider_system: string;\n}\n\ninterface ConversationMarkedReadPayload {\n read_by_actor_id: string;\n unread_count_before: number;\n unread_count_after: number;\n}\n\ninterface ConversationAttachmentUploadedPayload {\n attachment_id: string;\n mime_type: string;\n size_bytes: number;\n storage_class: string;\n}\n\ninterface ConversationAttachmentDownloadedPayload {\n attachment_id: string;\n download_actor_type: string;\n access_path: string;\n}\n\ninterface CallInitiatedPayload {\n direction: string;\n provider_system: string;\n from_number_ref: string;\n to_number_ref: string;\n}\n\ninterface CallConnectedPayload {\n provider_system: string;\n ring_duration_ms: number;\n}\n\ninterface CallEndedPayload {\n provider_system: string;\n duration_ms: number;\n end_reason: string;\n disposition: string;\n}\n\ninterface CallMissedPayload {\n provider_system: string;\n miss_reason: string;\n}\n\ninterface TaskCreatedPayload {\n task_id: string;\n created_by: string;\n assigned_to: string;\n priority: string;\n due_at: string;\n}\n\ninterface TaskAssignedPayload {\n task_id: string;\n assigned_to: string;\n assigned_by: string;\n}\n\ninterface TaskStatusChangedPayload {\n task_id: string;\n status_from: string;\n status_to: string;\n changed_by: string;\n}\n\ninterface ReminderScheduledPayload {\n reminder_id: string;\n conversation_id: string;\n scheduled_for: string;\n scheduled_by: string;\n}\n\ninterface ReminderTriggeredPayload {\n reminder_id: string;\n trigger_result: string;\n notification_attempted: boolean;\n}\n\ninterface TranslationRequestedPayload {\n target_language: string;\n source_language: string;\n char_count: number;\n mode: string;\n}\n\ninterface TranslationCompletedPayload {\n target_language: string;\n provider: string;\n latency_ms: number;\n success: boolean;\n error_code?: string;\n}\n\ninterface NotificationSentPayload {\n notification_id: string;\n channel: string;\n platform: string;\n recipient_ref: string;\n success: boolean;\n}\n\ninterface NotificationDeliveredPayload {\n notification_id: string;\n platform: string;\n delivered_at: string;\n}\n\ninterface NotificationOpenedPayload {\n notification_id: string;\n platform: string;\n opened_at: string;\n}\n\ninterface ProviderSyncStartedPayload {\n provider_system: string;\n operation: string;\n scope: string;\n batch_id: string;\n}\n\ninterface ProviderSyncSucceededPayload {\n provider_system: string;\n operation: string;\n batch_id: string;\n records_processed: number;\n duration_ms: number;\n}\n\ninterface ProviderSyncFailedPayload {\n provider_system: string;\n operation: string;\n batch_id: string;\n error_code: string;\n retryable: boolean;\n}\n\ninterface AuthLoginSucceededPayload {\n auth_provider: string;\n platform: string;\n session_ref: string;\n}\n\ninterface AuthLoginFailedPayload {\n auth_provider: string;\n platform: string;\n failure_code: string;\n}\n\ninterface SecurityAccessDeniedPayload {\n resource: string;\n policy: string;\n reason_code: string;\n actor_id: string;\n}\n\n// ---------------------------------------------------------------------------\n// Event type -> payload mapping\n// ---------------------------------------------------------------------------\n\n/**\n * Maps each event type string to its required payload interface.\n */\ninterface EventPayloadMap {\n \"conversation.created.v1\": ConversationCreatedPayload;\n \"conversation.message_sent.v1\": ConversationMessageSentPayload;\n \"conversation.message_received.v1\": ConversationMessageReceivedPayload;\n \"conversation.marked_read.v1\": ConversationMarkedReadPayload;\n \"conversation.attachment_uploaded.v1\": ConversationAttachmentUploadedPayload;\n \"conversation.attachment_downloaded.v1\": ConversationAttachmentDownloadedPayload;\n \"call.initiated.v1\": CallInitiatedPayload;\n \"call.connected.v1\": CallConnectedPayload;\n \"call.ended.v1\": CallEndedPayload;\n \"call.missed.v1\": CallMissedPayload;\n \"task.created.v1\": TaskCreatedPayload;\n \"task.assigned.v1\": TaskAssignedPayload;\n \"task.status_changed.v1\": TaskStatusChangedPayload;\n \"reminder.scheduled.v1\": ReminderScheduledPayload;\n \"reminder.triggered.v1\": ReminderTriggeredPayload;\n \"translation.requested.v1\": TranslationRequestedPayload;\n \"translation.completed.v1\": TranslationCompletedPayload;\n \"notification.sent.v1\": NotificationSentPayload;\n \"notification.delivered.v1\": NotificationDeliveredPayload;\n \"notification.opened.v1\": NotificationOpenedPayload;\n \"provider.sync_started.v1\": ProviderSyncStartedPayload;\n \"provider.sync_succeeded.v1\": ProviderSyncSucceededPayload;\n \"provider.sync_failed.v1\": ProviderSyncFailedPayload;\n \"auth.login_succeeded.v1\": AuthLoginSucceededPayload;\n \"auth.login_failed.v1\": AuthLoginFailedPayload;\n \"security.access_denied.v1\": SecurityAccessDeniedPayload;\n}\n\n// ---------------------------------------------------------------------------\n// Event envelope\n// ---------------------------------------------------------------------------\n\n/**\n * Subject references for the event. Uses tokenized references only -- no PHI.\n */\ninterface EventSubject {\n patient_ref?: string;\n conversation_id?: string;\n task_id?: string;\n call_id?: string;\n}\n\n/**\n * Actor who triggered the event.\n */\ninterface EventActor {\n actor_id: string;\n actor_type: \"user\" | \"system\" | \"webhook\";\n}\n\n/**\n * Compliance metadata for the event.\n */\ninterface EventCompliance {\n pii_level: \"none\" | \"limited\" | \"full\";\n contains_phi: boolean;\n consent_context: string;\n retention_class: string;\n}\n\n/**\n * Canonical event envelope. Every tracked event is wrapped in this structure\n * before being sent to the Truth API.\n */\ninterface EventEnvelope {\n event_id: string;\n event_type: string;\n schema_version: number;\n occurred_at: string;\n received_at: string;\n source: string;\n source_version: string;\n tenant_id: string;\n actor?: EventActor;\n subject?: EventSubject;\n compliance?: EventCompliance;\n payload: Record<string, unknown>;\n}\n\n// ---------------------------------------------------------------------------\n// Track options (per-call overrides)\n// ---------------------------------------------------------------------------\n\n/**\n * Optional overrides when calling truth.track().\n */\ninterface TrackOptions {\n /** Override the default actor for this event */\n actor?: EventActor;\n\n /** Subject references for this event */\n subject?: EventSubject;\n\n /** Compliance metadata for this event */\n compliance?: EventCompliance;\n\n /** Override the default tenant ID for this event */\n tenantId?: string;\n\n /** Override the occurred_at timestamp (ISO 8601) */\n occurredAt?: string;\n}\n\nexport {\n EVENT_TYPES,\n CONVERSATION_EVENTS,\n CALL_EVENTS,\n TASK_EVENTS,\n REMINDER_EVENTS,\n TRANSLATION_EVENTS,\n NOTIFICATION_EVENTS,\n PROVIDER_EVENTS,\n AUTH_EVENTS,\n SECURITY_EVENTS,\n};\n\nexport type {\n EventType,\n ConversationEventType,\n CallEventType,\n TaskEventType,\n ReminderEventType,\n TranslationEventType,\n NotificationEventType,\n ProviderEventType,\n AuthEventType,\n SecurityEventType,\n EventPayloadMap,\n EventEnvelope,\n EventActor,\n EventSubject,\n EventCompliance,\n TrackOptions,\n ConversationCreatedPayload,\n ConversationMessageSentPayload,\n ConversationMessageReceivedPayload,\n ConversationMarkedReadPayload,\n ConversationAttachmentUploadedPayload,\n ConversationAttachmentDownloadedPayload,\n CallInitiatedPayload,\n CallConnectedPayload,\n CallEndedPayload,\n CallMissedPayload,\n TaskCreatedPayload,\n TaskAssignedPayload,\n TaskStatusChangedPayload,\n ReminderScheduledPayload,\n ReminderTriggeredPayload,\n TranslationRequestedPayload,\n TranslationCompletedPayload,\n NotificationSentPayload,\n NotificationDeliveredPayload,\n NotificationOpenedPayload,\n ProviderSyncStartedPayload,\n ProviderSyncSucceededPayload,\n ProviderSyncFailedPayload,\n AuthLoginSucceededPayload,\n AuthLoginFailedPayload,\n SecurityAccessDeniedPayload,\n};\n","/**\n * Configuration interfaces for the Truth SDK.\n */\n\n/**\n * Environment options for the Truth platform.\n */\nconst ENVIRONMENTS = {\n local: \"local\",\n staging: \"staging\",\n stg: \"stg\",\n sandbox: \"sandbox\",\n uat: \"uat\",\n production: \"production\",\n} as const;\n\ntype Environment = (typeof ENVIRONMENTS)[keyof typeof ENVIRONMENTS];\n\n/**\n * Fetches a user-identity JWT for Convex calls. Return the token from\n * your identity provider's Clerk JWT template named \"convex\"\n * (e.g. `getToken({ template: \"convex\" })` from `@clerk/expo`), or\n * `null` when no user is signed in.\n *\n * Convex invokes this with `{ forceRefreshToken: true }` when the cached\n * token has expired — forward it to your provider (e.g. Clerk's\n * `getToken({ template: \"convex\", skipCache: opts?.forceRefreshToken })`)\n * so the refresh returns a fresh token rather than a stale cached one.\n */\ntype AuthTokenFetcher = (opts?: {\n forceRefreshToken?: boolean;\n}) => Promise<string | null | undefined>;\n\n/**\n * Configuration for initializing a TruthClient.\n */\ninterface TruthClientConfig {\n /** API key for authenticating with the Truth platform (e.g. \"hn_live_...\") */\n apiKey: string;\n\n /**\n * Per-call Clerk JWT fetcher for Convex data access. When provided,\n * every Convex query/mutation/action carries the caller's identity;\n * Convex deployments with `CLERK_AUTH_REQUIRED` enabled reject calls\n * without it. Omit for service contexts that don't act as a user.\n */\n getAuthToken?: AuthTokenFetcher;\n\n /** Target environment */\n environment: Environment;\n\n /** Override the default Convex URL for data access */\n convexUrl?: string;\n\n /** Event source identifier (e.g. \"communication-hub.backend\") */\n source?: string;\n\n /** Git SHA or version string for event source versioning */\n sourceVersion?: string;\n\n /** Default tenant (organization) ID for events */\n tenantId?: string;\n\n /** Number of events to buffer before flushing (default: 25) */\n batchSize?: number;\n\n /** Interval in milliseconds between automatic flushes (default: 5000) */\n flushIntervalMs?: number;\n\n /** Base URL for the Truth API (overrides environment-based default) */\n apiBaseUrl?: string;\n\n /**\n * Auto-register the service worker and subscribe to web push on init.\n * Only applies in browser environments with Push API support.\n * Default: true.\n */\n autoInitServiceWorker?: boolean;\n\n /** Path to the service worker file. Default: \"/truth-sw.js\" */\n serviceWorkerPath?: string;\n}\n\n/**\n * Actor context attached to tracked events.\n */\ninterface ActorContext {\n actorId: string;\n actorType: \"user\" | \"system\" | \"webhook\";\n}\n\n/**\n * Paginated result wrapper for list operations.\n */\ninterface PaginatedResult<T> {\n data: T[];\n cursor: string | null;\n hasMore: boolean;\n}\n\nexport { ENVIRONMENTS };\nexport type {\n AuthTokenFetcher,\n Environment,\n TruthClientConfig,\n ActorContext,\n PaginatedResult,\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,SAAS,wBAAkD;AASpD,IAAM,4BAAN,MAAM,mCAAkC,iBAAiB;AAAA,EAG9D,YAAY,SAAiB,cAAiC;AAC5D,UAAM,OAAO;AACb,SAAK,eAAe;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOc,WAA0B;AAAA;AACtC,UAAI,CAAC,KAAK,cAAc;AACtB;AAAA,MACF;AACA,UAAI;AACF,cAAM,QAAQ,MAAM,KAAK,aAAa;AACtC,YAAI,OAAO;AACT,eAAK,QAAQ,KAAK;AAAA,QACpB,OAAO;AACL,eAAK,UAAU;AA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