@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/react.js CHANGED
@@ -110,6 +110,7 @@ __export(react_exports, {
110
110
  usePhysicianByElationId: () => usePhysicianByElationId,
111
111
  usePhysiciansByElationIds: () => usePhysiciansByElationIds,
112
112
  useRemindersForConversations: () => useRemindersForConversations,
113
+ useSaveCallSummary: () => useSaveCallSummary,
113
114
  useTruth: () => useTruth,
114
115
  useTruthClient: () => useTruthClient,
115
116
  useTruthSdkContext: () => useTruthSdkContext,
@@ -122,7 +123,9 @@ __export(react_exports, {
122
123
  module.exports = __toCommonJS(react_exports);
123
124
 
124
125
  // src/react/calls.ts
126
+ var import_react4 = require("convex/react");
125
127
  var import_server2 = require("convex/server");
128
+ var import_react5 = require("react");
126
129
 
127
130
  // src/react/offline/use-persistent-query.ts
128
131
  var import_react_query3 = require("@convex-dev/react-query");
@@ -306,7 +309,6 @@ var AttachmentsError = class extends Error {
306
309
  var AttachmentsResource = class {
307
310
  constructor(apiBaseUrl, apiKey, convexClient, getAuthToken) {
308
311
  this.baseUrl = apiBaseUrl;
309
- this.apiKey = apiKey;
310
312
  this.auth = { apiKey, getAuthToken };
311
313
  this.convex = convexClient;
312
314
  }
@@ -737,7 +739,6 @@ var ConversationsResource = _ConversationsResource;
737
739
  var DialpadResource = class {
738
740
  constructor(apiBaseUrl, apiKey, getAuthToken) {
739
741
  this.baseUrl = apiBaseUrl;
740
- this.apiKey = apiKey;
741
742
  this.auth = { apiKey, getAuthToken };
742
743
  }
743
744
  /**
@@ -949,7 +950,6 @@ var MessagesResource = class {
949
950
  constructor(apiBaseUrl, apiKey, getAuthToken) {
950
951
  this.dialpad = new DialpadResource(apiBaseUrl, apiKey, getAuthToken);
951
952
  this.baseUrl = apiBaseUrl;
952
- this.apiKey = apiKey;
953
953
  this.auth = { apiKey, getAuthToken };
954
954
  }
955
955
  /**
@@ -1122,7 +1122,6 @@ var NotesError = class extends Error {
1122
1122
  var _NotesResource = class _NotesResource {
1123
1123
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1124
1124
  this.baseUrl = apiBaseUrl;
1125
- this.apiKey = apiKey;
1126
1125
  this.auth = { apiKey, getAuthToken };
1127
1126
  }
1128
1127
  post(path, body) {
@@ -1204,7 +1203,6 @@ var NotificationsError = class extends Error {
1204
1203
  var NotificationsResource = class {
1205
1204
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1206
1205
  this.baseUrl = apiBaseUrl;
1207
- this.apiKey = apiKey;
1208
1206
  this.auth = { apiKey, getAuthToken };
1209
1207
  }
1210
1208
  post(path, body) {
@@ -1377,7 +1375,6 @@ var PatientDetailsError = class extends Error {
1377
1375
  var PatientDetailsResource = class {
1378
1376
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1379
1377
  this.baseUrl = apiBaseUrl;
1380
- this.apiKey = apiKey;
1381
1378
  this.auth = { apiKey, getAuthToken };
1382
1379
  }
1383
1380
  post(path, body) {
@@ -1666,6 +1663,146 @@ var RemindersResource = class {
1666
1663
  }
1667
1664
  };
1668
1665
 
1666
+ // src/resources/reports.ts
1667
+ var import_zod = require("zod");
1668
+ var memberSchema = import_zod.z.object({
1669
+ elationId: import_zod.z.string(),
1670
+ name: import_zod.z.string(),
1671
+ doctor: import_zod.z.string().nullable(),
1672
+ status: import_zod.z.enum(["activated", "outreach", "scheduled", "review", "data"]),
1673
+ membershipStart: import_zod.z.string(),
1674
+ daysSinceMembershipStart: import_zod.z.number(),
1675
+ activationDate: import_zod.z.string().nullable(),
1676
+ futureApptDate: import_zod.z.string().nullable(),
1677
+ reason: import_zod.z.string().nullable(),
1678
+ hasLink: import_zod.z.boolean()
1679
+ });
1680
+ var reportSchema = import_zod.z.object({
1681
+ synthetic: import_zod.z.boolean(),
1682
+ generatedAt: import_zod.z.string(),
1683
+ employers: import_zod.z.array(
1684
+ import_zod.z.object({ id: import_zod.z.string(), name: import_zod.z.string(), activeMembers: import_zod.z.number() })
1685
+ ),
1686
+ selected: import_zod.z.object({
1687
+ employerId: import_zod.z.string(),
1688
+ employerName: import_zod.z.string(),
1689
+ kpis: import_zod.z.object({
1690
+ active: import_zod.z.number(),
1691
+ linked: import_zod.z.number(),
1692
+ activated: import_zod.z.number(),
1693
+ needsOutreach: import_zod.z.number(),
1694
+ scheduled: import_zod.z.number(),
1695
+ needsReview: import_zod.z.number(),
1696
+ dataIssue: import_zod.z.number(),
1697
+ activationRate: import_zod.z.number()
1698
+ }),
1699
+ coverage: import_zod.z.object({
1700
+ active: import_zod.z.number(),
1701
+ linked: import_zod.z.number(),
1702
+ unlinked: import_zod.z.number(),
1703
+ pct: import_zod.z.number()
1704
+ }),
1705
+ breakdown: import_zod.z.array(
1706
+ import_zod.z.object({
1707
+ status: import_zod.z.enum([
1708
+ "activated",
1709
+ "outreach",
1710
+ "scheduled",
1711
+ "review",
1712
+ "data"
1713
+ ]),
1714
+ label: import_zod.z.string(),
1715
+ count: import_zod.z.number(),
1716
+ pct: import_zod.z.number()
1717
+ })
1718
+ ),
1719
+ aging: import_zod.z.array(
1720
+ import_zod.z.object({
1721
+ bucket: import_zod.z.string(),
1722
+ total: import_zod.z.number(),
1723
+ outreach: import_zod.z.number(),
1724
+ scheduled: import_zod.z.number(),
1725
+ review: import_zod.z.number()
1726
+ })
1727
+ ),
1728
+ doctors: import_zod.z.array(
1729
+ import_zod.z.object({
1730
+ name: import_zod.z.string(),
1731
+ counts: import_zod.z.object({
1732
+ outreach: import_zod.z.number(),
1733
+ scheduled: import_zod.z.number(),
1734
+ review: import_zod.z.number(),
1735
+ data: import_zod.z.number()
1736
+ }),
1737
+ members: import_zod.z.array(memberSchema)
1738
+ })
1739
+ )
1740
+ }).nullable(),
1741
+ // True when the requested employer has no materialized report row yet
1742
+ // (ehr-sync's dailyHandler has not run for it). `selected` is null in that
1743
+ // case — the caller sees the employer roster but no report data to render.
1744
+ pending: import_zod.z.boolean()
1745
+ });
1746
+ var ReportsError = class extends Error {
1747
+ /**
1748
+ * Wraps a failed reports HTTP call with the operation name and status
1749
+ * code so callers can branch on `status` without re-parsing the message.
1750
+ * Falls back to a generated message when the server response body is
1751
+ * empty or unreadable.
1752
+ */
1753
+ constructor(operation, status, message) {
1754
+ const trimmedMessage = message == null ? void 0 : message.trim();
1755
+ super(trimmedMessage || `Reports ${operation} failed (HTTP ${status})`);
1756
+ this.name = "ReportsError";
1757
+ this.status = status;
1758
+ }
1759
+ };
1760
+ var ReportsResource = class {
1761
+ /**
1762
+ * Captures the Truth API base URL and the auth inputs (API key + optional
1763
+ * user-token fetcher) needed to authenticate every request this resource
1764
+ * makes.
1765
+ */
1766
+ constructor(apiBaseUrl, apiKey, getAuthToken) {
1767
+ this.baseUrl = apiBaseUrl;
1768
+ this.auth = { apiKey, getAuthToken };
1769
+ }
1770
+ /**
1771
+ * Fetches the member activation report from GET /reports/member-activation,
1772
+ * optionally scoped to a single employer. Requires the user JWT (not just
1773
+ * the API key) since the server hardens this route to
1774
+ * `verifiedUserProcedure` for PHI access — throws via `ReportsError` on a
1775
+ * non-OK response, including the response body (truncated) when present.
1776
+ */
1777
+ memberActivation(params) {
1778
+ return __async(this, null, function* () {
1779
+ const url = new URL(`${this.baseUrl}/api/reports/member-activation`);
1780
+ if (params == null ? void 0 : params.employerId) {
1781
+ url.searchParams.set("employerId", params.employerId);
1782
+ }
1783
+ const res = yield fetch(url.toString(), {
1784
+ method: "GET",
1785
+ // PHI (member activation report) — REQUIRE the user JWT. The server
1786
+ // hardens this route to `verifiedUserProcedure`, so degrading to
1787
+ // key-only would 401. `requireUserToken` retries across the Clerk-
1788
+ // hydration gap and throws rather than silently sending key-only.
1789
+ headers: yield buildAuthHeaders(this.auth, {
1790
+ requireUserToken: true
1791
+ })
1792
+ });
1793
+ if (!res.ok) {
1794
+ const text = yield res.text().catch(() => "");
1795
+ throw new ReportsError(
1796
+ "member-activation",
1797
+ res.status,
1798
+ text.slice(0, 200)
1799
+ );
1800
+ }
1801
+ return yield res.json();
1802
+ });
1803
+ }
1804
+ };
1805
+
1669
1806
  // src/resources/tasks.ts
1670
1807
  var TasksResource = class {
1671
1808
  constructor(convexClient) {
@@ -1760,7 +1897,6 @@ var TranslationError = class extends Error {
1760
1897
  var TranslationResource = class {
1761
1898
  constructor(apiBaseUrl, apiKey, getAuthToken) {
1762
1899
  this.baseUrl = apiBaseUrl;
1763
- this.apiKey = apiKey;
1764
1900
  this.auth = { apiKey, getAuthToken };
1765
1901
  }
1766
1902
  post(path, body) {
@@ -2066,6 +2202,14 @@ var CONVEX_URLS = {
2066
2202
  production: "https://gallant-gecko-217.convex.cloud"
2067
2203
  };
2068
2204
  var TruthClient = class {
2205
+ /**
2206
+ * Builds the Convex client and event tracker from `config`, then wires up
2207
+ * every resource (patients, appointments, EHR proxy, reports, etc.) so
2208
+ * each shares the same Convex connection / API base URL / auth token
2209
+ * fetcher. When running in a browser that supports web push and the
2210
+ * caller hasn't opted out, kicks off best-effort service-worker
2211
+ * registration and push subscription in the background.
2212
+ */
2069
2213
  constructor(config) {
2070
2214
  this._vapidPublicKey = null;
2071
2215
  this._webPushReady = null;
@@ -2109,6 +2253,11 @@ var TruthClient = class {
2109
2253
  this.convex,
2110
2254
  config.getAuthToken
2111
2255
  );
2256
+ this.reports = new ReportsResource(
2257
+ apiUrl,
2258
+ config.apiKey,
2259
+ config.getAuthToken
2260
+ );
2112
2261
  this.notes = new NotesResource(apiUrl, config.apiKey, config.getAuthToken);
2113
2262
  this.physicians = new PhysiciansResource(this.convex);
2114
2263
  this.notifications = new NotificationsResource(
@@ -2129,9 +2278,11 @@ var TruthClient = class {
2129
2278
  this._webPushReady = this.initWebPush();
2130
2279
  }
2131
2280
  }
2281
+ /** The VAPID public key fetched during web-push init, or `null` until `webPushReady` resolves (or if push is unsupported/disabled). */
2132
2282
  get vapidPublicKey() {
2133
2283
  return this._vapidPublicKey;
2134
2284
  }
2285
+ /** 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). */
2135
2286
  get webPushReady() {
2136
2287
  return this._webPushReady;
2137
2288
  }
@@ -2158,6 +2309,14 @@ var TruthClient = class {
2158
2309
  }
2159
2310
  });
2160
2311
  }
2312
+ /**
2313
+ * Best-effort web-push bootstrap: waits for auth (if configured), fetches
2314
+ * the VAPID key, registers the service worker, subscribes to push, and
2315
+ * registers the device with a placeholder `__pending__` userId (the
2316
+ * backend reconciles this once the real user is known). Any failure
2317
+ * along the way is swallowed — push notifications are opportunistic and
2318
+ * must never break client construction.
2319
+ */
2161
2320
  initWebPush() {
2162
2321
  return __async(this, null, function* () {
2163
2322
  try {
@@ -2486,7 +2645,9 @@ function TruthProvider({
2486
2645
  for (let attempt = 0; attempt < 6; attempt++) {
2487
2646
  try {
2488
2647
  token = (_a2 = yield fetcher({ forceRefreshToken })) != null ? _a2 : null;
2489
- if (token) break;
2648
+ if (token) {
2649
+ break;
2650
+ }
2490
2651
  } catch (e) {
2491
2652
  }
2492
2653
  yield new Promise(
@@ -2674,6 +2835,7 @@ var listActiveRef = (0, import_server2.makeFunctionReference)("dialpadCallEvents
2674
2835
  var listForConversationRef = (0, import_server2.makeFunctionReference)("dialpadCallEvents:listForConversation");
2675
2836
  var getByCallIdRef = (0, import_server2.makeFunctionReference)("dialpadCallEvents:getByCallId");
2676
2837
  var listLogForCallIdRef = (0, import_server2.makeFunctionReference)("dialpadCallEvents:listLogForCallId");
2838
+ var setUserSummaryRef = (0, import_server2.makeFunctionReference)("dialpadCallEvents:setUserSummary");
2677
2839
  var SKIP = "skip";
2678
2840
  function toResult(value, skipped) {
2679
2841
  if (skipped) {
@@ -2717,6 +2879,15 @@ function useDialpadCallLog(callId, options) {
2717
2879
  );
2718
2880
  return toResult(result, skipped);
2719
2881
  }
2882
+ function useSaveCallSummary() {
2883
+ const mutate = (0, import_react4.useMutation)(
2884
+ setUserSummaryRef
2885
+ );
2886
+ return (0, import_react5.useCallback)(
2887
+ (callId, userSummary, updatedBy) => mutate({ callId, userSummary, updatedBy }),
2888
+ [mutate]
2889
+ );
2890
+ }
2720
2891
 
2721
2892
  // src/react/conversation-by-id.ts
2722
2893
  var import_server3 = require("convex/server");
@@ -2739,7 +2910,7 @@ function useConversationById(id) {
2739
2910
 
2740
2911
  // src/react/conversations.ts
2741
2912
  var import_server4 = require("convex/server");
2742
- var import_react4 = require("react");
2913
+ var import_react6 = require("react");
2743
2914
  var conversationsListForUserRef = (0, import_server4.makeFunctionReference)("conversations:listForUser");
2744
2915
  var conversationsSearchForUserRef = (0, import_server4.makeFunctionReference)("conversations:searchForUser");
2745
2916
  var conversationsGetUnreadTotalForUserRef = (0, import_server4.makeFunctionReference)("conversations:getUnreadTotalForUser");
@@ -2826,7 +2997,7 @@ function useUnreadAggregate(userId, options) {
2826
2997
  }
2827
2998
  function useMemoizedPhones(phones) {
2828
2999
  const key = phones ? [...phones].sort().join("|") : "";
2829
- return (0, import_react4.useMemo)(
3000
+ return (0, import_react6.useMemo)(
2830
3001
  () => (phones == null ? void 0 : phones.length) ? [...phones].sort() : void 0,
2831
3002
  // eslint-disable-next-line react-hooks/exhaustive-deps
2832
3003
  [key]
@@ -2874,7 +3045,7 @@ function useConversationTasksByPhonePair(phonePair) {
2874
3045
  }
2875
3046
 
2876
3047
  // src/react/hooks.ts
2877
- var import_react5 = require("react");
3048
+ var import_react7 = require("react");
2878
3049
  var import_server5 = require("convex/server");
2879
3050
  var patientsListRef = (0, import_server5.makeFunctionReference)("patients:list");
2880
3051
  var patientsGetRef = (0, import_server5.makeFunctionReference)("patients:get");
@@ -2970,7 +3141,7 @@ function usePatientMedical(elationId, options) {
2970
3141
  appointmentsByPatientRef,
2971
3142
  id !== void 0 ? { elationPatientId: id } : "skip"
2972
3143
  );
2973
- (0, import_react5.useEffect)(() => {
3144
+ (0, import_react7.useEffect)(() => {
2974
3145
  if (id === void 0 || (options == null ? void 0 : options.skipRefresh)) {
2975
3146
  return;
2976
3147
  }
@@ -3010,7 +3181,7 @@ function usePatientBasic(input, options) {
3010
3181
  hintPatientByIdRef,
3011
3182
  input.hintId !== void 0 ? { hintId: input.hintId } : "skip"
3012
3183
  );
3013
- (0, import_react5.useEffect)(() => {
3184
+ (0, import_react7.useEffect)(() => {
3014
3185
  if (options == null ? void 0 : options.skipRefresh) {
3015
3186
  return;
3016
3187
  }
@@ -3067,7 +3238,7 @@ function usePatientPhoto(elationId, options) {
3067
3238
  patientPhotoByIdRef,
3068
3239
  id !== void 0 ? { elationPatientId: id } : "skip"
3069
3240
  );
3070
- (0, import_react5.useEffect)(() => {
3241
+ (0, import_react7.useEffect)(() => {
3071
3242
  if (options == null ? void 0 : options.skipRefresh) {
3072
3243
  return;
3073
3244
  }
@@ -3110,7 +3281,7 @@ function useConversationMessages(input, options) {
3110
3281
  }
3111
3282
 
3112
3283
  // src/react/notifications.ts
3113
- var import_react6 = require("react");
3284
+ var import_react8 = require("react");
3114
3285
  function loadExpo() {
3115
3286
  return __async(this, null, function* () {
3116
3287
  try {
@@ -3125,13 +3296,14 @@ function useNotifications(options) {
3125
3296
  const sdkContext = useTruthSdkContext();
3126
3297
  const apiBaseUrl = (_b = (_a = options.apiBaseUrl) != null ? _a : sdkContext == null ? void 0 : sdkContext.apiBaseUrl) != null ? _b : "";
3127
3298
  const apiKey = (_d = (_c = options.apiKey) != null ? _c : sdkContext == null ? void 0 : sdkContext.apiKey) != null ? _d : "";
3128
- const [permissionStatus, setPermissionStatus] = (0, import_react6.useState)("unknown");
3129
- const [devicePushToken, setDevicePushToken] = (0, import_react6.useState)(null);
3130
- const expoRef = (0, import_react6.useRef)(null);
3131
- const isWebRef = (0, import_react6.useRef)(false);
3132
- const vapidKeyRef = (0, import_react6.useRef)((_e = options.vapidPublicKey) != null ? _e : null);
3133
- const prevUserIdRef = (0, import_react6.useRef)(void 0);
3134
- (0, import_react6.useEffect)(() => {
3299
+ const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
3300
+ const [permissionStatus, setPermissionStatus] = (0, import_react8.useState)("unknown");
3301
+ const [devicePushToken, setDevicePushToken] = (0, import_react8.useState)(null);
3302
+ const expoRef = (0, import_react8.useRef)(null);
3303
+ const isWebRef = (0, import_react8.useRef)(false);
3304
+ const vapidKeyRef = (0, import_react8.useRef)((_e = options.vapidPublicKey) != null ? _e : null);
3305
+ const prevUserIdRef = (0, import_react8.useRef)(void 0);
3306
+ (0, import_react8.useEffect)(() => {
3135
3307
  let mounted = true;
3136
3308
  void (() => __async(null, null, function* () {
3137
3309
  var _a2;
@@ -3187,7 +3359,7 @@ function useNotifications(options) {
3187
3359
  mounted = false;
3188
3360
  };
3189
3361
  }, [apiBaseUrl, apiKey]);
3190
- const register = (0, import_react6.useCallback)(() => __async(null, null, function* () {
3362
+ const register = (0, import_react8.useCallback)(() => __async(null, null, function* () {
3191
3363
  var _a2, _b2;
3192
3364
  if (!options.userId) {
3193
3365
  return { ok: false, reason: "missing_userId" };
@@ -3215,10 +3387,10 @@ function useNotifications(options) {
3215
3387
  `${apiBaseUrl}/api/notifications/devices/register`,
3216
3388
  {
3217
3389
  method: "POST",
3218
- headers: {
3219
- "Content-Type": "application/json",
3220
- "X-API-Key": apiKey
3221
- },
3390
+ headers: yield buildAuthHeaders(
3391
+ { apiKey, getAuthToken },
3392
+ { json: true, requireUserToken: true }
3393
+ ),
3222
3394
  body: JSON.stringify({
3223
3395
  userId: options.userId,
3224
3396
  platform: "web",
@@ -3267,14 +3439,23 @@ function useNotifications(options) {
3267
3439
  if (!apiBaseUrl || !apiKey) {
3268
3440
  return { ok: false, reason: "missing_truth_config" };
3269
3441
  }
3442
+ let nativeHeaders;
3443
+ try {
3444
+ nativeHeaders = yield buildAuthHeaders(
3445
+ { apiKey, getAuthToken },
3446
+ { json: true, requireUserToken: true }
3447
+ );
3448
+ } catch (err) {
3449
+ return {
3450
+ ok: false,
3451
+ reason: `missing_user_token: ${err instanceof Error ? err.message : String(err)}`
3452
+ };
3453
+ }
3270
3454
  const res = yield fetch(
3271
3455
  `${apiBaseUrl}/api/notifications/devices/register`,
3272
3456
  {
3273
3457
  method: "POST",
3274
- headers: {
3275
- "Content-Type": "application/json",
3276
- "X-API-Key": apiKey
3277
- },
3458
+ headers: nativeHeaders,
3278
3459
  body: JSON.stringify(__spreadValues({
3279
3460
  userId: options.userId,
3280
3461
  platform,
@@ -3296,26 +3477,30 @@ function useNotifications(options) {
3296
3477
  }), [
3297
3478
  apiBaseUrl,
3298
3479
  apiKey,
3480
+ getAuthToken,
3299
3481
  options.userId,
3300
3482
  options.appVersion,
3301
3483
  options.serviceWorkerPath
3302
3484
  ]);
3303
- const unregister = (0, import_react6.useCallback)(() => __async(null, null, function* () {
3485
+ const unregister = (0, import_react8.useCallback)(() => __async(null, null, function* () {
3304
3486
  if (!devicePushToken) {
3305
3487
  return;
3306
3488
  }
3307
- yield fetch(`${apiBaseUrl}/api/notifications/devices/unregister`, {
3308
- method: "POST",
3309
- headers: {
3310
- "Content-Type": "application/json",
3311
- "X-API-Key": apiKey
3312
- },
3313
- body: JSON.stringify({ nativeToken: devicePushToken })
3314
- }).catch(() => {
3315
- });
3489
+ try {
3490
+ const headers = yield buildAuthHeaders(
3491
+ { apiKey, getAuthToken },
3492
+ { json: true, requireUserToken: true }
3493
+ );
3494
+ yield fetch(`${apiBaseUrl}/api/notifications/devices/unregister`, {
3495
+ method: "POST",
3496
+ headers,
3497
+ body: JSON.stringify({ nativeToken: devicePushToken })
3498
+ });
3499
+ } catch (e) {
3500
+ }
3316
3501
  setDevicePushToken(null);
3317
- }), [apiBaseUrl, apiKey, devicePushToken]);
3318
- const addReceivedListener = (0, import_react6.useCallback)(
3502
+ }), [apiBaseUrl, apiKey, getAuthToken, devicePushToken]);
3503
+ const addReceivedListener = (0, import_react8.useCallback)(
3319
3504
  (listener) => {
3320
3505
  if (isWebRef.current) {
3321
3506
  if (typeof navigator === "undefined" || !("serviceWorker" in navigator)) {
@@ -3344,7 +3529,7 @@ function useNotifications(options) {
3344
3529
  },
3345
3530
  []
3346
3531
  );
3347
- const addResponseListener = (0, import_react6.useCallback)(
3532
+ const addResponseListener = (0, import_react8.useCallback)(
3348
3533
  (listener) => {
3349
3534
  if (isWebRef.current) {
3350
3535
  if (typeof navigator === "undefined" || !("serviceWorker" in navigator)) {
@@ -3373,7 +3558,7 @@ function useNotifications(options) {
3373
3558
  },
3374
3559
  []
3375
3560
  );
3376
- const getBadgeCount = (0, import_react6.useCallback)(() => __async(null, null, function* () {
3561
+ const getBadgeCount = (0, import_react8.useCallback)(() => __async(null, null, function* () {
3377
3562
  var _a2;
3378
3563
  const expo = expoRef.current;
3379
3564
  if (!(expo == null ? void 0 : expo.getBadgeCountAsync)) {
@@ -3381,7 +3566,7 @@ function useNotifications(options) {
3381
3566
  }
3382
3567
  return (_a2 = yield expo.getBadgeCountAsync()) != null ? _a2 : 0;
3383
3568
  }), []);
3384
- const setBadgeCount = (0, import_react6.useCallback)((count) => __async(null, null, function* () {
3569
+ const setBadgeCount = (0, import_react8.useCallback)((count) => __async(null, null, function* () {
3385
3570
  const expo = expoRef.current;
3386
3571
  if (!(expo == null ? void 0 : expo.setBadgeCountAsync)) {
3387
3572
  return;
@@ -3389,7 +3574,7 @@ function useNotifications(options) {
3389
3574
  yield expo.setBadgeCountAsync(count);
3390
3575
  }), []);
3391
3576
  const autoRegister = options.autoRegister !== false;
3392
- (0, import_react6.useEffect)(() => {
3577
+ (0, import_react8.useEffect)(() => {
3393
3578
  if (!autoRegister) {
3394
3579
  return;
3395
3580
  }
@@ -3428,7 +3613,7 @@ function useNotifications(options) {
3428
3613
  remove == null ? void 0 : remove();
3429
3614
  };
3430
3615
  }, [autoRegister, options.userId, register]);
3431
- (0, import_react6.useEffect)(() => {
3616
+ (0, import_react8.useEffect)(() => {
3432
3617
  const prev = prevUserIdRef.current;
3433
3618
  prevUserIdRef.current = options.userId;
3434
3619
  if (!autoRegister) {
@@ -3439,7 +3624,7 @@ function useNotifications(options) {
3439
3624
  }
3440
3625
  void register();
3441
3626
  }, [options.userId, autoRegister, register]);
3442
- (0, import_react6.useEffect)(() => {
3627
+ (0, import_react8.useEffect)(() => {
3443
3628
  if (!autoRegister) {
3444
3629
  return;
3445
3630
  }
@@ -3476,20 +3661,25 @@ function useNotificationsActions() {
3476
3661
  const sdkContext = useTruthSdkContext();
3477
3662
  const apiBaseUrl = (_a = sdkContext == null ? void 0 : sdkContext.apiBaseUrl) != null ? _a : "";
3478
3663
  const apiKey = (_b = sdkContext == null ? void 0 : sdkContext.apiKey) != null ? _b : "";
3479
- const post = (0, import_react6.useCallback)(
3480
- (path, body) => __async(null, null, function* () {
3664
+ const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
3665
+ const post = (0, import_react8.useCallback)(
3666
+ (path, body, opts) => __async(null, null, function* () {
3481
3667
  if (!apiBaseUrl || !apiKey) {
3482
3668
  throw new Error(
3483
3669
  "useNotificationsActions: missing apiBaseUrl/apiKey \u2014 wrap in <TruthProvider> or pass options"
3484
3670
  );
3485
3671
  }
3672
+ const headers = (opts == null ? void 0 : opts.requireUserToken) ? yield buildAuthHeaders(
3673
+ { apiKey, getAuthToken },
3674
+ { json: true, requireUserToken: true }
3675
+ ) : {
3676
+ "Content-Type": "application/json",
3677
+ Accept: "application/json",
3678
+ "X-API-Key": apiKey
3679
+ };
3486
3680
  const res = yield fetch(`${apiBaseUrl}/api${path}`, {
3487
3681
  method: "POST",
3488
- headers: {
3489
- "Content-Type": "application/json",
3490
- Accept: "application/json",
3491
- "X-API-Key": apiKey
3492
- },
3682
+ headers,
3493
3683
  body: JSON.stringify(body)
3494
3684
  });
3495
3685
  if (!res.ok) {
@@ -3500,13 +3690,17 @@ function useNotificationsActions() {
3500
3690
  }
3501
3691
  return yield res.json();
3502
3692
  }),
3503
- [apiBaseUrl, apiKey]
3693
+ [apiBaseUrl, apiKey, getAuthToken]
3504
3694
  );
3505
- const get = (0, import_react6.useCallback)(
3506
- (path) => __async(null, null, function* () {
3695
+ const get = (0, import_react8.useCallback)(
3696
+ (path, opts) => __async(null, null, function* () {
3697
+ const headers = (opts == null ? void 0 : opts.requireUserToken) ? yield buildAuthHeaders(
3698
+ { apiKey, getAuthToken },
3699
+ { requireUserToken: true }
3700
+ ) : { Accept: "application/json", "X-API-Key": apiKey };
3507
3701
  const res = yield fetch(`${apiBaseUrl}/api${path}`, {
3508
3702
  method: "GET",
3509
- headers: { Accept: "application/json", "X-API-Key": apiKey }
3703
+ headers
3510
3704
  });
3511
3705
  if (!res.ok) {
3512
3706
  const text = yield res.text().catch(() => "");
@@ -3516,26 +3710,28 @@ function useNotificationsActions() {
3516
3710
  }
3517
3711
  return yield res.json();
3518
3712
  }),
3519
- [apiBaseUrl, apiKey]
3713
+ [apiBaseUrl, apiKey, getAuthToken]
3520
3714
  );
3521
- const send = (0, import_react6.useCallback)(
3715
+ const send = (0, import_react8.useCallback)(
3522
3716
  (input) => post("/notifications/send", input),
3523
3717
  [post]
3524
3718
  );
3525
- const schedule = (0, import_react6.useCallback)(
3719
+ const schedule = (0, import_react8.useCallback)(
3526
3720
  (input) => post("/notifications/schedule", input),
3527
3721
  [post]
3528
3722
  );
3529
- const getPreferences = (0, import_react6.useCallback)(
3723
+ const getPreferences = (0, import_react8.useCallback)(
3530
3724
  (userId) => get(
3531
- `/notifications/preferences/${encodeURIComponent(userId)}`
3725
+ `/notifications/preferences/${encodeURIComponent(userId)}`,
3726
+ { requireUserToken: true }
3532
3727
  ),
3533
3728
  [get]
3534
3729
  );
3535
- const updatePreferences = (0, import_react6.useCallback)(
3730
+ const updatePreferences = (0, import_react8.useCallback)(
3536
3731
  (userId, prefs) => post(
3537
3732
  `/notifications/preferences/${encodeURIComponent(userId)}`,
3538
- prefs
3733
+ prefs,
3734
+ { requireUserToken: true }
3539
3735
  ),
3540
3736
  [post]
3541
3737
  );
@@ -3615,12 +3811,12 @@ function usePatientSearch(options) {
3615
3811
 
3616
3812
  // src/react/patients-bulk.ts
3617
3813
  var import_server8 = require("convex/server");
3618
- var import_react7 = require("react");
3814
+ var import_react9 = require("react");
3619
3815
  var patientsGetByIdsRef = (0, import_server8.makeFunctionReference)("patients:getByIds");
3620
3816
  var patientsGetByPhonesRef = (0, import_server8.makeFunctionReference)("patients:getByPhones");
3621
3817
  var SKIP5 = "skip";
3622
3818
  function usePatientsByIds(ids) {
3623
- const stableIds = (0, import_react7.useMemo)(() => {
3819
+ const stableIds = (0, import_react9.useMemo)(() => {
3624
3820
  const arr = ids != null ? ids : [];
3625
3821
  return [...new Set(arr)].sort();
3626
3822
  }, [ids]);
@@ -3629,7 +3825,7 @@ function usePatientsByIds(ids) {
3629
3825
  patientsGetByIdsRef,
3630
3826
  skipped ? SKIP5 : { ids: stableIds }
3631
3827
  );
3632
- const mapped = (0, import_react7.useMemo)(() => {
3828
+ const mapped = (0, import_react9.useMemo)(() => {
3633
3829
  if (result === void 0) {
3634
3830
  return void 0;
3635
3831
  }
@@ -3651,7 +3847,7 @@ function usePatientsByIds(ids) {
3651
3847
  };
3652
3848
  }
3653
3849
  function usePatientsByPhones(phones) {
3654
- const stableDigits = (0, import_react7.useMemo)(() => {
3850
+ const stableDigits = (0, import_react9.useMemo)(() => {
3655
3851
  const arr = phones != null ? phones : [];
3656
3852
  const digits = arr.map((p) => p.replace(/\D+/g, "")).filter((s) => s.length > 0);
3657
3853
  return [...new Set(digits)].sort();
@@ -3661,7 +3857,7 @@ function usePatientsByPhones(phones) {
3661
3857
  patientsGetByPhonesRef,
3662
3858
  skipped ? SKIP5 : { phoneDigits: stableDigits }
3663
3859
  );
3664
- const mapped = (0, import_react7.useMemo)(() => {
3860
+ const mapped = (0, import_react9.useMemo)(() => {
3665
3861
  if (result === void 0) {
3666
3862
  return void 0;
3667
3863
  }
@@ -3700,23 +3896,23 @@ function useRemindersForConversations(conversationIds) {
3700
3896
  }
3701
3897
 
3702
3898
  // src/react/tasks.ts
3703
- var import_react8 = require("convex/react");
3899
+ var import_react10 = require("convex/react");
3704
3900
  var import_server10 = require("convex/server");
3705
- var import_react9 = require("react");
3901
+ var import_react11 = require("react");
3706
3902
  var conversationTasksMarkSeenRef = (0, import_server10.makeFunctionReference)("conversationTasks:markSeen");
3707
3903
  function useConversationTaskMarkSeen() {
3708
- const mutate = (0, import_react8.useMutation)(
3904
+ const mutate = (0, import_react10.useMutation)(
3709
3905
  conversationTasksMarkSeenRef
3710
3906
  );
3711
- return (0, import_react9.useCallback)(
3907
+ return (0, import_react11.useCallback)(
3712
3908
  (taskId, userId) => mutate({ taskId, userId }),
3713
3909
  [mutate]
3714
3910
  );
3715
3911
  }
3716
3912
 
3717
3913
  // src/react/tracking.ts
3718
- var import_react10 = require("react");
3719
- var TruthTrackingContext = (0, import_react10.createContext)(
3914
+ var import_react12 = require("react");
3915
+ var TruthTrackingContext = (0, import_react12.createContext)(
3720
3916
  null
3721
3917
  );
3722
3918
  function TruthTrackingProvider({
@@ -3729,7 +3925,7 @@ function TruthTrackingProvider({
3729
3925
  }) {
3730
3926
  var _a, _b;
3731
3927
  const resolvedApiKey = (_b = apiKey != null ? apiKey : typeof process !== "undefined" ? (_a = process.env) == null ? void 0 : _a.EXPO_PUBLIC_TRUTH_API_KEY : void 0) != null ? _b : "";
3732
- const value = (0, import_react10.useMemo)(() => {
3928
+ const value = (0, import_react12.useMemo)(() => {
3733
3929
  const tracker = new Tracker({
3734
3930
  apiKey: resolvedApiKey,
3735
3931
  environment,
@@ -3748,10 +3944,10 @@ function TruthTrackingProvider({
3748
3944
  }
3749
3945
  };
3750
3946
  }, [resolvedApiKey, environment, source, sourceVersion, tenantId]);
3751
- return (0, import_react10.createElement)(TruthTrackingContext.Provider, { value }, children);
3947
+ return (0, import_react12.createElement)(TruthTrackingContext.Provider, { value }, children);
3752
3948
  }
3753
3949
  function useTruth() {
3754
- const ctx = (0, import_react10.useContext)(TruthTrackingContext);
3950
+ const ctx = (0, import_react12.useContext)(TruthTrackingContext);
3755
3951
  if (!ctx) {
3756
3952
  throw new Error("useTruth must be used within a TruthTrackingProvider");
3757
3953
  }
@@ -3779,15 +3975,16 @@ function useUserSettings(userId) {
3779
3975
  }
3780
3976
 
3781
3977
  // src/react/users.ts
3782
- var import_react11 = require("react");
3978
+ var import_react13 = require("react");
3783
3979
  function useUserSync(input) {
3784
3980
  var _a, _b, _c, _d;
3785
3981
  const sdkContext = useTruthSdkContext();
3786
3982
  const apiBaseUrl = (_b = (_a = input.apiBaseUrl) != null ? _a : sdkContext == null ? void 0 : sdkContext.apiBaseUrl) != null ? _b : "";
3787
3983
  const apiKey = (_d = (_c = input.apiKey) != null ? _c : sdkContext == null ? void 0 : sdkContext.apiKey) != null ? _d : "";
3788
- const [status, setStatus] = (0, import_react11.useState)("idle");
3789
- const [error, setError] = (0, import_react11.useState)(null);
3790
- const lastKeyRef = (0, import_react11.useRef)(null);
3984
+ const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
3985
+ const [status, setStatus] = (0, import_react13.useState)("idle");
3986
+ const [error, setError] = (0, import_react13.useState)(null);
3987
+ const lastKeyRef = (0, import_react13.useRef)(null);
3791
3988
  const sync = () => __async(null, null, function* () {
3792
3989
  if (!input.userId) {
3793
3990
  return { ok: false, reason: "missing_userId" };
@@ -3798,12 +3995,13 @@ function useUserSync(input) {
3798
3995
  setStatus("syncing");
3799
3996
  setError(null);
3800
3997
  try {
3998
+ const headers = yield buildAuthHeaders(
3999
+ { apiKey, getAuthToken },
4000
+ { json: true, requireUserToken: true }
4001
+ );
3801
4002
  const res = yield fetch(`${apiBaseUrl}/api/users/sync`, {
3802
4003
  method: "POST",
3803
- headers: {
3804
- "Content-Type": "application/json",
3805
- "X-API-Key": apiKey
3806
- },
4004
+ headers,
3807
4005
  body: JSON.stringify({
3808
4006
  userId: input.userId,
3809
4007
  email: input.email,
@@ -3830,7 +4028,7 @@ function useUserSync(input) {
3830
4028
  return { ok: false, reason: message };
3831
4029
  }
3832
4030
  });
3833
- (0, import_react11.useEffect)(() => {
4031
+ (0, import_react13.useEffect)(() => {
3834
4032
  var _a2, _b2, _c2, _d2, _e;
3835
4033
  if (!input.userId) {
3836
4034
  return;
@@ -3869,13 +4067,13 @@ function useUserSync(input) {
3869
4067
  }
3870
4068
 
3871
4069
  // src/react/voicemail.ts
3872
- var import_react12 = require("react");
4070
+ var import_react14 = require("react");
3873
4071
  function useVoicemailUrl(client) {
3874
- const [url, setUrl] = (0, import_react12.useState)(null);
3875
- const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
3876
- const [error, setError] = (0, import_react12.useState)(null);
3877
- const inFlightRef = (0, import_react12.useRef)(false);
3878
- const fetchUrl = (0, import_react12.useCallback)(
4072
+ const [url, setUrl] = (0, import_react14.useState)(null);
4073
+ const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
4074
+ const [error, setError] = (0, import_react14.useState)(null);
4075
+ const inFlightRef = (0, import_react14.useRef)(false);
4076
+ const fetchUrl = (0, import_react14.useCallback)(
3879
4077
  (voicemailLink) => __async(null, null, function* () {
3880
4078
  if (inFlightRef.current) {
3881
4079
  return null;
@@ -3953,6 +4151,7 @@ function useVoicemailUrl(client) {
3953
4151
  usePhysicianByElationId,
3954
4152
  usePhysiciansByElationIds,
3955
4153
  useRemindersForConversations,
4154
+ useSaveCallSummary,
3956
4155
  useTruth,
3957
4156
  useTruthClient,
3958
4157
  useTruthSdkContext,