@hipnation-truth/sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +858 -0
- package/dist/index.d.ts +858 -0
- package/dist/index.js +927 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +882 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +493 -0
- package/dist/react.d.ts +493 -0
- package/dist/react.js +367 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +332 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +53 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,858 @@
|
|
|
1
|
+
import { ConvexHttpClient } from 'convex/browser';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Appointment interfaces for the Truth SDK.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Normalized appointment record from the Truth platform.
|
|
8
|
+
*/
|
|
9
|
+
interface Appointment {
|
|
10
|
+
/** Truth platform appointment ID */
|
|
11
|
+
id: string;
|
|
12
|
+
/** Associated patient ID */
|
|
13
|
+
patientId: string;
|
|
14
|
+
/** Provider/practitioner ID */
|
|
15
|
+
providerId?: string;
|
|
16
|
+
/** Provider/practitioner name */
|
|
17
|
+
providerName?: string;
|
|
18
|
+
/** Appointment start time (ISO 8601) */
|
|
19
|
+
startTime: string;
|
|
20
|
+
/** Appointment end time (ISO 8601) */
|
|
21
|
+
endTime: string;
|
|
22
|
+
/** Appointment status */
|
|
23
|
+
status: string;
|
|
24
|
+
/** Appointment type or reason */
|
|
25
|
+
appointmentType?: string;
|
|
26
|
+
/** Visit reason or chief complaint */
|
|
27
|
+
reason?: string;
|
|
28
|
+
/** Location or facility name */
|
|
29
|
+
location?: string;
|
|
30
|
+
/** Source EHR system (e.g. "elation", "hint") */
|
|
31
|
+
sourceSystem?: string;
|
|
32
|
+
/** ID in the source EHR system */
|
|
33
|
+
sourceId?: string;
|
|
34
|
+
/** Associated organization/tenant ID */
|
|
35
|
+
tenantId: string;
|
|
36
|
+
/** ISO 8601 timestamp of record creation */
|
|
37
|
+
createdAt: string;
|
|
38
|
+
/** ISO 8601 timestamp of last update */
|
|
39
|
+
updatedAt: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Options for listing appointments.
|
|
43
|
+
*/
|
|
44
|
+
interface AppointmentListOptions {
|
|
45
|
+
/** Filter by patient ID */
|
|
46
|
+
patientId?: string;
|
|
47
|
+
/** Filter by start date (ISO 8601 date string) */
|
|
48
|
+
startDate?: string;
|
|
49
|
+
/** Filter by end date (ISO 8601 date string) */
|
|
50
|
+
endDate?: string;
|
|
51
|
+
/** Filter by appointment status */
|
|
52
|
+
status?: string;
|
|
53
|
+
/** Maximum number of results to return */
|
|
54
|
+
limit?: number;
|
|
55
|
+
/** Cursor for pagination */
|
|
56
|
+
cursor?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Configuration interfaces for the Truth SDK.
|
|
61
|
+
*/
|
|
62
|
+
/**
|
|
63
|
+
* Environment options for the Truth platform.
|
|
64
|
+
*/
|
|
65
|
+
declare const ENVIRONMENTS: {
|
|
66
|
+
readonly local: "local";
|
|
67
|
+
readonly staging: "staging";
|
|
68
|
+
readonly uat: "uat";
|
|
69
|
+
readonly production: "production";
|
|
70
|
+
};
|
|
71
|
+
type Environment = (typeof ENVIRONMENTS)[keyof typeof ENVIRONMENTS];
|
|
72
|
+
/**
|
|
73
|
+
* Configuration for initializing a TruthClient.
|
|
74
|
+
*/
|
|
75
|
+
interface TruthClientConfig {
|
|
76
|
+
/** API key for authenticating with the Truth platform (e.g. "hn_live_...") */
|
|
77
|
+
apiKey: string;
|
|
78
|
+
/** Target environment */
|
|
79
|
+
environment: Environment;
|
|
80
|
+
/** Override the default Convex URL for data access */
|
|
81
|
+
convexUrl?: string;
|
|
82
|
+
/** Event source identifier (e.g. "communication-hub.backend") */
|
|
83
|
+
source?: string;
|
|
84
|
+
/** Git SHA or version string for event source versioning */
|
|
85
|
+
sourceVersion?: string;
|
|
86
|
+
/** Default tenant (organization) ID for events */
|
|
87
|
+
tenantId?: string;
|
|
88
|
+
/** Number of events to buffer before flushing (default: 25) */
|
|
89
|
+
batchSize?: number;
|
|
90
|
+
/** Interval in milliseconds between automatic flushes (default: 5000) */
|
|
91
|
+
flushIntervalMs?: number;
|
|
92
|
+
/** Base URL for the Truth API (overrides environment-based default) */
|
|
93
|
+
apiBaseUrl?: string;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Actor context attached to tracked events.
|
|
97
|
+
*/
|
|
98
|
+
interface ActorContext {
|
|
99
|
+
actorId: string;
|
|
100
|
+
actorType: "user" | "system" | "webhook";
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Paginated result wrapper for list operations.
|
|
104
|
+
*/
|
|
105
|
+
interface PaginatedResult<T> {
|
|
106
|
+
data: T[];
|
|
107
|
+
cursor: string | null;
|
|
108
|
+
hasMore: boolean;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* AppointmentResource provides data access to normalized appointment records
|
|
113
|
+
* backed by Convex.
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
declare class AppointmentResource {
|
|
117
|
+
private readonly convex;
|
|
118
|
+
constructor(convexClient: ConvexHttpClient);
|
|
119
|
+
/**
|
|
120
|
+
* Get an appointment by its Truth platform ID.
|
|
121
|
+
*/
|
|
122
|
+
get(id: string): Promise<Appointment | null>;
|
|
123
|
+
/**
|
|
124
|
+
* List appointments with optional filters, pagination, and limit.
|
|
125
|
+
*/
|
|
126
|
+
list(options?: AppointmentListOptions): Promise<PaginatedResult<Appointment>>;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Dialpad resource — typed access to Truth's Dialpad proxy endpoints.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* const sms = await truth.messages.dialpad.sendSms({ from_number, to_number, message });
|
|
135
|
+
* const call = await truth.messages.dialpad.initiateCall(userId, phoneNumber);
|
|
136
|
+
* await truth.messages.dialpad.hangupCall(callId);
|
|
137
|
+
* const url = await truth.messages.dialpad.authenticateVoicemail(voicemailLink);
|
|
138
|
+
* ```
|
|
139
|
+
*/
|
|
140
|
+
interface SendSmsParams {
|
|
141
|
+
from_number: string;
|
|
142
|
+
to_number: string;
|
|
143
|
+
message?: string;
|
|
144
|
+
media?: string;
|
|
145
|
+
}
|
|
146
|
+
interface SendSmsResponse {
|
|
147
|
+
id: string;
|
|
148
|
+
message_status: string;
|
|
149
|
+
[key: string]: unknown;
|
|
150
|
+
}
|
|
151
|
+
interface InitiateCallResponse {
|
|
152
|
+
call_id: number;
|
|
153
|
+
[key: string]: unknown;
|
|
154
|
+
}
|
|
155
|
+
interface CallStatusResponse {
|
|
156
|
+
state: string;
|
|
157
|
+
[key: string]: unknown;
|
|
158
|
+
}
|
|
159
|
+
interface DialpadUser {
|
|
160
|
+
id: number;
|
|
161
|
+
emails: string[];
|
|
162
|
+
first_name?: string;
|
|
163
|
+
last_name?: string;
|
|
164
|
+
[key: string]: unknown;
|
|
165
|
+
}
|
|
166
|
+
interface DialpadNumberInfo {
|
|
167
|
+
user_id?: number;
|
|
168
|
+
type?: string;
|
|
169
|
+
[key: string]: unknown;
|
|
170
|
+
}
|
|
171
|
+
interface VoicemailAuthResponse {
|
|
172
|
+
success: boolean;
|
|
173
|
+
authenticated_url: string | null;
|
|
174
|
+
error?: string;
|
|
175
|
+
}
|
|
176
|
+
declare class DialpadResource {
|
|
177
|
+
private readonly baseUrl;
|
|
178
|
+
constructor(apiBaseUrl: string);
|
|
179
|
+
/**
|
|
180
|
+
* Send an SMS or MMS message via Dialpad.
|
|
181
|
+
*/
|
|
182
|
+
sendSms(params: SendSmsParams): Promise<SendSmsResponse>;
|
|
183
|
+
/**
|
|
184
|
+
* Initiate an outbound call from a Dialpad user to a phone number.
|
|
185
|
+
*/
|
|
186
|
+
initiateCall(userId: number, phoneNumber: string): Promise<InitiateCallResponse>;
|
|
187
|
+
/**
|
|
188
|
+
* Hang up an active call.
|
|
189
|
+
*/
|
|
190
|
+
hangupCall(callId: number): Promise<void>;
|
|
191
|
+
/**
|
|
192
|
+
* Get the status of a call.
|
|
193
|
+
*/
|
|
194
|
+
getCallStatus(callId: number): Promise<CallStatusResponse | null>;
|
|
195
|
+
/**
|
|
196
|
+
* Get a Dialpad user by their user ID.
|
|
197
|
+
*/
|
|
198
|
+
getUser(userId: string | number): Promise<DialpadUser | null>;
|
|
199
|
+
/**
|
|
200
|
+
* Find a Dialpad user by email.
|
|
201
|
+
*/
|
|
202
|
+
getUserByEmail(email: string): Promise<DialpadUser | null>;
|
|
203
|
+
/**
|
|
204
|
+
* Find a Dialpad user by phone number.
|
|
205
|
+
*/
|
|
206
|
+
getUserByPhoneNumber(phoneNumber: string): Promise<DialpadUser | null>;
|
|
207
|
+
/**
|
|
208
|
+
* Get information about a Dialpad phone number.
|
|
209
|
+
*/
|
|
210
|
+
getNumberInfo(phoneNumber: string): Promise<DialpadNumberInfo | null>;
|
|
211
|
+
/**
|
|
212
|
+
* Authenticate a voicemail download URL. Truth appends the Dialpad API key,
|
|
213
|
+
* follows redirects, and returns the clean URL for client-side playback.
|
|
214
|
+
*/
|
|
215
|
+
authenticateVoicemail(voicemailLink: string): Promise<string | null>;
|
|
216
|
+
private get;
|
|
217
|
+
private post;
|
|
218
|
+
private put;
|
|
219
|
+
}
|
|
220
|
+
declare class MessagesResource {
|
|
221
|
+
readonly dialpad: DialpadResource;
|
|
222
|
+
constructor(apiBaseUrl: string);
|
|
223
|
+
}
|
|
224
|
+
declare class DialpadProxyError extends Error {
|
|
225
|
+
readonly method: string;
|
|
226
|
+
readonly path: string;
|
|
227
|
+
readonly status: number;
|
|
228
|
+
constructor(method: string, path: string, status: number);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* EHR proxy resource — typed access to Truth's EHR proxy endpoints.
|
|
233
|
+
*
|
|
234
|
+
* Provides per-provider proxy methods so consumers never construct
|
|
235
|
+
* proxy URLs manually.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* const patient = await truth.ehr.elation.get('/patients/123/');
|
|
240
|
+
* const notes = await truth.ehr.elation.post('/non_visit_notes/', noteData);
|
|
241
|
+
* const hintPatient = await truth.ehr.hint.get('/provider/patients/456');
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
declare class EhrProviderProxy {
|
|
245
|
+
private readonly baseUrl;
|
|
246
|
+
private readonly provider;
|
|
247
|
+
constructor(apiBaseUrl: string, provider: string);
|
|
248
|
+
/**
|
|
249
|
+
* GET request to the EHR proxy.
|
|
250
|
+
* @param path — path relative to the provider root (e.g., "/patients/123/")
|
|
251
|
+
* @param params — optional query parameters
|
|
252
|
+
*/
|
|
253
|
+
get<T = unknown>(path: string, params?: Record<string, string | number | boolean | undefined>): Promise<T>;
|
|
254
|
+
/**
|
|
255
|
+
* POST request to the EHR proxy.
|
|
256
|
+
*/
|
|
257
|
+
post<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
258
|
+
/**
|
|
259
|
+
* PUT request to the EHR proxy.
|
|
260
|
+
*/
|
|
261
|
+
put<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
262
|
+
/**
|
|
263
|
+
* PATCH request to the EHR proxy.
|
|
264
|
+
*/
|
|
265
|
+
patch<T = unknown>(path: string, body?: unknown): Promise<T>;
|
|
266
|
+
/**
|
|
267
|
+
* DELETE request to the EHR proxy.
|
|
268
|
+
*/
|
|
269
|
+
delete<T = unknown>(path: string): Promise<T>;
|
|
270
|
+
}
|
|
271
|
+
declare class EhrResource {
|
|
272
|
+
/** Elation EHR proxy */
|
|
273
|
+
readonly elation: EhrProviderProxy;
|
|
274
|
+
/** Hint Health proxy */
|
|
275
|
+
readonly hint: EhrProviderProxy;
|
|
276
|
+
constructor(apiBaseUrl: string);
|
|
277
|
+
}
|
|
278
|
+
declare class EhrProxyError extends Error {
|
|
279
|
+
readonly provider: string;
|
|
280
|
+
readonly method: string;
|
|
281
|
+
readonly path: string;
|
|
282
|
+
readonly status: number;
|
|
283
|
+
constructor(provider: string, method: string, path: string, status: number);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Patient interfaces for the Truth SDK.
|
|
288
|
+
*/
|
|
289
|
+
/**
|
|
290
|
+
* Normalized patient record from the Truth platform.
|
|
291
|
+
*/
|
|
292
|
+
interface Patient {
|
|
293
|
+
/** Truth platform patient ID */
|
|
294
|
+
id: string;
|
|
295
|
+
/** Elation EHR patient ID (if linked) */
|
|
296
|
+
elationId?: string;
|
|
297
|
+
/** Hint EHR patient ID (if linked) */
|
|
298
|
+
hintId?: string;
|
|
299
|
+
/** Patient first name */
|
|
300
|
+
firstName: string;
|
|
301
|
+
/** Patient last name */
|
|
302
|
+
lastName: string;
|
|
303
|
+
/** Date of birth (ISO 8601 date string, e.g. "1990-01-15") */
|
|
304
|
+
dateOfBirth?: string;
|
|
305
|
+
/** Patient sex */
|
|
306
|
+
sex?: string;
|
|
307
|
+
/** Primary email address */
|
|
308
|
+
email?: string;
|
|
309
|
+
/** Primary phone number */
|
|
310
|
+
phone?: string;
|
|
311
|
+
/** Patient status in the system */
|
|
312
|
+
status: string;
|
|
313
|
+
/** Associated organization/tenant ID */
|
|
314
|
+
tenantId: string;
|
|
315
|
+
/** ISO 8601 timestamp of record creation */
|
|
316
|
+
createdAt: string;
|
|
317
|
+
/** ISO 8601 timestamp of last update */
|
|
318
|
+
updatedAt: string;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Options for listing patients.
|
|
322
|
+
*/
|
|
323
|
+
interface PatientListOptions {
|
|
324
|
+
/** Search patients by name, email, or phone */
|
|
325
|
+
search?: string;
|
|
326
|
+
/** Maximum number of results to return */
|
|
327
|
+
limit?: number;
|
|
328
|
+
/** Cursor for pagination */
|
|
329
|
+
cursor?: string;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* PatientResource provides data access to normalized patient records
|
|
334
|
+
* backed by Convex.
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
declare class PatientResource {
|
|
338
|
+
private readonly convex;
|
|
339
|
+
constructor(convexClient: ConvexHttpClient);
|
|
340
|
+
/**
|
|
341
|
+
* Get a patient by their Truth platform ID.
|
|
342
|
+
*/
|
|
343
|
+
get(id: string): Promise<Patient | null>;
|
|
344
|
+
/**
|
|
345
|
+
* Get a patient by their Elation EHR ID.
|
|
346
|
+
*/
|
|
347
|
+
getByElationId(elationId: string): Promise<Patient | null>;
|
|
348
|
+
/**
|
|
349
|
+
* Get a patient by their Hint EHR ID.
|
|
350
|
+
*/
|
|
351
|
+
getByHintId(hintId: string): Promise<Patient | null>;
|
|
352
|
+
/**
|
|
353
|
+
* List patients with optional search, pagination, and limit.
|
|
354
|
+
*/
|
|
355
|
+
list(options?: PatientListOptions): Promise<PaginatedResult<Patient>>;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Typed event definitions for the Truth Platform event store.
|
|
360
|
+
*
|
|
361
|
+
* All 26 event types from the Communication Hub -> Truth Event Store Contract.
|
|
362
|
+
* Events are grouped by domain and include typed payload interfaces.
|
|
363
|
+
*/
|
|
364
|
+
declare const CONVERSATION_EVENTS: {
|
|
365
|
+
readonly created: "conversation.created.v1";
|
|
366
|
+
readonly messageSent: "conversation.message_sent.v1";
|
|
367
|
+
readonly messageReceived: "conversation.message_received.v1";
|
|
368
|
+
readonly markedRead: "conversation.marked_read.v1";
|
|
369
|
+
readonly attachmentUploaded: "conversation.attachment_uploaded.v1";
|
|
370
|
+
readonly attachmentDownloaded: "conversation.attachment_downloaded.v1";
|
|
371
|
+
};
|
|
372
|
+
declare const CALL_EVENTS: {
|
|
373
|
+
readonly initiated: "call.initiated.v1";
|
|
374
|
+
readonly connected: "call.connected.v1";
|
|
375
|
+
readonly ended: "call.ended.v1";
|
|
376
|
+
readonly missed: "call.missed.v1";
|
|
377
|
+
};
|
|
378
|
+
declare const TASK_EVENTS: {
|
|
379
|
+
readonly created: "task.created.v1";
|
|
380
|
+
readonly assigned: "task.assigned.v1";
|
|
381
|
+
readonly statusChanged: "task.status_changed.v1";
|
|
382
|
+
};
|
|
383
|
+
declare const REMINDER_EVENTS: {
|
|
384
|
+
readonly scheduled: "reminder.scheduled.v1";
|
|
385
|
+
readonly triggered: "reminder.triggered.v1";
|
|
386
|
+
};
|
|
387
|
+
declare const TRANSLATION_EVENTS: {
|
|
388
|
+
readonly requested: "translation.requested.v1";
|
|
389
|
+
readonly completed: "translation.completed.v1";
|
|
390
|
+
};
|
|
391
|
+
declare const NOTIFICATION_EVENTS: {
|
|
392
|
+
readonly sent: "notification.sent.v1";
|
|
393
|
+
readonly delivered: "notification.delivered.v1";
|
|
394
|
+
readonly opened: "notification.opened.v1";
|
|
395
|
+
};
|
|
396
|
+
declare const PROVIDER_EVENTS: {
|
|
397
|
+
readonly syncStarted: "provider.sync_started.v1";
|
|
398
|
+
readonly syncSucceeded: "provider.sync_succeeded.v1";
|
|
399
|
+
readonly syncFailed: "provider.sync_failed.v1";
|
|
400
|
+
};
|
|
401
|
+
declare const AUTH_EVENTS: {
|
|
402
|
+
readonly loginSucceeded: "auth.login_succeeded.v1";
|
|
403
|
+
readonly loginFailed: "auth.login_failed.v1";
|
|
404
|
+
};
|
|
405
|
+
declare const SECURITY_EVENTS: {
|
|
406
|
+
readonly accessDenied: "security.access_denied.v1";
|
|
407
|
+
};
|
|
408
|
+
/**
|
|
409
|
+
* All event type constants grouped by domain.
|
|
410
|
+
*/
|
|
411
|
+
declare const EVENT_TYPES: {
|
|
412
|
+
readonly conversation: {
|
|
413
|
+
readonly created: "conversation.created.v1";
|
|
414
|
+
readonly messageSent: "conversation.message_sent.v1";
|
|
415
|
+
readonly messageReceived: "conversation.message_received.v1";
|
|
416
|
+
readonly markedRead: "conversation.marked_read.v1";
|
|
417
|
+
readonly attachmentUploaded: "conversation.attachment_uploaded.v1";
|
|
418
|
+
readonly attachmentDownloaded: "conversation.attachment_downloaded.v1";
|
|
419
|
+
};
|
|
420
|
+
readonly call: {
|
|
421
|
+
readonly initiated: "call.initiated.v1";
|
|
422
|
+
readonly connected: "call.connected.v1";
|
|
423
|
+
readonly ended: "call.ended.v1";
|
|
424
|
+
readonly missed: "call.missed.v1";
|
|
425
|
+
};
|
|
426
|
+
readonly task: {
|
|
427
|
+
readonly created: "task.created.v1";
|
|
428
|
+
readonly assigned: "task.assigned.v1";
|
|
429
|
+
readonly statusChanged: "task.status_changed.v1";
|
|
430
|
+
};
|
|
431
|
+
readonly reminder: {
|
|
432
|
+
readonly scheduled: "reminder.scheduled.v1";
|
|
433
|
+
readonly triggered: "reminder.triggered.v1";
|
|
434
|
+
};
|
|
435
|
+
readonly translation: {
|
|
436
|
+
readonly requested: "translation.requested.v1";
|
|
437
|
+
readonly completed: "translation.completed.v1";
|
|
438
|
+
};
|
|
439
|
+
readonly notification: {
|
|
440
|
+
readonly sent: "notification.sent.v1";
|
|
441
|
+
readonly delivered: "notification.delivered.v1";
|
|
442
|
+
readonly opened: "notification.opened.v1";
|
|
443
|
+
};
|
|
444
|
+
readonly provider: {
|
|
445
|
+
readonly syncStarted: "provider.sync_started.v1";
|
|
446
|
+
readonly syncSucceeded: "provider.sync_succeeded.v1";
|
|
447
|
+
readonly syncFailed: "provider.sync_failed.v1";
|
|
448
|
+
};
|
|
449
|
+
readonly auth: {
|
|
450
|
+
readonly loginSucceeded: "auth.login_succeeded.v1";
|
|
451
|
+
readonly loginFailed: "auth.login_failed.v1";
|
|
452
|
+
};
|
|
453
|
+
readonly security: {
|
|
454
|
+
readonly accessDenied: "security.access_denied.v1";
|
|
455
|
+
};
|
|
456
|
+
};
|
|
457
|
+
type ConversationEventType = (typeof CONVERSATION_EVENTS)[keyof typeof CONVERSATION_EVENTS];
|
|
458
|
+
type CallEventType = (typeof CALL_EVENTS)[keyof typeof CALL_EVENTS];
|
|
459
|
+
type TaskEventType = (typeof TASK_EVENTS)[keyof typeof TASK_EVENTS];
|
|
460
|
+
type ReminderEventType = (typeof REMINDER_EVENTS)[keyof typeof REMINDER_EVENTS];
|
|
461
|
+
type TranslationEventType = (typeof TRANSLATION_EVENTS)[keyof typeof TRANSLATION_EVENTS];
|
|
462
|
+
type NotificationEventType = (typeof NOTIFICATION_EVENTS)[keyof typeof NOTIFICATION_EVENTS];
|
|
463
|
+
type ProviderEventType = (typeof PROVIDER_EVENTS)[keyof typeof PROVIDER_EVENTS];
|
|
464
|
+
type AuthEventType = (typeof AUTH_EVENTS)[keyof typeof AUTH_EVENTS];
|
|
465
|
+
type SecurityEventType = (typeof SECURITY_EVENTS)[keyof typeof SECURITY_EVENTS];
|
|
466
|
+
/**
|
|
467
|
+
* Union of all 26 registered event type strings.
|
|
468
|
+
*/
|
|
469
|
+
type EventType = ConversationEventType | CallEventType | TaskEventType | ReminderEventType | TranslationEventType | NotificationEventType | ProviderEventType | AuthEventType | SecurityEventType;
|
|
470
|
+
interface ConversationCreatedPayload {
|
|
471
|
+
channel: string;
|
|
472
|
+
origin_system: string;
|
|
473
|
+
participant_count: number;
|
|
474
|
+
}
|
|
475
|
+
interface ConversationMessageSentPayload {
|
|
476
|
+
channel: string;
|
|
477
|
+
direction: string;
|
|
478
|
+
message_chars: number;
|
|
479
|
+
has_attachment: boolean;
|
|
480
|
+
provider_system: string;
|
|
481
|
+
}
|
|
482
|
+
interface ConversationMessageReceivedPayload {
|
|
483
|
+
channel: string;
|
|
484
|
+
direction: string;
|
|
485
|
+
message_chars: number;
|
|
486
|
+
provider_system: string;
|
|
487
|
+
}
|
|
488
|
+
interface ConversationMarkedReadPayload {
|
|
489
|
+
read_by_actor_id: string;
|
|
490
|
+
unread_count_before: number;
|
|
491
|
+
unread_count_after: number;
|
|
492
|
+
}
|
|
493
|
+
interface ConversationAttachmentUploadedPayload {
|
|
494
|
+
attachment_id: string;
|
|
495
|
+
mime_type: string;
|
|
496
|
+
size_bytes: number;
|
|
497
|
+
storage_class: string;
|
|
498
|
+
}
|
|
499
|
+
interface ConversationAttachmentDownloadedPayload {
|
|
500
|
+
attachment_id: string;
|
|
501
|
+
download_actor_type: string;
|
|
502
|
+
access_path: string;
|
|
503
|
+
}
|
|
504
|
+
interface CallInitiatedPayload {
|
|
505
|
+
direction: string;
|
|
506
|
+
provider_system: string;
|
|
507
|
+
from_number_ref: string;
|
|
508
|
+
to_number_ref: string;
|
|
509
|
+
}
|
|
510
|
+
interface CallConnectedPayload {
|
|
511
|
+
provider_system: string;
|
|
512
|
+
ring_duration_ms: number;
|
|
513
|
+
}
|
|
514
|
+
interface CallEndedPayload {
|
|
515
|
+
provider_system: string;
|
|
516
|
+
duration_ms: number;
|
|
517
|
+
end_reason: string;
|
|
518
|
+
disposition: string;
|
|
519
|
+
}
|
|
520
|
+
interface CallMissedPayload {
|
|
521
|
+
provider_system: string;
|
|
522
|
+
miss_reason: string;
|
|
523
|
+
}
|
|
524
|
+
interface TaskCreatedPayload {
|
|
525
|
+
task_id: string;
|
|
526
|
+
created_by: string;
|
|
527
|
+
assigned_to: string;
|
|
528
|
+
priority: string;
|
|
529
|
+
due_at: string;
|
|
530
|
+
}
|
|
531
|
+
interface TaskAssignedPayload {
|
|
532
|
+
task_id: string;
|
|
533
|
+
assigned_to: string;
|
|
534
|
+
assigned_by: string;
|
|
535
|
+
}
|
|
536
|
+
interface TaskStatusChangedPayload {
|
|
537
|
+
task_id: string;
|
|
538
|
+
status_from: string;
|
|
539
|
+
status_to: string;
|
|
540
|
+
changed_by: string;
|
|
541
|
+
}
|
|
542
|
+
interface ReminderScheduledPayload {
|
|
543
|
+
reminder_id: string;
|
|
544
|
+
conversation_id: string;
|
|
545
|
+
scheduled_for: string;
|
|
546
|
+
scheduled_by: string;
|
|
547
|
+
}
|
|
548
|
+
interface ReminderTriggeredPayload {
|
|
549
|
+
reminder_id: string;
|
|
550
|
+
trigger_result: string;
|
|
551
|
+
notification_attempted: boolean;
|
|
552
|
+
}
|
|
553
|
+
interface TranslationRequestedPayload {
|
|
554
|
+
target_language: string;
|
|
555
|
+
source_language: string;
|
|
556
|
+
char_count: number;
|
|
557
|
+
mode: string;
|
|
558
|
+
}
|
|
559
|
+
interface TranslationCompletedPayload {
|
|
560
|
+
target_language: string;
|
|
561
|
+
provider: string;
|
|
562
|
+
latency_ms: number;
|
|
563
|
+
success: boolean;
|
|
564
|
+
error_code?: string;
|
|
565
|
+
}
|
|
566
|
+
interface NotificationSentPayload {
|
|
567
|
+
notification_id: string;
|
|
568
|
+
channel: string;
|
|
569
|
+
platform: string;
|
|
570
|
+
recipient_ref: string;
|
|
571
|
+
success: boolean;
|
|
572
|
+
}
|
|
573
|
+
interface NotificationDeliveredPayload {
|
|
574
|
+
notification_id: string;
|
|
575
|
+
platform: string;
|
|
576
|
+
delivered_at: string;
|
|
577
|
+
}
|
|
578
|
+
interface NotificationOpenedPayload {
|
|
579
|
+
notification_id: string;
|
|
580
|
+
platform: string;
|
|
581
|
+
opened_at: string;
|
|
582
|
+
}
|
|
583
|
+
interface ProviderSyncStartedPayload {
|
|
584
|
+
provider_system: string;
|
|
585
|
+
operation: string;
|
|
586
|
+
scope: string;
|
|
587
|
+
batch_id: string;
|
|
588
|
+
}
|
|
589
|
+
interface ProviderSyncSucceededPayload {
|
|
590
|
+
provider_system: string;
|
|
591
|
+
operation: string;
|
|
592
|
+
batch_id: string;
|
|
593
|
+
records_processed: number;
|
|
594
|
+
duration_ms: number;
|
|
595
|
+
}
|
|
596
|
+
interface ProviderSyncFailedPayload {
|
|
597
|
+
provider_system: string;
|
|
598
|
+
operation: string;
|
|
599
|
+
batch_id: string;
|
|
600
|
+
error_code: string;
|
|
601
|
+
retryable: boolean;
|
|
602
|
+
}
|
|
603
|
+
interface AuthLoginSucceededPayload {
|
|
604
|
+
auth_provider: string;
|
|
605
|
+
platform: string;
|
|
606
|
+
session_ref: string;
|
|
607
|
+
}
|
|
608
|
+
interface AuthLoginFailedPayload {
|
|
609
|
+
auth_provider: string;
|
|
610
|
+
platform: string;
|
|
611
|
+
failure_code: string;
|
|
612
|
+
}
|
|
613
|
+
interface SecurityAccessDeniedPayload {
|
|
614
|
+
resource: string;
|
|
615
|
+
policy: string;
|
|
616
|
+
reason_code: string;
|
|
617
|
+
actor_id: string;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Maps each event type string to its required payload interface.
|
|
621
|
+
*/
|
|
622
|
+
interface EventPayloadMap {
|
|
623
|
+
"conversation.created.v1": ConversationCreatedPayload;
|
|
624
|
+
"conversation.message_sent.v1": ConversationMessageSentPayload;
|
|
625
|
+
"conversation.message_received.v1": ConversationMessageReceivedPayload;
|
|
626
|
+
"conversation.marked_read.v1": ConversationMarkedReadPayload;
|
|
627
|
+
"conversation.attachment_uploaded.v1": ConversationAttachmentUploadedPayload;
|
|
628
|
+
"conversation.attachment_downloaded.v1": ConversationAttachmentDownloadedPayload;
|
|
629
|
+
"call.initiated.v1": CallInitiatedPayload;
|
|
630
|
+
"call.connected.v1": CallConnectedPayload;
|
|
631
|
+
"call.ended.v1": CallEndedPayload;
|
|
632
|
+
"call.missed.v1": CallMissedPayload;
|
|
633
|
+
"task.created.v1": TaskCreatedPayload;
|
|
634
|
+
"task.assigned.v1": TaskAssignedPayload;
|
|
635
|
+
"task.status_changed.v1": TaskStatusChangedPayload;
|
|
636
|
+
"reminder.scheduled.v1": ReminderScheduledPayload;
|
|
637
|
+
"reminder.triggered.v1": ReminderTriggeredPayload;
|
|
638
|
+
"translation.requested.v1": TranslationRequestedPayload;
|
|
639
|
+
"translation.completed.v1": TranslationCompletedPayload;
|
|
640
|
+
"notification.sent.v1": NotificationSentPayload;
|
|
641
|
+
"notification.delivered.v1": NotificationDeliveredPayload;
|
|
642
|
+
"notification.opened.v1": NotificationOpenedPayload;
|
|
643
|
+
"provider.sync_started.v1": ProviderSyncStartedPayload;
|
|
644
|
+
"provider.sync_succeeded.v1": ProviderSyncSucceededPayload;
|
|
645
|
+
"provider.sync_failed.v1": ProviderSyncFailedPayload;
|
|
646
|
+
"auth.login_succeeded.v1": AuthLoginSucceededPayload;
|
|
647
|
+
"auth.login_failed.v1": AuthLoginFailedPayload;
|
|
648
|
+
"security.access_denied.v1": SecurityAccessDeniedPayload;
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Subject references for the event. Uses tokenized references only -- no PHI.
|
|
652
|
+
*/
|
|
653
|
+
interface EventSubject {
|
|
654
|
+
patient_ref?: string;
|
|
655
|
+
conversation_id?: string;
|
|
656
|
+
task_id?: string;
|
|
657
|
+
call_id?: string;
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Actor who triggered the event.
|
|
661
|
+
*/
|
|
662
|
+
interface EventActor {
|
|
663
|
+
actor_id: string;
|
|
664
|
+
actor_type: "user" | "system" | "webhook";
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Compliance metadata for the event.
|
|
668
|
+
*/
|
|
669
|
+
interface EventCompliance {
|
|
670
|
+
pii_level: "none" | "limited" | "full";
|
|
671
|
+
contains_phi: boolean;
|
|
672
|
+
consent_context: string;
|
|
673
|
+
retention_class: string;
|
|
674
|
+
}
|
|
675
|
+
/**
|
|
676
|
+
* Canonical event envelope. Every tracked event is wrapped in this structure
|
|
677
|
+
* before being sent to the Truth API.
|
|
678
|
+
*/
|
|
679
|
+
interface EventEnvelope {
|
|
680
|
+
event_id: string;
|
|
681
|
+
event_type: string;
|
|
682
|
+
schema_version: number;
|
|
683
|
+
occurred_at: string;
|
|
684
|
+
received_at: string;
|
|
685
|
+
source: string;
|
|
686
|
+
source_version: string;
|
|
687
|
+
tenant_id: string;
|
|
688
|
+
actor?: EventActor;
|
|
689
|
+
subject?: EventSubject;
|
|
690
|
+
compliance?: EventCompliance;
|
|
691
|
+
payload: Record<string, unknown>;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Optional overrides when calling truth.track().
|
|
695
|
+
*/
|
|
696
|
+
interface TrackOptions {
|
|
697
|
+
/** Override the default actor for this event */
|
|
698
|
+
actor?: EventActor;
|
|
699
|
+
/** Subject references for this event */
|
|
700
|
+
subject?: EventSubject;
|
|
701
|
+
/** Compliance metadata for this event */
|
|
702
|
+
compliance?: EventCompliance;
|
|
703
|
+
/** Override the default tenant ID for this event */
|
|
704
|
+
tenantId?: string;
|
|
705
|
+
/** Override the occurred_at timestamp (ISO 8601) */
|
|
706
|
+
occurredAt?: string;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
/**
|
|
710
|
+
* TruthClient -- main entry point for the @hipnation-truth/sdk package.
|
|
711
|
+
*
|
|
712
|
+
* Provides:
|
|
713
|
+
* - `.patients` Resource-based patient data access (Convex-backed)
|
|
714
|
+
* - `.appointments` Resource-based appointment data access (Convex-backed)
|
|
715
|
+
* - `.ehr` EHR proxy access (Elation, Hint)
|
|
716
|
+
* - `.messages` Messaging proxy access (Dialpad)
|
|
717
|
+
* - `.track()` Fire-and-forget event tracking (batched HTTP -> Truth API)
|
|
718
|
+
* - `.identify()` Set default actor context for subsequent events
|
|
719
|
+
* - `.flush()` Force flush of buffered events (for graceful shutdown)
|
|
720
|
+
*/
|
|
721
|
+
|
|
722
|
+
declare class TruthClient {
|
|
723
|
+
/** Patient data resource (Convex-backed) */
|
|
724
|
+
readonly patients: PatientResource;
|
|
725
|
+
/** Appointment data resource (Convex-backed) */
|
|
726
|
+
readonly appointments: AppointmentResource;
|
|
727
|
+
/** EHR proxy — typed access to Elation and Hint APIs through Truth */
|
|
728
|
+
readonly ehr: EhrResource;
|
|
729
|
+
/** Messaging proxy — typed access to Dialpad APIs through Truth */
|
|
730
|
+
readonly messages: MessagesResource;
|
|
731
|
+
private readonly convex;
|
|
732
|
+
private readonly tracker;
|
|
733
|
+
constructor(config: TruthClientConfig);
|
|
734
|
+
/**
|
|
735
|
+
* The resolved Truth API base URL for this environment.
|
|
736
|
+
* Use this when making HTTP calls to Truth's proxy endpoints
|
|
737
|
+
* (e.g., EHR proxy, messages proxy).
|
|
738
|
+
*
|
|
739
|
+
* @example
|
|
740
|
+
* ```ts
|
|
741
|
+
* const url = `${truth.apiBaseUrl}/api/ehr/elation/patients/123`;
|
|
742
|
+
* ```
|
|
743
|
+
*/
|
|
744
|
+
get apiBaseUrl(): string;
|
|
745
|
+
/**
|
|
746
|
+
* Track an event. Fire-and-forget -- the event is buffered internally
|
|
747
|
+
* and flushed in batches to the Truth API.
|
|
748
|
+
*
|
|
749
|
+
* @example
|
|
750
|
+
* ```ts
|
|
751
|
+
* truth.track('conversation.message_sent.v1', {
|
|
752
|
+
* channel: 'sms',
|
|
753
|
+
* direction: 'outbound',
|
|
754
|
+
* message_chars: 140,
|
|
755
|
+
* has_attachment: false,
|
|
756
|
+
* provider_system: 'dialpad',
|
|
757
|
+
* });
|
|
758
|
+
* ```
|
|
759
|
+
*/
|
|
760
|
+
track<T extends EventType>(eventType: T, payload: EventPayloadMap[T], options?: TrackOptions): void;
|
|
761
|
+
/**
|
|
762
|
+
* Set the default actor context for all subsequent tracked events.
|
|
763
|
+
* Can be overridden per-event via TrackOptions.
|
|
764
|
+
*
|
|
765
|
+
* @example
|
|
766
|
+
* ```ts
|
|
767
|
+
* truth.identify('user_123', 'user');
|
|
768
|
+
* ```
|
|
769
|
+
*/
|
|
770
|
+
identify(actorId: string, actorType: ActorContext["actorType"]): void;
|
|
771
|
+
/**
|
|
772
|
+
* Flush all buffered events immediately. Returns a Promise that resolves
|
|
773
|
+
* when the flush completes. Use this for graceful shutdown.
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
* ```ts
|
|
777
|
+
* process.on('SIGTERM', async () => {
|
|
778
|
+
* await truth.flush();
|
|
779
|
+
* process.exit(0);
|
|
780
|
+
* });
|
|
781
|
+
* ```
|
|
782
|
+
*/
|
|
783
|
+
flush(): Promise<void>;
|
|
784
|
+
/**
|
|
785
|
+
* Gracefully shut down the client. Flushes all pending events and
|
|
786
|
+
* releases resources.
|
|
787
|
+
*/
|
|
788
|
+
destroy(): Promise<void>;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Event tracker with batching, retry, and flush support.
|
|
793
|
+
*
|
|
794
|
+
* Buffers events in an internal queue and flushes them to the Truth API
|
|
795
|
+
* endpoint. Flushes occur when the buffer reaches `batchSize` or every
|
|
796
|
+
* `flushIntervalMs` milliseconds, whichever comes first.
|
|
797
|
+
*/
|
|
798
|
+
|
|
799
|
+
/**
|
|
800
|
+
* Generates a UUID v7 string. Uses crypto.randomUUID where available,
|
|
801
|
+
* falling back to a timestamp + random bytes implementation.
|
|
802
|
+
*
|
|
803
|
+
* UUID v7 layout (RFC 9562):
|
|
804
|
+
* 48 bits - unix timestamp (ms)
|
|
805
|
+
* 4 bits - version (0b0111)
|
|
806
|
+
* 12 bits - random
|
|
807
|
+
* 2 bits - variant (0b10)
|
|
808
|
+
* 62 bits - random
|
|
809
|
+
*/
|
|
810
|
+
declare function generateUuidV7(): string;
|
|
811
|
+
interface TrackerConfig {
|
|
812
|
+
apiKey: string;
|
|
813
|
+
environment: string;
|
|
814
|
+
source: string;
|
|
815
|
+
sourceVersion: string;
|
|
816
|
+
tenantId: string;
|
|
817
|
+
batchSize: number;
|
|
818
|
+
flushIntervalMs: number;
|
|
819
|
+
apiBaseUrl?: string;
|
|
820
|
+
}
|
|
821
|
+
declare class Tracker {
|
|
822
|
+
private readonly config;
|
|
823
|
+
readonly apiUrl: string;
|
|
824
|
+
private queue;
|
|
825
|
+
private flushTimer;
|
|
826
|
+
private defaultActor;
|
|
827
|
+
private isFlushing;
|
|
828
|
+
private isShutdown;
|
|
829
|
+
constructor(config: TrackerConfig);
|
|
830
|
+
/**
|
|
831
|
+
* Set the default actor context for subsequent events.
|
|
832
|
+
*/
|
|
833
|
+
setActor(actor: ActorContext): void;
|
|
834
|
+
/**
|
|
835
|
+
* Enqueue a typed event for delivery. This is fire-and-forget from
|
|
836
|
+
* the caller's perspective -- events are buffered and flushed in batches.
|
|
837
|
+
*/
|
|
838
|
+
track<T extends EventType>(eventType: T, payload: EventPayloadMap[T], options?: TrackOptions): void;
|
|
839
|
+
/**
|
|
840
|
+
* Force an immediate flush of all buffered events.
|
|
841
|
+
* Returns a promise that resolves when the flush completes.
|
|
842
|
+
*/
|
|
843
|
+
flush(): Promise<void>;
|
|
844
|
+
/**
|
|
845
|
+
* Gracefully shut down the tracker. Flushes remaining events and
|
|
846
|
+
* clears the flush interval.
|
|
847
|
+
*/
|
|
848
|
+
shutdown(): Promise<void>;
|
|
849
|
+
/**
|
|
850
|
+
* Send a batch of events to the Truth API with exponential backoff retry.
|
|
851
|
+
*/
|
|
852
|
+
private sendBatch;
|
|
853
|
+
private startFlushInterval;
|
|
854
|
+
private stopFlushInterval;
|
|
855
|
+
private registerShutdownHooks;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
export { AUTH_EVENTS, type ActorContext, type Appointment, type AppointmentListOptions, AppointmentResource, type AuthEventType, type AuthLoginFailedPayload, type AuthLoginSucceededPayload, CALL_EVENTS, CONVERSATION_EVENTS, type CallConnectedPayload, type CallEndedPayload, type CallEventType, type CallInitiatedPayload, type CallMissedPayload, type CallStatusResponse, type ConversationAttachmentDownloadedPayload, type ConversationAttachmentUploadedPayload, type ConversationCreatedPayload, type ConversationEventType, type ConversationMarkedReadPayload, type ConversationMessageReceivedPayload, type ConversationMessageSentPayload, type DialpadNumberInfo, DialpadProxyError, DialpadResource, type DialpadUser, ENVIRONMENTS, EVENT_TYPES, EhrProviderProxy, EhrProxyError, EhrResource, type Environment, type EventActor, type EventCompliance, type EventEnvelope, type EventPayloadMap, type EventSubject, type EventType, type InitiateCallResponse, MessagesResource, NOTIFICATION_EVENTS, type NotificationDeliveredPayload, type NotificationEventType, type NotificationOpenedPayload, type NotificationSentPayload, PROVIDER_EVENTS, type PaginatedResult, type Patient, type PatientListOptions, PatientResource, type ProviderEventType, type ProviderSyncFailedPayload, type ProviderSyncStartedPayload, type ProviderSyncSucceededPayload, REMINDER_EVENTS, type ReminderEventType, type ReminderScheduledPayload, type ReminderTriggeredPayload, SECURITY_EVENTS, type SecurityAccessDeniedPayload, type SecurityEventType, type SendSmsParams, type SendSmsResponse, TASK_EVENTS, TRANSLATION_EVENTS, type TaskAssignedPayload, type TaskCreatedPayload, type TaskEventType, type TaskStatusChangedPayload, type TrackOptions, Tracker, type TranslationCompletedPayload, type TranslationEventType, type TranslationRequestedPayload, TruthClient, type TruthClientConfig, type VoicemailAuthResponse, generateUuidV7 };
|