@stackframe/stack 2.6.25 → 2.6.26
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/esm/lib/stack-app.js +41 -33
- package/dist/esm/lib/stack-app.js.map +1 -1
- package/dist/generated/quetzal-translations.d.mts +2 -2
- package/dist/generated/quetzal-translations.d.ts +2 -2
- package/dist/lib/stack-app.js +40 -32
- package/dist/lib/stack-app.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -8,7 +8,7 @@ import { encodeBase64 } from "@stackframe/stack-shared/dist/utils/bytes";
|
|
|
8
8
|
import { AsyncCache } from "@stackframe/stack-shared/dist/utils/caches";
|
|
9
9
|
import { scrambleDuringCompileTime } from "@stackframe/stack-shared/dist/utils/compile-time";
|
|
10
10
|
import { isBrowserLike } from "@stackframe/stack-shared/dist/utils/env";
|
|
11
|
-
import { StackAssertionError, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
|
|
11
|
+
import { StackAssertionError, concatStacktraces, throwErr } from "@stackframe/stack-shared/dist/utils/errors";
|
|
12
12
|
import { DependenciesMap } from "@stackframe/stack-shared/dist/utils/maps";
|
|
13
13
|
import { deepPlainEquals, filterUndefined, omit } from "@stackframe/stack-shared/dist/utils/objects";
|
|
14
14
|
import { neverResolve, runAsynchronously, wait } from "@stackframe/stack-shared/dist/utils/promises";
|
|
@@ -25,7 +25,7 @@ import { constructRedirectUrl } from "../utils/url";
|
|
|
25
25
|
import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "./auth";
|
|
26
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.26";
|
|
29
29
|
function getUrls(partial) {
|
|
30
30
|
const handler = partial.handler ?? "/handler";
|
|
31
31
|
const home = partial.home ?? "/";
|
|
@@ -106,19 +106,27 @@ function useAsyncCache(cache, dependencies, caller) {
|
|
|
106
106
|
getSnapshot,
|
|
107
107
|
() => throwErr(new Error("getServerSnapshot should never be called in useAsyncCache because we restrict to CSR earlier"))
|
|
108
108
|
);
|
|
109
|
-
|
|
109
|
+
const result = React.use(promise);
|
|
110
|
+
if (result.status === "error") {
|
|
111
|
+
const error = result.error;
|
|
112
|
+
if (error instanceof Error) {
|
|
113
|
+
concatStacktraces(error, new Error());
|
|
114
|
+
}
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
return result.data;
|
|
110
118
|
}
|
|
111
119
|
var stackAppInternalsSymbol = Symbol.for("StackAppInternals");
|
|
112
120
|
var allClientApps = /* @__PURE__ */ new Map();
|
|
113
121
|
var createCache = (fetcher) => {
|
|
114
122
|
return new AsyncCache(
|
|
115
|
-
async (dependencies) => await fetcher(dependencies),
|
|
123
|
+
async (dependencies) => await Result.fromThrowingAsync(async () => await fetcher(dependencies)),
|
|
116
124
|
{}
|
|
117
125
|
);
|
|
118
126
|
};
|
|
119
127
|
var createCacheBySession = (fetcher) => {
|
|
120
128
|
return new AsyncCache(
|
|
121
|
-
async ([session, ...extraDependencies]) => await fetcher(session, extraDependencies),
|
|
129
|
+
async ([session, ...extraDependencies]) => await Result.fromThrowingAsync(async () => await fetcher(session, extraDependencies)),
|
|
122
130
|
{
|
|
123
131
|
onSubscribe: ([session], refresh) => {
|
|
124
132
|
const handler = session.onInvalidate(() => refresh());
|
|
@@ -168,8 +176,8 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
168
176
|
this._currentUserOAuthConnectionCache = createCacheBySession(
|
|
169
177
|
async (session, [providerId, scope, redirect]) => {
|
|
170
178
|
return await this._getUserOAuthConnectionCacheFn({
|
|
171
|
-
getUser: async () => await this._currentUserCache.getOrWait([session], "write-only"),
|
|
172
|
-
getOrWaitOAuthToken: async () => await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, providerId, scope || ""], "write-only"),
|
|
179
|
+
getUser: async () => Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only")),
|
|
180
|
+
getOrWaitOAuthToken: async () => Result.orThrow(await this._currentUserOAuthConnectionAccessTokensCache.getOrWait([session, providerId, scope || ""], "write-only")),
|
|
173
181
|
useOAuthToken: () => useAsyncCache(this._currentUserOAuthConnectionAccessTokensCache, [session, providerId, scope || ""], "useOAuthToken"),
|
|
174
182
|
providerId,
|
|
175
183
|
scope,
|
|
@@ -554,7 +562,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
554
562
|
});
|
|
555
563
|
},
|
|
556
564
|
async listUsers() {
|
|
557
|
-
const result = await app._teamMemberProfilesCache.getOrWait([session, crud.id], "write-only");
|
|
565
|
+
const result = Result.orThrow(await app._teamMemberProfilesCache.getOrWait([session, crud.id], "write-only"));
|
|
558
566
|
return result.map((crud2) => app._clientTeamUserFromCrud(crud2));
|
|
559
567
|
},
|
|
560
568
|
useUsers() {
|
|
@@ -684,7 +692,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
684
692
|
const app = this;
|
|
685
693
|
async function getConnectedAccount(id, options) {
|
|
686
694
|
const scopeString = options?.scopes?.join(" ");
|
|
687
|
-
return await app._currentUserOAuthConnectionCache.getOrWait([session, id, scopeString || "", options?.or === "redirect"], "write-only");
|
|
695
|
+
return Result.orThrow(await app._currentUserOAuthConnectionCache.getOrWait([session, id, scopeString || "", options?.or === "redirect"], "write-only"));
|
|
688
696
|
}
|
|
689
697
|
function useConnectedAccount(id, options) {
|
|
690
698
|
const scopeString = options?.scopes?.join(" ");
|
|
@@ -713,7 +721,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
713
721
|
}, [teams, teamId]);
|
|
714
722
|
},
|
|
715
723
|
async listTeams() {
|
|
716
|
-
const teams = await app._currentUserTeamsCache.getOrWait([session], "write-only");
|
|
724
|
+
const teams = Result.orThrow(await app._currentUserTeamsCache.getOrWait([session], "write-only"));
|
|
717
725
|
return teams.map((crud2) => app._clientTeamFromCrud(crud2, session));
|
|
718
726
|
},
|
|
719
727
|
useTeams() {
|
|
@@ -733,7 +741,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
733
741
|
},
|
|
734
742
|
async listPermissions(scope, options) {
|
|
735
743
|
const recursive = options?.recursive ?? true;
|
|
736
|
-
const permissions = await app._currentUserPermissionsCache.getOrWait([session, scope.id, recursive], "write-only");
|
|
744
|
+
const permissions = Result.orThrow(await app._currentUserPermissionsCache.getOrWait([session, scope.id, recursive], "write-only"));
|
|
737
745
|
return permissions.map((crud2) => app._clientTeamPermissionFromCrud(crud2));
|
|
738
746
|
},
|
|
739
747
|
usePermissions(scope, options) {
|
|
@@ -773,7 +781,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
773
781
|
},
|
|
774
782
|
selectedTeam: crud.selected_team && this._clientTeamFromCrud(crud.selected_team, session),
|
|
775
783
|
async getTeamProfile(team) {
|
|
776
|
-
const result = await app._currentUserTeamProfileCache.getOrWait([session, team.id], "write-only");
|
|
784
|
+
const result = Result.orThrow(await app._currentUserTeamProfileCache.getOrWait([session, team.id], "write-only"));
|
|
777
785
|
return app._editableTeamProfileFromCrud(result, session);
|
|
778
786
|
},
|
|
779
787
|
useTeamProfile(team) {
|
|
@@ -785,7 +793,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
785
793
|
session.markInvalid();
|
|
786
794
|
},
|
|
787
795
|
async listContactChannels() {
|
|
788
|
-
const result = await app._clientContactChannelsCache.getOrWait([session], "write-only");
|
|
796
|
+
const result = Result.orThrow(await app._clientContactChannelsCache.getOrWait([session], "write-only"));
|
|
789
797
|
return result.map((crud2) => app._clientContactChannelFromCrud(crud2, session));
|
|
790
798
|
},
|
|
791
799
|
useContactChannels() {
|
|
@@ -986,7 +994,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
986
994
|
async getUser(options) {
|
|
987
995
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
988
996
|
const session = await this._getSession(options?.tokenStore);
|
|
989
|
-
const crud = await this._currentUserCache.getOrWait([session], "write-only");
|
|
997
|
+
const crud = Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
|
|
990
998
|
if (crud === null) {
|
|
991
999
|
switch (options?.or) {
|
|
992
1000
|
case "redirect": {
|
|
@@ -1218,7 +1226,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1218
1226
|
}
|
|
1219
1227
|
}
|
|
1220
1228
|
async getProject() {
|
|
1221
|
-
const crud = await this._currentProjectCache.getOrWait([], "write-only");
|
|
1229
|
+
const crud = Result.orThrow(await this._currentProjectCache.getOrWait([], "write-only"));
|
|
1222
1230
|
return this._clientProjectFromCrud(crud);
|
|
1223
1231
|
}
|
|
1224
1232
|
useProject() {
|
|
@@ -1227,7 +1235,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1227
1235
|
}
|
|
1228
1236
|
async _listOwnedProjects(session) {
|
|
1229
1237
|
this._ensureInternalProject();
|
|
1230
|
-
const crud = await this._ownedProjectsCache.getOrWait([session], "write-only");
|
|
1238
|
+
const crud = Result.orThrow(await this._ownedProjectsCache.getOrWait([session], "write-only"));
|
|
1231
1239
|
return crud.map((j) => this._getOwnedAdminApp(j.id, session)._adminOwnedProjectFromCrud(
|
|
1232
1240
|
j,
|
|
1233
1241
|
() => this._refreshOwnedProjects(session)
|
|
@@ -1304,7 +1312,7 @@ var _StackClientAppImpl = class __StackClientAppImpl {
|
|
|
1304
1312
|
},
|
|
1305
1313
|
setCurrentUser: (userJsonPromise) => {
|
|
1306
1314
|
runAsynchronously(async () => {
|
|
1307
|
-
await this._currentUserCache.forceSetCachedValueAsync([await this._getSession()], userJsonPromise);
|
|
1315
|
+
await this._currentUserCache.forceSetCachedValueAsync([await this._getSession()], Result.fromPromise(userJsonPromise));
|
|
1308
1316
|
});
|
|
1309
1317
|
}
|
|
1310
1318
|
};
|
|
@@ -1362,8 +1370,8 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1362
1370
|
this._serverUserOAuthConnectionCache = createCache(
|
|
1363
1371
|
async ([userId, providerId, scope, redirect]) => {
|
|
1364
1372
|
return await this._getUserOAuthConnectionCacheFn({
|
|
1365
|
-
getUser: async () => await this._serverUserCache.getOrWait([userId], "write-only"),
|
|
1366
|
-
getOrWaitOAuthToken: async () => await this._serverUserOAuthConnectionAccessTokensCache.getOrWait([userId, providerId, scope || ""], "write-only"),
|
|
1373
|
+
getUser: async () => Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only")),
|
|
1374
|
+
getOrWaitOAuthToken: async () => Result.orThrow(await this._serverUserOAuthConnectionAccessTokensCache.getOrWait([userId, providerId, scope || ""], "write-only")),
|
|
1367
1375
|
useOAuthToken: () => useAsyncCache(this._serverUserOAuthConnectionAccessTokensCache, [userId, providerId, scope || ""], "user.useConnectedAccount()"),
|
|
1368
1376
|
providerId,
|
|
1369
1377
|
scope,
|
|
@@ -1435,7 +1443,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1435
1443
|
const app = this;
|
|
1436
1444
|
async function getConnectedAccount(id, options) {
|
|
1437
1445
|
const scopeString = options?.scopes?.join(" ");
|
|
1438
|
-
return await app._serverUserOAuthConnectionCache.getOrWait([crud.id, id, scopeString || "", options?.or === "redirect"], "write-only");
|
|
1446
|
+
return Result.orThrow(await app._serverUserOAuthConnectionCache.getOrWait([crud.id, id, scopeString || "", options?.or === "redirect"], "write-only"));
|
|
1439
1447
|
}
|
|
1440
1448
|
function useConnectedAccount(id, options) {
|
|
1441
1449
|
const scopeString = options?.scopes?.join(" ");
|
|
@@ -1502,7 +1510,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1502
1510
|
}, [teams, teamId]);
|
|
1503
1511
|
},
|
|
1504
1512
|
async listTeams() {
|
|
1505
|
-
const teams = await app._serverTeamsCache.getOrWait([crud.id], "write-only");
|
|
1513
|
+
const teams = Result.orThrow(await app._serverTeamsCache.getOrWait([crud.id], "write-only"));
|
|
1506
1514
|
return teams.map((t) => app._serverTeamFromCrud(t));
|
|
1507
1515
|
},
|
|
1508
1516
|
useTeams() {
|
|
@@ -1522,7 +1530,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1522
1530
|
},
|
|
1523
1531
|
async listPermissions(scope, options) {
|
|
1524
1532
|
const recursive = options?.recursive ?? true;
|
|
1525
|
-
const permissions = await app._serverTeamUserPermissionsCache.getOrWait([scope.id, crud.id, recursive], "write-only");
|
|
1533
|
+
const permissions = Result.orThrow(await app._serverTeamUserPermissionsCache.getOrWait([scope.id, crud.id, recursive], "write-only"));
|
|
1526
1534
|
return permissions.map((crud2) => app._serverPermissionFromCrud(crud2));
|
|
1527
1535
|
},
|
|
1528
1536
|
usePermissions(scope, options) {
|
|
@@ -1558,7 +1566,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1558
1566
|
return result;
|
|
1559
1567
|
},
|
|
1560
1568
|
async getTeamProfile(team) {
|
|
1561
|
-
const result = await app._serverUserTeamProfileCache.getOrWait([team.id, crud.id], "write-only");
|
|
1569
|
+
const result = Result.orThrow(await app._serverUserTeamProfileCache.getOrWait([team.id, crud.id], "write-only"));
|
|
1562
1570
|
return app._serverEditableTeamProfileFromCrud(result);
|
|
1563
1571
|
},
|
|
1564
1572
|
useTeamProfile(team) {
|
|
@@ -1566,7 +1574,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1566
1574
|
return useMemo(() => app._serverEditableTeamProfileFromCrud(result), [result]);
|
|
1567
1575
|
},
|
|
1568
1576
|
async listContactChannels() {
|
|
1569
|
-
const result = await app._serverContactChannelsCache.getOrWait([crud.id], "write-only");
|
|
1577
|
+
const result = Result.orThrow(await app._serverContactChannelsCache.getOrWait([crud.id], "write-only"));
|
|
1570
1578
|
return result.map((data) => app._serverContactChannelFromCrud(crud.id, data));
|
|
1571
1579
|
},
|
|
1572
1580
|
useContactChannels() {
|
|
@@ -1618,7 +1626,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1618
1626
|
await app._serverTeamsCache.refresh([void 0]);
|
|
1619
1627
|
},
|
|
1620
1628
|
async listUsers() {
|
|
1621
|
-
const result = await app._serverTeamMemberProfilesCache.getOrWait([crud.id], "write-only");
|
|
1629
|
+
const result = Result.orThrow(await app._serverTeamMemberProfilesCache.getOrWait([crud.id], "write-only"));
|
|
1622
1630
|
return result.map((u) => app._serverTeamUserFromCrud(u));
|
|
1623
1631
|
},
|
|
1624
1632
|
useUsers() {
|
|
@@ -1662,7 +1670,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1662
1670
|
} else {
|
|
1663
1671
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1664
1672
|
const session = await this._getSession(options?.tokenStore);
|
|
1665
|
-
const crud = await this._currentServerUserCache.getOrWait([session], "write-only");
|
|
1673
|
+
const crud = Result.orThrow(await this._currentServerUserCache.getOrWait([session], "write-only"));
|
|
1666
1674
|
if (crud === null) {
|
|
1667
1675
|
switch (options?.or) {
|
|
1668
1676
|
case "redirect": {
|
|
@@ -1685,7 +1693,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1685
1693
|
return await this.getUser();
|
|
1686
1694
|
}
|
|
1687
1695
|
async getServerUserById(userId) {
|
|
1688
|
-
const crud = await this._serverUserCache.getOrWait([userId], "write-only");
|
|
1696
|
+
const crud = Result.orThrow(await this._serverUserCache.getOrWait([userId], "write-only"));
|
|
1689
1697
|
return crud && this._serverUserFromCrud(crud);
|
|
1690
1698
|
}
|
|
1691
1699
|
useUser(options) {
|
|
@@ -1723,7 +1731,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1723
1731
|
}, [crud]);
|
|
1724
1732
|
}
|
|
1725
1733
|
async listUsers(options) {
|
|
1726
|
-
const crud = await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "write-only");
|
|
1734
|
+
const crud = Result.orThrow(await this._serverUsersCache.getOrWait([options?.cursor, options?.limit, options?.orderBy, options?.desc, options?.query], "write-only"));
|
|
1727
1735
|
const result = crud.items.map((j) => this._serverUserFromCrud(j));
|
|
1728
1736
|
result.nextCursor = crud.pagination?.next_cursor ?? null;
|
|
1729
1737
|
return result;
|
|
@@ -1747,7 +1755,7 @@ var _StackServerAppImpl = class extends _StackClientAppImpl {
|
|
|
1747
1755
|
};
|
|
1748
1756
|
}
|
|
1749
1757
|
async listTeams() {
|
|
1750
|
-
const teams = await this._serverTeamsCache.getOrWait([void 0], "write-only");
|
|
1758
|
+
const teams = Result.orThrow(await this._serverTeamsCache.getOrWait([void 0], "write-only"));
|
|
1751
1759
|
return teams.map((t) => this._serverTeamFromCrud(t));
|
|
1752
1760
|
}
|
|
1753
1761
|
async createTeam(data) {
|
|
@@ -1908,7 +1916,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1908
1916
|
}
|
|
1909
1917
|
async getProject() {
|
|
1910
1918
|
return this._adminProjectFromCrud(
|
|
1911
|
-
await this._adminProjectCache.getOrWait([], "write-only"),
|
|
1919
|
+
Result.orThrow(await this._adminProjectCache.getOrWait([], "write-only")),
|
|
1912
1920
|
() => this._refreshProject()
|
|
1913
1921
|
);
|
|
1914
1922
|
}
|
|
@@ -1959,7 +1967,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1959
1967
|
};
|
|
1960
1968
|
}
|
|
1961
1969
|
async listApiKeys() {
|
|
1962
|
-
const crud = await this._apiKeysCache.getOrWait([], "write-only");
|
|
1970
|
+
const crud = Result.orThrow(await this._apiKeysCache.getOrWait([], "write-only"));
|
|
1963
1971
|
return crud.map((j) => this._createApiKeyFromCrud(j));
|
|
1964
1972
|
}
|
|
1965
1973
|
useApiKeys() {
|
|
@@ -1980,7 +1988,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
1980
1988
|
}, [crud]);
|
|
1981
1989
|
}
|
|
1982
1990
|
async listEmailTemplates() {
|
|
1983
|
-
const crud = await this._adminEmailTemplatesCache.getOrWait([], "write-only");
|
|
1991
|
+
const crud = Result.orThrow(await this._adminEmailTemplatesCache.getOrWait([], "write-only"));
|
|
1984
1992
|
return crud.map((j) => this._adminEmailTemplateFromCrud(j));
|
|
1985
1993
|
}
|
|
1986
1994
|
async updateEmailTemplate(type, data) {
|
|
@@ -2005,7 +2013,7 @@ var _StackAdminAppImpl = class extends _StackServerAppImpl {
|
|
|
2005
2013
|
await this._adminTeamPermissionDefinitionsCache.refresh([]);
|
|
2006
2014
|
}
|
|
2007
2015
|
async listTeamPermissionDefinitions() {
|
|
2008
|
-
const crud = await this._adminTeamPermissionDefinitionsCache.getOrWait([], "write-only");
|
|
2016
|
+
const crud = Result.orThrow(await this._adminTeamPermissionDefinitionsCache.getOrWait([], "write-only"));
|
|
2009
2017
|
return crud.map((p) => this._serverTeamPermissionDefinitionFromCrud(p));
|
|
2010
2018
|
}
|
|
2011
2019
|
useTeamPermissionDefinitions() {
|