@stackframe/stack 2.5.1 → 2.5.3

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.
@@ -265,6 +265,7 @@ type Project = {
265
265
  type Team = {
266
266
  id: string;
267
267
  displayName: string;
268
+ profileImageUrl?: string;
268
269
  createdAt: Date;
269
270
  toJson(): TeamJson;
270
271
  };
@@ -265,6 +265,7 @@ type Project = {
265
265
  type Team = {
266
266
  id: string;
267
267
  displayName: string;
268
+ profileImageUrl?: string;
268
269
  createdAt: Date;
269
270
  toJson(): TeamJson;
270
271
  };
@@ -59,7 +59,7 @@ var cookie = __toESM(require("cookie"));
59
59
  var import_sessions = require("@stackframe/stack-shared/dist/sessions");
60
60
  var import_strings = require("@stackframe/stack-shared/dist/utils/strings");
61
61
  var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
62
- var clientVersion = "js @stackframe/stack@2.5.1";
62
+ var clientVersion = "js @stackframe/stack@2.5.3";
63
63
  function permissionDefinitionScopeToType(scope) {
64
64
  return { "any-team": "team", "specific-team": "team", "global": "global" }[scope.type];
65
65
  }
@@ -165,6 +165,97 @@ var numberOfAppsCreated = 0;
165
165
  var _StackClientAppImpl = class __StackClientAppImpl {
166
166
  constructor(_options) {
167
167
  this._options = _options;
168
+ this._uniqueIdentifier = void 0;
169
+ this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
170
+ this._currentUserCache = createCacheBySession(async (session) => {
171
+ if (this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY) {
172
+ await (0, import_promises.wait)(2e3);
173
+ }
174
+ const user = await this._interface.getClientUserByToken(session);
175
+ return import_results.Result.or(user, null);
176
+ });
177
+ this._currentProjectCache = createCache(async () => {
178
+ return import_results.Result.orThrow(await this._interface.getClientProject());
179
+ });
180
+ this._ownedProjectsCache = createCacheBySession(async (session) => {
181
+ return await this._interface.listProjects(session);
182
+ });
183
+ this._currentUserPermissionsCache = createCacheBySession(async (session, [teamId, type, direct]) => {
184
+ return await this._interface.listClientUserTeamPermissions({ teamId, type, direct }, session);
185
+ });
186
+ this._currentUserTeamsCache = createCacheBySession(async (session) => {
187
+ return await this._interface.listClientUserTeams(session);
188
+ });
189
+ this._currentUserOAuthConnectionAccessTokensCache = createCacheBySession(
190
+ async (session, [accountId, scope]) => {
191
+ try {
192
+ return await this._interface.getAccessToken(accountId, scope || "", session);
193
+ } catch (err) {
194
+ if (!(err instanceof import_stack_shared.KnownErrors.OAuthConnectionDoesNotHaveRequiredScope || err instanceof import_stack_shared.KnownErrors.OAuthConnectionNotConnectedToUser)) {
195
+ throw err;
196
+ }
197
+ }
198
+ return null;
199
+ }
200
+ );
201
+ this._currentUserOAuthConnectionCache = createCacheBySession(
202
+ async (session, [connectionId, scope, redirect]) => {
203
+ const user = await this._currentUserCache.getOrWait([session], "write-only");
204
+ let hasConnection = true;
205
+ if (!user || !user.oauthProviders.find((p) => p === connectionId)) {
206
+ hasConnection = false;
207
+ }
208
+ const token = await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, connectionId, scope || ""], "write-only");
209
+ if (!token) {
210
+ hasConnection = false;
211
+ }
212
+ if (!hasConnection && redirect) {
213
+ await (0, import_auth.addNewOAuthProviderOrScope)(
214
+ this._interface,
215
+ {
216
+ provider: connectionId,
217
+ redirectUrl: this.urls.oauthCallback,
218
+ errorRedirectUrl: this.urls.error,
219
+ providerScope: (0, import_strings.mergeScopeStrings)(scope || "", (this._oauthScopesOnSignIn[connectionId] ?? []).join(" "))
220
+ },
221
+ session
222
+ );
223
+ return await (0, import_promises.neverResolve)();
224
+ } else if (!hasConnection) {
225
+ return null;
226
+ }
227
+ const app = this;
228
+ return {
229
+ id: connectionId,
230
+ async getAccessToken() {
231
+ const result = await app._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, connectionId, scope || ""], "write-only");
232
+ if (!result) {
233
+ throw new import_errors.StackAssertionError("No access token available");
234
+ }
235
+ return result;
236
+ },
237
+ useAccessToken() {
238
+ const result = useAsyncCache(app._currentUserOAuthConnectionAccessTokensCache, [session, connectionId, scope || ""], "oauthAccount.useAccessToken()");
239
+ if (!result) {
240
+ throw new import_errors.StackAssertionError("No access token available");
241
+ }
242
+ return result;
243
+ }
244
+ };
245
+ }
246
+ );
247
+ this._memoryTokenStore = createEmptyTokenStore();
248
+ this._requestTokenStores = /* @__PURE__ */ new WeakMap();
249
+ this._storedCookieTokenStore = null;
250
+ /**
251
+ * A map from token stores and session keys to sessions.
252
+ *
253
+ * This isn't just a map from session keys to sessions for two reasons:
254
+ *
255
+ * - So we can garbage-collect Session objects when the token store is garbage-collected
256
+ * - So different token stores are separated and don't leak information between each other, eg. if the same user sends two requests to the same server they should get a different session object
257
+ */
258
+ this._sessionsByTokenStoreAndSessionKey = /* @__PURE__ */ new WeakMap();
168
259
  if ("interface" in _options) {
169
260
  this._interface = _options.interface;
170
261
  } else {
@@ -187,89 +278,6 @@ var _StackClientAppImpl = class __StackClientAppImpl {
187
278
  (process.env.NODE_ENV === "development" ? console.log : console.warn)(`You have created more than 10 Stack apps (${numberOfAppsCreated}). This is usually a sign of a memory leak, but can sometimes be caused by hot reload of your tech stack. In production, make sure to minimize the number of Stack apps per page (usually, one per project).`);
188
279
  }
189
280
  }
190
- _uniqueIdentifier = void 0;
191
- _interface;
192
- _tokenStoreInit;
193
- _urlOptions;
194
- _oauthScopesOnSignIn;
195
- __DEMO_ENABLE_SLIGHT_FETCH_DELAY = false;
196
- _currentUserCache = createCacheBySession(async (session) => {
197
- if (this.__DEMO_ENABLE_SLIGHT_FETCH_DELAY) {
198
- await (0, import_promises.wait)(2e3);
199
- }
200
- const user = await this._interface.getClientUserByToken(session);
201
- return import_results.Result.or(user, null);
202
- });
203
- _currentProjectCache = createCache(async () => {
204
- return import_results.Result.orThrow(await this._interface.getClientProject());
205
- });
206
- _ownedProjectsCache = createCacheBySession(async (session) => {
207
- return await this._interface.listProjects(session);
208
- });
209
- _currentUserPermissionsCache = createCacheBySession(async (session, [teamId, type, direct]) => {
210
- return await this._interface.listClientUserTeamPermissions({ teamId, type, direct }, session);
211
- });
212
- _currentUserTeamsCache = createCacheBySession(async (session) => {
213
- return await this._interface.listClientUserTeams(session);
214
- });
215
- _currentUserOAuthConnectionAccessTokensCache = createCacheBySession(
216
- async (session, [accountId, scope]) => {
217
- try {
218
- return await this._interface.getAccessToken(accountId, scope || "", session);
219
- } catch (err) {
220
- if (!(err instanceof import_stack_shared.KnownErrors.OAuthConnectionDoesNotHaveRequiredScope || err instanceof import_stack_shared.KnownErrors.OAuthConnectionNotConnectedToUser)) {
221
- throw err;
222
- }
223
- }
224
- return null;
225
- }
226
- );
227
- _currentUserOAuthConnectionCache = createCacheBySession(
228
- async (session, [connectionId, scope, redirect]) => {
229
- const user = await this._currentUserCache.getOrWait([session], "write-only");
230
- let hasConnection = true;
231
- if (!user || !user.oauthProviders.find((p) => p === connectionId)) {
232
- hasConnection = false;
233
- }
234
- const token = await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, connectionId, scope || ""], "write-only");
235
- if (!token) {
236
- hasConnection = false;
237
- }
238
- if (!hasConnection && redirect) {
239
- await (0, import_auth.addNewOAuthProviderOrScope)(
240
- this._interface,
241
- {
242
- provider: connectionId,
243
- redirectUrl: this.urls.oauthCallback,
244
- errorRedirectUrl: this.urls.error,
245
- providerScope: (0, import_strings.mergeScopeStrings)(scope || "", (this._oauthScopesOnSignIn[connectionId] ?? []).join(" "))
246
- },
247
- session
248
- );
249
- return await (0, import_promises.neverResolve)();
250
- } else if (!hasConnection) {
251
- return null;
252
- }
253
- const app = this;
254
- return {
255
- id: connectionId,
256
- async getAccessToken() {
257
- const result = await app._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, connectionId, scope || ""], "write-only");
258
- if (!result) {
259
- throw new import_errors.StackAssertionError("No access token available");
260
- }
261
- return result;
262
- },
263
- useAccessToken() {
264
- const result = useAsyncCache(app._currentUserOAuthConnectionAccessTokensCache, [session, connectionId, scope || ""], "oauthAccount.useAccessToken()");
265
- if (!result) {
266
- throw new import_errors.StackAssertionError("No access token available");
267
- }
268
- return result;
269
- }
270
- };
271
- }
272
- );
273
281
  _initUniqueIdentifier() {
274
282
  if (!this._uniqueIdentifier) {
275
283
  throw new import_errors.StackAssertionError("Unique identifier not initialized");
@@ -297,9 +305,6 @@ var _StackClientAppImpl = class __StackClientAppImpl {
297
305
  (0, import_promises.runAsynchronously)(this._checkFeatureSupport(featureName, options));
298
306
  throw new import_errors.StackAssertionError(`${featureName} is not currently supported. Please reach out to Stack support for more information.`);
299
307
  }
300
- _memoryTokenStore = createEmptyTokenStore();
301
- _requestTokenStores = /* @__PURE__ */ new WeakMap();
302
- _storedCookieTokenStore = null;
303
308
  get _refreshTokenCookieName() {
304
309
  return `stack-refresh-${this.projectId}`;
305
310
  }
@@ -427,15 +432,6 @@ var _StackClientAppImpl = class __StackClientAppImpl {
427
432
  }
428
433
  }
429
434
  }
430
- /**
431
- * A map from token stores and session keys to sessions.
432
- *
433
- * This isn't just a map from session keys to sessions for two reasons:
434
- *
435
- * - So we can garbage-collect Session objects when the token store is garbage-collected
436
- * - So different token stores are separated and don't leak information between each other, eg. if the same user sends two requests to the same server they should get a different session object
437
- */
438
- _sessionsByTokenStoreAndSessionKey = /* @__PURE__ */ new WeakMap();
439
435
  _getSessionFromTokenStore(tokenStore) {
440
436
  const tokenObj = tokenStore.get();
441
437
  const sessionKey = import_sessions.InternalSession.calculateSessionKey(tokenObj);
@@ -517,6 +513,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
517
513
  return {
518
514
  id: json.id,
519
515
  displayName: json.displayName,
516
+ profileImageUrl: json.profileImageUrl,
520
517
  createdAt: new Date(json.createdAtMillis),
521
518
  toJson() {
522
519
  return json;
@@ -1039,33 +1036,6 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1039
1036
  }
1040
1037
  };
1041
1038
  var _StackServerAppImpl = class extends _StackClientAppImpl {
1042
- // TODO override the client user cache to use the server user cache, so we save some requests
1043
- _currentServerUserCache = createCacheBySession(async (session) => {
1044
- const user = await this._interface.getServerUserByToken(session);
1045
- return import_results.Result.or(user, null);
1046
- });
1047
- _serverUsersCache = createCache(async () => {
1048
- return await this._interface.listServerUsers();
1049
- });
1050
- _serverUserCache = createCache(async ([userId]) => {
1051
- const user = await this._interface.getServerUserById(userId);
1052
- return import_results.Result.or(user, null);
1053
- });
1054
- _serverTeamsCache = createCache(async () => {
1055
- return await this._interface.listServerTeams();
1056
- });
1057
- _serverTeamMembersCache = createCache(async ([teamId]) => {
1058
- return await this._interface.listServerTeamMembers(teamId);
1059
- });
1060
- _serverTeamPermissionDefinitionsCache = createCache(async () => {
1061
- return await this._interface.listPermissionDefinitions();
1062
- });
1063
- _serverTeamUserPermissionsCache = createCache(async ([teamId, userId, type, direct]) => {
1064
- return await this._interface.listServerTeamMemberPermissions({ teamId, userId, type, direct });
1065
- });
1066
- _serverEmailTemplatesCache = createCache(async () => {
1067
- return await this._interface.listEmailTemplates();
1068
- });
1069
1039
  constructor(options) {
1070
1040
  super("interface" in options ? {
1071
1041
  interface: options.interface,
@@ -1084,6 +1054,33 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1084
1054
  urls: options.urls ?? {},
1085
1055
  oauthScopesOnSignIn: options.oauthScopesOnSignIn ?? {}
1086
1056
  });
1057
+ // TODO override the client user cache to use the server user cache, so we save some requests
1058
+ this._currentServerUserCache = createCacheBySession(async (session) => {
1059
+ const user = await this._interface.getServerUserByToken(session);
1060
+ return import_results.Result.or(user, null);
1061
+ });
1062
+ this._serverUsersCache = createCache(async () => {
1063
+ return await this._interface.listServerUsers();
1064
+ });
1065
+ this._serverUserCache = createCache(async ([userId]) => {
1066
+ const user = await this._interface.getServerUserById(userId);
1067
+ return import_results.Result.or(user, null);
1068
+ });
1069
+ this._serverTeamsCache = createCache(async () => {
1070
+ return await this._interface.listServerTeams();
1071
+ });
1072
+ this._serverTeamMembersCache = createCache(async ([teamId]) => {
1073
+ return await this._interface.listServerTeamMembers(teamId);
1074
+ });
1075
+ this._serverTeamPermissionDefinitionsCache = createCache(async () => {
1076
+ return await this._interface.listPermissionDefinitions();
1077
+ });
1078
+ this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId, type, direct]) => {
1079
+ return await this._interface.listServerTeamMemberPermissions({ teamId, userId, type, direct });
1080
+ });
1081
+ this._serverEmailTemplatesCache = createCache(async () => {
1082
+ return await this._interface.listEmailTemplates();
1083
+ });
1087
1084
  }
1088
1085
  _createBaseUser(json) {
1089
1086
  return {
@@ -1226,6 +1223,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1226
1223
  return {
1227
1224
  id: json.id,
1228
1225
  displayName: json.displayName,
1226
+ profileImageUrl: json.profileImageUrl,
1229
1227
  createdAt: new Date(json.createdAtMillis),
1230
1228
  async listMembers() {
1231
1229
  return (await app._interface.listServerTeamMembers(json.id)).map((u) => app._serverTeamMemberFromJson(u));
@@ -1409,12 +1407,6 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1409
1407
  }
1410
1408
  };
1411
1409
  var _StackAdminAppImpl = class extends _StackServerAppImpl {
1412
- _adminProjectCache = createCache(async () => {
1413
- return await this._interface.getProject();
1414
- });
1415
- _apiKeySetsCache = createCache(async () => {
1416
- return await this._interface.listApiKeySets();
1417
- });
1418
1410
  constructor(options) {
1419
1411
  super({
1420
1412
  interface: new import_stack_shared.StackAdminInterface({
@@ -1433,6 +1425,12 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1433
1425
  urls: options.urls,
1434
1426
  oauthScopesOnSignIn: options.oauthScopesOnSignIn
1435
1427
  });
1428
+ this._adminProjectCache = createCache(async () => {
1429
+ return await this._interface.getProject();
1430
+ });
1431
+ this._apiKeySetsCache = createCache(async () => {
1432
+ return await this._interface.listApiKeySets();
1433
+ });
1436
1434
  }
1437
1435
  _createApiKeySetBaseFromJson(data) {
1438
1436
  const app = this;