@stackframe/js 2.8.56 → 2.8.58
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/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +235 -0
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js +74 -19
- package/dist/esm/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js +2 -1
- package/dist/esm/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +31 -23
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/esm/lib/stack-app/common.js.map +1 -1
- package/dist/esm/lib/stack-app/index.js.map +1 -1
- package/dist/esm/lib/stack-app/projects/index.js +4 -0
- package/dist/esm/lib/stack-app/projects/index.js.map +1 -1
- package/dist/esm/lib/stack-app/teams/index.js.map +1 -1
- package/dist/esm/lib/stack-app/users/index.js +13 -12
- package/dist/esm/lib/stack-app/users/index.js.map +1 -1
- package/dist/index.d.mts +249 -16
- package/dist/index.d.ts +249 -16
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +235 -0
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js +73 -18
- package/dist/lib/stack-app/apps/implementations/client-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/common.js +2 -1
- package/dist/lib/stack-app/apps/implementations/common.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +29 -21
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/admin-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/client-app.js.map +1 -1
- package/dist/lib/stack-app/apps/interfaces/server-app.js.map +1 -1
- package/dist/lib/stack-app/common.js.map +1 -1
- package/dist/lib/stack-app/email/index.js.map +1 -1
- package/dist/lib/stack-app/index.js.map +1 -1
- package/dist/lib/stack-app/project-configs/index.js.map +1 -1
- package/dist/lib/stack-app/projects/index.js +4 -0
- package/dist/lib/stack-app/projects/index.js.map +1 -1
- package/dist/lib/stack-app/teams/index.js.map +1 -1
- package/dist/lib/stack-app/users/index.js +15 -14
- package/dist/lib/stack-app/users/index.js.map +1 -1
- package/package.json +3 -2
- package/CHANGELOG.md +0 -2072
|
@@ -23,7 +23,7 @@ import { stackAppInternalsSymbol } from "../../common.js";
|
|
|
23
23
|
import { contactChannelCreateOptionsToCrud, contactChannelUpdateOptionsToCrud } from "../../contact-channels/index.js";
|
|
24
24
|
import { adminProjectCreateOptionsToCrud } from "../../projects/index.js";
|
|
25
25
|
import { teamCreateOptionsToCrud, teamUpdateOptionsToCrud } from "../../teams/index.js";
|
|
26
|
-
import {
|
|
26
|
+
import { userUpdateOptionsToCrud, withUserDestructureGuard } from "../../users/index.js";
|
|
27
27
|
import { clientVersion, createCache, createCacheBySession, createEmptyTokenStore, getBaseUrl, getDefaultExtraRequestHeaders, getDefaultProjectId, getDefaultPublishableClientKey, getUrls, resolveConstructorOptions } from "./common.js";
|
|
28
28
|
var isReactServer = false;
|
|
29
29
|
var process = globalThis.process ?? { env: {} };
|
|
@@ -897,13 +897,21 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
897
897
|
_internalSession: session,
|
|
898
898
|
currentSession: {
|
|
899
899
|
async getTokens() {
|
|
900
|
-
const tokens = await session.getOrFetchLikelyValidTokens(2e4);
|
|
900
|
+
const tokens = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
|
|
901
901
|
return {
|
|
902
902
|
accessToken: tokens?.accessToken.token ?? null,
|
|
903
903
|
refreshToken: tokens?.refreshToken?.token ?? null
|
|
904
904
|
};
|
|
905
905
|
}
|
|
906
906
|
},
|
|
907
|
+
async getAccessToken() {
|
|
908
|
+
const tokens = await this.currentSession.getTokens();
|
|
909
|
+
return tokens.accessToken;
|
|
910
|
+
},
|
|
911
|
+
async getRefreshToken() {
|
|
912
|
+
const tokens = await this.currentSession.getTokens();
|
|
913
|
+
return tokens.refreshToken;
|
|
914
|
+
},
|
|
907
915
|
async getAuthHeaders() {
|
|
908
916
|
return {
|
|
909
917
|
"x-stack-auth": JSON.stringify(await this.getAuthJson())
|
|
@@ -953,6 +961,8 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
953
961
|
passkeyAuthEnabled: crud.passkey_auth_enabled,
|
|
954
962
|
isMultiFactorRequired: crud.requires_totp_mfa,
|
|
955
963
|
isAnonymous: crud.is_anonymous,
|
|
964
|
+
isRestricted: crud.is_restricted,
|
|
965
|
+
restrictedReason: crud.restricted_reason,
|
|
956
966
|
toClientJson() {
|
|
957
967
|
return crud;
|
|
958
968
|
}
|
|
@@ -979,7 +989,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
979
989
|
return this.update({ clientMetadata: metadata });
|
|
980
990
|
},
|
|
981
991
|
async setSelectedTeam(team) {
|
|
982
|
-
await this.update({ selectedTeamId: team?.id ?? null });
|
|
992
|
+
await this.update({ selectedTeamId: typeof team === "string" ? team : team?.id ?? null });
|
|
983
993
|
},
|
|
984
994
|
getConnectedAccount,
|
|
985
995
|
async getTeam(teamId) {
|
|
@@ -1184,16 +1194,33 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1184
1194
|
const response = Result.orThrow(await this._customProductsCache.getOrWait([session, options.customCustomerId, options.cursor ?? null, options.limit ?? null], "write-only"));
|
|
1185
1195
|
return this._customerProductsFromResponse(response);
|
|
1186
1196
|
}
|
|
1197
|
+
async cancelSubscription(options) {
|
|
1198
|
+
const session = await this._getSession();
|
|
1199
|
+
const user = await this.getUser();
|
|
1200
|
+
if (!user) {
|
|
1201
|
+
throw new KnownErrors.UserAuthenticationRequired();
|
|
1202
|
+
}
|
|
1203
|
+
const customerType = "teamId" in options ? "team" : "user";
|
|
1204
|
+
const customerId = "teamId" in options ? options.teamId : user.id;
|
|
1205
|
+
await this._interface.cancelSubscription({
|
|
1206
|
+
customer_type: customerType,
|
|
1207
|
+
customer_id: customerId,
|
|
1208
|
+
product_id: options.productId
|
|
1209
|
+
}, session);
|
|
1210
|
+
if (customerType === "user") {
|
|
1211
|
+
await this._userProductsCache.invalidateWhere(([cachedSession, userId]) => cachedSession === session && userId === customerId);
|
|
1212
|
+
} else {
|
|
1213
|
+
await this._teamProductsCache.invalidateWhere(([cachedSession, teamId]) => cachedSession === session && teamId === customerId);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1187
1216
|
_currentUserFromCrud(crud, session) {
|
|
1188
|
-
const currentUser = {
|
|
1217
|
+
const currentUser = withUserDestructureGuard({
|
|
1189
1218
|
...this._createBaseUser(crud),
|
|
1190
1219
|
...this._createAuth(session),
|
|
1191
1220
|
...this._createUserExtraFromCurrent(crud, session),
|
|
1192
1221
|
...this._isInternalProject() ? this._createInternalUserExtra(session) : {},
|
|
1193
1222
|
...this._createCustomer(crud.id, "user", session)
|
|
1194
|
-
};
|
|
1195
|
-
attachUserDestructureGuard(currentUser);
|
|
1196
|
-
Object.freeze(currentUser);
|
|
1223
|
+
});
|
|
1197
1224
|
return currentUser;
|
|
1198
1225
|
}
|
|
1199
1226
|
_clientSessionFromCrud(crud) {
|
|
@@ -1266,7 +1293,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1266
1293
|
const queryParams = new URLSearchParams(window.location.search);
|
|
1267
1294
|
url = queryParams.get("after_auth_return_to") || url;
|
|
1268
1295
|
}
|
|
1269
|
-
} else if (handlerName === "signIn" || handlerName === "signUp") {
|
|
1296
|
+
} else if (handlerName === "signIn" || handlerName === "signUp" || handlerName === "onboarding") {
|
|
1270
1297
|
if (isReactServer || typeof window === "undefined") {
|
|
1271
1298
|
} else {
|
|
1272
1299
|
const currentUrl = new URL(window.location.href);
|
|
@@ -1315,6 +1342,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1315
1342
|
async redirectToAfterSignUp(options) {
|
|
1316
1343
|
return await this._redirectToHandler("afterSignUp", options);
|
|
1317
1344
|
}
|
|
1345
|
+
async redirectToOnboarding(options) {
|
|
1346
|
+
return await this._redirectToHandler("onboarding", options);
|
|
1347
|
+
}
|
|
1318
1348
|
async redirectToAfterSignOut(options) {
|
|
1319
1349
|
return await this._redirectToHandler("afterSignOut", options);
|
|
1320
1350
|
}
|
|
@@ -1380,16 +1410,22 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1380
1410
|
return result;
|
|
1381
1411
|
}
|
|
1382
1412
|
async getUser(options) {
|
|
1413
|
+
if (options?.or === "anonymous" && options.includeRestricted === false) {
|
|
1414
|
+
throw new Error("Cannot use { or: 'anonymous' } with { includeRestricted: false }. Anonymous users implicitly include restricted users.");
|
|
1415
|
+
}
|
|
1383
1416
|
this._ensurePersistentTokenStore(options?.tokenStore);
|
|
1384
1417
|
const session = await this._getSession(options?.tokenStore);
|
|
1385
1418
|
let crud = Result.orThrow(await this._currentUserCache.getOrWait([session], "write-only"));
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
if (crud === null) {
|
|
1419
|
+
const includeAnonymous = options?.or === "anonymous" || options?.or === "anonymous-if-exists[deprecated]";
|
|
1420
|
+
const includeRestricted = options?.includeRestricted === true || includeAnonymous;
|
|
1421
|
+
if (crud === null || crud.is_anonymous && !includeAnonymous || crud.is_restricted && !includeRestricted) {
|
|
1390
1422
|
switch (options?.or) {
|
|
1391
1423
|
case "redirect": {
|
|
1392
|
-
|
|
1424
|
+
if (!crud?.is_anonymous && crud?.is_restricted) {
|
|
1425
|
+
await this.redirectToOnboarding({ replace: true });
|
|
1426
|
+
} else {
|
|
1427
|
+
await this.redirectToSignIn({ replace: true });
|
|
1428
|
+
}
|
|
1393
1429
|
break;
|
|
1394
1430
|
}
|
|
1395
1431
|
case "throw": {
|
|
@@ -1397,7 +1433,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1397
1433
|
}
|
|
1398
1434
|
case "anonymous": {
|
|
1399
1435
|
const tokens = await this._signUpAnonymously();
|
|
1400
|
-
return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]" }) ?? throwErr("Something went wrong while signing up anonymously");
|
|
1436
|
+
return await this.getUser({ tokenStore: tokens, or: "anonymous-if-exists[deprecated]", includeRestricted: true }) ?? throwErr("Something went wrong while signing up anonymously");
|
|
1401
1437
|
}
|
|
1402
1438
|
case void 0:
|
|
1403
1439
|
case "anonymous-if-exists[deprecated]":
|
|
@@ -1409,7 +1445,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1409
1445
|
return crud && this._currentUserFromCrud(crud, session);
|
|
1410
1446
|
}
|
|
1411
1447
|
_getTokenPartialUserFromSession(session, options) {
|
|
1412
|
-
const accessToken = session.getAccessTokenIfNotExpiredYet(0);
|
|
1448
|
+
const accessToken = session.getAccessTokenIfNotExpiredYet(0, null);
|
|
1413
1449
|
if (!accessToken) {
|
|
1414
1450
|
return null;
|
|
1415
1451
|
}
|
|
@@ -1422,7 +1458,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1422
1458
|
primaryEmail: accessToken.payload.email,
|
|
1423
1459
|
displayName: accessToken.payload.name,
|
|
1424
1460
|
primaryEmailVerified: accessToken.payload.email_verified,
|
|
1425
|
-
isAnonymous
|
|
1461
|
+
isAnonymous,
|
|
1462
|
+
isRestricted: accessToken.payload.is_restricted,
|
|
1463
|
+
restrictedReason: accessToken.payload.restricted_reason
|
|
1426
1464
|
};
|
|
1427
1465
|
}
|
|
1428
1466
|
async _getPartialUserFromConvex(ctx) {
|
|
@@ -1435,7 +1473,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1435
1473
|
displayName: auth.name ?? null,
|
|
1436
1474
|
primaryEmail: auth.email ?? null,
|
|
1437
1475
|
primaryEmailVerified: auth.email_verified,
|
|
1438
|
-
isAnonymous: auth.is_anonymous
|
|
1476
|
+
isAnonymous: auth.is_anonymous,
|
|
1477
|
+
isRestricted: auth.is_restricted,
|
|
1478
|
+
restrictedReason: auth.restricted_reason ?? null
|
|
1439
1479
|
};
|
|
1440
1480
|
}
|
|
1441
1481
|
async getPartialUser(options) {
|
|
@@ -1457,7 +1497,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1457
1497
|
return async (args) => {
|
|
1458
1498
|
const session = await this._getSession(options.tokenStore ?? this._tokenStoreInit);
|
|
1459
1499
|
if (!args.forceRefreshToken) {
|
|
1460
|
-
const tokens2 = await session.getOrFetchLikelyValidTokens(2e4);
|
|
1500
|
+
const tokens2 = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
|
|
1461
1501
|
return tokens2?.accessToken.token ?? null;
|
|
1462
1502
|
}
|
|
1463
1503
|
const tokens = await session.fetchNewTokens();
|
|
@@ -1466,7 +1506,7 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1466
1506
|
}
|
|
1467
1507
|
async getConvexHttpClientAuth(options) {
|
|
1468
1508
|
const session = await this._getSession(options.tokenStore);
|
|
1469
|
-
const tokens = await session.getOrFetchLikelyValidTokens(2e4);
|
|
1509
|
+
const tokens = await session.getOrFetchLikelyValidTokens(2e4, 75e3);
|
|
1470
1510
|
return tokens?.accessToken.token ?? "";
|
|
1471
1511
|
}
|
|
1472
1512
|
async _updateClientUser(update, session) {
|
|
@@ -1813,6 +1853,20 @@ ${url}`);
|
|
|
1813
1853
|
await user.signOut({ redirectUrl: options?.redirectUrl });
|
|
1814
1854
|
}
|
|
1815
1855
|
}
|
|
1856
|
+
async getAccessToken(options) {
|
|
1857
|
+
const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
|
|
1858
|
+
if (user) {
|
|
1859
|
+
return await user.getAccessToken();
|
|
1860
|
+
}
|
|
1861
|
+
return null;
|
|
1862
|
+
}
|
|
1863
|
+
async getRefreshToken(options) {
|
|
1864
|
+
const user = await this.getUser({ tokenStore: options?.tokenStore ?? void 0 });
|
|
1865
|
+
if (user) {
|
|
1866
|
+
return await user.getRefreshToken();
|
|
1867
|
+
}
|
|
1868
|
+
return null;
|
|
1869
|
+
}
|
|
1816
1870
|
async getAuthHeaders(options) {
|
|
1817
1871
|
return {
|
|
1818
1872
|
"x-stack-auth": JSON.stringify(await this.getAuthJson(options))
|
|
@@ -1849,6 +1903,7 @@ ${url}`);
|
|
|
1849
1903
|
}
|
|
1850
1904
|
async _refreshUser(session) {
|
|
1851
1905
|
await this._refreshSession(session);
|
|
1906
|
+
session.suggestAccessTokenExpired();
|
|
1852
1907
|
}
|
|
1853
1908
|
async _refreshSession(session) {
|
|
1854
1909
|
await this._currentUserCache.refresh([session]);
|