@hipnation-truth/sdk 0.25.2 → 0.25.3

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
@@ -582,7 +582,8 @@ declare class DialpadProxyError extends Error {
582
582
  * EHR proxy resource — typed access to Truth's EHR proxy endpoints.
583
583
  *
584
584
  * Provides per-provider proxy methods so consumers never construct
585
- * proxy URLs manually.
585
+ * proxy URLs manually. Every request carries the application's
586
+ * `X-API-Key` — Truth's API gate rejects unauthenticated callers.
586
587
  *
587
588
  * @example
588
589
  * ```ts
@@ -594,28 +595,23 @@ declare class DialpadProxyError extends Error {
594
595
  declare class EhrProviderProxy {
595
596
  private readonly baseUrl;
596
597
  private readonly provider;
597
- constructor(apiBaseUrl: string, provider: string);
598
+ private readonly apiKey;
599
+ constructor(apiBaseUrl: string, provider: string, apiKey: string);
600
+ private headers;
601
+ private request;
598
602
  /**
599
603
  * GET request to the EHR proxy.
600
604
  * @param path — path relative to the provider root (e.g., "/patients/123/")
601
605
  * @param params — optional query parameters
602
606
  */
603
607
  get<T = unknown>(path: string, params?: Record<string, unknown>): Promise<T>;
604
- /**
605
- * POST request to the EHR proxy.
606
- */
608
+ /** POST request to the EHR proxy. */
607
609
  post<T = unknown>(path: string, body?: unknown): Promise<T>;
608
- /**
609
- * PUT request to the EHR proxy.
610
- */
610
+ /** PUT request to the EHR proxy. */
611
611
  put<T = unknown>(path: string, body?: unknown): Promise<T>;
612
- /**
613
- * PATCH request to the EHR proxy.
614
- */
612
+ /** PATCH request to the EHR proxy. */
615
613
  patch<T = unknown>(path: string, body?: unknown): Promise<T>;
616
- /**
617
- * DELETE request to the EHR proxy.
618
- */
614
+ /** DELETE request to the EHR proxy. */
619
615
  delete<T = unknown>(path: string): Promise<T>;
620
616
  }
621
617
  declare class EhrResource {
@@ -623,7 +619,7 @@ declare class EhrResource {
623
619
  readonly elation: EhrProviderProxy;
624
620
  /** Hint Health proxy */
625
621
  readonly hint: EhrProviderProxy;
626
- constructor(apiBaseUrl: string);
622
+ constructor(apiBaseUrl: string, apiKey: string);
627
623
  }
628
624
  declare class EhrProxyError extends Error {
629
625
  readonly provider: string;
package/dist/index.d.ts CHANGED
@@ -582,7 +582,8 @@ declare class DialpadProxyError extends Error {
582
582
  * EHR proxy resource — typed access to Truth's EHR proxy endpoints.
583
583
  *
584
584
  * Provides per-provider proxy methods so consumers never construct
585
- * proxy URLs manually.
585
+ * proxy URLs manually. Every request carries the application's
586
+ * `X-API-Key` — Truth's API gate rejects unauthenticated callers.
586
587
  *
587
588
  * @example
588
589
  * ```ts
@@ -594,28 +595,23 @@ declare class DialpadProxyError extends Error {
594
595
  declare class EhrProviderProxy {
595
596
  private readonly baseUrl;
596
597
  private readonly provider;
597
- constructor(apiBaseUrl: string, provider: string);
598
+ private readonly apiKey;
599
+ constructor(apiBaseUrl: string, provider: string, apiKey: string);
600
+ private headers;
601
+ private request;
598
602
  /**
599
603
  * GET request to the EHR proxy.
600
604
  * @param path — path relative to the provider root (e.g., "/patients/123/")
601
605
  * @param params — optional query parameters
602
606
  */
603
607
  get<T = unknown>(path: string, params?: Record<string, unknown>): Promise<T>;
604
- /**
605
- * POST request to the EHR proxy.
606
- */
608
+ /** POST request to the EHR proxy. */
607
609
  post<T = unknown>(path: string, body?: unknown): Promise<T>;
608
- /**
609
- * PUT request to the EHR proxy.
610
- */
610
+ /** PUT request to the EHR proxy. */
611
611
  put<T = unknown>(path: string, body?: unknown): Promise<T>;
612
- /**
613
- * PATCH request to the EHR proxy.
614
- */
612
+ /** PATCH request to the EHR proxy. */
615
613
  patch<T = unknown>(path: string, body?: unknown): Promise<T>;
616
- /**
617
- * DELETE request to the EHR proxy.
618
- */
614
+ /** DELETE request to the EHR proxy. */
619
615
  delete<T = unknown>(path: string): Promise<T>;
620
616
  }
621
617
  declare class EhrResource {
@@ -623,7 +619,7 @@ declare class EhrResource {
623
619
  readonly elation: EhrProviderProxy;
624
620
  /** Hint Health proxy */
625
621
  readonly hint: EhrProviderProxy;
626
- constructor(apiBaseUrl: string);
622
+ constructor(apiBaseUrl: string, apiKey: string);
627
623
  }
628
624
  declare class EhrProxyError extends Error {
629
625
  readonly provider: string;
package/dist/index.js CHANGED
@@ -933,16 +933,22 @@ var DialpadProxyError = class extends Error {
933
933
 
934
934
  // src/resources/ehr.ts
935
935
  var EhrProviderProxy = class {
936
- constructor(apiBaseUrl, provider) {
936
+ constructor(apiBaseUrl, provider, apiKey) {
937
937
  this.baseUrl = apiBaseUrl;
938
938
  this.provider = provider;
939
+ this.apiKey = apiKey;
939
940
  }
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) {
941
+ headers(withBody) {
942
+ const headers = {
943
+ Accept: "application/json",
944
+ "X-API-Key": this.apiKey
945
+ };
946
+ if (withBody) {
947
+ headers["Content-Type"] = "application/json";
948
+ }
949
+ return headers;
950
+ }
951
+ request(method, path, body, params) {
946
952
  return __async(this, null, function* () {
947
953
  const url = new URL(`/api/ehr/${this.provider}${path}`, this.baseUrl);
948
954
  if (params) {
@@ -953,96 +959,55 @@ var EhrProviderProxy = class {
953
959
  }
954
960
  }
955
961
  const response = yield fetch(url.toString(), {
956
- method: "GET",
957
- headers: { Accept: "application/json" }
962
+ method,
963
+ headers: this.headers(body !== void 0),
964
+ body: body !== void 0 ? JSON.stringify(body) : void 0
958
965
  });
959
966
  if (!response.ok) {
960
- throw new EhrProxyError(this.provider, "GET", path, response.status);
967
+ throw new EhrProxyError(this.provider, method, path, response.status);
961
968
  }
962
969
  return yield response.json();
963
970
  });
964
971
  }
965
972
  /**
966
- * POST request to the EHR proxy.
973
+ * GET request to the EHR proxy.
974
+ * @param path — path relative to the provider root (e.g., "/patients/123/")
975
+ * @param params — optional query parameters
967
976
  */
977
+ get(path, params) {
978
+ return __async(this, null, function* () {
979
+ return this.request("GET", path, void 0, params);
980
+ });
981
+ }
982
+ /** POST request to the EHR proxy. */
968
983
  post(path, body) {
969
984
  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();
985
+ return this.request("POST", path, body);
983
986
  });
984
987
  }
985
- /**
986
- * PUT request to the EHR proxy.
987
- */
988
+ /** PUT request to the EHR proxy. */
988
989
  put(path, body) {
989
990
  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();
991
+ return this.request("PUT", path, body);
1003
992
  });
1004
993
  }
1005
- /**
1006
- * PATCH request to the EHR proxy.
1007
- */
994
+ /** PATCH request to the EHR proxy. */
1008
995
  patch(path, body) {
1009
996
  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();
997
+ return this.request("PATCH", path, body);
1023
998
  });
1024
999
  }
1025
- /**
1026
- * DELETE request to the EHR proxy.
1027
- */
1000
+ /** DELETE request to the EHR proxy. */
1028
1001
  delete(path) {
1029
1002
  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();
1003
+ return this.request("DELETE", path);
1039
1004
  });
1040
1005
  }
1041
1006
  };
1042
1007
  var EhrResource = class {
1043
- constructor(apiBaseUrl) {
1044
- this.elation = new EhrProviderProxy(apiBaseUrl, "elation");
1045
- this.hint = new EhrProviderProxy(apiBaseUrl, "hint");
1008
+ constructor(apiBaseUrl, apiKey) {
1009
+ this.elation = new EhrProviderProxy(apiBaseUrl, "elation", apiKey);
1010
+ this.hint = new EhrProviderProxy(apiBaseUrl, "hint", apiKey);
1046
1011
  }
1047
1012
  };
1048
1013
  var EhrProxyError = class extends Error {
@@ -2007,7 +1972,7 @@ var TruthClient = class {
2007
1972
  const apiUrl = this.tracker.apiUrl;
2008
1973
  this.patients = new PatientResource(this.convex);
2009
1974
  this.appointments = new AppointmentResource(this.convex);
2010
- this.ehr = new EhrResource(apiUrl);
1975
+ this.ehr = new EhrResource(apiUrl, config.apiKey);
2011
1976
  this.messages = new MessagesResource(apiUrl, config.apiKey);
2012
1977
  this.reminders = new RemindersResource(this.convex);
2013
1978
  this.translation = new TranslationResource(apiUrl, config.apiKey);