@hipnation-truth/sdk 0.26.18 → 0.27.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
@@ -207,7 +207,6 @@ var AttachmentsError = class extends Error {
207
207
  var AttachmentsResource = class {
208
208
  constructor(apiBaseUrl, apiKey, convexClient, getAuthToken) {
209
209
  this.baseUrl = apiBaseUrl;
210
- this.apiKey = apiKey;
211
210
  this.auth = { apiKey, getAuthToken };
212
211
  this.convex = convexClient;
213
212
  }
@@ -638,7 +637,6 @@ var ConversationsResource = _ConversationsResource;
638
637
  var DialpadResource = class {
639
638
  constructor(apiBaseUrl, apiKey, getAuthToken) {
640
639
  this.baseUrl = apiBaseUrl;
641
- this.apiKey = apiKey;
642
640
  this.auth = { apiKey, getAuthToken };
643
641
  }
644
642
  /**
@@ -850,7 +848,6 @@ var MessagesResource = class {
850
848
  constructor(apiBaseUrl, apiKey, getAuthToken) {
851
849
  this.dialpad = new DialpadResource(apiBaseUrl, apiKey, getAuthToken);
852
850
  this.baseUrl = apiBaseUrl;
853
- this.apiKey = apiKey;
854
851
  this.auth = { apiKey, getAuthToken };
855
852
  }
856
853
  /**
@@ -1023,7 +1020,6 @@ var NotesError = class extends Error {
1023
1020
  var _NotesResource = class _NotesResource {
1024
1021
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1025
1022
  this.baseUrl = apiBaseUrl;
1026
- this.apiKey = apiKey;
1027
1023
  this.auth = { apiKey, getAuthToken };
1028
1024
  }
1029
1025
  post(path, body) {
@@ -1105,7 +1101,6 @@ var NotificationsError = class extends Error {
1105
1101
  var NotificationsResource = class {
1106
1102
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1107
1103
  this.baseUrl = apiBaseUrl;
1108
- this.apiKey = apiKey;
1109
1104
  this.auth = { apiKey, getAuthToken };
1110
1105
  }
1111
1106
  post(path, body) {
@@ -1278,7 +1273,6 @@ var PatientDetailsError = class extends Error {
1278
1273
  var PatientDetailsResource = class {
1279
1274
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1280
1275
  this.baseUrl = apiBaseUrl;
1281
- this.apiKey = apiKey;
1282
1276
  this.auth = { apiKey, getAuthToken };
1283
1277
  }
1284
1278
  post(path, body) {
@@ -1560,6 +1554,146 @@ var RemindersResource = class {
1560
1554
  }
1561
1555
  };
1562
1556
 
1557
+ // src/resources/reports.ts
1558
+ import { z } from "zod";
1559
+ var memberSchema = z.object({
1560
+ elationId: z.string(),
1561
+ name: z.string(),
1562
+ doctor: z.string().nullable(),
1563
+ status: z.enum(["activated", "outreach", "scheduled", "review", "data"]),
1564
+ membershipStart: z.string(),
1565
+ daysSinceMembershipStart: z.number(),
1566
+ activationDate: z.string().nullable(),
1567
+ futureApptDate: z.string().nullable(),
1568
+ reason: z.string().nullable(),
1569
+ hasLink: z.boolean()
1570
+ });
1571
+ var reportSchema = z.object({
1572
+ synthetic: z.boolean(),
1573
+ generatedAt: z.string(),
1574
+ employers: z.array(
1575
+ z.object({ id: z.string(), name: z.string(), activeMembers: z.number() })
1576
+ ),
1577
+ selected: z.object({
1578
+ employerId: z.string(),
1579
+ employerName: z.string(),
1580
+ kpis: z.object({
1581
+ active: z.number(),
1582
+ linked: z.number(),
1583
+ activated: z.number(),
1584
+ needsOutreach: z.number(),
1585
+ scheduled: z.number(),
1586
+ needsReview: z.number(),
1587
+ dataIssue: z.number(),
1588
+ activationRate: z.number()
1589
+ }),
1590
+ coverage: z.object({
1591
+ active: z.number(),
1592
+ linked: z.number(),
1593
+ unlinked: z.number(),
1594
+ pct: z.number()
1595
+ }),
1596
+ breakdown: z.array(
1597
+ z.object({
1598
+ status: z.enum([
1599
+ "activated",
1600
+ "outreach",
1601
+ "scheduled",
1602
+ "review",
1603
+ "data"
1604
+ ]),
1605
+ label: z.string(),
1606
+ count: z.number(),
1607
+ pct: z.number()
1608
+ })
1609
+ ),
1610
+ aging: z.array(
1611
+ z.object({
1612
+ bucket: z.string(),
1613
+ total: z.number(),
1614
+ outreach: z.number(),
1615
+ scheduled: z.number(),
1616
+ review: z.number()
1617
+ })
1618
+ ),
1619
+ doctors: z.array(
1620
+ z.object({
1621
+ name: z.string(),
1622
+ counts: z.object({
1623
+ outreach: z.number(),
1624
+ scheduled: z.number(),
1625
+ review: z.number(),
1626
+ data: z.number()
1627
+ }),
1628
+ members: z.array(memberSchema)
1629
+ })
1630
+ )
1631
+ }).nullable(),
1632
+ // True when the requested employer has no materialized report row yet
1633
+ // (ehr-sync's dailyHandler has not run for it). `selected` is null in that
1634
+ // case — the caller sees the employer roster but no report data to render.
1635
+ pending: z.boolean()
1636
+ });
1637
+ var ReportsError = class extends Error {
1638
+ /**
1639
+ * Wraps a failed reports HTTP call with the operation name and status
1640
+ * code so callers can branch on `status` without re-parsing the message.
1641
+ * Falls back to a generated message when the server response body is
1642
+ * empty or unreadable.
1643
+ */
1644
+ constructor(operation, status, message) {
1645
+ const trimmedMessage = message == null ? void 0 : message.trim();
1646
+ super(trimmedMessage || `Reports ${operation} failed (HTTP ${status})`);
1647
+ this.name = "ReportsError";
1648
+ this.status = status;
1649
+ }
1650
+ };
1651
+ var ReportsResource = class {
1652
+ /**
1653
+ * Captures the Truth API base URL and the auth inputs (API key + optional
1654
+ * user-token fetcher) needed to authenticate every request this resource
1655
+ * makes.
1656
+ */
1657
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1658
+ this.baseUrl = apiBaseUrl;
1659
+ this.auth = { apiKey, getAuthToken };
1660
+ }
1661
+ /**
1662
+ * Fetches the member activation report from GET /reports/member-activation,
1663
+ * optionally scoped to a single employer. Requires the user JWT (not just
1664
+ * the API key) since the server hardens this route to
1665
+ * `verifiedUserProcedure` for PHI access — throws via `ReportsError` on a
1666
+ * non-OK response, including the response body (truncated) when present.
1667
+ */
1668
+ memberActivation(params) {
1669
+ return __async(this, null, function* () {
1670
+ const url = new URL(`${this.baseUrl}/api/reports/member-activation`);
1671
+ if (params == null ? void 0 : params.employerId) {
1672
+ url.searchParams.set("employerId", params.employerId);
1673
+ }
1674
+ const res = yield fetch(url.toString(), {
1675
+ method: "GET",
1676
+ // PHI (member activation report) — REQUIRE the user JWT. The server
1677
+ // hardens this route to `verifiedUserProcedure`, so degrading to
1678
+ // key-only would 401. `requireUserToken` retries across the Clerk-
1679
+ // hydration gap and throws rather than silently sending key-only.
1680
+ headers: yield buildAuthHeaders(this.auth, {
1681
+ requireUserToken: true
1682
+ })
1683
+ });
1684
+ if (!res.ok) {
1685
+ const text = yield res.text().catch(() => "");
1686
+ throw new ReportsError(
1687
+ "member-activation",
1688
+ res.status,
1689
+ text.slice(0, 200)
1690
+ );
1691
+ }
1692
+ return yield res.json();
1693
+ });
1694
+ }
1695
+ };
1696
+
1563
1697
  // src/resources/tasks.ts
1564
1698
  var TasksResource = class {
1565
1699
  constructor(convexClient) {
@@ -1654,7 +1788,6 @@ var TranslationError = class extends Error {
1654
1788
  var TranslationResource = class {
1655
1789
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1656
1790
  this.baseUrl = apiBaseUrl;
1657
- this.apiKey = apiKey;
1658
1791
  this.auth = { apiKey, getAuthToken };
1659
1792
  }
1660
1793
  post(path, body) {
@@ -1974,6 +2107,14 @@ var CONVEX_URLS = {
1974
2107
  production: "https://gallant-gecko-217.convex.cloud"
1975
2108
  };
1976
2109
  var TruthClient = class {
2110
+ /**
2111
+ * Builds the Convex client and event tracker from `config`, then wires up
2112
+ * every resource (patients, appointments, EHR proxy, reports, etc.) so
2113
+ * each shares the same Convex connection / API base URL / auth token
2114
+ * fetcher. When running in a browser that supports web push and the
2115
+ * caller hasn't opted out, kicks off best-effort service-worker
2116
+ * registration and push subscription in the background.
2117
+ */
1977
2118
  constructor(config) {
1978
2119
  this._vapidPublicKey = null;
1979
2120
  this._webPushReady = null;
@@ -2017,6 +2158,11 @@ var TruthClient = class {
2017
2158
  this.convex,
2018
2159
  config.getAuthToken
2019
2160
  );
2161
+ this.reports = new ReportsResource(
2162
+ apiUrl,
2163
+ config.apiKey,
2164
+ config.getAuthToken
2165
+ );
2020
2166
  this.notes = new NotesResource(apiUrl, config.apiKey, config.getAuthToken);
2021
2167
  this.physicians = new PhysiciansResource(this.convex);
2022
2168
  this.notifications = new NotificationsResource(
@@ -2037,9 +2183,11 @@ var TruthClient = class {
2037
2183
  this._webPushReady = this.initWebPush();
2038
2184
  }
2039
2185
  }
2186
+ /** The VAPID public key fetched during web-push init, or `null` until `webPushReady` resolves (or if push is unsupported/disabled). */
2040
2187
  get vapidPublicKey() {
2041
2188
  return this._vapidPublicKey;
2042
2189
  }
2190
+ /** 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). */
2043
2191
  get webPushReady() {
2044
2192
  return this._webPushReady;
2045
2193
  }
@@ -2066,6 +2214,14 @@ var TruthClient = class {
2066
2214
  }
2067
2215
  });
2068
2216
  }
2217
+ /**
2218
+ * Best-effort web-push bootstrap: waits for auth (if configured), fetches
2219
+ * the VAPID key, registers the service worker, subscribes to push, and
2220
+ * registers the device with a placeholder `__pending__` userId (the
2221
+ * backend reconciles this once the real user is known). Any failure
2222
+ * along the way is swallowed — push notifications are opportunistic and
2223
+ * must never break client construction.
2224
+ */
2069
2225
  initWebPush() {
2070
2226
  return __async(this, null, function* () {
2071
2227
  try {
@@ -2256,6 +2412,8 @@ export {
2256
2412
  PhysiciansResource,
2257
2413
  REMINDER_EVENTS,
2258
2414
  RemindersResource,
2415
+ ReportsError,
2416
+ ReportsResource,
2259
2417
  SECURITY_EVENTS,
2260
2418
  TASK_EVENTS,
2261
2419
  TRANSLATION_EVENTS,