@hipnation-truth/sdk 0.26.0 → 0.26.1

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
@@ -134,6 +134,31 @@ var AppointmentResource = class {
134
134
  }
135
135
  };
136
136
 
137
+ // src/resources/rest-auth.ts
138
+ function buildAuthHeaders(auth, options) {
139
+ return __async(this, null, function* () {
140
+ const headers = {
141
+ "X-API-Key": auth.apiKey
142
+ };
143
+ if ((options == null ? void 0 : options.accept) !== false) {
144
+ headers.Accept = "application/json";
145
+ }
146
+ if (options == null ? void 0 : options.json) {
147
+ headers["Content-Type"] = "application/json";
148
+ }
149
+ if (auth.getAuthToken) {
150
+ try {
151
+ const token = yield auth.getAuthToken();
152
+ if (token) {
153
+ headers.Authorization = `Bearer ${token}`;
154
+ }
155
+ } catch (e) {
156
+ }
157
+ }
158
+ return headers;
159
+ });
160
+ }
161
+
137
162
  // src/resources/attachments.ts
138
163
  var AttachmentsError = class extends Error {
139
164
  constructor(operation, status, message) {
@@ -143,20 +168,17 @@ var AttachmentsError = class extends Error {
143
168
  }
144
169
  };
145
170
  var AttachmentsResource = class {
146
- constructor(apiBaseUrl, apiKey, convexClient) {
171
+ constructor(apiBaseUrl, apiKey, convexClient, getAuthToken) {
147
172
  this.baseUrl = apiBaseUrl;
148
173
  this.apiKey = apiKey;
174
+ this.auth = { apiKey, getAuthToken };
149
175
  this.convex = convexClient;
150
176
  }
151
177
  post(path, body) {
152
178
  return __async(this, null, function* () {
153
179
  const res = yield fetch(`${this.baseUrl}/api${path}`, {
154
180
  method: "POST",
155
- headers: {
156
- "Content-Type": "application/json",
157
- Accept: "application/json",
158
- "X-API-Key": this.apiKey
159
- },
181
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
160
182
  body: JSON.stringify(body)
161
183
  });
162
184
  if (!res.ok) {
@@ -287,31 +309,6 @@ var AttachmentsResource = class {
287
309
  }
288
310
  };
289
311
 
290
- // src/resources/rest-auth.ts
291
- function buildAuthHeaders(auth, options) {
292
- return __async(this, null, function* () {
293
- const headers = {
294
- "X-API-Key": auth.apiKey
295
- };
296
- if ((options == null ? void 0 : options.accept) !== false) {
297
- headers.Accept = "application/json";
298
- }
299
- if (options == null ? void 0 : options.json) {
300
- headers["Content-Type"] = "application/json";
301
- }
302
- if (auth.getAuthToken) {
303
- try {
304
- const token = yield auth.getAuthToken();
305
- if (token) {
306
- headers.Authorization = `Bearer ${token}`;
307
- }
308
- } catch (e) {
309
- }
310
- }
311
- return headers;
312
- });
313
- }
314
-
315
312
  // src/resources/conversations.ts
316
313
  var ConversationsError = class extends Error {
317
314
  constructor(operation, status, message) {
@@ -581,9 +578,10 @@ var ConversationsResource = _ConversationsResource;
581
578
 
582
579
  // src/resources/dialpad.ts
583
580
  var DialpadResource = class {
584
- constructor(apiBaseUrl, apiKey) {
581
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
585
582
  this.baseUrl = apiBaseUrl;
586
583
  this.apiKey = apiKey;
584
+ this.auth = { apiKey, getAuthToken };
587
585
  }
588
586
  /**
589
587
  * Send an SMS or MMS message via Dialpad.
@@ -724,10 +722,7 @@ var DialpadResource = class {
724
722
  const url = `${this.baseUrl}/api/messages/dialpad/voicemail/authenticate`;
725
723
  const response = yield fetch(url, {
726
724
  method: "POST",
727
- headers: {
728
- "Content-Type": "application/json",
729
- "X-API-Key": this.apiKey
730
- },
725
+ headers: yield buildAuthHeaders(this.auth, { json: true, accept: false }),
731
726
  body: JSON.stringify({ voicemail_link: voicemailLink })
732
727
  });
733
728
  const result = yield response.json();
@@ -752,10 +747,7 @@ var DialpadResource = class {
752
747
  }
753
748
  const response = yield fetch(url.toString(), {
754
749
  method: "GET",
755
- headers: {
756
- Accept: "application/json",
757
- "X-API-Key": this.apiKey
758
- }
750
+ headers: yield buildAuthHeaders(this.auth)
759
751
  });
760
752
  if (!response.ok) {
761
753
  throw new DialpadProxyError("GET", path, response.status);
@@ -768,11 +760,7 @@ var DialpadResource = class {
768
760
  const url = `${this.baseUrl}/api/messages/dialpad${path}`;
769
761
  const response = yield fetch(url, {
770
762
  method: "POST",
771
- headers: {
772
- "Content-Type": "application/json",
773
- Accept: "application/json",
774
- "X-API-Key": this.apiKey
775
- },
763
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
776
764
  body: body !== void 0 ? JSON.stringify(body) : void 0
777
765
  });
778
766
  if (!response.ok) {
@@ -787,11 +775,7 @@ var DialpadResource = class {
787
775
  const url = `${this.baseUrl}/api/messages/dialpad${path}`;
788
776
  const response = yield fetch(url, {
789
777
  method: "PUT",
790
- headers: {
791
- "Content-Type": "application/json",
792
- Accept: "application/json",
793
- "X-API-Key": this.apiKey
794
- },
778
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
795
779
  body: body !== void 0 ? JSON.stringify(body) : void 0
796
780
  });
797
781
  if (!response.ok) {
@@ -805,10 +789,11 @@ var DialpadResource = class {
805
789
  }
806
790
  };
807
791
  var MessagesResource = class {
808
- constructor(apiBaseUrl, apiKey) {
809
- this.dialpad = new DialpadResource(apiBaseUrl, apiKey);
792
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
793
+ this.dialpad = new DialpadResource(apiBaseUrl, apiKey, getAuthToken);
810
794
  this.baseUrl = apiBaseUrl;
811
795
  this.apiKey = apiKey;
796
+ this.auth = { apiKey, getAuthToken };
812
797
  }
813
798
  /**
814
799
  * Get an authenticated URL for a Dialpad voicemail recording.
@@ -827,11 +812,7 @@ var MessagesResource = class {
827
812
  return __async(this, null, function* () {
828
813
  const res = yield fetch(`${this.baseUrl}/api/conversations/voicemail/url`, {
829
814
  method: "POST",
830
- headers: {
831
- "Content-Type": "application/json",
832
- Accept: "application/json",
833
- "X-API-Key": this.apiKey
834
- },
815
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
835
816
  body: JSON.stringify({ voicemailLink })
836
817
  });
837
818
  if (!res.ok) {
@@ -855,11 +836,7 @@ var MessagesResource = class {
855
836
  return __async(this, null, function* () {
856
837
  const res = yield fetch(`${this.baseUrl}/api/conversations/calls/end`, {
857
838
  method: "POST",
858
- headers: {
859
- "Content-Type": "application/json",
860
- Accept: "application/json",
861
- "X-API-Key": this.apiKey
862
- },
839
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
863
840
  body: JSON.stringify({ callId })
864
841
  });
865
842
  if (!res.ok) {
@@ -980,9 +957,10 @@ var NotesError = class extends Error {
980
957
  }
981
958
  };
982
959
  var _NotesResource = class _NotesResource {
983
- constructor(apiBaseUrl, apiKey) {
960
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
984
961
  this.baseUrl = apiBaseUrl;
985
962
  this.apiKey = apiKey;
963
+ this.auth = { apiKey, getAuthToken };
986
964
  }
987
965
  post(path, body) {
988
966
  return __async(this, null, function* () {
@@ -995,11 +973,7 @@ var _NotesResource = class _NotesResource {
995
973
  try {
996
974
  res = yield fetch(`${this.baseUrl}/api${path}`, {
997
975
  method: "POST",
998
- headers: {
999
- "Content-Type": "application/json",
1000
- Accept: "application/json",
1001
- "X-API-Key": this.apiKey
1002
- },
976
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1003
977
  body: JSON.stringify(body),
1004
978
  signal: controller.signal
1005
979
  });
@@ -1060,19 +1034,16 @@ var NotificationsError = class extends Error {
1060
1034
  }
1061
1035
  };
1062
1036
  var NotificationsResource = class {
1063
- constructor(apiBaseUrl, apiKey) {
1037
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1064
1038
  this.baseUrl = apiBaseUrl;
1065
1039
  this.apiKey = apiKey;
1040
+ this.auth = { apiKey, getAuthToken };
1066
1041
  }
1067
1042
  post(path, body) {
1068
1043
  return __async(this, null, function* () {
1069
1044
  const res = yield fetch(`${this.baseUrl}/api${path}`, {
1070
1045
  method: "POST",
1071
- headers: {
1072
- "Content-Type": "application/json",
1073
- Accept: "application/json",
1074
- "X-API-Key": this.apiKey
1075
- },
1046
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1076
1047
  body: JSON.stringify(body)
1077
1048
  });
1078
1049
  if (!res.ok) {
@@ -1090,10 +1061,7 @@ var NotificationsResource = class {
1090
1061
  }
1091
1062
  const res = yield fetch(url.toString(), {
1092
1063
  method: "GET",
1093
- headers: {
1094
- Accept: "application/json",
1095
- "X-API-Key": this.apiKey
1096
- }
1064
+ headers: yield buildAuthHeaders(this.auth)
1097
1065
  });
1098
1066
  if (!res.ok) {
1099
1067
  const text = yield res.text().catch(() => "");
@@ -1106,10 +1074,7 @@ var NotificationsResource = class {
1106
1074
  return __async(this, null, function* () {
1107
1075
  const res = yield fetch(`${this.baseUrl}/api${path}`, {
1108
1076
  method: "DELETE",
1109
- headers: {
1110
- Accept: "application/json",
1111
- "X-API-Key": this.apiKey
1112
- }
1077
+ headers: yield buildAuthHeaders(this.auth)
1113
1078
  });
1114
1079
  if (!res.ok) {
1115
1080
  const text = yield res.text().catch(() => "");
@@ -1242,19 +1207,16 @@ var PatientDetailsError = class extends Error {
1242
1207
  }
1243
1208
  };
1244
1209
  var PatientDetailsResource = class {
1245
- constructor(apiBaseUrl, apiKey) {
1210
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1246
1211
  this.baseUrl = apiBaseUrl;
1247
1212
  this.apiKey = apiKey;
1213
+ this.auth = { apiKey, getAuthToken };
1248
1214
  }
1249
1215
  post(path, body) {
1250
1216
  return __async(this, null, function* () {
1251
1217
  const res = yield fetch(`${this.baseUrl}/api${path}`, {
1252
1218
  method: "POST",
1253
- headers: {
1254
- "Content-Type": "application/json",
1255
- Accept: "application/json",
1256
- "X-API-Key": this.apiKey
1257
- },
1219
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1258
1220
  body: JSON.stringify(body)
1259
1221
  });
1260
1222
  if (!res.ok) {
@@ -1576,20 +1538,17 @@ var TranslationError = class extends Error {
1576
1538
  }
1577
1539
  };
1578
1540
  var TranslationResource = class {
1579
- constructor(apiBaseUrl, apiKey) {
1541
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1580
1542
  this.baseUrl = apiBaseUrl;
1581
1543
  this.apiKey = apiKey;
1544
+ this.auth = { apiKey, getAuthToken };
1582
1545
  }
1583
1546
  post(path, body) {
1584
1547
  return __async(this, null, function* () {
1585
1548
  const url = `${this.baseUrl}/api${path}`;
1586
1549
  const res = yield fetch(url, {
1587
1550
  method: "POST",
1588
- headers: {
1589
- "Content-Type": "application/json",
1590
- Accept: "application/json",
1591
- "X-API-Key": this.apiKey
1592
- },
1551
+ headers: yield buildAuthHeaders(this.auth, { json: true }),
1593
1552
  body: JSON.stringify(body)
1594
1553
  });
1595
1554
  if (!res.ok) {
@@ -1921,19 +1880,36 @@ var TruthClient = class {
1921
1880
  this.patients = new PatientResource(this.convex);
1922
1881
  this.appointments = new AppointmentResource(this.convex);
1923
1882
  this.ehr = new EhrResource(apiUrl, config.apiKey, config.getAuthToken);
1924
- this.messages = new MessagesResource(apiUrl, config.apiKey);
1883
+ this.messages = new MessagesResource(
1884
+ apiUrl,
1885
+ config.apiKey,
1886
+ config.getAuthToken
1887
+ );
1925
1888
  this.reminders = new RemindersResource(this.convex);
1926
- this.translation = new TranslationResource(apiUrl, config.apiKey);
1889
+ this.translation = new TranslationResource(
1890
+ apiUrl,
1891
+ config.apiKey,
1892
+ config.getAuthToken
1893
+ );
1927
1894
  this.tasks = new TasksResource(this.convex);
1928
- this.patientDetails = new PatientDetailsResource(apiUrl, config.apiKey);
1895
+ this.patientDetails = new PatientDetailsResource(
1896
+ apiUrl,
1897
+ config.apiKey,
1898
+ config.getAuthToken
1899
+ );
1929
1900
  this.attachments = new AttachmentsResource(
1930
1901
  apiUrl,
1931
1902
  config.apiKey,
1932
- this.convex
1903
+ this.convex,
1904
+ config.getAuthToken
1933
1905
  );
1934
- this.notes = new NotesResource(apiUrl, config.apiKey);
1906
+ this.notes = new NotesResource(apiUrl, config.apiKey, config.getAuthToken);
1935
1907
  this.physicians = new PhysiciansResource(this.convex);
1936
- this.notifications = new NotificationsResource(apiUrl, config.apiKey);
1908
+ this.notifications = new NotificationsResource(
1909
+ apiUrl,
1910
+ config.apiKey,
1911
+ config.getAuthToken
1912
+ );
1937
1913
  this.conversations = new ConversationsResource(
1938
1914
  apiUrl,
1939
1915
  config.apiKey,