@stackframe/stack 2.6.19 → 2.6.21
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-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/global-css.js +1 -1
- package/dist/esm/generated/global-css.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 +124 -101
- 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/generated/quetzal-translations.d.mts +2 -2
- package/dist/generated/quetzal-translations.d.ts +2 -2
- 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 +123 -100
- package/dist/lib/stack-app.js.map +1 -1
- package/package.json +20 -9
|
@@ -23,9 +23,9 @@ import * as NextNavigationUnscrambled from "next/navigation";
|
|
|
23
23
|
import React, { useCallback, useMemo } from "react";
|
|
24
24
|
import { constructRedirectUrl } from "../utils/url";
|
|
25
25
|
import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "./auth";
|
|
26
|
-
import {
|
|
26
|
+
import { createBrowserCookieHelper, createCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "./cookie";
|
|
27
27
|
var NextNavigation = scrambleDuringCompileTime(NextNavigationUnscrambled);
|
|
28
|
-
var clientVersion = "js @stackframe/stack@2.6.
|
|
28
|
+
var clientVersion = "js @stackframe/stack@2.6.21";
|
|
29
29
|
function getUrls(partial) {
|
|
30
30
|
const handler = partial.handler ?? "/handler";
|
|
31
31
|
const home = partial.home ?? "/";
|
|
@@ -195,7 +195,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
195
195
|
);
|
|
196
196
|
this._memoryTokenStore = createEmptyTokenStore();
|
|
197
197
|
this._requestTokenStores = /* @__PURE__ */ new WeakMap();
|
|
198
|
-
this.
|
|
198
|
+
this._storedBrowserCookieTokenStore = null;
|
|
199
199
|
/**
|
|
200
200
|
* A map from token stores and session keys to sessions.
|
|
201
201
|
*
|
|
@@ -319,38 +319,38 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
319
319
|
get _accessTokenCookieName() {
|
|
320
320
|
return `stack-access`;
|
|
321
321
|
}
|
|
322
|
-
|
|
322
|
+
_getBrowserCookieTokenStore() {
|
|
323
323
|
if (!isBrowserLike()) {
|
|
324
324
|
throw new Error("Cannot use cookie token store on the server!");
|
|
325
325
|
}
|
|
326
|
-
if (this.
|
|
326
|
+
if (this._storedBrowserCookieTokenStore === null) {
|
|
327
327
|
const getCurrentValue = (old) => {
|
|
328
328
|
const tokens = this._getTokensFromCookies({
|
|
329
|
-
refreshTokenCookie:
|
|
329
|
+
refreshTokenCookie: getCookieClient(this._refreshTokenCookieName) ?? getCookieClient("stack-refresh"),
|
|
330
330
|
// keep old cookie name for backwards-compatibility
|
|
331
|
-
accessTokenCookie:
|
|
331
|
+
accessTokenCookie: getCookieClient(this._accessTokenCookieName)
|
|
332
332
|
});
|
|
333
333
|
return {
|
|
334
334
|
refreshToken: tokens.refreshToken,
|
|
335
335
|
accessToken: tokens.accessToken ?? (old?.refreshToken === tokens.refreshToken ? old.accessToken : null)
|
|
336
336
|
};
|
|
337
337
|
};
|
|
338
|
-
this.
|
|
338
|
+
this._storedBrowserCookieTokenStore = new Store(getCurrentValue(null));
|
|
339
339
|
let hasSucceededInWriting = true;
|
|
340
340
|
setInterval(() => {
|
|
341
341
|
if (hasSucceededInWriting) {
|
|
342
|
-
const oldValue = this.
|
|
342
|
+
const oldValue = this._storedBrowserCookieTokenStore.get();
|
|
343
343
|
const currentValue = getCurrentValue(oldValue);
|
|
344
344
|
if (!deepPlainEquals(currentValue, oldValue)) {
|
|
345
|
-
this.
|
|
345
|
+
this._storedBrowserCookieTokenStore.set(currentValue);
|
|
346
346
|
}
|
|
347
347
|
}
|
|
348
348
|
}, 100);
|
|
349
|
-
this.
|
|
349
|
+
this._storedBrowserCookieTokenStore.onChange((value) => {
|
|
350
350
|
try {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
351
|
+
setOrDeleteCookieClient(this._refreshTokenCookieName, value.refreshToken, { maxAge: 60 * 60 * 24 * 365 });
|
|
352
|
+
setOrDeleteCookieClient(this._accessTokenCookieName, value.accessToken ? JSON.stringify([value.refreshToken, value.accessToken]) : null, { maxAge: 60 * 60 * 24 });
|
|
353
|
+
deleteCookieClient("stack-refresh");
|
|
354
354
|
hasSucceededInWriting = true;
|
|
355
355
|
} catch (e) {
|
|
356
356
|
if (!isBrowserLike()) {
|
|
@@ -361,30 +361,31 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
361
361
|
}
|
|
362
362
|
});
|
|
363
363
|
}
|
|
364
|
-
return this.
|
|
364
|
+
return this._storedBrowserCookieTokenStore;
|
|
365
365
|
}
|
|
366
|
-
_getOrCreateTokenStore(overrideTokenStoreInit) {
|
|
366
|
+
_getOrCreateTokenStore(cookieHelper, overrideTokenStoreInit) {
|
|
367
367
|
const tokenStoreInit = overrideTokenStoreInit === void 0 ? this._tokenStoreInit : overrideTokenStoreInit;
|
|
368
368
|
switch (tokenStoreInit) {
|
|
369
369
|
case "cookie": {
|
|
370
|
-
return this.
|
|
370
|
+
return this._getBrowserCookieTokenStore();
|
|
371
371
|
}
|
|
372
372
|
case "nextjs-cookie": {
|
|
373
373
|
if (isBrowserLike()) {
|
|
374
|
-
return this.
|
|
374
|
+
return this._getBrowserCookieTokenStore();
|
|
375
375
|
} else {
|
|
376
376
|
const tokens = this._getTokensFromCookies({
|
|
377
|
-
refreshTokenCookie:
|
|
377
|
+
refreshTokenCookie: cookieHelper.get(this._refreshTokenCookieName) ?? cookieHelper.get("stack-refresh"),
|
|
378
378
|
// keep old cookie name for backwards-compatibility
|
|
379
|
-
accessTokenCookie:
|
|
379
|
+
accessTokenCookie: cookieHelper.get(this._accessTokenCookieName)
|
|
380
380
|
});
|
|
381
381
|
const store = new Store(tokens);
|
|
382
382
|
store.onChange((value) => {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
383
|
+
runAsynchronously(async () => {
|
|
384
|
+
await Promise.all([
|
|
385
|
+
setOrDeleteCookie(this._refreshTokenCookieName, value.refreshToken, { maxAge: 60 * 60 * 24 * 365, noOpIfServerComponent: true }),
|
|
386
|
+
setOrDeleteCookie(this._accessTokenCookieName, value.accessToken ? JSON.stringify([value.refreshToken, value.accessToken]) : null, { maxAge: 60 * 60 * 24, noOpIfServerComponent: true })
|
|
387
|
+
]);
|
|
388
|
+
});
|
|
388
389
|
});
|
|
389
390
|
return store;
|
|
390
391
|
}
|
|
@@ -407,7 +408,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
407
408
|
} catch (e) {
|
|
408
409
|
throw new Error(`Invalid x-stack-auth header: ${stackAuthHeader}`, { cause: e });
|
|
409
410
|
}
|
|
410
|
-
return this._getOrCreateTokenStore({
|
|
411
|
+
return this._getOrCreateTokenStore(cookieHelper, {
|
|
411
412
|
accessToken: parsed2.accessToken ?? null,
|
|
412
413
|
refreshToken: parsed2.refreshToken ?? null
|
|
413
414
|
});
|
|
@@ -431,6 +432,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
431
432
|
}
|
|
432
433
|
}
|
|
433
434
|
}
|
|
435
|
+
_useTokenStore(overrideTokenStoreInit) {
|
|
436
|
+
suspendIfSsr();
|
|
437
|
+
const cookieHelper = createBrowserCookieHelper();
|
|
438
|
+
const tokenStore = this._getOrCreateTokenStore(cookieHelper, overrideTokenStoreInit);
|
|
439
|
+
return tokenStore;
|
|
440
|
+
}
|
|
434
441
|
_getSessionFromTokenStore(tokenStore) {
|
|
435
442
|
const tokenObj = tokenStore.get();
|
|
436
443
|
const sessionKey = InternalSession.calculateSessionKey(tokenObj);
|
|
@@ -458,12 +465,12 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
458
465
|
sessionsBySessionKey.set(sessionKey, session);
|
|
459
466
|
return session;
|
|
460
467
|
}
|
|
461
|
-
_getSession(overrideTokenStoreInit) {
|
|
462
|
-
const tokenStore = this._getOrCreateTokenStore(overrideTokenStoreInit);
|
|
468
|
+
async _getSession(overrideTokenStoreInit) {
|
|
469
|
+
const tokenStore = this._getOrCreateTokenStore(await createCookieHelper(), overrideTokenStoreInit);
|
|
463
470
|
return this._getSessionFromTokenStore(tokenStore);
|
|
464
471
|
}
|
|
465
472
|
_useSession(overrideTokenStoreInit) {
|
|
466
|
-
const tokenStore = this.
|
|
473
|
+
const tokenStore = this._useTokenStore(overrideTokenStoreInit);
|
|
467
474
|
const subscribe = useCallback((cb) => {
|
|
468
475
|
const { unsubscribe } = tokenStore.onChange(() => {
|
|
469
476
|
cb();
|
|
@@ -477,7 +484,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
477
484
|
if (!("accessToken" in tokens) || !("refreshToken" in tokens)) {
|
|
478
485
|
throw new StackAssertionError("Invalid tokens object; can't sign in with this", { tokens });
|
|
479
486
|
}
|
|
480
|
-
const tokenStore = this._getOrCreateTokenStore();
|
|
487
|
+
const tokenStore = this._getOrCreateTokenStore(await createCookieHelper());
|
|
481
488
|
tokenStore.set(tokens);
|
|
482
489
|
}
|
|
483
490
|
_hasPersistentTokenStore(overrideTokenStoreInit) {
|
|
@@ -527,7 +534,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
527
534
|
}
|
|
528
535
|
};
|
|
529
536
|
}
|
|
530
|
-
_clientTeamFromCrud(crud) {
|
|
537
|
+
_clientTeamFromCrud(crud, session) {
|
|
531
538
|
const app = this;
|
|
532
539
|
return {
|
|
533
540
|
id: crud.id,
|
|
@@ -536,28 +543,31 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
536
543
|
clientMetadata: crud.client_metadata,
|
|
537
544
|
clientReadOnlyMetadata: crud.client_read_only_metadata,
|
|
538
545
|
async inviteUser(options) {
|
|
546
|
+
if (!options.callbackUrl && typeof window === "undefined") {
|
|
547
|
+
throw new Error("Cannot invite user without a callback URL from the server. Make sure you pass the `callbackUrl` option: `inviteUser({ email, callbackUrl: ... })`");
|
|
548
|
+
}
|
|
539
549
|
await app._interface.sendTeamInvitation({
|
|
540
550
|
teamId: crud.id,
|
|
541
551
|
email: options.email,
|
|
542
|
-
session
|
|
543
|
-
callbackUrl: constructRedirectUrl(app.urls.teamInvitation)
|
|
552
|
+
session,
|
|
553
|
+
callbackUrl: options.callbackUrl ?? constructRedirectUrl(app.urls.teamInvitation)
|
|
544
554
|
});
|
|
545
555
|
},
|
|
546
556
|
async listUsers() {
|
|
547
|
-
const result = await app._teamMemberProfilesCache.getOrWait([
|
|
557
|
+
const result = await app._teamMemberProfilesCache.getOrWait([session, crud.id], "write-only");
|
|
548
558
|
return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
|
|
549
559
|
},
|
|
550
560
|
useUsers() {
|
|
551
|
-
const result = useAsyncCache(app._teamMemberProfilesCache, [
|
|
561
|
+
const result = useAsyncCache(app._teamMemberProfilesCache, [session, crud.id], "team.useUsers()");
|
|
552
562
|
return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
|
|
553
563
|
},
|
|
554
564
|
async update(data) {
|
|
555
|
-
await app._interface.updateTeam({ data: teamUpdateOptionsToCrud(data), teamId: crud.id },
|
|
556
|
-
await app._currentUserTeamsCache.refresh([
|
|
565
|
+
await app._interface.updateTeam({ data: teamUpdateOptionsToCrud(data), teamId: crud.id }, session);
|
|
566
|
+
await app._currentUserTeamsCache.refresh([session]);
|
|
557
567
|
}
|
|
558
568
|
};
|
|
559
569
|
}
|
|
560
|
-
_clientContactChannelFromCrud(crud) {
|
|
570
|
+
_clientContactChannelFromCrud(crud, session) {
|
|
561
571
|
const app = this;
|
|
562
572
|
return {
|
|
563
573
|
id: crud.id,
|
|
@@ -567,15 +577,15 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
567
577
|
isPrimary: crud.is_primary,
|
|
568
578
|
usedForAuth: crud.used_for_auth,
|
|
569
579
|
async sendVerificationEmail() {
|
|
570
|
-
await app._interface.sendCurrentUserContactChannelVerificationEmail(crud.id, constructRedirectUrl(app.urls.emailVerification),
|
|
580
|
+
await app._interface.sendCurrentUserContactChannelVerificationEmail(crud.id, constructRedirectUrl(app.urls.emailVerification), session);
|
|
571
581
|
},
|
|
572
582
|
async update(data) {
|
|
573
|
-
await app._interface.updateClientContactChannel(crud.id, contactChannelUpdateOptionsToCrud(data),
|
|
574
|
-
await app._clientContactChannelsCache.refresh([
|
|
583
|
+
await app._interface.updateClientContactChannel(crud.id, contactChannelUpdateOptionsToCrud(data), session);
|
|
584
|
+
await app._clientContactChannelsCache.refresh([session]);
|
|
575
585
|
},
|
|
576
586
|
async delete() {
|
|
577
|
-
await app._interface.deleteClientContactChannel(crud.id,
|
|
578
|
-
await app._clientContactChannelsCache.refresh([
|
|
587
|
+
await app._interface.deleteClientContactChannel(crud.id, session);
|
|
588
|
+
await app._clientContactChannelsCache.refresh([session]);
|
|
579
589
|
}
|
|
580
590
|
};
|
|
581
591
|
}
|
|
@@ -631,10 +641,25 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
631
641
|
}
|
|
632
642
|
};
|
|
633
643
|
}
|
|
644
|
+
_editableTeamProfileFromCrud(crud, session) {
|
|
645
|
+
const app = this;
|
|
646
|
+
return {
|
|
647
|
+
displayName: crud.display_name,
|
|
648
|
+
profileImageUrl: crud.profile_image_url,
|
|
649
|
+
async update(update) {
|
|
650
|
+
await app._interface.updateTeamMemberProfile({
|
|
651
|
+
teamId: crud.team_id,
|
|
652
|
+
userId: crud.user_id,
|
|
653
|
+
profile: {
|
|
654
|
+
display_name: update.displayName,
|
|
655
|
+
profile_image_url: update.profileImageUrl
|
|
656
|
+
}
|
|
657
|
+
}, session);
|
|
658
|
+
await app._currentUserTeamProfileCache.refresh([session, crud.team_id]);
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
}
|
|
634
662
|
_createBaseUser(crud) {
|
|
635
|
-
if (!crud) {
|
|
636
|
-
throw new StackAssertionError("User not found");
|
|
637
|
-
}
|
|
638
663
|
return {
|
|
639
664
|
id: crud.id,
|
|
640
665
|
displayName: crud.display_name,
|
|
@@ -649,32 +674,13 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
649
674
|
otpAuthEnabled: crud.otp_auth_enabled,
|
|
650
675
|
oauthProviders: crud.oauth_providers,
|
|
651
676
|
passkeyAuthEnabled: crud.passkey_auth_enabled,
|
|
652
|
-
selectedTeam: crud.selected_team && this._clientTeamFromCrud(crud.selected_team),
|
|
653
677
|
isMultiFactorRequired: crud.requires_totp_mfa,
|
|
654
678
|
toClientJson() {
|
|
655
679
|
return crud;
|
|
656
680
|
}
|
|
657
681
|
};
|
|
658
682
|
}
|
|
659
|
-
|
|
660
|
-
const app = this;
|
|
661
|
-
return {
|
|
662
|
-
displayName: crud.display_name,
|
|
663
|
-
profileImageUrl: crud.profile_image_url,
|
|
664
|
-
async update(update) {
|
|
665
|
-
await app._interface.updateTeamMemberProfile({
|
|
666
|
-
teamId: crud.team_id,
|
|
667
|
-
userId: crud.user_id,
|
|
668
|
-
profile: {
|
|
669
|
-
display_name: update.displayName,
|
|
670
|
-
profile_image_url: update.profileImageUrl
|
|
671
|
-
}
|
|
672
|
-
}, app._getSession());
|
|
673
|
-
await app._currentUserTeamProfileCache.refresh([app._getSession(), crud.team_id]);
|
|
674
|
-
}
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
_createUserExtra(crud, session) {
|
|
683
|
+
_createUserExtraFromCurrent(crud, session) {
|
|
678
684
|
const app = this;
|
|
679
685
|
async function getConnectedAccount(id, options) {
|
|
680
686
|
const scopeString = options?.scopes?.join(" ");
|
|
@@ -708,11 +714,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
708
714
|
},
|
|
709
715
|
async listTeams() {
|
|
710
716
|
const teams = await app._currentUserTeamsCache.getOrWait([session], "write-only");
|
|
711
|
-
return teams.map((crud2) => app._clientTeamFromCrud(crud2));
|
|
717
|
+
return teams.map((crud2) => app._clientTeamFromCrud(crud2, session));
|
|
712
718
|
},
|
|
713
719
|
useTeams() {
|
|
714
720
|
const teams = useAsyncCache(app._currentUserTeamsCache, [session], "user.useTeams()");
|
|
715
|
-
return useMemo(() => teams.map((crud2) => app._clientTeamFromCrud(crud2)), [teams]);
|
|
721
|
+
return useMemo(() => teams.map((crud2) => app._clientTeamFromCrud(crud2, session)), [teams]);
|
|
716
722
|
},
|
|
717
723
|
async createTeam(data) {
|
|
718
724
|
const crud2 = await app._interface.createClientTeam({
|
|
@@ -720,7 +726,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
720
726
|
creator_user_id: "me"
|
|
721
727
|
}, session);
|
|
722
728
|
await app._currentUserTeamsCache.refresh([session]);
|
|
723
|
-
return app._clientTeamFromCrud(crud2);
|
|
729
|
+
return app._clientTeamFromCrud(crud2, session);
|
|
724
730
|
},
|
|
725
731
|
async leaveTeam(team) {
|
|
726
732
|
await app._interface.leaveTeam(team.id, session);
|
|
@@ -750,7 +756,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
750
756
|
return await app._updateClientUser(update, session);
|
|
751
757
|
},
|
|
752
758
|
async sendVerificationEmail() {
|
|
753
|
-
if (!crud
|
|
759
|
+
if (!crud.primary_email) {
|
|
754
760
|
throw new StackAssertionError("User does not have a primary email");
|
|
755
761
|
}
|
|
756
762
|
return await app._sendVerificationEmail(crud.primary_email, session);
|
|
@@ -765,13 +771,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
765
771
|
await app._currentUserCache.refresh([session]);
|
|
766
772
|
return result;
|
|
767
773
|
},
|
|
774
|
+
selectedTeam: crud.selected_team && this._clientTeamFromCrud(crud.selected_team, session),
|
|
768
775
|
async getTeamProfile(team) {
|
|
769
776
|
const result = await app._currentUserTeamProfileCache.getOrWait([session, team.id], "write-only");
|
|
770
|
-
return app._editableTeamProfileFromCrud(result);
|
|
777
|
+
return app._editableTeamProfileFromCrud(result, session);
|
|
771
778
|
},
|
|
772
779
|
useTeamProfile(team) {
|
|
773
780
|
const result = useAsyncCache(app._currentUserTeamProfileCache, [session, team.id], "user.useTeamProfile()");
|
|
774
|
-
return app._editableTeamProfileFromCrud(result);
|
|
781
|
+
return app._editableTeamProfileFromCrud(result, session);
|
|
775
782
|
},
|
|
776
783
|
async delete() {
|
|
777
784
|
await app._interface.deleteCurrentUser(session);
|
|
@@ -779,16 +786,16 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
779
786
|
},
|
|
780
787
|
async listContactChannels() {
|
|
781
788
|
const result = await app._clientContactChannelsCache.getOrWait([session], "write-only");
|
|
782
|
-
return result.map((crud2) => app._clientContactChannelFromCrud(crud2));
|
|
789
|
+
return result.map((crud2) => app._clientContactChannelFromCrud(crud2, session));
|
|
783
790
|
},
|
|
784
791
|
useContactChannels() {
|
|
785
792
|
const result = useAsyncCache(app._clientContactChannelsCache, [session], "user.useContactChannels()");
|
|
786
|
-
return result.map((crud2) => app._clientContactChannelFromCrud(crud2));
|
|
793
|
+
return result.map((crud2) => app._clientContactChannelFromCrud(crud2, session));
|
|
787
794
|
},
|
|
788
795
|
async createContactChannel(data) {
|
|
789
796
|
const crud2 = await app._interface.createClientContactChannel(contactChannelCreateOptionsToCrud("me", data), session);
|
|
790
797
|
await app._clientContactChannelsCache.refresh([session]);
|
|
791
|
-
return app._clientContactChannelFromCrud(crud2);
|
|
798
|
+
return app._clientContactChannelFromCrud(crud2, session);
|
|
792
799
|
}
|
|
793
800
|
};
|
|
794
801
|
}
|
|
@@ -811,7 +818,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
811
818
|
const currentUser = {
|
|
812
819
|
...this._createBaseUser(crud),
|
|
813
820
|
...this._createAuth(session),
|
|
814
|
-
...this.
|
|
821
|
+
...this._createUserExtraFromCurrent(crud, session),
|
|
815
822
|
...this._isInternalProject() ? this._createInternalUserExtra(session) : {}
|
|
816
823
|
};
|
|
817
824
|
Object.freeze(currentUser);
|
|
@@ -943,14 +950,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
943
950
|
return await this._interface.acceptTeamInvitation({
|
|
944
951
|
type: "check",
|
|
945
952
|
code,
|
|
946
|
-
session: this._getSession()
|
|
953
|
+
session: await this._getSession()
|
|
947
954
|
});
|
|
948
955
|
}
|
|
949
956
|
async acceptTeamInvitation(code) {
|
|
950
957
|
const result = await this._interface.acceptTeamInvitation({
|
|
951
958
|
type: "use",
|
|
952
959
|
code,
|
|
953
|
-
session: this._getSession()
|
|
960
|
+
session: await this._getSession()
|
|
954
961
|
});
|
|
955
962
|
if (result.status === "ok") {
|
|
956
963
|
return Result.ok(void 0);
|
|
@@ -962,7 +969,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
962
969
|
const result = await this._interface.acceptTeamInvitation({
|
|
963
970
|
type: "details",
|
|
964
971
|
code,
|
|
965
|
-
session: this._getSession()
|
|
972
|
+
session: await this._getSession()
|
|
966
973
|
});
|
|
967
974
|
if (result.status === "ok") {
|
|
968
975
|
return Result.ok({ teamDisplayName: result.data.team_display_name });
|
|
@@ -972,13 +979,13 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
972
979
|
}
|
|
973
980
|
async verifyEmail(code) {
|
|
974
981
|
const result = await this._interface.verifyEmail(code);
|
|
975
|
-
await this._currentUserCache.refresh([this._getSession()]);
|
|
976
|
-
await this._clientContactChannelsCache.refresh([this._getSession()]);
|
|
982
|
+
await this._currentUserCache.refresh([await this._getSession()]);
|
|
983
|
+
await this._clientContactChannelsCache.refresh([await this._getSession()]);
|
|
977
984
|
return result;
|
|
978
985
|
}
|
|
979
986
|
async getUser(options) {
|
|
980
987
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
981
|
-
const session = this._getSession(options?.tokenStore);
|
|
988
|
+
const session = await this._getSession(options?.tokenStore);
|
|
982
989
|
const crud = await this._currentUserCache.getOrWait([session], "write-only");
|
|
983
990
|
if (crud === null) {
|
|
984
991
|
switch (options?.or) {
|
|
@@ -1061,14 +1068,14 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1061
1068
|
return await callback();
|
|
1062
1069
|
} catch (e) {
|
|
1063
1070
|
if (e instanceof KnownErrors.MultiFactorAuthenticationRequired) {
|
|
1064
|
-
return Result.ok(await this._experimentalMfa(e, this._getSession()));
|
|
1071
|
+
return Result.ok(await this._experimentalMfa(e, await this._getSession()));
|
|
1065
1072
|
}
|
|
1066
1073
|
throw e;
|
|
1067
1074
|
}
|
|
1068
1075
|
}
|
|
1069
1076
|
async signInWithCredential(options) {
|
|
1070
1077
|
this._ensurePersistentTokenStore();
|
|
1071
|
-
const session = this._getSession();
|
|
1078
|
+
const session = await this._getSession();
|
|
1072
1079
|
let result;
|
|
1073
1080
|
try {
|
|
1074
1081
|
result = await this._catchMfaRequiredError(async () => {
|
|
@@ -1092,7 +1099,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1092
1099
|
}
|
|
1093
1100
|
async signUpWithCredential(options) {
|
|
1094
1101
|
this._ensurePersistentTokenStore();
|
|
1095
|
-
const session = this._getSession();
|
|
1102
|
+
const session = await this._getSession();
|
|
1096
1103
|
const emailVerificationRedirectUrl = constructRedirectUrl(this.urls.emailVerification);
|
|
1097
1104
|
const result = await this._interface.signUpWithCredential(
|
|
1098
1105
|
options.email,
|
|
@@ -1137,10 +1144,11 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1137
1144
|
}
|
|
1138
1145
|
async signInWithPasskey() {
|
|
1139
1146
|
this._ensurePersistentTokenStore();
|
|
1147
|
+
const session = await this._getSession();
|
|
1140
1148
|
let result;
|
|
1141
1149
|
try {
|
|
1142
1150
|
result = await this._catchMfaRequiredError(async () => {
|
|
1143
|
-
const initiationResult = await this._interface.initiatePasskeyAuthentication({},
|
|
1151
|
+
const initiationResult = await this._interface.initiatePasskeyAuthentication({}, session);
|
|
1144
1152
|
if (initiationResult.status !== "ok") {
|
|
1145
1153
|
return Result.error(new KnownErrors.PasskeyAuthenticationFailed("Failed to get initiation options for passkey authentication"));
|
|
1146
1154
|
}
|
|
@@ -1295,7 +1303,9 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1295
1303
|
};
|
|
1296
1304
|
},
|
|
1297
1305
|
setCurrentUser: (userJsonPromise) => {
|
|
1298
|
-
runAsynchronously(
|
|
1306
|
+
runAsynchronously(async () => {
|
|
1307
|
+
await this._currentUserCache.forceSetCachedValueAsync([await this._getSession()], userJsonPromise);
|
|
1308
|
+
});
|
|
1299
1309
|
}
|
|
1300
1310
|
};
|
|
1301
1311
|
}
|
|
@@ -1385,11 +1395,18 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1385
1395
|
}
|
|
1386
1396
|
_serverEditableTeamProfileFromCrud(crud) {
|
|
1387
1397
|
const app = this;
|
|
1388
|
-
const clientProfile = this._editableTeamProfileFromCrud(crud);
|
|
1389
1398
|
return {
|
|
1390
|
-
|
|
1399
|
+
displayName: crud.display_name,
|
|
1400
|
+
profileImageUrl: crud.profile_image_url,
|
|
1391
1401
|
async update(update) {
|
|
1392
|
-
await
|
|
1402
|
+
await app._interface.updateServerTeamMemberProfile({
|
|
1403
|
+
teamId: crud.team_id,
|
|
1404
|
+
userId: crud.user_id,
|
|
1405
|
+
profile: {
|
|
1406
|
+
display_name: update.displayName,
|
|
1407
|
+
profile_image_url: update.profileImageUrl
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1393
1410
|
await app._serverUserTeamProfileCache.refresh([crud.team_id, crud.user_id]);
|
|
1394
1411
|
}
|
|
1395
1412
|
};
|
|
@@ -1397,7 +1414,12 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1397
1414
|
_serverContactChannelFromCrud(userId, crud) {
|
|
1398
1415
|
const app = this;
|
|
1399
1416
|
return {
|
|
1400
|
-
|
|
1417
|
+
id: crud.id,
|
|
1418
|
+
value: crud.value,
|
|
1419
|
+
type: crud.type,
|
|
1420
|
+
isVerified: crud.is_verified,
|
|
1421
|
+
isPrimary: crud.is_primary,
|
|
1422
|
+
usedForAuth: crud.used_for_auth,
|
|
1401
1423
|
async sendVerificationEmail() {
|
|
1402
1424
|
await app._interface.sendServerContactChannelVerificationEmail(userId, crud.id, constructRedirectUrl(app.urls.emailVerification));
|
|
1403
1425
|
},
|
|
@@ -1468,6 +1490,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1468
1490
|
},
|
|
1469
1491
|
getConnectedAccount,
|
|
1470
1492
|
useConnectedAccount,
|
|
1493
|
+
selectedTeam: crud.selected_team ? app._serverTeamFromCrud(crud.selected_team) : null,
|
|
1471
1494
|
async getTeam(teamId) {
|
|
1472
1495
|
const teams = await this.listTeams();
|
|
1473
1496
|
return teams.find((t) => t.id === teamId) ?? null;
|
|
@@ -1617,11 +1640,13 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1617
1640
|
await app._serverTeamMemberProfilesCache.refresh([crud.id]);
|
|
1618
1641
|
},
|
|
1619
1642
|
async inviteUser(options) {
|
|
1620
|
-
|
|
1643
|
+
if (!options.callbackUrl && typeof window === "undefined") {
|
|
1644
|
+
throw new Error("Cannot invite user without a callback URL from the server. Make sure you pass the `callbackUrl` option: `inviteUser({ email, callbackUrl: ... })`");
|
|
1645
|
+
}
|
|
1646
|
+
await app._interface.sendServerTeamInvitation({
|
|
1621
1647
|
teamId: crud.id,
|
|
1622
1648
|
email: options.email,
|
|
1623
|
-
|
|
1624
|
-
callbackUrl: constructRedirectUrl(app.urls.teamInvitation)
|
|
1649
|
+
callbackUrl: options.callbackUrl ?? constructRedirectUrl(app.urls.teamInvitation)
|
|
1625
1650
|
});
|
|
1626
1651
|
}
|
|
1627
1652
|
};
|
|
@@ -1633,11 +1658,10 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1633
1658
|
}
|
|
1634
1659
|
async getUser(options) {
|
|
1635
1660
|
if (typeof options === "string") {
|
|
1636
|
-
|
|
1637
|
-
return allUsers.find((u) => u.id === options) ?? null;
|
|
1661
|
+
return await this.getServerUserById(options);
|
|
1638
1662
|
} else {
|
|
1639
1663
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1640
|
-
const session = this._getSession(options?.tokenStore);
|
|
1664
|
+
const session = await this._getSession(options?.tokenStore);
|
|
1641
1665
|
const crud = await this._currentServerUserCache.getOrWait([session], "write-only");
|
|
1642
1666
|
if (crud === null) {
|
|
1643
1667
|
switch (options?.or) {
|
|
@@ -1666,12 +1690,11 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1666
1690
|
}
|
|
1667
1691
|
useUser(options) {
|
|
1668
1692
|
if (typeof options === "string") {
|
|
1669
|
-
|
|
1670
|
-
return users.find((u) => u.id === options) ?? null;
|
|
1693
|
+
return this.useUserById(options);
|
|
1671
1694
|
} else {
|
|
1672
1695
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1673
1696
|
const router = NextNavigation.useRouter();
|
|
1674
|
-
const session = this.
|
|
1697
|
+
const session = this._useSession(options?.tokenStore);
|
|
1675
1698
|
const crud = useAsyncCache(this._currentServerUserCache, [session], "useUser()");
|
|
1676
1699
|
if (crud === null) {
|
|
1677
1700
|
switch (options?.or) {
|
|
@@ -1757,7 +1780,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1757
1780
|
async _refreshUsers() {
|
|
1758
1781
|
await Promise.all([
|
|
1759
1782
|
super._refreshUsers(),
|
|
1760
|
-
this._serverUsersCache.
|
|
1783
|
+
this._serverUsersCache.refreshWhere(() => true)
|
|
1761
1784
|
]);
|
|
1762
1785
|
}
|
|
1763
1786
|
};
|