@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.mjs CHANGED
@@ -868,16 +868,22 @@ var DialpadProxyError = class extends Error {
868
868
 
869
869
  // src/resources/ehr.ts
870
870
  var EhrProviderProxy = class {
871
- constructor(apiBaseUrl, provider) {
871
+ constructor(apiBaseUrl, provider, apiKey) {
872
872
  this.baseUrl = apiBaseUrl;
873
873
  this.provider = provider;
874
+ this.apiKey = apiKey;
874
875
  }
875
- /**
876
- * GET request to the EHR proxy.
877
- * @param path — path relative to the provider root (e.g., "/patients/123/")
878
- * @param params — optional query parameters
879
- */
880
- get(path, params) {
876
+ headers(withBody) {
877
+ const headers = {
878
+ Accept: "application/json",
879
+ "X-API-Key": this.apiKey
880
+ };
881
+ if (withBody) {
882
+ headers["Content-Type"] = "application/json";
883
+ }
884
+ return headers;
885
+ }
886
+ request(method, path, body, params) {
881
887
  return __async(this, null, function* () {
882
888
  const url = new URL(`/api/ehr/${this.provider}${path}`, this.baseUrl);
883
889
  if (params) {
@@ -888,96 +894,55 @@ var EhrProviderProxy = class {
888
894
  }
889
895
  }
890
896
  const response = yield fetch(url.toString(), {
891
- method: "GET",
892
- headers: { Accept: "application/json" }
897
+ method,
898
+ headers: this.headers(body !== void 0),
899
+ body: body !== void 0 ? JSON.stringify(body) : void 0
893
900
  });
894
901
  if (!response.ok) {
895
- throw new EhrProxyError(this.provider, "GET", path, response.status);
902
+ throw new EhrProxyError(this.provider, method, path, response.status);
896
903
  }
897
904
  return yield response.json();
898
905
  });
899
906
  }
900
907
  /**
901
- * POST request to the EHR proxy.
908
+ * GET request to the EHR proxy.
909
+ * @param path — path relative to the provider root (e.g., "/patients/123/")
910
+ * @param params — optional query parameters
902
911
  */
912
+ get(path, params) {
913
+ return __async(this, null, function* () {
914
+ return this.request("GET", path, void 0, params);
915
+ });
916
+ }
917
+ /** POST request to the EHR proxy. */
903
918
  post(path, body) {
904
919
  return __async(this, null, function* () {
905
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
906
- const response = yield fetch(url, {
907
- method: "POST",
908
- headers: {
909
- "Content-Type": "application/json",
910
- Accept: "application/json"
911
- },
912
- body: body !== void 0 ? JSON.stringify(body) : void 0
913
- });
914
- if (!response.ok) {
915
- throw new EhrProxyError(this.provider, "POST", path, response.status);
916
- }
917
- return yield response.json();
920
+ return this.request("POST", path, body);
918
921
  });
919
922
  }
920
- /**
921
- * PUT request to the EHR proxy.
922
- */
923
+ /** PUT request to the EHR proxy. */
923
924
  put(path, body) {
924
925
  return __async(this, null, function* () {
925
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
926
- const response = yield fetch(url, {
927
- method: "PUT",
928
- headers: {
929
- "Content-Type": "application/json",
930
- Accept: "application/json"
931
- },
932
- body: body !== void 0 ? JSON.stringify(body) : void 0
933
- });
934
- if (!response.ok) {
935
- throw new EhrProxyError(this.provider, "PUT", path, response.status);
936
- }
937
- return yield response.json();
926
+ return this.request("PUT", path, body);
938
927
  });
939
928
  }
940
- /**
941
- * PATCH request to the EHR proxy.
942
- */
929
+ /** PATCH request to the EHR proxy. */
943
930
  patch(path, body) {
944
931
  return __async(this, null, function* () {
945
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
946
- const response = yield fetch(url, {
947
- method: "PATCH",
948
- headers: {
949
- "Content-Type": "application/json",
950
- Accept: "application/json"
951
- },
952
- body: body !== void 0 ? JSON.stringify(body) : void 0
953
- });
954
- if (!response.ok) {
955
- throw new EhrProxyError(this.provider, "PATCH", path, response.status);
956
- }
957
- return yield response.json();
932
+ return this.request("PATCH", path, body);
958
933
  });
959
934
  }
960
- /**
961
- * DELETE request to the EHR proxy.
962
- */
935
+ /** DELETE request to the EHR proxy. */
963
936
  delete(path) {
964
937
  return __async(this, null, function* () {
965
- const url = `${this.baseUrl}/api/ehr/${this.provider}${path}`;
966
- const response = yield fetch(url, {
967
- method: "DELETE",
968
- headers: { Accept: "application/json" }
969
- });
970
- if (!response.ok) {
971
- throw new EhrProxyError(this.provider, "DELETE", path, response.status);
972
- }
973
- return yield response.json();
938
+ return this.request("DELETE", path);
974
939
  });
975
940
  }
976
941
  };
977
942
  var EhrResource = class {
978
- constructor(apiBaseUrl) {
979
- this.elation = new EhrProviderProxy(apiBaseUrl, "elation");
980
- this.hint = new EhrProviderProxy(apiBaseUrl, "hint");
943
+ constructor(apiBaseUrl, apiKey) {
944
+ this.elation = new EhrProviderProxy(apiBaseUrl, "elation", apiKey);
945
+ this.hint = new EhrProviderProxy(apiBaseUrl, "hint", apiKey);
981
946
  }
982
947
  };
983
948
  var EhrProxyError = class extends Error {
@@ -1942,7 +1907,7 @@ var TruthClient = class {
1942
1907
  const apiUrl = this.tracker.apiUrl;
1943
1908
  this.patients = new PatientResource(this.convex);
1944
1909
  this.appointments = new AppointmentResource(this.convex);
1945
- this.ehr = new EhrResource(apiUrl);
1910
+ this.ehr = new EhrResource(apiUrl, config.apiKey);
1946
1911
  this.messages = new MessagesResource(apiUrl, config.apiKey);
1947
1912
  this.reminders = new RemindersResource(this.convex);
1948
1913
  this.translation = new TranslationResource(apiUrl, config.apiKey);