@stackframe/stack 2.4.25 → 2.4.27

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 (38) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/components-page/oauth-callback.js +1 -2
  3. package/dist/components-page/oauth-callback.js.map +1 -1
  4. package/dist/esm/components-page/oauth-callback.js +1 -2
  5. package/dist/esm/components-page/oauth-callback.js.map +1 -1
  6. package/dist/esm/global.d.js +1 -0
  7. package/dist/esm/global.d.js.map +1 -0
  8. package/dist/esm/index.js +2 -0
  9. package/dist/esm/index.js.map +1 -1
  10. package/dist/esm/lib/auth.js +1 -2
  11. package/dist/esm/lib/auth.js.map +1 -1
  12. package/dist/esm/lib/cookie.js +2 -2
  13. package/dist/esm/lib/cookie.js.map +1 -1
  14. package/dist/esm/lib/stack-app.js +27 -27
  15. package/dist/esm/lib/stack-app.js.map +1 -1
  16. package/dist/esm/providers/styled-components-registry.js +1 -2
  17. package/dist/esm/providers/styled-components-registry.js.map +1 -1
  18. package/dist/esm/utils/email.js +1 -2
  19. package/dist/esm/utils/email.js.map +1 -1
  20. package/dist/global.d.d.mts +2 -0
  21. package/dist/global.d.d.ts +2 -0
  22. package/dist/global.d.js +2 -0
  23. package/dist/global.d.js.map +1 -0
  24. package/dist/index.d.mts +1 -0
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.js +3 -0
  27. package/dist/index.js.map +1 -1
  28. package/dist/lib/auth.js +1 -2
  29. package/dist/lib/auth.js.map +1 -1
  30. package/dist/lib/cookie.js +2 -2
  31. package/dist/lib/cookie.js.map +1 -1
  32. package/dist/lib/stack-app.js +25 -25
  33. package/dist/lib/stack-app.js.map +1 -1
  34. package/dist/providers/styled-components-registry.js +1 -2
  35. package/dist/providers/styled-components-registry.js.map +1 -1
  36. package/dist/utils/email.js +1 -2
  37. package/dist/utils/email.js.map +1 -1
  38. package/package.json +7 -5
@@ -60,7 +60,7 @@ var import_sessions = require("@stackframe/stack-shared/dist/sessions");
60
60
  var import_use_trigger = require("@stackframe/stack-shared/dist/hooks/use-trigger");
61
61
  var import_strings = require("@stackframe/stack-shared/dist/utils/strings");
62
62
  var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
63
- var clientVersion = "js @stackframe/stack@2.4.25";
63
+ var clientVersion = "js @stackframe/stack@2.4.27";
64
64
  function permissionDefinitionScopeToType(scope) {
65
65
  return { "any-team": "team", "specific-team": "team", "global": "global" }[scope.type];
66
66
  }
@@ -120,21 +120,29 @@ function createEmptyTokenStore() {
120
120
  });
121
121
  }
122
122
  var loadingSentinel = Symbol("stackAppCacheLoadingSentinel");
123
+ var cachePromiseByComponentId = /* @__PURE__ */ new Map();
123
124
  function useAsyncCache(cache, dependencies, caller) {
124
125
  (0, import_react2.suspendIfSsr)(caller);
126
+ const id = import_react.default.useId();
125
127
  const subscribe = (0, import_react.useCallback)((cb) => {
126
- const { unsubscribe } = cache.onChange(dependencies, () => cb());
128
+ const { unsubscribe } = cache.onStateChange(dependencies, () => {
129
+ cachePromiseByComponentId.delete(id);
130
+ cb();
131
+ });
127
132
  return unsubscribe;
128
133
  }, [cache, ...dependencies]);
129
134
  const getSnapshot = (0, import_react.useCallback)(() => {
130
- return import_results.AsyncResult.or(cache.getIfCached(dependencies), loadingSentinel);
135
+ if (!cachePromiseByComponentId.has(id)) {
136
+ cachePromiseByComponentId.set(id, cache.getOrWait(dependencies, "read-write"));
137
+ }
138
+ return cachePromiseByComponentId.get(id);
131
139
  }, [cache, ...dependencies]);
132
- const value = import_react.default.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
133
- if (value === loadingSentinel) {
134
- return (0, import_react.use)(cache.getOrWait(dependencies, "read-write"));
135
- } else {
136
- return (0, import_react.use)((0, import_promises.resolved)(value));
137
- }
140
+ const promise = import_react.default.useSyncExternalStore(
141
+ subscribe,
142
+ getSnapshot,
143
+ () => (0, import_errors.throwErr)(new Error("getServerSnapshot should never be called in useAsyncCache because we restrict to CSR earlier"))
144
+ );
145
+ return (0, import_react.use)(promise);
138
146
  }
139
147
  var stackAppInternalsSymbol = Symbol.for("StackAppInternals");
140
148
  var allClientApps = /* @__PURE__ */ new Map();
@@ -386,17 +394,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
386
394
  if (tokenStoreInit === null) {
387
395
  return createEmptyTokenStore();
388
396
  } else if (typeof tokenStoreInit === "object" && "headers" in tokenStoreInit) {
389
- if (this._requestTokenStores.has(tokenStoreInit))
390
- return this._requestTokenStores.get(tokenStoreInit);
397
+ if (this._requestTokenStores.has(tokenStoreInit)) return this._requestTokenStores.get(tokenStoreInit);
391
398
  const stackAuthHeader = tokenStoreInit.headers.get("x-stack-auth");
392
399
  if (stackAuthHeader) {
393
400
  let parsed2;
394
401
  try {
395
402
  parsed2 = JSON.parse(stackAuthHeader);
396
- if (typeof parsed2 !== "object")
397
- throw new Error("x-stack-auth header must be a JSON object");
398
- if (parsed2 === null)
399
- throw new Error("x-stack-auth header must not be null");
403
+ if (typeof parsed2 !== "object") throw new Error("x-stack-auth header must be a JSON object");
404
+ if (parsed2 === null) throw new Error("x-stack-auth header must not be null");
400
405
  } catch (e) {
401
406
  throw new Error(`Invalid x-stack-auth header: ${stackAuthHeader}`, { cause: e });
402
407
  }
@@ -437,8 +442,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
437
442
  const tokenObj = tokenStore.get();
438
443
  const sessionKey = import_sessions.InternalSession.calculateSessionKey(tokenObj);
439
444
  const existing = sessionKey ? this._sessionsByTokenStoreAndSessionKey.get(tokenStore)?.get(sessionKey) : null;
440
- if (existing)
441
- return existing;
445
+ if (existing) return existing;
442
446
  const session = this._interface.createSession({
443
447
  refreshToken: tokenObj.refreshToken,
444
448
  accessToken: tokenObj.accessToken
@@ -522,8 +526,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
522
526
  };
523
527
  }
524
528
  _teamMemberFromJson(json) {
525
- if (json === null)
526
- return null;
529
+ if (json === null) return null;
527
530
  return {
528
531
  teamId: json.teamId,
529
532
  userId: json.userId,
@@ -1202,8 +1205,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1202
1205
  return currentUser;
1203
1206
  }
1204
1207
  _serverTeamMemberFromJson(json) {
1205
- if (json === null)
1206
- return null;
1208
+ if (json === null) return null;
1207
1209
  const app = this;
1208
1210
  return {
1209
1211
  ...app._teamMemberFromJson(json),
@@ -1436,10 +1438,8 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1436
1438
  return this.whyInvalid() === null;
1437
1439
  },
1438
1440
  whyInvalid() {
1439
- if (this.expiresAt.getTime() < Date.now())
1440
- return "expired";
1441
- if (this.manuallyRevokedAt)
1442
- return "manually-revoked";
1441
+ if (this.expiresAt.getTime() < Date.now()) return "expired";
1442
+ if (this.manuallyRevokedAt) return "manually-revoked";
1443
1443
  return null;
1444
1444
  },
1445
1445
  async revoke() {