convex 1.42.0 → 1.42.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.
Files changed (46) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/browser.bundle.js +24 -6
  3. package/dist/browser.bundle.js.map +2 -2
  4. package/dist/cjs/browser/sync/authentication_manager.js +21 -4
  5. package/dist/cjs/browser/sync/authentication_manager.js.map +2 -2
  6. package/dist/cjs/browser/sync/client.js +2 -1
  7. package/dist/cjs/browser/sync/client.js.map +2 -2
  8. package/dist/cjs/cli/lib/typecheck.js +28 -10
  9. package/dist/cjs/cli/lib/typecheck.js.map +2 -2
  10. package/dist/cjs/index.js +1 -1
  11. package/dist/cjs/index.js.map +1 -1
  12. package/dist/cjs/server/impl/registration_impl.js +0 -2
  13. package/dist/cjs/server/impl/registration_impl.js.map +2 -2
  14. package/dist/cjs-types/browser/sync/authentication_manager.d.ts +2 -0
  15. package/dist/cjs-types/browser/sync/authentication_manager.d.ts.map +1 -1
  16. package/dist/cjs-types/browser/sync/client.d.ts +16 -0
  17. package/dist/cjs-types/browser/sync/client.d.ts.map +1 -1
  18. package/dist/cjs-types/index.d.ts +1 -1
  19. package/dist/cjs-types/server/impl/registration_impl.d.ts.map +1 -1
  20. package/dist/cli.bundle.cjs +53 -16
  21. package/dist/cli.bundle.cjs.map +3 -3
  22. package/dist/esm/browser/sync/authentication_manager.js +21 -4
  23. package/dist/esm/browser/sync/authentication_manager.js.map +2 -2
  24. package/dist/esm/browser/sync/client.js +2 -1
  25. package/dist/esm/browser/sync/client.js.map +2 -2
  26. package/dist/esm/cli/lib/typecheck.js +28 -10
  27. package/dist/esm/cli/lib/typecheck.js.map +3 -3
  28. package/dist/esm/index.js +1 -1
  29. package/dist/esm/index.js.map +1 -1
  30. package/dist/esm/server/impl/registration_impl.js +0 -2
  31. package/dist/esm/server/impl/registration_impl.js.map +2 -2
  32. package/dist/esm-types/browser/sync/authentication_manager.d.ts +2 -0
  33. package/dist/esm-types/browser/sync/authentication_manager.d.ts.map +1 -1
  34. package/dist/esm-types/browser/sync/client.d.ts +16 -0
  35. package/dist/esm-types/browser/sync/client.d.ts.map +1 -1
  36. package/dist/esm-types/index.d.ts +1 -1
  37. package/dist/esm-types/server/impl/registration_impl.d.ts.map +1 -1
  38. package/dist/react.bundle.js +24 -6
  39. package/dist/react.bundle.js.map +2 -2
  40. package/package.json +1 -1
  41. package/src/browser/sync/authentication_manager.ts +42 -14
  42. package/src/browser/sync/client.ts +17 -0
  43. package/src/cli/lib/typecheck.ts +26 -10
  44. package/src/index.ts +1 -1
  45. package/src/react/ConvexAuthState.test.tsx +145 -0
  46. package/src/server/impl/registration_impl.ts +0 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.42.1
4
+
5
+ - Fixed an issue where the CLI would be unable to find the `tsgo` binary in
6
+ newer versions of `@typescript/native-preview`.
7
+ - Added a new `initialAuthTokenReuse` option to `ConvexReactClient` that
8
+ prevents extra function calls when users re-authenticate.
9
+
3
10
  ## 1.42.0
4
11
 
5
12
  - Added a new `npx convex project create` command that can be used
@@ -29,7 +29,7 @@ var convex = (() => {
29
29
  });
30
30
 
31
31
  // src/index.ts
32
- var version = "1.42.0";
32
+ var version = "1.42.1";
33
33
 
34
34
  // src/values/base64.ts
35
35
  var base64_exports = {};
@@ -2325,6 +2325,7 @@ var convex = (() => {
2325
2325
  clearAuth;
2326
2326
  logger;
2327
2327
  refreshTokenLeewaySeconds;
2328
+ initialAuthTokenReuse;
2328
2329
  // Track last value to avoid redundant calls
2329
2330
  lastRefreshChange;
2330
2331
  // Number of times we have attempted to confirm the latest token. We retry up
@@ -2340,6 +2341,7 @@ var convex = (() => {
2340
2341
  this.clearAuth = callbacks.clearAuth;
2341
2342
  this.logger = config.logger;
2342
2343
  this.refreshTokenLeewaySeconds = config.refreshTokenLeewaySeconds;
2344
+ this.initialAuthTokenReuse = config.initialAuthTokenReuse;
2343
2345
  this.lastRefreshChange = false;
2344
2346
  }
2345
2347
  notifyRefreshChange(isRefreshing) {
@@ -2395,7 +2397,12 @@ var convex = (() => {
2395
2397
  this.syncState.markAuthCompletion();
2396
2398
  if (this.authState.state === "waitingForServerConfirmationOfCachedToken") {
2397
2399
  this._logVerbose("server confirmed auth token is valid");
2398
- void this.refetchToken();
2400
+ const cachedToken = this.syncState.getAuth()?.value;
2401
+ if (this.initialAuthTokenReuse && cachedToken) {
2402
+ this.scheduleTokenRefetch(cachedToken, serverMessage.clientClockSkew);
2403
+ } else {
2404
+ void this.refetchToken();
2405
+ }
2399
2406
  this.authState.config.onAuthChange(true);
2400
2407
  return;
2401
2408
  }
@@ -2526,7 +2533,7 @@ var convex = (() => {
2526
2533
  );
2527
2534
  this.tryRestartSocket();
2528
2535
  }
2529
- scheduleTokenRefetch(token) {
2536
+ scheduleTokenRefetch(token, clientClockSkewMs) {
2530
2537
  if (this.authState.state === "noAuth") {
2531
2538
  return;
2532
2539
  }
@@ -2544,13 +2551,23 @@ var convex = (() => {
2544
2551
  );
2545
2552
  return;
2546
2553
  }
2547
- const tokenValiditySeconds = exp - iat;
2548
- if (tokenValiditySeconds <= 2) {
2554
+ const fullLifetimeSeconds = exp - iat;
2555
+ if (fullLifetimeSeconds <= 2) {
2549
2556
  this.logger.error(
2550
2557
  "Auth token does not live long enough, cannot refetch the token"
2551
2558
  );
2552
2559
  return;
2553
2560
  }
2561
+ let tokenValiditySeconds;
2562
+ if (clientClockSkewMs !== void 0) {
2563
+ const estimatedServerNowSeconds = (Date.now() - clientClockSkewMs) / 1e3;
2564
+ tokenValiditySeconds = exp - estimatedServerNowSeconds;
2565
+ if (tokenValiditySeconds <= 0) {
2566
+ tokenValiditySeconds = 0;
2567
+ }
2568
+ } else {
2569
+ tokenValiditySeconds = fullLifetimeSeconds;
2570
+ }
2554
2571
  let delay = Math.min(
2555
2572
  MAXIMUM_REFRESH_DELAY,
2556
2573
  (tokenValiditySeconds - this.refreshTokenLeewaySeconds) * 1e3
@@ -2775,7 +2792,8 @@ var convex = (() => {
2775
2792
  },
2776
2793
  {
2777
2794
  logger: this.logger,
2778
- refreshTokenLeewaySeconds: authRefreshTokenLeewaySeconds
2795
+ refreshTokenLeewaySeconds: authRefreshTokenLeewaySeconds,
2796
+ initialAuthTokenReuse: options.initialAuthTokenReuse ?? false
2779
2797
  }
2780
2798
  );
2781
2799
  this.optimisticQueryResults = new OptimisticQueryResults();