@hipnation-truth/sdk 0.26.0 → 0.26.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.d.ts CHANGED
@@ -1383,8 +1383,9 @@ interface Attachment {
1383
1383
  declare class AttachmentsResource {
1384
1384
  private readonly baseUrl;
1385
1385
  private readonly apiKey;
1386
+ private readonly auth;
1386
1387
  private readonly convex;
1387
- constructor(apiBaseUrl: string, apiKey: string, convexClient: ConvexHttpClient);
1388
+ constructor(apiBaseUrl: string, apiKey: string, convexClient: ConvexHttpClient, getAuthToken?: AuthTokenFetcher);
1388
1389
  private post;
1389
1390
  createUploadUrl(input: CreateUploadUrlInput): Promise<CreateUploadUrlResult>;
1390
1391
  getDownloadUrl(s3Key: string, expiresIn?: number): Promise<GetDownloadUrlResult>;
@@ -1601,6 +1602,7 @@ declare class ConversationsResource {
1601
1602
  * const url = await truth.messages.dialpad.authenticateVoicemail(voicemailLink);
1602
1603
  * ```
1603
1604
  */
1605
+
1604
1606
  interface SendSmsParams {
1605
1607
  from_number: string;
1606
1608
  to_number: string;
@@ -1635,7 +1637,8 @@ interface DialpadNumberInfo {
1635
1637
  declare class DialpadResource {
1636
1638
  private readonly baseUrl;
1637
1639
  private readonly apiKey;
1638
- constructor(apiBaseUrl: string, apiKey: string);
1640
+ private readonly auth;
1641
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
1639
1642
  /**
1640
1643
  * Send an SMS or MMS message via Dialpad.
1641
1644
  */
@@ -1700,7 +1703,8 @@ declare class MessagesResource {
1700
1703
  readonly dialpad: DialpadResource;
1701
1704
  private readonly baseUrl;
1702
1705
  private readonly apiKey;
1703
- constructor(apiBaseUrl: string, apiKey: string);
1706
+ private readonly auth;
1707
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
1704
1708
  /**
1705
1709
  * Get an authenticated URL for a Dialpad voicemail recording.
1706
1710
  *
@@ -1783,6 +1787,7 @@ declare class EhrResource {
1783
1787
  * OAuth token and the HTTP call so applications can drop Elation
1784
1788
  * credentials from their own config.
1785
1789
  */
1790
+
1786
1791
  interface NonVisitNoteBullet {
1787
1792
  text: string;
1788
1793
  category?: string;
@@ -1827,7 +1832,8 @@ interface PushConversationToElationResult {
1827
1832
  declare class NotesResource {
1828
1833
  private readonly baseUrl;
1829
1834
  private readonly apiKey;
1830
- constructor(apiBaseUrl: string, apiKey: string);
1835
+ private readonly auth;
1836
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
1831
1837
  /** 30s upstream timeout — Elation API has occasional slow hops; we
1832
1838
  * don't want a pending mutation to hold the UI thread indefinitely. */
1833
1839
  private static readonly REQUEST_TIMEOUT_MS;
@@ -1857,6 +1863,7 @@ declare class NotesResource {
1857
1863
  * Client-side React usage lives in `@hipnation-truth/sdk/react` via
1858
1864
  * the `useNotifications` hook which mirrors `expo-notifications`.
1859
1865
  */
1866
+
1860
1867
  type NotificationPlatform = "ios" | "android" | "web";
1861
1868
  interface RegisterDeviceInput {
1862
1869
  userId: string;
@@ -1967,7 +1974,8 @@ interface PushEventPayload {
1967
1974
  declare class NotificationsResource {
1968
1975
  private readonly baseUrl;
1969
1976
  private readonly apiKey;
1970
- constructor(apiBaseUrl: string, apiKey: string);
1977
+ private readonly auth;
1978
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
1971
1979
  private post;
1972
1980
  private get;
1973
1981
  private delete;
@@ -2025,6 +2033,7 @@ declare class NotificationsResource {
2025
2033
  * X-API-Key. Replaces CommHub's getPatientDetails / getPatientBasicDetails
2026
2034
  * / getPatientMedicalDetails actions.
2027
2035
  */
2036
+
2028
2037
  interface PatientDetailsInput {
2029
2038
  hintId?: string;
2030
2039
  elationId?: string;
@@ -2047,7 +2056,8 @@ interface PatientMedicalDetailsResult {
2047
2056
  declare class PatientDetailsResource {
2048
2057
  private readonly baseUrl;
2049
2058
  private readonly apiKey;
2050
- constructor(apiBaseUrl: string, apiKey: string);
2059
+ private readonly auth;
2060
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
2051
2061
  private post;
2052
2062
  get(input: PatientDetailsInput): Promise<PatientDetailsResult>;
2053
2063
  getBasic(input: PatientDetailsInput): Promise<PatientBasicDetailsResult>;
@@ -2297,7 +2307,8 @@ interface TranslateBatchInput {
2297
2307
  declare class TranslationResource {
2298
2308
  private readonly baseUrl;
2299
2309
  private readonly apiKey;
2300
- constructor(apiBaseUrl: string, apiKey: string);
2310
+ private readonly auth;
2311
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
2301
2312
  private post;
2302
2313
  translate(input: TranslateTextInput): Promise<TranslationResult>;
2303
2314
  translateBatch(input: TranslateBatchInput): Promise<TranslationResult[]>;
@@ -2669,12 +2680,21 @@ declare class TruthClient {
2669
2680
  readonly userSettings: UserSettingsResource;
2670
2681
  private readonly convex;
2671
2682
  private readonly tracker;
2683
+ private readonly _getAuthToken?;
2672
2684
  private _vapidPublicKey;
2673
2685
  private _webPushReady;
2674
2686
  private readonly _serviceWorkerPath;
2675
2687
  constructor(config: TruthClientConfig);
2676
2688
  get vapidPublicKey(): string | null;
2677
2689
  get webPushReady(): Promise<void> | null;
2690
+ /**
2691
+ * When a Clerk token fetcher is configured (publishable-key clients),
2692
+ * the VAPID endpoint is auth-gated — calling it before the session has
2693
+ * hydrated 401s and strands web-push in the "no key" path. Wait
2694
+ * (briefly, bounded) for a token to become available first. No fetcher
2695
+ * → resolve immediately (secret-key path is unaffected).
2696
+ */
2697
+ private waitForAuthToken;
2678
2698
  private initWebPush;
2679
2699
  /**
2680
2700
  * The resolved Truth API base URL for this environment.
package/dist/react.js CHANGED
@@ -471,6 +471,31 @@ var AppointmentResource = class {
471
471
  }
472
472
  };
473
473
 
474
+ // src/resources/rest-auth.ts
475
+ function buildAuthHeaders(auth, options) {
476
+ return __async(this, null, function* () {
477
+ const headers = {
478
+ "X-API-Key": auth.apiKey
479
+ };
480
+ if ((options == null ? void 0 : options.accept) !== false) {
481
+ headers.Accept = "application/json";
482
+ }
483
+ if (options == null ? void 0 : options.json) {
484
+ headers["Content-Type"] = "application/json";
485
+ }
486
+ if (auth.getAuthToken) {
487
+ try {
488
+ const token = yield auth.getAuthToken();
489
+ if (token) {
490
+ headers.Authorization = `Bearer ${token}`;
491
+ }
492
+ } catch (e) {
493
+ }
494
+ }
495
+ return headers;
496
+ });
497
+ }
498
+
474
499
  // src/resources/attachments.ts
475
500
  var AttachmentsError = class extends Error {
476
501
  constructor(operation, status, message) {
@@ -480,20 +505,17 @@ var AttachmentsError = class extends Error {
480
505
  }
481
506
  };
482
507
  var AttachmentsResource = class {
483
- constructor(apiBaseUrl, apiKey, convexClient) {
508
+ constructor(apiBaseUrl, apiKey, convexClient, getAuthToken) {
484
509
  this.baseUrl = apiBaseUrl;
485
510
  this.apiKey = apiKey;
511
+ this.auth = { apiKey, getAuthToken };
486
512
  this.convex = convexClient;
487
513
  }
488
514
  post(path, body) {
489
515
  return __async(this, null, function* () {
490
516
  const res = yield fetch(`${this.baseUrl}/api${path}`, {
491
517
  method: "POST",
492
- headers: {
493
- "Content-Type": "application/json",
494
- Accept: "application/json",
495
- "X-API-Key": this.apiKey
496
- },
518
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
497
519
  body: JSON.stringify(body)
498
520
  });
499
521
  if (!res.ok) {
@@ -624,31 +646,6 @@ var AttachmentsResource = class {
624
646
  }
625
647
  };
626
648
 
627
- // src/resources/rest-auth.ts
628
- function buildAuthHeaders(auth, options) {
629
- return __async(this, null, function* () {
630
- const headers = {
631
- "X-API-Key": auth.apiKey
632
- };
633
- if ((options == null ? void 0 : options.accept) !== false) {
634
- headers.Accept = "application/json";
635
- }
636
- if (options == null ? void 0 : options.json) {
637
- headers["Content-Type"] = "application/json";
638
- }
639
- if (auth.getAuthToken) {
640
- try {
641
- const token = yield auth.getAuthToken();
642
- if (token) {
643
- headers.Authorization = `Bearer ${token}`;
644
- }
645
- } catch (e) {
646
- }
647
- }
648
- return headers;
649
- });
650
- }
651
-
652
649
  // src/resources/conversations.ts
653
650
  var ConversationsError = class extends Error {
654
651
  constructor(operation, status, message) {
@@ -918,9 +915,10 @@ var ConversationsResource = _ConversationsResource;
918
915
 
919
916
  // src/resources/dialpad.ts
920
917
  var DialpadResource = class {
921
- constructor(apiBaseUrl, apiKey) {
918
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
922
919
  this.baseUrl = apiBaseUrl;
923
920
  this.apiKey = apiKey;
921
+ this.auth = { apiKey, getAuthToken };
924
922
  }
925
923
  /**
926
924
  * Send an SMS or MMS message via Dialpad.
@@ -1061,10 +1059,7 @@ var DialpadResource = class {
1061
1059
  const url = `${this.baseUrl}/api/messages/dialpad/voicemail/authenticate`;
1062
1060
  const response = yield fetch(url, {
1063
1061
  method: "POST",
1064
- headers: {
1065
- "Content-Type": "application/json",
1066
- "X-API-Key": this.apiKey
1067
- },
1062
+ headers: yield buildAuthHeaders(this.auth, { json: true, accept: false }),
1068
1063
  body: JSON.stringify({ voicemail_link: voicemailLink })
1069
1064
  });
1070
1065
  const result = yield response.json();
@@ -1089,10 +1084,7 @@ var DialpadResource = class {
1089
1084
  }
1090
1085
  const response = yield fetch(url.toString(), {
1091
1086
  method: "GET",
1092
- headers: {
1093
- Accept: "application/json",
1094
- "X-API-Key": this.apiKey
1095
- }
1087
+ headers: yield buildAuthHeaders(this.auth)
1096
1088
  });
1097
1089
  if (!response.ok) {
1098
1090
  throw new DialpadProxyError("GET", path, response.status);
@@ -1105,11 +1097,7 @@ var DialpadResource = class {
1105
1097
  const url = `${this.baseUrl}/api/messages/dialpad${path}`;
1106
1098
  const response = yield fetch(url, {
1107
1099
  method: "POST",
1108
- headers: {
1109
- "Content-Type": "application/json",
1110
- Accept: "application/json",
1111
- "X-API-Key": this.apiKey
1112
- },
1100
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1113
1101
  body: body !== void 0 ? JSON.stringify(body) : void 0
1114
1102
  });
1115
1103
  if (!response.ok) {
@@ -1124,11 +1112,7 @@ var DialpadResource = class {
1124
1112
  const url = `${this.baseUrl}/api/messages/dialpad${path}`;
1125
1113
  const response = yield fetch(url, {
1126
1114
  method: "PUT",
1127
- headers: {
1128
- "Content-Type": "application/json",
1129
- Accept: "application/json",
1130
- "X-API-Key": this.apiKey
1131
- },
1115
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1132
1116
  body: body !== void 0 ? JSON.stringify(body) : void 0
1133
1117
  });
1134
1118
  if (!response.ok) {
@@ -1142,10 +1126,11 @@ var DialpadResource = class {
1142
1126
  }
1143
1127
  };
1144
1128
  var MessagesResource = class {
1145
- constructor(apiBaseUrl, apiKey) {
1146
- this.dialpad = new DialpadResource(apiBaseUrl, apiKey);
1129
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1130
+ this.dialpad = new DialpadResource(apiBaseUrl, apiKey, getAuthToken);
1147
1131
  this.baseUrl = apiBaseUrl;
1148
1132
  this.apiKey = apiKey;
1133
+ this.auth = { apiKey, getAuthToken };
1149
1134
  }
1150
1135
  /**
1151
1136
  * Get an authenticated URL for a Dialpad voicemail recording.
@@ -1164,11 +1149,7 @@ var MessagesResource = class {
1164
1149
  return __async(this, null, function* () {
1165
1150
  const res = yield fetch(`${this.baseUrl}/api/conversations/voicemail/url`, {
1166
1151
  method: "POST",
1167
- headers: {
1168
- "Content-Type": "application/json",
1169
- Accept: "application/json",
1170
- "X-API-Key": this.apiKey
1171
- },
1152
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1172
1153
  body: JSON.stringify({ voicemailLink })
1173
1154
  });
1174
1155
  if (!res.ok) {
@@ -1192,11 +1173,7 @@ var MessagesResource = class {
1192
1173
  return __async(this, null, function* () {
1193
1174
  const res = yield fetch(`${this.baseUrl}/api/conversations/calls/end`, {
1194
1175
  method: "POST",
1195
- headers: {
1196
- "Content-Type": "application/json",
1197
- Accept: "application/json",
1198
- "X-API-Key": this.apiKey
1199
- },
1176
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1200
1177
  body: JSON.stringify({ callId })
1201
1178
  });
1202
1179
  if (!res.ok) {
@@ -1317,9 +1294,10 @@ var NotesError = class extends Error {
1317
1294
  }
1318
1295
  };
1319
1296
  var _NotesResource = class _NotesResource {
1320
- constructor(apiBaseUrl, apiKey) {
1297
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1321
1298
  this.baseUrl = apiBaseUrl;
1322
1299
  this.apiKey = apiKey;
1300
+ this.auth = { apiKey, getAuthToken };
1323
1301
  }
1324
1302
  post(path, body) {
1325
1303
  return __async(this, null, function* () {
@@ -1332,11 +1310,7 @@ var _NotesResource = class _NotesResource {
1332
1310
  try {
1333
1311
  res = yield fetch(`${this.baseUrl}/api${path}`, {
1334
1312
  method: "POST",
1335
- headers: {
1336
- "Content-Type": "application/json",
1337
- Accept: "application/json",
1338
- "X-API-Key": this.apiKey
1339
- },
1313
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1340
1314
  body: JSON.stringify(body),
1341
1315
  signal: controller.signal
1342
1316
  });
@@ -1397,19 +1371,16 @@ var NotificationsError = class extends Error {
1397
1371
  }
1398
1372
  };
1399
1373
  var NotificationsResource = class {
1400
- constructor(apiBaseUrl, apiKey) {
1374
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1401
1375
  this.baseUrl = apiBaseUrl;
1402
1376
  this.apiKey = apiKey;
1377
+ this.auth = { apiKey, getAuthToken };
1403
1378
  }
1404
1379
  post(path, body) {
1405
1380
  return __async(this, null, function* () {
1406
1381
  const res = yield fetch(`${this.baseUrl}/api${path}`, {
1407
1382
  method: "POST",
1408
- headers: {
1409
- "Content-Type": "application/json",
1410
- Accept: "application/json",
1411
- "X-API-Key": this.apiKey
1412
- },
1383
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1413
1384
  body: JSON.stringify(body)
1414
1385
  });
1415
1386
  if (!res.ok) {
@@ -1427,10 +1398,7 @@ var NotificationsResource = class {
1427
1398
  }
1428
1399
  const res = yield fetch(url.toString(), {
1429
1400
  method: "GET",
1430
- headers: {
1431
- Accept: "application/json",
1432
- "X-API-Key": this.apiKey
1433
- }
1401
+ headers: yield buildAuthHeaders(this.auth)
1434
1402
  });
1435
1403
  if (!res.ok) {
1436
1404
  const text = yield res.text().catch(() => "");
@@ -1443,10 +1411,7 @@ var NotificationsResource = class {
1443
1411
  return __async(this, null, function* () {
1444
1412
  const res = yield fetch(`${this.baseUrl}/api${path}`, {
1445
1413
  method: "DELETE",
1446
- headers: {
1447
- Accept: "application/json",
1448
- "X-API-Key": this.apiKey
1449
- }
1414
+ headers: yield buildAuthHeaders(this.auth)
1450
1415
  });
1451
1416
  if (!res.ok) {
1452
1417
  const text = yield res.text().catch(() => "");
@@ -1579,19 +1544,16 @@ var PatientDetailsError = class extends Error {
1579
1544
  }
1580
1545
  };
1581
1546
  var PatientDetailsResource = class {
1582
- constructor(apiBaseUrl, apiKey) {
1547
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1583
1548
  this.baseUrl = apiBaseUrl;
1584
1549
  this.apiKey = apiKey;
1550
+ this.auth = { apiKey, getAuthToken };
1585
1551
  }
1586
1552
  post(path, body) {
1587
1553
  return __async(this, null, function* () {
1588
1554
  const res = yield fetch(`${this.baseUrl}/api${path}`, {
1589
1555
  method: "POST",
1590
- headers: {
1591
- "Content-Type": "application/json",
1592
- Accept: "application/json",
1593
- "X-API-Key": this.apiKey
1594
- },
1556
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1595
1557
  body: JSON.stringify(body)
1596
1558
  });
1597
1559
  if (!res.ok) {
@@ -1913,20 +1875,17 @@ var TranslationError = class extends Error {
1913
1875
  }
1914
1876
  };
1915
1877
  var TranslationResource = class {
1916
- constructor(apiBaseUrl, apiKey) {
1878
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1917
1879
  this.baseUrl = apiBaseUrl;
1918
1880
  this.apiKey = apiKey;
1881
+ this.auth = { apiKey, getAuthToken };
1919
1882
  }
1920
1883
  post(path, body) {
1921
1884
  return __async(this, null, function* () {
1922
1885
  const url = `${this.baseUrl}/api${path}`;
1923
1886
  const res = yield fetch(url, {
1924
1887
  method: "POST",
1925
- headers: {
1926
- "Content-Type": "application/json",
1927
- Accept: "application/json",
1928
- "X-API-Key": this.apiKey
1929
- },
1888
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1930
1889
  body: JSON.stringify(body)
1931
1890
  });
1932
1891
  if (!res.ok) {
@@ -2244,19 +2203,36 @@ var TruthClient = class {
2244
2203
  this.patients = new PatientResource(this.convex);
2245
2204
  this.appointments = new AppointmentResource(this.convex);
2246
2205
  this.ehr = new EhrResource(apiUrl, config.apiKey, config.getAuthToken);
2247
- this.messages = new MessagesResource(apiUrl, config.apiKey);
2206
+ this.messages = new MessagesResource(
2207
+ apiUrl,
2208
+ config.apiKey,
2209
+ config.getAuthToken
2210
+ );
2248
2211
  this.reminders = new RemindersResource(this.convex);
2249
- this.translation = new TranslationResource(apiUrl, config.apiKey);
2212
+ this.translation = new TranslationResource(
2213
+ apiUrl,
2214
+ config.apiKey,
2215
+ config.getAuthToken
2216
+ );
2250
2217
  this.tasks = new TasksResource(this.convex);
2251
- this.patientDetails = new PatientDetailsResource(apiUrl, config.apiKey);
2218
+ this.patientDetails = new PatientDetailsResource(
2219
+ apiUrl,
2220
+ config.apiKey,
2221
+ config.getAuthToken
2222
+ );
2252
2223
  this.attachments = new AttachmentsResource(
2253
2224
  apiUrl,
2254
2225
  config.apiKey,
2255
- this.convex
2226
+ this.convex,
2227
+ config.getAuthToken
2256
2228
  );
2257
- this.notes = new NotesResource(apiUrl, config.apiKey);
2229
+ this.notes = new NotesResource(apiUrl, config.apiKey, config.getAuthToken);
2258
2230
  this.physicians = new PhysiciansResource(this.convex);
2259
- this.notifications = new NotificationsResource(apiUrl, config.apiKey);
2231
+ this.notifications = new NotificationsResource(
2232
+ apiUrl,
2233
+ config.apiKey,
2234
+ config.getAuthToken
2235
+ );
2260
2236
  this.conversations = new ConversationsResource(
2261
2237
  apiUrl,
2262
2238
  config.apiKey,
@@ -2264,6 +2240,7 @@ var TruthClient = class {
2264
2240
  config.getAuthToken
2265
2241
  );
2266
2242
  this.userSettings = new UserSettingsResource(this.convex);
2243
+ this._getAuthToken = config.getAuthToken;
2267
2244
  this._serviceWorkerPath = (_h = config.serviceWorkerPath) != null ? _h : "/truth-sw.js";
2268
2245
  if (typeof window !== "undefined" && isWebPushSupported() && config.autoInitServiceWorker !== false) {
2269
2246
  this._webPushReady = this.initWebPush();
@@ -2275,9 +2252,33 @@ var TruthClient = class {
2275
2252
  get webPushReady() {
2276
2253
  return this._webPushReady;
2277
2254
  }
2255
+ /**
2256
+ * When a Clerk token fetcher is configured (publishable-key clients),
2257
+ * the VAPID endpoint is auth-gated — calling it before the session has
2258
+ * hydrated 401s and strands web-push in the "no key" path. Wait
2259
+ * (briefly, bounded) for a token to become available first. No fetcher
2260
+ * → resolve immediately (secret-key path is unaffected).
2261
+ */
2262
+ waitForAuthToken() {
2263
+ return __async(this, null, function* () {
2264
+ if (!this._getAuthToken) {
2265
+ return;
2266
+ }
2267
+ for (let attempt = 0; attempt < 20; attempt++) {
2268
+ try {
2269
+ if (yield this._getAuthToken()) {
2270
+ return;
2271
+ }
2272
+ } catch (e) {
2273
+ }
2274
+ yield new Promise((resolve) => setTimeout(resolve, 500));
2275
+ }
2276
+ });
2277
+ }
2278
2278
  initWebPush() {
2279
2279
  return __async(this, null, function* () {
2280
2280
  try {
2281
+ yield this.waitForAuthToken();
2281
2282
  const key = yield this.notifications.getVapidKey();
2282
2283
  if (!key) {
2283
2284
  return;