@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
|
@@ -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.
|
|
27
|
+
var clientVersion = "js @stackframe/stack@2.5.19";
|
|
27
28
|
function getUrls(partial) {
|
|
28
29
|
const handler = partial.handler ?? "/handler";
|
|
29
30
|
const home = partial.home ?? "/";
|
|
@@ -44,6 +45,8 @@ function getUrls(partial) {
|
|
|
44
45
|
home,
|
|
45
46
|
accountSettings: `${handler}/account-settings`,
|
|
46
47
|
error: `${handler}/error`,
|
|
48
|
+
teamInvitation: `${handler}/team-invitation`,
|
|
49
|
+
teamCreation: `${handler}/team-creation`,
|
|
47
50
|
...filterUndefined(partial)
|
|
48
51
|
};
|
|
49
52
|
}
|
|
@@ -175,6 +178,16 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
175
178
|
});
|
|
176
179
|
}
|
|
177
180
|
);
|
|
181
|
+
this._teamMemberProfilesCache = createCacheBySession(
|
|
182
|
+
async (session, [teamId]) => {
|
|
183
|
+
return await this._interface.listTeamMemberProfiles({ teamId }, session);
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
this._currentUserTeamProfileCache = createCacheBySession(
|
|
187
|
+
async (session, [teamId]) => {
|
|
188
|
+
return await this._interface.getTeamMemberProfile({ teamId, userId: "me" }, session);
|
|
189
|
+
}
|
|
190
|
+
);
|
|
178
191
|
this._memoryTokenStore = createEmptyTokenStore();
|
|
179
192
|
this._requestTokenStores = /* @__PURE__ */ new WeakMap();
|
|
180
193
|
this._storedCookieTokenStore = null;
|
|
@@ -456,6 +469,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
456
469
|
return React.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
457
470
|
}
|
|
458
471
|
async _signInToAccountWithTokens(tokens) {
|
|
472
|
+
if (!("accessToken" in tokens) || !("refreshToken" in tokens)) {
|
|
473
|
+
throw new StackAssertionError("Invalid tokens object; can't sign in with this", { tokens });
|
|
474
|
+
}
|
|
459
475
|
const tokenStore = this._getOrCreateTokenStore();
|
|
460
476
|
tokenStore.set(tokens);
|
|
461
477
|
}
|
|
@@ -478,9 +494,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
478
494
|
_clientProjectFromCrud(crud) {
|
|
479
495
|
return {
|
|
480
496
|
id: crud.id,
|
|
497
|
+
displayName: crud.display_name,
|
|
481
498
|
config: {
|
|
499
|
+
signUpEnabled: crud.config.sign_up_enabled,
|
|
482
500
|
credentialEnabled: crud.config.credential_enabled,
|
|
483
501
|
magicLinkEnabled: crud.config.magic_link_enabled,
|
|
502
|
+
clientTeamCreationEnabled: crud.config.client_team_creation_enabled,
|
|
484
503
|
oauthProviders: crud.config.enabled_oauth_providers.map((p) => ({
|
|
485
504
|
id: p.id
|
|
486
505
|
}))
|
|
@@ -492,11 +511,37 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
492
511
|
id: crud.id
|
|
493
512
|
};
|
|
494
513
|
}
|
|
514
|
+
_clientTeamUserFromCrud(crud) {
|
|
515
|
+
return {
|
|
516
|
+
id: crud.user_id,
|
|
517
|
+
teamProfile: {
|
|
518
|
+
displayName: crud.display_name,
|
|
519
|
+
profileImageUrl: crud.profile_image_url
|
|
520
|
+
}
|
|
521
|
+
};
|
|
522
|
+
}
|
|
495
523
|
_clientTeamFromCrud(crud) {
|
|
524
|
+
const app = this;
|
|
496
525
|
return {
|
|
497
526
|
id: crud.id,
|
|
498
527
|
displayName: crud.display_name,
|
|
499
|
-
profileImageUrl: crud.profile_image_url
|
|
528
|
+
profileImageUrl: crud.profile_image_url,
|
|
529
|
+
async inviteUser(options) {
|
|
530
|
+
return await app._interface.sendTeamInvitation({
|
|
531
|
+
teamId: crud.id,
|
|
532
|
+
email: options.email,
|
|
533
|
+
session: app._getSession(),
|
|
534
|
+
callbackUrl: constructRedirectUrl(app.urls.teamInvitation)
|
|
535
|
+
});
|
|
536
|
+
},
|
|
537
|
+
async listUsers() {
|
|
538
|
+
const result = await app._teamMemberProfilesCache.getOrWait([app._getSession(), crud.id], "write-only");
|
|
539
|
+
return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
|
|
540
|
+
},
|
|
541
|
+
useUsers() {
|
|
542
|
+
const result = useAsyncCache(app._teamMemberProfilesCache, [app._getSession(), crud.id], "team.useUsers()");
|
|
543
|
+
return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
|
|
544
|
+
}
|
|
500
545
|
};
|
|
501
546
|
}
|
|
502
547
|
_createAuth(session) {
|
|
@@ -542,11 +587,30 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
542
587
|
emailAuthEnabled: crud.auth_with_email,
|
|
543
588
|
oauthProviders: crud.oauth_providers,
|
|
544
589
|
selectedTeam: crud.selected_team && this._clientTeamFromCrud(crud.selected_team),
|
|
590
|
+
isMultiFactorRequired: crud.requires_totp_mfa,
|
|
545
591
|
toClientJson() {
|
|
546
592
|
return crud;
|
|
547
593
|
}
|
|
548
594
|
};
|
|
549
595
|
}
|
|
596
|
+
_editableTeamProfileFromCrud(crud) {
|
|
597
|
+
const app = this;
|
|
598
|
+
return {
|
|
599
|
+
displayName: crud.display_name,
|
|
600
|
+
profileImageUrl: crud.profile_image_url,
|
|
601
|
+
async update(update) {
|
|
602
|
+
await app._interface.updateTeamMemberProfile({
|
|
603
|
+
teamId: crud.team_id,
|
|
604
|
+
userId: crud.user_id,
|
|
605
|
+
profile: {
|
|
606
|
+
display_name: update.displayName,
|
|
607
|
+
profile_image_url: update.profileImageUrl
|
|
608
|
+
}
|
|
609
|
+
}, app._getSession());
|
|
610
|
+
await app._currentUserTeamProfileCache.refresh([app._getSession(), crud.team_id]);
|
|
611
|
+
}
|
|
612
|
+
};
|
|
613
|
+
}
|
|
550
614
|
_createUserExtra(crud, session) {
|
|
551
615
|
const app = this;
|
|
552
616
|
async function getConnectedAccount(id, options) {
|
|
@@ -592,6 +656,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
592
656
|
await app._currentUserTeamsCache.refresh([session]);
|
|
593
657
|
return app._clientTeamFromCrud(crud2);
|
|
594
658
|
},
|
|
659
|
+
async leaveTeam(team) {
|
|
660
|
+
await app._interface.leaveTeam(team.id, session);
|
|
661
|
+
},
|
|
595
662
|
async listPermissions(scope, options) {
|
|
596
663
|
const recursive = options?.recursive ?? true;
|
|
597
664
|
const permissions = await app._currentUserPermissionsCache.getOrWait([session, scope.id, recursive], "write-only");
|
|
@@ -613,17 +680,25 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
613
680
|
async hasPermission(scope, permissionId) {
|
|
614
681
|
return await this.getPermission(scope, permissionId) !== null;
|
|
615
682
|
},
|
|
616
|
-
update(update) {
|
|
617
|
-
return app._updateClientUser(update, session);
|
|
683
|
+
async update(update) {
|
|
684
|
+
return await app._updateClientUser(update, session);
|
|
618
685
|
},
|
|
619
|
-
sendVerificationEmail() {
|
|
686
|
+
async sendVerificationEmail() {
|
|
620
687
|
if (!crud?.primary_email) {
|
|
621
688
|
throw new StackAssertionError("User does not have a primary email");
|
|
622
689
|
}
|
|
623
|
-
return app._sendVerificationEmail(crud.primary_email, session);
|
|
690
|
+
return await app._sendVerificationEmail(crud.primary_email, session);
|
|
691
|
+
},
|
|
692
|
+
async updatePassword(options) {
|
|
693
|
+
return await app._updatePassword(options, session);
|
|
624
694
|
},
|
|
625
|
-
|
|
626
|
-
|
|
695
|
+
async getTeamProfile(team) {
|
|
696
|
+
const result = await app._currentUserTeamProfileCache.getOrWait([session, team.id], "write-only");
|
|
697
|
+
return app._editableTeamProfileFromCrud(result);
|
|
698
|
+
},
|
|
699
|
+
useTeamProfile(team) {
|
|
700
|
+
const result = useAsyncCache(app._currentUserTeamProfileCache, [session, team.id], "user.useTeamProfile()");
|
|
701
|
+
return app._editableTeamProfileFromCrud(result);
|
|
627
702
|
}
|
|
628
703
|
};
|
|
629
704
|
}
|
|
@@ -757,6 +832,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
757
832
|
async redirectToError(options) {
|
|
758
833
|
return await this._redirectToHandler("error", options);
|
|
759
834
|
}
|
|
835
|
+
async redirectToTeamInvitation(options) {
|
|
836
|
+
return await this._redirectToHandler("teamInvitation", options);
|
|
837
|
+
}
|
|
838
|
+
async redirectToTeamCreation(options) {
|
|
839
|
+
return await this._redirectToHandler("teamCreation", options);
|
|
840
|
+
}
|
|
760
841
|
async sendForgotPasswordEmail(email) {
|
|
761
842
|
const redirectUrl = constructRedirectUrl(this.urls.passwordReset);
|
|
762
843
|
const error = await this._interface.sendForgotPasswordEmail(email, redirectUrl);
|
|
@@ -774,6 +855,42 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
774
855
|
async verifyPasswordResetCode(code) {
|
|
775
856
|
return await this._interface.verifyPasswordResetCode(code);
|
|
776
857
|
}
|
|
858
|
+
async verifyTeamInvitationCode(code) {
|
|
859
|
+
const result = await this._interface.acceptTeamInvitation({
|
|
860
|
+
type: "check",
|
|
861
|
+
code,
|
|
862
|
+
session: this._getSession()
|
|
863
|
+
});
|
|
864
|
+
if (result.status === "ok") {
|
|
865
|
+
return Result.ok(void 0);
|
|
866
|
+
} else {
|
|
867
|
+
return Result.error(result.error);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
async acceptTeamInvitation(code) {
|
|
871
|
+
const result = await this._interface.acceptTeamInvitation({
|
|
872
|
+
type: "use",
|
|
873
|
+
code,
|
|
874
|
+
session: this._getSession()
|
|
875
|
+
});
|
|
876
|
+
if (result.status === "ok") {
|
|
877
|
+
return Result.ok(void 0);
|
|
878
|
+
} else {
|
|
879
|
+
return Result.error(result.error);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
async getTeamInvitationDetails(code) {
|
|
883
|
+
const result = await this._interface.acceptTeamInvitation({
|
|
884
|
+
type: "details",
|
|
885
|
+
code,
|
|
886
|
+
session: this._getSession()
|
|
887
|
+
});
|
|
888
|
+
if (result.status === "ok") {
|
|
889
|
+
return Result.ok({ teamDisplayName: result.data.team_display_name });
|
|
890
|
+
} else {
|
|
891
|
+
return Result.error(result.error);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
777
894
|
async verifyEmail(code) {
|
|
778
895
|
return await this._interface.verifyEmail(code);
|
|
779
896
|
}
|
|
@@ -838,10 +955,49 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
838
955
|
}
|
|
839
956
|
);
|
|
840
957
|
}
|
|
958
|
+
/**
|
|
959
|
+
* @deprecated
|
|
960
|
+
* TODO remove
|
|
961
|
+
*/
|
|
962
|
+
async _experimentalMfa(error, session) {
|
|
963
|
+
const otp = prompt("Please enter the six-digit TOTP code from your authenticator app.");
|
|
964
|
+
if (!otp) {
|
|
965
|
+
throw new KnownErrors.InvalidTotpCode();
|
|
966
|
+
}
|
|
967
|
+
return await this._interface.totpMfa(
|
|
968
|
+
error.details?.attempt_code ?? throwErr("attempt code missing"),
|
|
969
|
+
otp,
|
|
970
|
+
session
|
|
971
|
+
);
|
|
972
|
+
}
|
|
973
|
+
/**
|
|
974
|
+
* @deprecated
|
|
975
|
+
* TODO remove
|
|
976
|
+
*/
|
|
977
|
+
async _catchMfaRequiredError(callback) {
|
|
978
|
+
try {
|
|
979
|
+
return await callback();
|
|
980
|
+
} catch (e) {
|
|
981
|
+
if (e instanceof KnownErrors.MultiFactorAuthenticationRequired) {
|
|
982
|
+
return await this._experimentalMfa(e, this._getSession());
|
|
983
|
+
}
|
|
984
|
+
throw e;
|
|
985
|
+
}
|
|
986
|
+
}
|
|
841
987
|
async signInWithCredential(options) {
|
|
842
988
|
this._ensurePersistentTokenStore();
|
|
843
989
|
const session = this._getSession();
|
|
844
|
-
|
|
990
|
+
let result;
|
|
991
|
+
try {
|
|
992
|
+
result = await this._catchMfaRequiredError(async () => {
|
|
993
|
+
return await this._interface.signInWithCredential(options.email, options.password, session);
|
|
994
|
+
});
|
|
995
|
+
} catch (e) {
|
|
996
|
+
if (e instanceof KnownErrors.InvalidTotpCode) {
|
|
997
|
+
return e;
|
|
998
|
+
}
|
|
999
|
+
throw e;
|
|
1000
|
+
}
|
|
845
1001
|
if (!(result instanceof KnownError)) {
|
|
846
1002
|
await this._signInToAccountWithTokens(result);
|
|
847
1003
|
return await this.redirectToAfterSignIn({ replace: true });
|
|
@@ -866,7 +1022,17 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
866
1022
|
}
|
|
867
1023
|
async signInWithMagicLink(code) {
|
|
868
1024
|
this._ensurePersistentTokenStore();
|
|
869
|
-
|
|
1025
|
+
let result;
|
|
1026
|
+
try {
|
|
1027
|
+
result = await this._catchMfaRequiredError(async () => {
|
|
1028
|
+
return await this._interface.signInWithMagicLink(code);
|
|
1029
|
+
});
|
|
1030
|
+
} catch (e) {
|
|
1031
|
+
if (e instanceof KnownErrors.InvalidTotpCode) {
|
|
1032
|
+
return e;
|
|
1033
|
+
}
|
|
1034
|
+
throw e;
|
|
1035
|
+
}
|
|
870
1036
|
if (result instanceof KnownError) {
|
|
871
1037
|
return result;
|
|
872
1038
|
}
|
|
@@ -879,10 +1045,21 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
879
1045
|
}
|
|
880
1046
|
async callOAuthCallback() {
|
|
881
1047
|
this._ensurePersistentTokenStore();
|
|
882
|
-
|
|
1048
|
+
let result;
|
|
1049
|
+
try {
|
|
1050
|
+
result = await this._catchMfaRequiredError(async () => {
|
|
1051
|
+
return await callOAuthCallback(this._interface, this.urls.oauthCallback);
|
|
1052
|
+
});
|
|
1053
|
+
} catch (e) {
|
|
1054
|
+
if (e instanceof KnownErrors.InvalidTotpCode) {
|
|
1055
|
+
alert("Invalid TOTP code. Please try signing in again.");
|
|
1056
|
+
}
|
|
1057
|
+
throw e;
|
|
1058
|
+
}
|
|
883
1059
|
if (result) {
|
|
1060
|
+
console.log("OAuth callback result", result);
|
|
884
1061
|
await this._signInToAccountWithTokens(result);
|
|
885
|
-
if (result.afterCallbackRedirectUrl) {
|
|
1062
|
+
if ("afterCallbackRedirectUrl" in result && result.afterCallbackRedirectUrl) {
|
|
886
1063
|
await _redirectTo(result.afterCallbackRedirectUrl, { replace: true });
|
|
887
1064
|
return true;
|
|
888
1065
|
} else if (result.newUser) {
|
|
@@ -1036,11 +1213,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1036
1213
|
this._serverTeamsCache = createCache(async ([userId]) => {
|
|
1037
1214
|
return await this._interface.listServerTeams({ userId });
|
|
1038
1215
|
});
|
|
1039
|
-
this._serverTeamUsersCache = createCache(async ([teamId]) => {
|
|
1040
|
-
return await this._interface.listServerTeamUsers(teamId);
|
|
1041
|
-
});
|
|
1042
1216
|
this._serverTeamUserPermissionsCache = createCache(async ([teamId, userId, recursive]) => {
|
|
1043
|
-
return await this._interface.
|
|
1217
|
+
return await this._interface.listServerTeamPermissions({ teamId, userId, recursive }, null);
|
|
1044
1218
|
});
|
|
1045
1219
|
this._serverUserOAuthConnectionAccessTokensCache = createCache(
|
|
1046
1220
|
async ([userId, providerId, scope]) => {
|
|
@@ -1068,12 +1242,33 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1068
1242
|
});
|
|
1069
1243
|
}
|
|
1070
1244
|
);
|
|
1245
|
+
this._serverTeamMemberProfilesCache = createCache(
|
|
1246
|
+
async ([teamId]) => {
|
|
1247
|
+
return await this._interface.listServerTeamMemberProfiles({ teamId });
|
|
1248
|
+
}
|
|
1249
|
+
);
|
|
1250
|
+
this._serverUserTeamProfileCache = createCache(
|
|
1251
|
+
async ([teamId, userId]) => {
|
|
1252
|
+
return await this._interface.getServerTeamMemberProfile({ teamId, userId });
|
|
1253
|
+
}
|
|
1254
|
+
);
|
|
1071
1255
|
}
|
|
1072
1256
|
async _updateServerUser(userId, update) {
|
|
1073
1257
|
const result = await this._interface.updateServerUser(userId, serverUserUpdateOptionsToCrud(update));
|
|
1074
1258
|
await this._refreshUsers();
|
|
1075
1259
|
return result;
|
|
1076
1260
|
}
|
|
1261
|
+
_serverEditableTeamProfileFromCrud(crud) {
|
|
1262
|
+
const app = this;
|
|
1263
|
+
const clientProfile = this._editableTeamProfileFromCrud(crud);
|
|
1264
|
+
return {
|
|
1265
|
+
...clientProfile,
|
|
1266
|
+
async update(update) {
|
|
1267
|
+
await clientProfile.update(update);
|
|
1268
|
+
await app._serverUserTeamProfileCache.refresh([crud.team_id, crud.user_id]);
|
|
1269
|
+
}
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1077
1272
|
_serverUserFromCrud(crud) {
|
|
1078
1273
|
const app = this;
|
|
1079
1274
|
async function getConnectedAccount(id, options) {
|
|
@@ -1152,6 +1347,9 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1152
1347
|
await app._serverTeamsCache.refresh([void 0]);
|
|
1153
1348
|
return app._serverTeamFromCrud(team);
|
|
1154
1349
|
},
|
|
1350
|
+
leaveTeam: async (team) => {
|
|
1351
|
+
await app._interface.leaveServerTeam({ teamId: team.id, userId: crud.id });
|
|
1352
|
+
},
|
|
1155
1353
|
async listPermissions(scope, options) {
|
|
1156
1354
|
const recursive = options?.recursive ?? true;
|
|
1157
1355
|
const permissions = await app._serverTeamUserPermissionsCache.getOrWait([scope.id, crud.id, recursive], "write-only");
|
|
@@ -1181,6 +1379,23 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1181
1379
|
},
|
|
1182
1380
|
async updatePassword(options) {
|
|
1183
1381
|
return await app._checkFeatureSupport("updatePassword() on ServerUser", {});
|
|
1382
|
+
},
|
|
1383
|
+
async getTeamProfile(team) {
|
|
1384
|
+
const result = await app._serverUserTeamProfileCache.getOrWait([team.id, crud.id], "write-only");
|
|
1385
|
+
return app._serverEditableTeamProfileFromCrud(result);
|
|
1386
|
+
},
|
|
1387
|
+
useTeamProfile(team) {
|
|
1388
|
+
const result = useAsyncCache(app._serverUserTeamProfileCache, [team.id, crud.id], "user.useTeamProfile()");
|
|
1389
|
+
return useMemo(() => app._serverEditableTeamProfileFromCrud(result), [result]);
|
|
1390
|
+
}
|
|
1391
|
+
};
|
|
1392
|
+
}
|
|
1393
|
+
_serverTeamUserFromCrud(crud) {
|
|
1394
|
+
return {
|
|
1395
|
+
...this._serverUserFromCrud(crud.user),
|
|
1396
|
+
teamProfile: {
|
|
1397
|
+
displayName: crud.display_name,
|
|
1398
|
+
profileImageUrl: crud.profile_image_url
|
|
1184
1399
|
}
|
|
1185
1400
|
};
|
|
1186
1401
|
}
|
|
@@ -1201,9 +1416,6 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1201
1416
|
displayName: crud.display_name,
|
|
1202
1417
|
profileImageUrl: crud.profile_image_url,
|
|
1203
1418
|
createdAt: new Date(crud.created_at_millis),
|
|
1204
|
-
async listUsers() {
|
|
1205
|
-
return (await app._interface.listServerTeamUsers(crud.id)).map((u) => app._serverUserFromCrud(u));
|
|
1206
|
-
},
|
|
1207
1419
|
async update(update) {
|
|
1208
1420
|
await app._interface.updateServerTeam(crud.id, serverTeamUpdateOptionsToCrud(update));
|
|
1209
1421
|
await app._serverTeamsCache.refresh([void 0]);
|
|
@@ -1212,26 +1424,43 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1212
1424
|
await app._interface.deleteServerTeam(crud.id);
|
|
1213
1425
|
await app._serverTeamsCache.refresh([void 0]);
|
|
1214
1426
|
},
|
|
1427
|
+
async listUsers() {
|
|
1428
|
+
const result = await app._serverTeamMemberProfilesCache.getOrWait([crud.id], "write-only");
|
|
1429
|
+
return result.map((u) => app._serverTeamUserFromCrud(u));
|
|
1430
|
+
},
|
|
1215
1431
|
useUsers() {
|
|
1216
|
-
const result = useAsyncCache(app.
|
|
1217
|
-
return useMemo(() => result.map((u) => app.
|
|
1432
|
+
const result = useAsyncCache(app._serverTeamMemberProfilesCache, [crud.id], "team.useUsers()");
|
|
1433
|
+
return useMemo(() => result.map((u) => app._serverTeamUserFromCrud(u)), [result]);
|
|
1218
1434
|
},
|
|
1219
1435
|
async addUser(userId) {
|
|
1220
1436
|
await app._interface.addServerUserToTeam({
|
|
1221
1437
|
teamId: crud.id,
|
|
1222
1438
|
userId
|
|
1223
1439
|
});
|
|
1224
|
-
await app.
|
|
1440
|
+
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
|
|
1225
1441
|
},
|
|
1226
1442
|
async removeUser(userId) {
|
|
1227
1443
|
await app._interface.removeServerUserFromTeam({
|
|
1228
1444
|
teamId: crud.id,
|
|
1229
1445
|
userId
|
|
1230
1446
|
});
|
|
1231
|
-
await app.
|
|
1447
|
+
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
|
|
1448
|
+
},
|
|
1449
|
+
async inviteUser(options) {
|
|
1450
|
+
return await app._interface.sendTeamInvitation({
|
|
1451
|
+
teamId: crud.id,
|
|
1452
|
+
email: options.email,
|
|
1453
|
+
session: null,
|
|
1454
|
+
callbackUrl: constructRedirectUrl(app.urls.teamInvitation)
|
|
1455
|
+
});
|
|
1232
1456
|
}
|
|
1233
1457
|
};
|
|
1234
1458
|
}
|
|
1459
|
+
async createUser(options) {
|
|
1460
|
+
const crud = await this._interface.createServerUser(serverUserCreateOptionsToCrud(options));
|
|
1461
|
+
await this._refreshUsers();
|
|
1462
|
+
return this._serverUserFromCrud(crud);
|
|
1463
|
+
}
|
|
1235
1464
|
async getUser(options) {
|
|
1236
1465
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1237
1466
|
const session = this._getSession(options?.tokenStore);
|
|
@@ -1409,8 +1638,10 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1409
1638
|
isProductionMode: data.is_production_mode,
|
|
1410
1639
|
config: {
|
|
1411
1640
|
id: data.config.id,
|
|
1641
|
+
signUpEnabled: data.config.sign_up_enabled,
|
|
1412
1642
|
credentialEnabled: data.config.credential_enabled,
|
|
1413
1643
|
magicLinkEnabled: data.config.magic_link_enabled,
|
|
1644
|
+
clientTeamCreationEnabled: data.config.client_team_creation_enabled,
|
|
1414
1645
|
allowLocalhost: data.config.allow_localhost,
|
|
1415
1646
|
oauthProviders: data.config.oauth_providers.map((p) => p.type === "shared" ? {
|
|
1416
1647
|
id: p.id,
|
|
@@ -1447,6 +1678,9 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1447
1678
|
await app._interface.updateProject(adminProjectUpdateOptionsToCrud(update));
|
|
1448
1679
|
await onRefresh();
|
|
1449
1680
|
},
|
|
1681
|
+
async delete() {
|
|
1682
|
+
await app._interface.deleteProject();
|
|
1683
|
+
},
|
|
1450
1684
|
async getProductionModeErrors() {
|
|
1451
1685
|
return getProductionModeErrors(data);
|
|
1452
1686
|
},
|
|
@@ -1589,7 +1823,8 @@ function userUpdateOptionsToCrud(options) {
|
|
|
1589
1823
|
return {
|
|
1590
1824
|
display_name: options.displayName,
|
|
1591
1825
|
client_metadata: options.clientMetadata,
|
|
1592
|
-
selected_team_id: options.selectedTeamId
|
|
1826
|
+
selected_team_id: options.selectedTeamId,
|
|
1827
|
+
totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
|
|
1593
1828
|
};
|
|
1594
1829
|
}
|
|
1595
1830
|
function serverUserUpdateOptionsToCrud(options) {
|
|
@@ -1601,7 +1836,17 @@ function serverUserUpdateOptionsToCrud(options) {
|
|
|
1601
1836
|
selected_team_id: options.selectedTeamId,
|
|
1602
1837
|
primary_email_auth_enabled: options.primaryEmailAuthEnabled,
|
|
1603
1838
|
primary_email_verified: options.primaryEmailVerified,
|
|
1604
|
-
password: options.password
|
|
1839
|
+
password: options.password,
|
|
1840
|
+
totp_secret_base64: options.totpMultiFactorSecret != null ? encodeBase64(options.totpMultiFactorSecret) : options.totpMultiFactorSecret
|
|
1841
|
+
};
|
|
1842
|
+
}
|
|
1843
|
+
function serverUserCreateOptionsToCrud(options) {
|
|
1844
|
+
return {
|
|
1845
|
+
primary_email: options.primaryEmail,
|
|
1846
|
+
password: options.password,
|
|
1847
|
+
primary_email_auth_enabled: true,
|
|
1848
|
+
display_name: options.displayName,
|
|
1849
|
+
primary_email_verified: options.primaryEmailVerified
|
|
1605
1850
|
};
|
|
1606
1851
|
}
|
|
1607
1852
|
function adminProjectUpdateOptionsToCrud(options) {
|
|
@@ -1635,10 +1880,12 @@ function adminProjectUpdateOptionsToCrud(options) {
|
|
|
1635
1880
|
sender_name: options.config.emailConfig.senderName,
|
|
1636
1881
|
sender_email: options.config.emailConfig.senderEmail
|
|
1637
1882
|
}),
|
|
1883
|
+
sign_up_enabled: options.config?.signUpEnabled,
|
|
1638
1884
|
credential_enabled: options.config?.credentialEnabled,
|
|
1639
1885
|
magic_link_enabled: options.config?.magicLinkEnabled,
|
|
1640
1886
|
allow_localhost: options.config?.allowLocalhost,
|
|
1641
1887
|
create_team_on_sign_up: options.config?.createTeamOnSignUp,
|
|
1888
|
+
client_team_creation_enabled: options.config?.clientTeamCreationEnabled,
|
|
1642
1889
|
team_creator_default_permissions: options.config?.teamCreatorDefaultPermissions,
|
|
1643
1890
|
team_member_default_permissions: options.config?.teamMemberDefaultPermissions
|
|
1644
1891
|
}
|