@stackframe/js 2.8.12 → 2.8.17
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 +46 -0
- package/dist/esm/index.js +1 -1
- package/dist/esm/lib/auth.js +2 -2
- package/dist/esm/lib/cookie.js +1 -129
- package/dist/esm/lib/cookie.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/implementations/admin-app-impl.js +10 -7
- 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 -20
- 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/index.js +3 -3
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js +29 -7
- package/dist/esm/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/esm/lib/stack-app/apps/index.js +3 -3
- package/dist/esm/lib/stack-app/apps/interfaces/admin-app.js +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 +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 +1 -1
- package/dist/esm/lib/stack-app/common.js.map +1 -1
- package/dist/esm/lib/stack-app/contact-channels/index.js.map +1 -1
- package/dist/esm/lib/stack-app/index.js +2 -2
- package/dist/esm/lib/stack-app/internal-api-keys/index.js.map +1 -1
- package/dist/esm/lib/stack-app/notification-categories/index.js +1 -0
- package/dist/esm/lib/stack-app/notification-categories/index.js.map +1 -0
- package/dist/esm/lib/stack-app/users/index.js.map +1 -1
- package/dist/index.d.mts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/lib/auth.js +2 -2
- package/dist/lib/cookie.js +4 -132
- package/dist/lib/cookie.js.map +1 -1
- package/dist/lib/stack-app/apps/implementations/admin-app-impl.js +10 -7
- 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 +74 -20
- 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/index.js +3 -3
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js +29 -7
- package/dist/lib/stack-app/apps/implementations/server-app-impl.js.map +1 -1
- package/dist/lib/stack-app/apps/index.js +3 -3
- package/dist/lib/stack-app/apps/interfaces/admin-app.js +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 +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 +1 -1
- package/dist/lib/stack-app/common.js.map +1 -1
- package/dist/lib/stack-app/contact-channels/index.js.map +1 -1
- package/dist/lib/stack-app/index.js +2 -2
- package/dist/lib/stack-app/internal-api-keys/index.js.map +1 -1
- package/dist/lib/stack-app/notification-categories/index.js +19 -0
- package/dist/lib/stack-app/notification-categories/index.js.map +1 -0
- package/dist/lib/stack-app/users/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -13,16 +13,16 @@ import { deindent, mergeScopeStrings } from "@stackframe/stack-shared/dist/utils
|
|
|
13
13
|
import { getRelativePart, isRelative } from "@stackframe/stack-shared/dist/utils/urls";
|
|
14
14
|
import { generateUuid } from "@stackframe/stack-shared/dist/utils/uuids";
|
|
15
15
|
import * as cookie from "cookie";
|
|
16
|
-
import { constructRedirectUrl } from "../../../../utils/url";
|
|
17
|
-
import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "../../../auth";
|
|
18
|
-
import { createCookieHelper, createPlaceholderCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "../../../cookie";
|
|
19
|
-
import { apiKeyCreationOptionsToCrud } from "../../api-keys";
|
|
20
|
-
import { stackAppInternalsSymbol } from "../../common";
|
|
21
|
-
import { contactChannelCreateOptionsToCrud, contactChannelUpdateOptionsToCrud } from "../../contact-channels";
|
|
22
|
-
import { adminProjectCreateOptionsToCrud } from "../../projects";
|
|
23
|
-
import { teamCreateOptionsToCrud, teamUpdateOptionsToCrud } from "../../teams";
|
|
24
|
-
import { userUpdateOptionsToCrud } from "../../users";
|
|
25
|
-
import { clientVersion, createCache, createCacheBySession, createEmptyTokenStore, getBaseUrl, getDefaultExtraRequestHeaders, getDefaultProjectId, getDefaultPublishableClientKey, getUrls } from "./common";
|
|
16
|
+
import { constructRedirectUrl } from "../../../../utils/url.js";
|
|
17
|
+
import { addNewOAuthProviderOrScope, callOAuthCallback, signInWithOAuth } from "../../../auth.js";
|
|
18
|
+
import { createCookieHelper, createPlaceholderCookieHelper, deleteCookieClient, getCookieClient, setOrDeleteCookie, setOrDeleteCookieClient } from "../../../cookie.js";
|
|
19
|
+
import { apiKeyCreationOptionsToCrud } from "../../api-keys/index.js";
|
|
20
|
+
import { stackAppInternalsSymbol } from "../../common.js";
|
|
21
|
+
import { contactChannelCreateOptionsToCrud, contactChannelUpdateOptionsToCrud } from "../../contact-channels/index.js";
|
|
22
|
+
import { adminProjectCreateOptionsToCrud } from "../../projects/index.js";
|
|
23
|
+
import { teamCreateOptionsToCrud, teamUpdateOptionsToCrud } from "../../teams/index.js";
|
|
24
|
+
import { userUpdateOptionsToCrud } from "../../users/index.js";
|
|
25
|
+
import { clientVersion, createCache, createCacheBySession, createEmptyTokenStore, getBaseUrl, getDefaultExtraRequestHeaders, getDefaultProjectId, getDefaultPublishableClientKey, getUrls } from "./common.js";
|
|
26
26
|
var isReactServer = false;
|
|
27
27
|
var process = globalThis.process ?? { env: {} };
|
|
28
28
|
var allClientApps = /* @__PURE__ */ new Map();
|
|
@@ -113,6 +113,12 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
113
113
|
return results;
|
|
114
114
|
}
|
|
115
115
|
);
|
|
116
|
+
this._notificationCategoriesCache = createCacheBySession(
|
|
117
|
+
async (session) => {
|
|
118
|
+
const results = await this._interface.listNotificationCategories(session);
|
|
119
|
+
return results;
|
|
120
|
+
}
|
|
121
|
+
);
|
|
116
122
|
this._anonymousSignUpInProgress = null;
|
|
117
123
|
this._memoryTokenStore = createEmptyTokenStore();
|
|
118
124
|
this._nextServerCookiesTokenStores = /* @__PURE__ */ new WeakMap();
|
|
@@ -571,6 +577,19 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
571
577
|
}
|
|
572
578
|
};
|
|
573
579
|
}
|
|
580
|
+
_clientNotificationCategoryFromCrud(crud, session) {
|
|
581
|
+
const app = this;
|
|
582
|
+
return {
|
|
583
|
+
id: crud.notification_category_id,
|
|
584
|
+
name: crud.notification_category_name,
|
|
585
|
+
enabled: crud.enabled,
|
|
586
|
+
canDisable: crud.can_disable,
|
|
587
|
+
async setEnabled(enabled) {
|
|
588
|
+
await app._interface.setNotificationsEnabled(crud.notification_category_id, enabled, session);
|
|
589
|
+
await app._notificationCategoriesCache.refresh([session]);
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
}
|
|
574
593
|
_createAuth(session) {
|
|
575
594
|
const app = this;
|
|
576
595
|
return {
|
|
@@ -782,6 +801,10 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
782
801
|
await app._clientContactChannelsCache.refresh([session]);
|
|
783
802
|
return app._clientContactChannelFromCrud(crud2, session);
|
|
784
803
|
},
|
|
804
|
+
async listNotificationCategories() {
|
|
805
|
+
const results = Result.orThrow(await app._notificationCategoriesCache.getOrWait([session], "write-only"));
|
|
806
|
+
return results.map((crud2) => app._clientNotificationCategoryFromCrud(crud2, session));
|
|
807
|
+
},
|
|
785
808
|
async listApiKeys() {
|
|
786
809
|
const results = await app._interface.listProjectApiKeys({ user_id: "me" }, session, "client");
|
|
787
810
|
return results.map((crud2) => app._clientApiKeyFromCrud(session, crud2));
|
|
@@ -950,6 +973,9 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
950
973
|
async redirectToTeamInvitation(options) {
|
|
951
974
|
return await this._redirectToHandler("teamInvitation", options);
|
|
952
975
|
}
|
|
976
|
+
async redirectToMfa(options) {
|
|
977
|
+
return await this._redirectToHandler("mfa", options);
|
|
978
|
+
}
|
|
953
979
|
async sendForgotPasswordEmail(email, options) {
|
|
954
980
|
return await this._interface.sendForgotPasswordEmail(email, options?.callbackUrl ?? constructRedirectUrl(this.urls.passwordReset, "callbackUrl"));
|
|
955
981
|
}
|
|
@@ -1049,19 +1075,14 @@ var __StackClientAppImplIncomplete = class __StackClientAppImplIncomplete {
|
|
|
1049
1075
|
);
|
|
1050
1076
|
}
|
|
1051
1077
|
/**
|
|
1052
|
-
*
|
|
1053
|
-
* TODO remove
|
|
1078
|
+
* Handles MFA verification by redirecting to the OTP page
|
|
1054
1079
|
*/
|
|
1055
1080
|
async _experimentalMfa(error, session) {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
throw new KnownErrors.InvalidTotpCode();
|
|
1081
|
+
if (typeof window !== "undefined") {
|
|
1082
|
+
window.sessionStorage.setItem("stack_mfa_attempt_code", error.details?.attempt_code ?? throwErr("attempt code missing"));
|
|
1059
1083
|
}
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
otp,
|
|
1063
|
-
session
|
|
1064
|
-
);
|
|
1084
|
+
await this.redirectToMfa();
|
|
1085
|
+
throw new StackAssertionError("we should have redirected in redirectToMfa()");
|
|
1065
1086
|
}
|
|
1066
1087
|
/**
|
|
1067
1088
|
* @deprecated
|
|
@@ -1245,6 +1266,39 @@ ${url}`);
|
|
|
1245
1266
|
}
|
|
1246
1267
|
return Result.error(new KnownErrors.CliAuthError("Timed out waiting for CLI authentication."));
|
|
1247
1268
|
}
|
|
1269
|
+
/*
|
|
1270
|
+
* Completes the MFA sign-in process by verifying the provided OTP code
|
|
1271
|
+
* @param totp The TOTP (Time-based One-Time Password) provided by the user
|
|
1272
|
+
* @param code The Attempt code provided by the user
|
|
1273
|
+
* @param options Additional options for the sign-in process
|
|
1274
|
+
* @returns A Result indicating success or failure
|
|
1275
|
+
*/
|
|
1276
|
+
async signInWithMfa(totp, code, options) {
|
|
1277
|
+
this._ensurePersistentTokenStore();
|
|
1278
|
+
let result;
|
|
1279
|
+
try {
|
|
1280
|
+
result = await this._catchMfaRequiredError(async () => {
|
|
1281
|
+
return await this._interface.signInWithMfa(totp, code);
|
|
1282
|
+
});
|
|
1283
|
+
} catch (e) {
|
|
1284
|
+
if (e instanceof KnownErrors.InvalidTotpCode) {
|
|
1285
|
+
return Result.error(e);
|
|
1286
|
+
}
|
|
1287
|
+
throw e;
|
|
1288
|
+
}
|
|
1289
|
+
if (result.status === "ok") {
|
|
1290
|
+
await this._signInToAccountWithTokens(result.data);
|
|
1291
|
+
if (!options?.noRedirect) {
|
|
1292
|
+
if (result.data.newUser) {
|
|
1293
|
+
await this.redirectToAfterSignUp({ replace: true });
|
|
1294
|
+
} else {
|
|
1295
|
+
await this.redirectToAfterSignIn({ replace: true });
|
|
1296
|
+
}
|
|
1297
|
+
}
|
|
1298
|
+
return Result.ok(void 0);
|
|
1299
|
+
}
|
|
1300
|
+
return Result.error(result.error);
|
|
1301
|
+
}
|
|
1248
1302
|
async signInWithPasskey() {
|
|
1249
1303
|
this._ensurePersistentTokenStore();
|
|
1250
1304
|
const session = await this._getSession();
|