@hipnation-truth/sdk 0.25.2 → 0.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.d.ts CHANGED
@@ -1420,19 +1420,6 @@ declare class AttachmentsResource {
1420
1420
  }>;
1421
1421
  }
1422
1422
 
1423
- /**
1424
- * ConversationsResource — write methods that hang off a specific
1425
- * conversation: notes, tasks, outbound messages.
1426
- *
1427
- * Replaces CommHub's `truthConversationApi.ts` raw-fetch wrappers so
1428
- * the frontend goes through a typed SDK surface instead of building
1429
- * URLs by hand.
1430
- *
1431
- * All methods proxy the matching oRPC procedures (`/conversations/*`)
1432
- * via Truth's application-key auth. Errors surface as
1433
- * `ConversationsError` with a status code so callers can distinguish
1434
- * transport failures (status=0) from API rejections (status>=400).
1435
- */
1436
1423
  /** Address a conversation by either Convex `_id` or the phonePair. */
1437
1424
  interface ConversationAddress {
1438
1425
  conversationId?: string;
@@ -1560,8 +1547,9 @@ declare class ConversationsResource {
1560
1547
  private static readonly REQUEST_TIMEOUT_MS;
1561
1548
  private readonly baseUrl;
1562
1549
  private readonly apiKey;
1550
+ private readonly auth;
1563
1551
  private readonly convex;
1564
- constructor(apiBaseUrl: string, apiKey: string, convex?: convex_browser.ConvexHttpClient);
1552
+ constructor(apiBaseUrl: string, apiKey: string, convex?: convex_browser.ConvexHttpClient, getAuthToken?: AuthTokenFetcher);
1565
1553
  /**
1566
1554
  * Mark a conversation read for the calling user (zeroes unreadCount,
1567
1555
  * stamps `lastReadAt`). Calls the public Convex `markRead` mutation
@@ -1748,7 +1736,8 @@ declare class MessagesResource {
1748
1736
  * EHR proxy resource — typed access to Truth's EHR proxy endpoints.
1749
1737
  *
1750
1738
  * Provides per-provider proxy methods so consumers never construct
1751
- * proxy URLs manually.
1739
+ * proxy URLs manually. Every request carries the application's
1740
+ * `X-API-Key` — Truth's API gate rejects unauthenticated callers.
1752
1741
  *
1753
1742
  * @example
1754
1743
  * ```ts
@@ -1757,31 +1746,26 @@ declare class MessagesResource {
1757
1746
  * const hintPatient = await truth.ehr.hint.get('/provider/patients/456');
1758
1747
  * ```
1759
1748
  */
1749
+
1760
1750
  declare class EhrProviderProxy {
1761
1751
  private readonly baseUrl;
1762
1752
  private readonly provider;
1763
- constructor(apiBaseUrl: string, provider: string);
1753
+ private readonly auth;
1754
+ constructor(apiBaseUrl: string, provider: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
1755
+ private request;
1764
1756
  /**
1765
1757
  * GET request to the EHR proxy.
1766
1758
  * @param path — path relative to the provider root (e.g., "/patients/123/")
1767
1759
  * @param params — optional query parameters
1768
1760
  */
1769
1761
  get<T = unknown>(path: string, params?: Record<string, unknown>): Promise<T>;
1770
- /**
1771
- * POST request to the EHR proxy.
1772
- */
1762
+ /** POST request to the EHR proxy. */
1773
1763
  post<T = unknown>(path: string, body?: unknown): Promise<T>;
1774
- /**
1775
- * PUT request to the EHR proxy.
1776
- */
1764
+ /** PUT request to the EHR proxy. */
1777
1765
  put<T = unknown>(path: string, body?: unknown): Promise<T>;
1778
- /**
1779
- * PATCH request to the EHR proxy.
1780
- */
1766
+ /** PATCH request to the EHR proxy. */
1781
1767
  patch<T = unknown>(path: string, body?: unknown): Promise<T>;
1782
- /**
1783
- * DELETE request to the EHR proxy.
1784
- */
1768
+ /** DELETE request to the EHR proxy. */
1785
1769
  delete<T = unknown>(path: string): Promise<T>;
1786
1770
  }
1787
1771
  declare class EhrResource {
@@ -1789,7 +1773,7 @@ declare class EhrResource {
1789
1773
  readonly elation: EhrProviderProxy;
1790
1774
  /** Hint Health proxy */
1791
1775
  readonly hint: EhrProviderProxy;
1792
- constructor(apiBaseUrl: string);
1776
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
1793
1777
  }
1794
1778
 
1795
1779
  /**
package/dist/react.js CHANGED
@@ -624,6 +624,31 @@ var AttachmentsResource = class {
624
624
  }
625
625
  };
626
626
 
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
+
627
652
  // src/resources/conversations.ts
628
653
  var ConversationsError = class extends Error {
629
654
  constructor(operation, status, message) {
@@ -736,9 +761,10 @@ var ConversationMessagesSubresource = class {
736
761
  }
737
762
  };
738
763
  var _ConversationsResource = class _ConversationsResource {
739
- constructor(apiBaseUrl, apiKey, convex) {
764
+ constructor(apiBaseUrl, apiKey, convex, getAuthToken) {
740
765
  this.baseUrl = apiBaseUrl;
741
766
  this.apiKey = apiKey;
767
+ this.auth = { apiKey, getAuthToken };
742
768
  this.convex = convex != null ? convex : null;
743
769
  const post = (path, body) => this.postRequest(path, body);
744
770
  const patch = (path, body) => this.patchRequest(path, body);
@@ -821,11 +847,7 @@ var _ConversationsResource = class _ConversationsResource {
821
847
  try {
822
848
  res = yield fetch(`${this.baseUrl}/api${path}`, {
823
849
  method: "POST",
824
- headers: {
825
- "Content-Type": "application/json",
826
- Accept: "application/json",
827
- "X-API-Key": this.apiKey
828
- },
850
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
829
851
  body: JSON.stringify(body),
830
852
  signal: controller.signal
831
853
  });
@@ -867,11 +889,7 @@ var _ConversationsResource = class _ConversationsResource {
867
889
  try {
868
890
  res = yield fetch(`${this.baseUrl}/api${path}`, {
869
891
  method: "PATCH",
870
- headers: {
871
- "Content-Type": "application/json",
872
- Accept: "application/json",
873
- "X-API-Key": this.apiKey
874
- },
892
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
875
893
  body: JSON.stringify(body),
876
894
  signal: controller.signal
877
895
  });
@@ -1205,16 +1223,12 @@ var DialpadProxyError = class extends Error {
1205
1223
 
1206
1224
  // src/resources/ehr.ts
1207
1225
  var EhrProviderProxy = class {
1208
- constructor(apiBaseUrl, provider) {
1226
+ constructor(apiBaseUrl, provider, apiKey, getAuthToken) {
1209
1227
  this.baseUrl = apiBaseUrl;
1210
1228
  this.provider = provider;
1229
+ this.auth = { apiKey, getAuthToken };
1211
1230
  }
1212
- /**
1213
- * GET request to the EHR proxy.
1214
- * @param path — path relative to the provider root (e.g., "/patients/123/")
1215
- * @param params — optional query parameters
1216
- */
1217
- get(path, params) {
1231
+ request(method, path, body, params) {
1218
1232
  return __async(this, null, function* () {
1219
1233
  const url = new URL(`/api/ehr/${this.provider}${path}`, this.baseUrl);
1220
1234
  if (params) {
@@ -1225,96 +1239,60 @@ var EhrProviderProxy = class {
1225
1239
  }
1226
1240
  }
1227
1241
  const response = yield fetch(url.toString(), {
1228
- method: "GET",
1229
- headers: { Accept: "application/json" }
1242
+ method,
1243
+ headers: yield buildAuthHeaders(this.auth, { json: body !== void 0 }),
1244
+ body: body !== void 0 ? JSON.stringify(body) : void 0
1230
1245
  });
1231
1246
  if (!response.ok) {
1232
- throw new EhrProxyError(this.provider, "GET", path, response.status);
1247
+ throw new EhrProxyError(this.provider, method, path, response.status);
1233
1248
  }
1234
1249
  return yield response.json();
1235
1250
  });
1236
1251
  }
1237
1252
  /**
1238
- * POST request to the EHR proxy.
1253
+ * GET request to the EHR proxy.
1254
+ * @param path — path relative to the provider root (e.g., "/patients/123/")
1255
+ * @param params — optional query parameters
1239
1256
  */
1257
+ get(path, params) {
1258
+ return __async(this, null, function* () {
1259
+ return this.request("GET", path, void 0, params);
1260
+ });
1261
+ }
1262
+ /** POST request to the EHR proxy. */
1240
1263
  post(path, body) {
1241
1264
  return __async(this, null, function* () {
1242
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
1243
- const response = yield fetch(url, {
1244
- method: "POST",
1245
- headers: {
1246
- "Content-Type": "application/json",
1247
- Accept: "application/json"
1248
- },
1249
- body: body !== void 0 ? JSON.stringify(body) : void 0
1250
- });
1251
- if (!response.ok) {
1252
- throw new EhrProxyError(this.provider, "POST", path, response.status);
1253
- }
1254
- return yield response.json();
1265
+ return this.request("POST", path, body);
1255
1266
  });
1256
1267
  }
1257
- /**
1258
- * PUT request to the EHR proxy.
1259
- */
1268
+ /** PUT request to the EHR proxy. */
1260
1269
  put(path, body) {
1261
1270
  return __async(this, null, function* () {
1262
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
1263
- const response = yield fetch(url, {
1264
- method: "PUT",
1265
- headers: {
1266
- "Content-Type": "application/json",
1267
- Accept: "application/json"
1268
- },
1269
- body: body !== void 0 ? JSON.stringify(body) : void 0
1270
- });
1271
- if (!response.ok) {
1272
- throw new EhrProxyError(this.provider, "PUT", path, response.status);
1273
- }
1274
- return yield response.json();
1271
+ return this.request("PUT", path, body);
1275
1272
  });
1276
1273
  }
1277
- /**
1278
- * PATCH request to the EHR proxy.
1279
- */
1274
+ /** PATCH request to the EHR proxy. */
1280
1275
  patch(path, body) {
1281
1276
  return __async(this, null, function* () {
1282
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
1283
- const response = yield fetch(url, {
1284
- method: "PATCH",
1285
- headers: {
1286
- "Content-Type": "application/json",
1287
- Accept: "application/json"
1288
- },
1289
- body: body !== void 0 ? JSON.stringify(body) : void 0
1290
- });
1291
- if (!response.ok) {
1292
- throw new EhrProxyError(this.provider, "PATCH", path, response.status);
1293
- }
1294
- return yield response.json();
1277
+ return this.request("PATCH", path, body);
1295
1278
  });
1296
1279
  }
1297
- /**
1298
- * DELETE request to the EHR proxy.
1299
- */
1280
+ /** DELETE request to the EHR proxy. */
1300
1281
  delete(path) {
1301
1282
  return __async(this, null, function* () {
1302
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
1303
- const response = yield fetch(url, {
1304
- method: "DELETE",
1305
- headers: { Accept: "application/json" }
1306
- });
1307
- if (!response.ok) {
1308
- throw new EhrProxyError(this.provider, "DELETE", path, response.status);
1309
- }
1310
- return yield response.json();
1283
+ return this.request("DELETE", path);
1311
1284
  });
1312
1285
  }
1313
1286
  };
1314
1287
  var EhrResource = class {
1315
- constructor(apiBaseUrl) {
1316
- this.elation = new EhrProviderProxy(apiBaseUrl, "elation");
1317
- this.hint = new EhrProviderProxy(apiBaseUrl, "hint");
1288
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1289
+ this.elation = new EhrProviderProxy(
1290
+ apiBaseUrl,
1291
+ "elation",
1292
+ apiKey,
1293
+ getAuthToken
1294
+ );
1295
+ this.hint = new EhrProviderProxy(apiBaseUrl, "hint", apiKey, getAuthToken);
1318
1296
  }
1319
1297
  };
1320
1298
  var EhrProxyError = class extends Error {
@@ -2265,7 +2243,7 @@ var TruthClient = class {
2265
2243
  const apiUrl = this.tracker.apiUrl;
2266
2244
  this.patients = new PatientResource(this.convex);
2267
2245
  this.appointments = new AppointmentResource(this.convex);
2268
- this.ehr = new EhrResource(apiUrl);
2246
+ this.ehr = new EhrResource(apiUrl, config.apiKey, config.getAuthToken);
2269
2247
  this.messages = new MessagesResource(apiUrl, config.apiKey);
2270
2248
  this.reminders = new RemindersResource(this.convex);
2271
2249
  this.translation = new TranslationResource(apiUrl, config.apiKey);
@@ -2282,7 +2260,8 @@ var TruthClient = class {
2282
2260
  this.conversations = new ConversationsResource(
2283
2261
  apiUrl,
2284
2262
  config.apiKey,
2285
- this.convex
2263
+ this.convex,
2264
+ config.getAuthToken
2286
2265
  );
2287
2266
  this.userSettings = new UserSettingsResource(this.convex);
2288
2267
  this._serviceWorkerPath = (_h = config.serviceWorkerPath) != null ? _h : "/truth-sw.js";