@hipnation-truth/sdk 0.1.6 → 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.mjs CHANGED
@@ -86,10 +86,95 @@ var AppointmentResource = class {
86
86
  }
87
87
  };
88
88
 
89
+ // src/resources/attachments.ts
90
+ var AttachmentsError = class extends Error {
91
+ constructor(operation, status, message) {
92
+ super(message != null ? message : `Attachment ${operation} failed (HTTP ${status})`);
93
+ this.name = "AttachmentsError";
94
+ this.status = status;
95
+ }
96
+ };
97
+ var AttachmentsResource = class {
98
+ constructor(apiBaseUrl, apiKey, convexClient) {
99
+ this.baseUrl = apiBaseUrl;
100
+ this.apiKey = apiKey;
101
+ this.convex = convexClient;
102
+ }
103
+ post(path, body) {
104
+ return __async(this, null, function* () {
105
+ const res = yield fetch(`${this.baseUrl}/api${path}`, {
106
+ method: "POST",
107
+ headers: {
108
+ "Content-Type": "application/json",
109
+ Accept: "application/json",
110
+ "X-API-Key": this.apiKey
111
+ },
112
+ body: JSON.stringify(body)
113
+ });
114
+ if (!res.ok) {
115
+ const text = yield res.text().catch(() => "");
116
+ throw new AttachmentsError(path, res.status, text.slice(0, 200));
117
+ }
118
+ return yield res.json();
119
+ });
120
+ }
121
+ createUploadUrl(input) {
122
+ return __async(this, null, function* () {
123
+ return yield this.post(
124
+ "/attachments/upload-url",
125
+ input
126
+ );
127
+ });
128
+ }
129
+ getDownloadUrl(s3Key, expiresIn) {
130
+ return __async(this, null, function* () {
131
+ return yield this.post("/attachments/download-url", {
132
+ s3Key,
133
+ expiresIn
134
+ });
135
+ });
136
+ }
137
+ record(input) {
138
+ return __async(this, null, function* () {
139
+ return yield this.convex.mutation(
140
+ "attachments:record",
141
+ input
142
+ );
143
+ });
144
+ }
145
+ get(attachmentId) {
146
+ return __async(this, null, function* () {
147
+ try {
148
+ const row = yield this.convex.query(
149
+ "attachments:getById",
150
+ { attachmentId }
151
+ );
152
+ return row != null ? row : null;
153
+ } catch (e) {
154
+ return null;
155
+ }
156
+ });
157
+ }
158
+ listByConversation(conversationId) {
159
+ return __async(this, null, function* () {
160
+ try {
161
+ const rows = yield this.convex.query(
162
+ "attachments:listByConversation",
163
+ { conversationId }
164
+ );
165
+ return rows != null ? rows : [];
166
+ } catch (e) {
167
+ return [];
168
+ }
169
+ });
170
+ }
171
+ };
172
+
89
173
  // src/resources/dialpad.ts
90
174
  var DialpadResource = class {
91
- constructor(apiBaseUrl) {
175
+ constructor(apiBaseUrl, apiKey) {
92
176
  this.baseUrl = apiBaseUrl;
177
+ this.apiKey = apiKey;
93
178
  }
94
179
  /**
95
180
  * Send an SMS or MMS message via Dialpad.
@@ -122,6 +207,33 @@ var DialpadResource = class {
122
207
  yield this.put(`/call/${callId}/actions/hangup`);
123
208
  });
124
209
  }
210
+ /**
211
+ * Alias for `hangupCall` — mirrors the CommHub `endCall` action name so
212
+ * the SDK swap is a direct rename.
213
+ */
214
+ endCall(callId) {
215
+ return __async(this, null, function* () {
216
+ yield this.hangupCall(callId);
217
+ });
218
+ }
219
+ /**
220
+ * Send an MMS with a pre-uploaded attachment. Takes the S3 key returned
221
+ * by `client.attachments.createUploadUrl(...)` + PUT, fetches a short-
222
+ * lived download URL, and hands it to Dialpad as `media[]`.
223
+ *
224
+ * Replaces CommHub's `sendAttachment` Hasura Action (which stored bytes
225
+ * as base64 in Postgres and served them through a GET endpoint).
226
+ */
227
+ sendAttachmentWithUrl(params) {
228
+ return __async(this, null, function* () {
229
+ return this.sendSms({
230
+ from_number: params.from_number,
231
+ to_number: params.to_number,
232
+ message: params.message,
233
+ media: [params.mediaUrl]
234
+ });
235
+ });
236
+ }
125
237
  /**
126
238
  * Get the status of a call.
127
239
  */
@@ -203,7 +315,10 @@ var DialpadResource = class {
203
315
  const url = `${this.baseUrl}/api/messages/dialpad/voicemail/authenticate`;
204
316
  const response = yield fetch(url, {
205
317
  method: "POST",
206
- headers: { "Content-Type": "application/json" },
318
+ headers: {
319
+ "Content-Type": "application/json",
320
+ "X-API-Key": this.apiKey
321
+ },
207
322
  body: JSON.stringify({ voicemail_link: voicemailLink })
208
323
  });
209
324
  const result = yield response.json();
@@ -228,7 +343,10 @@ var DialpadResource = class {
228
343
  }
229
344
  const response = yield fetch(url.toString(), {
230
345
  method: "GET",
231
- headers: { Accept: "application/json" }
346
+ headers: {
347
+ Accept: "application/json",
348
+ "X-API-Key": this.apiKey
349
+ }
232
350
  });
233
351
  if (!response.ok) {
234
352
  throw new DialpadProxyError("GET", path, response.status);
@@ -243,7 +361,8 @@ var DialpadResource = class {
243
361
  method: "POST",
244
362
  headers: {
245
363
  "Content-Type": "application/json",
246
- Accept: "application/json"
364
+ Accept: "application/json",
365
+ "X-API-Key": this.apiKey
247
366
  },
248
367
  body: body !== void 0 ? JSON.stringify(body) : void 0
249
368
  });
@@ -261,7 +380,8 @@ var DialpadResource = class {
261
380
  method: "PUT",
262
381
  headers: {
263
382
  "Content-Type": "application/json",
264
- Accept: "application/json"
383
+ Accept: "application/json",
384
+ "X-API-Key": this.apiKey
265
385
  },
266
386
  body: body !== void 0 ? JSON.stringify(body) : void 0
267
387
  });
@@ -276,8 +396,8 @@ var DialpadResource = class {
276
396
  }
277
397
  };
278
398
  var MessagesResource = class {
279
- constructor(apiBaseUrl) {
280
- this.dialpad = new DialpadResource(apiBaseUrl);
399
+ constructor(apiBaseUrl, apiKey) {
400
+ this.dialpad = new DialpadResource(apiBaseUrl, apiKey);
281
401
  }
282
402
  };
283
403
  var DialpadProxyError = class extends Error {
@@ -419,6 +539,93 @@ var EhrProxyError = class extends Error {
419
539
  }
420
540
  };
421
541
 
542
+ // src/resources/notes.ts
543
+ var NotesError = class extends Error {
544
+ constructor(operation, status, message) {
545
+ super(message != null ? message : `Notes ${operation} failed (HTTP ${status})`);
546
+ this.name = "NotesError";
547
+ this.status = status;
548
+ }
549
+ };
550
+ var NotesResource = class {
551
+ constructor(apiBaseUrl, apiKey) {
552
+ this.baseUrl = apiBaseUrl;
553
+ this.apiKey = apiKey;
554
+ }
555
+ pushToElation(input) {
556
+ return __async(this, null, function* () {
557
+ const res = yield fetch(`${this.baseUrl}/api/notes/push-to-elation`, {
558
+ method: "POST",
559
+ headers: {
560
+ "Content-Type": "application/json",
561
+ Accept: "application/json",
562
+ "X-API-Key": this.apiKey
563
+ },
564
+ body: JSON.stringify(input)
565
+ });
566
+ if (!res.ok) {
567
+ const text = yield res.text().catch(() => "");
568
+ throw new NotesError("pushToElation", res.status, text.slice(0, 200));
569
+ }
570
+ return yield res.json();
571
+ });
572
+ }
573
+ };
574
+
575
+ // src/resources/patient-details.ts
576
+ var PatientDetailsError = class extends Error {
577
+ constructor(operation, status, message) {
578
+ super(message != null ? message : `Patient ${operation} failed (HTTP ${status})`);
579
+ this.name = "PatientDetailsError";
580
+ this.status = status;
581
+ }
582
+ };
583
+ var PatientDetailsResource = class {
584
+ constructor(apiBaseUrl, apiKey) {
585
+ this.baseUrl = apiBaseUrl;
586
+ this.apiKey = apiKey;
587
+ }
588
+ post(path, body) {
589
+ return __async(this, null, function* () {
590
+ const res = yield fetch(`${this.baseUrl}/api${path}`, {
591
+ method: "POST",
592
+ headers: {
593
+ "Content-Type": "application/json",
594
+ Accept: "application/json",
595
+ "X-API-Key": this.apiKey
596
+ },
597
+ body: JSON.stringify(body)
598
+ });
599
+ if (!res.ok) {
600
+ const text = yield res.text().catch(() => "");
601
+ throw new PatientDetailsError(path, res.status, text.slice(0, 200));
602
+ }
603
+ return yield res.json();
604
+ });
605
+ }
606
+ get(input) {
607
+ return __async(this, null, function* () {
608
+ return yield this.post("/patients/details", input);
609
+ });
610
+ }
611
+ getBasic(input) {
612
+ return __async(this, null, function* () {
613
+ return yield this.post(
614
+ "/patients/details/basic",
615
+ input
616
+ );
617
+ });
618
+ }
619
+ getMedical(elationId) {
620
+ return __async(this, null, function* () {
621
+ return yield this.post(
622
+ "/patients/details/medical",
623
+ { elationId }
624
+ );
625
+ });
626
+ }
627
+ };
628
+
422
629
  // src/resources/patients.ts
423
630
  var PatientResource = class {
424
631
  constructor(convexClient) {
@@ -499,6 +706,180 @@ var PatientResource = class {
499
706
  }
500
707
  };
501
708
 
709
+ // src/resources/reminders.ts
710
+ var RemindersResource = class {
711
+ constructor(convexClient) {
712
+ this.convex = convexClient;
713
+ }
714
+ /**
715
+ * Schedule a reminder to fire at `remindAt`. Returns the reminder id,
716
+ * which callers should store if they may want to cancel it later.
717
+ */
718
+ schedule(input) {
719
+ return __async(this, null, function* () {
720
+ const remindAt = input.remindAt instanceof Date ? input.remindAt.toISOString() : input.remindAt;
721
+ const result = yield this.convex.mutation(
722
+ "reminders:schedule",
723
+ {
724
+ conversationId: input.conversationId,
725
+ remindAt,
726
+ note: input.note,
727
+ createdBy: input.createdBy
728
+ }
729
+ );
730
+ return result;
731
+ });
732
+ }
733
+ /**
734
+ * Cancel a pending reminder. No-op if the reminder has already fired or
735
+ * been cancelled.
736
+ */
737
+ cancel(reminderId, cancelledBy) {
738
+ return __async(this, null, function* () {
739
+ return yield this.convex.mutation(
740
+ "reminders:cancel",
741
+ { reminderId, cancelledBy }
742
+ );
743
+ });
744
+ }
745
+ /**
746
+ * List reminders for a conversation (most recent first).
747
+ */
748
+ listByConversation(conversationId) {
749
+ return __async(this, null, function* () {
750
+ try {
751
+ const rows = yield this.convex.query(
752
+ "reminders:listByConversation",
753
+ { conversationId }
754
+ );
755
+ return rows != null ? rows : [];
756
+ } catch (e) {
757
+ return [];
758
+ }
759
+ });
760
+ }
761
+ };
762
+
763
+ // src/resources/tasks.ts
764
+ var TasksResource = class {
765
+ constructor(convexClient) {
766
+ this.convex = convexClient;
767
+ }
768
+ create(input) {
769
+ return __async(this, null, function* () {
770
+ return yield this.convex.mutation(
771
+ "tasks:create",
772
+ input
773
+ );
774
+ });
775
+ }
776
+ updateStatus(input) {
777
+ return __async(this, null, function* () {
778
+ return yield this.convex.mutation(
779
+ "tasks:updateStatus",
780
+ input
781
+ );
782
+ });
783
+ }
784
+ get(taskId) {
785
+ return __async(this, null, function* () {
786
+ try {
787
+ const row = yield this.convex.query(
788
+ "tasks:get",
789
+ { taskId }
790
+ );
791
+ return row != null ? row : null;
792
+ } catch (e) {
793
+ return null;
794
+ }
795
+ });
796
+ }
797
+ listByAssignee(assignedTo, options) {
798
+ return __async(this, null, function* () {
799
+ try {
800
+ const rows = yield this.convex.query(
801
+ "tasks:listByAssignee",
802
+ {
803
+ assignedTo,
804
+ status: options == null ? void 0 : options.status,
805
+ limit: options == null ? void 0 : options.limit
806
+ }
807
+ );
808
+ return rows != null ? rows : [];
809
+ } catch (e) {
810
+ return [];
811
+ }
812
+ });
813
+ }
814
+ listOpen(limit) {
815
+ return __async(this, null, function* () {
816
+ try {
817
+ const rows = yield this.convex.query(
818
+ "tasks:listOpen",
819
+ { limit }
820
+ );
821
+ return rows != null ? rows : [];
822
+ } catch (e) {
823
+ return [];
824
+ }
825
+ });
826
+ }
827
+ };
828
+
829
+ // src/resources/translation.ts
830
+ var TranslationError = class extends Error {
831
+ constructor(operation, status, message) {
832
+ super(message != null ? message : `Translation ${operation} failed (HTTP ${status})`);
833
+ this.name = "TranslationError";
834
+ this.status = status;
835
+ this.operation = operation;
836
+ }
837
+ };
838
+ var TranslationResource = class {
839
+ constructor(apiBaseUrl, apiKey) {
840
+ this.baseUrl = apiBaseUrl;
841
+ this.apiKey = apiKey;
842
+ }
843
+ post(path, body) {
844
+ return __async(this, null, function* () {
845
+ const url = `${this.baseUrl}/api${path}`;
846
+ const res = yield fetch(url, {
847
+ method: "POST",
848
+ headers: {
849
+ "Content-Type": "application/json",
850
+ Accept: "application/json",
851
+ "X-API-Key": this.apiKey
852
+ },
853
+ body: JSON.stringify(body)
854
+ });
855
+ if (!res.ok) {
856
+ const text = yield res.text().catch(() => "");
857
+ throw new TranslationError(path, res.status, text.slice(0, 200));
858
+ }
859
+ return yield res.json();
860
+ });
861
+ }
862
+ translate(input) {
863
+ return __async(this, null, function* () {
864
+ return yield this.post("/translation/translate", input);
865
+ });
866
+ }
867
+ translateBatch(input) {
868
+ return __async(this, null, function* () {
869
+ const response = yield this.post(
870
+ "/translation/translate-batch",
871
+ input
872
+ );
873
+ return response.results;
874
+ });
875
+ }
876
+ detect(text) {
877
+ return __async(this, null, function* () {
878
+ return yield this.post("/translation/detect", { text });
879
+ });
880
+ }
881
+ };
882
+
502
883
  // src/tracking/tracker.ts
503
884
  function generateUuidV7() {
504
885
  const now = Date.now();
@@ -719,7 +1100,17 @@ var TruthClient = class {
719
1100
  this.patients = new PatientResource(this.convex);
720
1101
  this.appointments = new AppointmentResource(this.convex);
721
1102
  this.ehr = new EhrResource(apiUrl);
722
- this.messages = new MessagesResource(apiUrl);
1103
+ this.messages = new MessagesResource(apiUrl, config.apiKey);
1104
+ this.reminders = new RemindersResource(this.convex);
1105
+ this.translation = new TranslationResource(apiUrl, config.apiKey);
1106
+ this.tasks = new TasksResource(this.convex);
1107
+ this.patientDetails = new PatientDetailsResource(apiUrl, config.apiKey);
1108
+ this.attachments = new AttachmentsResource(
1109
+ apiUrl,
1110
+ config.apiKey,
1111
+ this.convex
1112
+ );
1113
+ this.notes = new NotesResource(apiUrl, config.apiKey);
723
1114
  }
724
1115
  /**
725
1116
  * The resolved Truth API base URL for this environment.
@@ -860,6 +1251,8 @@ var ENVIRONMENTS = {
860
1251
  export {
861
1252
  AUTH_EVENTS,
862
1253
  AppointmentResource,
1254
+ AttachmentsError,
1255
+ AttachmentsResource,
863
1256
  CALL_EVENTS,
864
1257
  CONVERSATION_EVENTS,
865
1258
  DialpadProxyError,
@@ -871,13 +1264,21 @@ export {
871
1264
  EhrResource,
872
1265
  MessagesResource,
873
1266
  NOTIFICATION_EVENTS,
1267
+ NotesError,
1268
+ NotesResource,
874
1269
  PROVIDER_EVENTS,
1270
+ PatientDetailsError,
1271
+ PatientDetailsResource,
875
1272
  PatientResource,
876
1273
  REMINDER_EVENTS,
1274
+ RemindersResource,
877
1275
  SECURITY_EVENTS,
878
1276
  TASK_EVENTS,
879
1277
  TRANSLATION_EVENTS,
1278
+ TasksResource,
880
1279
  Tracker,
1280
+ TranslationError,
1281
+ TranslationResource,
881
1282
  TruthClient,
882
1283
  generateUuidV7
883
1284
  };