@stackframe/js 2.7.8 → 2.7.16

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.
@@ -301,13 +301,14 @@ type UserUpdateOptions = {
301
301
  passkeyAuthEnabled?: boolean;
302
302
  };
303
303
  type ServerBaseUser = {
304
- setPrimaryEmail(email: string, options?: {
304
+ setPrimaryEmail(email: string | null, options?: {
305
305
  verified?: boolean | undefined;
306
306
  }): Promise<void>;
307
307
  readonly lastActiveAt: Date;
308
308
  readonly serverMetadata: any;
309
309
  setServerMetadata(metadata: any): Promise<void>;
310
310
  setClientReadOnlyMetadata(metadata: any): Promise<void>;
311
+ createTeam(data: Omit<ServerTeamCreateOptions, "creatorUserId">): Promise<ServerTeam>;
311
312
  listContactChannels(): Promise<ServerContactChannel[]>;
312
313
  createContactChannel(data: ServerContactChannelCreateOptions): Promise<ServerContactChannel>;
313
314
  update(user: ServerUserUpdateOptions): Promise<void>;
@@ -332,7 +333,7 @@ type ServerUser = ServerBaseUser & BaseUser & UserExtra;
332
333
  type CurrentServerUser = Auth & ServerUser;
333
334
  type CurrentInternalServerUser = CurrentServerUser & InternalUserExtra;
334
335
  type ServerUserUpdateOptions = {
335
- primaryEmail?: string;
336
+ primaryEmail?: string | null;
336
337
  primaryEmailVerified?: boolean;
337
338
  primaryEmailAuthEnabled?: boolean;
338
339
  clientReadOnlyMetadata?: ReadonlyJson;
@@ -340,12 +341,15 @@ type ServerUserUpdateOptions = {
340
341
  password?: string;
341
342
  } & UserUpdateOptions;
342
343
  type ServerUserCreateOptions = {
343
- primaryEmail?: string;
344
+ primaryEmail?: string | null;
344
345
  primaryEmailAuthEnabled?: boolean;
345
346
  password?: string;
346
347
  otpAuthEnabled?: boolean;
347
348
  displayName?: string;
348
349
  primaryEmailVerified?: boolean;
350
+ clientMetadata?: any;
351
+ clientReadOnlyMetadata?: any;
352
+ serverMetadata?: any;
349
353
  };
350
354
  type Project = {
351
355
  readonly id: string;
@@ -559,7 +563,9 @@ type ServerListUsersOptions = {
559
563
  desc?: boolean;
560
564
  query?: string;
561
565
  };
562
- type ServerTeamCreateOptions = TeamCreateOptions;
566
+ type ServerTeamCreateOptions = TeamCreateOptions & {
567
+ creatorUserId?: string;
568
+ };
563
569
  type ServerTeamUpdateOptions = TeamUpdateOptions & {
564
570
  clientReadOnlyMetadata?: ReadonlyJson;
565
571
  serverMetadata?: ReadonlyJson;
@@ -301,13 +301,14 @@ type UserUpdateOptions = {
301
301
  passkeyAuthEnabled?: boolean;
302
302
  };
303
303
  type ServerBaseUser = {
304
- setPrimaryEmail(email: string, options?: {
304
+ setPrimaryEmail(email: string | null, options?: {
305
305
  verified?: boolean | undefined;
306
306
  }): Promise<void>;
307
307
  readonly lastActiveAt: Date;
308
308
  readonly serverMetadata: any;
309
309
  setServerMetadata(metadata: any): Promise<void>;
310
310
  setClientReadOnlyMetadata(metadata: any): Promise<void>;
311
+ createTeam(data: Omit<ServerTeamCreateOptions, "creatorUserId">): Promise<ServerTeam>;
311
312
  listContactChannels(): Promise<ServerContactChannel[]>;
312
313
  createContactChannel(data: ServerContactChannelCreateOptions): Promise<ServerContactChannel>;
313
314
  update(user: ServerUserUpdateOptions): Promise<void>;
@@ -332,7 +333,7 @@ type ServerUser = ServerBaseUser & BaseUser & UserExtra;
332
333
  type CurrentServerUser = Auth & ServerUser;
333
334
  type CurrentInternalServerUser = CurrentServerUser & InternalUserExtra;
334
335
  type ServerUserUpdateOptions = {
335
- primaryEmail?: string;
336
+ primaryEmail?: string | null;
336
337
  primaryEmailVerified?: boolean;
337
338
  primaryEmailAuthEnabled?: boolean;
338
339
  clientReadOnlyMetadata?: ReadonlyJson;
@@ -340,12 +341,15 @@ type ServerUserUpdateOptions = {
340
341
  password?: string;
341
342
  } & UserUpdateOptions;
342
343
  type ServerUserCreateOptions = {
343
- primaryEmail?: string;
344
+ primaryEmail?: string | null;
344
345
  primaryEmailAuthEnabled?: boolean;
345
346
  password?: string;
346
347
  otpAuthEnabled?: boolean;
347
348
  displayName?: string;
348
349
  primaryEmailVerified?: boolean;
350
+ clientMetadata?: any;
351
+ clientReadOnlyMetadata?: any;
352
+ serverMetadata?: any;
349
353
  };
350
354
  type Project = {
351
355
  readonly id: string;
@@ -559,7 +563,9 @@ type ServerListUsersOptions = {
559
563
  desc?: boolean;
560
564
  query?: string;
561
565
  };
562
- type ServerTeamCreateOptions = TeamCreateOptions;
566
+ type ServerTeamCreateOptions = TeamCreateOptions & {
567
+ creatorUserId?: string;
568
+ };
563
569
  type ServerTeamUpdateOptions = TeamUpdateOptions & {
564
570
  clientReadOnlyMetadata?: ReadonlyJson;
565
571
  serverMetadata?: ReadonlyJson;
@@ -62,7 +62,7 @@ var import_url = require("../utils/url");
62
62
  var import_auth = require("./auth");
63
63
  var import_cookie = require("./cookie");
64
64
  var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
65
- var clientVersion = "js @stackframe/js@2.7.8";
65
+ var clientVersion = "js @stackframe/js@2.7.16";
66
66
  function getUrls(partial) {
67
67
  const handler = partial.handler ?? "/handler";
68
68
  const home = partial.home ?? "/";
@@ -88,10 +88,10 @@ function getUrls(partial) {
88
88
  };
89
89
  }
90
90
  function getDefaultProjectId() {
91
- return process.env.NEXT_PUBLIC_STACK_PROJECT_ID || (0, import_errors.throwErr)(new Error("Welcome to Stack Auth! It seems that you haven't provided a project ID. Please create a project on the Stack dashboard at https://app.stack-auth.com and put it in the NEXT_PUBLIC_STACK_PROJECT_ID environment variable."));
91
+ return (0, import_env.getPublicEnvVar)("NEXT_PUBLIC_STACK_PROJECT_ID") || (0, import_errors.throwErr)(new Error("Welcome to Stack Auth! It seems that you haven't provided a project ID. Please create a project on the Stack dashboard at https://app.stack-auth.com and put it in the NEXT_PUBLIC_STACK_PROJECT_ID environment variable."));
92
92
  }
93
93
  function getDefaultPublishableClientKey() {
94
- return process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY || (0, import_errors.throwErr)(new Error("Welcome to Stack Auth! It seems that you haven't provided a publishable client key. Please create an API key for your project on the Stack dashboard at https://app.stack-auth.com and copy your publishable client key into the NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY environment variable."));
94
+ return (0, import_env.getPublicEnvVar)("NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY") || (0, import_errors.throwErr)(new Error("Welcome to Stack Auth! It seems that you haven't provided a publishable client key. Please create an API key for your project on the Stack dashboard at https://app.stack-auth.com and copy your publishable client key into the NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY environment variable."));
95
95
  }
96
96
  function getDefaultSecretServerKey() {
97
97
  return process.env.STACK_SECRET_SERVER_KEY || (0, import_errors.throwErr)(new Error("No secret server key provided. Please copy your key from the Stack dashboard and put your it in the STACK_SECRET_SERVER_KEY environment variable."));
@@ -100,7 +100,8 @@ function getDefaultSuperSecretAdminKey() {
100
100
  return process.env.STACK_SUPER_SECRET_ADMIN_KEY || (0, import_errors.throwErr)(new Error("No super secret admin key provided. Please copy your key from the Stack dashboard and put it in the STACK_SUPER_SECRET_ADMIN_KEY environment variable."));
101
101
  }
102
102
  function getDefaultBaseUrl() {
103
- return process.env.NEXT_PUBLIC_STACK_API_URL || process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
103
+ const url = (0, import_env.getPublicEnvVar)("NEXT_PUBLIC_STACK_API_URL") || (0, import_env.getPublicEnvVar)("NEXT_PUBLIC_STACK_URL") || defaultBaseUrl;
104
+ return url.endsWith("/") ? url.slice(0, -1) : url;
104
105
  }
105
106
  var defaultBaseUrl = "https://api.stack-auth.com";
106
107
  function createEmptyTokenStore() {
@@ -217,7 +218,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
217
218
  this._interface = _options.interface;
218
219
  } else {
219
220
  this._interface = new import_stack_shared.StackClientInterface({
220
- baseUrl: _options.baseUrl ?? getDefaultBaseUrl(),
221
+ getBaseUrl: () => _options.baseUrl ?? getDefaultBaseUrl(),
221
222
  projectId: _options.projectId ?? getDefaultProjectId(),
222
223
  clientVersion,
223
224
  publishableClientKey: _options.publishableClientKey ?? getDefaultPublishableClientKey()
@@ -718,10 +719,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
718
719
  return teams.map((crud2) => app._clientTeamFromCrud(crud2, session));
719
720
  },
720
721
  async createTeam(data) {
721
- const crud2 = await app._interface.createClientTeam({
722
- ...teamCreateOptionsToCrud(data),
723
- creator_user_id: "me"
724
- }, session);
722
+ const crud2 = await app._interface.createClientTeam(teamCreateOptionsToCrud(data, "me"), session);
725
723
  await app._currentUserTeamsCache.refresh([session]);
726
724
  return app._clientTeamFromCrud(crud2, session);
727
725
  },
@@ -807,7 +805,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
807
805
  _getOwnedAdminApp(forProjectId, session) {
808
806
  if (!this._ownedAdminApps.has([session, forProjectId])) {
809
807
  this._ownedAdminApps.set([session, forProjectId], new _StackAdminAppImpl({
810
- baseUrl: this._interface.options.baseUrl,
808
+ baseUrl: this._interface.options.getBaseUrl(),
811
809
  projectId: forProjectId,
812
810
  tokenStore: null,
813
811
  projectOwnerSession: session,
@@ -1172,8 +1170,10 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1172
1170
  } catch (e) {
1173
1171
  if (e instanceof import_stack_shared.KnownErrors.InvalidTotpCode) {
1174
1172
  alert("Invalid TOTP code. Please try signing in again.");
1173
+ return false;
1174
+ } else {
1175
+ throw e;
1175
1176
  }
1176
- throw e;
1177
1177
  }
1178
1178
  if (result.status === "ok" && result.data) {
1179
1179
  await this._signInToAccountWithTokens(result.data);
@@ -1270,7 +1270,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
1270
1270
  throw new import_errors.StackAssertionError("Cannot serialize to JSON from an application without a publishable client key");
1271
1271
  }
1272
1272
  return {
1273
- baseUrl: this._interface.options.baseUrl,
1273
+ baseUrl: this._options.baseUrl,
1274
1274
  projectId: this.projectId,
1275
1275
  publishableClientKey: this._interface.options.publishableClientKey,
1276
1276
  tokenStore: this._tokenStoreInit,
@@ -1299,7 +1299,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1299
1299
  oauthScopesOnSignIn: options.oauthScopesOnSignIn
1300
1300
  } : {
1301
1301
  interface: new import_stack_shared.StackServerInterface({
1302
- baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
1302
+ getBaseUrl: () => options.baseUrl ?? getDefaultBaseUrl(),
1303
1303
  projectId: options.projectId ?? getDefaultProjectId(),
1304
1304
  clientVersion,
1305
1305
  publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
@@ -1485,10 +1485,10 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1485
1485
  return teams.map((t) => app._serverTeamFromCrud(t));
1486
1486
  },
1487
1487
  createTeam: async (data) => {
1488
- const team = await app._interface.createServerTeam({
1489
- ...serverTeamCreateOptionsToCrud(data),
1490
- creator_user_id: crud.id
1491
- });
1488
+ const team = await app._interface.createServerTeam(serverTeamCreateOptionsToCrud({
1489
+ creatorUserId: crud.id,
1490
+ ...data
1491
+ }));
1492
1492
  await app._serverTeamsCache.refresh([void 0]);
1493
1493
  return app._serverTeamFromCrud(team);
1494
1494
  },
@@ -1697,7 +1697,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1697
1697
  async _refreshUsers() {
1698
1698
  await Promise.all([
1699
1699
  super._refreshUsers(),
1700
- this._serverUsersCache.refreshWhere(() => true)
1700
+ this._serverUserCache.refreshWhere(() => true),
1701
+ this._serverUsersCache.refreshWhere(() => true),
1702
+ this._serverContactChannelsCache.refreshWhere(() => true)
1701
1703
  ]);
1702
1704
  }
1703
1705
  };
@@ -1705,7 +1707,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1705
1707
  constructor(options) {
1706
1708
  super({
1707
1709
  interface: new import_stack_shared.StackAdminInterface({
1708
- baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
1710
+ getBaseUrl: () => options.baseUrl ?? getDefaultBaseUrl(),
1709
1711
  projectId: options.projectId ?? getDefaultProjectId(),
1710
1712
  clientVersion,
1711
1713
  ..."projectOwnerSession" in options ? {
@@ -2003,7 +2005,10 @@ function serverUserCreateOptionsToCrud(options) {
2003
2005
  otp_auth_enabled: options.otpAuthEnabled,
2004
2006
  primary_email_auth_enabled: options.primaryEmailAuthEnabled,
2005
2007
  display_name: options.displayName,
2006
- primary_email_verified: options.primaryEmailVerified
2008
+ primary_email_verified: options.primaryEmailVerified,
2009
+ client_metadata: options.clientMetadata,
2010
+ client_read_only_metadata: options.clientReadOnlyMetadata,
2011
+ server_metadata: options.serverMetadata
2007
2012
  };
2008
2013
  }
2009
2014
  function adminProjectUpdateOptionsToCrud(options) {
@@ -2074,14 +2079,19 @@ function teamUpdateOptionsToCrud(options) {
2074
2079
  client_metadata: options.clientMetadata
2075
2080
  };
2076
2081
  }
2077
- function teamCreateOptionsToCrud(options) {
2082
+ function teamCreateOptionsToCrud(options, creatorUserId) {
2078
2083
  return {
2079
2084
  display_name: options.displayName,
2080
- profile_image_url: options.profileImageUrl
2085
+ profile_image_url: options.profileImageUrl,
2086
+ creator_user_id: creatorUserId
2081
2087
  };
2082
2088
  }
2083
2089
  function serverTeamCreateOptionsToCrud(options) {
2084
- return teamCreateOptionsToCrud(options);
2090
+ return {
2091
+ display_name: options.displayName,
2092
+ profile_image_url: options.profileImageUrl,
2093
+ creator_user_id: options.creatorUserId
2094
+ };
2085
2095
  }
2086
2096
  function serverTeamUpdateOptionsToCrud(options) {
2087
2097
  return {