@stackframe/stack 2.5.17 → 2.5.19
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.
- package/CHANGELOG.md +20 -0
- package/dist/components/credential-sign-in.js +4 -1
- package/dist/components/credential-sign-in.js.map +1 -1
- package/dist/components/elements/sidebar-layout.d.mts +21 -0
- package/dist/components/elements/sidebar-layout.d.ts +21 -0
- package/dist/components/elements/sidebar-layout.js +125 -0
- package/dist/components/elements/sidebar-layout.js.map +1 -0
- package/dist/components/elements/user-avatar.d.mts +5 -11
- package/dist/components/elements/user-avatar.d.ts +5 -11
- package/dist/components/elements/user-avatar.js.map +1 -1
- package/dist/components/message-cards/predefined-message-card.d.mts +1 -1
- package/dist/components/message-cards/predefined-message-card.d.ts +1 -1
- package/dist/components/message-cards/predefined-message-card.js +8 -0
- package/dist/components/message-cards/predefined-message-card.js.map +1 -1
- package/dist/components/selected-team-switcher.d.mts +1 -0
- package/dist/components/selected-team-switcher.d.ts +1 -0
- package/dist/components/selected-team-switcher.js +35 -5
- package/dist/components/selected-team-switcher.js.map +1 -1
- package/dist/components-page/account-settings.js +123 -31
- package/dist/components-page/account-settings.js.map +1 -1
- package/dist/components-page/auth-page.d.mts +1 -0
- package/dist/components-page/auth-page.d.ts +1 -0
- package/dist/components-page/auth-page.js +4 -1
- package/dist/components-page/auth-page.js.map +1 -1
- package/dist/components-page/forgot-password.d.mts +4 -1
- package/dist/components-page/forgot-password.d.ts +4 -1
- package/dist/components-page/forgot-password.js +55 -7
- package/dist/components-page/forgot-password.js.map +1 -1
- package/dist/components-page/password-reset.d.mts +6 -2
- package/dist/components-page/password-reset.d.ts +6 -2
- package/dist/components-page/password-reset.js +100 -8
- package/dist/components-page/password-reset.js.map +1 -1
- package/dist/components-page/stack-handler.d.mts +1 -0
- package/dist/components-page/stack-handler.d.ts +1 -0
- package/dist/components-page/stack-handler.js +32 -6
- package/dist/components-page/stack-handler.js.map +1 -1
- package/dist/{components/password-reset-form.d.mts → components-page/team-creation.d.mts} +2 -3
- package/dist/{components/password-reset-form.d.ts → components-page/team-creation.d.ts} +2 -3
- package/dist/components-page/team-creation.js +92 -0
- package/dist/components-page/team-creation.js.map +1 -0
- package/dist/components-page/team-invitation.d.mts +8 -0
- package/dist/components-page/team-invitation.d.ts +8 -0
- package/dist/components-page/team-invitation.js +141 -0
- package/dist/components-page/team-invitation.js.map +1 -0
- package/dist/components-page/team-settings.d.mts +8 -0
- package/dist/components-page/team-settings.d.ts +8 -0
- package/dist/components-page/team-settings.js +139 -0
- package/dist/components-page/team-settings.js.map +1 -0
- package/dist/esm/components/credential-sign-in.js +4 -1
- package/dist/esm/components/credential-sign-in.js.map +1 -1
- package/dist/esm/components/elements/sidebar-layout.js +90 -0
- package/dist/esm/components/elements/sidebar-layout.js.map +1 -0
- package/dist/esm/components/elements/user-avatar.js.map +1 -1
- package/dist/esm/components/message-cards/predefined-message-card.js +8 -0
- package/dist/esm/components/message-cards/predefined-message-card.js.map +1 -1
- package/dist/esm/components/selected-team-switcher.js +39 -7
- package/dist/esm/components/selected-team-switcher.js.map +1 -1
- package/dist/esm/components-page/account-settings.js +114 -32
- package/dist/esm/components-page/account-settings.js.map +1 -1
- package/dist/esm/components-page/auth-page.js +4 -1
- package/dist/esm/components-page/auth-page.js.map +1 -1
- package/dist/esm/components-page/forgot-password.js +52 -5
- package/dist/esm/components-page/forgot-password.js.map +1 -1
- package/dist/esm/components-page/password-reset.js +101 -9
- package/dist/esm/components-page/password-reset.js.map +1 -1
- package/dist/esm/components-page/stack-handler.js +32 -6
- package/dist/esm/components-page/stack-handler.js.map +1 -1
- package/dist/esm/components-page/team-creation.js +68 -0
- package/dist/esm/components-page/team-creation.js.map +1 -0
- package/dist/esm/components-page/team-invitation.js +107 -0
- package/dist/esm/components-page/team-invitation.js.map +1 -0
- package/dist/esm/components-page/team-settings.js +115 -0
- package/dist/esm/components-page/team-settings.js.map +1 -0
- package/dist/esm/generated/global-css.js +1 -1
- package/dist/esm/generated/global-css.js.map +1 -1
- package/dist/esm/lib/auth.js +5 -1
- package/dist/esm/lib/auth.js.map +1 -1
- package/dist/esm/lib/stack-app.js +272 -25
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/generated/global-css.d.mts +1 -1
- package/dist/generated/global-css.d.ts +1 -1
- package/dist/generated/global-css.js +1 -1
- package/dist/generated/global-css.js.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/lib/auth.js +5 -1
- package/dist/lib/auth.js.map +1 -1
- package/dist/lib/hooks.d.mts +1 -0
- package/dist/lib/hooks.d.ts +1 -0
- package/dist/lib/stack-app.d.mts +64 -5
- package/dist/lib/stack-app.d.ts +64 -5
- package/dist/lib/stack-app.js +272 -25
- package/dist/lib/stack-app.js.map +1 -1
- package/dist/providers/stack-provider-client.d.mts +1 -0
- package/dist/providers/stack-provider-client.d.ts +1 -0
- package/dist/providers/stack-provider.d.mts +1 -0
- package/dist/providers/stack-provider.d.ts +1 -0
- package/package.json +10 -6
- package/dist/components/forgot-password-form.d.mts +0 -7
- package/dist/components/forgot-password-form.d.ts +0 -7
- package/dist/components/forgot-password-form.js +0 -83
- package/dist/components/forgot-password-form.js.map +0 -1
- package/dist/components/password-reset-form.js +0 -135
- package/dist/components/password-reset-form.js.map +0 -1
- package/dist/esm/components/forgot-password-form.js +0 -59
- package/dist/esm/components/forgot-password-form.js.map +0 -1
- package/dist/esm/components/password-reset-form.js +0 -105
- package/dist/esm/components/password-reset-form.js.map +0 -1
package/dist/lib/stack-app.js
CHANGED
|
@@ -42,6 +42,7 @@ var import_stack_sc = require("@stackframe/stack-sc");
|
|
|
42
42
|
var import_stack_shared = require("@stackframe/stack-shared");
|
|
43
43
|
var import_production_mode = require("@stackframe/stack-shared/dist/helpers/production-mode");
|
|
44
44
|
var import_sessions = require("@stackframe/stack-shared/dist/sessions");
|
|
45
|
+
var import_bytes = require("@stackframe/stack-shared/dist/utils/bytes");
|
|
45
46
|
var import_caches = require("@stackframe/stack-shared/dist/utils/caches");
|
|
46
47
|
var import_compile_time = require("@stackframe/stack-shared/dist/utils/compile-time");
|
|
47
48
|
var import_env = require("@stackframe/stack-shared/dist/utils/env");
|
|
@@ -62,7 +63,7 @@ var import_url = require("../utils/url");
|
|
|
62
63
|
var import_auth = require("./auth");
|
|
63
64
|
var import_cookie = require("./cookie");
|
|
64
65
|
var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
|
|
65
|
-
var clientVersion = "js @stackframe/stack@2.5.
|
|
66
|
+
var clientVersion = "js @stackframe/stack@2.5.19";
|
|
66
67
|
function getUrls(partial) {
|
|
67
68
|
const handler = partial.handler ?? "/handler";
|
|
68
69
|
const home = partial.home ?? "/";
|
|
@@ -83,6 +84,8 @@ function getUrls(partial) {
|
|
|
83
84
|
home,
|
|
84
85
|
accountSettings: `${handler}/account-settings`,
|
|
85
86
|
error: `${handler}/error`,
|
|
87
|
+
teamInvitation: `${handler}/team-invitation`,
|
|
88
|
+
teamCreation: `${handler}/team-creation`,
|
|
86
89
|
...(0, import_objects.filterUndefined)(partial)
|
|
87
90
|
};
|
|
88
91
|
}
|
|
@@ -214,6 +217,16 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
214
217
|
});
|
|
215
218
|
}
|
|
216
219
|
);
|
|
220
|
+
this._teamMemberProfilesCache = createCacheBySession(
|
|
221
|
+
async (session, [teamId]) => {
|
|
222
|
+
return await this._interface.listTeamMemberProfiles({ teamId }, session);
|
|
223
|
+
}
|
|
224
|
+
);
|
|
225
|
+
this._currentUserTeamProfileCache = createCacheBySession(
|
|
226
|
+
async (session, [teamId]) => {
|
|
227
|
+
return await this._interface.getTeamMemberProfile({ teamId, userId: "me" }, session);
|
|
228
|
+
}
|
|
229
|
+
);
|
|
217
230
|
this._memoryTokenStore = createEmptyTokenStore();
|
|
218
231
|
this._requestTokenStores = /* @__PURE__ */ new WeakMap();
|
|
219
232
|
this._storedCookieTokenStore = null;
|
|
@@ -495,6 +508,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
495
508
|
return import_react2.default.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
496
509
|
}
|
|
497
510
|
async _signInToAccountWithTokens(tokens) {
|
|
511
|
+
if (!("accessToken" in tokens) || !("refreshToken" in tokens)) {
|
|
512
|
+
throw new import_errors.StackAssertionError("Invalid tokens object; can't sign in with this", { tokens });
|
|
513
|
+
}
|
|
498
514
|
const tokenStore = this._getOrCreateTokenStore();
|
|
499
515
|
tokenStore.set(tokens);
|
|
500
516
|
}
|
|
@@ -517,9 +533,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
517
533
|
_clientProjectFromCrud(crud) {
|
|
518
534
|
return {
|
|
519
535
|
id: crud.id,
|
|
536
|
+
displayName: crud.display_name,
|
|
520
537
|
config: {
|
|
538
|
+
signUpEnabled: crud.config.sign_up_enabled,
|
|
521
539
|
credentialEnabled: crud.config.credential_enabled,
|
|
522
540
|
magicLinkEnabled: crud.config.magic_link_enabled,
|
|
541
|
+
clientTeamCreationEnabled: crud.config.client_team_creation_enabled,
|
|
523
542
|
oauthProviders: crud.config.enabled_oauth_providers.map((p) => ({
|
|
524
543
|
id: p.id
|
|
525
544
|
}))
|
|
@@ -531,11 +550,37 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
531
550
|
id: crud.id
|
|
532
551
|
};
|
|
533
552
|
}
|
|
553
|
+
_clientTeamUserFromCrud(crud) {
|
|
554
|
+
return {
|
|
555
|
+
id: crud.user_id,
|
|
556
|
+
teamProfile: {
|
|
557
|
+
displayName: crud.display_name,
|
|
558
|
+
profileImageUrl: crud.profile_image_url
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
}
|
|
534
562
|
_clientTeamFromCrud(crud) {
|
|
563
|
+
const app = this;
|
|
535
564
|
return {
|
|
536
565
|
id: crud.id,
|
|
537
566
|
displayName: crud.display_name,
|
|
538
|
-
profileImageUrl: crud.profile_image_url
|
|
567
|
+
profileImageUrl: crud.profile_image_url,
|
|
568
|
+
async inviteUser(options) {
|
|
569
|
+
return await app._interface.sendTeamInvitation({
|
|
570
|
+
teamId: crud.id,
|
|
571
|
+
email: options.email,
|
|
572
|
+
session: app._getSession(),
|
|
573
|
+
callbackUrl: (0, import_url.constructRedirectUrl)(app.urls.teamInvitation)
|
|
574
|
+
});
|
|
575
|
+
},
|
|
576
|
+
async listUsers() {
|
|
577
|
+
const result = await app._teamMemberProfilesCache.getOrWait([app._getSession(), crud.id], "write-only");
|
|
578
|
+
return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
|
|
579
|
+
},
|
|
580
|
+
useUsers() {
|
|
581
|
+
const result = useAsyncCache(app._teamMemberProfilesCache, [app._getSession(), crud.id], "team.useUsers()");
|
|
582
|
+
return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
|
|
583
|
+
}
|
|
539
584
|
};
|
|
540
585
|
}
|
|
541
586
|
_createAuth(session) {
|
|
@@ -581,11 +626,30 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
581
626
|
emailAuthEnabled: crud.auth_with_email,
|
|
582
627
|
oauthProviders: crud.oauth_providers,
|
|
583
628
|
selectedTeam: crud.selected_team && this._clientTeamFromCrud(crud.selected_team),
|
|
629
|
+
isMultiFactorRequired: crud.requires_totp_mfa,
|
|
584
630
|
toClientJson() {
|
|
585
631
|
return crud;
|
|
586
632
|
}
|
|
587
633
|
};
|
|
588
634
|
}
|
|
635
|
+
_editableTeamProfileFromCrud(crud) {
|
|
636
|
+
const app = this;
|
|
637
|
+
return {
|
|
638
|
+
displayName: crud.display_name,
|
|
639
|
+
profileImageUrl: crud.profile_image_url,
|
|
640
|
+
async update(update) {
|
|
641
|
+
await app._interface.updateTeamMemberProfile({
|
|
642
|
+
teamId: crud.team_id,
|
|
643
|
+
userId: crud.user_id,
|
|
644
|
+
profile: {
|
|
645
|
+
display_name: update.displayName,
|
|
646
|
+
profile_image_url: update.profileImageUrl
|
|
647
|
+
}
|
|
648
|
+
}, app._getSession());
|
|
649
|
+
await app._currentUserTeamProfileCache.refresh([app._getSession(), crud.team_id]);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
}
|
|
589
653
|
_createUserExtra(crud, session) {
|
|
590
654
|
const app = this;
|
|
591
655
|
async function getConnectedAccount(id, options) {
|
|
@@ -631,6 +695,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
631
695
|
await app._currentUserTeamsCache.refresh([session]);
|
|
632
696
|
return app._clientTeamFromCrud(crud2);
|
|
633
697
|
},
|
|
698
|
+
async leaveTeam(team) {
|
|
699
|
+
await app._interface.leaveTeam(team.id, session);
|
|
700
|
+
},
|
|
634
701
|
async listPermissions(scope, options) {
|
|
635
702
|
const recursive = options?.recursive ?? true;
|
|
636
703
|
const permissions = await app._currentUserPermissionsCache.getOrWait([session, scope.id, recursive], "write-only");
|
|
@@ -652,17 +719,25 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
652
719
|
async hasPermission(scope, permissionId) {
|
|
653
720
|
return await this.getPermission(scope, permissionId) !== null;
|
|
654
721
|
},
|
|
655
|
-
update(update) {
|
|
656
|
-
return app._updateClientUser(update, session);
|
|
722
|
+
async update(update) {
|
|
723
|
+
return await app._updateClientUser(update, session);
|
|
657
724
|
},
|
|
658
|
-
sendVerificationEmail() {
|
|
725
|
+
async sendVerificationEmail() {
|
|
659
726
|
if (!crud?.primary_email) {
|
|
660
727
|
throw new import_errors.StackAssertionError("User does not have a primary email");
|
|
661
728
|
}
|
|
662
|
-
return app._sendVerificationEmail(crud.primary_email, session);
|
|
729
|
+
return await app._sendVerificationEmail(crud.primary_email, session);
|
|
730
|
+
},
|
|
731
|
+
async updatePassword(options) {
|
|
732
|
+
return await app._updatePassword(options, session);
|
|
663
733
|
},
|
|
664
|
-
|
|
665
|
-
|
|
734
|
+
async getTeamProfile(team) {
|
|
735
|
+
const result = await app._currentUserTeamProfileCache.getOrWait([session, team.id], "write-only");
|
|
736
|
+
return app._editableTeamProfileFromCrud(result);
|
|
737
|
+
},
|
|
738
|
+
useTeamProfile(team) {
|
|
739
|
+
const result = useAsyncCache(app._currentUserTeamProfileCache, [session, team.id], "user.useTeamProfile()");
|
|
740
|
+
return app._editableTeamProfileFromCrud(result);
|
|
666
741
|
}
|
|
667
742
|
};
|
|
668
743
|
}
|
|
@@ -796,6 +871,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
796
871
|
async redirectToError(options) {
|
|
797
872
|
return await this._redirectToHandler("error", options);
|
|
798
873
|
}
|
|
874
|
+
async redirectToTeamInvitation(options) {
|
|
875
|
+
return await this._redirectToHandler("teamInvitation", options);
|
|
876
|
+
}
|
|
877
|
+
async redirectToTeamCreation(options) {
|
|
878
|
+
return await this._redirectToHandler("teamCreation", options);
|
|
879
|
+
}
|
|
799
880
|
async sendForgotPasswordEmail(email) {
|
|
800
881
|
const redirectUrl = (0, import_url.constructRedirectUrl)(this.urls.passwordReset);
|
|
801
882
|
const error = await this._interface.sendForgotPasswordEmail(email, redirectUrl);
|
|
@@ -813,6 +894,42 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
813
894
|
async verifyPasswordResetCode(code) {
|
|
814
895
|
return await this._interface.verifyPasswordResetCode(code);
|
|
815
896
|
}
|
|
897
|
+
async verifyTeamInvitationCode(code) {
|
|
898
|
+
const result = await this._interface.acceptTeamInvitation({
|
|
899
|
+
type: "check",
|
|
900
|
+
code,
|
|
901
|
+
session: this._getSession()
|
|
902
|
+
});
|
|
903
|
+
if (result.status === "ok") {
|
|
904
|
+
return import_results.Result.ok(void 0);
|
|
905
|
+
} else {
|
|
906
|
+
return import_results.Result.error(result.error);
|
|
907
|
+
}
|
|
908
|
+
}
|
|
909
|
+
async acceptTeamInvitation(code) {
|
|
910
|
+
const result = await this._interface.acceptTeamInvitation({
|
|
911
|
+
type: "use",
|
|
912
|
+
code,
|
|
913
|
+
session: this._getSession()
|
|
914
|
+
});
|
|
915
|
+
if (result.status === "ok") {
|
|
916
|
+
return import_results.Result.ok(void 0);
|
|
917
|
+
} else {
|
|
918
|
+
return import_results.Result.error(result.error);
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
async getTeamInvitationDetails(code) {
|
|
922
|
+
const result = await this._interface.acceptTeamInvitation({
|
|
923
|
+
type: "details",
|
|
924
|
+
code,
|
|
925
|
+
session: this._getSession()
|
|
926
|
+
});
|
|
927
|
+
if (result.status === "ok") {
|
|
928
|
+
return import_results.Result.ok({ teamDisplayName: result.data.team_display_name });
|
|
929
|
+
} else {
|
|
930
|
+
return import_results.Result.error(result.error);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
816
933
|
async verifyEmail(code) {
|
|
817
934
|
return await this._interface.verifyEmail(code);
|
|
818
935
|
}
|
|
@@ -877,10 +994,49 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
877
994
|
}
|
|
878
995
|
);
|
|
879
996
|
}
|
|
997
|
+
/**
|
|
998
|
+
* @deprecated
|
|
999
|
+
* TODO remove
|
|
1000
|
+
*/
|
|
1001
|
+
async _experimentalMfa(error, session) {
|
|
1002
|
+
const otp = prompt("Please enter the six-digit TOTP code from your authenticator app.");
|
|
1003
|
+
if (!otp) {
|
|
1004
|
+
throw new import_stack_shared.KnownErrors.InvalidTotpCode();
|
|
1005
|
+
}
|
|
1006
|
+
return await this._interface.totpMfa(
|
|
1007
|
+
error.details?.attempt_code ?? (0, import_errors.throwErr)("attempt code missing"),
|
|
1008
|
+
otp,
|
|
1009
|
+
session
|
|
1010
|
+
);
|
|
1011
|
+
}
|
|
1012
|
+
/**
|
|
1013
|
+
* @deprecated
|
|
1014
|
+
* TODO remove
|
|
1015
|
+
*/
|
|
1016
|
+
async _catchMfaRequiredError(callback) {
|
|
1017
|
+
try {
|
|
1018
|
+
return await callback();
|
|
1019
|
+
} catch (e) {
|
|
1020
|
+
if (e instanceof import_stack_shared.KnownErrors.MultiFactorAuthenticationRequired) {
|
|
1021
|
+
return await this._experimentalMfa(e, this._getSession());
|
|
1022
|
+
}
|
|
1023
|
+
throw e;
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
880
1026
|
async signInWithCredential(options) {
|
|
881
1027
|
this._ensurePersistentTokenStore();
|
|
882
1028
|
const session = this._getSession();
|
|
883
|
-
|
|
1029
|
+
let result;
|
|
1030
|
+
try {
|
|
1031
|
+
result = await this._catchMfaRequiredError(async () => {
|
|
1032
|
+
return await this._interface.signInWithCredential(options.email, options.password, session);
|
|
1033
|
+
});
|
|
1034
|
+
} catch (e) {
|
|
1035
|
+
if (e instanceof import_stack_shared.KnownErrors.InvalidTotpCode) {
|
|
1036
|
+
return e;
|
|
1037
|
+
}
|
|
1038
|
+
throw e;
|
|
1039
|
+
}
|
|
884
1040
|
if (!(result instanceof import_stack_shared.KnownError)) {
|
|
885
1041
|
await this._signInToAccountWithTokens(result);
|
|
886
1042
|
return await this.redirectToAfterSignIn({ replace: true });
|
|
@@ -905,7 +1061,17 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
905
1061
|
}
|
|
906
1062
|
async signInWithMagicLink(code) {
|
|
907
1063
|
this._ensurePersistentTokenStore();
|
|
908
|
-
|
|
1064
|
+
let result;
|
|
1065
|
+
try {
|
|
1066
|
+
result = await this._catchMfaRequiredError(async () => {
|
|
1067
|
+
return await this._interface.signInWithMagicLink(code);
|
|
1068
|
+
});
|
|
1069
|
+
} catch (e) {
|
|
1070
|
+
if (e instanceof import_stack_shared.KnownErrors.InvalidTotpCode) {
|
|
1071
|
+
return e;
|
|
1072
|
+
}
|
|
1073
|
+
throw e;
|
|
1074
|
+
}
|
|
909
1075
|
if (result instanceof import_stack_shared.KnownError) {
|
|
910
1076
|
return result;
|
|
911
1077
|
}
|
|
@@ -918,10 +1084,21 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
918
1084
|
}
|
|
919
1085
|
async callOAuthCallback() {
|
|
920
1086
|
this._ensurePersistentTokenStore();
|
|
921
|
-
|
|
1087
|
+
let result;
|
|
1088
|
+
try {
|
|
1089
|
+
result = await this._catchMfaRequiredError(async () => {
|
|
1090
|
+
return await (0, import_auth.callOAuthCallback)(this._interface, this.urls.oauthCallback);
|
|
1091
|
+
});
|
|
1092
|
+
} catch (e) {
|
|
1093
|
+
if (e instanceof import_stack_shared.KnownErrors.InvalidTotpCode) {
|
|
1094
|
+
alert("Invalid TOTP code. Please try signing in again.");
|
|
1095
|
+
}
|
|
1096
|
+
throw e;
|
|
1097
|
+
}
|
|
922
1098
|
if (result) {
|
|
1099
|
+
console.log("OAuth callback result", result);
|
|
923
1100
|
await this._signInToAccountWithTokens(result);
|
|
924
|
-
if (result.afterCallbackRedirectUrl) {
|
|
1101
|
+
if ("afterCallbackRedirectUrl" in result && result.afterCallbackRedirectUrl) {
|
|
925
1102
|
await _redirectTo(result.afterCallbackRedirectUrl, { replace: true });
|
|
926
1103
|
return true;
|
|
927
1104
|
} else if (result.newUser) {
|
|
@@ -1075,11 +1252,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1075
1252
|
this._serverTeamsCache = createCache(async ([userId]) => {
|
|
1076
1253
|
return await this._interface.listServerTeams({ userId });
|
|
1077
1254
|
});
|
|
1078
|
-
this._serverTeamUsersCache = createCache(async ([teamId]) => {
|
|
1079
|
-
return await this._interface.listServerTeamUsers(teamId);
|
|
1080
|
-
});
|
|
1081
1255
|
this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId, recursive]) => {
|
|
1082
|
-
return await this._interface.
|
|
1256
|
+
return await this._interface.listServerTeamPermissions({ teamId, userId, recursive }, null);
|
|
1083
1257
|
});
|
|
1084
1258
|
this._serverUserOAuthConnectionAccessTokensCache = createCache(
|
|
1085
1259
|
async ([userId, providerId, scope]) => {
|
|
@@ -1107,12 +1281,33 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1107
1281
|
});
|
|
1108
1282
|
}
|
|
1109
1283
|
);
|
|
1284
|
+
this._serverTeamMemberProfilesCache = createCache(
|
|
1285
|
+
async ([teamId]) => {
|
|
1286
|
+
return await this._interface.listServerTeamMemberProfiles({ teamId });
|
|
1287
|
+
}
|
|
1288
|
+
);
|
|
1289
|
+
this._serverUserTeamProfileCache = createCache(
|
|
1290
|
+
async ([teamId, userId]) => {
|
|
1291
|
+
return await this._interface.getServerTeamMemberProfile({ teamId, userId });
|
|
1292
|
+
}
|
|
1293
|
+
);
|
|
1110
1294
|
}
|
|
1111
1295
|
async _updateServerUser(userId, update) {
|
|
1112
1296
|
const result = await this._interface.updateServerUser(userId, serverUserUpdateOptionsToCrud(update));
|
|
1113
1297
|
await this._refreshUsers();
|
|
1114
1298
|
return result;
|
|
1115
1299
|
}
|
|
1300
|
+
_serverEditableTeamProfileFromCrud(crud) {
|
|
1301
|
+
const app = this;
|
|
1302
|
+
const clientProfile = this._editableTeamProfileFromCrud(crud);
|
|
1303
|
+
return {
|
|
1304
|
+
...clientProfile,
|
|
1305
|
+
async update(update) {
|
|
1306
|
+
await clientProfile.update(update);
|
|
1307
|
+
await app._serverUserTeamProfileCache.refresh([crud.team_id, crud.user_id]);
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1116
1311
|
_serverUserFromCrud(crud) {
|
|
1117
1312
|
const app = this;
|
|
1118
1313
|
async function getConnectedAccount(id, options) {
|
|
@@ -1191,6 +1386,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1191
1386
|
await app._serverTeamsCache.refresh([void 0]);
|
|
1192
1387
|
return app._serverTeamFromCrud(team);
|
|
1193
1388
|
},
|
|
1389
|
+
leaveTeam: async (team) => {
|
|
1390
|
+
await app._interface.leaveServerTeam({ teamId: team.id, userId: crud.id });
|
|
1391
|
+
},
|
|
1194
1392
|
async listPermissions(scope, options) {
|
|
1195
1393
|
const recursive = options?.recursive ?? true;
|
|
1196
1394
|
const permissions = await app._serverTeamUserPermissionsCache.getOrWait([scope.id, crud.id, recursive], "write-only");
|
|
@@ -1220,6 +1418,23 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1220
1418
|
},
|
|
1221
1419
|
async updatePassword(options) {
|
|
1222
1420
|
return await app._checkFeatureSupport("updatePassword() on ServerUser", {});
|
|
1421
|
+
},
|
|
1422
|
+
async getTeamProfile(team) {
|
|
1423
|
+
const result = await app._serverUserTeamProfileCache.getOrWait([team.id, crud.id], "write-only");
|
|
1424
|
+
return app._serverEditableTeamProfileFromCrud(result);
|
|
1425
|
+
},
|
|
1426
|
+
useTeamProfile(team) {
|
|
1427
|
+
const result = useAsyncCache(app._serverUserTeamProfileCache, [team.id, crud.id], "user.useTeamProfile()");
|
|
1428
|
+
return (0, import_react2.useMemo)(() => app._serverEditableTeamProfileFromCrud(result), [result]);
|
|
1429
|
+
}
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
_serverTeamUserFromCrud(crud) {
|
|
1433
|
+
return {
|
|
1434
|
+
...this._serverUserFromCrud(crud.user),
|
|
1435
|
+
teamProfile: {
|
|
1436
|
+
displayName: crud.display_name,
|
|
1437
|
+
profileImageUrl: crud.profile_image_url
|
|
1223
1438
|
}
|
|
1224
1439
|
};
|
|
1225
1440
|
}
|
|
@@ -1240,9 +1455,6 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1240
1455
|
displayName: crud.display_name,
|
|
1241
1456
|
profileImageUrl: crud.profile_image_url,
|
|
1242
1457
|
createdAt: new Date(crud.created_at_millis),
|
|
1243
|
-
async listUsers() {
|
|
1244
|
-
return (await app._interface.listServerTeamUsers(crud.id)).map((u) => app._serverUserFromCrud(u));
|
|
1245
|
-
},
|
|
1246
1458
|
async update(update) {
|
|
1247
1459
|
await app._interface.updateServerTeam(crud.id, serverTeamUpdateOptionsToCrud(update));
|
|
1248
1460
|
await app._serverTeamsCache.refresh([void 0]);
|
|
@@ -1251,26 +1463,43 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1251
1463
|
await app._interface.deleteServerTeam(crud.id);
|
|
1252
1464
|
await app._serverTeamsCache.refresh([void 0]);
|
|
1253
1465
|
},
|
|
1466
|
+
async listUsers() {
|
|
1467
|
+
const result = await app._serverTeamMemberProfilesCache.getOrWait([crud.id], "write-only");
|
|
1468
|
+
return result.map((u) => app._serverTeamUserFromCrud(u));
|
|
1469
|
+
},
|
|
1254
1470
|
useUsers() {
|
|
1255
|
-
const result = useAsyncCache(app.
|
|
1256
|
-
return (0, import_react2.useMemo)(() => result.map((u) => app.
|
|
1471
|
+
const result = useAsyncCache(app._serverTeamMemberProfilesCache, [crud.id], "team.useUsers()");
|
|
1472
|
+
return (0, import_react2.useMemo)(() => result.map((u) => app._serverTeamUserFromCrud(u)), [result]);
|
|
1257
1473
|
},
|
|
1258
1474
|
async addUser(userId) {
|
|
1259
1475
|
await app._interface.addServerUserToTeam({
|
|
1260
1476
|
teamId: crud.id,
|
|
1261
1477
|
userId
|
|
1262
1478
|
});
|
|
1263
|
-
await app.
|
|
1479
|
+
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
|
|
1264
1480
|
},
|
|
1265
1481
|
async removeUser(userId) {
|
|
1266
1482
|
await app._interface.removeServerUserFromTeam({
|
|
1267
1483
|
teamId: crud.id,
|
|
1268
1484
|
userId
|
|
1269
1485
|
});
|
|
1270
|
-
await app.
|
|
1486
|
+
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
|
|
1487
|
+
},
|
|
1488
|
+
async inviteUser(options) {
|
|
1489
|
+
return await app._interface.sendTeamInvitation({
|
|
1490
|
+
teamId: crud.id,
|
|
1491
|
+
email: options.email,
|
|
1492
|
+
session: null,
|
|
1493
|
+
callbackUrl: (0, import_url.constructRedirectUrl)(app.urls.teamInvitation)
|
|
1494
|
+
});
|
|
1271
1495
|
}
|
|
1272
1496
|
};
|
|
1273
1497
|
}
|
|
1498
|
+
async createUser(options) {
|
|
1499
|
+
const crud = await this._interface.createServerUser(serverUserCreateOptionsToCrud(options));
|
|
1500
|
+
await this._refreshUsers();
|
|
1501
|
+
return this._serverUserFromCrud(crud);
|
|
1502
|
+
}
|
|
1274
1503
|
async getUser(options) {
|
|
1275
1504
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1276
1505
|
const session = this._getSession(options?.tokenStore);
|
|
@@ -1448,8 +1677,10 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1448
1677
|
isProductionMode: data.is_production_mode,
|
|
1449
1678
|
config: {
|
|
1450
1679
|
id: data.config.id,
|
|
1680
|
+
signUpEnabled: data.config.sign_up_enabled,
|
|
1451
1681
|
credentialEnabled: data.config.credential_enabled,
|
|
1452
1682
|
magicLinkEnabled: data.config.magic_link_enabled,
|
|
1683
|
+
clientTeamCreationEnabled: data.config.client_team_creation_enabled,
|
|
1453
1684
|
allowLocalhost: data.config.allow_localhost,
|
|
1454
1685
|
oauthProviders: data.config.oauth_providers.map((p) => p.type === "shared" ? {
|
|
1455
1686
|
id: p.id,
|
|
@@ -1486,6 +1717,9 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1486
1717
|
await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));
|
|
1487
1718
|
await onRefresh();
|
|
1488
1719
|
},
|
|
1720
|
+
async delete() {
|
|
1721
|
+
await app._interface.deleteProject();
|
|
1722
|
+
},
|
|
1489
1723
|
async getProductionModeErrors() {
|
|
1490
1724
|
return (0, import_production_mode.getProductionModeErrors)(data);
|
|
1491
1725
|
},
|
|
@@ -1628,7 +1862,8 @@ function userUpdateOptionsToCrud(options) {
|
|
|
1628
1862
|
return {
|
|
1629
1863
|
display_name: options.displayName,
|
|
1630
1864
|
client_metadata: options.clientMetadata,
|
|
1631
|
-
selected_team_id: options.selectedTeamId
|
|
1865
|
+
selected_team_id: options.selectedTeamId,
|
|
1866
|
+
totp_secret_base64: options.totpMultiFactorSecret != null ? (0, import_bytes.encodeBase64)(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
|
|
1632
1867
|
};
|
|
1633
1868
|
}
|
|
1634
1869
|
function serverUserUpdateOptionsToCrud(options) {
|
|
@@ -1640,7 +1875,17 @@ function serverUserUpdateOptionsToCrud(options) {
|
|
|
1640
1875
|
selected_team_id: options.selectedTeamId,
|
|
1641
1876
|
primary_email_auth_enabled: options.primaryEmailAuthEnabled,
|
|
1642
1877
|
primary_email_verified: options.primaryEmailVerified,
|
|
1643
|
-
password: options.password
|
|
1878
|
+
password: options.password,
|
|
1879
|
+
totp_secret_base64: options.totpMultiFactorSecret != null ? (0, import_bytes.encodeBase64)(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
function serverUserCreateOptionsToCrud(options) {
|
|
1883
|
+
return {
|
|
1884
|
+
primary_email: options.primaryEmail,
|
|
1885
|
+
password: options.password,
|
|
1886
|
+
primary_email_auth_enabled: true,
|
|
1887
|
+
display_name: options.displayName,
|
|
1888
|
+
primary_email_verified: options.primaryEmailVerified
|
|
1644
1889
|
};
|
|
1645
1890
|
}
|
|
1646
1891
|
function adminProjectUpdateOptionsToCrud(options) {
|
|
@@ -1674,10 +1919,12 @@ function adminProjectUpdateOptionsToCrud(options) {
|
|
|
1674
1919
|
sender_name: options.config.emailConfig.senderName,
|
|
1675
1920
|
sender_email: options.config.emailConfig.senderEmail
|
|
1676
1921
|
}),
|
|
1922
|
+
sign_up_enabled: options.config?.signUpEnabled,
|
|
1677
1923
|
credential_enabled: options.config?.credentialEnabled,
|
|
1678
1924
|
magic_link_enabled: options.config?.magicLinkEnabled,
|
|
1679
1925
|
allow_localhost: options.config?.allowLocalhost,
|
|
1680
1926
|
create_team_on_sign_up: options.config?.createTeamOnSignUp,
|
|
1927
|
+
client_team_creation_enabled: options.config?.clientTeamCreationEnabled,
|
|
1681
1928
|
team_creator_default_permissions: options.config?.teamCreatorDefaultPermissions,
|
|
1682
1929
|
team_member_default_permissions: options.config?.teamMemberDefaultPermissions
|
|
1683
1930
|
}
|