@hipnation-truth/sdk 0.26.19 → 0.28.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
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
8
  var __getProtoOf = Object.getPrototypeOf;
@@ -20,6 +22,7 @@ var __spreadValues = (a, b) => {
20
22
  }
21
23
  return a;
22
24
  };
25
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
26
  var __export = (target, all) => {
24
27
  for (var name in all)
25
28
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -64,6 +67,8 @@ __export(src_exports, {
64
67
  AttachmentsResource: () => AttachmentsResource,
65
68
  CALL_EVENTS: () => CALL_EVENTS,
66
69
  CONVERSATION_EVENTS: () => CONVERSATION_EVENTS,
70
+ CareInboxError: () => CareInboxError,
71
+ CareInboxResource: () => CareInboxResource,
67
72
  ConversationsError: () => ConversationsError,
68
73
  ConversationsResource: () => ConversationsResource,
69
74
  DialpadProxyError: () => DialpadProxyError,
@@ -86,6 +91,8 @@ __export(src_exports, {
86
91
  PhysiciansResource: () => PhysiciansResource,
87
92
  REMINDER_EVENTS: () => REMINDER_EVENTS,
88
93
  RemindersResource: () => RemindersResource,
94
+ ReportsError: () => ReportsError,
95
+ ReportsResource: () => ReportsResource,
89
96
  SECURITY_EVENTS: () => SECURITY_EVENTS,
90
97
  TASK_EVENTS: () => TASK_EVENTS,
91
98
  TRANSLATION_EVENTS: () => TRANSLATION_EVENTS,
@@ -95,12 +102,25 @@ __export(src_exports, {
95
102
  TranslationResource: () => TranslationResource,
96
103
  TruthClient: () => TruthClient,
97
104
  UserSettingsResource: () => UserSettingsResource,
105
+ careInboxErrorInfo: () => careInboxErrorInfo,
106
+ careInboxRefs: () => careInboxRefs,
107
+ createCareInboxSource: () => createCareInboxSource,
98
108
  generateUuidV7: () => generateUuidV7,
109
+ isCareInboxError: () => isCareInboxError,
99
110
  isWebPushSupported: () => isWebPushSupported,
100
111
  onServiceWorkerMessage: () => onServiceWorkerMessage,
101
112
  registerServiceWorker: () => registerServiceWorker,
102
113
  subscribeToPush: () => subscribeToPush,
103
- subscriptionToJSON: () => subscriptionToJSON
114
+ subscriptionToJSON: () => subscriptionToJSON,
115
+ toCareInboxError: () => toCareInboxError,
116
+ toEmailMailbox: () => toEmailMailbox,
117
+ toEmailMessage: () => toEmailMessage,
118
+ toEmailThreadDetail: () => toEmailThreadDetail,
119
+ toEmailThreadSummary: () => toEmailThreadSummary,
120
+ toMailboxAccess: () => toMailboxAccess,
121
+ toMarkReadResult: () => toMarkReadResult,
122
+ toThreadPage: () => toThreadPage,
123
+ toUnlinkedMessagePage: () => toUnlinkedMessagePage
104
124
  });
105
125
  module.exports = __toCommonJS(src_exports);
106
126
 
@@ -272,7 +292,6 @@ var AttachmentsError = class extends Error {
272
292
  var AttachmentsResource = class {
273
293
  constructor(apiBaseUrl, apiKey, convexClient, getAuthToken) {
274
294
  this.baseUrl = apiBaseUrl;
275
- this.apiKey = apiKey;
276
295
  this.auth = { apiKey, getAuthToken };
277
296
  this.convex = convexClient;
278
297
  }
@@ -418,6 +437,304 @@ var AttachmentsResource = class {
418
437
  }
419
438
  };
420
439
 
440
+ // src/resources/care-inbox.ts
441
+ var NO_PARTICIPANT = { address: "", name: null };
442
+ function participant(p) {
443
+ return p ? { address: p.address, name: p.name } : __spreadValues({}, NO_PARTICIPANT);
444
+ }
445
+ function toEmailMessage(m) {
446
+ var _a, _b;
447
+ return {
448
+ id: m.id,
449
+ threadId: (_a = m.threadId) != null ? _a : "",
450
+ mailboxId: m.mailboxId,
451
+ direction: m.direction,
452
+ from: participant(m.from),
453
+ to: m.to.map(participant),
454
+ subject: (_b = m.subject) != null ? _b : "",
455
+ sentAt: m.sentAt,
456
+ hasAttachments: m.hasAttachments,
457
+ linkedPatientId: m.linkedPatientId,
458
+ linkedPatientName: m.linkedPatientName,
459
+ bodyText: m.bodyText
460
+ };
461
+ }
462
+ function toEmailThreadSummary(t) {
463
+ var _a, _b;
464
+ return {
465
+ id: t.id,
466
+ mailboxId: t.mailboxId,
467
+ subject: (_a = t.subject) != null ? _a : "",
468
+ lastMessageAt: t.lastMessageAt,
469
+ lastDirection: (_b = t.lastDirection) != null ? _b : "inbound",
470
+ counterpart: participant(t.counterpart),
471
+ messageCount: t.messageCount,
472
+ unreadCount: t.unreadCount,
473
+ unlinkedCount: t.unlinkedCount,
474
+ linkedPatientName: t.linkedPatientName,
475
+ hasAttachments: t.hasAttachments
476
+ };
477
+ }
478
+ function toEmailMailbox(m) {
479
+ var _a;
480
+ return {
481
+ id: m.id,
482
+ address: (_a = m.address) != null ? _a : "",
483
+ displayName: m.displayName,
484
+ mode: m.mode,
485
+ canSend: m.canSend,
486
+ bodyVisible: m.bodyVisible
487
+ };
488
+ }
489
+ function toMailboxAccess(a) {
490
+ return { mailboxes: a.mailboxes.map(toEmailMailbox), canTriage: a.canTriage };
491
+ }
492
+ function toEmailThreadDetail(d) {
493
+ return {
494
+ summary: toEmailThreadSummary(d.summary),
495
+ mailbox: toEmailMailbox(d.mailbox),
496
+ messages: d.messages.map(toEmailMessage),
497
+ bodyVisible: d.bodyVisible,
498
+ patientContact: null
499
+ };
500
+ }
501
+ function toThreadPage(p) {
502
+ return {
503
+ threads: p.threads.map(toEmailThreadSummary),
504
+ nextCursor: p.nextCursor
505
+ };
506
+ }
507
+ function toUnlinkedMessagePage(p) {
508
+ return {
509
+ messages: p.messages.map(toEmailMessage),
510
+ nextCursor: p.nextCursor
511
+ };
512
+ }
513
+ function toMarkReadResult(r) {
514
+ return { thread: toEmailThreadSummary(r.thread) };
515
+ }
516
+ var REASONS = [
517
+ "send_disabled",
518
+ "not_triage",
519
+ "body_gated",
520
+ "unauthenticated"
521
+ ];
522
+ var CODES = [
523
+ "forbidden",
524
+ "not_found",
525
+ "offline",
526
+ "unavailable",
527
+ "validation",
528
+ "unknown"
529
+ ];
530
+ function asReason(value) {
531
+ return REASONS.includes(value) ? value : null;
532
+ }
533
+ function asCode(value) {
534
+ return CODES.includes(value) ? value : null;
535
+ }
536
+ var CareInboxError = class extends Error {
537
+ constructor(code, fields = {}) {
538
+ var _a, _b, _c, _d;
539
+ const reason = (_a = fields.reason) != null ? _a : null;
540
+ const status = (_b = fields.status) != null ? _b : 0;
541
+ super(
542
+ `Care inbox request failed: ${code}${reason ? ` (${reason})` : ""}${status ? ` HTTP ${status}` : ""}`
543
+ );
544
+ this.name = "CareInboxError";
545
+ this.code = code;
546
+ this.status = status;
547
+ this.rpcCode = (_c = fields.rpcCode) != null ? _c : null;
548
+ this.reason = reason;
549
+ this.detail = (_d = fields.detail) != null ? _d : null;
550
+ }
551
+ };
552
+ function codeForStatus(status, rpcCode) {
553
+ if (status === 0) {
554
+ if (rpcCode === "TRANSPORT" || rpcCode === "TIMEOUT") {
555
+ return "offline";
556
+ }
557
+ if (rpcCode === "NO_USER_TOKEN") {
558
+ return "forbidden";
559
+ }
560
+ return "unknown";
561
+ }
562
+ if (status === 400) {
563
+ return "validation";
564
+ }
565
+ if (status === 401 || status === 403) {
566
+ return "forbidden";
567
+ }
568
+ if (status === 404) {
569
+ return "not_found";
570
+ }
571
+ if (status === 503) {
572
+ return "unavailable";
573
+ }
574
+ return "unknown";
575
+ }
576
+ function httpError(fields) {
577
+ var _a;
578
+ const unauthenticated = fields.status === 401 || fields.rpcCode === "NO_USER_TOKEN";
579
+ return new CareInboxError(codeForStatus(fields.status, fields.rpcCode), __spreadProps(__spreadValues({}, fields), {
580
+ reason: (_a = fields.reason) != null ? _a : unauthenticated ? "unauthenticated" : null
581
+ }));
582
+ }
583
+ function isCareInboxError(value) {
584
+ return value instanceof Error && asCode(value.code) !== null;
585
+ }
586
+ function toCareInboxError(value) {
587
+ if (value instanceof CareInboxError) {
588
+ return value;
589
+ }
590
+ const data = value && typeof value === "object" ? value.data : void 0;
591
+ if (data && typeof data === "object") {
592
+ const { code, reason } = data;
593
+ const known = asCode(code);
594
+ if (known) {
595
+ return new CareInboxError(known, { reason: asReason(reason) });
596
+ }
597
+ }
598
+ if (isCareInboxError(value)) {
599
+ const v = value;
600
+ return new CareInboxError(value.code, {
601
+ status: typeof v.status === "number" && Number.isInteger(v.status) && v.status >= 0 ? v.status : 0,
602
+ rpcCode: typeof v.rpcCode === "string" ? v.rpcCode : null,
603
+ reason: asReason(v.reason),
604
+ detail: typeof v.detail === "string" ? v.detail : null
605
+ });
606
+ }
607
+ return new CareInboxError("unknown");
608
+ }
609
+ function careInboxErrorInfo(err) {
610
+ const e = toCareInboxError(err);
611
+ return { code: e.code, reason: e.reason };
612
+ }
613
+ function newRequestId() {
614
+ const c = globalThis.crypto;
615
+ if (c && typeof c.randomUUID === "function") {
616
+ return c.randomUUID();
617
+ }
618
+ const bytes = new Uint8Array(16);
619
+ if (c && typeof c.getRandomValues === "function") {
620
+ c.getRandomValues(bytes);
621
+ } else {
622
+ for (let i = 0; i < bytes.length; i++) {
623
+ bytes[i] = Math.floor(Math.random() * 256);
624
+ }
625
+ }
626
+ bytes[6] = bytes[6] & 15 | 64;
627
+ bytes[8] = bytes[8] & 63 | 128;
628
+ const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(
629
+ ""
630
+ );
631
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
632
+ }
633
+ var _CareInboxResource = class _CareInboxResource {
634
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
635
+ this.baseUrl = apiBaseUrl;
636
+ this.auth = { apiKey, getAuthToken };
637
+ }
638
+ /** Link one message to a patient (triage only). */
639
+ linkMessage(input) {
640
+ return __async(this, null, function* () {
641
+ var _a;
642
+ return this.post("/care-inbox/link", {
643
+ messageId: input.messageId,
644
+ patientId: input.patientId,
645
+ requestId: (_a = input.requestId) != null ? _a : newRequestId()
646
+ });
647
+ });
648
+ }
649
+ /** Undo a manual link (triage only). */
650
+ unlinkMessage(input) {
651
+ return __async(this, null, function* () {
652
+ var _a;
653
+ return this.post("/care-inbox/unlink", {
654
+ messageId: input.messageId,
655
+ requestId: (_a = input.requestId) != null ? _a : newRequestId()
656
+ });
657
+ });
658
+ }
659
+ /** Reply into a thread. This build always rejects 403 `send_disabled`. */
660
+ replyToThread(input) {
661
+ return __async(this, null, function* () {
662
+ return this.post("/care-inbox/outbound/thread-reply", {
663
+ threadId: input.threadId,
664
+ body: input.body,
665
+ clientRequestId: input.clientRequestId
666
+ });
667
+ });
668
+ }
669
+ /** Start a new email. This build always rejects 403 `send_disabled`. */
670
+ composeEmail(input) {
671
+ return __async(this, null, function* () {
672
+ return this.post("/care-inbox/outbound/compose", __spreadProps(__spreadValues({
673
+ to: input.to,
674
+ subject: input.subject,
675
+ body: input.body
676
+ }, input.patientId !== void 0 ? { patientId: input.patientId } : {}), {
677
+ mailboxId: input.mailboxId,
678
+ clientRequestId: input.clientRequestId
679
+ }));
680
+ });
681
+ }
682
+ post(path, body) {
683
+ return __async(this, null, function* () {
684
+ const fail = (rpcCode) => httpError({ status: 0, rpcCode, reason: null, detail: null });
685
+ if (!this.auth.apiKey) {
686
+ throw fail("NO_API_KEY");
687
+ }
688
+ let headers;
689
+ try {
690
+ headers = yield buildAuthHeaders(this.auth, {
691
+ json: true,
692
+ requireUserToken: true
693
+ });
694
+ } catch (e) {
695
+ throw fail("NO_USER_TOKEN");
696
+ }
697
+ const controller = new AbortController();
698
+ const timeout = setTimeout(
699
+ () => controller.abort(),
700
+ _CareInboxResource.REQUEST_TIMEOUT_MS
701
+ );
702
+ let res;
703
+ try {
704
+ res = yield fetch(`${this.baseUrl}/api${path}`, {
705
+ method: "POST",
706
+ headers,
707
+ body: JSON.stringify(body),
708
+ signal: controller.signal
709
+ });
710
+ } catch (err) {
711
+ const isAbort = err instanceof Error && (err.name === "AbortError" || err.name === "TimeoutError");
712
+ throw fail(isAbort ? "TIMEOUT" : "TRANSPORT");
713
+ } finally {
714
+ clearTimeout(timeout);
715
+ }
716
+ if (!res.ok) {
717
+ let parsed = {};
718
+ try {
719
+ parsed = yield res.json();
720
+ } catch (e) {
721
+ }
722
+ const data = parsed.data && typeof parsed.data === "object" ? parsed.data : {};
723
+ throw httpError({
724
+ status: res.status,
725
+ rpcCode: typeof parsed.code === "string" ? parsed.code : null,
726
+ reason: asReason(data.reason),
727
+ detail: typeof parsed.message === "string" ? parsed.message.slice(0, 200) : null
728
+ });
729
+ }
730
+ return yield res.json();
731
+ });
732
+ }
733
+ };
734
+ /** 30s upstream timeout — matches ConversationsResource. */
735
+ _CareInboxResource.REQUEST_TIMEOUT_MS = 3e4;
736
+ var CareInboxResource = _CareInboxResource;
737
+
421
738
  // src/resources/conversations.ts
422
739
  var ConversationsError = class extends Error {
423
740
  constructor(operation, status, message) {
@@ -580,6 +897,25 @@ var _ConversationsResource = class _ConversationsResource {
580
897
  );
581
898
  });
582
899
  }
900
+ /**
901
+ * Mark / unmark a conversation Urgent (conversation-level, shared by
902
+ * participants). Refused if `userId` is not a participant.
903
+ */
904
+ setUrgent(input) {
905
+ return __async(this, null, function* () {
906
+ if (!this.convex) {
907
+ throw new ConversationsError(
908
+ "/setUrgent",
909
+ 0,
910
+ "ConversationsResource missing Convex client"
911
+ );
912
+ }
913
+ return yield this.convex.mutation(
914
+ "conversations:setUrgent",
915
+ input
916
+ );
917
+ });
918
+ }
583
919
  /**
584
920
  * Zero unread on every conversation the user has reads for, except
585
921
  * those whose `providerPhone` is in `excludedProviderPhones`.
@@ -703,7 +1039,6 @@ var ConversationsResource = _ConversationsResource;
703
1039
  var DialpadResource = class {
704
1040
  constructor(apiBaseUrl, apiKey, getAuthToken) {
705
1041
  this.baseUrl = apiBaseUrl;
706
- this.apiKey = apiKey;
707
1042
  this.auth = { apiKey, getAuthToken };
708
1043
  }
709
1044
  /**
@@ -915,7 +1250,6 @@ var MessagesResource = class {
915
1250
  constructor(apiBaseUrl, apiKey, getAuthToken) {
916
1251
  this.dialpad = new DialpadResource(apiBaseUrl, apiKey, getAuthToken);
917
1252
  this.baseUrl = apiBaseUrl;
918
- this.apiKey = apiKey;
919
1253
  this.auth = { apiKey, getAuthToken };
920
1254
  }
921
1255
  /**
@@ -1088,7 +1422,6 @@ var NotesError = class extends Error {
1088
1422
  var _NotesResource = class _NotesResource {
1089
1423
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1090
1424
  this.baseUrl = apiBaseUrl;
1091
- this.apiKey = apiKey;
1092
1425
  this.auth = { apiKey, getAuthToken };
1093
1426
  }
1094
1427
  post(path, body) {
@@ -1144,6 +1477,11 @@ var _NotesResource = class _NotesResource {
1144
1477
  * physician/practice in Elation, posts the note, and writes an audit
1145
1478
  * row to `elationSyncEvents`. Replaces CommHub's `pushNotesToElation`
1146
1479
  * Hasura action.
1480
+ *
1481
+ * Auth: requires a user token. The server runs this route under
1482
+ * `verifiedUserProcedure`, so the API key alone is rejected with 401 —
1483
+ * configure `getAuthToken` on the client. `input.initiatedBy` is ignored;
1484
+ * the audit row's actor is the verified JWT `sub`.
1147
1485
  */
1148
1486
  pushConversationToElation(input) {
1149
1487
  return __async(this, null, function* () {
@@ -1170,7 +1508,6 @@ var NotificationsError = class extends Error {
1170
1508
  var NotificationsResource = class {
1171
1509
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1172
1510
  this.baseUrl = apiBaseUrl;
1173
- this.apiKey = apiKey;
1174
1511
  this.auth = { apiKey, getAuthToken };
1175
1512
  }
1176
1513
  post(path, body) {
@@ -1343,7 +1680,6 @@ var PatientDetailsError = class extends Error {
1343
1680
  var PatientDetailsResource = class {
1344
1681
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1345
1682
  this.baseUrl = apiBaseUrl;
1346
- this.apiKey = apiKey;
1347
1683
  this.auth = { apiKey, getAuthToken };
1348
1684
  }
1349
1685
  post(path, body) {
@@ -1625,6 +1961,151 @@ var RemindersResource = class {
1625
1961
  }
1626
1962
  };
1627
1963
 
1964
+ // src/resources/reports.ts
1965
+ var import_zod = require("zod");
1966
+ var memberSchema = import_zod.z.object({
1967
+ elationId: import_zod.z.string(),
1968
+ name: import_zod.z.string(),
1969
+ // T6: mirrors truth's member-activation-report.ts memberSchema (T5).
1970
+ // Optional/nullable so a comhub build against an older/newer server
1971
+ // payload still parses either way.
1972
+ lastName: import_zod.z.string().nullable().optional(),
1973
+ firstName: import_zod.z.string().nullable().optional(),
1974
+ doctor: import_zod.z.string().nullable(),
1975
+ status: import_zod.z.enum(["activated", "outreach", "scheduled", "review", "data"]),
1976
+ membershipStart: import_zod.z.string(),
1977
+ daysSinceMembershipStart: import_zod.z.number(),
1978
+ activationDate: import_zod.z.string().nullable(),
1979
+ futureApptDate: import_zod.z.string().nullable(),
1980
+ reason: import_zod.z.string().nullable(),
1981
+ hasLink: import_zod.z.boolean()
1982
+ });
1983
+ var reportSchema = import_zod.z.object({
1984
+ synthetic: import_zod.z.boolean(),
1985
+ generatedAt: import_zod.z.string(),
1986
+ employers: import_zod.z.array(
1987
+ import_zod.z.object({ id: import_zod.z.string(), name: import_zod.z.string(), activeMembers: import_zod.z.number() })
1988
+ ),
1989
+ selected: import_zod.z.object({
1990
+ employerId: import_zod.z.string(),
1991
+ employerName: import_zod.z.string(),
1992
+ kpis: import_zod.z.object({
1993
+ active: import_zod.z.number(),
1994
+ linked: import_zod.z.number(),
1995
+ activated: import_zod.z.number(),
1996
+ needsOutreach: import_zod.z.number(),
1997
+ scheduled: import_zod.z.number(),
1998
+ needsReview: import_zod.z.number(),
1999
+ dataIssue: import_zod.z.number(),
2000
+ activationRate: import_zod.z.number()
2001
+ }),
2002
+ coverage: import_zod.z.object({
2003
+ active: import_zod.z.number(),
2004
+ linked: import_zod.z.number(),
2005
+ unlinked: import_zod.z.number(),
2006
+ pct: import_zod.z.number()
2007
+ }),
2008
+ breakdown: import_zod.z.array(
2009
+ import_zod.z.object({
2010
+ status: import_zod.z.enum([
2011
+ "activated",
2012
+ "outreach",
2013
+ "scheduled",
2014
+ "review",
2015
+ "data"
2016
+ ]),
2017
+ label: import_zod.z.string(),
2018
+ count: import_zod.z.number(),
2019
+ pct: import_zod.z.number()
2020
+ })
2021
+ ),
2022
+ aging: import_zod.z.array(
2023
+ import_zod.z.object({
2024
+ bucket: import_zod.z.string(),
2025
+ total: import_zod.z.number(),
2026
+ outreach: import_zod.z.number(),
2027
+ scheduled: import_zod.z.number(),
2028
+ review: import_zod.z.number()
2029
+ })
2030
+ ),
2031
+ doctors: import_zod.z.array(
2032
+ import_zod.z.object({
2033
+ name: import_zod.z.string(),
2034
+ counts: import_zod.z.object({
2035
+ outreach: import_zod.z.number(),
2036
+ scheduled: import_zod.z.number(),
2037
+ review: import_zod.z.number(),
2038
+ data: import_zod.z.number()
2039
+ }),
2040
+ members: import_zod.z.array(memberSchema)
2041
+ })
2042
+ )
2043
+ }).nullable(),
2044
+ // True when the requested employer has no materialized report row yet
2045
+ // (ehr-sync's dailyHandler has not run for it). `selected` is null in that
2046
+ // case — the caller sees the employer roster but no report data to render.
2047
+ pending: import_zod.z.boolean()
2048
+ });
2049
+ var ReportsError = class extends Error {
2050
+ /**
2051
+ * Wraps a failed reports HTTP call with the operation name and status
2052
+ * code so callers can branch on `status` without re-parsing the message.
2053
+ * Falls back to a generated message when the server response body is
2054
+ * empty or unreadable.
2055
+ */
2056
+ constructor(operation, status, message) {
2057
+ const trimmedMessage = message == null ? void 0 : message.trim();
2058
+ super(trimmedMessage || `Reports ${operation} failed (HTTP ${status})`);
2059
+ this.name = "ReportsError";
2060
+ this.status = status;
2061
+ }
2062
+ };
2063
+ var ReportsResource = class {
2064
+ /**
2065
+ * Captures the Truth API base URL and the auth inputs (API key + optional
2066
+ * user-token fetcher) needed to authenticate every request this resource
2067
+ * makes.
2068
+ */
2069
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
2070
+ this.baseUrl = apiBaseUrl;
2071
+ this.auth = { apiKey, getAuthToken };
2072
+ }
2073
+ /**
2074
+ * Fetches the member activation report from GET /reports/member-activation,
2075
+ * optionally scoped to a single employer. Requires the user JWT (not just
2076
+ * the API key) since the server hardens this route to
2077
+ * `verifiedUserProcedure` for PHI access — throws via `ReportsError` on a
2078
+ * non-OK response, including the response body (truncated) when present.
2079
+ */
2080
+ memberActivation(params) {
2081
+ return __async(this, null, function* () {
2082
+ const url = new URL(`${this.baseUrl}/api/reports/member-activation`);
2083
+ if (params == null ? void 0 : params.employerId) {
2084
+ url.searchParams.set("employerId", params.employerId);
2085
+ }
2086
+ const res = yield fetch(url.toString(), {
2087
+ method: "GET",
2088
+ // PHI (member activation report) — REQUIRE the user JWT. The server
2089
+ // hardens this route to `verifiedUserProcedure`, so degrading to
2090
+ // key-only would 401. `requireUserToken` retries across the Clerk-
2091
+ // hydration gap and throws rather than silently sending key-only.
2092
+ headers: yield buildAuthHeaders(this.auth, {
2093
+ requireUserToken: true
2094
+ })
2095
+ });
2096
+ if (!res.ok) {
2097
+ const text = yield res.text().catch(() => "");
2098
+ throw new ReportsError(
2099
+ "member-activation",
2100
+ res.status,
2101
+ text.slice(0, 200)
2102
+ );
2103
+ }
2104
+ return yield res.json();
2105
+ });
2106
+ }
2107
+ };
2108
+
1628
2109
  // src/resources/tasks.ts
1629
2110
  var TasksResource = class {
1630
2111
  constructor(convexClient) {
@@ -1719,7 +2200,6 @@ var TranslationError = class extends Error {
1719
2200
  var TranslationResource = class {
1720
2201
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1721
2202
  this.baseUrl = apiBaseUrl;
1722
- this.apiKey = apiKey;
1723
2203
  this.auth = { apiKey, getAuthToken };
1724
2204
  }
1725
2205
  post(path, body) {
@@ -2039,6 +2519,14 @@ var CONVEX_URLS = {
2039
2519
  production: "https://gallant-gecko-217.convex.cloud"
2040
2520
  };
2041
2521
  var TruthClient = class {
2522
+ /**
2523
+ * Builds the Convex client and event tracker from `config`, then wires up
2524
+ * every resource (patients, appointments, EHR proxy, reports, etc.) so
2525
+ * each shares the same Convex connection / API base URL / auth token
2526
+ * fetcher. When running in a browser that supports web push and the
2527
+ * caller hasn't opted out, kicks off best-effort service-worker
2528
+ * registration and push subscription in the background.
2529
+ */
2042
2530
  constructor(config) {
2043
2531
  this._vapidPublicKey = null;
2044
2532
  this._webPushReady = null;
@@ -2082,6 +2570,11 @@ var TruthClient = class {
2082
2570
  this.convex,
2083
2571
  config.getAuthToken
2084
2572
  );
2573
+ this.reports = new ReportsResource(
2574
+ apiUrl,
2575
+ config.apiKey,
2576
+ config.getAuthToken
2577
+ );
2085
2578
  this.notes = new NotesResource(apiUrl, config.apiKey, config.getAuthToken);
2086
2579
  this.physicians = new PhysiciansResource(this.convex);
2087
2580
  this.notifications = new NotificationsResource(
@@ -2095,6 +2588,11 @@ var TruthClient = class {
2095
2588
  this.convex,
2096
2589
  config.getAuthToken
2097
2590
  );
2591
+ this.careInbox = new CareInboxResource(
2592
+ apiUrl,
2593
+ config.apiKey,
2594
+ config.getAuthToken
2595
+ );
2098
2596
  this.userSettings = new UserSettingsResource(this.convex);
2099
2597
  this._getAuthToken = config.getAuthToken;
2100
2598
  this._serviceWorkerPath = (_h = config.serviceWorkerPath) != null ? _h : "/truth-sw.js";
@@ -2102,9 +2600,11 @@ var TruthClient = class {
2102
2600
  this._webPushReady = this.initWebPush();
2103
2601
  }
2104
2602
  }
2603
+ /** The VAPID public key fetched during web-push init, or `null` until `webPushReady` resolves (or if push is unsupported/disabled). */
2105
2604
  get vapidPublicKey() {
2106
2605
  return this._vapidPublicKey;
2107
2606
  }
2607
+ /** Resolves once background web-push initialization (service worker registration + subscription) finishes; `null` if it was never started (SSR, unsupported browser, or opted out via config). */
2108
2608
  get webPushReady() {
2109
2609
  return this._webPushReady;
2110
2610
  }
@@ -2131,6 +2631,14 @@ var TruthClient = class {
2131
2631
  }
2132
2632
  });
2133
2633
  }
2634
+ /**
2635
+ * Best-effort web-push bootstrap: waits for auth (if configured), fetches
2636
+ * the VAPID key, registers the service worker, subscribes to push, and
2637
+ * registers the device with a placeholder `__pending__` userId (the
2638
+ * backend reconciles this once the real user is known). Any failure
2639
+ * along the way is swallowed — push notifications are opportunistic and
2640
+ * must never break client construction.
2641
+ */
2134
2642
  initWebPush() {
2135
2643
  return __async(this, null, function* () {
2136
2644
  try {
@@ -2226,6 +2734,103 @@ var TruthClient = class {
2226
2734
  }
2227
2735
  };
2228
2736
 
2737
+ // src/resources/care-inbox-source.ts
2738
+ var import_server2 = require("convex/server");
2739
+ var careInboxRefs = {
2740
+ listThreadsForUser: (0, import_server2.makeFunctionReference)("careInboxQueries:listThreadsForUser"),
2741
+ getThread: (0, import_server2.makeFunctionReference)("careInboxQueries:getThread"),
2742
+ listUnlinked: (0, import_server2.makeFunctionReference)("careInboxQueries:listUnlinked"),
2743
+ unreadEmailCount: (0, import_server2.makeFunctionReference)("careInboxQueries:unreadEmailCount"),
2744
+ listMailboxesForUser: (0, import_server2.makeFunctionReference)("careInboxQueries:listMailboxesForUser"),
2745
+ searchPatientsForLink: (0, import_server2.makeFunctionReference)("careInboxQueries:searchPatientsForLink"),
2746
+ markRead: (0, import_server2.makeFunctionReference)("careInboxReads:markRead"),
2747
+ openThreadBodies: (0, import_server2.makeFunctionReference)("careInboxReads:openThreadBodies")
2748
+ };
2749
+ function compactArgs(args) {
2750
+ const out = {};
2751
+ for (const [k, v] of Object.entries(args)) {
2752
+ if (v !== void 0) {
2753
+ out[k] = v;
2754
+ }
2755
+ }
2756
+ return out;
2757
+ }
2758
+ function guarded(run) {
2759
+ return __async(this, null, function* () {
2760
+ try {
2761
+ return yield run();
2762
+ } catch (err) {
2763
+ throw toCareInboxError(err);
2764
+ }
2765
+ });
2766
+ }
2767
+ function createCareInboxSource({
2768
+ convex,
2769
+ careInbox
2770
+ }) {
2771
+ const q = (ref, args) => convex.query(
2772
+ ref,
2773
+ compactArgs(args)
2774
+ );
2775
+ return {
2776
+ listThreads: (args = {}) => guarded(
2777
+ () => __async(null, null, function* () {
2778
+ return toThreadPage(
2779
+ yield q(careInboxRefs.listThreadsForUser, {
2780
+ mailboxId: args.mailboxId,
2781
+ filter: args.filter,
2782
+ cursor: args.cursor,
2783
+ limit: args.limit
2784
+ })
2785
+ );
2786
+ })
2787
+ ),
2788
+ getUnreadCount: (args = {}) => guarded(
2789
+ () => q(careInboxRefs.unreadEmailCount, {
2790
+ mailboxId: args.mailboxId
2791
+ })
2792
+ ),
2793
+ getThread: (threadId) => guarded(() => __async(null, null, function* () {
2794
+ const detail = yield q(
2795
+ careInboxRefs.getThread,
2796
+ { threadId }
2797
+ );
2798
+ if (!detail) {
2799
+ throw new CareInboxError("unavailable");
2800
+ }
2801
+ return toEmailThreadDetail(detail);
2802
+ })),
2803
+ listMailboxesForUser: () => guarded(
2804
+ () => __async(null, null, function* () {
2805
+ return toMailboxAccess(
2806
+ yield q(
2807
+ careInboxRefs.listMailboxesForUser,
2808
+ {}
2809
+ )
2810
+ );
2811
+ })
2812
+ ),
2813
+ searchPatientsForLink: (query) => guarded(
2814
+ () => q(careInboxRefs.searchPatientsForLink, {
2815
+ q: query
2816
+ })
2817
+ ),
2818
+ linkMessage: (args) => guarded(() => careInbox.linkMessage(args)),
2819
+ unlinkMessage: (args) => guarded(() => careInbox.unlinkMessage(args)),
2820
+ sendReply: (args) => guarded(() => careInbox.replyToThread(args)),
2821
+ sendEmail: (args) => guarded(() => careInbox.composeEmail(args)),
2822
+ markRead: ({ threadId }) => guarded(
2823
+ () => __async(null, null, function* () {
2824
+ return toMarkReadResult(
2825
+ yield convex.mutation(careInboxRefs.markRead, {
2826
+ threadId
2827
+ })
2828
+ );
2829
+ })
2830
+ )
2831
+ };
2832
+ }
2833
+
2229
2834
  // src/tracking/events.ts
2230
2835
  var CONVERSATION_EVENTS = {
2231
2836
  created: "conversation.created.v1",
@@ -2300,6 +2905,8 @@ var ENVIRONMENTS = {
2300
2905
  AttachmentsResource,
2301
2906
  CALL_EVENTS,
2302
2907
  CONVERSATION_EVENTS,
2908
+ CareInboxError,
2909
+ CareInboxResource,
2303
2910
  ConversationsError,
2304
2911
  ConversationsResource,
2305
2912
  DialpadProxyError,
@@ -2322,6 +2929,8 @@ var ENVIRONMENTS = {
2322
2929
  PhysiciansResource,
2323
2930
  REMINDER_EVENTS,
2324
2931
  RemindersResource,
2932
+ ReportsError,
2933
+ ReportsResource,
2325
2934
  SECURITY_EVENTS,
2326
2935
  TASK_EVENTS,
2327
2936
  TRANSLATION_EVENTS,
@@ -2331,11 +2940,24 @@ var ENVIRONMENTS = {
2331
2940
  TranslationResource,
2332
2941
  TruthClient,
2333
2942
  UserSettingsResource,
2943
+ careInboxErrorInfo,
2944
+ careInboxRefs,
2945
+ createCareInboxSource,
2334
2946
  generateUuidV7,
2947
+ isCareInboxError,
2335
2948
  isWebPushSupported,
2336
2949
  onServiceWorkerMessage,
2337
2950
  registerServiceWorker,
2338
2951
  subscribeToPush,
2339
- subscriptionToJSON
2952
+ subscriptionToJSON,
2953
+ toCareInboxError,
2954
+ toEmailMailbox,
2955
+ toEmailMessage,
2956
+ toEmailThreadDetail,
2957
+ toEmailThreadSummary,
2958
+ toMailboxAccess,
2959
+ toMarkReadResult,
2960
+ toThreadPage,
2961
+ toUnlinkedMessagePage
2340
2962
  });
2341
2963
  //# sourceMappingURL=index.js.map