@hipnation-truth/sdk 0.26.10 → 0.26.12
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 +12 -1
- package/dist/react.js +80 -25
- package/dist/react.js.map +1 -1
- package/package.json +1 -1
package/dist/react.d.ts
CHANGED
|
@@ -2853,6 +2853,17 @@ interface TruthProviderProps {
|
|
|
2853
2853
|
* a ref on every call.
|
|
2854
2854
|
*/
|
|
2855
2855
|
getAuthToken?: AuthTokenFetcher;
|
|
2856
|
+
/**
|
|
2857
|
+
* Whether the caller's identity provider reports a signed-in user.
|
|
2858
|
+
* Optional but RECOMMENDED when `getAuthToken` is wired — pass
|
|
2859
|
+
* `useAuth().isSignedIn` (Clerk). It lets the provider settle to a
|
|
2860
|
+
* signed-out state instantly (no token to fetch) and, crucially,
|
|
2861
|
+
* re-resolve the token the moment the user signs in. When omitted, the
|
|
2862
|
+
* provider falls back to probing `getAuthToken` with a bounded retry to
|
|
2863
|
+
* decide signed-in vs. signed-out, which is robust at load but not
|
|
2864
|
+
* reactive to a later sign-in without a remount.
|
|
2865
|
+
*/
|
|
2866
|
+
isSignedIn?: boolean;
|
|
2856
2867
|
/**
|
|
2857
2868
|
* Synchronous encrypted KV mirror for durable offline reads, injected
|
|
2858
2869
|
* by the consuming app (e.g. MMKV on `ch/`). Omit on web — the SDK
|
|
@@ -2870,7 +2881,7 @@ interface TruthProviderProps {
|
|
|
2870
2881
|
offlineEnabled?: boolean;
|
|
2871
2882
|
children: ReactNode;
|
|
2872
2883
|
}
|
|
2873
|
-
declare function TruthProvider({ environment, convexUrl, apiBaseUrl, apiKey, source, sourceVersion, tenantId, getAuthToken, offlineStore, offlineEnabled, children, }: TruthProviderProps): react.FunctionComponentElement<react.ProviderProps<TruthSdkContextValue | null>>;
|
|
2884
|
+
declare function TruthProvider({ environment, convexUrl, apiBaseUrl, apiKey, source, sourceVersion, tenantId, getAuthToken, isSignedIn, offlineStore, offlineEnabled, children, }: TruthProviderProps): react.FunctionComponentElement<react.ProviderProps<TruthSdkContextValue | null>>;
|
|
2874
2885
|
|
|
2875
2886
|
/**
|
|
2876
2887
|
* React hooks for conversation reminders — bulk lookup keyed by
|
package/dist/react.js
CHANGED
|
@@ -2285,6 +2285,7 @@ function TruthProvider({
|
|
|
2285
2285
|
sourceVersion,
|
|
2286
2286
|
tenantId,
|
|
2287
2287
|
getAuthToken,
|
|
2288
|
+
isSignedIn,
|
|
2288
2289
|
offlineStore = NOOP_STORE,
|
|
2289
2290
|
offlineEnabled = false,
|
|
2290
2291
|
children
|
|
@@ -2310,10 +2311,47 @@ function TruthProvider({
|
|
|
2310
2311
|
}) : void 0,
|
|
2311
2312
|
[hasAuthFetcher]
|
|
2312
2313
|
);
|
|
2313
|
-
const [
|
|
2314
|
+
const [tokenPhase, setTokenPhase] = (0, import_react2.useState)(
|
|
2315
|
+
hasAuthFetcher ? "pending" : "anon"
|
|
2316
|
+
);
|
|
2314
2317
|
(0, import_react2.useEffect)(() => {
|
|
2315
|
-
|
|
2316
|
-
|
|
2318
|
+
if (!hasAuthFetcher) {
|
|
2319
|
+
setTokenPhase("anon");
|
|
2320
|
+
return;
|
|
2321
|
+
}
|
|
2322
|
+
if (isSignedIn === false) {
|
|
2323
|
+
setTokenPhase("anon");
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
let cancelled = false;
|
|
2327
|
+
setTokenPhase("pending");
|
|
2328
|
+
void (() => __async(null, null, function* () {
|
|
2329
|
+
var _a2, _b2;
|
|
2330
|
+
for (let attempt = 0; attempt < 8 && !cancelled; attempt++) {
|
|
2331
|
+
let token = null;
|
|
2332
|
+
try {
|
|
2333
|
+
token = (_b2 = yield (_a2 = getAuthTokenRef.current) == null ? void 0 : _a2.call(getAuthTokenRef, { forceRefreshToken: false })) != null ? _b2 : null;
|
|
2334
|
+
} catch (e) {
|
|
2335
|
+
}
|
|
2336
|
+
if (cancelled) {
|
|
2337
|
+
return;
|
|
2338
|
+
}
|
|
2339
|
+
if (token) {
|
|
2340
|
+
setTokenPhase("authed");
|
|
2341
|
+
return;
|
|
2342
|
+
}
|
|
2343
|
+
yield new Promise(
|
|
2344
|
+
(resolve) => setTimeout(resolve, 300 + attempt * 300)
|
|
2345
|
+
);
|
|
2346
|
+
}
|
|
2347
|
+
if (!cancelled) {
|
|
2348
|
+
setTokenPhase("anon");
|
|
2349
|
+
}
|
|
2350
|
+
}))();
|
|
2351
|
+
return () => {
|
|
2352
|
+
cancelled = true;
|
|
2353
|
+
};
|
|
2354
|
+
}, [hasAuthFetcher, isSignedIn, stableGetAuthToken]);
|
|
2317
2355
|
const fetchAccessToken = (0, import_react2.useCallback)(
|
|
2318
2356
|
(_0) => __async(null, [_0], function* ({
|
|
2319
2357
|
forceRefreshToken
|
|
@@ -2321,7 +2359,6 @@ function TruthProvider({
|
|
|
2321
2359
|
var _a2;
|
|
2322
2360
|
const fetcher = stableGetAuthToken;
|
|
2323
2361
|
if (!fetcher) {
|
|
2324
|
-
setTokenAttempted(true);
|
|
2325
2362
|
return null;
|
|
2326
2363
|
}
|
|
2327
2364
|
let token = null;
|
|
@@ -2331,20 +2368,24 @@ function TruthProvider({
|
|
|
2331
2368
|
if (token) break;
|
|
2332
2369
|
} catch (e) {
|
|
2333
2370
|
}
|
|
2334
|
-
yield new Promise(
|
|
2371
|
+
yield new Promise(
|
|
2372
|
+
(resolve) => setTimeout(resolve, 200 + attempt * 150)
|
|
2373
|
+
);
|
|
2335
2374
|
}
|
|
2336
|
-
setTokenAttempted(true);
|
|
2337
2375
|
return token;
|
|
2338
2376
|
}),
|
|
2339
2377
|
[stableGetAuthToken]
|
|
2340
2378
|
);
|
|
2341
2379
|
const useConvexAuthAdapter = (0, import_react2.useCallback)(
|
|
2342
2380
|
() => ({
|
|
2343
|
-
isLoading: hasAuthFetcher &&
|
|
2344
|
-
|
|
2381
|
+
isLoading: hasAuthFetcher && tokenPhase === "pending",
|
|
2382
|
+
// REAL token presence — see `tokenPhase` above. Flipping this true
|
|
2383
|
+
// only once a token exists is what stops `setAuth` from resuming the
|
|
2384
|
+
// socket unauthenticated on web.
|
|
2385
|
+
isAuthenticated: hasAuthFetcher && tokenPhase === "authed",
|
|
2345
2386
|
fetchAccessToken
|
|
2346
2387
|
}),
|
|
2347
|
-
[hasAuthFetcher,
|
|
2388
|
+
[hasAuthFetcher, tokenPhase, fetchAccessToken]
|
|
2348
2389
|
);
|
|
2349
2390
|
const convexQueryClient = (0, import_react2.useMemo)(
|
|
2350
2391
|
() => new import_react_query.ConvexQueryClient(convexClient),
|
|
@@ -2713,6 +2754,17 @@ function useConversationTasksByPhonePair(phonePair) {
|
|
|
2713
2754
|
|
|
2714
2755
|
// src/react/hooks.ts
|
|
2715
2756
|
var import_react5 = require("react");
|
|
2757
|
+
|
|
2758
|
+
// src/react/elation-id.ts
|
|
2759
|
+
function toFiniteElationId(value) {
|
|
2760
|
+
if (value === void 0 || value === null || value === "") {
|
|
2761
|
+
return void 0;
|
|
2762
|
+
}
|
|
2763
|
+
const n = typeof value === "number" ? value : Number(value);
|
|
2764
|
+
return Number.isFinite(n) ? n : void 0;
|
|
2765
|
+
}
|
|
2766
|
+
|
|
2767
|
+
// src/react/hooks.ts
|
|
2716
2768
|
var import_server5 = require("convex/server");
|
|
2717
2769
|
var patientsListRef = (0, import_server5.makeFunctionReference)("patients:list");
|
|
2718
2770
|
var patientsGetRef = (0, import_server5.makeFunctionReference)("patients:get");
|
|
@@ -2796,24 +2848,25 @@ function usePatientMedical(elationId, options) {
|
|
|
2796
2848
|
const apiBaseUrl = (_a = options == null ? void 0 : options.apiBaseUrl) != null ? _a : sdkContext == null ? void 0 : sdkContext.apiBaseUrl;
|
|
2797
2849
|
const apiKey = (_b = options == null ? void 0 : options.apiKey) != null ? _b : sdkContext == null ? void 0 : sdkContext.apiKey;
|
|
2798
2850
|
const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
|
|
2851
|
+
const id = toFiniteElationId(elationId);
|
|
2799
2852
|
const medications = usePersistentQuery(
|
|
2800
2853
|
medicationsByPatientRef,
|
|
2801
|
-
|
|
2854
|
+
id !== void 0 ? { elationPatientId: id } : "skip"
|
|
2802
2855
|
);
|
|
2803
2856
|
const problems = usePersistentQuery(
|
|
2804
2857
|
problemsByPatientRef,
|
|
2805
|
-
|
|
2858
|
+
id !== void 0 ? { elationPatientId: id } : "skip"
|
|
2806
2859
|
);
|
|
2807
2860
|
const allergies = usePersistentQuery(
|
|
2808
2861
|
allergiesByPatientRef,
|
|
2809
|
-
|
|
2862
|
+
id !== void 0 ? { elationPatientId: id } : "skip"
|
|
2810
2863
|
);
|
|
2811
2864
|
const appointments = usePersistentQuery(
|
|
2812
2865
|
appointmentsByPatientRef,
|
|
2813
|
-
|
|
2866
|
+
id !== void 0 ? { elationPatientId: id } : "skip"
|
|
2814
2867
|
);
|
|
2815
2868
|
(0, import_react5.useEffect)(() => {
|
|
2816
|
-
if (
|
|
2869
|
+
if (id === void 0 || (options == null ? void 0 : options.skipRefresh)) {
|
|
2817
2870
|
return;
|
|
2818
2871
|
}
|
|
2819
2872
|
if (!apiBaseUrl || !apiKey) {
|
|
@@ -2824,12 +2877,12 @@ function usePatientMedical(elationId, options) {
|
|
|
2824
2877
|
`${apiBaseUrl}/api/patients/medical/refresh`,
|
|
2825
2878
|
apiKey,
|
|
2826
2879
|
getAuthToken,
|
|
2827
|
-
{ elationId },
|
|
2880
|
+
{ elationId: id },
|
|
2828
2881
|
controller.signal
|
|
2829
2882
|
).catch(() => {
|
|
2830
2883
|
});
|
|
2831
2884
|
return () => controller.abort();
|
|
2832
|
-
}, [
|
|
2885
|
+
}, [id, apiBaseUrl, apiKey, getAuthToken, options == null ? void 0 : options.skipRefresh]);
|
|
2833
2886
|
return { medications, problems, allergies, appointments };
|
|
2834
2887
|
}
|
|
2835
2888
|
var elationPatientByIdRef = (0, import_server5.makeFunctionReference)("elationPatients:getByElationId");
|
|
@@ -2842,9 +2895,10 @@ function usePatientBasic(input, options) {
|
|
|
2842
2895
|
const apiBaseUrl = (_a = options == null ? void 0 : options.apiBaseUrl) != null ? _a : sdkContext == null ? void 0 : sdkContext.apiBaseUrl;
|
|
2843
2896
|
const apiKey = (_b = options == null ? void 0 : options.apiKey) != null ? _b : sdkContext == null ? void 0 : sdkContext.apiKey;
|
|
2844
2897
|
const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
|
|
2898
|
+
const elationId = toFiniteElationId(input.elationId);
|
|
2845
2899
|
const elationRow = usePersistentQuery(
|
|
2846
2900
|
elationPatientByIdRef,
|
|
2847
|
-
|
|
2901
|
+
elationId !== void 0 ? { elationId } : "skip"
|
|
2848
2902
|
);
|
|
2849
2903
|
const hintRow = usePersistentQuery(
|
|
2850
2904
|
hintPatientByIdRef,
|
|
@@ -2854,7 +2908,7 @@ function usePatientBasic(input, options) {
|
|
|
2854
2908
|
if (options == null ? void 0 : options.skipRefresh) {
|
|
2855
2909
|
return;
|
|
2856
2910
|
}
|
|
2857
|
-
if (!input.hintId &&
|
|
2911
|
+
if (!input.hintId && elationId === void 0) {
|
|
2858
2912
|
return;
|
|
2859
2913
|
}
|
|
2860
2914
|
if (!apiBaseUrl || !apiKey) {
|
|
@@ -2865,14 +2919,14 @@ function usePatientBasic(input, options) {
|
|
|
2865
2919
|
`${apiBaseUrl}/api/patients/basic/refresh`,
|
|
2866
2920
|
apiKey,
|
|
2867
2921
|
getAuthToken,
|
|
2868
|
-
{ hintId: input.hintId, elationId
|
|
2922
|
+
{ hintId: input.hintId, elationId },
|
|
2869
2923
|
controller.signal
|
|
2870
2924
|
).catch(() => {
|
|
2871
2925
|
});
|
|
2872
2926
|
return () => controller.abort();
|
|
2873
2927
|
}, [
|
|
2874
2928
|
input.hintId,
|
|
2875
|
-
|
|
2929
|
+
elationId,
|
|
2876
2930
|
apiBaseUrl,
|
|
2877
2931
|
apiKey,
|
|
2878
2932
|
getAuthToken,
|
|
@@ -2880,7 +2934,7 @@ function usePatientBasic(input, options) {
|
|
|
2880
2934
|
]);
|
|
2881
2935
|
const elationPatient = elationRow === void 0 ? void 0 : elationRow === null ? null : (_c = elationRow.raw) != null ? _c : null;
|
|
2882
2936
|
const hintPatient = hintRow === void 0 ? void 0 : hintRow === null ? null : (_d = hintRow.raw) != null ? _d : null;
|
|
2883
|
-
const elationLoading =
|
|
2937
|
+
const elationLoading = elationId !== void 0 && elationRow === void 0;
|
|
2884
2938
|
const hintLoading = input.hintId !== void 0 && hintRow === void 0;
|
|
2885
2939
|
return {
|
|
2886
2940
|
elationPatient,
|
|
@@ -2902,15 +2956,16 @@ function usePatientPhoto(elationId, options) {
|
|
|
2902
2956
|
const apiBaseUrl = (_a = options == null ? void 0 : options.apiBaseUrl) != null ? _a : sdkContext == null ? void 0 : sdkContext.apiBaseUrl;
|
|
2903
2957
|
const apiKey = (_b = options == null ? void 0 : options.apiKey) != null ? _b : sdkContext == null ? void 0 : sdkContext.apiKey;
|
|
2904
2958
|
const getAuthToken = sdkContext == null ? void 0 : sdkContext.getAuthToken;
|
|
2959
|
+
const id = toFiniteElationId(elationId);
|
|
2905
2960
|
const photo = usePersistentQuery(
|
|
2906
2961
|
patientPhotoByIdRef,
|
|
2907
|
-
|
|
2962
|
+
id !== void 0 ? { elationPatientId: id } : "skip"
|
|
2908
2963
|
);
|
|
2909
2964
|
(0, import_react5.useEffect)(() => {
|
|
2910
2965
|
if (options == null ? void 0 : options.skipRefresh) {
|
|
2911
2966
|
return;
|
|
2912
2967
|
}
|
|
2913
|
-
if (
|
|
2968
|
+
if (id === void 0) {
|
|
2914
2969
|
return;
|
|
2915
2970
|
}
|
|
2916
2971
|
if (!apiBaseUrl || !apiKey) {
|
|
@@ -2921,12 +2976,12 @@ function usePatientPhoto(elationId, options) {
|
|
|
2921
2976
|
`${apiBaseUrl}/api/patients/photo/refresh`,
|
|
2922
2977
|
apiKey,
|
|
2923
2978
|
getAuthToken,
|
|
2924
|
-
{ elationId },
|
|
2979
|
+
{ elationId: id },
|
|
2925
2980
|
controller.signal
|
|
2926
2981
|
).catch(() => {
|
|
2927
2982
|
});
|
|
2928
2983
|
return () => controller.abort();
|
|
2929
|
-
}, [
|
|
2984
|
+
}, [id, apiBaseUrl, apiKey, getAuthToken, options == null ? void 0 : options.skipRefresh]);
|
|
2930
2985
|
return photo;
|
|
2931
2986
|
}
|
|
2932
2987
|
var messagesByPhonesRef = (0, import_server5.makeFunctionReference)("conversationMessages:getByPhones");
|