@hipnation-truth/sdk 0.26.7 → 0.26.9

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
@@ -2779,13 +2779,14 @@ interface TruthSdkContextValue {
2779
2779
  * signed-out render throws UNAUTHENTICATED and blanks the app. When no
2780
2780
  * fetcher is configured this stays false and queries run unconditionally
2781
2781
  * (legacy behavior).
2782
+ *
2783
+ * The "is the caller authenticated yet" half of the gate is no longer
2784
+ * tracked here: `<TruthProvider>` now mounts `ConvexProviderWithAuth`,
2785
+ * so `useConvexQueriesReady()` reads Convex's own server-acknowledged
2786
+ * `useConvexAuth().isAuthenticated`. `authGated` only answers "should we
2787
+ * gate at all", which still depends on whether a fetcher was supplied.
2782
2788
  */
2783
2789
  authGated: boolean;
2784
- /**
2785
- * Whether Convex currently considers the caller authenticated (driven
2786
- * by `setAuth`'s onChange). Only meaningful when `authGated` is true.
2787
- */
2788
- authReady: boolean;
2789
2790
  }
2790
2791
  /**
2791
2792
  * Read the Truth REST API base URL + API key + shared client from
package/dist/react.js CHANGED
@@ -122,13 +122,15 @@ __export(react_exports, {
122
122
  module.exports = __toCommonJS(react_exports);
123
123
 
124
124
  // src/react/calls.ts
125
- var import_react3 = require("convex/react");
126
125
  var import_server2 = require("convex/server");
127
126
 
128
127
  // src/react/offline/use-persistent-query.ts
129
128
  var import_react_query3 = require("@convex-dev/react-query");
130
129
  var import_react_query4 = require("@tanstack/react-query");
131
130
 
131
+ // src/react/queries-ready.ts
132
+ var import_react3 = require("convex/react");
133
+
132
134
  // src/react/provider.ts
133
135
  var import_react_query = require("@convex-dev/react-query");
134
136
  var import_react_query2 = require("@tanstack/react-query");
@@ -2302,29 +2304,42 @@ function TruthProvider({
2302
2304
  }) : void 0,
2303
2305
  [hasAuthFetcher]
2304
2306
  );
2305
- const [convexAuthed, setConvexAuthed] = (0, import_react2.useState)(false);
2307
+ const [tokenAttempted, setTokenAttempted] = (0, import_react2.useState)(false);
2306
2308
  (0, import_react2.useEffect)(() => {
2307
- if (!stableGetAuthToken) {
2308
- convexClient.clearAuth();
2309
- setConvexAuthed(false);
2310
- return;
2311
- }
2312
- const fetchToken = (opts) => __async(null, null, function* () {
2309
+ setTokenAttempted(false);
2310
+ }, [stableGetAuthToken]);
2311
+ const fetchAccessToken = (0, import_react2.useCallback)(
2312
+ (_0) => __async(null, [_0], function* ({
2313
+ forceRefreshToken
2314
+ }) {
2315
+ var _a2;
2316
+ const fetcher = stableGetAuthToken;
2317
+ if (!fetcher) {
2318
+ setTokenAttempted(true);
2319
+ return null;
2320
+ }
2321
+ let token = null;
2313
2322
  for (let attempt = 0; attempt < 6; attempt++) {
2314
2323
  try {
2315
- const token = yield stableGetAuthToken(opts);
2316
- if (token) return token;
2324
+ token = (_a2 = yield fetcher({ forceRefreshToken })) != null ? _a2 : null;
2325
+ if (token) break;
2317
2326
  } catch (e) {
2318
2327
  }
2319
2328
  yield new Promise((resolve) => setTimeout(resolve, 200 + attempt * 150));
2320
2329
  }
2321
- return null;
2322
- });
2323
- convexClient.setAuth(
2324
- fetchToken,
2325
- (isAuthenticated) => setConvexAuthed(isAuthenticated)
2326
- );
2327
- }, [convexClient, stableGetAuthToken]);
2330
+ setTokenAttempted(true);
2331
+ return token;
2332
+ }),
2333
+ [stableGetAuthToken]
2334
+ );
2335
+ const useConvexAuthAdapter = (0, import_react2.useCallback)(
2336
+ () => ({
2337
+ isLoading: hasAuthFetcher && !tokenAttempted,
2338
+ isAuthenticated: hasAuthFetcher,
2339
+ fetchAccessToken
2340
+ }),
2341
+ [hasAuthFetcher, tokenAttempted, fetchAccessToken]
2342
+ );
2328
2343
  const convexQueryClient = (0, import_react2.useMemo)(
2329
2344
  () => new import_react_query.ConvexQueryClient(convexClient),
2330
2345
  [convexClient]
@@ -2399,8 +2414,7 @@ function TruthProvider({
2399
2414
  offlineStore,
2400
2415
  offlineEnabled,
2401
2416
  getAuthToken: stableGetAuthToken,
2402
- authGated: hasAuthFetcher,
2403
- authReady: convexAuthed
2417
+ authGated: hasAuthFetcher
2404
2418
  }),
2405
2419
  [
2406
2420
  resolvedApiBaseUrl,
@@ -2410,15 +2424,9 @@ function TruthProvider({
2410
2424
  offlineStore,
2411
2425
  offlineEnabled,
2412
2426
  stableGetAuthToken,
2413
- hasAuthFetcher,
2414
- convexAuthed
2427
+ hasAuthFetcher
2415
2428
  ]
2416
2429
  );
2417
- const convexTree = (0, import_react2.createElement)(
2418
- import_react.ConvexProvider,
2419
- { client: convexClient },
2420
- children
2421
- );
2422
2430
  const queryTree = persister ? (0, import_react2.createElement)(
2423
2431
  import_react_query_persist_client.PersistQueryClientProvider,
2424
2432
  {
@@ -2431,22 +2439,28 @@ function TruthProvider({
2431
2439
  buster: String(SCHEMA_VERSION)
2432
2440
  }
2433
2441
  },
2434
- convexTree
2435
- ) : (0, import_react2.createElement)(import_react_query2.QueryClientProvider, { client: queryClient }, convexTree);
2442
+ children
2443
+ ) : (0, import_react2.createElement)(import_react_query2.QueryClientProvider, { client: queryClient }, children);
2444
+ const authedTree = (0, import_react2.createElement)(
2445
+ import_react.ConvexProviderWithAuth,
2446
+ { client: convexClient, useAuth: useConvexAuthAdapter },
2447
+ queryTree
2448
+ );
2436
2449
  return (0, import_react2.createElement)(
2437
2450
  TruthSdkContext.Provider,
2438
2451
  { value: sdkContext },
2439
- queryTree
2452
+ authedTree
2440
2453
  );
2441
2454
  }
2442
2455
 
2443
2456
  // src/react/queries-ready.ts
2444
2457
  function useConvexQueriesReady() {
2445
2458
  const ctx = useTruthSdkContext();
2459
+ const { isAuthenticated } = (0, import_react3.useConvexAuth)();
2446
2460
  if (!(ctx == null ? void 0 : ctx.authGated)) {
2447
2461
  return true;
2448
2462
  }
2449
- return ctx.authReady;
2463
+ return isAuthenticated;
2450
2464
  }
2451
2465
 
2452
2466
  // src/react/offline/use-persistent-query.ts
@@ -2505,7 +2519,7 @@ function toResult(value, skipped) {
2505
2519
  }
2506
2520
  function useActiveCalls(options) {
2507
2521
  const ready = useConvexQueriesReady();
2508
- const result = (0, import_react3.useQuery)(listActiveRef, ready ? options != null ? options : {} : "skip");
2522
+ const result = usePersistentQuery(listActiveRef, ready ? options != null ? options : {} : "skip");
2509
2523
  return toResult(result, false);
2510
2524
  }
2511
2525
  function useDialpadCallsForConversation(conversationId, options) {