@hipnation-truth/sdk 0.26.9 → 0.26.11
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 +58 -11
- 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
|
|
@@ -2293,10 +2294,16 @@ function TruthProvider({
|
|
|
2293
2294
|
const url = resolveConvexUrl(environment, convexUrl);
|
|
2294
2295
|
const resolvedApiBaseUrl = (_a = apiBaseUrl != null ? apiBaseUrl : readEnv("EXPO_PUBLIC_TRUTH_API_BASE_URL")) != null ? _a : resolveApiBaseUrl(environment);
|
|
2295
2296
|
const resolvedApiKey = (_b = apiKey != null ? apiKey : readEnv("EXPO_PUBLIC_TRUTH_API_KEY")) != null ? _b : "";
|
|
2296
|
-
const
|
|
2297
|
+
const hasAuthFetcher = Boolean(getAuthToken);
|
|
2298
|
+
const convexClient = (0, import_react2.useMemo)(
|
|
2299
|
+
() => new import_react.ConvexReactClient(
|
|
2300
|
+
url,
|
|
2301
|
+
hasAuthFetcher ? { expectAuth: true } : void 0
|
|
2302
|
+
),
|
|
2303
|
+
[url, hasAuthFetcher]
|
|
2304
|
+
);
|
|
2297
2305
|
const getAuthTokenRef = (0, import_react2.useRef)(getAuthToken);
|
|
2298
2306
|
getAuthTokenRef.current = getAuthToken;
|
|
2299
|
-
const hasAuthFetcher = Boolean(getAuthToken);
|
|
2300
2307
|
const stableGetAuthToken = (0, import_react2.useMemo)(
|
|
2301
2308
|
() => hasAuthFetcher ? (opts) => __async(null, null, function* () {
|
|
2302
2309
|
var _a2, _b2;
|
|
@@ -2304,10 +2311,47 @@ function TruthProvider({
|
|
|
2304
2311
|
}) : void 0,
|
|
2305
2312
|
[hasAuthFetcher]
|
|
2306
2313
|
);
|
|
2307
|
-
const [
|
|
2314
|
+
const [tokenPhase, setTokenPhase] = (0, import_react2.useState)(
|
|
2315
|
+
hasAuthFetcher ? "pending" : "anon"
|
|
2316
|
+
);
|
|
2308
2317
|
(0, import_react2.useEffect)(() => {
|
|
2309
|
-
|
|
2310
|
-
|
|
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]);
|
|
2311
2355
|
const fetchAccessToken = (0, import_react2.useCallback)(
|
|
2312
2356
|
(_0) => __async(null, [_0], function* ({
|
|
2313
2357
|
forceRefreshToken
|
|
@@ -2315,7 +2359,6 @@ function TruthProvider({
|
|
|
2315
2359
|
var _a2;
|
|
2316
2360
|
const fetcher = stableGetAuthToken;
|
|
2317
2361
|
if (!fetcher) {
|
|
2318
|
-
setTokenAttempted(true);
|
|
2319
2362
|
return null;
|
|
2320
2363
|
}
|
|
2321
2364
|
let token = null;
|
|
@@ -2325,20 +2368,24 @@ function TruthProvider({
|
|
|
2325
2368
|
if (token) break;
|
|
2326
2369
|
} catch (e) {
|
|
2327
2370
|
}
|
|
2328
|
-
yield new Promise(
|
|
2371
|
+
yield new Promise(
|
|
2372
|
+
(resolve) => setTimeout(resolve, 200 + attempt * 150)
|
|
2373
|
+
);
|
|
2329
2374
|
}
|
|
2330
|
-
setTokenAttempted(true);
|
|
2331
2375
|
return token;
|
|
2332
2376
|
}),
|
|
2333
2377
|
[stableGetAuthToken]
|
|
2334
2378
|
);
|
|
2335
2379
|
const useConvexAuthAdapter = (0, import_react2.useCallback)(
|
|
2336
2380
|
() => ({
|
|
2337
|
-
isLoading: hasAuthFetcher &&
|
|
2338
|
-
|
|
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",
|
|
2339
2386
|
fetchAccessToken
|
|
2340
2387
|
}),
|
|
2341
|
-
[hasAuthFetcher,
|
|
2388
|
+
[hasAuthFetcher, tokenPhase, fetchAccessToken]
|
|
2342
2389
|
);
|
|
2343
2390
|
const convexQueryClient = (0, import_react2.useMemo)(
|
|
2344
2391
|
() => new import_react_query.ConvexQueryClient(convexClient),
|