@hipnation-truth/sdk 0.1.6 → 0.2.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.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();
@@ -577,8 +968,9 @@ function generateUuidV7() {
577
968
  var API_URLS = {
578
969
  local: "http://localhost:3000",
579
970
  staging: "https://app.sandbox.communication-hub.com",
971
+ stg: "https://app.sandbox.communication-hub.com",
580
972
  sandbox: "https://app.sandbox.communication-hub.com",
581
- uat: "https://app.sandbox.communication-hub.com",
973
+ uat: "https://app.truth.communication-hub.com",
582
974
  production: "https://app.truth.communication-hub.com"
583
975
  };
584
976
  var DEFAULT_BATCH_SIZE = 25;
@@ -740,8 +1132,9 @@ function sleep(ms) {
740
1132
  var CONVEX_URLS = {
741
1133
  local: "https://courteous-duck-623.convex.cloud",
742
1134
  staging: "https://courteous-duck-623.convex.cloud",
1135
+ stg: "https://courteous-duck-623.convex.cloud",
743
1136
  sandbox: "https://courteous-duck-623.convex.cloud",
744
- uat: "https://courteous-duck-623.convex.cloud",
1137
+ uat: "https://gallant-gecko-217.convex.cloud",
745
1138
  production: "https://gallant-gecko-217.convex.cloud"
746
1139
  };
747
1140
  var TruthClient = class {
@@ -763,7 +1156,17 @@ var TruthClient = class {
763
1156
  this.patients = new PatientResource(this.convex);
764
1157
  this.appointments = new AppointmentResource(this.convex);
765
1158
  this.ehr = new EhrResource(apiUrl);
766
- this.messages = new MessagesResource(apiUrl);
1159
+ this.messages = new MessagesResource(apiUrl, config.apiKey);
1160
+ this.reminders = new RemindersResource(this.convex);
1161
+ this.translation = new TranslationResource(apiUrl, config.apiKey);
1162
+ this.tasks = new TasksResource(this.convex);
1163
+ this.patientDetails = new PatientDetailsResource(apiUrl, config.apiKey);
1164
+ this.attachments = new AttachmentsResource(
1165
+ apiUrl,
1166
+ config.apiKey,
1167
+ this.convex
1168
+ );
1169
+ this.notes = new NotesResource(apiUrl, config.apiKey);
767
1170
  }
768
1171
  /**
769
1172
  * The resolved Truth API base URL for this environment.
@@ -897,6 +1300,7 @@ var EVENT_TYPES = {
897
1300
  var ENVIRONMENTS = {
898
1301
  local: "local",
899
1302
  staging: "staging",
1303
+ stg: "stg",
900
1304
  sandbox: "sandbox",
901
1305
  uat: "uat",
902
1306
  production: "production"
@@ -905,6 +1309,8 @@ var ENVIRONMENTS = {
905
1309
  0 && (module.exports = {
906
1310
  AUTH_EVENTS,
907
1311
  AppointmentResource,
1312
+ AttachmentsError,
1313
+ AttachmentsResource,
908
1314
  CALL_EVENTS,
909
1315
  CONVERSATION_EVENTS,
910
1316
  DialpadProxyError,
@@ -916,13 +1322,21 @@ var ENVIRONMENTS = {
916
1322
  EhrResource,
917
1323
  MessagesResource,
918
1324
  NOTIFICATION_EVENTS,
1325
+ NotesError,
1326
+ NotesResource,
919
1327
  PROVIDER_EVENTS,
1328
+ PatientDetailsError,
1329
+ PatientDetailsResource,
920
1330
  PatientResource,
921
1331
  REMINDER_EVENTS,
1332
+ RemindersResource,
922
1333
  SECURITY_EVENTS,
923
1334
  TASK_EVENTS,
924
1335
  TRANSLATION_EVENTS,
1336
+ TasksResource,
925
1337
  Tracker,
1338
+ TranslationError,
1339
+ TranslationResource,
926
1340
  TruthClient,
927
1341
  generateUuidV7
928
1342
  });