@stackframe/stack 2.4.4 → 2.4.7

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 (39) hide show
  1. package/dist/components/card-frame.d.mts +1 -1
  2. package/dist/components/card-frame.d.ts +1 -1
  3. package/dist/components/user-avatar.js +19 -1
  4. package/dist/components/user-avatar.js.map +1 -1
  5. package/dist/components-core/button.js +1 -1
  6. package/dist/components-core/button.js.map +1 -1
  7. package/dist/components-core/index.d.mts +4 -4
  8. package/dist/components-core/index.d.ts +4 -4
  9. package/dist/components-core/loading-indicator.d.mts +4 -6
  10. package/dist/components-core/loading-indicator.d.ts +4 -6
  11. package/dist/components-core/loading-indicator.js +9 -6
  12. package/dist/components-core/loading-indicator.js.map +1 -1
  13. package/dist/components-core-joy/text.d.mts +2 -2
  14. package/dist/components-core-joy/text.d.ts +2 -2
  15. package/dist/components-page/oauth-callback.js +21 -6
  16. package/dist/components-page/oauth-callback.js.map +1 -1
  17. package/dist/components-page/stack-handler.js +8 -0
  18. package/dist/components-page/stack-handler.js.map +1 -1
  19. package/dist/esm/components/user-avatar.js +9 -1
  20. package/dist/esm/components/user-avatar.js.map +1 -1
  21. package/dist/esm/components-core/button.js +1 -1
  22. package/dist/esm/components-core/button.js.map +1 -1
  23. package/dist/esm/components-core/loading-indicator.js +9 -6
  24. package/dist/esm/components-core/loading-indicator.js.map +1 -1
  25. package/dist/esm/components-page/oauth-callback.js +21 -6
  26. package/dist/esm/components-page/oauth-callback.js.map +1 -1
  27. package/dist/esm/components-page/stack-handler.js +10 -2
  28. package/dist/esm/components-page/stack-handler.js.map +1 -1
  29. package/dist/esm/lib/stack-app.js +56 -71
  30. package/dist/esm/lib/stack-app.js.map +1 -1
  31. package/dist/lib/stack-app.d.mts +9 -3
  32. package/dist/lib/stack-app.d.ts +9 -3
  33. package/dist/lib/stack-app.js +55 -70
  34. package/dist/lib/stack-app.js.map +1 -1
  35. package/dist/providers/component-provider.d.mts +6 -6
  36. package/dist/providers/component-provider.d.ts +6 -6
  37. package/dist/providers/joy-provider.d.mts +2 -2
  38. package/dist/providers/joy-provider.d.ts +2 -2
  39. package/package.json +3 -3
@@ -53,6 +53,7 @@ var import_objects = require("@stackframe/stack-shared/dist/utils/objects");
53
53
  var import_promises = require("@stackframe/stack-shared/dist/utils/promises");
54
54
  var import_caches = require("@stackframe/stack-shared/dist/utils/caches");
55
55
  var import_react3 = require("@stackframe/stack-shared/dist/utils/react");
56
+ var clientVersion = "js @stackframe/stack@2.4.7";
56
57
  function permissionDefinitionScopeToType(scope) {
57
58
  return { "any-team": "team", "specific-team": "team", "global": "global" }[scope.type];
58
59
  }
@@ -77,16 +78,16 @@ function getUrls(partial) {
77
78
  };
78
79
  }
79
80
  function getDefaultProjectId() {
80
- return process.env.NEXT_PUBLIC_STACK_PROJECT_ID || (0, import_errors.throwErr)("Welcome to Stack! 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.");
81
+ return process.env.NEXT_PUBLIC_STACK_PROJECT_ID || (0, import_errors.throwErr)(new Error("Welcome to Stack! 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."));
81
82
  }
82
83
  function getDefaultPublishableClientKey() {
83
- return process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY || (0, import_errors.throwErr)("Welcome to Stack! 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.");
84
+ return process.env.NEXT_PUBLIC_STACK_PUBLISHABLE_CLIENT_KEY || (0, import_errors.throwErr)(new Error("Welcome to Stack! 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."));
84
85
  }
85
86
  function getDefaultSecretServerKey() {
86
- return process.env.STACK_SECRET_SERVER_KEY || (0, import_errors.throwErr)("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.");
87
+ 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."));
87
88
  }
88
89
  function getDefaultSuperSecretAdminKey() {
89
- return process.env.STACK_SUPER_SECRET_ADMIN_KEY || (0, import_errors.throwErr)("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.");
90
+ 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."));
90
91
  }
91
92
  function getDefaultBaseUrl() {
92
93
  return process.env.NEXT_PUBLIC_STACK_URL || defaultBaseUrl;
@@ -232,6 +233,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
232
233
  this._interface = new import_stack_shared.StackClientInterface({
233
234
  baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
234
235
  projectId: options.projectId ?? getDefaultProjectId(),
236
+ clientVersion,
235
237
  publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey()
236
238
  });
237
239
  }
@@ -299,6 +301,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
299
301
  hasPassword: json.hasPassword,
300
302
  authWithEmail: json.authWithEmail,
301
303
  oauthProviders: json.oauthProviders,
304
+ async getSelectedTeam() {
305
+ return await this.getTeam(json.selectedTeamId || "");
306
+ },
307
+ useSelectedTeam() {
308
+ return this.useTeam(json.selectedTeamId || "");
309
+ },
302
310
  async getTeam(teamId) {
303
311
  const teams = await this.listTeams();
304
312
  return teams.find((t) => t.id === teamId) ?? null;
@@ -345,8 +353,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
345
353
  return permissions.find((p) => p.id === permissionId) ?? null;
346
354
  },
347
355
  async hasPermission(scope, permissionId) {
348
- const permissions = await this.listPermissions(scope);
349
- return permissions.some((p) => p.id === permissionId);
356
+ return await this.getPermission(scope, permissionId) !== null;
350
357
  },
351
358
  toJson() {
352
359
  return json;
@@ -369,6 +376,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
369
376
  const currentUser = {
370
377
  ...this._userFromJson(json),
371
378
  tokenStore,
379
+ async updateSelectedTeam(team) {
380
+ await app._updateUser({ selectedTeamId: team?.id ?? null }, tokenStore);
381
+ },
372
382
  update(update) {
373
383
  return app._updateUser(update, tokenStore);
374
384
  },
@@ -405,22 +415,6 @@ var _StackClientAppImpl = class __StackClientAppImpl {
405
415
  return currentUser;
406
416
  }
407
417
  }
408
- _userToJson(user) {
409
- return {
410
- projectId: user.projectId,
411
- id: user.id,
412
- displayName: user.displayName,
413
- primaryEmail: user.primaryEmail,
414
- primaryEmailVerified: user.primaryEmailVerified,
415
- profileImageUrl: user.profileImageUrl,
416
- signedUpAtMillis: user.signedUpAt.getTime(),
417
- clientMetadata: user.clientMetadata,
418
- authMethod: user.authMethod,
419
- hasPassword: user.hasPassword,
420
- authWithEmail: user.authWithEmail,
421
- oauthProviders: user.oauthProviders
422
- };
423
- }
424
418
  _projectAdminFromJson(data, adminInterface, onRefresh) {
425
419
  if (data.id !== adminInterface.projectId) {
426
420
  throw new Error(`The project ID of the provided project JSON (${data.id}) does not match the project ID of the app (${adminInterface.projectId})! This is a Stack bug.`);
@@ -458,6 +452,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
458
452
  return new import_stack_shared.StackAdminInterface({
459
453
  baseUrl: this._interface.options.baseUrl,
460
454
  projectId: forProjectId,
455
+ clientVersion,
461
456
  projectOwnerTokens: tokenStore
462
457
  });
463
458
  }
@@ -467,11 +462,16 @@ var _StackClientAppImpl = class __StackClientAppImpl {
467
462
  get urls() {
468
463
  return getUrls(this._urlOptions);
469
464
  }
470
- async _redirectTo(handlerName) {
471
- if (!this.urls[handlerName]) {
465
+ async _redirectTo(handlerName, options) {
466
+ const url = this.urls[handlerName];
467
+ if (!url) {
472
468
  throw new Error(`No URL for handler name ${handlerName}`);
473
469
  }
474
- window.location.href = this.urls[handlerName];
470
+ if (options?.replace) {
471
+ window.location.replace(url);
472
+ } else {
473
+ window.location.assign(url);
474
+ }
475
475
  return await (0, import_promises.wait)(2e3);
476
476
  }
477
477
  async redirectToSignIn() {
@@ -598,7 +598,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
598
598
  const tokenStore = getTokenStore(this._tokenStoreOptions);
599
599
  const errorCode = await this._interface.signInWithCredential(options.email, options.password, tokenStore);
600
600
  if (!errorCode) {
601
- window.location.assign(this.urls.afterSignIn);
601
+ await this.redirectToAfterSignIn({ replace: true });
602
602
  }
603
603
  return errorCode;
604
604
  }
@@ -613,7 +613,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
613
613
  tokenStore
614
614
  );
615
615
  if (!errorCode) {
616
- window.location.assign(this.urls.afterSignUp);
616
+ await this.redirectToAfterSignUp({ replace: true });
617
617
  }
618
618
  return errorCode;
619
619
  }
@@ -625,11 +625,10 @@ var _StackClientAppImpl = class __StackClientAppImpl {
625
625
  return result;
626
626
  }
627
627
  if (result.newUser) {
628
- window.location.replace(this.urls.afterSignUp);
628
+ await this.redirectToAfterSignUp({ replace: true });
629
629
  } else {
630
- window.location.replace(this.urls.afterSignIn);
630
+ await this.redirectToAfterSignIn({ replace: true });
631
631
  }
632
- await (0, import_promises.neverResolve)();
633
632
  }
634
633
  async callOAuthCallback() {
635
634
  this._ensurePersistentTokenStore();
@@ -637,16 +636,18 @@ var _StackClientAppImpl = class __StackClientAppImpl {
637
636
  const result = await (0, import_auth.callOAuthCallback)(this._interface, tokenStore, this.urls.oauthCallback);
638
637
  if (result) {
639
638
  if (result.newUser) {
640
- window.location.replace(this.urls.afterSignUp);
639
+ await this.redirectToAfterSignUp({ replace: true });
640
+ return true;
641
641
  } else {
642
- window.location.replace(this.urls.afterSignIn);
642
+ await this.redirectToAfterSignIn({ replace: true });
643
+ return true;
643
644
  }
644
645
  }
645
- await (0, import_promises.neverResolve)();
646
+ return false;
646
647
  }
647
648
  async _signOut(tokenStore) {
648
649
  await this._interface.signOut(tokenStore);
649
- window.location.assign(this.urls.afterSignOut);
650
+ await this.redirectToAfterSignOut();
650
651
  }
651
652
  async _sendVerificationEmail(tokenStore) {
652
653
  const emailVerificationRedirectUrl = (0, import_url.constructRedirectUrl)(this.urls.emailVerification);
@@ -792,24 +793,21 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
792
793
  return await this._interface.listTeamMemberPermissions({ teamId, userId, type, direct });
793
794
  });
794
795
  constructor(options) {
795
- if ("interface" in options) {
796
- super({
797
- interface: options.interface,
798
- tokenStore: options.tokenStore,
799
- urls: options.urls
800
- });
801
- } else {
802
- super({
803
- interface: new import_stack_shared.StackServerInterface({
804
- baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
805
- projectId: options.projectId ?? getDefaultProjectId(),
806
- publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
807
- secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
808
- }),
809
- tokenStore: options.tokenStore,
810
- urls: options.urls ?? {}
811
- });
812
- }
796
+ super("interface" in options ? {
797
+ interface: options.interface,
798
+ tokenStore: options.tokenStore,
799
+ urls: options.urls
800
+ } : {
801
+ interface: new import_stack_shared.StackServerInterface({
802
+ baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
803
+ projectId: options.projectId ?? getDefaultProjectId(),
804
+ clientVersion,
805
+ publishableClientKey: options.publishableClientKey ?? getDefaultPublishableClientKey(),
806
+ secretServerKey: options.secretServerKey ?? getDefaultSecretServerKey()
807
+ }),
808
+ tokenStore: options.tokenStore,
809
+ urls: options.urls ?? {}
810
+ });
813
811
  }
814
812
  _serverUserFromJson(json) {
815
813
  if (json === null)
@@ -893,7 +891,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
893
891
  return permissions.some((p) => p.id === permissionId);
894
892
  },
895
893
  toJson() {
896
- return app._serverUserToJson(this);
894
+ return json;
897
895
  }
898
896
  };
899
897
  }
@@ -910,6 +908,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
910
908
  await app._refreshUser(tokenStore);
911
909
  return res;
912
910
  },
911
+ async updateSelectedTeam(team) {
912
+ await this.update({ selectedTeamId: team?.id ?? null });
913
+ },
913
914
  async update(update) {
914
915
  const res = await nonCurrentServerUser.update(update);
915
916
  await app._refreshUser(tokenStore);
@@ -965,23 +966,6 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
965
966
  }
966
967
  };
967
968
  }
968
- _serverUserToJson(user) {
969
- return {
970
- projectId: user.projectId,
971
- id: user.id,
972
- displayName: user.displayName,
973
- primaryEmail: user.primaryEmail,
974
- primaryEmailVerified: user.primaryEmailVerified,
975
- profileImageUrl: user.profileImageUrl,
976
- signedUpAtMillis: user.signedUpAt.getTime(),
977
- clientMetadata: user.clientMetadata,
978
- serverMetadata: user.serverMetadata,
979
- authMethod: user.authMethod,
980
- hasPassword: user.hasPassword,
981
- authWithEmail: user.authWithEmail,
982
- oauthProviders: user.oauthProviders
983
- };
984
- }
985
969
  _serverTeamFromJson(json) {
986
970
  const app = this;
987
971
  return {
@@ -1142,6 +1126,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1142
1126
  interface: new import_stack_shared.StackAdminInterface({
1143
1127
  baseUrl: options.baseUrl ?? getDefaultBaseUrl(),
1144
1128
  projectId: options.projectId ?? getDefaultProjectId(),
1129
+ clientVersion,
1145
1130
  ..."projectOwnerTokens" in options ? {
1146
1131
  projectOwnerTokens: options.projectOwnerTokens
1147
1132
  } : {