@stackframe/stack 2.6.19 → 2.6.20
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 +10 -0
- package/dist/components-page/stack-handler.d.mts +13 -7
- package/dist/components-page/stack-handler.d.ts +13 -7
- package/dist/components-page/stack-handler.js +146 -126
- package/dist/components-page/stack-handler.js.map +1 -1
- package/dist/esm/components-page/stack-handler.js +148 -128
- package/dist/esm/components-page/stack-handler.js.map +1 -1
- package/dist/esm/generated/quetzal-translations.js +10 -10
- package/dist/esm/generated/quetzal-translations.js.map +1 -1
- package/dist/esm/lib/cookie.js +118 -40
- package/dist/esm/lib/cookie.js.map +1 -1
- package/dist/esm/lib/stack-app.js +123 -99
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/generated/quetzal-translations.d.mts +1 -1
- package/dist/generated/quetzal-translations.d.ts +1 -1
- package/dist/generated/quetzal-translations.js +10 -10
- package/dist/generated/quetzal-translations.js.map +1 -1
- package/dist/lib/cookie.d.mts +21 -5
- package/dist/lib/cookie.d.ts +21 -5
- package/dist/lib/cookie.js +125 -41
- package/dist/lib/cookie.js.map +1 -1
- package/dist/lib/stack-app.d.mts +3 -4
- package/dist/lib/stack-app.d.ts +3 -4
- package/dist/lib/stack-app.js +122 -98
- package/dist/lib/stack-app.js.map +1 -1
- package/package.json +20 -9
package/dist/lib/stack-app.js
CHANGED
|
@@ -64,7 +64,7 @@ var import_url = require("../utils/url");
|
|
|
64
64
|
var import_auth = require("./auth");
|
|
65
65
|
var import_cookie = require("./cookie");
|
|
66
66
|
var NextNavigation = (0, import_compile_time.scrambleDuringCompileTime)(NextNavigationUnscrambled);
|
|
67
|
-
var clientVersion = "js @stackframe/stack@2.6.
|
|
67
|
+
var clientVersion = "js @stackframe/stack@2.6.20";
|
|
68
68
|
function getUrls(partial) {
|
|
69
69
|
const handler = partial.handler ?? "/handler";
|
|
70
70
|
const home = partial.home ?? "/";
|
|
@@ -234,7 +234,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
234
234
|
);
|
|
235
235
|
this._memoryTokenStore = createEmptyTokenStore();
|
|
236
236
|
this._requestTokenStores = /* @__PURE__ */ new WeakMap();
|
|
237
|
-
this.
|
|
237
|
+
this._storedBrowserCookieTokenStore = null;
|
|
238
238
|
/**
|
|
239
239
|
* A map from token stores and session keys to sessions.
|
|
240
240
|
*
|
|
@@ -358,38 +358,38 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
358
358
|
get _accessTokenCookieName() {
|
|
359
359
|
return `stack-access`;
|
|
360
360
|
}
|
|
361
|
-
|
|
361
|
+
_getBrowserCookieTokenStore() {
|
|
362
362
|
if (!(0, import_env.isBrowserLike)()) {
|
|
363
363
|
throw new Error("Cannot use cookie token store on the server!");
|
|
364
364
|
}
|
|
365
|
-
if (this.
|
|
365
|
+
if (this._storedBrowserCookieTokenStore === null) {
|
|
366
366
|
const getCurrentValue = (old) => {
|
|
367
367
|
const tokens = this._getTokensFromCookies({
|
|
368
|
-
refreshTokenCookie: (0, import_cookie.
|
|
368
|
+
refreshTokenCookie: (0, import_cookie.getCookieClient)(this._refreshTokenCookieName) ?? (0, import_cookie.getCookieClient)("stack-refresh"),
|
|
369
369
|
// keep old cookie name for backwards-compatibility
|
|
370
|
-
accessTokenCookie: (0, import_cookie.
|
|
370
|
+
accessTokenCookie: (0, import_cookie.getCookieClient)(this._accessTokenCookieName)
|
|
371
371
|
});
|
|
372
372
|
return {
|
|
373
373
|
refreshToken: tokens.refreshToken,
|
|
374
374
|
accessToken: tokens.accessToken ?? (old?.refreshToken === tokens.refreshToken ? old.accessToken : null)
|
|
375
375
|
};
|
|
376
376
|
};
|
|
377
|
-
this.
|
|
377
|
+
this._storedBrowserCookieTokenStore = new import_stores.Store(getCurrentValue(null));
|
|
378
378
|
let hasSucceededInWriting = true;
|
|
379
379
|
setInterval(() => {
|
|
380
380
|
if (hasSucceededInWriting) {
|
|
381
|
-
const oldValue = this.
|
|
381
|
+
const oldValue = this._storedBrowserCookieTokenStore.get();
|
|
382
382
|
const currentValue = getCurrentValue(oldValue);
|
|
383
383
|
if (!(0, import_objects.deepPlainEquals)(currentValue, oldValue)) {
|
|
384
|
-
this.
|
|
384
|
+
this._storedBrowserCookieTokenStore.set(currentValue);
|
|
385
385
|
}
|
|
386
386
|
}
|
|
387
387
|
}, 100);
|
|
388
|
-
this.
|
|
388
|
+
this._storedBrowserCookieTokenStore.onChange((value) => {
|
|
389
389
|
try {
|
|
390
|
-
(0, import_cookie.
|
|
391
|
-
(0, import_cookie.
|
|
392
|
-
(0, import_cookie.
|
|
390
|
+
(0, import_cookie.setOrDeleteCookieClient)(this._refreshTokenCookieName, value.refreshToken, { maxAge: 60 * 60 * 24 * 365 });
|
|
391
|
+
(0, import_cookie.setOrDeleteCookieClient)(this._accessTokenCookieName, value.accessToken ? JSON.stringify([value.refreshToken, value.accessToken]) : null, { maxAge: 60 * 60 * 24 });
|
|
392
|
+
(0, import_cookie.deleteCookieClient)("stack-refresh");
|
|
393
393
|
hasSucceededInWriting = true;
|
|
394
394
|
} catch (e) {
|
|
395
395
|
if (!(0, import_env.isBrowserLike)()) {
|
|
@@ -400,30 +400,31 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
400
400
|
}
|
|
401
401
|
});
|
|
402
402
|
}
|
|
403
|
-
return this.
|
|
403
|
+
return this._storedBrowserCookieTokenStore;
|
|
404
404
|
}
|
|
405
|
-
_getOrCreateTokenStore(overrideTokenStoreInit) {
|
|
405
|
+
_getOrCreateTokenStore(cookieHelper, overrideTokenStoreInit) {
|
|
406
406
|
const tokenStoreInit = overrideTokenStoreInit === void 0 ? this._tokenStoreInit : overrideTokenStoreInit;
|
|
407
407
|
switch (tokenStoreInit) {
|
|
408
408
|
case "cookie": {
|
|
409
|
-
return this.
|
|
409
|
+
return this._getBrowserCookieTokenStore();
|
|
410
410
|
}
|
|
411
411
|
case "nextjs-cookie": {
|
|
412
412
|
if ((0, import_env.isBrowserLike)()) {
|
|
413
|
-
return this.
|
|
413
|
+
return this._getBrowserCookieTokenStore();
|
|
414
414
|
} else {
|
|
415
415
|
const tokens = this._getTokensFromCookies({
|
|
416
|
-
refreshTokenCookie:
|
|
416
|
+
refreshTokenCookie: cookieHelper.get(this._refreshTokenCookieName) ?? cookieHelper.get("stack-refresh"),
|
|
417
417
|
// keep old cookie name for backwards-compatibility
|
|
418
|
-
accessTokenCookie:
|
|
418
|
+
accessTokenCookie: cookieHelper.get(this._accessTokenCookieName)
|
|
419
419
|
});
|
|
420
420
|
const store = new import_stores.Store(tokens);
|
|
421
421
|
store.onChange((value) => {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
422
|
+
(0, import_promises.runAsynchronously)(async () => {
|
|
423
|
+
await Promise.all([
|
|
424
|
+
(0, import_cookie.setOrDeleteCookie)(this._refreshTokenCookieName, value.refreshToken, { maxAge: 60 * 60 * 24 * 365, noOpIfServerComponent: true }),
|
|
425
|
+
(0, import_cookie.setOrDeleteCookie)(this._accessTokenCookieName, value.accessToken ? JSON.stringify([value.refreshToken, value.accessToken]) : null, { maxAge: 60 * 60 * 24, noOpIfServerComponent: true })
|
|
426
|
+
]);
|
|
427
|
+
});
|
|
427
428
|
});
|
|
428
429
|
return store;
|
|
429
430
|
}
|
|
@@ -446,7 +447,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
446
447
|
} catch (e) {
|
|
447
448
|
throw new Error(`Invalid x-stack-auth header: ${stackAuthHeader}`, { cause: e });
|
|
448
449
|
}
|
|
449
|
-
return this._getOrCreateTokenStore({
|
|
450
|
+
return this._getOrCreateTokenStore(cookieHelper, {
|
|
450
451
|
accessToken: parsed2.accessToken ?? null,
|
|
451
452
|
refreshToken: parsed2.refreshToken ?? null
|
|
452
453
|
});
|
|
@@ -470,6 +471,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
470
471
|
}
|
|
471
472
|
}
|
|
472
473
|
}
|
|
474
|
+
_useTokenStore(overrideTokenStoreInit) {
|
|
475
|
+
(0, import_react.suspendIfSsr)();
|
|
476
|
+
const cookieHelper = (0, import_cookie.createBrowserCookieHelper)();
|
|
477
|
+
const tokenStore = this._getOrCreateTokenStore(cookieHelper, overrideTokenStoreInit);
|
|
478
|
+
return tokenStore;
|
|
479
|
+
}
|
|
473
480
|
_getSessionFromTokenStore(tokenStore) {
|
|
474
481
|
const tokenObj = tokenStore.get();
|
|
475
482
|
const sessionKey = import_sessions.InternalSession.calculateSessionKey(tokenObj);
|
|
@@ -497,12 +504,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
497
504
|
sessionsBySessionKey.set(sessionKey, session);
|
|
498
505
|
return session;
|
|
499
506
|
}
|
|
500
|
-
_getSession(overrideTokenStoreInit) {
|
|
501
|
-
const tokenStore = this._getOrCreateTokenStore(overrideTokenStoreInit);
|
|
507
|
+
async _getSession(overrideTokenStoreInit) {
|
|
508
|
+
const tokenStore = this._getOrCreateTokenStore(await (0, import_cookie.createCookieHelper)(), overrideTokenStoreInit);
|
|
502
509
|
return this._getSessionFromTokenStore(tokenStore);
|
|
503
510
|
}
|
|
504
511
|
_useSession(overrideTokenStoreInit) {
|
|
505
|
-
const tokenStore = this.
|
|
512
|
+
const tokenStore = this._useTokenStore(overrideTokenStoreInit);
|
|
506
513
|
const subscribe = (0, import_react2.useCallback)((cb) => {
|
|
507
514
|
const { unsubscribe } = tokenStore.onChange(() => {
|
|
508
515
|
cb();
|
|
@@ -516,7 +523,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
516
523
|
if (!("accessToken" in tokens) || !("refreshToken" in tokens)) {
|
|
517
524
|
throw new import_errors.StackAssertionError("Invalid tokens object; can't sign in with this", { tokens });
|
|
518
525
|
}
|
|
519
|
-
const tokenStore = this._getOrCreateTokenStore();
|
|
526
|
+
const tokenStore = this._getOrCreateTokenStore(await (0, import_cookie.createCookieHelper)());
|
|
520
527
|
tokenStore.set(tokens);
|
|
521
528
|
}
|
|
522
529
|
_hasPersistentTokenStore(overrideTokenStoreInit) {
|
|
@@ -566,7 +573,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
566
573
|
}
|
|
567
574
|
};
|
|
568
575
|
}
|
|
569
|
-
_clientTeamFromCrud(crud) {
|
|
576
|
+
_clientTeamFromCrud(crud, session) {
|
|
570
577
|
const app = this;
|
|
571
578
|
return {
|
|
572
579
|
id: crud.id,
|
|
@@ -575,28 +582,31 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
575
582
|
clientMetadata: crud.client_metadata,
|
|
576
583
|
clientReadOnlyMetadata: crud.client_read_only_metadata,
|
|
577
584
|
async inviteUser(options) {
|
|
585
|
+
if (!options.callbackUrl && typeof window === "undefined") {
|
|
586
|
+
throw new Error("Cannot invite user without a callback URL when calling the inviteUser function on the server.");
|
|
587
|
+
}
|
|
578
588
|
await app._interface.sendTeamInvitation({
|
|
579
589
|
teamId: crud.id,
|
|
580
590
|
email: options.email,
|
|
581
|
-
session
|
|
582
|
-
callbackUrl: (0, import_url.constructRedirectUrl)(app.urls.teamInvitation)
|
|
591
|
+
session,
|
|
592
|
+
callbackUrl: options.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.teamInvitation)
|
|
583
593
|
});
|
|
584
594
|
},
|
|
585
595
|
async listUsers() {
|
|
586
|
-
const result = await app._teamMemberProfilesCache.getOrWait([
|
|
596
|
+
const result = await app._teamMemberProfilesCache.getOrWait([session, crud.id], "write-only");
|
|
587
597
|
return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
|
|
588
598
|
},
|
|
589
599
|
useUsers() {
|
|
590
|
-
const result = useAsyncCache(app._teamMemberProfilesCache, [
|
|
600
|
+
const result = useAsyncCache(app._teamMemberProfilesCache, [session, crud.id], "team.useUsers()");
|
|
591
601
|
return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
|
|
592
602
|
},
|
|
593
603
|
async update(data) {
|
|
594
|
-
await app._interface.updateTeam({ data: teamUpdateOptionsToCrud(data), teamId: crud.id },
|
|
595
|
-
await app._currentUserTeamsCache.refresh([
|
|
604
|
+
await app._interface.updateTeam({ data: teamUpdateOptionsToCrud(data), teamId: crud.id }, session);
|
|
605
|
+
await app._currentUserTeamsCache.refresh([session]);
|
|
596
606
|
}
|
|
597
607
|
};
|
|
598
608
|
}
|
|
599
|
-
_clientContactChannelFromCrud(crud) {
|
|
609
|
+
_clientContactChannelFromCrud(crud, session) {
|
|
600
610
|
const app = this;
|
|
601
611
|
return {
|
|
602
612
|
id: crud.id,
|
|
@@ -606,15 +616,15 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
606
616
|
isPrimary: crud.is_primary,
|
|
607
617
|
usedForAuth: crud.used_for_auth,
|
|
608
618
|
async sendVerificationEmail() {
|
|
609
|
-
await app._interface.sendCurrentUserContactChannelVerificationEmail(crud.id, (0, import_url.constructRedirectUrl)(app.urls.emailVerification),
|
|
619
|
+
await app._interface.sendCurrentUserContactChannelVerificationEmail(crud.id, (0, import_url.constructRedirectUrl)(app.urls.emailVerification), session);
|
|
610
620
|
},
|
|
611
621
|
async update(data) {
|
|
612
|
-
await app._interface.updateClientContactChannel(crud.id, contactChannelUpdateOptionsToCrud(data),
|
|
613
|
-
await app._clientContactChannelsCache.refresh([
|
|
622
|
+
await app._interface.updateClientContactChannel(crud.id, contactChannelUpdateOptionsToCrud(data), session);
|
|
623
|
+
await app._clientContactChannelsCache.refresh([session]);
|
|
614
624
|
},
|
|
615
625
|
async delete() {
|
|
616
|
-
await app._interface.deleteClientContactChannel(crud.id,
|
|
617
|
-
await app._clientContactChannelsCache.refresh([
|
|
626
|
+
await app._interface.deleteClientContactChannel(crud.id, session);
|
|
627
|
+
await app._clientContactChannelsCache.refresh([session]);
|
|
618
628
|
}
|
|
619
629
|
};
|
|
620
630
|
}
|
|
@@ -670,10 +680,25 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
670
680
|
}
|
|
671
681
|
};
|
|
672
682
|
}
|
|
683
|
+
_editableTeamProfileFromCrud(crud, session) {
|
|
684
|
+
const app = this;
|
|
685
|
+
return {
|
|
686
|
+
displayName: crud.display_name,
|
|
687
|
+
profileImageUrl: crud.profile_image_url,
|
|
688
|
+
async update(update) {
|
|
689
|
+
await app._interface.updateTeamMemberProfile({
|
|
690
|
+
teamId: crud.team_id,
|
|
691
|
+
userId: crud.user_id,
|
|
692
|
+
profile: {
|
|
693
|
+
display_name: update.displayName,
|
|
694
|
+
profile_image_url: update.profileImageUrl
|
|
695
|
+
}
|
|
696
|
+
}, session);
|
|
697
|
+
await app._currentUserTeamProfileCache.refresh([session, crud.team_id]);
|
|
698
|
+
}
|
|
699
|
+
};
|
|
700
|
+
}
|
|
673
701
|
_createBaseUser(crud) {
|
|
674
|
-
if (!crud) {
|
|
675
|
-
throw new import_errors.StackAssertionError("User not found");
|
|
676
|
-
}
|
|
677
702
|
return {
|
|
678
703
|
id: crud.id,
|
|
679
704
|
displayName: crud.display_name,
|
|
@@ -688,32 +713,13 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
688
713
|
otpAuthEnabled: crud.otp_auth_enabled,
|
|
689
714
|
oauthProviders: crud.oauth_providers,
|
|
690
715
|
passkeyAuthEnabled: crud.passkey_auth_enabled,
|
|
691
|
-
selectedTeam: crud.selected_team && this._clientTeamFromCrud(crud.selected_team),
|
|
692
716
|
isMultiFactorRequired: crud.requires_totp_mfa,
|
|
693
717
|
toClientJson() {
|
|
694
718
|
return crud;
|
|
695
719
|
}
|
|
696
720
|
};
|
|
697
721
|
}
|
|
698
|
-
|
|
699
|
-
const app = this;
|
|
700
|
-
return {
|
|
701
|
-
displayName: crud.display_name,
|
|
702
|
-
profileImageUrl: crud.profile_image_url,
|
|
703
|
-
async update(update) {
|
|
704
|
-
await app._interface.updateTeamMemberProfile({
|
|
705
|
-
teamId: crud.team_id,
|
|
706
|
-
userId: crud.user_id,
|
|
707
|
-
profile: {
|
|
708
|
-
display_name: update.displayName,
|
|
709
|
-
profile_image_url: update.profileImageUrl
|
|
710
|
-
}
|
|
711
|
-
}, app._getSession());
|
|
712
|
-
await app._currentUserTeamProfileCache.refresh([app._getSession(), crud.team_id]);
|
|
713
|
-
}
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
_createUserExtra(crud, session) {
|
|
722
|
+
_createUserExtraFromCurrent(crud, session) {
|
|
717
723
|
const app = this;
|
|
718
724
|
async function getConnectedAccount(id, options) {
|
|
719
725
|
const scopeString = options?.scopes?.join(" ");
|
|
@@ -747,11 +753,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
747
753
|
},
|
|
748
754
|
async listTeams() {
|
|
749
755
|
const teams = await app._currentUserTeamsCache.getOrWait([session], "write-only");
|
|
750
|
-
return teams.map((crud2) => app._clientTeamFromCrud(crud2));
|
|
756
|
+
return teams.map((crud2) => app._clientTeamFromCrud(crud2, session));
|
|
751
757
|
},
|
|
752
758
|
useTeams() {
|
|
753
759
|
const teams = useAsyncCache(app._currentUserTeamsCache, [session], "user.useTeams()");
|
|
754
|
-
return (0, import_react2.useMemo)(() => teams.map((crud2) => app._clientTeamFromCrud(crud2)), [teams]);
|
|
760
|
+
return (0, import_react2.useMemo)(() => teams.map((crud2) => app._clientTeamFromCrud(crud2, session)), [teams]);
|
|
755
761
|
},
|
|
756
762
|
async createTeam(data) {
|
|
757
763
|
const crud2 = await app._interface.createClientTeam({
|
|
@@ -759,7 +765,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
759
765
|
creator_user_id: "me"
|
|
760
766
|
}, session);
|
|
761
767
|
await app._currentUserTeamsCache.refresh([session]);
|
|
762
|
-
return app._clientTeamFromCrud(crud2);
|
|
768
|
+
return app._clientTeamFromCrud(crud2, session);
|
|
763
769
|
},
|
|
764
770
|
async leaveTeam(team) {
|
|
765
771
|
await app._interface.leaveTeam(team.id, session);
|
|
@@ -789,7 +795,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
789
795
|
return await app._updateClientUser(update, session);
|
|
790
796
|
},
|
|
791
797
|
async sendVerificationEmail() {
|
|
792
|
-
if (!crud
|
|
798
|
+
if (!crud.primary_email) {
|
|
793
799
|
throw new import_errors.StackAssertionError("User does not have a primary email");
|
|
794
800
|
}
|
|
795
801
|
return await app._sendVerificationEmail(crud.primary_email, session);
|
|
@@ -804,13 +810,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
804
810
|
await app._currentUserCache.refresh([session]);
|
|
805
811
|
return result;
|
|
806
812
|
},
|
|
813
|
+
selectedTeam: crud.selected_team && this._clientTeamFromCrud(crud.selected_team, session),
|
|
807
814
|
async getTeamProfile(team) {
|
|
808
815
|
const result = await app._currentUserTeamProfileCache.getOrWait([session, team.id], "write-only");
|
|
809
|
-
return app._editableTeamProfileFromCrud(result);
|
|
816
|
+
return app._editableTeamProfileFromCrud(result, session);
|
|
810
817
|
},
|
|
811
818
|
useTeamProfile(team) {
|
|
812
819
|
const result = useAsyncCache(app._currentUserTeamProfileCache, [session, team.id], "user.useTeamProfile()");
|
|
813
|
-
return app._editableTeamProfileFromCrud(result);
|
|
820
|
+
return app._editableTeamProfileFromCrud(result, session);
|
|
814
821
|
},
|
|
815
822
|
async delete() {
|
|
816
823
|
await app._interface.deleteCurrentUser(session);
|
|
@@ -818,16 +825,16 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
818
825
|
},
|
|
819
826
|
async listContactChannels() {
|
|
820
827
|
const result = await app._clientContactChannelsCache.getOrWait([session], "write-only");
|
|
821
|
-
return result.map((crud2) => app._clientContactChannelFromCrud(crud2));
|
|
828
|
+
return result.map((crud2) => app._clientContactChannelFromCrud(crud2, session));
|
|
822
829
|
},
|
|
823
830
|
useContactChannels() {
|
|
824
831
|
const result = useAsyncCache(app._clientContactChannelsCache, [session], "user.useContactChannels()");
|
|
825
|
-
return result.map((crud2) => app._clientContactChannelFromCrud(crud2));
|
|
832
|
+
return result.map((crud2) => app._clientContactChannelFromCrud(crud2, session));
|
|
826
833
|
},
|
|
827
834
|
async createContactChannel(data) {
|
|
828
835
|
const crud2 = await app._interface.createClientContactChannel(contactChannelCreateOptionsToCrud("me", data), session);
|
|
829
836
|
await app._clientContactChannelsCache.refresh([session]);
|
|
830
|
-
return app._clientContactChannelFromCrud(crud2);
|
|
837
|
+
return app._clientContactChannelFromCrud(crud2, session);
|
|
831
838
|
}
|
|
832
839
|
};
|
|
833
840
|
}
|
|
@@ -850,7 +857,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
850
857
|
const currentUser = {
|
|
851
858
|
...this._createBaseUser(crud),
|
|
852
859
|
...this._createAuth(session),
|
|
853
|
-
...this.
|
|
860
|
+
...this._createUserExtraFromCurrent(crud, session),
|
|
854
861
|
...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
|
|
855
862
|
};
|
|
856
863
|
Object.freeze(currentUser);
|
|
@@ -982,14 +989,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
982
989
|
return await this._interface.acceptTeamInvitation({
|
|
983
990
|
type: "check",
|
|
984
991
|
code,
|
|
985
|
-
session: this._getSession()
|
|
992
|
+
session: await this._getSession()
|
|
986
993
|
});
|
|
987
994
|
}
|
|
988
995
|
async acceptTeamInvitation(code) {
|
|
989
996
|
const result = await this._interface.acceptTeamInvitation({
|
|
990
997
|
type: "use",
|
|
991
998
|
code,
|
|
992
|
-
session: this._getSession()
|
|
999
|
+
session: await this._getSession()
|
|
993
1000
|
});
|
|
994
1001
|
if (result.status === "ok") {
|
|
995
1002
|
return import_results.Result.ok(void 0);
|
|
@@ -1001,7 +1008,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1001
1008
|
const result = await this._interface.acceptTeamInvitation({
|
|
1002
1009
|
type: "details",
|
|
1003
1010
|
code,
|
|
1004
|
-
session: this._getSession()
|
|
1011
|
+
session: await this._getSession()
|
|
1005
1012
|
});
|
|
1006
1013
|
if (result.status === "ok") {
|
|
1007
1014
|
return import_results.Result.ok({ teamDisplayName: result.data.team_display_name });
|
|
@@ -1011,13 +1018,13 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1011
1018
|
}
|
|
1012
1019
|
async verifyEmail(code) {
|
|
1013
1020
|
const result = await this._interface.verifyEmail(code);
|
|
1014
|
-
await this._currentUserCache.refresh([this._getSession()]);
|
|
1015
|
-
await this._clientContactChannelsCache.refresh([this._getSession()]);
|
|
1021
|
+
await this._currentUserCache.refresh([await this._getSession()]);
|
|
1022
|
+
await this._clientContactChannelsCache.refresh([await this._getSession()]);
|
|
1016
1023
|
return result;
|
|
1017
1024
|
}
|
|
1018
1025
|
async getUser(options) {
|
|
1019
1026
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1020
|
-
const session = this._getSession(options?.tokenStore);
|
|
1027
|
+
const session = await this._getSession(options?.tokenStore);
|
|
1021
1028
|
const crud = await this._currentUserCache.getOrWait([session], "write-only");
|
|
1022
1029
|
if (crud === null) {
|
|
1023
1030
|
switch (options?.or) {
|
|
@@ -1100,14 +1107,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1100
1107
|
return await callback();
|
|
1101
1108
|
} catch (e) {
|
|
1102
1109
|
if (e instanceof import_stack_shared.KnownErrors.MultiFactorAuthenticationRequired) {
|
|
1103
|
-
return import_results.Result.ok(await this._experimentalMfa(e, this._getSession()));
|
|
1110
|
+
return import_results.Result.ok(await this._experimentalMfa(e, await this._getSession()));
|
|
1104
1111
|
}
|
|
1105
1112
|
throw e;
|
|
1106
1113
|
}
|
|
1107
1114
|
}
|
|
1108
1115
|
async signInWithCredential(options) {
|
|
1109
1116
|
this._ensurePersistentTokenStore();
|
|
1110
|
-
const session = this._getSession();
|
|
1117
|
+
const session = await this._getSession();
|
|
1111
1118
|
let result;
|
|
1112
1119
|
try {
|
|
1113
1120
|
result = await this._catchMfaRequiredError(async () => {
|
|
@@ -1131,7 +1138,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1131
1138
|
}
|
|
1132
1139
|
async signUpWithCredential(options) {
|
|
1133
1140
|
this._ensurePersistentTokenStore();
|
|
1134
|
-
const session = this._getSession();
|
|
1141
|
+
const session = await this._getSession();
|
|
1135
1142
|
const emailVerificationRedirectUrl = (0, import_url.constructRedirectUrl)(this.urls.emailVerification);
|
|
1136
1143
|
const result = await this._interface.signUpWithCredential(
|
|
1137
1144
|
options.email,
|
|
@@ -1176,10 +1183,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1176
1183
|
}
|
|
1177
1184
|
async signInWithPasskey() {
|
|
1178
1185
|
this._ensurePersistentTokenStore();
|
|
1186
|
+
const session = await this._getSession();
|
|
1179
1187
|
let result;
|
|
1180
1188
|
try {
|
|
1181
1189
|
result = await this._catchMfaRequiredError(async () => {
|
|
1182
|
-
const initiationResult = await this._interface.initiatePasskeyAuthentication({},
|
|
1190
|
+
const initiationResult = await this._interface.initiatePasskeyAuthentication({}, session);
|
|
1183
1191
|
if (initiationResult.status !== "ok") {
|
|
1184
1192
|
return import_results.Result.error(new import_stack_shared.KnownErrors.PasskeyAuthenticationFailed("Failed to get initiation options for passkey authentication"));
|
|
1185
1193
|
}
|
|
@@ -1334,7 +1342,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1334
1342
|
};
|
|
1335
1343
|
},
|
|
1336
1344
|
setCurrentUser: (userJsonPromise) => {
|
|
1337
|
-
(0, import_promises.runAsynchronously)(
|
|
1345
|
+
(0, import_promises.runAsynchronously)(async () => {
|
|
1346
|
+
await this._currentUserCache.forceSetCachedValueAsync([await this._getSession()], userJsonPromise);
|
|
1347
|
+
});
|
|
1338
1348
|
}
|
|
1339
1349
|
};
|
|
1340
1350
|
}
|
|
@@ -1424,11 +1434,18 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1424
1434
|
}
|
|
1425
1435
|
_serverEditableTeamProfileFromCrud(crud) {
|
|
1426
1436
|
const app = this;
|
|
1427
|
-
const clientProfile = this._editableTeamProfileFromCrud(crud);
|
|
1428
1437
|
return {
|
|
1429
|
-
|
|
1438
|
+
displayName: crud.display_name,
|
|
1439
|
+
profileImageUrl: crud.profile_image_url,
|
|
1430
1440
|
async update(update) {
|
|
1431
|
-
await
|
|
1441
|
+
await app._interface.updateServerTeamMemberProfile({
|
|
1442
|
+
teamId: crud.team_id,
|
|
1443
|
+
userId: crud.user_id,
|
|
1444
|
+
profile: {
|
|
1445
|
+
display_name: update.displayName,
|
|
1446
|
+
profile_image_url: update.profileImageUrl
|
|
1447
|
+
}
|
|
1448
|
+
});
|
|
1432
1449
|
await app._serverUserTeamProfileCache.refresh([crud.team_id, crud.user_id]);
|
|
1433
1450
|
}
|
|
1434
1451
|
};
|
|
@@ -1436,7 +1453,12 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1436
1453
|
_serverContactChannelFromCrud(userId, crud) {
|
|
1437
1454
|
const app = this;
|
|
1438
1455
|
return {
|
|
1439
|
-
|
|
1456
|
+
id: crud.id,
|
|
1457
|
+
value: crud.value,
|
|
1458
|
+
type: crud.type,
|
|
1459
|
+
isVerified: crud.is_verified,
|
|
1460
|
+
isPrimary: crud.is_primary,
|
|
1461
|
+
usedForAuth: crud.used_for_auth,
|
|
1440
1462
|
async sendVerificationEmail() {
|
|
1441
1463
|
await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, (0, import_url.constructRedirectUrl)(app.urls.emailVerification));
|
|
1442
1464
|
},
|
|
@@ -1507,6 +1529,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1507
1529
|
},
|
|
1508
1530
|
getConnectedAccount,
|
|
1509
1531
|
useConnectedAccount,
|
|
1532
|
+
selectedTeam: crud.selected_team ? app._serverTeamFromCrud(crud.selected_team) : null,
|
|
1510
1533
|
async getTeam(teamId) {
|
|
1511
1534
|
const teams = await this.listTeams();
|
|
1512
1535
|
return teams.find((t) => t.id === teamId) ?? null;
|
|
@@ -1656,11 +1679,14 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1656
1679
|
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
|
|
1657
1680
|
},
|
|
1658
1681
|
async inviteUser(options) {
|
|
1682
|
+
if (!options.callbackUrl && typeof window === "undefined") {
|
|
1683
|
+
throw new Error("Cannot invite user without a callback URL when calling the inviteUser function on the server.");
|
|
1684
|
+
}
|
|
1659
1685
|
await app._interface.sendTeamInvitation({
|
|
1660
1686
|
teamId: crud.id,
|
|
1661
1687
|
email: options.email,
|
|
1662
1688
|
session: null,
|
|
1663
|
-
callbackUrl: (0, import_url.constructRedirectUrl)(app.urls.teamInvitation)
|
|
1689
|
+
callbackUrl: options.callbackUrl ?? (0, import_url.constructRedirectUrl)(app.urls.teamInvitation)
|
|
1664
1690
|
});
|
|
1665
1691
|
}
|
|
1666
1692
|
};
|
|
@@ -1672,11 +1698,10 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1672
1698
|
}
|
|
1673
1699
|
async getUser(options) {
|
|
1674
1700
|
if (typeof options === "string") {
|
|
1675
|
-
|
|
1676
|
-
return allUsers.find((u) => u.id === options) ?? null;
|
|
1701
|
+
return await this.getServerUserById(options);
|
|
1677
1702
|
} else {
|
|
1678
1703
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1679
|
-
const session = this._getSession(options?.tokenStore);
|
|
1704
|
+
const session = await this._getSession(options?.tokenStore);
|
|
1680
1705
|
const crud = await this._currentServerUserCache.getOrWait([session], "write-only");
|
|
1681
1706
|
if (crud === null) {
|
|
1682
1707
|
switch (options?.or) {
|
|
@@ -1705,12 +1730,11 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1705
1730
|
}
|
|
1706
1731
|
useUser(options) {
|
|
1707
1732
|
if (typeof options === "string") {
|
|
1708
|
-
|
|
1709
|
-
return users.find((u) => u.id === options) ?? null;
|
|
1733
|
+
return this.useUserById(options);
|
|
1710
1734
|
} else {
|
|
1711
1735
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1712
1736
|
const router = NextNavigation.useRouter();
|
|
1713
|
-
const session = this.
|
|
1737
|
+
const session = this._useSession(options?.tokenStore);
|
|
1714
1738
|
const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
|
|
1715
1739
|
if (crud === null) {
|
|
1716
1740
|
switch (options?.or) {
|
|
@@ -1796,7 +1820,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1796
1820
|
async _refreshUsers() {
|
|
1797
1821
|
await Promise.all([
|
|
1798
1822
|
super._refreshUsers(),
|
|
1799
|
-
this._serverUsersCache.
|
|
1823
|
+
this._serverUsersCache.refreshWhere(() => true)
|
|
1800
1824
|
]);
|
|
1801
1825
|
}
|
|
1802
1826
|
};
|