@hipnation-truth/sdk 0.26.4 → 0.26.6

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.d.ts CHANGED
@@ -591,23 +591,6 @@ interface UsePatientMedicalOptions {
591
591
  */
592
592
  skipRefresh?: boolean;
593
593
  }
594
- /**
595
- * Composite hook that returns a patient's medical records — medications,
596
- * problems, allergies, appointments — from the Convex cache.
597
- *
598
- * On mount (and when `elationId` changes) fires a background refresh
599
- * against Truth's `/api/patients/medical/refresh` endpoint so stale data
600
- * is pulled in without blocking render. Returns cached data immediately;
601
- * Convex subscription updates the UI when refresh completes.
602
- *
603
- * OFFLINE-READS POLICY: these medical-record queries ARE mirrored offline
604
- * via `usePersistentQuery`, so medications, problems, allergies and
605
- * appointments render from the at-rest mirror when the device is offline.
606
- * Full medical records are the most sensitive PHI we hold, so they are
607
- * only ever written to the encrypted-at-rest store (256-bit MMKV key held
608
- * in the device keychain), never to any plaintext storage. Keep them on
609
- * the encrypted mirror only — do not relax the store's encryption.
610
- */
611
594
  declare function usePatientMedical(elationId: number | undefined, options?: UsePatientMedicalOptions): {
612
595
  medications: unknown[] | undefined;
613
596
  problems: unknown[] | undefined;
@@ -2771,6 +2754,13 @@ interface TruthSdkContextValue {
2771
2754
  apiKey: string;
2772
2755
  environment: string;
2773
2756
  client: TruthClient;
2757
+ /**
2758
+ * Clerk token fetcher (template "convex"), if wired. Hooks that make their
2759
+ * own HTTP calls (e.g. the patient `…/refresh` endpoints) use this to attach
2760
+ * `Authorization: Bearer <jwt>` so they work under a publishable `hn_pk_*`
2761
+ * key, which the API gate accepts only with a verified user JWT.
2762
+ */
2763
+ getAuthToken?: AuthTokenFetcher;
2774
2764
  /** Injected offline mirror (or the Noop default on web / flag off). */
2775
2765
  offlineStore: OfflineStore;
2776
2766
  /** Whether the offline-reads layer is active for this provider. */
package/dist/react.js CHANGED
@@ -2390,6 +2390,7 @@ function TruthProvider({
2390
2390
  client: truthClient,
2391
2391
  offlineStore,
2392
2392
  offlineEnabled,
2393
+ getAuthToken: stableGetAuthToken,
2393
2394
  authGated: hasAuthFetcher,
2394
2395
  authReady: convexAuthed
2395
2396
  }),
@@ -2400,6 +2401,7 @@ function TruthProvider({
2400
2401
  truthClient,
2401
2402
  offlineStore,
2402
2403
  offlineEnabled,
2404
+ stableGetAuthToken,
2403
2405
  hasAuthFetcher,
2404
2406
  convexAuthed
2405
2407
  ]
@@ -2739,11 +2741,33 @@ var medicationsByPatientRef = (0, import_server5.makeFunctionReference)("medical
2739
2741
  var problemsByPatientRef = (0, import_server5.makeFunctionReference)("medicalRecords:getProblemsByElationPatient");
2740
2742
  var allergiesByPatientRef = (0, import_server5.makeFunctionReference)("medicalRecords:getAllergiesByElationPatient");
2741
2743
  var appointmentsByPatientRef = (0, import_server5.makeFunctionReference)("medicalRecords:getAppointmentsByElationPatient");
2744
+ function postPatientRefresh(url, apiKey, getAuthToken, body, signal) {
2745
+ return __async(this, null, function* () {
2746
+ const headers = {
2747
+ "Content-Type": "application/json",
2748
+ "X-API-Key": apiKey
2749
+ };
2750
+ try {
2751
+ const token = yield getAuthToken == null ? void 0 : getAuthToken();
2752
+ if (token) {
2753
+ headers.Authorization = `Bearer ${token}`;
2754
+ }
2755
+ } catch (e) {
2756
+ }
2757
+ yield fetch(url, {
2758
+ method: "POST",
2759
+ headers,
2760
+ body: JSON.stringify(body),
2761
+ signal
2762
+ });
2763
+ });
2764
+ }
2742
2765
  function usePatientMedical(elationId, options) {
2743
2766
  var _a, _b;
2744
2767
  const sdkContext = useTruthSdkContext();
2745
2768
  const apiBaseUrl = (_a = options == null ? void 0 : options.apiBaseUrl) != null ? _a : sdkContext == null ? void 0 : sdkContext.apiBaseUrl;
2746
2769
  const apiKey = (_b = options == null ? void 0 : options.apiKey) != null ? _b : sdkContext == null ? void 0 : sdkContext.apiKey;
2770
+ const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
2747
2771
  const medications = usePersistentQuery(
2748
2772
  medicationsByPatientRef,
2749
2773
  elationId !== void 0 ? { elationPatientId: elationId } : "skip"
@@ -2768,18 +2792,16 @@ function usePatientMedical(elationId, options) {
2768
2792
  return;
2769
2793
  }
2770
2794
  const controller = new AbortController();
2771
- void fetch(`${apiBaseUrl}/api/patients/medical/refresh`, {
2772
- method: "POST",
2773
- headers: {
2774
- "Content-Type": "application/json",
2775
- "X-API-Key": apiKey
2776
- },
2777
- body: JSON.stringify({ elationId }),
2778
- signal: controller.signal
2779
- }).catch(() => {
2795
+ void postPatientRefresh(
2796
+ `${apiBaseUrl}/api/patients/medical/refresh`,
2797
+ apiKey,
2798
+ getAuthToken,
2799
+ { elationId },
2800
+ controller.signal
2801
+ ).catch(() => {
2780
2802
  });
2781
2803
  return () => controller.abort();
2782
- }, [elationId, apiBaseUrl, apiKey, options == null ? void 0 : options.skipRefresh]);
2804
+ }, [elationId, apiBaseUrl, apiKey, getAuthToken, options == null ? void 0 : options.skipRefresh]);
2783
2805
  return { medications, problems, allergies, appointments };
2784
2806
  }
2785
2807
  var elationPatientByIdRef = (0, import_server5.makeFunctionReference)("elationPatients:getByElationId");
@@ -2791,6 +2813,7 @@ function usePatientBasic(input, options) {
2791
2813
  const sdkContext = useTruthSdkContext();
2792
2814
  const apiBaseUrl = (_a = options == null ? void 0 : options.apiBaseUrl) != null ? _a : sdkContext == null ? void 0 : sdkContext.apiBaseUrl;
2793
2815
  const apiKey = (_b = options == null ? void 0 : options.apiKey) != null ? _b : sdkContext == null ? void 0 : sdkContext.apiKey;
2816
+ const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
2794
2817
  const elationRow = usePersistentQuery(
2795
2818
  elationPatientByIdRef,
2796
2819
  input.elationId !== void 0 ? { elationId: input.elationId } : "skip"
@@ -2810,21 +2833,23 @@ function usePatientBasic(input, options) {
2810
2833
  return;
2811
2834
  }
2812
2835
  const controller = new AbortController();
2813
- void fetch(`${apiBaseUrl}/api/patients/basic/refresh`, {
2814
- method: "POST",
2815
- headers: {
2816
- "Content-Type": "application/json",
2817
- "X-API-Key": apiKey
2818
- },
2819
- body: JSON.stringify({
2820
- hintId: input.hintId,
2821
- elationId: input.elationId
2822
- }),
2823
- signal: controller.signal
2824
- }).catch(() => {
2836
+ void postPatientRefresh(
2837
+ `${apiBaseUrl}/api/patients/basic/refresh`,
2838
+ apiKey,
2839
+ getAuthToken,
2840
+ { hintId: input.hintId, elationId: input.elationId },
2841
+ controller.signal
2842
+ ).catch(() => {
2825
2843
  });
2826
2844
  return () => controller.abort();
2827
- }, [input.hintId, input.elationId, apiBaseUrl, apiKey, options == null ? void 0 : options.skipRefresh]);
2845
+ }, [
2846
+ input.hintId,
2847
+ input.elationId,
2848
+ apiBaseUrl,
2849
+ apiKey,
2850
+ getAuthToken,
2851
+ options == null ? void 0 : options.skipRefresh
2852
+ ]);
2828
2853
  const elationPatient = elationRow === void 0 ? void 0 : elationRow === null ? null : (_c = elationRow.raw) != null ? _c : null;
2829
2854
  const hintPatient = hintRow === void 0 ? void 0 : hintRow === null ? null : (_d = hintRow.raw) != null ? _d : null;
2830
2855
  const elationLoading = input.elationId !== void 0 && elationRow === void 0;
@@ -2848,6 +2873,7 @@ function usePatientPhoto(elationId, options) {
2848
2873
  const sdkContext = useTruthSdkContext();
2849
2874
  const apiBaseUrl = (_a = options == null ? void 0 : options.apiBaseUrl) != null ? _a : sdkContext == null ? void 0 : sdkContext.apiBaseUrl;
2850
2875
  const apiKey = (_b = options == null ? void 0 : options.apiKey) != null ? _b : sdkContext == null ? void 0 : sdkContext.apiKey;
2876
+ const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
2851
2877
  const photo = usePersistentQuery(
2852
2878
  patientPhotoByIdRef,
2853
2879
  elationId !== void 0 ? { elationPatientId: elationId } : "skip"
@@ -2863,18 +2889,16 @@ function usePatientPhoto(elationId, options) {
2863
2889
  return;
2864
2890
  }
2865
2891
  const controller = new AbortController();
2866
- void fetch(`${apiBaseUrl}/api/patients/photo/refresh`, {
2867
- method: "POST",
2868
- headers: {
2869
- "Content-Type": "application/json",
2870
- "X-API-Key": apiKey
2871
- },
2872
- body: JSON.stringify({ elationId }),
2873
- signal: controller.signal
2874
- }).catch(() => {
2892
+ void postPatientRefresh(
2893
+ `${apiBaseUrl}/api/patients/photo/refresh`,
2894
+ apiKey,
2895
+ getAuthToken,
2896
+ { elationId },
2897
+ controller.signal
2898
+ ).catch(() => {
2875
2899
  });
2876
2900
  return () => controller.abort();
2877
- }, [elationId, apiBaseUrl, apiKey, options == null ? void 0 : options.skipRefresh]);
2901
+ }, [elationId, apiBaseUrl, apiKey, getAuthToken, options == null ? void 0 : options.skipRefresh]);
2878
2902
  return photo;
2879
2903
  }
2880
2904
  var messagesByPhonesRef = (0, import_server5.makeFunctionReference)("conversationMessages:getByPhones");