@stackframe/stack 2.5.16 → 2.5.18

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 (86) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/components/credential-sign-in.js +6 -1
  3. package/dist/components/credential-sign-in.js.map +1 -1
  4. package/dist/components/elements/user-avatar.d.mts +1 -0
  5. package/dist/components/elements/user-avatar.d.ts +1 -0
  6. package/dist/components/message-cards/predefined-message-card.d.mts +1 -1
  7. package/dist/components/message-cards/predefined-message-card.d.ts +1 -1
  8. package/dist/components/message-cards/predefined-message-card.js +8 -0
  9. package/dist/components/message-cards/predefined-message-card.js.map +1 -1
  10. package/dist/components/selected-team-switcher.d.mts +1 -0
  11. package/dist/components/selected-team-switcher.d.ts +1 -0
  12. package/dist/components-page/account-settings.js +110 -16
  13. package/dist/components-page/account-settings.js.map +1 -1
  14. package/dist/components-page/auth-page.d.mts +1 -0
  15. package/dist/components-page/auth-page.d.ts +1 -0
  16. package/dist/components-page/auth-page.js +4 -1
  17. package/dist/components-page/auth-page.js.map +1 -1
  18. package/dist/components-page/forgot-password.d.mts +4 -1
  19. package/dist/components-page/forgot-password.d.ts +4 -1
  20. package/dist/components-page/forgot-password.js +55 -7
  21. package/dist/components-page/forgot-password.js.map +1 -1
  22. package/dist/components-page/password-reset.d.mts +6 -2
  23. package/dist/components-page/password-reset.d.ts +6 -2
  24. package/dist/components-page/password-reset.js +100 -8
  25. package/dist/components-page/password-reset.js.map +1 -1
  26. package/dist/components-page/stack-handler.d.mts +1 -0
  27. package/dist/components-page/stack-handler.d.ts +1 -0
  28. package/dist/components-page/stack-handler.js +12 -6
  29. package/dist/components-page/stack-handler.js.map +1 -1
  30. package/dist/components-page/team-invitation.d.mts +8 -0
  31. package/dist/components-page/team-invitation.d.ts +8 -0
  32. package/dist/components-page/team-invitation.js +141 -0
  33. package/dist/components-page/team-invitation.js.map +1 -0
  34. package/dist/esm/components/credential-sign-in.js +6 -1
  35. package/dist/esm/components/credential-sign-in.js.map +1 -1
  36. package/dist/esm/components/message-cards/predefined-message-card.js +8 -0
  37. package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -1
  38. package/dist/esm/components-page/account-settings.js +90 -6
  39. package/dist/esm/components-page/account-settings.js.map +1 -1
  40. package/dist/esm/components-page/auth-page.js +4 -1
  41. package/dist/esm/components-page/auth-page.js.map +1 -1
  42. package/dist/esm/components-page/forgot-password.js +52 -5
  43. package/dist/esm/components-page/forgot-password.js.map +1 -1
  44. package/dist/esm/components-page/password-reset.js +101 -9
  45. package/dist/esm/components-page/password-reset.js.map +1 -1
  46. package/dist/esm/components-page/stack-handler.js +12 -6
  47. package/dist/esm/components-page/stack-handler.js.map +1 -1
  48. package/dist/esm/components-page/team-invitation.js +107 -0
  49. package/dist/esm/components-page/team-invitation.js.map +1 -0
  50. package/dist/esm/generated/global-css.js +1 -1
  51. package/dist/esm/generated/global-css.js.map +1 -1
  52. package/dist/esm/lib/auth.js +1 -1
  53. package/dist/esm/lib/auth.js.map +1 -1
  54. package/dist/esm/lib/stack-app.js +115 -12
  55. package/dist/esm/lib/stack-app.js.map +1 -1
  56. package/dist/generated/global-css.d.mts +1 -1
  57. package/dist/generated/global-css.d.ts +1 -1
  58. package/dist/generated/global-css.js +1 -1
  59. package/dist/generated/global-css.js.map +1 -1
  60. package/dist/index.d.mts +1 -0
  61. package/dist/index.d.ts +1 -0
  62. package/dist/lib/auth.js +1 -1
  63. package/dist/lib/auth.js.map +1 -1
  64. package/dist/lib/hooks.d.mts +1 -0
  65. package/dist/lib/hooks.d.ts +1 -0
  66. package/dist/lib/stack-app.d.mts +29 -0
  67. package/dist/lib/stack-app.d.ts +29 -0
  68. package/dist/lib/stack-app.js +115 -12
  69. package/dist/lib/stack-app.js.map +1 -1
  70. package/dist/providers/stack-provider-client.d.mts +1 -0
  71. package/dist/providers/stack-provider-client.d.ts +1 -0
  72. package/dist/providers/stack-provider.d.mts +1 -0
  73. package/dist/providers/stack-provider.d.ts +1 -0
  74. package/package.json +7 -4
  75. package/dist/components/forgot-password-form.d.mts +0 -7
  76. package/dist/components/forgot-password-form.d.ts +0 -7
  77. package/dist/components/forgot-password-form.js +0 -83
  78. package/dist/components/forgot-password-form.js.map +0 -1
  79. package/dist/components/password-reset-form.d.mts +0 -8
  80. package/dist/components/password-reset-form.d.ts +0 -8
  81. package/dist/components/password-reset-form.js +0 -135
  82. package/dist/components/password-reset-form.js.map +0 -1
  83. package/dist/esm/components/forgot-password-form.js +0 -59
  84. package/dist/esm/components/forgot-password-form.js.map +0 -1
  85. package/dist/esm/components/password-reset-form.js +0 -105
  86. package/dist/esm/components/password-reset-form.js.map +0 -1
@@ -3,6 +3,7 @@ import { isReactServer } from "@stackframe/stack-sc";
3
3
  import { KnownError, KnownErrors, StackAdminInterface, StackClientInterface, StackServerInterface } from "@stackframe/stack-shared";
4
4
  import { getProductionModeErrors } from "@stackframe/stack-shared/dist/helpers/production-mode";
5
5
  import { InternalSession } from "@stackframe/stack-shared/dist/sessions";
6
+ import { encodeBase64 } from "@stackframe/stack-shared/dist/utils/bytes";
6
7
  import { AsyncCache } from "@stackframe/stack-shared/dist/utils/caches";
7
8
  import { scrambleDuringCompileTime } from "@stackframe/stack-shared/dist/utils/compile-time";
8
9
  import { isBrowserLike } from "@stackframe/stack-shared/dist/utils/env";
@@ -23,7 +24,7 @@ import { constructRedirectUrl } from "../utils/url";
23
24
  import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "./auth";
24
25
  import { deleteCookie, getCookie, setOrDeleteCookie } from "./cookie";
25
26
  var NextNavigation = scrambleDuringCompileTime(NextNavigationUnscrambled);
26
- var clientVersion = "js @stackframe/stack@2.5.16";
27
+ var clientVersion = "js @stackframe/stack@2.5.18";
27
28
  function getUrls(partial) {
28
29
  const handler = partial.handler ?? "/handler";
29
30
  const home = partial.home ?? "/";
@@ -44,6 +45,7 @@ function getUrls(partial) {
44
45
  home,
45
46
  accountSettings: `${handler}/account-settings`,
46
47
  error: `${handler}/error`,
48
+ teamInvitation: `${handler}/team-invitation`,
47
49
  ...filterUndefined(partial)
48
50
  };
49
51
  }
@@ -478,7 +480,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
478
480
  _clientProjectFromCrud(crud) {
479
481
  return {
480
482
  id: crud.id,
483
+ displayName: crud.display_name,
481
484
  config: {
485
+ signUpEnabled: crud.config.sign_up_enabled,
482
486
  credentialEnabled: crud.config.credential_enabled,
483
487
  magicLinkEnabled: crud.config.magic_link_enabled,
484
488
  oauthProviders: crud.config.enabled_oauth_providers.map((p) => ({
@@ -493,10 +497,19 @@ var _StackClientAppImpl = class __StackClientAppImpl {
493
497
  };
494
498
  }
495
499
  _clientTeamFromCrud(crud) {
500
+ const app = this;
496
501
  return {
497
502
  id: crud.id,
498
503
  displayName: crud.display_name,
499
- profileImageUrl: crud.profile_image_url
504
+ profileImageUrl: crud.profile_image_url,
505
+ async inviteUser(options) {
506
+ return await app._interface.sendTeamInvitation({
507
+ teamId: crud.id,
508
+ email: options.email,
509
+ session: app._getSession(),
510
+ callbackUrl: constructRedirectUrl(app.urls.teamInvitation)
511
+ });
512
+ }
500
513
  };
501
514
  }
502
515
  _createAuth(session) {
@@ -542,6 +555,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
542
555
  emailAuthEnabled: crud.auth_with_email,
543
556
  oauthProviders: crud.oauth_providers,
544
557
  selectedTeam: crud.selected_team && this._clientTeamFromCrud(crud.selected_team),
558
+ isMultiFactorRequired: crud.requires_totp_mfa,
545
559
  toClientJson() {
546
560
  return crud;
547
561
  }
@@ -613,17 +627,17 @@ var _StackClientAppImpl = class __StackClientAppImpl {
613
627
  async hasPermission(scope, permissionId) {
614
628
  return await this.getPermission(scope, permissionId) !== null;
615
629
  },
616
- update(update) {
617
- return app._updateClientUser(update, session);
630
+ async update(update) {
631
+ return await app._updateClientUser(update, session);
618
632
  },
619
- sendVerificationEmail() {
633
+ async sendVerificationEmail() {
620
634
  if (!crud?.primary_email) {
621
635
  throw new StackAssertionError("User does not have a primary email");
622
636
  }
623
- return app._sendVerificationEmail(crud.primary_email, session);
637
+ return await app._sendVerificationEmail(crud.primary_email, session);
624
638
  },
625
- updatePassword(options) {
626
- return app._updatePassword(options, session);
639
+ async updatePassword(options) {
640
+ return await app._updatePassword(options, session);
627
641
  }
628
642
  };
629
643
  }
@@ -757,6 +771,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
757
771
  async redirectToError(options) {
758
772
  return await this._redirectToHandler("error", options);
759
773
  }
774
+ async redirectToTeamInvitation(options) {
775
+ return await this._redirectToHandler("teamInvitation", options);
776
+ }
760
777
  async sendForgotPasswordEmail(email) {
761
778
  const redirectUrl = constructRedirectUrl(this.urls.passwordReset);
762
779
  const error = await this._interface.sendForgotPasswordEmail(email, redirectUrl);
@@ -774,6 +791,42 @@ var _StackClientAppImpl = class __StackClientAppImpl {
774
791
  async verifyPasswordResetCode(code) {
775
792
  return await this._interface.verifyPasswordResetCode(code);
776
793
  }
794
+ async verifyTeamInvitationCode(code) {
795
+ const result = await this._interface.acceptTeamInvitation({
796
+ type: "check",
797
+ code,
798
+ session: this._getSession()
799
+ });
800
+ if (result.status === "ok") {
801
+ return Result.ok(void 0);
802
+ } else {
803
+ return Result.error(result.error);
804
+ }
805
+ }
806
+ async acceptTeamInvitation(code) {
807
+ const result = await this._interface.acceptTeamInvitation({
808
+ type: "use",
809
+ code,
810
+ session: this._getSession()
811
+ });
812
+ if (result.status === "ok") {
813
+ return Result.ok(void 0);
814
+ } else {
815
+ return Result.error(result.error);
816
+ }
817
+ }
818
+ async getTeamInvitationDetails(code) {
819
+ const result = await this._interface.acceptTeamInvitation({
820
+ type: "details",
821
+ code,
822
+ session: this._getSession()
823
+ });
824
+ if (result.status === "ok") {
825
+ return Result.ok({ teamDisplayName: result.data.team_display_name });
826
+ } else {
827
+ return Result.error(result.error);
828
+ }
829
+ }
777
830
  async verifyEmail(code) {
778
831
  return await this._interface.verifyEmail(code);
779
832
  }
@@ -841,7 +894,31 @@ var _StackClientAppImpl = class __StackClientAppImpl {
841
894
  async signInWithCredential(options) {
842
895
  this._ensurePersistentTokenStore();
843
896
  const session = this._getSession();
844
- const result = await this._interface.signInWithCredential(options.email, options.password, session);
897
+ let result;
898
+ try {
899
+ result = await this._interface.signInWithCredential(options.email, options.password, session);
900
+ } catch (e) {
901
+ if (options.__experimental_mfa && e instanceof KnownErrors.MultiFactorAuthenticationRequired) {
902
+ const otp = prompt("Please enter the six-digit TOTP code from your authenticator app.");
903
+ try {
904
+ if (!otp) {
905
+ throw new KnownErrors.InvalidTotpCode();
906
+ }
907
+ result = await this._interface.totpMfa(
908
+ e.details?.attempt_code ?? throwErr("attempt code missing"),
909
+ otp,
910
+ session
911
+ );
912
+ } catch (e2) {
913
+ if (e2 instanceof KnownErrors.InvalidTotpCode) {
914
+ return e2;
915
+ }
916
+ throw e2;
917
+ }
918
+ } else {
919
+ throw e;
920
+ }
921
+ }
845
922
  if (!(result instanceof KnownError)) {
846
923
  await this._signInToAccountWithTokens(result);
847
924
  return await this.redirectToAfterSignIn({ replace: true });
@@ -1040,7 +1117,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1040
1117
  return await this._interface.listServerTeamUsers(teamId);
1041
1118
  });
1042
1119
  this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId, recursive]) => {
1043
- return await this._interface.listServerTeamMemberPermissions({ teamId, userId, recursive });
1120
+ return await this._interface.listServerTeamPermissions({ teamId, userId, recursive }, null);
1044
1121
  });
1045
1122
  this._serverUserOAuthConnectionAccessTokensCache = createCache(
1046
1123
  async ([userId, providerId, scope]) => {
@@ -1229,9 +1306,22 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
1229
1306
  userId
1230
1307
  });
1231
1308
  await app._serverTeamUsersCache.refresh([crud.id]);
1309
+ },
1310
+ async inviteUser(options) {
1311
+ return await app._interface.sendTeamInvitation({
1312
+ teamId: crud.id,
1313
+ email: options.email,
1314
+ session: null,
1315
+ callbackUrl: constructRedirectUrl(app.urls.teamInvitation)
1316
+ });
1232
1317
  }
1233
1318
  };
1234
1319
  }
1320
+ async createUser(options) {
1321
+ const crud = await this._interface.createServerUser(serverUserCreateOptionsToCrud(options));
1322
+ await this._refreshUsers();
1323
+ return this._serverUserFromCrud(crud);
1324
+ }
1235
1325
  async getUser(options) {
1236
1326
  this._ensurePersistentTokenStore(options?.tokenStore);
1237
1327
  const session = this._getSession(options?.tokenStore);
@@ -1409,6 +1499,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
1409
1499
  isProductionMode: data.is_production_mode,
1410
1500
  config: {
1411
1501
  id: data.config.id,
1502
+ signUpEnabled: data.config.sign_up_enabled,
1412
1503
  credentialEnabled: data.config.credential_enabled,
1413
1504
  magicLinkEnabled: data.config.magic_link_enabled,
1414
1505
  allowLocalhost: data.config.allow_localhost,
@@ -1589,7 +1680,8 @@ function userUpdateOptionsToCrud(options) {
1589
1680
  return {
1590
1681
  display_name: options.displayName,
1591
1682
  client_metadata: options.clientMetadata,
1592
- selected_team_id: options.selectedTeamId
1683
+ selected_team_id: options.selectedTeamId,
1684
+ totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
1593
1685
  };
1594
1686
  }
1595
1687
  function serverUserUpdateOptionsToCrud(options) {
@@ -1601,7 +1693,17 @@ function serverUserUpdateOptionsToCrud(options) {
1601
1693
  selected_team_id: options.selectedTeamId,
1602
1694
  primary_email_auth_enabled: options.primaryEmailAuthEnabled,
1603
1695
  primary_email_verified: options.primaryEmailVerified,
1604
- password: options.password
1696
+ password: options.password,
1697
+ totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
1698
+ };
1699
+ }
1700
+ function serverUserCreateOptionsToCrud(options) {
1701
+ return {
1702
+ primary_email: options.primaryEmail,
1703
+ password: options.password,
1704
+ primary_email_auth_enabled: true,
1705
+ display_name: options.displayName,
1706
+ primary_email_verified: options.primaryEmailVerified
1605
1707
  };
1606
1708
  }
1607
1709
  function adminProjectUpdateOptionsToCrud(options) {
@@ -1635,6 +1737,7 @@ function adminProjectUpdateOptionsToCrud(options) {
1635
1737
  sender_name: options.config.emailConfig.senderName,
1636
1738
  sender_email: options.config.emailConfig.senderEmail
1637
1739
  }),
1740
+ sign_up_enabled: options.config?.signUpEnabled,
1638
1741
  credential_enabled: options.config?.credentialEnabled,
1639
1742
  magic_link_enabled: options.config?.magicLinkEnabled,
1640
1743
  allow_localhost: options.config?.allowLocalhost,