@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/index.d.mts CHANGED
@@ -239,19 +239,6 @@ declare class AttachmentsResource {
239
239
  }>;
240
240
  }
241
241
 
242
- /**
243
- * ConversationsResource — write methods that hang off a specific
244
- * conversation: notes, tasks, outbound messages.
245
- *
246
- * Replaces CommHub's `truthConversationApi.ts` raw-fetch wrappers so
247
- * the frontend goes through a typed SDK surface instead of building
248
- * URLs by hand.
249
- *
250
- * All methods proxy the matching oRPC procedures (`/conversations/*`)
251
- * via Truth's application-key auth. Errors surface as
252
- * `ConversationsError` with a status code so callers can distinguish
253
- * transport failures (status=0) from API rejections (status>=400).
254
- */
255
242
  /** Address a conversation by either Convex `_id` or the phonePair. */
256
243
  interface ConversationAddress {
257
244
  conversationId?: string;
@@ -383,8 +370,9 @@ declare class ConversationsResource {
383
370
  private static readonly REQUEST_TIMEOUT_MS;
384
371
  private readonly baseUrl;
385
372
  private readonly apiKey;
373
+ private readonly auth;
386
374
  private readonly convex;
387
- constructor(apiBaseUrl: string, apiKey: string, convex?: convex_browser.ConvexHttpClient);
375
+ constructor(apiBaseUrl: string, apiKey: string, convex?: convex_browser.ConvexHttpClient, getAuthToken?: AuthTokenFetcher);
388
376
  /**
389
377
  * Mark a conversation read for the calling user (zeroes unreadCount,
390
378
  * stamps `lastReadAt`). Calls the public Convex `markRead` mutation
@@ -582,7 +570,8 @@ declare class DialpadProxyError extends Error {
582
570
  * EHR proxy resource — typed access to Truth's EHR proxy endpoints.
583
571
  *
584
572
  * Provides per-provider proxy methods so consumers never construct
585
- * proxy URLs manually.
573
+ * proxy URLs manually. Every request carries the application's
574
+ * `X-API-Key` — Truth's API gate rejects unauthenticated callers.
586
575
  *
587
576
  * @example
588
577
  * ```ts
@@ -591,31 +580,26 @@ declare class DialpadProxyError extends Error {
591
580
  * const hintPatient = await truth.ehr.hint.get('/provider/patients/456');
592
581
  * ```
593
582
  */
583
+
594
584
  declare class EhrProviderProxy {
595
585
  private readonly baseUrl;
596
586
  private readonly provider;
597
- constructor(apiBaseUrl: string, provider: string);
587
+ private readonly auth;
588
+ constructor(apiBaseUrl: string, provider: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
589
+ private request;
598
590
  /**
599
591
  * GET request to the EHR proxy.
600
592
  * @param path — path relative to the provider root (e.g., "/patients/123/")
601
593
  * @param params — optional query parameters
602
594
  */
603
595
  get<T = unknown>(path: string, params?: Record<string, unknown>): Promise<T>;
604
- /**
605
- * POST request to the EHR proxy.
606
- */
596
+ /** POST request to the EHR proxy. */
607
597
  post<T = unknown>(path: string, body?: unknown): Promise<T>;
608
- /**
609
- * PUT request to the EHR proxy.
610
- */
598
+ /** PUT request to the EHR proxy. */
611
599
  put<T = unknown>(path: string, body?: unknown): Promise<T>;
612
- /**
613
- * PATCH request to the EHR proxy.
614
- */
600
+ /** PATCH request to the EHR proxy. */
615
601
  patch<T = unknown>(path: string, body?: unknown): Promise<T>;
616
- /**
617
- * DELETE request to the EHR proxy.
618
- */
602
+ /** DELETE request to the EHR proxy. */
619
603
  delete<T = unknown>(path: string): Promise<T>;
620
604
  }
621
605
  declare class EhrResource {
@@ -623,7 +607,7 @@ declare class EhrResource {
623
607
  readonly elation: EhrProviderProxy;
624
608
  /** Hint Health proxy */
625
609
  readonly hint: EhrProviderProxy;
626
- constructor(apiBaseUrl: string);
610
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
627
611
  }
628
612
  declare class EhrProxyError extends Error {
629
613
  readonly provider: string;
package/dist/index.d.ts CHANGED
@@ -239,19 +239,6 @@ declare class AttachmentsResource {
239
239
  }>;
240
240
  }
241
241
 
242
- /**
243
- * ConversationsResource — write methods that hang off a specific
244
- * conversation: notes, tasks, outbound messages.
245
- *
246
- * Replaces CommHub's `truthConversationApi.ts` raw-fetch wrappers so
247
- * the frontend goes through a typed SDK surface instead of building
248
- * URLs by hand.
249
- *
250
- * All methods proxy the matching oRPC procedures (`/conversations/*`)
251
- * via Truth's application-key auth. Errors surface as
252
- * `ConversationsError` with a status code so callers can distinguish
253
- * transport failures (status=0) from API rejections (status>=400).
254
- */
255
242
  /** Address a conversation by either Convex `_id` or the phonePair. */
256
243
  interface ConversationAddress {
257
244
  conversationId?: string;
@@ -383,8 +370,9 @@ declare class ConversationsResource {
383
370
  private static readonly REQUEST_TIMEOUT_MS;
384
371
  private readonly baseUrl;
385
372
  private readonly apiKey;
373
+ private readonly auth;
386
374
  private readonly convex;
387
- constructor(apiBaseUrl: string, apiKey: string, convex?: convex_browser.ConvexHttpClient);
375
+ constructor(apiBaseUrl: string, apiKey: string, convex?: convex_browser.ConvexHttpClient, getAuthToken?: AuthTokenFetcher);
388
376
  /**
389
377
  * Mark a conversation read for the calling user (zeroes unreadCount,
390
378
  * stamps `lastReadAt`). Calls the public Convex `markRead` mutation
@@ -582,7 +570,8 @@ declare class DialpadProxyError extends Error {
582
570
  * EHR proxy resource — typed access to Truth's EHR proxy endpoints.
583
571
  *
584
572
  * Provides per-provider proxy methods so consumers never construct
585
- * proxy URLs manually.
573
+ * proxy URLs manually. Every request carries the application's
574
+ * `X-API-Key` — Truth's API gate rejects unauthenticated callers.
586
575
  *
587
576
  * @example
588
577
  * ```ts
@@ -591,31 +580,26 @@ declare class DialpadProxyError extends Error {
591
580
  * const hintPatient = await truth.ehr.hint.get('/provider/patients/456');
592
581
  * ```
593
582
  */
583
+
594
584
  declare class EhrProviderProxy {
595
585
  private readonly baseUrl;
596
586
  private readonly provider;
597
- constructor(apiBaseUrl: string, provider: string);
587
+ private readonly auth;
588
+ constructor(apiBaseUrl: string, provider: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
589
+ private request;
598
590
  /**
599
591
  * GET request to the EHR proxy.
600
592
  * @param path — path relative to the provider root (e.g., "/patients/123/")
601
593
  * @param params — optional query parameters
602
594
  */
603
595
  get<T = unknown>(path: string, params?: Record<string, unknown>): Promise<T>;
604
- /**
605
- * POST request to the EHR proxy.
606
- */
596
+ /** POST request to the EHR proxy. */
607
597
  post<T = unknown>(path: string, body?: unknown): Promise<T>;
608
- /**
609
- * PUT request to the EHR proxy.
610
- */
598
+ /** PUT request to the EHR proxy. */
611
599
  put<T = unknown>(path: string, body?: unknown): Promise<T>;
612
- /**
613
- * PATCH request to the EHR proxy.
614
- */
600
+ /** PATCH request to the EHR proxy. */
615
601
  patch<T = unknown>(path: string, body?: unknown): Promise<T>;
616
- /**
617
- * DELETE request to the EHR proxy.
618
- */
602
+ /** DELETE request to the EHR proxy. */
619
603
  delete<T = unknown>(path: string): Promise<T>;
620
604
  }
621
605
  declare class EhrResource {
@@ -623,7 +607,7 @@ declare class EhrResource {
623
607
  readonly elation: EhrProviderProxy;
624
608
  /** Hint Health proxy */
625
609
  readonly hint: EhrProviderProxy;
626
- constructor(apiBaseUrl: string);
610
+ constructor(apiBaseUrl: string, apiKey: string, getAuthToken?: AuthTokenFetcher);
627
611
  }
628
612
  declare class EhrProxyError extends Error {
629
613
  readonly provider: string;
package/dist/index.js CHANGED
@@ -352,6 +352,31 @@ var AttachmentsResource = class {
352
352
  }
353
353
  };
354
354
 
355
+ // src/resources/rest-auth.ts
356
+ function buildAuthHeaders(auth, options) {
357
+ return __async(this, null, function* () {
358
+ const headers = {
359
+ "X-API-Key": auth.apiKey
360
+ };
361
+ if ((options == null ? void 0 : options.accept) !== false) {
362
+ headers.Accept = "application/json";
363
+ }
364
+ if (options == null ? void 0 : options.json) {
365
+ headers["Content-Type"] = "application/json";
366
+ }
367
+ if (auth.getAuthToken) {
368
+ try {
369
+ const token = yield auth.getAuthToken();
370
+ if (token) {
371
+ headers.Authorization = `Bearer ${token}`;
372
+ }
373
+ } catch (e) {
374
+ }
375
+ }
376
+ return headers;
377
+ });
378
+ }
379
+
355
380
  // src/resources/conversations.ts
356
381
  var ConversationsError = class extends Error {
357
382
  constructor(operation, status, message) {
@@ -464,9 +489,10 @@ var ConversationMessagesSubresource = class {
464
489
  }
465
490
  };
466
491
  var _ConversationsResource = class _ConversationsResource {
467
- constructor(apiBaseUrl, apiKey, convex) {
492
+ constructor(apiBaseUrl, apiKey, convex, getAuthToken) {
468
493
  this.baseUrl = apiBaseUrl;
469
494
  this.apiKey = apiKey;
495
+ this.auth = { apiKey, getAuthToken };
470
496
  this.convex = convex != null ? convex : null;
471
497
  const post = (path, body) => this.postRequest(path, body);
472
498
  const patch = (path, body) => this.patchRequest(path, body);
@@ -549,11 +575,7 @@ var _ConversationsResource = class _ConversationsResource {
549
575
  try {
550
576
  res = yield fetch(`${this.baseUrl}/api${path}`, {
551
577
  method: "POST",
552
- headers: {
553
- "Content-Type": "application/json",
554
- Accept: "application/json",
555
- "X-API-Key": this.apiKey
556
- },
578
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
557
579
  body: JSON.stringify(body),
558
580
  signal: controller.signal
559
581
  });
@@ -595,11 +617,7 @@ var _ConversationsResource = class _ConversationsResource {
595
617
  try {
596
618
  res = yield fetch(`${this.baseUrl}/api${path}`, {
597
619
  method: "PATCH",
598
- headers: {
599
- "Content-Type": "application/json",
600
- Accept: "application/json",
601
- "X-API-Key": this.apiKey
602
- },
620
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
603
621
  body: JSON.stringify(body),
604
622
  signal: controller.signal
605
623
  });
@@ -933,16 +951,12 @@ var DialpadProxyError = class extends Error {
933
951
 
934
952
  // src/resources/ehr.ts
935
953
  var EhrProviderProxy = class {
936
- constructor(apiBaseUrl, provider) {
954
+ constructor(apiBaseUrl, provider, apiKey, getAuthToken) {
937
955
  this.baseUrl = apiBaseUrl;
938
956
  this.provider = provider;
957
+ this.auth = { apiKey, getAuthToken };
939
958
  }
940
- /**
941
- * GET request to the EHR proxy.
942
- * @param path — path relative to the provider root (e.g., "/patients/123/")
943
- * @param params — optional query parameters
944
- */
945
- get(path, params) {
959
+ request(method, path, body, params) {
946
960
  return __async(this, null, function* () {
947
961
  const url = new URL(`/api/ehr/${this.provider}${path}`, this.baseUrl);
948
962
  if (params) {
@@ -953,96 +967,60 @@ var EhrProviderProxy = class {
953
967
  }
954
968
  }
955
969
  const response = yield fetch(url.toString(), {
956
- method: "GET",
957
- headers: { Accept: "application/json" }
970
+ method,
971
+ headers: yield buildAuthHeaders(this.auth, { json: body !== void 0 }),
972
+ body: body !== void 0 ? JSON.stringify(body) : void 0
958
973
  });
959
974
  if (!response.ok) {
960
- throw new EhrProxyError(this.provider, "GET", path, response.status);
975
+ throw new EhrProxyError(this.provider, method, path, response.status);
961
976
  }
962
977
  return yield response.json();
963
978
  });
964
979
  }
965
980
  /**
966
- * POST request to the EHR proxy.
981
+ * GET request to the EHR proxy.
982
+ * @param path — path relative to the provider root (e.g., "/patients/123/")
983
+ * @param params — optional query parameters
967
984
  */
985
+ get(path, params) {
986
+ return __async(this, null, function* () {
987
+ return this.request("GET", path, void 0, params);
988
+ });
989
+ }
990
+ /** POST request to the EHR proxy. */
968
991
  post(path, body) {
969
992
  return __async(this, null, function* () {
970
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
971
- const response = yield fetch(url, {
972
- method: "POST",
973
- headers: {
974
- "Content-Type": "application/json",
975
- Accept: "application/json"
976
- },
977
- body: body !== void 0 ? JSON.stringify(body) : void 0
978
- });
979
- if (!response.ok) {
980
- throw new EhrProxyError(this.provider, "POST", path, response.status);
981
- }
982
- return yield response.json();
993
+ return this.request("POST", path, body);
983
994
  });
984
995
  }
985
- /**
986
- * PUT request to the EHR proxy.
987
- */
996
+ /** PUT request to the EHR proxy. */
988
997
  put(path, body) {
989
998
  return __async(this, null, function* () {
990
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
991
- const response = yield fetch(url, {
992
- method: "PUT",
993
- headers: {
994
- "Content-Type": "application/json",
995
- Accept: "application/json"
996
- },
997
- body: body !== void 0 ? JSON.stringify(body) : void 0
998
- });
999
- if (!response.ok) {
1000
- throw new EhrProxyError(this.provider, "PUT", path, response.status);
1001
- }
1002
- return yield response.json();
999
+ return this.request("PUT", path, body);
1003
1000
  });
1004
1001
  }
1005
- /**
1006
- * PATCH request to the EHR proxy.
1007
- */
1002
+ /** PATCH request to the EHR proxy. */
1008
1003
  patch(path, body) {
1009
1004
  return __async(this, null, function* () {
1010
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
1011
- const response = yield fetch(url, {
1012
- method: "PATCH",
1013
- headers: {
1014
- "Content-Type": "application/json",
1015
- Accept: "application/json"
1016
- },
1017
- body: body !== void 0 ? JSON.stringify(body) : void 0
1018
- });
1019
- if (!response.ok) {
1020
- throw new EhrProxyError(this.provider, "PATCH", path, response.status);
1021
- }
1022
- return yield response.json();
1005
+ return this.request("PATCH", path, body);
1023
1006
  });
1024
1007
  }
1025
- /**
1026
- * DELETE request to the EHR proxy.
1027
- */
1008
+ /** DELETE request to the EHR proxy. */
1028
1009
  delete(path) {
1029
1010
  return __async(this, null, function* () {
1030
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
1031
- const response = yield fetch(url, {
1032
- method: "DELETE",
1033
- headers: { Accept: "application/json" }
1034
- });
1035
- if (!response.ok) {
1036
- throw new EhrProxyError(this.provider, "DELETE", path, response.status);
1037
- }
1038
- return yield response.json();
1011
+ return this.request("DELETE", path);
1039
1012
  });
1040
1013
  }
1041
1014
  };
1042
1015
  var EhrResource = class {
1043
- constructor(apiBaseUrl) {
1044
- this.elation = new EhrProviderProxy(apiBaseUrl, "elation");
1045
- this.hint = new EhrProviderProxy(apiBaseUrl, "hint");
1016
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1017
+ this.elation = new EhrProviderProxy(
1018
+ apiBaseUrl,
1019
+ "elation",
1020
+ apiKey,
1021
+ getAuthToken
1022
+ );
1023
+ this.hint = new EhrProviderProxy(apiBaseUrl, "hint", apiKey, getAuthToken);
1046
1024
  }
1047
1025
  };
1048
1026
  var EhrProxyError = class extends Error {
@@ -2007,7 +1985,7 @@ var TruthClient = class {
2007
1985
  const apiUrl = this.tracker.apiUrl;
2008
1986
  this.patients = new PatientResource(this.convex);
2009
1987
  this.appointments = new AppointmentResource(this.convex);
2010
- this.ehr = new EhrResource(apiUrl);
1988
+ this.ehr = new EhrResource(apiUrl, config.apiKey, config.getAuthToken);
2011
1989
  this.messages = new MessagesResource(apiUrl, config.apiKey);
2012
1990
  this.reminders = new RemindersResource(this.convex);
2013
1991
  this.translation = new TranslationResource(apiUrl, config.apiKey);
@@ -2024,7 +2002,8 @@ var TruthClient = class {
2024
2002
  this.conversations = new ConversationsResource(
2025
2003
  apiUrl,
2026
2004
  config.apiKey,
2027
- this.convex
2005
+ this.convex,
2006
+ config.getAuthToken
2028
2007
  );
2029
2008
  this.userSettings = new UserSettingsResource(this.convex);
2030
2009
  this._serviceWorkerPath = (_h = config.serviceWorkerPath) != null ? _h : "/truth-sw.js";