@hipnation-truth/sdk 0.4.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.d.mts CHANGED
@@ -118,6 +118,109 @@ declare function usePatientMedical(elationId: number | undefined, options?: UseP
118
118
  allergies: unknown[] | undefined;
119
119
  appointments: unknown[] | undefined;
120
120
  };
121
+ interface UsePatientBasicOptions {
122
+ /** Truth API base URL used for the background refresh. */
123
+ apiBaseUrl?: string;
124
+ /** API key for the refresh call. */
125
+ apiKey?: string;
126
+ /** Suppress the background refresh. */
127
+ skipRefresh?: boolean;
128
+ }
129
+ interface UsePatientBasicResult {
130
+ /**
131
+ * Raw Elation patient payload (matches the shape Elation's
132
+ * `/patients/{id}` returns — `first_name`, `last_name`, `phones`, etc).
133
+ * Returns `undefined` while the cache miss is loading, `null` if the
134
+ * patient isn't in Convex yet (first-open-after-backfill).
135
+ */
136
+ elationPatient: Record<string, unknown> | null | undefined;
137
+ /**
138
+ * Raw Hint patient payload (matches the shape Hint's
139
+ * `/provider/patients/{id}` returns — `memberships`, `account`,
140
+ * `phones`, etc).
141
+ */
142
+ hintPatient: Record<string, unknown> | null | undefined;
143
+ /**
144
+ * The full Convex row for Elation (includes `elationId`, `lastSyncedAt`,
145
+ * `photoS3Key`, `preferredPharmacyNcpdpId`, etc). Use this when you
146
+ * need the structured/typed fields rather than the raw Elation payload.
147
+ */
148
+ elationRow: Record<string, unknown> | null | undefined;
149
+ /**
150
+ * The full Convex row for Hint. Similar relationship to `hintPatient`.
151
+ */
152
+ hintRow: Record<string, unknown> | null | undefined;
153
+ /** True while either cache miss is still pending. */
154
+ loading: boolean;
155
+ }
156
+ /**
157
+ * Composite hook returning a patient's basic details — Hint demographics
158
+ * + memberships + account, Elation demographics + clinical metadata —
159
+ * from the Convex cache.
160
+ *
161
+ * On mount (and when inputs change) fires a background refresh against
162
+ * `/api/patients/basic/refresh` so stale rows get pulled fresh without
163
+ * blocking render. Returns cached data immediately; Convex subscription
164
+ * updates the UI when refresh completes.
165
+ */
166
+ declare function usePatientBasic(input: {
167
+ hintId?: string;
168
+ elationId?: number;
169
+ }, options?: UsePatientBasicOptions): UsePatientBasicResult;
170
+ /**
171
+ * Read a shared pharmacy row by NCPDP id. Backs the pharmacy card in
172
+ * the patient panel (from Elation's preferred_pharmacy reference).
173
+ */
174
+ declare function usePharmacyByNcpdpId(ncpdpId: string | undefined): any;
175
+ interface UsePatientPhotoOptions {
176
+ apiBaseUrl?: string;
177
+ apiKey?: string;
178
+ skipRefresh?: boolean;
179
+ }
180
+ /**
181
+ * Subscribe to a patient's profile photo (s3Key + metadata). The
182
+ * consumer constructs a download URL via the Truth attachments resource
183
+ * (signed S3 URL). Fires a background refresh to pull the latest photo
184
+ * binary from Elation + upload to S3.
185
+ */
186
+ declare function usePatientPhoto(elationId: number | undefined, options?: UsePatientPhotoOptions): any;
187
+ interface ConversationMessage {
188
+ kind: "call" | "sms";
189
+ id: string;
190
+ providerId: string;
191
+ state: string | null;
192
+ direction: string | null;
193
+ fromNumber: string | null;
194
+ toNumber: string | null;
195
+ voicemailLink: string | null;
196
+ duration: number | null;
197
+ text: string | null;
198
+ mms: boolean;
199
+ mmsUrl: string | null;
200
+ messageStatus: string | null;
201
+ occurredAt: string;
202
+ conversationId: string | null;
203
+ patientId: string | null;
204
+ }
205
+ interface UseConversationMessagesOptions {
206
+ /** Max items to return (default 200). */
207
+ limit?: number;
208
+ }
209
+ /**
210
+ * Subscribe to a conversation's calls + SMS merged chronologically.
211
+ * Pass the patient phone + the provider phone — Truth computes a
212
+ * normalized pair key server-side so formatting differences don't
213
+ * matter.
214
+ *
215
+ * Returns `undefined` while loading, then `ConversationMessage[]`
216
+ * sorted newest-first. Updates live as new webhook events land in
217
+ * Convex via the kinesis consumer.
218
+ */
219
+ declare function useConversationMessages(input: {
220
+ phoneA?: string;
221
+ phoneB?: string;
222
+ conversationId?: string;
223
+ }, options?: UseConversationMessagesOptions): ConversationMessage[] | undefined;
121
224
 
122
225
  interface TruthProviderProps {
123
226
  /** Truth environment — determines which Convex deployment to connect to */
@@ -549,4 +652,4 @@ interface PatientListOptions {
549
652
  cursor?: string;
550
653
  }
551
654
 
552
- export { type Appointment, type AppointmentListOptions, type EventPayloadMap, type EventType, type Patient, type PatientListOptions, type Physician, type TrackOptions, TruthProvider, type TruthProviderProps, type TruthTrackingContextValue, TruthTrackingProvider, type TruthTrackingProviderProps, type UseAppointmentListOptions, type UsePatientListOptions, type UsePatientMedicalOptions, useAppointment, useAppointmentByElationId, useAppointments, usePatient, usePatientByElationId, usePatientByHintId, usePatientMedical, usePatients, usePhysicianByElationId, usePhysiciansByElationIds, useTruth };
655
+ export { type Appointment, type AppointmentListOptions, type ConversationMessage, type EventPayloadMap, type EventType, type Patient, type PatientListOptions, type Physician, type TrackOptions, TruthProvider, type TruthProviderProps, type TruthTrackingContextValue, TruthTrackingProvider, type TruthTrackingProviderProps, type UseAppointmentListOptions, type UseConversationMessagesOptions, type UsePatientBasicOptions, type UsePatientBasicResult, type UsePatientListOptions, type UsePatientMedicalOptions, type UsePatientPhotoOptions, useAppointment, useAppointmentByElationId, useAppointments, useConversationMessages, usePatient, usePatientBasic, usePatientByElationId, usePatientByHintId, usePatientMedical, usePatientPhoto, usePatients, usePharmacyByNcpdpId, usePhysicianByElationId, usePhysiciansByElationIds, useTruth };
package/dist/react.d.ts CHANGED
@@ -118,6 +118,109 @@ declare function usePatientMedical(elationId: number | undefined, options?: UseP
118
118
  allergies: unknown[] | undefined;
119
119
  appointments: unknown[] | undefined;
120
120
  };
121
+ interface UsePatientBasicOptions {
122
+ /** Truth API base URL used for the background refresh. */
123
+ apiBaseUrl?: string;
124
+ /** API key for the refresh call. */
125
+ apiKey?: string;
126
+ /** Suppress the background refresh. */
127
+ skipRefresh?: boolean;
128
+ }
129
+ interface UsePatientBasicResult {
130
+ /**
131
+ * Raw Elation patient payload (matches the shape Elation's
132
+ * `/patients/{id}` returns — `first_name`, `last_name`, `phones`, etc).
133
+ * Returns `undefined` while the cache miss is loading, `null` if the
134
+ * patient isn't in Convex yet (first-open-after-backfill).
135
+ */
136
+ elationPatient: Record<string, unknown> | null | undefined;
137
+ /**
138
+ * Raw Hint patient payload (matches the shape Hint's
139
+ * `/provider/patients/{id}` returns — `memberships`, `account`,
140
+ * `phones`, etc).
141
+ */
142
+ hintPatient: Record<string, unknown> | null | undefined;
143
+ /**
144
+ * The full Convex row for Elation (includes `elationId`, `lastSyncedAt`,
145
+ * `photoS3Key`, `preferredPharmacyNcpdpId`, etc). Use this when you
146
+ * need the structured/typed fields rather than the raw Elation payload.
147
+ */
148
+ elationRow: Record<string, unknown> | null | undefined;
149
+ /**
150
+ * The full Convex row for Hint. Similar relationship to `hintPatient`.
151
+ */
152
+ hintRow: Record<string, unknown> | null | undefined;
153
+ /** True while either cache miss is still pending. */
154
+ loading: boolean;
155
+ }
156
+ /**
157
+ * Composite hook returning a patient's basic details — Hint demographics
158
+ * + memberships + account, Elation demographics + clinical metadata —
159
+ * from the Convex cache.
160
+ *
161
+ * On mount (and when inputs change) fires a background refresh against
162
+ * `/api/patients/basic/refresh` so stale rows get pulled fresh without
163
+ * blocking render. Returns cached data immediately; Convex subscription
164
+ * updates the UI when refresh completes.
165
+ */
166
+ declare function usePatientBasic(input: {
167
+ hintId?: string;
168
+ elationId?: number;
169
+ }, options?: UsePatientBasicOptions): UsePatientBasicResult;
170
+ /**
171
+ * Read a shared pharmacy row by NCPDP id. Backs the pharmacy card in
172
+ * the patient panel (from Elation's preferred_pharmacy reference).
173
+ */
174
+ declare function usePharmacyByNcpdpId(ncpdpId: string | undefined): any;
175
+ interface UsePatientPhotoOptions {
176
+ apiBaseUrl?: string;
177
+ apiKey?: string;
178
+ skipRefresh?: boolean;
179
+ }
180
+ /**
181
+ * Subscribe to a patient's profile photo (s3Key + metadata). The
182
+ * consumer constructs a download URL via the Truth attachments resource
183
+ * (signed S3 URL). Fires a background refresh to pull the latest photo
184
+ * binary from Elation + upload to S3.
185
+ */
186
+ declare function usePatientPhoto(elationId: number | undefined, options?: UsePatientPhotoOptions): any;
187
+ interface ConversationMessage {
188
+ kind: "call" | "sms";
189
+ id: string;
190
+ providerId: string;
191
+ state: string | null;
192
+ direction: string | null;
193
+ fromNumber: string | null;
194
+ toNumber: string | null;
195
+ voicemailLink: string | null;
196
+ duration: number | null;
197
+ text: string | null;
198
+ mms: boolean;
199
+ mmsUrl: string | null;
200
+ messageStatus: string | null;
201
+ occurredAt: string;
202
+ conversationId: string | null;
203
+ patientId: string | null;
204
+ }
205
+ interface UseConversationMessagesOptions {
206
+ /** Max items to return (default 200). */
207
+ limit?: number;
208
+ }
209
+ /**
210
+ * Subscribe to a conversation's calls + SMS merged chronologically.
211
+ * Pass the patient phone + the provider phone — Truth computes a
212
+ * normalized pair key server-side so formatting differences don't
213
+ * matter.
214
+ *
215
+ * Returns `undefined` while loading, then `ConversationMessage[]`
216
+ * sorted newest-first. Updates live as new webhook events land in
217
+ * Convex via the kinesis consumer.
218
+ */
219
+ declare function useConversationMessages(input: {
220
+ phoneA?: string;
221
+ phoneB?: string;
222
+ conversationId?: string;
223
+ }, options?: UseConversationMessagesOptions): ConversationMessage[] | undefined;
121
224
 
122
225
  interface TruthProviderProps {
123
226
  /** Truth environment — determines which Convex deployment to connect to */
@@ -549,4 +652,4 @@ interface PatientListOptions {
549
652
  cursor?: string;
550
653
  }
551
654
 
552
- export { type Appointment, type AppointmentListOptions, type EventPayloadMap, type EventType, type Patient, type PatientListOptions, type Physician, type TrackOptions, TruthProvider, type TruthProviderProps, type TruthTrackingContextValue, TruthTrackingProvider, type TruthTrackingProviderProps, type UseAppointmentListOptions, type UsePatientListOptions, type UsePatientMedicalOptions, useAppointment, useAppointmentByElationId, useAppointments, usePatient, usePatientByElationId, usePatientByHintId, usePatientMedical, usePatients, usePhysicianByElationId, usePhysiciansByElationIds, useTruth };
655
+ export { type Appointment, type AppointmentListOptions, type ConversationMessage, type EventPayloadMap, type EventType, type Patient, type PatientListOptions, type Physician, type TrackOptions, TruthProvider, type TruthProviderProps, type TruthTrackingContextValue, TruthTrackingProvider, type TruthTrackingProviderProps, type UseAppointmentListOptions, type UseConversationMessagesOptions, type UsePatientBasicOptions, type UsePatientBasicResult, type UsePatientListOptions, type UsePatientMedicalOptions, type UsePatientPhotoOptions, useAppointment, useAppointmentByElationId, useAppointments, useConversationMessages, usePatient, usePatientBasic, usePatientByElationId, usePatientByHintId, usePatientMedical, usePatientPhoto, usePatients, usePharmacyByNcpdpId, usePhysicianByElationId, usePhysiciansByElationIds, useTruth };
package/dist/react.js CHANGED
@@ -47,11 +47,15 @@ __export(react_exports, {
47
47
  useAppointment: () => useAppointment,
48
48
  useAppointmentByElationId: () => useAppointmentByElationId,
49
49
  useAppointments: () => useAppointments,
50
+ useConversationMessages: () => useConversationMessages,
50
51
  usePatient: () => usePatient,
52
+ usePatientBasic: () => usePatientBasic,
51
53
  usePatientByElationId: () => usePatientByElationId,
52
54
  usePatientByHintId: () => usePatientByHintId,
53
55
  usePatientMedical: () => usePatientMedical,
56
+ usePatientPhoto: () => usePatientPhoto,
54
57
  usePatients: () => usePatients,
58
+ usePharmacyByNcpdpId: () => usePharmacyByNcpdpId,
55
59
  usePhysicianByElationId: () => usePhysicianByElationId,
56
60
  usePhysiciansByElationIds: () => usePhysiciansByElationIds,
57
61
  useTruth: () => useTruth
@@ -158,6 +162,110 @@ function usePatientMedical(elationId, options) {
158
162
  }, [elationId, options == null ? void 0 : options.apiBaseUrl, options == null ? void 0 : options.apiKey, options == null ? void 0 : options.skipRefresh]);
159
163
  return { medications, problems, allergies, appointments };
160
164
  }
165
+ var elationPatientByIdRef = (0, import_server.makeFunctionReference)("elationPatients:getByElationId");
166
+ var hintPatientByIdRef = (0, import_server.makeFunctionReference)("hintPatients:getByHintId");
167
+ var pharmacyByNcpdpRef = (0, import_server.makeFunctionReference)("elationPharmacies:getByNcpdpId");
168
+ var patientPhotoByIdRef = (0, import_server.makeFunctionReference)("elationPatientPhotos:getByElationPatientId");
169
+ function usePatientBasic(input, options) {
170
+ var _a, _b;
171
+ const elationRow = (0, import_react.useQuery)(
172
+ elationPatientByIdRef,
173
+ input.elationId !== void 0 ? { elationId: input.elationId } : "skip"
174
+ );
175
+ const hintRow = (0, import_react.useQuery)(
176
+ hintPatientByIdRef,
177
+ input.hintId !== void 0 ? { hintId: input.hintId } : "skip"
178
+ );
179
+ (0, import_react2.useEffect)(() => {
180
+ if (options == null ? void 0 : options.skipRefresh) return;
181
+ if (!input.hintId && input.elationId === void 0) return;
182
+ const apiBaseUrl = options == null ? void 0 : options.apiBaseUrl;
183
+ const apiKey = options == null ? void 0 : options.apiKey;
184
+ if (!apiBaseUrl || !apiKey) return;
185
+ const controller = new AbortController();
186
+ void fetch(`${apiBaseUrl}/api/patients/basic/refresh`, {
187
+ method: "POST",
188
+ headers: {
189
+ "Content-Type": "application/json",
190
+ "X-API-Key": apiKey
191
+ },
192
+ body: JSON.stringify({
193
+ hintId: input.hintId,
194
+ elationId: input.elationId
195
+ }),
196
+ signal: controller.signal
197
+ }).catch(() => {
198
+ });
199
+ return () => controller.abort();
200
+ }, [
201
+ input.hintId,
202
+ input.elationId,
203
+ options == null ? void 0 : options.apiBaseUrl,
204
+ options == null ? void 0 : options.apiKey,
205
+ options == null ? void 0 : options.skipRefresh
206
+ ]);
207
+ const elationPatient = elationRow === void 0 ? void 0 : elationRow === null ? null : (_a = elationRow.raw) != null ? _a : null;
208
+ const hintPatient = hintRow === void 0 ? void 0 : hintRow === null ? null : (_b = hintRow.raw) != null ? _b : null;
209
+ const elationLoading = input.elationId !== void 0 && elationRow === void 0;
210
+ const hintLoading = input.hintId !== void 0 && hintRow === void 0;
211
+ return {
212
+ elationPatient,
213
+ hintPatient,
214
+ elationRow,
215
+ hintRow,
216
+ loading: elationLoading || hintLoading
217
+ };
218
+ }
219
+ function usePharmacyByNcpdpId(ncpdpId) {
220
+ return (0, import_react.useQuery)(
221
+ pharmacyByNcpdpRef,
222
+ ncpdpId ? { ncpdpId } : "skip"
223
+ );
224
+ }
225
+ function usePatientPhoto(elationId, options) {
226
+ const photo = (0, import_react.useQuery)(
227
+ patientPhotoByIdRef,
228
+ elationId !== void 0 ? { elationPatientId: elationId } : "skip"
229
+ );
230
+ (0, import_react2.useEffect)(() => {
231
+ if (options == null ? void 0 : options.skipRefresh) return;
232
+ if (elationId === void 0) return;
233
+ const apiBaseUrl = options == null ? void 0 : options.apiBaseUrl;
234
+ const apiKey = options == null ? void 0 : options.apiKey;
235
+ if (!apiBaseUrl || !apiKey) return;
236
+ const controller = new AbortController();
237
+ void fetch(`${apiBaseUrl}/api/patients/photo/refresh`, {
238
+ method: "POST",
239
+ headers: {
240
+ "Content-Type": "application/json",
241
+ "X-API-Key": apiKey
242
+ },
243
+ body: JSON.stringify({ elationId }),
244
+ signal: controller.signal
245
+ }).catch(() => {
246
+ });
247
+ return () => controller.abort();
248
+ }, [elationId, options == null ? void 0 : options.apiBaseUrl, options == null ? void 0 : options.apiKey, options == null ? void 0 : options.skipRefresh]);
249
+ return photo;
250
+ }
251
+ var messagesByPhonesRef = (0, import_server.makeFunctionReference)("conversationMessages:getByPhones");
252
+ var messagesByConversationIdRef = (0, import_server.makeFunctionReference)("conversationMessages:getByConversationId");
253
+ function useConversationMessages(input, options) {
254
+ const hasPair = !!input.phoneA && !!input.phoneB;
255
+ const byPair = (0, import_react.useQuery)(
256
+ messagesByPhonesRef,
257
+ hasPair ? {
258
+ phoneA: input.phoneA,
259
+ phoneB: input.phoneB,
260
+ limit: options == null ? void 0 : options.limit
261
+ } : "skip"
262
+ );
263
+ const byConvo = (0, import_react.useQuery)(
264
+ messagesByConversationIdRef,
265
+ !hasPair && input.conversationId ? { conversationId: input.conversationId, limit: options == null ? void 0 : options.limit } : "skip"
266
+ );
267
+ return hasPair ? byPair : byConvo;
268
+ }
161
269
 
162
270
  // src/react/provider.ts
163
271
  var import_react3 = require("convex/react");
@@ -423,11 +531,15 @@ function useTruth() {
423
531
  useAppointment,
424
532
  useAppointmentByElationId,
425
533
  useAppointments,
534
+ useConversationMessages,
426
535
  usePatient,
536
+ usePatientBasic,
427
537
  usePatientByElationId,
428
538
  usePatientByHintId,
429
539
  usePatientMedical,
540
+ usePatientPhoto,
430
541
  usePatients,
542
+ usePharmacyByNcpdpId,
431
543
  usePhysicianByElationId,
432
544
  usePhysiciansByElationIds,
433
545
  useTruth
package/dist/react.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/react.ts","../src/react/hooks.ts","../src/react/provider.ts","../src/react/tracking.ts","../src/tracking/tracker.ts"],"sourcesContent":["/**\n * @hipnation-truth/sdk/react\n *\n * React hooks and provider for Truth SDK — real-time Convex-backed data.\n *\n * @example\n * ```tsx\n * import { TruthProvider, usePatients, useAppointments } from '@hipnation-truth/sdk/react';\n *\n * function App() {\n * return (\n * <TruthProvider environment=\"sandbox\">\n * <PatientList />\n * </TruthProvider>\n * );\n * }\n *\n * function PatientList() {\n * const patients = usePatients({ limit: 20 });\n * if (!patients) return <div>Loading...</div>;\n * return patients.map(p => <div key={p._id}>{p.firstName}</div>);\n * }\n * ```\n */\n\n// Re-export types consumers commonly need\nexport type {\n Physician,\n UseAppointmentListOptions,\n UsePatientListOptions,\n UsePatientMedicalOptions,\n} from \"./react/hooks\";\n// Patient / Appointment / Physician / Medical hooks\nexport {\n useAppointment,\n useAppointmentByElationId,\n useAppointments,\n usePatient,\n usePatientByElationId,\n usePatientByHintId,\n usePatientMedical,\n usePatients,\n usePhysicianByElationId,\n usePhysiciansByElationIds,\n} from \"./react/hooks\";\nexport type { TruthProviderProps } from \"./react/provider\";\n// Provider\nexport { TruthProvider } from \"./react/provider\";\nexport type {\n TruthTrackingContextValue,\n TruthTrackingProviderProps,\n} from \"./react/tracking\";\n// Tracking\nexport { TruthTrackingProvider, useTruth } from \"./react/tracking\";\n// Re-export event types for track() calls\nexport type {\n EventPayloadMap,\n EventType,\n TrackOptions,\n} from \"./tracking/events\";\nexport type { Appointment, AppointmentListOptions } from \"./types/appointment\";\nexport type { Patient, PatientListOptions } from \"./types/patient\";\n","/**\n * React hooks for Truth SDK — real-time Convex-backed data access.\n *\n * These hooks use Convex React subscriptions for live-updating data.\n * Must be used within a ConvexProvider (see TruthProvider).\n *\n * @example\n * ```tsx\n * import { usePatients, useAppointments } from '@hipnation-truth/sdk/react';\n *\n * function PatientList() {\n * const patients = usePatients({ limit: 20 });\n * return patients?.map(p => <div key={p._id}>{p.firstName} {p.lastName}</div>);\n * }\n * ```\n */\n\n\"use client\";\n\nimport { useQuery } from \"convex/react\";\nimport { useEffect } from \"react\";\n\n// ---------------------------------------------------------------------------\n// Convex function references\n// ---------------------------------------------------------------------------\n// We use string-based references to avoid importing the generated API\n// (which lives in the consuming app, not the SDK). Convex supports this\n// via the `api` module pattern, but for a published SDK we use\n// makeFunctionReference to stay decoupled from the app's codegen.\n\nimport type { FunctionReference } from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\n\n// Patient query references\nconst patientsListRef = makeFunctionReference<\n \"query\",\n {\n search?: string;\n lastName?: string;\n cursor?: string;\n limit?: number;\n },\n unknown[]\n>(\"patients:list\");\n\nconst patientsGetRef = makeFunctionReference<\n \"query\",\n { id: string },\n unknown | null\n>(\"patients:get\");\n\nconst patientsByElationIdRef = makeFunctionReference<\n \"query\",\n { elationId: string },\n unknown | null\n>(\"patients:getByElationId\");\n\nconst patientsByHintIdRef = makeFunctionReference<\n \"query\",\n { hintId: string },\n unknown | null\n>(\"patients:getByHintId\");\n\n// Appointment query references\nconst appointmentsListRef = makeFunctionReference<\n \"query\",\n {\n patientId?: string;\n status?: string;\n startDate?: string;\n endDate?: string;\n limit?: number;\n },\n unknown[]\n>(\"appointments:list\");\n\nconst appointmentsGetRef = makeFunctionReference<\n \"query\",\n { id: string },\n unknown | null\n>(\"appointments:get\");\n\nconst appointmentsByElationIdRef = makeFunctionReference<\n \"query\",\n { elationId: string },\n unknown | null\n>(\"appointments:getByElationId\");\n\n// ---------------------------------------------------------------------------\n// Patient hooks\n// ---------------------------------------------------------------------------\n\ninterface UsePatientListOptions {\n search?: string;\n lastName?: string;\n limit?: number;\n}\n\n/**\n * Subscribe to a list of patients with optional search and filtering.\n * Returns undefined while loading, then an array of patients.\n */\nfunction usePatients(options?: UsePatientListOptions) {\n return useQuery(patientsListRef as FunctionReference<\"query\">, options ?? {});\n}\n\n/**\n * Subscribe to a single patient by Convex document ID.\n */\nfunction usePatient(id: string) {\n return useQuery(patientsGetRef as FunctionReference<\"query\">, { id });\n}\n\n/**\n * Subscribe to a patient by their Elation ID.\n */\nfunction usePatientByElationId(elationId: string) {\n return useQuery(patientsByElationIdRef as FunctionReference<\"query\">, {\n elationId,\n });\n}\n\n/**\n * Subscribe to a patient by their Hint ID.\n */\nfunction usePatientByHintId(hintId: string) {\n return useQuery(patientsByHintIdRef as FunctionReference<\"query\">, {\n hintId,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Appointment hooks\n// ---------------------------------------------------------------------------\n\ninterface UseAppointmentListOptions {\n patientId?: string;\n status?: string;\n startDate?: string;\n endDate?: string;\n limit?: number;\n}\n\n/**\n * Subscribe to a list of appointments with optional filtering.\n */\nfunction useAppointments(options?: UseAppointmentListOptions) {\n return useQuery(\n appointmentsListRef as FunctionReference<\"query\">,\n options ?? {},\n );\n}\n\n/**\n * Subscribe to a single appointment by Convex document ID.\n */\nfunction useAppointment(id: string) {\n return useQuery(appointmentsGetRef as FunctionReference<\"query\">, { id });\n}\n\n/**\n * Subscribe to an appointment by its Elation ID.\n */\nfunction useAppointmentByElationId(elationId: string) {\n return useQuery(appointmentsByElationIdRef as FunctionReference<\"query\">, {\n elationId,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Physician hooks\n// ---------------------------------------------------------------------------\n\ninterface 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\nconst physiciansGetByElationIdsRef = makeFunctionReference<\n \"query\",\n { ids: number[] },\n Physician[]\n>(\"physicians:getByElationIds\");\n\nconst physiciansGetByElationIdRef = makeFunctionReference<\n \"query\",\n { id: number },\n Physician | null\n>(\"physicians:getByElationId\");\n\n/**\n * Resolve a batch of physicians by their Elation IDs. Returns an array\n * of physicians that exist in Convex; missing ids are silently dropped.\n *\n * Use this to resolve medication `prescribing_physician` / appointment\n * physician ids to display names, avoiding the per-physician HTTP\n * round-trip through Truth's Elation proxy.\n *\n * Pass `undefined` (or an empty array) to skip the query — the hook\n * returns `undefined` until you pass a populated list.\n */\nfunction usePhysiciansByElationIds(ids: number[] | undefined) {\n return useQuery(\n physiciansGetByElationIdsRef as FunctionReference<\"query\">,\n ids && ids.length > 0 ? { ids } : \"skip\",\n );\n}\n\n/**\n * Subscribe to a single physician by their Elation ID.\n */\nfunction usePhysicianByElationId(id: number | undefined) {\n return useQuery(\n physiciansGetByElationIdRef as FunctionReference<\"query\">,\n id !== undefined ? { id } : \"skip\",\n );\n}\n\n// ---------------------------------------------------------------------------\n// Patient medical hooks (medications, problems, allergies, appointments)\n// ---------------------------------------------------------------------------\n\nconst medicationsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getMedicationsByElationPatient\");\n\nconst problemsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getProblemsByElationPatient\");\n\nconst allergiesByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getAllergiesByElationPatient\");\n\nconst appointmentsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getAppointmentsByElationPatient\");\n\ninterface UsePatientMedicalOptions {\n /**\n * Base URL of the Truth API. Required to trigger the background refresh\n * (e.g. `https://app.truth.communication-hub.com`). If omitted, the hook\n * only reads from Convex and does not refresh.\n */\n apiBaseUrl?: string;\n /** API key used for the refresh call. */\n apiKey?: string;\n /**\n * If true, suppress the background refresh. Useful when you know the\n * data was just refreshed by another component on the page.\n */\n skipRefresh?: boolean;\n}\n\n/**\n * Composite hook that returns a patient's medical records — medications,\n * problems, allergies, appointments — from the Convex cache.\n *\n * On mount (and when `elationId` changes) fires a background refresh\n * against Truth's `/api/patients/medical/refresh` endpoint so stale data\n * is pulled in without blocking render. Returns cached data immediately;\n * Convex subscription updates the UI when refresh completes.\n */\nfunction usePatientMedical(\n elationId: number | undefined,\n options?: UsePatientMedicalOptions,\n) {\n const medications = useQuery(\n medicationsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const problems = useQuery(\n problemsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const allergies = useQuery(\n allergiesByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const appointments = useQuery(\n appointmentsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n useEffect(() => {\n if (elationId === undefined || options?.skipRefresh) {\n return;\n }\n const apiBaseUrl = options?.apiBaseUrl;\n const apiKey = options?.apiKey;\n if (!apiBaseUrl || !apiKey) {\n return;\n }\n\n const controller = new AbortController();\n void fetch(`${apiBaseUrl}/api/patients/medical/refresh`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": apiKey,\n },\n body: JSON.stringify({ elationId }),\n signal: controller.signal,\n }).catch(() => {\n /* background refresh — failures are non-fatal */\n });\n\n return () => controller.abort();\n }, [elationId, options?.apiBaseUrl, options?.apiKey, options?.skipRefresh]);\n\n return { medications, problems, allergies, appointments };\n}\n\nexport {\n usePatients,\n usePatient,\n usePatientByElationId,\n usePatientByHintId,\n useAppointments,\n useAppointment,\n useAppointmentByElationId,\n usePhysiciansByElationIds,\n usePhysicianByElationId,\n usePatientMedical,\n};\nexport type {\n UsePatientListOptions,\n UseAppointmentListOptions,\n UsePatientMedicalOptions,\n Physician,\n};\n","/**\n * TruthProvider — Convex React provider pre-configured for Truth.\n *\n * Wraps children in a ConvexProvider connected to the correct\n * Truth Convex deployment for the given environment.\n *\n * @example\n * ```tsx\n * import { TruthProvider } from '@hipnation-truth/sdk/react';\n *\n * function App() {\n * return (\n * <TruthProvider environment=\"sandbox\">\n * <MyApp />\n * </TruthProvider>\n * );\n * }\n * ```\n */\n\n\"use client\";\n\nimport { ConvexProvider, ConvexReactClient } from \"convex/react\";\nimport type { ReactNode } from \"react\";\nimport { createElement, useMemo } from \"react\";\n\n// Mirrors CONVEX_URLS in client.ts. UAT shares prod resources.\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\ninterface TruthProviderProps {\n /** Truth environment — determines which Convex deployment to connect to */\n environment?: string;\n /** Override the Convex URL directly */\n convexUrl?: string;\n children: ReactNode;\n}\n\nfunction TruthProvider({\n environment = \"sandbox\",\n convexUrl,\n children,\n}: TruthProviderProps) {\n const url = convexUrl ?? CONVEX_URLS[environment] ?? CONVEX_URLS.sandbox;\n\n const client = useMemo(() => new ConvexReactClient(url), [url]);\n\n return createElement(ConvexProvider, { client }, children);\n}\n\nexport { TruthProvider };\nexport type { TruthProviderProps };\n","/**\n * React tracking hook — fire-and-forget event tracking from client components.\n *\n * Creates a lightweight Tracker instance scoped to the browser session\n * and exposes a useTrack() hook for emitting events to Truth's Kinesis stream.\n *\n * @example\n * ```tsx\n * import { useTruth } from '@hipnation-truth/sdk/react';\n *\n * function ConversationView({ conversationId }) {\n * const truth = useTruth();\n *\n * useEffect(() => {\n * truth.track('conversation.marked_read.v1', {\n * read_by_actor_id: userId,\n * unread_count_before: 5,\n * unread_count_after: 0,\n * }, { subject: { conversation_id: conversationId } });\n * }, [conversationId]);\n * }\n * ```\n */\n\n\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport { createContext, createElement, useContext, useMemo } from \"react\";\nimport type {\n EventPayloadMap,\n EventType,\n TrackOptions,\n} from \"../tracking/events\";\nimport { Tracker } from \"../tracking/tracker\";\nimport type { ActorContext } from \"../types/config\";\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface TruthTrackingContextValue {\n track: <T extends EventType>(\n eventType: T,\n payload: EventPayloadMap[T],\n options?: TrackOptions,\n ) => void;\n identify: (actorId: string, actorType: ActorContext[\"actorType\"]) => void;\n}\n\nconst TruthTrackingContext = createContext<TruthTrackingContextValue | null>(\n null,\n);\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\ninterface TruthTrackingProviderProps {\n /** Truth environment — determines API URL for event delivery */\n environment?: string;\n /** Event source identifier */\n source?: string;\n /** Source version (git SHA) */\n sourceVersion?: string;\n /** Default tenant ID */\n tenantId?: string;\n /** API key for authentication */\n apiKey?: string;\n children: ReactNode;\n}\n\nfunction TruthTrackingProvider({\n environment = \"sandbox\",\n source = \"communication-hub.frontend\",\n sourceVersion = \"unknown\",\n tenantId = \"hipnation\",\n apiKey = \"\",\n children,\n}: TruthTrackingProviderProps) {\n const value = useMemo<TruthTrackingContextValue>(() => {\n const tracker = new Tracker({\n apiKey,\n environment,\n source,\n sourceVersion,\n tenantId,\n batchSize: 10,\n flushIntervalMs: 5000,\n });\n\n return {\n track: (eventType, payload, options) => {\n tracker.track(eventType, payload, options);\n },\n identify: (actorId, actorType) => {\n tracker.setActor({ actorId, actorType });\n },\n };\n }, [apiKey, environment, source, sourceVersion, tenantId]);\n\n return createElement(TruthTrackingContext.Provider, { value }, children);\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * Access the Truth tracking context. Must be within a TruthTrackingProvider.\n * Returns `{ track, identify }` for emitting events to Kinesis.\n */\nfunction useTruth(): TruthTrackingContextValue {\n const ctx = useContext(TruthTrackingContext);\n if (!ctx) {\n throw new Error(\"useTruth must be used within a TruthTrackingProvider\");\n }\n return ctx;\n}\n\nexport { TruthTrackingProvider, useTruth };\nexport type { TruthTrackingProviderProps, TruthTrackingContextValue };\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_B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;AAMA,SAAS,MAAM,IAA2B;AACxC,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AACzD;;;ADjRA,IAAM,2BAAuB;AAAA,EAC3B;AACF;AAoBA,SAAS,sBAAsB;AAAA,EAC7B,cAAc;AAAA,EACd,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,SAAS;AAAA,EACT;AACF,GAA+B;AAC7B,QAAM,YAAQ,uBAAmC,MAAM;AACrD,UAAM,UAAU,IAAI,QAAQ;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MACX,iBAAiB;AAAA,IACnB,CAAC;AAED,WAAO;AAAA,MACL,OAAO,CAAC,WAAW,SAAS,YAAY;AACtC,gBAAQ,MAAM,WAAW,SAAS,OAAO;AAAA,MAC3C;AAAA,MACA,UAAU,CAAC,SAAS,cAAc;AAChC,gBAAQ,SAAS,EAAE,SAAS,UAAU,CAAC;AAAA,MACzC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,aAAa,QAAQ,eAAe,QAAQ,CAAC;AAEzD,aAAO,6BAAc,qBAAqB,UAAU,EAAE,MAAM,GAAG,QAAQ;AACzE;AAUA,SAAS,WAAsC;AAC7C,QAAM,UAAM,0BAAW,oBAAoB;AAC3C,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,SAAO;AACT;","names":["import_react","import_react","import_react"]}
1
+ {"version":3,"sources":["../src/react.ts","../src/react/hooks.ts","../src/react/provider.ts","../src/react/tracking.ts","../src/tracking/tracker.ts"],"sourcesContent":["/**\n * @hipnation-truth/sdk/react\n *\n * React hooks and provider for Truth SDK — real-time Convex-backed data.\n *\n * @example\n * ```tsx\n * import { TruthProvider, usePatients, useAppointments } from '@hipnation-truth/sdk/react';\n *\n * function App() {\n * return (\n * <TruthProvider environment=\"sandbox\">\n * <PatientList />\n * </TruthProvider>\n * );\n * }\n *\n * function PatientList() {\n * const patients = usePatients({ limit: 20 });\n * if (!patients) return <div>Loading...</div>;\n * return patients.map(p => <div key={p._id}>{p.firstName}</div>);\n * }\n * ```\n */\n\n// Re-export types consumers commonly need\nexport type {\n ConversationMessage,\n Physician,\n UseAppointmentListOptions,\n UseConversationMessagesOptions,\n UsePatientBasicOptions,\n UsePatientBasicResult,\n UsePatientListOptions,\n UsePatientMedicalOptions,\n UsePatientPhotoOptions,\n} from \"./react/hooks\";\n// Patient / Appointment / Physician / Medical / Messages hooks\nexport {\n useAppointment,\n useAppointmentByElationId,\n useAppointments,\n useConversationMessages,\n usePatient,\n usePatientBasic,\n usePatientByElationId,\n usePatientByHintId,\n usePatientMedical,\n usePatientPhoto,\n usePatients,\n usePharmacyByNcpdpId,\n usePhysicianByElationId,\n usePhysiciansByElationIds,\n} from \"./react/hooks\";\nexport type { TruthProviderProps } from \"./react/provider\";\n// Provider\nexport { TruthProvider } from \"./react/provider\";\nexport type {\n TruthTrackingContextValue,\n TruthTrackingProviderProps,\n} from \"./react/tracking\";\n// Tracking\nexport { TruthTrackingProvider, useTruth } from \"./react/tracking\";\n// Re-export event types for track() calls\nexport type {\n EventPayloadMap,\n EventType,\n TrackOptions,\n} from \"./tracking/events\";\nexport type { Appointment, AppointmentListOptions } from \"./types/appointment\";\nexport type { Patient, PatientListOptions } from \"./types/patient\";\n","/**\n * React hooks for Truth SDK — real-time Convex-backed data access.\n *\n * These hooks use Convex React subscriptions for live-updating data.\n * Must be used within a ConvexProvider (see TruthProvider).\n *\n * @example\n * ```tsx\n * import { usePatients, useAppointments } from '@hipnation-truth/sdk/react';\n *\n * function PatientList() {\n * const patients = usePatients({ limit: 20 });\n * return patients?.map(p => <div key={p._id}>{p.firstName} {p.lastName}</div>);\n * }\n * ```\n */\n\n\"use client\";\n\nimport { useQuery } from \"convex/react\";\nimport { useEffect } from \"react\";\n\n// ---------------------------------------------------------------------------\n// Convex function references\n// ---------------------------------------------------------------------------\n// We use string-based references to avoid importing the generated API\n// (which lives in the consuming app, not the SDK). Convex supports this\n// via the `api` module pattern, but for a published SDK we use\n// makeFunctionReference to stay decoupled from the app's codegen.\n\nimport type { FunctionReference } from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\n\n// Patient query references\nconst patientsListRef = makeFunctionReference<\n \"query\",\n {\n search?: string;\n lastName?: string;\n cursor?: string;\n limit?: number;\n },\n unknown[]\n>(\"patients:list\");\n\nconst patientsGetRef = makeFunctionReference<\n \"query\",\n { id: string },\n unknown | null\n>(\"patients:get\");\n\nconst patientsByElationIdRef = makeFunctionReference<\n \"query\",\n { elationId: string },\n unknown | null\n>(\"patients:getByElationId\");\n\nconst patientsByHintIdRef = makeFunctionReference<\n \"query\",\n { hintId: string },\n unknown | null\n>(\"patients:getByHintId\");\n\n// Appointment query references\nconst appointmentsListRef = makeFunctionReference<\n \"query\",\n {\n patientId?: string;\n status?: string;\n startDate?: string;\n endDate?: string;\n limit?: number;\n },\n unknown[]\n>(\"appointments:list\");\n\nconst appointmentsGetRef = makeFunctionReference<\n \"query\",\n { id: string },\n unknown | null\n>(\"appointments:get\");\n\nconst appointmentsByElationIdRef = makeFunctionReference<\n \"query\",\n { elationId: string },\n unknown | null\n>(\"appointments:getByElationId\");\n\n// ---------------------------------------------------------------------------\n// Patient hooks\n// ---------------------------------------------------------------------------\n\ninterface UsePatientListOptions {\n search?: string;\n lastName?: string;\n limit?: number;\n}\n\n/**\n * Subscribe to a list of patients with optional search and filtering.\n * Returns undefined while loading, then an array of patients.\n */\nfunction usePatients(options?: UsePatientListOptions) {\n return useQuery(patientsListRef as FunctionReference<\"query\">, options ?? {});\n}\n\n/**\n * Subscribe to a single patient by Convex document ID.\n */\nfunction usePatient(id: string) {\n return useQuery(patientsGetRef as FunctionReference<\"query\">, { id });\n}\n\n/**\n * Subscribe to a patient by their Elation ID.\n */\nfunction usePatientByElationId(elationId: string) {\n return useQuery(patientsByElationIdRef as FunctionReference<\"query\">, {\n elationId,\n });\n}\n\n/**\n * Subscribe to a patient by their Hint ID.\n */\nfunction usePatientByHintId(hintId: string) {\n return useQuery(patientsByHintIdRef as FunctionReference<\"query\">, {\n hintId,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Appointment hooks\n// ---------------------------------------------------------------------------\n\ninterface UseAppointmentListOptions {\n patientId?: string;\n status?: string;\n startDate?: string;\n endDate?: string;\n limit?: number;\n}\n\n/**\n * Subscribe to a list of appointments with optional filtering.\n */\nfunction useAppointments(options?: UseAppointmentListOptions) {\n return useQuery(\n appointmentsListRef as FunctionReference<\"query\">,\n options ?? {},\n );\n}\n\n/**\n * Subscribe to a single appointment by Convex document ID.\n */\nfunction useAppointment(id: string) {\n return useQuery(appointmentsGetRef as FunctionReference<\"query\">, { id });\n}\n\n/**\n * Subscribe to an appointment by its Elation ID.\n */\nfunction useAppointmentByElationId(elationId: string) {\n return useQuery(appointmentsByElationIdRef as FunctionReference<\"query\">, {\n elationId,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Physician hooks\n// ---------------------------------------------------------------------------\n\ninterface 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\nconst physiciansGetByElationIdsRef = makeFunctionReference<\n \"query\",\n { ids: number[] },\n Physician[]\n>(\"physicians:getByElationIds\");\n\nconst physiciansGetByElationIdRef = makeFunctionReference<\n \"query\",\n { id: number },\n Physician | null\n>(\"physicians:getByElationId\");\n\n/**\n * Resolve a batch of physicians by their Elation IDs. Returns an array\n * of physicians that exist in Convex; missing ids are silently dropped.\n *\n * Use this to resolve medication `prescribing_physician` / appointment\n * physician ids to display names, avoiding the per-physician HTTP\n * round-trip through Truth's Elation proxy.\n *\n * Pass `undefined` (or an empty array) to skip the query — the hook\n * returns `undefined` until you pass a populated list.\n */\nfunction usePhysiciansByElationIds(ids: number[] | undefined) {\n return useQuery(\n physiciansGetByElationIdsRef as FunctionReference<\"query\">,\n ids && ids.length > 0 ? { ids } : \"skip\",\n );\n}\n\n/**\n * Subscribe to a single physician by their Elation ID.\n */\nfunction usePhysicianByElationId(id: number | undefined) {\n return useQuery(\n physiciansGetByElationIdRef as FunctionReference<\"query\">,\n id !== undefined ? { id } : \"skip\",\n );\n}\n\n// ---------------------------------------------------------------------------\n// Patient medical hooks (medications, problems, allergies, appointments)\n// ---------------------------------------------------------------------------\n\nconst medicationsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getMedicationsByElationPatient\");\n\nconst problemsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getProblemsByElationPatient\");\n\nconst allergiesByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getAllergiesByElationPatient\");\n\nconst appointmentsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getAppointmentsByElationPatient\");\n\ninterface UsePatientMedicalOptions {\n /**\n * Base URL of the Truth API. Required to trigger the background refresh\n * (e.g. `https://app.truth.communication-hub.com`). If omitted, the hook\n * only reads from Convex and does not refresh.\n */\n apiBaseUrl?: string;\n /** API key used for the refresh call. */\n apiKey?: string;\n /**\n * If true, suppress the background refresh. Useful when you know the\n * data was just refreshed by another component on the page.\n */\n skipRefresh?: boolean;\n}\n\n/**\n * Composite hook that returns a patient's medical records — medications,\n * problems, allergies, appointments — from the Convex cache.\n *\n * On mount (and when `elationId` changes) fires a background refresh\n * against Truth's `/api/patients/medical/refresh` endpoint so stale data\n * is pulled in without blocking render. Returns cached data immediately;\n * Convex subscription updates the UI when refresh completes.\n */\nfunction usePatientMedical(\n elationId: number | undefined,\n options?: UsePatientMedicalOptions,\n) {\n const medications = useQuery(\n medicationsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const problems = useQuery(\n problemsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const allergies = useQuery(\n allergiesByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const appointments = useQuery(\n appointmentsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n useEffect(() => {\n if (elationId === undefined || options?.skipRefresh) {\n return;\n }\n const apiBaseUrl = options?.apiBaseUrl;\n const apiKey = options?.apiKey;\n if (!apiBaseUrl || !apiKey) {\n return;\n }\n\n const controller = new AbortController();\n void fetch(`${apiBaseUrl}/api/patients/medical/refresh`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": apiKey,\n },\n body: JSON.stringify({ elationId }),\n signal: controller.signal,\n }).catch(() => {\n /* background refresh — failures are non-fatal */\n });\n\n return () => controller.abort();\n }, [elationId, options?.apiBaseUrl, options?.apiKey, options?.skipRefresh]);\n\n return { medications, problems, allergies, appointments };\n}\n\n// ---------------------------------------------------------------------------\n// Patient basic hooks (Elation demographics + Hint memberships/account)\n// ---------------------------------------------------------------------------\n//\n// Replaces the CommHub `getPatientBasicDetails` Hasura Action. Reads\n// from Convex-cached rows (populated by the patients-backfill cron +\n// `/api/patients/basic/refresh` on-demand), falling back to an empty\n// state until the background refresh completes.\n\nconst elationPatientByIdRef = makeFunctionReference<\n \"query\",\n { elationId: number },\n unknown | null\n>(\"elationPatients:getByElationId\");\n\nconst hintPatientByIdRef = makeFunctionReference<\n \"query\",\n { hintId: string },\n unknown | null\n>(\"hintPatients:getByHintId\");\n\nconst pharmacyByNcpdpRef = makeFunctionReference<\n \"query\",\n { ncpdpId: string },\n unknown | null\n>(\"elationPharmacies:getByNcpdpId\");\n\nconst patientPhotoByIdRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown | null\n>(\"elationPatientPhotos:getByElationPatientId\");\n\ninterface UsePatientBasicOptions {\n /** Truth API base URL used for the background refresh. */\n apiBaseUrl?: string;\n /** API key for the refresh call. */\n apiKey?: string;\n /** Suppress the background refresh. */\n skipRefresh?: boolean;\n}\n\ninterface UsePatientBasicResult {\n /**\n * Raw Elation patient payload (matches the shape Elation's\n * `/patients/{id}` returns — `first_name`, `last_name`, `phones`, etc).\n * Returns `undefined` while the cache miss is loading, `null` if the\n * patient isn't in Convex yet (first-open-after-backfill).\n */\n elationPatient: Record<string, unknown> | null | undefined;\n /**\n * Raw Hint patient payload (matches the shape Hint's\n * `/provider/patients/{id}` returns — `memberships`, `account`,\n * `phones`, etc).\n */\n hintPatient: Record<string, unknown> | null | undefined;\n /**\n * The full Convex row for Elation (includes `elationId`, `lastSyncedAt`,\n * `photoS3Key`, `preferredPharmacyNcpdpId`, etc). Use this when you\n * need the structured/typed fields rather than the raw Elation payload.\n */\n elationRow: Record<string, unknown> | null | undefined;\n /**\n * The full Convex row for Hint. Similar relationship to `hintPatient`.\n */\n hintRow: Record<string, unknown> | null | undefined;\n /** True while either cache miss is still pending. */\n loading: boolean;\n}\n\n/**\n * Composite hook returning a patient's basic details — Hint demographics\n * + memberships + account, Elation demographics + clinical metadata —\n * from the Convex cache.\n *\n * On mount (and when inputs change) fires a background refresh against\n * `/api/patients/basic/refresh` so stale rows get pulled fresh without\n * blocking render. Returns cached data immediately; Convex subscription\n * updates the UI when refresh completes.\n */\nfunction usePatientBasic(\n input: { hintId?: string; elationId?: number },\n options?: UsePatientBasicOptions,\n): UsePatientBasicResult {\n const elationRow = useQuery(\n elationPatientByIdRef as FunctionReference<\"query\">,\n input.elationId !== undefined ? { elationId: input.elationId } : \"skip\",\n ) as Record<string, unknown> | null | undefined;\n\n const hintRow = useQuery(\n hintPatientByIdRef as FunctionReference<\"query\">,\n input.hintId !== undefined ? { hintId: input.hintId } : \"skip\",\n ) as Record<string, unknown> | null | undefined;\n\n useEffect(() => {\n if (options?.skipRefresh) return;\n if (!input.hintId && input.elationId === undefined) return;\n const apiBaseUrl = options?.apiBaseUrl;\n const apiKey = options?.apiKey;\n if (!apiBaseUrl || !apiKey) return;\n\n const controller = new AbortController();\n void fetch(`${apiBaseUrl}/api/patients/basic/refresh`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": apiKey,\n },\n body: JSON.stringify({\n hintId: input.hintId,\n elationId: input.elationId,\n }),\n signal: controller.signal,\n }).catch(() => {\n /* background refresh — failures are non-fatal */\n });\n\n return () => controller.abort();\n }, [\n input.hintId,\n input.elationId,\n options?.apiBaseUrl,\n options?.apiKey,\n options?.skipRefresh,\n ]);\n\n // Surface the raw payload under elationPatient/hintPatient so consumers\n // can keep using the exact Elation/Hint field names (first_name,\n // memberships, account.past_due_in_cents) with zero mapping.\n const elationPatient =\n elationRow === undefined\n ? undefined\n : elationRow === null\n ? null\n : ((elationRow.raw as Record<string, unknown>) ?? null);\n const hintPatient =\n hintRow === undefined\n ? undefined\n : hintRow === null\n ? null\n : ((hintRow.raw as Record<string, unknown>) ?? null);\n\n const elationLoading =\n input.elationId !== undefined && elationRow === undefined;\n const hintLoading = input.hintId !== undefined && hintRow === undefined;\n\n return {\n elationPatient,\n hintPatient,\n elationRow,\n hintRow,\n loading: elationLoading || hintLoading,\n };\n}\n\n/**\n * Read a shared pharmacy row by NCPDP id. Backs the pharmacy card in\n * the patient panel (from Elation's preferred_pharmacy reference).\n */\nfunction usePharmacyByNcpdpId(ncpdpId: string | undefined) {\n return useQuery(\n pharmacyByNcpdpRef as FunctionReference<\"query\">,\n ncpdpId ? { ncpdpId } : \"skip\",\n );\n}\n\ninterface UsePatientPhotoOptions {\n apiBaseUrl?: string;\n apiKey?: string;\n skipRefresh?: boolean;\n}\n\n/**\n * Subscribe to a patient's profile photo (s3Key + metadata). The\n * consumer constructs a download URL via the Truth attachments resource\n * (signed S3 URL). Fires a background refresh to pull the latest photo\n * binary from Elation + upload to S3.\n */\nfunction usePatientPhoto(\n elationId: number | undefined,\n options?: UsePatientPhotoOptions,\n) {\n const photo = useQuery(\n patientPhotoByIdRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n );\n\n useEffect(() => {\n if (options?.skipRefresh) return;\n if (elationId === undefined) return;\n const apiBaseUrl = options?.apiBaseUrl;\n const apiKey = options?.apiKey;\n if (!apiBaseUrl || !apiKey) return;\n\n const controller = new AbortController();\n void fetch(`${apiBaseUrl}/api/patients/photo/refresh`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": apiKey,\n },\n body: JSON.stringify({ elationId }),\n signal: controller.signal,\n }).catch(() => {\n /* non-fatal */\n });\n\n return () => controller.abort();\n }, [elationId, options?.apiBaseUrl, options?.apiKey, options?.skipRefresh]);\n\n return photo;\n}\n\n// ---------------------------------------------------------------------------\n// Conversation messages (Dialpad calls + SMS merged)\n// ---------------------------------------------------------------------------\n\ninterface ConversationMessage {\n kind: \"call\" | \"sms\";\n id: string;\n providerId: string;\n state: string | null;\n direction: string | null;\n fromNumber: string | null;\n toNumber: string | null;\n voicemailLink: string | null;\n duration: number | null;\n text: string | null;\n mms: boolean;\n mmsUrl: string | null;\n messageStatus: string | null;\n occurredAt: string;\n conversationId: string | null;\n patientId: string | null;\n}\n\nconst messagesByPhonesRef = makeFunctionReference<\n \"query\",\n { phoneA: string; phoneB: string; limit?: number },\n ConversationMessage[]\n>(\"conversationMessages:getByPhones\");\n\nconst messagesByConversationIdRef = makeFunctionReference<\n \"query\",\n { conversationId: string; limit?: number },\n ConversationMessage[]\n>(\"conversationMessages:getByConversationId\");\n\ninterface UseConversationMessagesOptions {\n /** Max items to return (default 200). */\n limit?: number;\n}\n\n/**\n * Subscribe to a conversation's calls + SMS merged chronologically.\n * Pass the patient phone + the provider phone — Truth computes a\n * normalized pair key server-side so formatting differences don't\n * matter.\n *\n * Returns `undefined` while loading, then `ConversationMessage[]`\n * sorted newest-first. Updates live as new webhook events land in\n * Convex via the kinesis consumer.\n */\nfunction useConversationMessages(\n input: { phoneA?: string; phoneB?: string; conversationId?: string },\n options?: UseConversationMessagesOptions,\n): ConversationMessage[] | undefined {\n const hasPair = !!input.phoneA && !!input.phoneB;\n const byPair = useQuery(\n messagesByPhonesRef as FunctionReference<\"query\">,\n hasPair\n ? {\n phoneA: input.phoneA as string,\n phoneB: input.phoneB as string,\n limit: options?.limit,\n }\n : \"skip\",\n ) as ConversationMessage[] | undefined;\n\n const byConvo = useQuery(\n messagesByConversationIdRef as FunctionReference<\"query\">,\n !hasPair && input.conversationId\n ? { conversationId: input.conversationId, limit: options?.limit }\n : \"skip\",\n ) as ConversationMessage[] | undefined;\n\n return hasPair ? byPair : byConvo;\n}\n\nexport {\n usePatients,\n usePatient,\n usePatientByElationId,\n usePatientByHintId,\n useAppointments,\n useAppointment,\n useAppointmentByElationId,\n usePhysiciansByElationIds,\n usePhysicianByElationId,\n usePatientMedical,\n usePatientBasic,\n usePharmacyByNcpdpId,\n usePatientPhoto,\n useConversationMessages,\n};\nexport type { ConversationMessage, UseConversationMessagesOptions };\nexport type {\n UsePatientListOptions,\n UseAppointmentListOptions,\n UsePatientMedicalOptions,\n UsePatientBasicOptions,\n UsePatientBasicResult,\n UsePatientPhotoOptions,\n Physician,\n};\n","/**\n * TruthProvider — Convex React provider pre-configured for Truth.\n *\n * Wraps children in a ConvexProvider connected to the correct\n * Truth Convex deployment for the given environment.\n *\n * @example\n * ```tsx\n * import { TruthProvider } from '@hipnation-truth/sdk/react';\n *\n * function App() {\n * return (\n * <TruthProvider environment=\"sandbox\">\n * <MyApp />\n * </TruthProvider>\n * );\n * }\n * ```\n */\n\n\"use client\";\n\nimport { ConvexProvider, ConvexReactClient } from \"convex/react\";\nimport type { ReactNode } from \"react\";\nimport { createElement, useMemo } from \"react\";\n\n// Mirrors CONVEX_URLS in client.ts. UAT shares prod resources.\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\ninterface TruthProviderProps {\n /** Truth environment — determines which Convex deployment to connect to */\n environment?: string;\n /** Override the Convex URL directly */\n convexUrl?: string;\n children: ReactNode;\n}\n\nfunction TruthProvider({\n environment = \"sandbox\",\n convexUrl,\n children,\n}: TruthProviderProps) {\n const url = convexUrl ?? CONVEX_URLS[environment] ?? CONVEX_URLS.sandbox;\n\n const client = useMemo(() => new ConvexReactClient(url), [url]);\n\n return createElement(ConvexProvider, { client }, children);\n}\n\nexport { TruthProvider };\nexport type { TruthProviderProps };\n","/**\n * React tracking hook — fire-and-forget event tracking from client components.\n *\n * Creates a lightweight Tracker instance scoped to the browser session\n * and exposes a useTrack() hook for emitting events to Truth's Kinesis stream.\n *\n * @example\n * ```tsx\n * import { useTruth } from '@hipnation-truth/sdk/react';\n *\n * function ConversationView({ conversationId }) {\n * const truth = useTruth();\n *\n * useEffect(() => {\n * truth.track('conversation.marked_read.v1', {\n * read_by_actor_id: userId,\n * unread_count_before: 5,\n * unread_count_after: 0,\n * }, { subject: { conversation_id: conversationId } });\n * }, [conversationId]);\n * }\n * ```\n */\n\n\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport { createContext, createElement, useContext, useMemo } from \"react\";\nimport type {\n EventPayloadMap,\n EventType,\n TrackOptions,\n} from \"../tracking/events\";\nimport { Tracker } from \"../tracking/tracker\";\nimport type { ActorContext } from \"../types/config\";\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface TruthTrackingContextValue {\n track: <T extends EventType>(\n eventType: T,\n payload: EventPayloadMap[T],\n options?: TrackOptions,\n ) => void;\n identify: (actorId: string, actorType: ActorContext[\"actorType\"]) => void;\n}\n\nconst TruthTrackingContext = createContext<TruthTrackingContextValue | null>(\n null,\n);\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\ninterface TruthTrackingProviderProps {\n /** Truth environment — determines API URL for event delivery */\n environment?: string;\n /** Event source identifier */\n source?: string;\n /** Source version (git SHA) */\n sourceVersion?: string;\n /** Default tenant ID */\n tenantId?: string;\n /** API key for authentication */\n apiKey?: string;\n children: ReactNode;\n}\n\nfunction TruthTrackingProvider({\n environment = \"sandbox\",\n source = \"communication-hub.frontend\",\n sourceVersion = \"unknown\",\n tenantId = \"hipnation\",\n apiKey = \"\",\n children,\n}: TruthTrackingProviderProps) {\n const value = useMemo<TruthTrackingContextValue>(() => {\n const tracker = new Tracker({\n apiKey,\n environment,\n source,\n sourceVersion,\n tenantId,\n batchSize: 10,\n flushIntervalMs: 5000,\n });\n\n return {\n track: (eventType, payload, options) => {\n tracker.track(eventType, payload, options);\n },\n identify: (actorId, actorType) => {\n tracker.setActor({ actorId, actorType });\n },\n };\n }, [apiKey, environment, source, sourceVersion, tenantId]);\n\n return createElement(TruthTrackingContext.Provider, { value }, children);\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * Access the Truth tracking context. Must be within a TruthTrackingProvider.\n * Returns `{ track, identify }` for emitting events to Kinesis.\n */\nfunction useTruth(): TruthTrackingContextValue {\n const ctx = useContext(TruthTrackingContext);\n if (!ctx) {\n throw new Error(\"useTruth must be used within a TruthTrackingProvider\");\n }\n return ctx;\n}\n\nexport { TruthTrackingProvider, useTruth };\nexport type { TruthTrackingProviderProps, TruthTrackingContextValue };\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACmBA,mBAAyB;AACzB,IAAAA,gBAA0B;AAW1B,oBAAsC;AAGtC,IAAM,sBAAkB,qCAStB,eAAe;AAEjB,IAAM,qBAAiB,qCAIrB,cAAc;AAEhB,IAAM,6BAAyB,qCAI7B,yBAAyB;AAE3B,IAAM,0BAAsB,qCAI1B,sBAAsB;AAGxB,IAAM,0BAAsB,qCAU1B,mBAAmB;AAErB,IAAM,yBAAqB,qCAIz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ACrD,UAAM,UAAU,IAAI,QAAQ;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MACX,iBAAiB;AAAA,IACnB,CAAC;AAED,WAAO;AAAA,MACL,OAAO,CAAC,WAAW,SAAS,YAAY;AACtC,gBAAQ,MAAM,WAAW,SAAS,OAAO;AAAA,MAC3C;AAAA,MACA,UAAU,CAAC,SAAS,cAAc;AAChC,gBAAQ,SAAS,EAAE,SAAS,UAAU,CAAC;AAAA,MACzC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,aAAa,QAAQ,eAAe,QAAQ,CAAC;AAEzD,aAAO,6BAAc,qBAAqB,UAAU,EAAE,MAAM,GAAG,QAAQ;AACzE;AAUA,SAAS,WAAsC;AAC7C,QAAM,UAAM,0BAAW,oBAAoB;AAC3C,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,SAAO;AACT;","names":["import_react","import_react","import_react"]}
package/dist/react.mjs CHANGED
@@ -121,6 +121,110 @@ function usePatientMedical(elationId, options) {
121
121
  }, [elationId, options == null ? void 0 : options.apiBaseUrl, options == null ? void 0 : options.apiKey, options == null ? void 0 : options.skipRefresh]);
122
122
  return { medications, problems, allergies, appointments };
123
123
  }
124
+ var elationPatientByIdRef = makeFunctionReference("elationPatients:getByElationId");
125
+ var hintPatientByIdRef = makeFunctionReference("hintPatients:getByHintId");
126
+ var pharmacyByNcpdpRef = makeFunctionReference("elationPharmacies:getByNcpdpId");
127
+ var patientPhotoByIdRef = makeFunctionReference("elationPatientPhotos:getByElationPatientId");
128
+ function usePatientBasic(input, options) {
129
+ var _a, _b;
130
+ const elationRow = useQuery(
131
+ elationPatientByIdRef,
132
+ input.elationId !== void 0 ? { elationId: input.elationId } : "skip"
133
+ );
134
+ const hintRow = useQuery(
135
+ hintPatientByIdRef,
136
+ input.hintId !== void 0 ? { hintId: input.hintId } : "skip"
137
+ );
138
+ useEffect(() => {
139
+ if (options == null ? void 0 : options.skipRefresh) return;
140
+ if (!input.hintId && input.elationId === void 0) return;
141
+ const apiBaseUrl = options == null ? void 0 : options.apiBaseUrl;
142
+ const apiKey = options == null ? void 0 : options.apiKey;
143
+ if (!apiBaseUrl || !apiKey) return;
144
+ const controller = new AbortController();
145
+ void fetch(`${apiBaseUrl}/api/patients/basic/refresh`, {
146
+ method: "POST",
147
+ headers: {
148
+ "Content-Type": "application/json",
149
+ "X-API-Key": apiKey
150
+ },
151
+ body: JSON.stringify({
152
+ hintId: input.hintId,
153
+ elationId: input.elationId
154
+ }),
155
+ signal: controller.signal
156
+ }).catch(() => {
157
+ });
158
+ return () => controller.abort();
159
+ }, [
160
+ input.hintId,
161
+ input.elationId,
162
+ options == null ? void 0 : options.apiBaseUrl,
163
+ options == null ? void 0 : options.apiKey,
164
+ options == null ? void 0 : options.skipRefresh
165
+ ]);
166
+ const elationPatient = elationRow === void 0 ? void 0 : elationRow === null ? null : (_a = elationRow.raw) != null ? _a : null;
167
+ const hintPatient = hintRow === void 0 ? void 0 : hintRow === null ? null : (_b = hintRow.raw) != null ? _b : null;
168
+ const elationLoading = input.elationId !== void 0 && elationRow === void 0;
169
+ const hintLoading = input.hintId !== void 0 && hintRow === void 0;
170
+ return {
171
+ elationPatient,
172
+ hintPatient,
173
+ elationRow,
174
+ hintRow,
175
+ loading: elationLoading || hintLoading
176
+ };
177
+ }
178
+ function usePharmacyByNcpdpId(ncpdpId) {
179
+ return useQuery(
180
+ pharmacyByNcpdpRef,
181
+ ncpdpId ? { ncpdpId } : "skip"
182
+ );
183
+ }
184
+ function usePatientPhoto(elationId, options) {
185
+ const photo = useQuery(
186
+ patientPhotoByIdRef,
187
+ elationId !== void 0 ? { elationPatientId: elationId } : "skip"
188
+ );
189
+ useEffect(() => {
190
+ if (options == null ? void 0 : options.skipRefresh) return;
191
+ if (elationId === void 0) return;
192
+ const apiBaseUrl = options == null ? void 0 : options.apiBaseUrl;
193
+ const apiKey = options == null ? void 0 : options.apiKey;
194
+ if (!apiBaseUrl || !apiKey) return;
195
+ const controller = new AbortController();
196
+ void fetch(`${apiBaseUrl}/api/patients/photo/refresh`, {
197
+ method: "POST",
198
+ headers: {
199
+ "Content-Type": "application/json",
200
+ "X-API-Key": apiKey
201
+ },
202
+ body: JSON.stringify({ elationId }),
203
+ signal: controller.signal
204
+ }).catch(() => {
205
+ });
206
+ return () => controller.abort();
207
+ }, [elationId, options == null ? void 0 : options.apiBaseUrl, options == null ? void 0 : options.apiKey, options == null ? void 0 : options.skipRefresh]);
208
+ return photo;
209
+ }
210
+ var messagesByPhonesRef = makeFunctionReference("conversationMessages:getByPhones");
211
+ var messagesByConversationIdRef = makeFunctionReference("conversationMessages:getByConversationId");
212
+ function useConversationMessages(input, options) {
213
+ const hasPair = !!input.phoneA && !!input.phoneB;
214
+ const byPair = useQuery(
215
+ messagesByPhonesRef,
216
+ hasPair ? {
217
+ phoneA: input.phoneA,
218
+ phoneB: input.phoneB,
219
+ limit: options == null ? void 0 : options.limit
220
+ } : "skip"
221
+ );
222
+ const byConvo = useQuery(
223
+ messagesByConversationIdRef,
224
+ !hasPair && input.conversationId ? { conversationId: input.conversationId, limit: options == null ? void 0 : options.limit } : "skip"
225
+ );
226
+ return hasPair ? byPair : byConvo;
227
+ }
124
228
 
125
229
  // src/react/provider.ts
126
230
  import { ConvexProvider, ConvexReactClient } from "convex/react";
@@ -385,11 +489,15 @@ export {
385
489
  useAppointment,
386
490
  useAppointmentByElationId,
387
491
  useAppointments,
492
+ useConversationMessages,
388
493
  usePatient,
494
+ usePatientBasic,
389
495
  usePatientByElationId,
390
496
  usePatientByHintId,
391
497
  usePatientMedical,
498
+ usePatientPhoto,
392
499
  usePatients,
500
+ usePharmacyByNcpdpId,
393
501
  usePhysicianByElationId,
394
502
  usePhysiciansByElationIds,
395
503
  useTruth
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/react/hooks.ts","../src/react/provider.ts","../src/react/tracking.ts","../src/tracking/tracker.ts"],"sourcesContent":["/**\n * React hooks for Truth SDK — real-time Convex-backed data access.\n *\n * These hooks use Convex React subscriptions for live-updating data.\n * Must be used within a ConvexProvider (see TruthProvider).\n *\n * @example\n * ```tsx\n * import { usePatients, useAppointments } from '@hipnation-truth/sdk/react';\n *\n * function PatientList() {\n * const patients = usePatients({ limit: 20 });\n * return patients?.map(p => <div key={p._id}>{p.firstName} {p.lastName}</div>);\n * }\n * ```\n */\n\n\"use client\";\n\nimport { useQuery } from \"convex/react\";\nimport { useEffect } from \"react\";\n\n// ---------------------------------------------------------------------------\n// Convex function references\n// ---------------------------------------------------------------------------\n// We use string-based references to avoid importing the generated API\n// (which lives in the consuming app, not the SDK). Convex supports this\n// via the `api` module pattern, but for a published SDK we use\n// makeFunctionReference to stay decoupled from the app's codegen.\n\nimport type { FunctionReference } from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\n\n// Patient query references\nconst patientsListRef = makeFunctionReference<\n \"query\",\n {\n search?: string;\n lastName?: string;\n cursor?: string;\n limit?: number;\n },\n unknown[]\n>(\"patients:list\");\n\nconst patientsGetRef = makeFunctionReference<\n \"query\",\n { id: string },\n unknown | null\n>(\"patients:get\");\n\nconst patientsByElationIdRef = makeFunctionReference<\n \"query\",\n { elationId: string },\n unknown | null\n>(\"patients:getByElationId\");\n\nconst patientsByHintIdRef = makeFunctionReference<\n \"query\",\n { hintId: string },\n unknown | null\n>(\"patients:getByHintId\");\n\n// Appointment query references\nconst appointmentsListRef = makeFunctionReference<\n \"query\",\n {\n patientId?: string;\n status?: string;\n startDate?: string;\n endDate?: string;\n limit?: number;\n },\n unknown[]\n>(\"appointments:list\");\n\nconst appointmentsGetRef = makeFunctionReference<\n \"query\",\n { id: string },\n unknown | null\n>(\"appointments:get\");\n\nconst appointmentsByElationIdRef = makeFunctionReference<\n \"query\",\n { elationId: string },\n unknown | null\n>(\"appointments:getByElationId\");\n\n// ---------------------------------------------------------------------------\n// Patient hooks\n// ---------------------------------------------------------------------------\n\ninterface UsePatientListOptions {\n search?: string;\n lastName?: string;\n limit?: number;\n}\n\n/**\n * Subscribe to a list of patients with optional search and filtering.\n * Returns undefined while loading, then an array of patients.\n */\nfunction usePatients(options?: UsePatientListOptions) {\n return useQuery(patientsListRef as FunctionReference<\"query\">, options ?? {});\n}\n\n/**\n * Subscribe to a single patient by Convex document ID.\n */\nfunction usePatient(id: string) {\n return useQuery(patientsGetRef as FunctionReference<\"query\">, { id });\n}\n\n/**\n * Subscribe to a patient by their Elation ID.\n */\nfunction usePatientByElationId(elationId: string) {\n return useQuery(patientsByElationIdRef as FunctionReference<\"query\">, {\n elationId,\n });\n}\n\n/**\n * Subscribe to a patient by their Hint ID.\n */\nfunction usePatientByHintId(hintId: string) {\n return useQuery(patientsByHintIdRef as FunctionReference<\"query\">, {\n hintId,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Appointment hooks\n// ---------------------------------------------------------------------------\n\ninterface UseAppointmentListOptions {\n patientId?: string;\n status?: string;\n startDate?: string;\n endDate?: string;\n limit?: number;\n}\n\n/**\n * Subscribe to a list of appointments with optional filtering.\n */\nfunction useAppointments(options?: UseAppointmentListOptions) {\n return useQuery(\n appointmentsListRef as FunctionReference<\"query\">,\n options ?? {},\n );\n}\n\n/**\n * Subscribe to a single appointment by Convex document ID.\n */\nfunction useAppointment(id: string) {\n return useQuery(appointmentsGetRef as FunctionReference<\"query\">, { id });\n}\n\n/**\n * Subscribe to an appointment by its Elation ID.\n */\nfunction useAppointmentByElationId(elationId: string) {\n return useQuery(appointmentsByElationIdRef as FunctionReference<\"query\">, {\n elationId,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Physician hooks\n// ---------------------------------------------------------------------------\n\ninterface 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\nconst physiciansGetByElationIdsRef = makeFunctionReference<\n \"query\",\n { ids: number[] },\n Physician[]\n>(\"physicians:getByElationIds\");\n\nconst physiciansGetByElationIdRef = makeFunctionReference<\n \"query\",\n { id: number },\n Physician | null\n>(\"physicians:getByElationId\");\n\n/**\n * Resolve a batch of physicians by their Elation IDs. Returns an array\n * of physicians that exist in Convex; missing ids are silently dropped.\n *\n * Use this to resolve medication `prescribing_physician` / appointment\n * physician ids to display names, avoiding the per-physician HTTP\n * round-trip through Truth's Elation proxy.\n *\n * Pass `undefined` (or an empty array) to skip the query — the hook\n * returns `undefined` until you pass a populated list.\n */\nfunction usePhysiciansByElationIds(ids: number[] | undefined) {\n return useQuery(\n physiciansGetByElationIdsRef as FunctionReference<\"query\">,\n ids && ids.length > 0 ? { ids } : \"skip\",\n );\n}\n\n/**\n * Subscribe to a single physician by their Elation ID.\n */\nfunction usePhysicianByElationId(id: number | undefined) {\n return useQuery(\n physiciansGetByElationIdRef as FunctionReference<\"query\">,\n id !== undefined ? { id } : \"skip\",\n );\n}\n\n// ---------------------------------------------------------------------------\n// Patient medical hooks (medications, problems, allergies, appointments)\n// ---------------------------------------------------------------------------\n\nconst medicationsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getMedicationsByElationPatient\");\n\nconst problemsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getProblemsByElationPatient\");\n\nconst allergiesByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getAllergiesByElationPatient\");\n\nconst appointmentsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getAppointmentsByElationPatient\");\n\ninterface UsePatientMedicalOptions {\n /**\n * Base URL of the Truth API. Required to trigger the background refresh\n * (e.g. `https://app.truth.communication-hub.com`). If omitted, the hook\n * only reads from Convex and does not refresh.\n */\n apiBaseUrl?: string;\n /** API key used for the refresh call. */\n apiKey?: string;\n /**\n * If true, suppress the background refresh. Useful when you know the\n * data was just refreshed by another component on the page.\n */\n skipRefresh?: boolean;\n}\n\n/**\n * Composite hook that returns a patient's medical records — medications,\n * problems, allergies, appointments — from the Convex cache.\n *\n * On mount (and when `elationId` changes) fires a background refresh\n * against Truth's `/api/patients/medical/refresh` endpoint so stale data\n * is pulled in without blocking render. Returns cached data immediately;\n * Convex subscription updates the UI when refresh completes.\n */\nfunction usePatientMedical(\n elationId: number | undefined,\n options?: UsePatientMedicalOptions,\n) {\n const medications = useQuery(\n medicationsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const problems = useQuery(\n problemsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const allergies = useQuery(\n allergiesByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const appointments = useQuery(\n appointmentsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n useEffect(() => {\n if (elationId === undefined || options?.skipRefresh) {\n return;\n }\n const apiBaseUrl = options?.apiBaseUrl;\n const apiKey = options?.apiKey;\n if (!apiBaseUrl || !apiKey) {\n return;\n }\n\n const controller = new AbortController();\n void fetch(`${apiBaseUrl}/api/patients/medical/refresh`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": apiKey,\n },\n body: JSON.stringify({ elationId }),\n signal: controller.signal,\n }).catch(() => {\n /* background refresh — failures are non-fatal */\n });\n\n return () => controller.abort();\n }, [elationId, options?.apiBaseUrl, options?.apiKey, options?.skipRefresh]);\n\n return { medications, problems, allergies, appointments };\n}\n\nexport {\n usePatients,\n usePatient,\n usePatientByElationId,\n usePatientByHintId,\n useAppointments,\n useAppointment,\n useAppointmentByElationId,\n usePhysiciansByElationIds,\n usePhysicianByElationId,\n usePatientMedical,\n};\nexport type {\n UsePatientListOptions,\n UseAppointmentListOptions,\n UsePatientMedicalOptions,\n Physician,\n};\n","/**\n * TruthProvider — Convex React provider pre-configured for Truth.\n *\n * Wraps children in a ConvexProvider connected to the correct\n * Truth Convex deployment for the given environment.\n *\n * @example\n * ```tsx\n * import { TruthProvider } from '@hipnation-truth/sdk/react';\n *\n * function App() {\n * return (\n * <TruthProvider environment=\"sandbox\">\n * <MyApp />\n * </TruthProvider>\n * );\n * }\n * ```\n */\n\n\"use client\";\n\nimport { ConvexProvider, ConvexReactClient } from \"convex/react\";\nimport type { ReactNode } from \"react\";\nimport { createElement, useMemo } from \"react\";\n\n// Mirrors CONVEX_URLS in client.ts. UAT shares prod resources.\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\ninterface TruthProviderProps {\n /** Truth environment — determines which Convex deployment to connect to */\n environment?: string;\n /** Override the Convex URL directly */\n convexUrl?: string;\n children: ReactNode;\n}\n\nfunction TruthProvider({\n environment = \"sandbox\",\n convexUrl,\n children,\n}: TruthProviderProps) {\n const url = convexUrl ?? CONVEX_URLS[environment] ?? CONVEX_URLS.sandbox;\n\n const client = useMemo(() => new ConvexReactClient(url), [url]);\n\n return createElement(ConvexProvider, { client }, children);\n}\n\nexport { TruthProvider };\nexport type { TruthProviderProps };\n","/**\n * React tracking hook — fire-and-forget event tracking from client components.\n *\n * Creates a lightweight Tracker instance scoped to the browser session\n * and exposes a useTrack() hook for emitting events to Truth's Kinesis stream.\n *\n * @example\n * ```tsx\n * import { useTruth } from '@hipnation-truth/sdk/react';\n *\n * function ConversationView({ conversationId }) {\n * const truth = useTruth();\n *\n * useEffect(() => {\n * truth.track('conversation.marked_read.v1', {\n * read_by_actor_id: userId,\n * unread_count_before: 5,\n * unread_count_after: 0,\n * }, { subject: { conversation_id: conversationId } });\n * }, [conversationId]);\n * }\n * ```\n */\n\n\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport { createContext, createElement, useContext, useMemo } from \"react\";\nimport type {\n EventPayloadMap,\n EventType,\n TrackOptions,\n} from \"../tracking/events\";\nimport { Tracker } from \"../tracking/tracker\";\nimport type { ActorContext } from \"../types/config\";\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface TruthTrackingContextValue {\n track: <T extends EventType>(\n eventType: T,\n payload: EventPayloadMap[T],\n options?: TrackOptions,\n ) => void;\n identify: (actorId: string, actorType: ActorContext[\"actorType\"]) => void;\n}\n\nconst TruthTrackingContext = createContext<TruthTrackingContextValue | null>(\n null,\n);\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\ninterface TruthTrackingProviderProps {\n /** Truth environment — determines API URL for event delivery */\n environment?: string;\n /** Event source identifier */\n source?: string;\n /** Source version (git SHA) */\n sourceVersion?: string;\n /** Default tenant ID */\n tenantId?: string;\n /** API key for authentication */\n apiKey?: string;\n children: ReactNode;\n}\n\nfunction TruthTrackingProvider({\n environment = \"sandbox\",\n source = \"communication-hub.frontend\",\n sourceVersion = \"unknown\",\n tenantId = \"hipnation\",\n apiKey = \"\",\n children,\n}: TruthTrackingProviderProps) {\n const value = useMemo<TruthTrackingContextValue>(() => {\n const tracker = new Tracker({\n apiKey,\n environment,\n source,\n sourceVersion,\n tenantId,\n batchSize: 10,\n flushIntervalMs: 5000,\n });\n\n return {\n track: (eventType, payload, options) => {\n tracker.track(eventType, payload, options);\n },\n identify: (actorId, actorType) => {\n tracker.setActor({ actorId, actorType });\n },\n };\n }, [apiKey, environment, source, sourceVersion, tenantId]);\n\n return createElement(TruthTrackingContext.Provider, { value }, children);\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * Access the Truth tracking context. Must be within a TruthTrackingProvider.\n * Returns `{ track, identify }` for emitting events to Kinesis.\n */\nfunction useTruth(): TruthTrackingContextValue {\n const ctx = useContext(TruthTrackingContext);\n if (!ctx) {\n throw new Error(\"useTruth must be used within a TruthTrackingProvider\");\n }\n return ctx;\n}\n\nexport { TruthTrackingProvider, useTruth };\nexport type { TruthTrackingProviderProps, TruthTrackingContextValue };\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_INTER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AA,EAC3B;AACF;AAoBA,SAAS,sBAAsB;AAAA,EAC7B,cAAc;AAAA,EACd,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,WAAW;AAAA,EACX,SAAS;AAAA,EACT;AACF,GAA+B;AAC7B,QAAM,QAAQC,SAAmC,MAAM;AACrD,UAAM,UAAU,IAAI,QAAQ;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MACX,iBAAiB;AAAA,IACnB,CAAC;AAED,WAAO;AAAA,MACL,OAAO,CAAC,WAAW,SAAS,YAAY;AACtC,gBAAQ,MAAM,WAAW,SAAS,OAAO;AAAA,MAC3C;AAAA,MACA,UAAU,CAAC,SAAS,cAAc;AAChC,gBAAQ,SAAS,EAAE,SAAS,UAAU,CAAC;AAAA,MACzC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,aAAa,QAAQ,eAAe,QAAQ,CAAC;AAEzD,SAAOC,eAAc,qBAAqB,UAAU,EAAE,MAAM,GAAG,QAAQ;AACzE;AAUA,SAAS,WAAsC;AAC7C,QAAM,MAAM,WAAW,oBAAoB;AAC3C,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,SAAO;AACT;","names":["createElement","useMemo","useMemo","createElement"]}
1
+ {"version":3,"sources":["../src/react/hooks.ts","../src/react/provider.ts","../src/react/tracking.ts","../src/tracking/tracker.ts"],"sourcesContent":["/**\n * React hooks for Truth SDK — real-time Convex-backed data access.\n *\n * These hooks use Convex React subscriptions for live-updating data.\n * Must be used within a ConvexProvider (see TruthProvider).\n *\n * @example\n * ```tsx\n * import { usePatients, useAppointments } from '@hipnation-truth/sdk/react';\n *\n * function PatientList() {\n * const patients = usePatients({ limit: 20 });\n * return patients?.map(p => <div key={p._id}>{p.firstName} {p.lastName}</div>);\n * }\n * ```\n */\n\n\"use client\";\n\nimport { useQuery } from \"convex/react\";\nimport { useEffect } from \"react\";\n\n// ---------------------------------------------------------------------------\n// Convex function references\n// ---------------------------------------------------------------------------\n// We use string-based references to avoid importing the generated API\n// (which lives in the consuming app, not the SDK). Convex supports this\n// via the `api` module pattern, but for a published SDK we use\n// makeFunctionReference to stay decoupled from the app's codegen.\n\nimport type { FunctionReference } from \"convex/server\";\nimport { makeFunctionReference } from \"convex/server\";\n\n// Patient query references\nconst patientsListRef = makeFunctionReference<\n \"query\",\n {\n search?: string;\n lastName?: string;\n cursor?: string;\n limit?: number;\n },\n unknown[]\n>(\"patients:list\");\n\nconst patientsGetRef = makeFunctionReference<\n \"query\",\n { id: string },\n unknown | null\n>(\"patients:get\");\n\nconst patientsByElationIdRef = makeFunctionReference<\n \"query\",\n { elationId: string },\n unknown | null\n>(\"patients:getByElationId\");\n\nconst patientsByHintIdRef = makeFunctionReference<\n \"query\",\n { hintId: string },\n unknown | null\n>(\"patients:getByHintId\");\n\n// Appointment query references\nconst appointmentsListRef = makeFunctionReference<\n \"query\",\n {\n patientId?: string;\n status?: string;\n startDate?: string;\n endDate?: string;\n limit?: number;\n },\n unknown[]\n>(\"appointments:list\");\n\nconst appointmentsGetRef = makeFunctionReference<\n \"query\",\n { id: string },\n unknown | null\n>(\"appointments:get\");\n\nconst appointmentsByElationIdRef = makeFunctionReference<\n \"query\",\n { elationId: string },\n unknown | null\n>(\"appointments:getByElationId\");\n\n// ---------------------------------------------------------------------------\n// Patient hooks\n// ---------------------------------------------------------------------------\n\ninterface UsePatientListOptions {\n search?: string;\n lastName?: string;\n limit?: number;\n}\n\n/**\n * Subscribe to a list of patients with optional search and filtering.\n * Returns undefined while loading, then an array of patients.\n */\nfunction usePatients(options?: UsePatientListOptions) {\n return useQuery(patientsListRef as FunctionReference<\"query\">, options ?? {});\n}\n\n/**\n * Subscribe to a single patient by Convex document ID.\n */\nfunction usePatient(id: string) {\n return useQuery(patientsGetRef as FunctionReference<\"query\">, { id });\n}\n\n/**\n * Subscribe to a patient by their Elation ID.\n */\nfunction usePatientByElationId(elationId: string) {\n return useQuery(patientsByElationIdRef as FunctionReference<\"query\">, {\n elationId,\n });\n}\n\n/**\n * Subscribe to a patient by their Hint ID.\n */\nfunction usePatientByHintId(hintId: string) {\n return useQuery(patientsByHintIdRef as FunctionReference<\"query\">, {\n hintId,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Appointment hooks\n// ---------------------------------------------------------------------------\n\ninterface UseAppointmentListOptions {\n patientId?: string;\n status?: string;\n startDate?: string;\n endDate?: string;\n limit?: number;\n}\n\n/**\n * Subscribe to a list of appointments with optional filtering.\n */\nfunction useAppointments(options?: UseAppointmentListOptions) {\n return useQuery(\n appointmentsListRef as FunctionReference<\"query\">,\n options ?? {},\n );\n}\n\n/**\n * Subscribe to a single appointment by Convex document ID.\n */\nfunction useAppointment(id: string) {\n return useQuery(appointmentsGetRef as FunctionReference<\"query\">, { id });\n}\n\n/**\n * Subscribe to an appointment by its Elation ID.\n */\nfunction useAppointmentByElationId(elationId: string) {\n return useQuery(appointmentsByElationIdRef as FunctionReference<\"query\">, {\n elationId,\n });\n}\n\n// ---------------------------------------------------------------------------\n// Physician hooks\n// ---------------------------------------------------------------------------\n\ninterface 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\nconst physiciansGetByElationIdsRef = makeFunctionReference<\n \"query\",\n { ids: number[] },\n Physician[]\n>(\"physicians:getByElationIds\");\n\nconst physiciansGetByElationIdRef = makeFunctionReference<\n \"query\",\n { id: number },\n Physician | null\n>(\"physicians:getByElationId\");\n\n/**\n * Resolve a batch of physicians by their Elation IDs. Returns an array\n * of physicians that exist in Convex; missing ids are silently dropped.\n *\n * Use this to resolve medication `prescribing_physician` / appointment\n * physician ids to display names, avoiding the per-physician HTTP\n * round-trip through Truth's Elation proxy.\n *\n * Pass `undefined` (or an empty array) to skip the query — the hook\n * returns `undefined` until you pass a populated list.\n */\nfunction usePhysiciansByElationIds(ids: number[] | undefined) {\n return useQuery(\n physiciansGetByElationIdsRef as FunctionReference<\"query\">,\n ids && ids.length > 0 ? { ids } : \"skip\",\n );\n}\n\n/**\n * Subscribe to a single physician by their Elation ID.\n */\nfunction usePhysicianByElationId(id: number | undefined) {\n return useQuery(\n physiciansGetByElationIdRef as FunctionReference<\"query\">,\n id !== undefined ? { id } : \"skip\",\n );\n}\n\n// ---------------------------------------------------------------------------\n// Patient medical hooks (medications, problems, allergies, appointments)\n// ---------------------------------------------------------------------------\n\nconst medicationsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getMedicationsByElationPatient\");\n\nconst problemsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getProblemsByElationPatient\");\n\nconst allergiesByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getAllergiesByElationPatient\");\n\nconst appointmentsByPatientRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown[]\n>(\"medicalRecords:getAppointmentsByElationPatient\");\n\ninterface UsePatientMedicalOptions {\n /**\n * Base URL of the Truth API. Required to trigger the background refresh\n * (e.g. `https://app.truth.communication-hub.com`). If omitted, the hook\n * only reads from Convex and does not refresh.\n */\n apiBaseUrl?: string;\n /** API key used for the refresh call. */\n apiKey?: string;\n /**\n * If true, suppress the background refresh. Useful when you know the\n * data was just refreshed by another component on the page.\n */\n skipRefresh?: boolean;\n}\n\n/**\n * Composite hook that returns a patient's medical records — medications,\n * problems, allergies, appointments — from the Convex cache.\n *\n * On mount (and when `elationId` changes) fires a background refresh\n * against Truth's `/api/patients/medical/refresh` endpoint so stale data\n * is pulled in without blocking render. Returns cached data immediately;\n * Convex subscription updates the UI when refresh completes.\n */\nfunction usePatientMedical(\n elationId: number | undefined,\n options?: UsePatientMedicalOptions,\n) {\n const medications = useQuery(\n medicationsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const problems = useQuery(\n problemsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const allergies = useQuery(\n allergiesByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n const appointments = useQuery(\n appointmentsByPatientRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n ) as unknown[] | undefined;\n\n useEffect(() => {\n if (elationId === undefined || options?.skipRefresh) {\n return;\n }\n const apiBaseUrl = options?.apiBaseUrl;\n const apiKey = options?.apiKey;\n if (!apiBaseUrl || !apiKey) {\n return;\n }\n\n const controller = new AbortController();\n void fetch(`${apiBaseUrl}/api/patients/medical/refresh`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": apiKey,\n },\n body: JSON.stringify({ elationId }),\n signal: controller.signal,\n }).catch(() => {\n /* background refresh — failures are non-fatal */\n });\n\n return () => controller.abort();\n }, [elationId, options?.apiBaseUrl, options?.apiKey, options?.skipRefresh]);\n\n return { medications, problems, allergies, appointments };\n}\n\n// ---------------------------------------------------------------------------\n// Patient basic hooks (Elation demographics + Hint memberships/account)\n// ---------------------------------------------------------------------------\n//\n// Replaces the CommHub `getPatientBasicDetails` Hasura Action. Reads\n// from Convex-cached rows (populated by the patients-backfill cron +\n// `/api/patients/basic/refresh` on-demand), falling back to an empty\n// state until the background refresh completes.\n\nconst elationPatientByIdRef = makeFunctionReference<\n \"query\",\n { elationId: number },\n unknown | null\n>(\"elationPatients:getByElationId\");\n\nconst hintPatientByIdRef = makeFunctionReference<\n \"query\",\n { hintId: string },\n unknown | null\n>(\"hintPatients:getByHintId\");\n\nconst pharmacyByNcpdpRef = makeFunctionReference<\n \"query\",\n { ncpdpId: string },\n unknown | null\n>(\"elationPharmacies:getByNcpdpId\");\n\nconst patientPhotoByIdRef = makeFunctionReference<\n \"query\",\n { elationPatientId: number },\n unknown | null\n>(\"elationPatientPhotos:getByElationPatientId\");\n\ninterface UsePatientBasicOptions {\n /** Truth API base URL used for the background refresh. */\n apiBaseUrl?: string;\n /** API key for the refresh call. */\n apiKey?: string;\n /** Suppress the background refresh. */\n skipRefresh?: boolean;\n}\n\ninterface UsePatientBasicResult {\n /**\n * Raw Elation patient payload (matches the shape Elation's\n * `/patients/{id}` returns — `first_name`, `last_name`, `phones`, etc).\n * Returns `undefined` while the cache miss is loading, `null` if the\n * patient isn't in Convex yet (first-open-after-backfill).\n */\n elationPatient: Record<string, unknown> | null | undefined;\n /**\n * Raw Hint patient payload (matches the shape Hint's\n * `/provider/patients/{id}` returns — `memberships`, `account`,\n * `phones`, etc).\n */\n hintPatient: Record<string, unknown> | null | undefined;\n /**\n * The full Convex row for Elation (includes `elationId`, `lastSyncedAt`,\n * `photoS3Key`, `preferredPharmacyNcpdpId`, etc). Use this when you\n * need the structured/typed fields rather than the raw Elation payload.\n */\n elationRow: Record<string, unknown> | null | undefined;\n /**\n * The full Convex row for Hint. Similar relationship to `hintPatient`.\n */\n hintRow: Record<string, unknown> | null | undefined;\n /** True while either cache miss is still pending. */\n loading: boolean;\n}\n\n/**\n * Composite hook returning a patient's basic details — Hint demographics\n * + memberships + account, Elation demographics + clinical metadata —\n * from the Convex cache.\n *\n * On mount (and when inputs change) fires a background refresh against\n * `/api/patients/basic/refresh` so stale rows get pulled fresh without\n * blocking render. Returns cached data immediately; Convex subscription\n * updates the UI when refresh completes.\n */\nfunction usePatientBasic(\n input: { hintId?: string; elationId?: number },\n options?: UsePatientBasicOptions,\n): UsePatientBasicResult {\n const elationRow = useQuery(\n elationPatientByIdRef as FunctionReference<\"query\">,\n input.elationId !== undefined ? { elationId: input.elationId } : \"skip\",\n ) as Record<string, unknown> | null | undefined;\n\n const hintRow = useQuery(\n hintPatientByIdRef as FunctionReference<\"query\">,\n input.hintId !== undefined ? { hintId: input.hintId } : \"skip\",\n ) as Record<string, unknown> | null | undefined;\n\n useEffect(() => {\n if (options?.skipRefresh) return;\n if (!input.hintId && input.elationId === undefined) return;\n const apiBaseUrl = options?.apiBaseUrl;\n const apiKey = options?.apiKey;\n if (!apiBaseUrl || !apiKey) return;\n\n const controller = new AbortController();\n void fetch(`${apiBaseUrl}/api/patients/basic/refresh`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": apiKey,\n },\n body: JSON.stringify({\n hintId: input.hintId,\n elationId: input.elationId,\n }),\n signal: controller.signal,\n }).catch(() => {\n /* background refresh — failures are non-fatal */\n });\n\n return () => controller.abort();\n }, [\n input.hintId,\n input.elationId,\n options?.apiBaseUrl,\n options?.apiKey,\n options?.skipRefresh,\n ]);\n\n // Surface the raw payload under elationPatient/hintPatient so consumers\n // can keep using the exact Elation/Hint field names (first_name,\n // memberships, account.past_due_in_cents) with zero mapping.\n const elationPatient =\n elationRow === undefined\n ? undefined\n : elationRow === null\n ? null\n : ((elationRow.raw as Record<string, unknown>) ?? null);\n const hintPatient =\n hintRow === undefined\n ? undefined\n : hintRow === null\n ? null\n : ((hintRow.raw as Record<string, unknown>) ?? null);\n\n const elationLoading =\n input.elationId !== undefined && elationRow === undefined;\n const hintLoading = input.hintId !== undefined && hintRow === undefined;\n\n return {\n elationPatient,\n hintPatient,\n elationRow,\n hintRow,\n loading: elationLoading || hintLoading,\n };\n}\n\n/**\n * Read a shared pharmacy row by NCPDP id. Backs the pharmacy card in\n * the patient panel (from Elation's preferred_pharmacy reference).\n */\nfunction usePharmacyByNcpdpId(ncpdpId: string | undefined) {\n return useQuery(\n pharmacyByNcpdpRef as FunctionReference<\"query\">,\n ncpdpId ? { ncpdpId } : \"skip\",\n );\n}\n\ninterface UsePatientPhotoOptions {\n apiBaseUrl?: string;\n apiKey?: string;\n skipRefresh?: boolean;\n}\n\n/**\n * Subscribe to a patient's profile photo (s3Key + metadata). The\n * consumer constructs a download URL via the Truth attachments resource\n * (signed S3 URL). Fires a background refresh to pull the latest photo\n * binary from Elation + upload to S3.\n */\nfunction usePatientPhoto(\n elationId: number | undefined,\n options?: UsePatientPhotoOptions,\n) {\n const photo = useQuery(\n patientPhotoByIdRef as FunctionReference<\"query\">,\n elationId !== undefined ? { elationPatientId: elationId } : \"skip\",\n );\n\n useEffect(() => {\n if (options?.skipRefresh) return;\n if (elationId === undefined) return;\n const apiBaseUrl = options?.apiBaseUrl;\n const apiKey = options?.apiKey;\n if (!apiBaseUrl || !apiKey) return;\n\n const controller = new AbortController();\n void fetch(`${apiBaseUrl}/api/patients/photo/refresh`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n \"X-API-Key\": apiKey,\n },\n body: JSON.stringify({ elationId }),\n signal: controller.signal,\n }).catch(() => {\n /* non-fatal */\n });\n\n return () => controller.abort();\n }, [elationId, options?.apiBaseUrl, options?.apiKey, options?.skipRefresh]);\n\n return photo;\n}\n\n// ---------------------------------------------------------------------------\n// Conversation messages (Dialpad calls + SMS merged)\n// ---------------------------------------------------------------------------\n\ninterface ConversationMessage {\n kind: \"call\" | \"sms\";\n id: string;\n providerId: string;\n state: string | null;\n direction: string | null;\n fromNumber: string | null;\n toNumber: string | null;\n voicemailLink: string | null;\n duration: number | null;\n text: string | null;\n mms: boolean;\n mmsUrl: string | null;\n messageStatus: string | null;\n occurredAt: string;\n conversationId: string | null;\n patientId: string | null;\n}\n\nconst messagesByPhonesRef = makeFunctionReference<\n \"query\",\n { phoneA: string; phoneB: string; limit?: number },\n ConversationMessage[]\n>(\"conversationMessages:getByPhones\");\n\nconst messagesByConversationIdRef = makeFunctionReference<\n \"query\",\n { conversationId: string; limit?: number },\n ConversationMessage[]\n>(\"conversationMessages:getByConversationId\");\n\ninterface UseConversationMessagesOptions {\n /** Max items to return (default 200). */\n limit?: number;\n}\n\n/**\n * Subscribe to a conversation's calls + SMS merged chronologically.\n * Pass the patient phone + the provider phone — Truth computes a\n * normalized pair key server-side so formatting differences don't\n * matter.\n *\n * Returns `undefined` while loading, then `ConversationMessage[]`\n * sorted newest-first. Updates live as new webhook events land in\n * Convex via the kinesis consumer.\n */\nfunction useConversationMessages(\n input: { phoneA?: string; phoneB?: string; conversationId?: string },\n options?: UseConversationMessagesOptions,\n): ConversationMessage[] | undefined {\n const hasPair = !!input.phoneA && !!input.phoneB;\n const byPair = useQuery(\n messagesByPhonesRef as FunctionReference<\"query\">,\n hasPair\n ? {\n phoneA: input.phoneA as string,\n phoneB: input.phoneB as string,\n limit: options?.limit,\n }\n : \"skip\",\n ) as ConversationMessage[] | undefined;\n\n const byConvo = useQuery(\n messagesByConversationIdRef as FunctionReference<\"query\">,\n !hasPair && input.conversationId\n ? { conversationId: input.conversationId, limit: options?.limit }\n : \"skip\",\n ) as ConversationMessage[] | undefined;\n\n return hasPair ? byPair : byConvo;\n}\n\nexport {\n usePatients,\n usePatient,\n usePatientByElationId,\n usePatientByHintId,\n useAppointments,\n useAppointment,\n useAppointmentByElationId,\n usePhysiciansByElationIds,\n usePhysicianByElationId,\n usePatientMedical,\n usePatientBasic,\n usePharmacyByNcpdpId,\n usePatientPhoto,\n useConversationMessages,\n};\nexport type { ConversationMessage, UseConversationMessagesOptions };\nexport type {\n UsePatientListOptions,\n UseAppointmentListOptions,\n UsePatientMedicalOptions,\n UsePatientBasicOptions,\n UsePatientBasicResult,\n UsePatientPhotoOptions,\n Physician,\n};\n","/**\n * TruthProvider — Convex React provider pre-configured for Truth.\n *\n * Wraps children in a ConvexProvider connected to the correct\n * Truth Convex deployment for the given environment.\n *\n * @example\n * ```tsx\n * import { TruthProvider } from '@hipnation-truth/sdk/react';\n *\n * function App() {\n * return (\n * <TruthProvider environment=\"sandbox\">\n * <MyApp />\n * </TruthProvider>\n * );\n * }\n * ```\n */\n\n\"use client\";\n\nimport { ConvexProvider, ConvexReactClient } from \"convex/react\";\nimport type { ReactNode } from \"react\";\nimport { createElement, useMemo } from \"react\";\n\n// Mirrors CONVEX_URLS in client.ts. UAT shares prod resources.\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\ninterface TruthProviderProps {\n /** Truth environment — determines which Convex deployment to connect to */\n environment?: string;\n /** Override the Convex URL directly */\n convexUrl?: string;\n children: ReactNode;\n}\n\nfunction TruthProvider({\n environment = \"sandbox\",\n convexUrl,\n children,\n}: TruthProviderProps) {\n const url = convexUrl ?? CONVEX_URLS[environment] ?? CONVEX_URLS.sandbox;\n\n const client = useMemo(() => new ConvexReactClient(url), [url]);\n\n return createElement(ConvexProvider, { client }, children);\n}\n\nexport { TruthProvider };\nexport type { TruthProviderProps };\n","/**\n * React tracking hook — fire-and-forget event tracking from client components.\n *\n * Creates a lightweight Tracker instance scoped to the browser session\n * and exposes a useTrack() hook for emitting events to Truth's Kinesis stream.\n *\n * @example\n * ```tsx\n * import { useTruth } from '@hipnation-truth/sdk/react';\n *\n * function ConversationView({ conversationId }) {\n * const truth = useTruth();\n *\n * useEffect(() => {\n * truth.track('conversation.marked_read.v1', {\n * read_by_actor_id: userId,\n * unread_count_before: 5,\n * unread_count_after: 0,\n * }, { subject: { conversation_id: conversationId } });\n * }, [conversationId]);\n * }\n * ```\n */\n\n\"use client\";\n\nimport type { ReactNode } from \"react\";\nimport { createContext, createElement, useContext, useMemo } from \"react\";\nimport type {\n EventPayloadMap,\n EventType,\n TrackOptions,\n} from \"../tracking/events\";\nimport { Tracker } from \"../tracking/tracker\";\nimport type { ActorContext } from \"../types/config\";\n\n// ---------------------------------------------------------------------------\n// Context\n// ---------------------------------------------------------------------------\n\ninterface TruthTrackingContextValue {\n track: <T extends EventType>(\n eventType: T,\n payload: EventPayloadMap[T],\n options?: TrackOptions,\n ) => void;\n identify: (actorId: string, actorType: ActorContext[\"actorType\"]) => void;\n}\n\nconst TruthTrackingContext = createContext<TruthTrackingContextValue | null>(\n null,\n);\n\n// ---------------------------------------------------------------------------\n// Provider\n// ---------------------------------------------------------------------------\n\ninterface TruthTrackingProviderProps {\n /** Truth environment — determines API URL for event delivery */\n environment?: string;\n /** Event source identifier */\n source?: string;\n /** Source version (git SHA) */\n sourceVersion?: string;\n /** Default tenant ID */\n tenantId?: string;\n /** API key for authentication */\n apiKey?: string;\n children: ReactNode;\n}\n\nfunction TruthTrackingProvider({\n environment = \"sandbox\",\n source = \"communication-hub.frontend\",\n sourceVersion = \"unknown\",\n tenantId = \"hipnation\",\n apiKey = \"\",\n children,\n}: TruthTrackingProviderProps) {\n const value = useMemo<TruthTrackingContextValue>(() => {\n const tracker = new Tracker({\n apiKey,\n environment,\n source,\n sourceVersion,\n tenantId,\n batchSize: 10,\n flushIntervalMs: 5000,\n });\n\n return {\n track: (eventType, payload, options) => {\n tracker.track(eventType, payload, options);\n },\n identify: (actorId, actorType) => {\n tracker.setActor({ actorId, actorType });\n },\n };\n }, [apiKey, environment, source, sourceVersion, tenantId]);\n\n return createElement(TruthTrackingContext.Provider, { value }, children);\n}\n\n// ---------------------------------------------------------------------------\n// Hook\n// ---------------------------------------------------------------------------\n\n/**\n * Access the Truth tracking context. Must be within a TruthTrackingProvider.\n * Returns `{ track, identify }` for emitting events to Kinesis.\n */\nfunction useTruth(): TruthTrackingContextValue {\n const ctx = useContext(TruthTrackingContext);\n if (!ctx) {\n throw new Error(\"useTruth must be used within a TruthTrackingProvider\");\n }\n return ctx;\n}\n\nexport { TruthTrackingProvider, useTruth };\nexport type { TruthTrackingProviderProps, TruthTrackingContextValue };\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAmBA,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAW1B,SAAS,6BAA6B;AAGtC,IAAM,kBAAkB,sBAStB,eAAe;AAEjB,IAAM,iBAAiB,sBAIrB,cAAc;AAEhB,IAAM,yBAAyB,sBAI7B,yBAAyB;AAE3B,IAAM,sBAAsB,sBAI1B,sBAAsB;AAGxB,IAAM,sBAAsB,sBAU1B,mBAAmB;AAErB,IAAM,qBAAqB,sBAIzB,kBAAkB;AAEpB,IAAM,6BAA6B,sBAIjC,6BAA6B;AAgB/B,SAAS,YAAY,SAAiC;AACpD,SAAO,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AAA,MACA;AAAA,MACA;AAAA,MACA,WAAW;AAAA,MACX,iBAAiB;AAAA,IACnB,CAAC;AAED,WAAO;AAAA,MACL,OAAO,CAAC,WAAW,SAAS,YAAY;AACtC,gBAAQ,MAAM,WAAW,SAAS,OAAO;AAAA,MAC3C;AAAA,MACA,UAAU,CAAC,SAAS,cAAc;AAChC,gBAAQ,SAAS,EAAE,SAAS,UAAU,CAAC;AAAA,MACzC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,QAAQ,aAAa,QAAQ,eAAe,QAAQ,CAAC;AAEzD,SAAOC,eAAc,qBAAqB,UAAU,EAAE,MAAM,GAAG,QAAQ;AACzE;AAUA,SAAS,WAAsC;AAC7C,QAAM,MAAM,WAAW,oBAAoB;AAC3C,MAAI,CAAC,KAAK;AACR,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACA,SAAO;AACT;","names":["createElement","useMemo","useMemo","createElement"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hipnation-truth/sdk",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "HIPnation Truth Platform SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",