@hipnation-truth/sdk 0.1.5 → 0.2.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.js CHANGED
@@ -57,6 +57,8 @@ var src_exports = {};
57
57
  __export(src_exports, {
58
58
  AUTH_EVENTS: () => AUTH_EVENTS,
59
59
  AppointmentResource: () => AppointmentResource,
60
+ AttachmentsError: () => AttachmentsError,
61
+ AttachmentsResource: () => AttachmentsResource,
60
62
  CALL_EVENTS: () => CALL_EVENTS,
61
63
  CONVERSATION_EVENTS: () => CONVERSATION_EVENTS,
62
64
  DialpadProxyError: () => DialpadProxyError,
@@ -68,13 +70,21 @@ __export(src_exports, {
68
70
  EhrResource: () => EhrResource,
69
71
  MessagesResource: () => MessagesResource,
70
72
  NOTIFICATION_EVENTS: () => NOTIFICATION_EVENTS,
73
+ NotesError: () => NotesError,
74
+ NotesResource: () => NotesResource,
71
75
  PROVIDER_EVENTS: () => PROVIDER_EVENTS,
76
+ PatientDetailsError: () => PatientDetailsError,
77
+ PatientDetailsResource: () => PatientDetailsResource,
72
78
  PatientResource: () => PatientResource,
73
79
  REMINDER_EVENTS: () => REMINDER_EVENTS,
80
+ RemindersResource: () => RemindersResource,
74
81
  SECURITY_EVENTS: () => SECURITY_EVENTS,
75
82
  TASK_EVENTS: () => TASK_EVENTS,
76
83
  TRANSLATION_EVENTS: () => TRANSLATION_EVENTS,
84
+ TasksResource: () => TasksResource,
77
85
  Tracker: () => Tracker,
86
+ TranslationError: () => TranslationError,
87
+ TranslationResource: () => TranslationResource,
78
88
  TruthClient: () => TruthClient,
79
89
  generateUuidV7: () => generateUuidV7
80
90
  });
@@ -130,10 +140,95 @@ var AppointmentResource = class {
130
140
  }
131
141
  };
132
142
 
143
+ // src/resources/attachments.ts
144
+ var AttachmentsError = class extends Error {
145
+ constructor(operation, status, message) {
146
+ super(message != null ? message : `Attachment ${operation} failed (HTTP ${status})`);
147
+ this.name = "AttachmentsError";
148
+ this.status = status;
149
+ }
150
+ };
151
+ var AttachmentsResource = class {
152
+ constructor(apiBaseUrl, apiKey, convexClient) {
153
+ this.baseUrl = apiBaseUrl;
154
+ this.apiKey = apiKey;
155
+ this.convex = convexClient;
156
+ }
157
+ post(path, body) {
158
+ return __async(this, null, function* () {
159
+ const res = yield fetch(`${this.baseUrl}/api${path}`, {
160
+ method: "POST",
161
+ headers: {
162
+ "Content-Type": "application/json",
163
+ Accept: "application/json",
164
+ "X-API-Key": this.apiKey
165
+ },
166
+ body: JSON.stringify(body)
167
+ });
168
+ if (!res.ok) {
169
+ const text = yield res.text().catch(() => "");
170
+ throw new AttachmentsError(path, res.status, text.slice(0, 200));
171
+ }
172
+ return yield res.json();
173
+ });
174
+ }
175
+ createUploadUrl(input) {
176
+ return __async(this, null, function* () {
177
+ return yield this.post(
178
+ "/attachments/upload-url",
179
+ input
180
+ );
181
+ });
182
+ }
183
+ getDownloadUrl(s3Key, expiresIn) {
184
+ return __async(this, null, function* () {
185
+ return yield this.post("/attachments/download-url", {
186
+ s3Key,
187
+ expiresIn
188
+ });
189
+ });
190
+ }
191
+ record(input) {
192
+ return __async(this, null, function* () {
193
+ return yield this.convex.mutation(
194
+ "attachments:record",
195
+ input
196
+ );
197
+ });
198
+ }
199
+ get(attachmentId) {
200
+ return __async(this, null, function* () {
201
+ try {
202
+ const row = yield this.convex.query(
203
+ "attachments:getById",
204
+ { attachmentId }
205
+ );
206
+ return row != null ? row : null;
207
+ } catch (e) {
208
+ return null;
209
+ }
210
+ });
211
+ }
212
+ listByConversation(conversationId) {
213
+ return __async(this, null, function* () {
214
+ try {
215
+ const rows = yield this.convex.query(
216
+ "attachments:listByConversation",
217
+ { conversationId }
218
+ );
219
+ return rows != null ? rows : [];
220
+ } catch (e) {
221
+ return [];
222
+ }
223
+ });
224
+ }
225
+ };
226
+
133
227
  // src/resources/dialpad.ts
134
228
  var DialpadResource = class {
135
- constructor(apiBaseUrl) {
229
+ constructor(apiBaseUrl, apiKey) {
136
230
  this.baseUrl = apiBaseUrl;
231
+ this.apiKey = apiKey;
137
232
  }
138
233
  /**
139
234
  * Send an SMS or MMS message via Dialpad.
@@ -166,6 +261,33 @@ var DialpadResource = class {
166
261
  yield this.put(`/call/${callId}/actions/hangup`);
167
262
  });
168
263
  }
264
+ /**
265
+ * Alias for `hangupCall` — mirrors the CommHub `endCall` action name so
266
+ * the SDK swap is a direct rename.
267
+ */
268
+ endCall(callId) {
269
+ return __async(this, null, function* () {
270
+ yield this.hangupCall(callId);
271
+ });
272
+ }
273
+ /**
274
+ * Send an MMS with a pre-uploaded attachment. Takes the S3 key returned
275
+ * by `client.attachments.createUploadUrl(...)` + PUT, fetches a short-
276
+ * lived download URL, and hands it to Dialpad as `media[]`.
277
+ *
278
+ * Replaces CommHub's `sendAttachment` Hasura Action (which stored bytes
279
+ * as base64 in Postgres and served them through a GET endpoint).
280
+ */
281
+ sendAttachmentWithUrl(params) {
282
+ return __async(this, null, function* () {
283
+ return this.sendSms({
284
+ from_number: params.from_number,
285
+ to_number: params.to_number,
286
+ message: params.message,
287
+ media: [params.mediaUrl]
288
+ });
289
+ });
290
+ }
169
291
  /**
170
292
  * Get the status of a call.
171
293
  */
@@ -247,7 +369,10 @@ var DialpadResource = class {
247
369
  const url = `${this.baseUrl}/api/messages/dialpad/voicemail/authenticate`;
248
370
  const response = yield fetch(url, {
249
371
  method: "POST",
250
- headers: { "Content-Type": "application/json" },
372
+ headers: {
373
+ "Content-Type": "application/json",
374
+ "X-API-Key": this.apiKey
375
+ },
251
376
  body: JSON.stringify({ voicemail_link: voicemailLink })
252
377
  });
253
378
  const result = yield response.json();
@@ -272,7 +397,10 @@ var DialpadResource = class {
272
397
  }
273
398
  const response = yield fetch(url.toString(), {
274
399
  method: "GET",
275
- headers: { Accept: "application/json" }
400
+ headers: {
401
+ Accept: "application/json",
402
+ "X-API-Key": this.apiKey
403
+ }
276
404
  });
277
405
  if (!response.ok) {
278
406
  throw new DialpadProxyError("GET", path, response.status);
@@ -287,7 +415,8 @@ var DialpadResource = class {
287
415
  method: "POST",
288
416
  headers: {
289
417
  "Content-Type": "application/json",
290
- Accept: "application/json"
418
+ Accept: "application/json",
419
+ "X-API-Key": this.apiKey
291
420
  },
292
421
  body: body !== void 0 ? JSON.stringify(body) : void 0
293
422
  });
@@ -305,7 +434,8 @@ var DialpadResource = class {
305
434
  method: "PUT",
306
435
  headers: {
307
436
  "Content-Type": "application/json",
308
- Accept: "application/json"
437
+ Accept: "application/json",
438
+ "X-API-Key": this.apiKey
309
439
  },
310
440
  body: body !== void 0 ? JSON.stringify(body) : void 0
311
441
  });
@@ -320,8 +450,8 @@ var DialpadResource = class {
320
450
  }
321
451
  };
322
452
  var MessagesResource = class {
323
- constructor(apiBaseUrl) {
324
- this.dialpad = new DialpadResource(apiBaseUrl);
453
+ constructor(apiBaseUrl, apiKey) {
454
+ this.dialpad = new DialpadResource(apiBaseUrl, apiKey);
325
455
  }
326
456
  };
327
457
  var DialpadProxyError = class extends Error {
@@ -463,6 +593,93 @@ var EhrProxyError = class extends Error {
463
593
  }
464
594
  };
465
595
 
596
+ // src/resources/notes.ts
597
+ var NotesError = class extends Error {
598
+ constructor(operation, status, message) {
599
+ super(message != null ? message : `Notes ${operation} failed (HTTP ${status})`);
600
+ this.name = "NotesError";
601
+ this.status = status;
602
+ }
603
+ };
604
+ var NotesResource = class {
605
+ constructor(apiBaseUrl, apiKey) {
606
+ this.baseUrl = apiBaseUrl;
607
+ this.apiKey = apiKey;
608
+ }
609
+ pushToElation(input) {
610
+ return __async(this, null, function* () {
611
+ const res = yield fetch(`${this.baseUrl}/api/notes/push-to-elation`, {
612
+ method: "POST",
613
+ headers: {
614
+ "Content-Type": "application/json",
615
+ Accept: "application/json",
616
+ "X-API-Key": this.apiKey
617
+ },
618
+ body: JSON.stringify(input)
619
+ });
620
+ if (!res.ok) {
621
+ const text = yield res.text().catch(() => "");
622
+ throw new NotesError("pushToElation", res.status, text.slice(0, 200));
623
+ }
624
+ return yield res.json();
625
+ });
626
+ }
627
+ };
628
+
629
+ // src/resources/patient-details.ts
630
+ var PatientDetailsError = class extends Error {
631
+ constructor(operation, status, message) {
632
+ super(message != null ? message : `Patient ${operation} failed (HTTP ${status})`);
633
+ this.name = "PatientDetailsError";
634
+ this.status = status;
635
+ }
636
+ };
637
+ var PatientDetailsResource = class {
638
+ constructor(apiBaseUrl, apiKey) {
639
+ this.baseUrl = apiBaseUrl;
640
+ this.apiKey = apiKey;
641
+ }
642
+ post(path, body) {
643
+ return __async(this, null, function* () {
644
+ const res = yield fetch(`${this.baseUrl}/api${path}`, {
645
+ method: "POST",
646
+ headers: {
647
+ "Content-Type": "application/json",
648
+ Accept: "application/json",
649
+ "X-API-Key": this.apiKey
650
+ },
651
+ body: JSON.stringify(body)
652
+ });
653
+ if (!res.ok) {
654
+ const text = yield res.text().catch(() => "");
655
+ throw new PatientDetailsError(path, res.status, text.slice(0, 200));
656
+ }
657
+ return yield res.json();
658
+ });
659
+ }
660
+ get(input) {
661
+ return __async(this, null, function* () {
662
+ return yield this.post("/patients/details", input);
663
+ });
664
+ }
665
+ getBasic(input) {
666
+ return __async(this, null, function* () {
667
+ return yield this.post(
668
+ "/patients/details/basic",
669
+ input
670
+ );
671
+ });
672
+ }
673
+ getMedical(elationId) {
674
+ return __async(this, null, function* () {
675
+ return yield this.post(
676
+ "/patients/details/medical",
677
+ { elationId }
678
+ );
679
+ });
680
+ }
681
+ };
682
+
466
683
  // src/resources/patients.ts
467
684
  var PatientResource = class {
468
685
  constructor(convexClient) {
@@ -543,6 +760,180 @@ var PatientResource = class {
543
760
  }
544
761
  };
545
762
 
763
+ // src/resources/reminders.ts
764
+ var RemindersResource = class {
765
+ constructor(convexClient) {
766
+ this.convex = convexClient;
767
+ }
768
+ /**
769
+ * Schedule a reminder to fire at `remindAt`. Returns the reminder id,
770
+ * which callers should store if they may want to cancel it later.
771
+ */
772
+ schedule(input) {
773
+ return __async(this, null, function* () {
774
+ const remindAt = input.remindAt instanceof Date ? input.remindAt.toISOString() : input.remindAt;
775
+ const result = yield this.convex.mutation(
776
+ "reminders:schedule",
777
+ {
778
+ conversationId: input.conversationId,
779
+ remindAt,
780
+ note: input.note,
781
+ createdBy: input.createdBy
782
+ }
783
+ );
784
+ return result;
785
+ });
786
+ }
787
+ /**
788
+ * Cancel a pending reminder. No-op if the reminder has already fired or
789
+ * been cancelled.
790
+ */
791
+ cancel(reminderId, cancelledBy) {
792
+ return __async(this, null, function* () {
793
+ return yield this.convex.mutation(
794
+ "reminders:cancel",
795
+ { reminderId, cancelledBy }
796
+ );
797
+ });
798
+ }
799
+ /**
800
+ * List reminders for a conversation (most recent first).
801
+ */
802
+ listByConversation(conversationId) {
803
+ return __async(this, null, function* () {
804
+ try {
805
+ const rows = yield this.convex.query(
806
+ "reminders:listByConversation",
807
+ { conversationId }
808
+ );
809
+ return rows != null ? rows : [];
810
+ } catch (e) {
811
+ return [];
812
+ }
813
+ });
814
+ }
815
+ };
816
+
817
+ // src/resources/tasks.ts
818
+ var TasksResource = class {
819
+ constructor(convexClient) {
820
+ this.convex = convexClient;
821
+ }
822
+ create(input) {
823
+ return __async(this, null, function* () {
824
+ return yield this.convex.mutation(
825
+ "tasks:create",
826
+ input
827
+ );
828
+ });
829
+ }
830
+ updateStatus(input) {
831
+ return __async(this, null, function* () {
832
+ return yield this.convex.mutation(
833
+ "tasks:updateStatus",
834
+ input
835
+ );
836
+ });
837
+ }
838
+ get(taskId) {
839
+ return __async(this, null, function* () {
840
+ try {
841
+ const row = yield this.convex.query(
842
+ "tasks:get",
843
+ { taskId }
844
+ );
845
+ return row != null ? row : null;
846
+ } catch (e) {
847
+ return null;
848
+ }
849
+ });
850
+ }
851
+ listByAssignee(assignedTo, options) {
852
+ return __async(this, null, function* () {
853
+ try {
854
+ const rows = yield this.convex.query(
855
+ "tasks:listByAssignee",
856
+ {
857
+ assignedTo,
858
+ status: options == null ? void 0 : options.status,
859
+ limit: options == null ? void 0 : options.limit
860
+ }
861
+ );
862
+ return rows != null ? rows : [];
863
+ } catch (e) {
864
+ return [];
865
+ }
866
+ });
867
+ }
868
+ listOpen(limit) {
869
+ return __async(this, null, function* () {
870
+ try {
871
+ const rows = yield this.convex.query(
872
+ "tasks:listOpen",
873
+ { limit }
874
+ );
875
+ return rows != null ? rows : [];
876
+ } catch (e) {
877
+ return [];
878
+ }
879
+ });
880
+ }
881
+ };
882
+
883
+ // src/resources/translation.ts
884
+ var TranslationError = class extends Error {
885
+ constructor(operation, status, message) {
886
+ super(message != null ? message : `Translation ${operation} failed (HTTP ${status})`);
887
+ this.name = "TranslationError";
888
+ this.status = status;
889
+ this.operation = operation;
890
+ }
891
+ };
892
+ var TranslationResource = class {
893
+ constructor(apiBaseUrl, apiKey) {
894
+ this.baseUrl = apiBaseUrl;
895
+ this.apiKey = apiKey;
896
+ }
897
+ post(path, body) {
898
+ return __async(this, null, function* () {
899
+ const url = `${this.baseUrl}/api${path}`;
900
+ const res = yield fetch(url, {
901
+ method: "POST",
902
+ headers: {
903
+ "Content-Type": "application/json",
904
+ Accept: "application/json",
905
+ "X-API-Key": this.apiKey
906
+ },
907
+ body: JSON.stringify(body)
908
+ });
909
+ if (!res.ok) {
910
+ const text = yield res.text().catch(() => "");
911
+ throw new TranslationError(path, res.status, text.slice(0, 200));
912
+ }
913
+ return yield res.json();
914
+ });
915
+ }
916
+ translate(input) {
917
+ return __async(this, null, function* () {
918
+ return yield this.post("/translation/translate", input);
919
+ });
920
+ }
921
+ translateBatch(input) {
922
+ return __async(this, null, function* () {
923
+ const response = yield this.post(
924
+ "/translation/translate-batch",
925
+ input
926
+ );
927
+ return response.results;
928
+ });
929
+ }
930
+ detect(text) {
931
+ return __async(this, null, function* () {
932
+ return yield this.post("/translation/detect", { text });
933
+ });
934
+ }
935
+ };
936
+
546
937
  // src/tracking/tracker.ts
547
938
  function generateUuidV7() {
548
939
  const now = Date.now();
@@ -681,7 +1072,7 @@ var Tracker = class {
681
1072
  method: "POST",
682
1073
  headers: {
683
1074
  "Content-Type": "application/json",
684
- Authorization: `Bearer ${this.config.apiKey}`
1075
+ "X-API-Key": this.config.apiKey
685
1076
  },
686
1077
  body: JSON.stringify({ events: batch })
687
1078
  });
@@ -763,7 +1154,17 @@ var TruthClient = class {
763
1154
  this.patients = new PatientResource(this.convex);
764
1155
  this.appointments = new AppointmentResource(this.convex);
765
1156
  this.ehr = new EhrResource(apiUrl);
766
- this.messages = new MessagesResource(apiUrl);
1157
+ this.messages = new MessagesResource(apiUrl, config.apiKey);
1158
+ this.reminders = new RemindersResource(this.convex);
1159
+ this.translation = new TranslationResource(apiUrl, config.apiKey);
1160
+ this.tasks = new TasksResource(this.convex);
1161
+ this.patientDetails = new PatientDetailsResource(apiUrl, config.apiKey);
1162
+ this.attachments = new AttachmentsResource(
1163
+ apiUrl,
1164
+ config.apiKey,
1165
+ this.convex
1166
+ );
1167
+ this.notes = new NotesResource(apiUrl, config.apiKey);
767
1168
  }
768
1169
  /**
769
1170
  * The resolved Truth API base URL for this environment.
@@ -905,6 +1306,8 @@ var ENVIRONMENTS = {
905
1306
  0 && (module.exports = {
906
1307
  AUTH_EVENTS,
907
1308
  AppointmentResource,
1309
+ AttachmentsError,
1310
+ AttachmentsResource,
908
1311
  CALL_EVENTS,
909
1312
  CONVERSATION_EVENTS,
910
1313
  DialpadProxyError,
@@ -916,13 +1319,21 @@ var ENVIRONMENTS = {
916
1319
  EhrResource,
917
1320
  MessagesResource,
918
1321
  NOTIFICATION_EVENTS,
1322
+ NotesError,
1323
+ NotesResource,
919
1324
  PROVIDER_EVENTS,
1325
+ PatientDetailsError,
1326
+ PatientDetailsResource,
920
1327
  PatientResource,
921
1328
  REMINDER_EVENTS,
1329
+ RemindersResource,
922
1330
  SECURITY_EVENTS,
923
1331
  TASK_EVENTS,
924
1332
  TRANSLATION_EVENTS,
1333
+ TasksResource,
925
1334
  Tracker,
1335
+ TranslationError,
1336
+ TranslationResource,
926
1337
  TruthClient,
927
1338
  generateUuidV7
928
1339
  });