@hipnation-truth/sdk 0.23.2 → 0.25.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/react.d.ts CHANGED
@@ -599,6 +599,14 @@ interface UsePatientMedicalOptions {
599
599
  * against Truth's `/api/patients/medical/refresh` endpoint so stale data
600
600
  * is pulled in without blocking render. Returns cached data immediately;
601
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.
602
610
  */
603
611
  declare function usePatientMedical(elationId: number | undefined, options?: UsePatientMedicalOptions): {
604
612
  medications: unknown[] | undefined;
@@ -834,6 +842,77 @@ interface UseNotificationsActions {
834
842
  }
835
843
  declare function useNotificationsActions(): UseNotificationsActions;
836
844
 
845
+ /**
846
+ * Offline mirror storage seam.
847
+ *
848
+ * The Truth SDK is consumed by two apps with very different storage
849
+ * stories:
850
+ * - `ch/` (Expo / React Native) — has access to native, encrypted,
851
+ * synchronous KV (MMKV) and wants durable offline reads.
852
+ * - `truth/apps/web` (Next.js) — has no such store and must behave
853
+ * exactly as it does today.
854
+ *
855
+ * So the SDK never imports a native module. Instead the consuming app
856
+ * *injects* an `OfflineStore` implementation through `<TruthProvider>`.
857
+ * When none is injected the SDK falls back to {@link NoopStore} and the
858
+ * entire offline layer becomes a transparent pass-through.
859
+ *
860
+ * The interface is deliberately **synchronous**: cold-start hydration
861
+ * has to read the last-known value during the first render, before any
862
+ * effect or promise resolves, so async storage (AsyncStorage) is not
863
+ * sufficient here. MMKV's `getString`/`set` are synchronous and map
864
+ * onto this directly.
865
+ */
866
+ /** Synchronous KV mirror. Sync getters enable instant cold-start hydration. */
867
+ interface OfflineStore {
868
+ /** Return the stored string for `key`, or `null` when absent. */
869
+ get(key: string): string | null;
870
+ /** Write `value` under `key`, overwriting any prior value. */
871
+ set(key: string, value: string): void;
872
+ /** Remove a single `key`. No-op when absent. */
873
+ delete(key: string): void;
874
+ /**
875
+ * Wipe every key this store owns. Called on logout / user switch so a
876
+ * second user on the same device never sees the first user's cached
877
+ * PHI. MUST clear durably (survive the next cold start).
878
+ */
879
+ clearAll(): void;
880
+ }
881
+ /**
882
+ * Used when no store is injected (e.g. `truth/apps/web`) → the offline
883
+ * layer is a no-op and behavior is identical to a build without it.
884
+ */
885
+ declare class NoopStore implements OfflineStore {
886
+ get(): string | null;
887
+ set(): void;
888
+ delete(): void;
889
+ clearAll(): void;
890
+ }
891
+
892
+ /**
893
+ * TanStack Query persister backed by the injected {@link OfflineStore}.
894
+ *
895
+ * Under Path A the whole dehydrated query cache is serialized as a
896
+ * single blob and written through the synchronous `OfflineStore` (MMKV
897
+ * on `ch/`). On cold start `PersistQueryClientProvider` calls
898
+ * `restoreClient()` to rehydrate that blob before the Convex websocket
899
+ * reconnects, which is what makes last-known data render with no
900
+ * network.
901
+ *
902
+ * The store is synchronous, so all three methods resolve immediately —
903
+ * but the `Persister` contract allows returning a value or a promise, so
904
+ * returning the raw values is fine.
905
+ */
906
+
907
+ /**
908
+ * Read the epoch-millis timestamp the persisted cache was last written
909
+ * (TanStack stamps `timestamp` on every persist → it tracks the most
910
+ * recent successful sync). Returns `null` when nothing is persisted or
911
+ * the blob is unreadable. Powers the "Offline · updated {relative}"
912
+ * indicator without the app having to know the dehydrated cache format.
913
+ */
914
+ declare function readPersistedSavedAt(store: OfflineStore, cacheKey?: string): number | null;
915
+
837
916
  /**
838
917
  * React hook for patient family-member lookup — Truth SDK.
839
918
  *
@@ -1178,12 +1257,26 @@ declare const ENVIRONMENTS: {
1178
1257
  readonly production: "production";
1179
1258
  };
1180
1259
  type Environment = (typeof ENVIRONMENTS)[keyof typeof ENVIRONMENTS];
1260
+ /**
1261
+ * Fetches a user-identity JWT for Convex calls. Return the token from
1262
+ * your identity provider's Clerk JWT template named "convex"
1263
+ * (e.g. `getToken({ template: "convex" })` from `@clerk/expo`), or
1264
+ * `null` when no user is signed in.
1265
+ */
1266
+ type AuthTokenFetcher = () => Promise<string | null | undefined>;
1181
1267
  /**
1182
1268
  * Configuration for initializing a TruthClient.
1183
1269
  */
1184
1270
  interface TruthClientConfig {
1185
1271
  /** API key for authenticating with the Truth platform (e.g. "hn_live_...") */
1186
1272
  apiKey: string;
1273
+ /**
1274
+ * Per-call Clerk JWT fetcher for Convex data access. When provided,
1275
+ * every Convex query/mutation/action carries the caller's identity;
1276
+ * Convex deployments with `CLERK_AUTH_REQUIRED` enabled reject calls
1277
+ * without it. Omit for service contexts that don't act as a user.
1278
+ */
1279
+ getAuthToken?: AuthTokenFetcher;
1187
1280
  /** Target environment */
1188
1281
  environment: Environment;
1189
1282
  /** Override the default Convex URL for data access */
@@ -2651,6 +2744,10 @@ interface TruthSdkContextValue {
2651
2744
  apiKey: string;
2652
2745
  environment: string;
2653
2746
  client: TruthClient;
2747
+ /** Injected offline mirror (or the Noop default on web / flag off). */
2748
+ offlineStore: OfflineStore;
2749
+ /** Whether the offline-reads layer is active for this provider. */
2750
+ offlineEnabled: boolean;
2654
2751
  }
2655
2752
  /**
2656
2753
  * Read the Truth REST API base URL + API key + shared client from
@@ -2659,6 +2756,17 @@ interface TruthSdkContextValue {
2659
2756
  * compatibility.
2660
2757
  */
2661
2758
  declare function useTruthSdkContext(): TruthSdkContextValue | null;
2759
+ /**
2760
+ * Read the injected offline mirror. Returns the shared `NoopStore`
2761
+ * (transparent pass-through) when no provider is mounted or no store was
2762
+ * injected — so callers never have to null-check.
2763
+ */
2764
+ declare function useOfflineStore(): OfflineStore;
2765
+ /**
2766
+ * Whether the offline-reads layer is active. `false` when no provider is
2767
+ * mounted or the feature flag is off.
2768
+ */
2769
+ declare function useOfflineEnabled(): boolean;
2662
2770
  /**
2663
2771
  * Hook variant of `getTruthClient()` for code that lives inside the
2664
2772
  * React tree. Returns the shared `TruthClient` instance from
@@ -2696,9 +2804,34 @@ interface TruthProviderProps {
2696
2804
  source?: string;
2697
2805
  sourceVersion?: string;
2698
2806
  tenantId?: string;
2807
+ /**
2808
+ * Per-call Clerk JWT fetcher (template "convex") identifying the
2809
+ * signed-in user to Convex. Wire it to your identity provider, e.g.
2810
+ * `useAuth().getToken({ template: "convex" })` from `@clerk/expo`.
2811
+ * Applied to both the live websocket client (React hooks) and the
2812
+ * shared `TruthClient` (resource methods). Identity changes are
2813
+ * picked up without remounting — the latest fetcher is read through
2814
+ * a ref on every call.
2815
+ */
2816
+ getAuthToken?: AuthTokenFetcher;
2817
+ /**
2818
+ * Synchronous encrypted KV mirror for durable offline reads, injected
2819
+ * by the consuming app (e.g. MMKV on `ch/`). Omit on web — the SDK
2820
+ * falls back to a `NoopStore` and the offline layer is a transparent
2821
+ * pass-through. Never import a native module into the SDK; inject it
2822
+ * here instead.
2823
+ */
2824
+ offlineStore?: OfflineStore;
2825
+ /**
2826
+ * Feature flag for the offline-reads layer. Default `false`. Has no
2827
+ * effect unless a real (non-Noop) `offlineStore` is also injected.
2828
+ * When both are set, the TanStack query cache is persisted to the
2829
+ * store so last-known reads survive a cold start with no network.
2830
+ */
2831
+ offlineEnabled?: boolean;
2699
2832
  children: ReactNode;
2700
2833
  }
2701
- declare function TruthProvider({ environment, convexUrl, apiBaseUrl, apiKey, source, sourceVersion, tenantId, children, }: TruthProviderProps): react.FunctionComponentElement<react.ProviderProps<TruthSdkContextValue | null>>;
2834
+ declare function TruthProvider({ environment, convexUrl, apiBaseUrl, apiKey, source, sourceVersion, tenantId, getAuthToken, offlineStore, offlineEnabled, children, }: TruthProviderProps): react.FunctionComponentElement<react.ProviderProps<TruthSdkContextValue | null>>;
2702
2835
 
2703
2836
  /**
2704
2837
  * React hooks for conversation reminders — bulk lookup keyed by
@@ -2897,4 +3030,4 @@ interface UseVoicemailUrlResult {
2897
3030
  */
2898
3031
  declare function useVoicemailUrl(client: TruthClient): UseVoicemailUrlResult;
2899
3032
 
2900
- export { ACTIVE_CALL_STATES, API_BASE_URLS, type Appointment, type AppointmentListOptions, CONNECTED_CALL_STATES, CONVEX_URLS, type ConversationListItem, type ConversationMessage, type ConversationMessageRow, type ConversationNoteRow, type ConversationRow, type ConversationTaskForUserRow, type ConversationTaskRow, type DialpadCallLogRow, type DialpadCallRow, DialpadCallState, type EventPayloadMap, type EventType, type FamilyMemberRow, type Patient, type PatientListOptions, type PatientSearchResult, type PermissionStatus, type Physician$1 as Physician, RINGING_CALL_STATES, TERMINAL_CALL_STATES, type TrackOptions, TruthProvider, type TruthProviderProps, type TruthTrackingContextValue, TruthTrackingProvider, type TruthTrackingProviderProps, type UseActiveCallsOptions, type UseAppointmentListOptions, type UseConversationMessagesOptions, type UseConversationsFilters, type UseMessagesOptions, type UseNotificationsActions, type UseNotificationsOptions, type UseNotificationsResult, type UsePatientBasicOptions, type UsePatientBasicResult, type UsePatientFamilyMembersInput, type UsePatientListOptions, type UsePatientMedicalOptions, type UsePatientPhotoOptions, type UsePatientSearchOptions, type UseQueryResult, type UseUserSyncInput, type UseUserSyncResult, getTruthClient, resolveApiBaseUrl, resolveConvexUrl, useActiveCalls, useAppointment, useAppointmentByElationId, useAppointments, useConversationById, useConversationByPhonePair, useConversationMessages, useConversationNotes, useConversationNotesByPhonePair, useConversationTaskMarkSeen, useConversationTasks, useConversationTasksByPhonePair, useConversationTasksForUser, useConversations, useDialpadCallByCallId, useDialpadCallLog, useDialpadCallsForConversation, useMessages, useNotifications, useNotificationsActions, usePatient, usePatientBasic, usePatientByElationId, usePatientByHintId, usePatientFamilyMembers, usePatientMedical, usePatientPhoto, usePatientSearch, usePatients, usePatientsByIds, usePatientsByPhones, usePharmacyByNcpdpId, usePhysicianByElationId, usePhysiciansByElationIds, useRemindersForConversations, useTruth, useTruthClient, useTruthSdkContext, useUnreadAggregate, useUnreadCount, useUserSettings, useUserSync, useVoicemailUrl };
3033
+ export { ACTIVE_CALL_STATES, API_BASE_URLS, type Appointment, type AppointmentListOptions, CONNECTED_CALL_STATES, CONVEX_URLS, type ConversationListItem, type ConversationMessage, type ConversationMessageRow, type ConversationNoteRow, type ConversationRow, type ConversationTaskForUserRow, type ConversationTaskRow, type DialpadCallLogRow, type DialpadCallRow, DialpadCallState, type EventPayloadMap, type EventType, type FamilyMemberRow, NoopStore, type OfflineStore, type Patient, type PatientListOptions, type PatientSearchResult, type PermissionStatus, type Physician$1 as Physician, RINGING_CALL_STATES, TERMINAL_CALL_STATES, type TrackOptions, TruthProvider, type TruthProviderProps, type TruthTrackingContextValue, TruthTrackingProvider, type TruthTrackingProviderProps, type UseActiveCallsOptions, type UseAppointmentListOptions, type UseConversationMessagesOptions, type UseConversationsFilters, type UseMessagesOptions, type UseNotificationsActions, type UseNotificationsOptions, type UseNotificationsResult, type UsePatientBasicOptions, type UsePatientBasicResult, type UsePatientFamilyMembersInput, type UsePatientListOptions, type UsePatientMedicalOptions, type UsePatientPhotoOptions, type UsePatientSearchOptions, type UseQueryResult, type UseUserSyncInput, type UseUserSyncResult, getTruthClient, readPersistedSavedAt, resolveApiBaseUrl, resolveConvexUrl, useActiveCalls, useAppointment, useAppointmentByElationId, useAppointments, useConversationById, useConversationByPhonePair, useConversationMessages, useConversationNotes, useConversationNotesByPhonePair, useConversationTaskMarkSeen, useConversationTasks, useConversationTasksByPhonePair, useConversationTasksForUser, useConversations, useDialpadCallByCallId, useDialpadCallLog, useDialpadCallsForConversation, useMessages, useNotifications, useNotificationsActions, useOfflineEnabled, useOfflineStore, usePatient, usePatientBasic, usePatientByElationId, usePatientByHintId, usePatientFamilyMembers, usePatientMedical, usePatientPhoto, usePatientSearch, usePatients, usePatientsByIds, usePatientsByPhones, usePharmacyByNcpdpId, usePhysicianByElationId, usePhysiciansByElationIds, useRemindersForConversations, useTruth, useTruthClient, useTruthSdkContext, useUnreadAggregate, useUnreadCount, useUserSettings, useUserSync, useVoicemailUrl };