@stackframe/stack 2.4.11 → 2.4.13

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.
@@ -57,7 +57,7 @@ var import_compile_time = require("@stackframe/stack-shared/dist/utils/compile-t
57
57
  var import_stack_sc = require("@stackframe/stack-sc");
58
58
  var cookie = __toESM(require("cookie"));
59
59
  var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
60
- var clientVersion = "js @stackframe/stack@2.4.11";
60
+ var clientVersion = "js @stackframe/stack@2.4.13";
61
61
  function permissionDefinitionScopeToType(scope) {
62
62
  return { "any-team": "team", "specific-team": "team", "global": "global" }[scope.type];
63
63
  }
@@ -166,7 +166,7 @@ var createCacheByTokenStore = (fetcher) => {
166
166
  {
167
167
  onSubscribe: ([tokenStore], refresh) => {
168
168
  const handlerObj = tokenStore.onChange((newValue, oldValue) => {
169
- if (JSON.stringify(newValue) === JSON.stringify(oldValue))
169
+ if (newValue.refreshToken === oldValue?.refreshToken)
170
170
  return;
171
171
  refresh();
172
172
  });
@@ -175,6 +175,7 @@ var createCacheByTokenStore = (fetcher) => {
175
175
  }
176
176
  );
177
177
  };
178
+ var numberOfAppsCreated = 0;
178
179
  var _StackClientAppImpl = class __StackClientAppImpl {
179
180
  constructor(_options) {
180
181
  this._options = _options;
@@ -190,6 +191,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
190
191
  }
191
192
  this._tokenStoreInit = _options.tokenStore;
192
193
  this._urlOptions = _options.urls ?? {};
194
+ if (_options.uniqueIdentifier) {
195
+ this._uniqueIdentifier = _options.uniqueIdentifier;
196
+ this._initUniqueIdentifier();
197
+ }
198
+ numberOfAppsCreated++;
199
+ if (numberOfAppsCreated > 10) {
200
+ console.warn(`You have created more than 10 Stack apps (${numberOfAppsCreated}). This is usually a sign of a memory leak. Make sure to minimize the number of Stack apps per page (usually, one per project).`);
201
+ }
193
202
  }
194
203
  _uniqueIdentifier = void 0;
195
204
  _interface;
@@ -215,17 +224,23 @@ var _StackClientAppImpl = class __StackClientAppImpl {
215
224
  _currentUserTeamsCache = createCacheByTokenStore(async (tokenStore) => {
216
225
  return await this._interface.listClientUserTeams(tokenStore);
217
226
  });
227
+ _initUniqueIdentifier() {
228
+ if (!this._uniqueIdentifier) {
229
+ throw new import_errors.StackAssertionError("Unique identifier not initialized");
230
+ }
231
+ if (allClientApps.has(this._uniqueIdentifier)) {
232
+ throw new import_errors.StackAssertionError("A Stack client app with the same unique identifier already exists");
233
+ }
234
+ allClientApps.set(this._uniqueIdentifier, [this._options.checkString ?? "default check string", this]);
235
+ }
218
236
  /**
219
237
  * Cloudflare workers does not allow use of randomness on the global scope (on which the Stack app is probably
220
238
  * initialized). For that reason, we generate the unique identifier lazily when it is first needed.
221
239
  */
222
240
  _getUniqueIdentifier() {
223
241
  if (!this._uniqueIdentifier) {
224
- this._uniqueIdentifier = this._options.uniqueIdentifier || (0, import_uuids.generateUuid)();
225
- if (allClientApps.has(this._uniqueIdentifier)) {
226
- throw new import_errors.StackAssertionError("A Stack client app with the same unique identifier already exists");
227
- }
228
- allClientApps.set(this._uniqueIdentifier, [this._options.checkString ?? "default check string", this]);
242
+ this._uniqueIdentifier = (0, import_uuids.generateUuid)();
243
+ this._initUniqueIdentifier();
229
244
  }
230
245
  return this._uniqueIdentifier;
231
246
  }
@@ -410,6 +425,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
410
425
  const currentUser = {
411
426
  ...this._userFromJson(json),
412
427
  tokenStore,
428
+ async refreshAccessToken() {
429
+ await app._interface.refreshAccessToken(tokenStore);
430
+ },
413
431
  async updateSelectedTeam(team) {
414
432
  await app._updateUser({ selectedTeamId: team?.id ?? null }, tokenStore);
415
433
  },
@@ -487,7 +505,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
487
505
  baseUrl: this._interface.options.baseUrl,
488
506
  projectId: forProjectId,
489
507
  clientVersion,
490
- projectOwnerTokens: tokenStore
508
+ projectOwnerTokens: tokenStore,
509
+ refreshProjectOwnerTokens: async () => await this._interface.refreshAccessToken(tokenStore)
491
510
  });
492
511
  }
493
512
  get projectId() {
@@ -599,7 +618,10 @@ var _StackClientAppImpl = class __StackClientAppImpl {
599
618
  if (userJson === null) {
600
619
  switch (options?.or) {
601
620
  case "redirect": {
602
- router.replace(this.urls.signIn);
621
+ (0, import_promises.runAsynchronously)(async () => {
622
+ await (0, import_promises.wait)(0);
623
+ router.replace(this.urls.signIn);
624
+ });
603
625
  (0, import_react3.suspend)();
604
626
  throw new import_errors.StackAssertionError("suspend should never return");
605
627
  }
@@ -941,6 +963,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
941
963
  const currentUser = {
942
964
  ...nonCurrentServerUser,
943
965
  tokenStore,
966
+ async refreshAccessToken() {
967
+ await app._interface.refreshAccessToken(tokenStore);
968
+ },
944
969
  async delete() {
945
970
  const res = await nonCurrentServerUser.delete();
946
971
  await app._refreshUser(tokenStore);
@@ -1166,7 +1191,8 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1166
1191
  projectId: options.projectId ?? getDefaultProjectId(),
1167
1192
  clientVersion,
1168
1193
  ..."projectOwnerTokens" in options ? {
1169
- projectOwnerTokens: options.projectOwnerTokens
1194
+ projectOwnerTokens: options.projectOwnerTokens,
1195
+ refreshProjectOwnerTokens: options.refreshProjectOwnerTokens
1170
1196
  } : {
1171
1197
  publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
1172
1198
  secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey(),