@scalemule/nextjs 0.0.37 → 0.0.39
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/client.d.mts +1 -5
- package/dist/client.d.ts +1 -5
- package/dist/{index-BIIUrnPr.d.mts → index-BoENfro3.d.mts} +1 -54
- package/dist/{index-BIIUrnPr.d.ts → index-BoENfro3.d.ts} +1 -54
- package/dist/index.d.mts +3 -7
- package/dist/index.d.ts +3 -7
- package/dist/index.js +42 -112
- package/dist/index.mjs +42 -112
- package/dist/server/auth.js +6 -266
- package/dist/server/auth.mjs +6 -266
- package/dist/server/index.d.mts +4 -68
- package/dist/server/index.d.ts +4 -68
- package/dist/server/index.js +6 -273
- package/dist/server/index.mjs +7 -267
- package/dist/server/webhook-handler.d.mts +2 -2
- package/dist/server/webhook-handler.d.ts +2 -2
- package/dist/testing.d.mts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/{webhook-handler-BobYTuNP.d.ts → webhook-handler-CjSSCdvI.d.ts} +1 -1
- package/dist/{webhook-handler-CNKQ1k2a.d.mts → webhook-handler-Cz9jtet2.d.mts} +1 -1
- package/package.json +2 -2
package/dist/server/auth.mjs
CHANGED
|
@@ -765,7 +765,6 @@ function createServerClient(config) {
|
|
|
765
765
|
}
|
|
766
766
|
var SESSION_COOKIE_NAME = "sm_session";
|
|
767
767
|
var USER_ID_COOKIE_NAME = "sm_user_id";
|
|
768
|
-
var KNOWN_ACCOUNTS_COOKIE_NAME = "sm_known_accounts";
|
|
769
768
|
({
|
|
770
769
|
secure: process.env.NODE_ENV === "production"});
|
|
771
770
|
function createCookieHeader(name, value, options = {}) {
|
|
@@ -846,163 +845,6 @@ async function getSession() {
|
|
|
846
845
|
// Note: actual expiry is managed by ScaleMule backend
|
|
847
846
|
};
|
|
848
847
|
}
|
|
849
|
-
var MAX_KNOWN_ACCOUNTS = 10;
|
|
850
|
-
function maskEmail(email) {
|
|
851
|
-
const [local, domain] = email.split("@");
|
|
852
|
-
if (!domain) return "***@***.***";
|
|
853
|
-
const tldDot = domain.lastIndexOf(".");
|
|
854
|
-
const tld = tldDot > 0 ? domain.slice(tldDot) : "";
|
|
855
|
-
const domainBase = tldDot > 0 ? domain.slice(0, tldDot) : domain;
|
|
856
|
-
return `${local[0] || "*"}***@${domainBase[0] || "*"}***${tld}`;
|
|
857
|
-
}
|
|
858
|
-
function stableColorIndex(userId) {
|
|
859
|
-
let hash = 0;
|
|
860
|
-
for (let i = 0; i < userId.length; i++) {
|
|
861
|
-
hash = (hash << 5) - hash + userId.charCodeAt(i) | 0;
|
|
862
|
-
}
|
|
863
|
-
return Math.abs(hash) % 8;
|
|
864
|
-
}
|
|
865
|
-
function applyPrivacyToEntry(entry, privacy) {
|
|
866
|
-
switch (privacy) {
|
|
867
|
-
case "full":
|
|
868
|
-
return entry;
|
|
869
|
-
case "masked":
|
|
870
|
-
return {
|
|
871
|
-
userId: entry.userId,
|
|
872
|
-
email: entry.email ? maskEmail(entry.email) : void 0,
|
|
873
|
-
fullName: entry.fullName ? `${entry.fullName[0].toUpperCase()}.` : void 0,
|
|
874
|
-
provider: entry.provider,
|
|
875
|
-
lastActiveAt: entry.lastActiveAt,
|
|
876
|
-
colorIndex: stableColorIndex(entry.userId)
|
|
877
|
-
};
|
|
878
|
-
case "minimal":
|
|
879
|
-
return {
|
|
880
|
-
userId: entry.userId,
|
|
881
|
-
provider: entry.provider,
|
|
882
|
-
lastActiveAt: entry.lastActiveAt,
|
|
883
|
-
displayLabel: "Account",
|
|
884
|
-
colorIndex: stableColorIndex(entry.userId)
|
|
885
|
-
};
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
function appendKnownAccountCookie(headers, account, existingCookie, options = {}, privacy) {
|
|
889
|
-
let accounts = {};
|
|
890
|
-
if (existingCookie) {
|
|
891
|
-
try {
|
|
892
|
-
accounts = JSON.parse(decodeURIComponent(existingCookie));
|
|
893
|
-
} catch {
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
const effectivePrivacy = privacy || "full";
|
|
897
|
-
for (const [userId, entry] of Object.entries(accounts)) {
|
|
898
|
-
accounts[userId] = applyPrivacyToEntry(entry, effectivePrivacy);
|
|
899
|
-
}
|
|
900
|
-
accounts[account.userId] = applyPrivacyToEntry(account, effectivePrivacy);
|
|
901
|
-
const entries = Object.entries(accounts);
|
|
902
|
-
if (entries.length > MAX_KNOWN_ACCOUNTS) {
|
|
903
|
-
entries.sort((a, b) => new Date(b[1].lastActiveAt).getTime() - new Date(a[1].lastActiveAt).getTime());
|
|
904
|
-
accounts = Object.fromEntries(entries.slice(0, MAX_KNOWN_ACCOUNTS));
|
|
905
|
-
}
|
|
906
|
-
const maxAge = 365 * 24 * 60 * 60;
|
|
907
|
-
const secure = options.secure ?? process.env.NODE_ENV === "production";
|
|
908
|
-
const sameSite = options.sameSite ?? "lax";
|
|
909
|
-
const path = options.path ?? "/";
|
|
910
|
-
let cookie = `${KNOWN_ACCOUNTS_COOKIE_NAME}=${encodeURIComponent(JSON.stringify(accounts))}; Path=${path}; Max-Age=${maxAge}; SameSite=${sameSite}`;
|
|
911
|
-
if (secure) {
|
|
912
|
-
cookie += "; Secure";
|
|
913
|
-
}
|
|
914
|
-
if (options.domain) {
|
|
915
|
-
cookie += `; Domain=${options.domain}`;
|
|
916
|
-
}
|
|
917
|
-
headers.append("Set-Cookie", cookie);
|
|
918
|
-
}
|
|
919
|
-
function removeKnownAccountFromCookie(headers, userId, existingCookie, options = {}) {
|
|
920
|
-
let accounts = {};
|
|
921
|
-
if (existingCookie) {
|
|
922
|
-
try {
|
|
923
|
-
accounts = JSON.parse(decodeURIComponent(existingCookie));
|
|
924
|
-
} catch {
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
delete accounts[userId];
|
|
928
|
-
const maxAge = 365 * 24 * 60 * 60;
|
|
929
|
-
const secure = options.secure ?? process.env.NODE_ENV === "production";
|
|
930
|
-
const sameSite = options.sameSite ?? "lax";
|
|
931
|
-
const path = options.path ?? "/";
|
|
932
|
-
let cookie = `${KNOWN_ACCOUNTS_COOKIE_NAME}=${encodeURIComponent(JSON.stringify(accounts))}; Path=${path}; Max-Age=${maxAge}; SameSite=${sameSite}`;
|
|
933
|
-
if (secure) {
|
|
934
|
-
cookie += "; Secure";
|
|
935
|
-
}
|
|
936
|
-
if (options.domain) {
|
|
937
|
-
cookie += `; Domain=${options.domain}`;
|
|
938
|
-
}
|
|
939
|
-
headers.append("Set-Cookie", cookie);
|
|
940
|
-
}
|
|
941
|
-
function clearKnownAccountsCookie(headers, options = {}) {
|
|
942
|
-
const path = options.path ?? "/";
|
|
943
|
-
let cookie = `${KNOWN_ACCOUNTS_COOKIE_NAME}=; Path=${path}; Max-Age=0`;
|
|
944
|
-
if (options.domain) {
|
|
945
|
-
cookie += `; Domain=${options.domain}`;
|
|
946
|
-
}
|
|
947
|
-
headers.append("Set-Cookie", cookie);
|
|
948
|
-
}
|
|
949
|
-
function getKnownAccountsFromRequest(request) {
|
|
950
|
-
const cookieHeader = request.headers.get("cookie");
|
|
951
|
-
if (!cookieHeader) return [];
|
|
952
|
-
const cookies3 = Object.fromEntries(
|
|
953
|
-
cookieHeader.split(";").map((c) => {
|
|
954
|
-
const [key, ...rest] = c.trim().split("=");
|
|
955
|
-
return [key, decodeURIComponent(rest.join("="))];
|
|
956
|
-
})
|
|
957
|
-
);
|
|
958
|
-
const raw = cookies3[KNOWN_ACCOUNTS_COOKIE_NAME];
|
|
959
|
-
if (!raw) return [];
|
|
960
|
-
try {
|
|
961
|
-
const accounts = JSON.parse(raw);
|
|
962
|
-
return Object.values(accounts);
|
|
963
|
-
} catch {
|
|
964
|
-
return [];
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
function getKnownAccountsCookieRaw(request) {
|
|
968
|
-
const cookieHeader = request.headers.get("cookie");
|
|
969
|
-
if (!cookieHeader) return null;
|
|
970
|
-
const cookies3 = Object.fromEntries(
|
|
971
|
-
cookieHeader.split(";").map((c) => {
|
|
972
|
-
const [key, ...rest] = c.trim().split("=");
|
|
973
|
-
return [key, decodeURIComponent(rest.join("="))];
|
|
974
|
-
})
|
|
975
|
-
);
|
|
976
|
-
return cookies3[KNOWN_ACCOUNTS_COOKIE_NAME] || null;
|
|
977
|
-
}
|
|
978
|
-
function normalizeKnownAccountsCookie(request, privacy, options = {}) {
|
|
979
|
-
if (!privacy || privacy === "full") return null;
|
|
980
|
-
const raw = getKnownAccountsCookieRaw(request);
|
|
981
|
-
if (!raw) return null;
|
|
982
|
-
let accounts = {};
|
|
983
|
-
try {
|
|
984
|
-
accounts = JSON.parse(raw);
|
|
985
|
-
} catch {
|
|
986
|
-
return null;
|
|
987
|
-
}
|
|
988
|
-
let changed = false;
|
|
989
|
-
for (const [userId, entry] of Object.entries(accounts)) {
|
|
990
|
-
const normalized = applyPrivacyToEntry(entry, privacy);
|
|
991
|
-
if (JSON.stringify(normalized) !== JSON.stringify(entry)) {
|
|
992
|
-
accounts[userId] = normalized;
|
|
993
|
-
changed = true;
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
if (!changed) return null;
|
|
997
|
-
const maxAge = 365 * 24 * 60 * 60;
|
|
998
|
-
const secure = options.secure ?? process.env.NODE_ENV === "production";
|
|
999
|
-
const sameSite = options.sameSite ?? "lax";
|
|
1000
|
-
const path = options.path ?? "/";
|
|
1001
|
-
let cookie = `${KNOWN_ACCOUNTS_COOKIE_NAME}=${encodeURIComponent(JSON.stringify(accounts))}; Path=${path}; Max-Age=${maxAge}; SameSite=${sameSite}`;
|
|
1002
|
-
if (secure) cookie += "; Secure";
|
|
1003
|
-
if (options.domain) cookie += `; Domain=${options.domain}`;
|
|
1004
|
-
return cookie;
|
|
1005
|
-
}
|
|
1006
848
|
|
|
1007
849
|
// src/server/timing.ts
|
|
1008
850
|
function constantTimeEqual(a, b) {
|
|
@@ -1089,25 +931,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1089
931
|
} catch {
|
|
1090
932
|
return successResponse({ user: registeredUser, message: "Registration successful" }, 201);
|
|
1091
933
|
}
|
|
1092
|
-
|
|
1093
|
-
if (config.enableAccountSwitcher) {
|
|
1094
|
-
const existingKnown = getKnownAccountsCookieRaw(request);
|
|
1095
|
-
appendKnownAccountCookie(
|
|
1096
|
-
registerResponse.headers,
|
|
1097
|
-
{
|
|
1098
|
-
userId: registeredUser.id,
|
|
1099
|
-
email: registeredUser.email,
|
|
1100
|
-
fullName: registeredUser.full_name ?? void 0,
|
|
1101
|
-
avatarUrl: registeredUser.avatar_url ?? void 0,
|
|
1102
|
-
provider: "email",
|
|
1103
|
-
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1104
|
-
},
|
|
1105
|
-
existingKnown,
|
|
1106
|
-
cookieOptions,
|
|
1107
|
-
config.accountSwitcherPrivacy
|
|
1108
|
-
);
|
|
1109
|
-
}
|
|
1110
|
-
return registerResponse;
|
|
934
|
+
return withSession(loginData, { user: registeredUser, sessionToken: loginData.session_token, userId: registeredUser.id }, cookieOptions);
|
|
1111
935
|
}
|
|
1112
936
|
// ==================== Login ====================
|
|
1113
937
|
case "login": {
|
|
@@ -1138,25 +962,7 @@ function createAuthRoutes(config = {}) {
|
|
|
1138
962
|
email: loginData.user.email
|
|
1139
963
|
});
|
|
1140
964
|
}
|
|
1141
|
-
|
|
1142
|
-
if (config.enableAccountSwitcher) {
|
|
1143
|
-
const existingKnown = getKnownAccountsCookieRaw(request);
|
|
1144
|
-
appendKnownAccountCookie(
|
|
1145
|
-
loginResponse.headers,
|
|
1146
|
-
{
|
|
1147
|
-
userId: loginData.user.id,
|
|
1148
|
-
email: loginData.user.email,
|
|
1149
|
-
fullName: loginData.user.full_name ?? void 0,
|
|
1150
|
-
avatarUrl: loginData.user.avatar_url ?? void 0,
|
|
1151
|
-
provider: "email",
|
|
1152
|
-
lastActiveAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1153
|
-
},
|
|
1154
|
-
existingKnown,
|
|
1155
|
-
cookieOptions,
|
|
1156
|
-
config.accountSwitcherPrivacy
|
|
1157
|
-
);
|
|
1158
|
-
}
|
|
1159
|
-
return loginResponse;
|
|
965
|
+
return withSession(loginData, { user: loginData.user, sessionToken: loginData.session_token, userId: loginData.user.id }, cookieOptions);
|
|
1160
966
|
}
|
|
1161
967
|
// ==================== Logout ====================
|
|
1162
968
|
case "logout": {
|
|
@@ -1303,59 +1109,6 @@ function createAuthRoutes(config = {}) {
|
|
|
1303
1109
|
}
|
|
1304
1110
|
return successResponse({ message: "Password changed successfully" });
|
|
1305
1111
|
}
|
|
1306
|
-
// ==================== Switch Account ====================
|
|
1307
|
-
// Clears the active session so the user can re-authenticate as a different account.
|
|
1308
|
-
// The known accounts cookie is preserved — only the session cookie is cleared.
|
|
1309
|
-
case "switch-account": {
|
|
1310
|
-
if (!config.enableAccountSwitcher) {
|
|
1311
|
-
return errorResponse("NOT_FOUND", "Account switcher not enabled", 404);
|
|
1312
|
-
}
|
|
1313
|
-
const session = await getSession();
|
|
1314
|
-
if (session) {
|
|
1315
|
-
try {
|
|
1316
|
-
await sm.auth.logout(session.sessionToken);
|
|
1317
|
-
} catch {
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
const switchResponse = clearSession({ message: "Session cleared for account switch" }, cookieOptions);
|
|
1321
|
-
const knownAccounts = getKnownAccountsFromRequest(request);
|
|
1322
|
-
return new Response(
|
|
1323
|
-
JSON.stringify({ success: true, data: { message: "Session cleared for account switch", knownAccounts } }),
|
|
1324
|
-
{ status: 200, headers: switchResponse.headers }
|
|
1325
|
-
);
|
|
1326
|
-
}
|
|
1327
|
-
// ==================== Forget Account ====================
|
|
1328
|
-
// Remove a specific account from the known accounts cookie.
|
|
1329
|
-
case "forget-account": {
|
|
1330
|
-
if (!config.enableAccountSwitcher) {
|
|
1331
|
-
return errorResponse("NOT_FOUND", "Account switcher not enabled", 404);
|
|
1332
|
-
}
|
|
1333
|
-
const { user_id } = body;
|
|
1334
|
-
if (!user_id) {
|
|
1335
|
-
return errorResponse("VALIDATION_ERROR", "user_id required", 400);
|
|
1336
|
-
}
|
|
1337
|
-
const headers = new Headers();
|
|
1338
|
-
headers.set("Content-Type", "application/json");
|
|
1339
|
-
const existingKnown = getKnownAccountsCookieRaw(request);
|
|
1340
|
-
removeKnownAccountFromCookie(headers, user_id, existingKnown, cookieOptions);
|
|
1341
|
-
return new Response(
|
|
1342
|
-
JSON.stringify({ success: true, data: { message: "Account forgotten" } }),
|
|
1343
|
-
{ status: 200, headers }
|
|
1344
|
-
);
|
|
1345
|
-
}
|
|
1346
|
-
// ==================== Forget All Accounts ====================
|
|
1347
|
-
case "forget-all-accounts": {
|
|
1348
|
-
if (!config.enableAccountSwitcher) {
|
|
1349
|
-
return errorResponse("NOT_FOUND", "Account switcher not enabled", 404);
|
|
1350
|
-
}
|
|
1351
|
-
const headers = new Headers();
|
|
1352
|
-
headers.set("Content-Type", "application/json");
|
|
1353
|
-
clearKnownAccountsCookie(headers, cookieOptions);
|
|
1354
|
-
return new Response(
|
|
1355
|
-
JSON.stringify({ success: true, data: { message: "All accounts forgotten" } }),
|
|
1356
|
-
{ status: 200, headers }
|
|
1357
|
-
);
|
|
1358
|
-
}
|
|
1359
1112
|
default:
|
|
1360
1113
|
return errorResponse("NOT_FOUND", `Unknown endpoint: ${path}`, 404);
|
|
1361
1114
|
}
|
|
@@ -1371,25 +1124,20 @@ function createAuthRoutes(config = {}) {
|
|
|
1371
1124
|
switch (path) {
|
|
1372
1125
|
// ==================== Get Current User ====================
|
|
1373
1126
|
case "me": {
|
|
1374
|
-
const normCookie = config.enableAccountSwitcher ? normalizeKnownAccountsCookie(request, config.accountSwitcherPrivacy, cookieOptions) : null;
|
|
1375
|
-
const withNorm = (resp) => {
|
|
1376
|
-
if (normCookie) resp.headers.append("Set-Cookie", normCookie);
|
|
1377
|
-
return resp;
|
|
1378
|
-
};
|
|
1379
1127
|
const session = await getSession();
|
|
1380
1128
|
if (!session) {
|
|
1381
|
-
return
|
|
1129
|
+
return errorResponse("UNAUTHORIZED", "Authentication required", 401);
|
|
1382
1130
|
}
|
|
1383
1131
|
let userData;
|
|
1384
1132
|
try {
|
|
1385
1133
|
userData = await sm.auth.me(session.sessionToken);
|
|
1386
1134
|
} catch {
|
|
1387
|
-
return
|
|
1135
|
+
return clearSession(
|
|
1388
1136
|
{ error: { code: "SESSION_EXPIRED", message: "Session expired" } },
|
|
1389
1137
|
cookieOptions
|
|
1390
|
-
)
|
|
1138
|
+
);
|
|
1391
1139
|
}
|
|
1392
|
-
return
|
|
1140
|
+
return successResponse({ user: userData, sessionToken: session.sessionToken, userId: session.userId });
|
|
1393
1141
|
}
|
|
1394
1142
|
// ==================== Get Session Status ====================
|
|
1395
1143
|
case "session": {
|
|
@@ -1399,14 +1147,6 @@ function createAuthRoutes(config = {}) {
|
|
|
1399
1147
|
userId: session?.userId || null
|
|
1400
1148
|
});
|
|
1401
1149
|
}
|
|
1402
|
-
// ==================== Get Known Accounts ====================
|
|
1403
|
-
case "known-accounts": {
|
|
1404
|
-
if (!config.enableAccountSwitcher) {
|
|
1405
|
-
return errorResponse("NOT_FOUND", "Account switcher not enabled", 404);
|
|
1406
|
-
}
|
|
1407
|
-
const knownAccounts = getKnownAccountsFromRequest(request);
|
|
1408
|
-
return successResponse({ knownAccounts });
|
|
1409
|
-
}
|
|
1410
1150
|
default:
|
|
1411
1151
|
return errorResponse("NOT_FOUND", `Unknown endpoint: ${path}`, 404);
|
|
1412
1152
|
}
|
package/dist/server/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as ServerConfig } from '../webhook-handler-
|
|
2
|
-
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-
|
|
3
|
-
import { p as ClientContext, A as ApiError } from '../index-
|
|
1
|
+
import { S as ServerConfig } from '../webhook-handler-Cz9jtet2.mjs';
|
|
2
|
+
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-Cz9jtet2.mjs';
|
|
3
|
+
import { p as ClientContext, A as ApiError } from '../index-BoENfro3.mjs';
|
|
4
4
|
import { NextRequest, NextResponse } from 'next/server';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -110,12 +110,6 @@ declare function buildFlagContext(clientContext: Pick<ClientContext, 'ip'> | und
|
|
|
110
110
|
*/
|
|
111
111
|
declare const SESSION_COOKIE_NAME = "sm_session";
|
|
112
112
|
declare const USER_ID_COOKIE_NAME = "sm_user_id";
|
|
113
|
-
/**
|
|
114
|
-
* Known accounts cookie — stores display metadata (email, name, avatar) for
|
|
115
|
-
* accounts that have logged in on this device. NOT httpOnly so client JS can
|
|
116
|
-
* read it to render the account switcher UI. Contains NO tokens or secrets.
|
|
117
|
-
*/
|
|
118
|
-
declare const KNOWN_ACCOUNTS_COOKIE_NAME = "sm_known_accounts";
|
|
119
113
|
interface SessionCookieOptions {
|
|
120
114
|
/** Cookie max age in seconds (default: 7 days) */
|
|
121
115
|
maxAge?: number;
|
|
@@ -187,51 +181,6 @@ declare function getSession(): Promise<SessionData | null>;
|
|
|
187
181
|
* Use this when you need to read cookies from a Request directly.
|
|
188
182
|
*/
|
|
189
183
|
declare function getSessionFromRequest(request: Request): SessionData | null;
|
|
190
|
-
/**
|
|
191
|
-
* Known account entry stored in cookie.
|
|
192
|
-
* Contains display metadata ONLY — no tokens, no secrets.
|
|
193
|
-
*/
|
|
194
|
-
interface KnownAccountEntry {
|
|
195
|
-
userId: string;
|
|
196
|
-
email?: string;
|
|
197
|
-
fullName?: string;
|
|
198
|
-
avatarUrl?: string;
|
|
199
|
-
provider?: string;
|
|
200
|
-
lastActiveAt: string;
|
|
201
|
-
displayLabel?: string;
|
|
202
|
-
colorIndex?: number;
|
|
203
|
-
}
|
|
204
|
-
type AccountSwitcherPrivacy = 'full' | 'masked' | 'minimal';
|
|
205
|
-
/**
|
|
206
|
-
* Add an account to the known accounts cookie.
|
|
207
|
-
* Called after successful login. The cookie is NOT httpOnly so client JS
|
|
208
|
-
* can read it to render the account switcher UI.
|
|
209
|
-
*
|
|
210
|
-
* Appends Set-Cookie headers to an existing Headers object.
|
|
211
|
-
*/
|
|
212
|
-
declare function appendKnownAccountCookie(headers: Headers, account: KnownAccountEntry, existingCookie: string | null, options?: SessionCookieOptions, privacy?: AccountSwitcherPrivacy): void;
|
|
213
|
-
/**
|
|
214
|
-
* Remove a specific account from the known accounts cookie.
|
|
215
|
-
*/
|
|
216
|
-
declare function removeKnownAccountFromCookie(headers: Headers, userId: string, existingCookie: string | null, options?: SessionCookieOptions): void;
|
|
217
|
-
/**
|
|
218
|
-
* Clear the known accounts cookie entirely.
|
|
219
|
-
*/
|
|
220
|
-
declare function clearKnownAccountsCookie(headers: Headers, options?: SessionCookieOptions): void;
|
|
221
|
-
/**
|
|
222
|
-
* Read known accounts from a Request's cookies.
|
|
223
|
-
*/
|
|
224
|
-
declare function getKnownAccountsFromRequest(request: Request): KnownAccountEntry[];
|
|
225
|
-
/**
|
|
226
|
-
* Read the raw known accounts cookie value from a Request.
|
|
227
|
-
*/
|
|
228
|
-
declare function getKnownAccountsCookieRaw(request: Request): string | null;
|
|
229
|
-
/**
|
|
230
|
-
* Normalize all entries in the known accounts cookie to the given privacy level.
|
|
231
|
-
* Returns a Set-Cookie header string if any entries changed, or null if nothing changed.
|
|
232
|
-
* Used on /me requests to migrate legacy full-PII cookies to the configured privacy level.
|
|
233
|
-
*/
|
|
234
|
-
declare function normalizeKnownAccountsCookie(request: Request, privacy: AccountSwitcherPrivacy | undefined, options?: SessionCookieOptions): string | null;
|
|
235
184
|
/**
|
|
236
185
|
* Require authentication - throws Response if not authenticated
|
|
237
186
|
*
|
|
@@ -271,19 +220,6 @@ interface AuthRoutesConfig {
|
|
|
271
220
|
cookies?: SessionCookieOptions;
|
|
272
221
|
/** Enable CSRF validation on state-changing requests (POST/DELETE/PATCH) */
|
|
273
222
|
csrf?: boolean;
|
|
274
|
-
/**
|
|
275
|
-
* Enable the account switcher — remembers which accounts have logged in on
|
|
276
|
-
* this device (metadata only, no tokens). Switching requires re-authentication.
|
|
277
|
-
* Adds routes: switch-account, forget-account, forget-all-accounts, known-accounts.
|
|
278
|
-
*/
|
|
279
|
-
enableAccountSwitcher?: boolean;
|
|
280
|
-
/**
|
|
281
|
-
* Privacy level for account switcher display metadata.
|
|
282
|
-
* - 'full': Store email, name, avatar as-is (default)
|
|
283
|
-
* - 'masked': Mask email, truncate name to initial
|
|
284
|
-
* - 'minimal': No PII — just a colored "Account" label
|
|
285
|
-
*/
|
|
286
|
-
accountSwitcherPrivacy?: 'full' | 'masked' | 'minimal';
|
|
287
223
|
/** Callbacks */
|
|
288
224
|
onLogin?: (user: {
|
|
289
225
|
id: string;
|
|
@@ -1075,4 +1011,4 @@ declare function invalidateBundleCache(key?: string): void;
|
|
|
1075
1011
|
*/
|
|
1076
1012
|
declare function prefetchBundles(keys: string[]): Promise<void>;
|
|
1077
1013
|
|
|
1078
|
-
export { type AnalyticsRoutesConfig, type AnalyticsTrackingGateConfig, type AuthMiddlewareConfig, type AuthRoutesConfig, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, type HandlerContext, type HandlerOptions,
|
|
1014
|
+
export { type AnalyticsRoutesConfig, type AnalyticsTrackingGateConfig, type AuthMiddlewareConfig, type AuthRoutesConfig, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, type HandlerContext, type HandlerOptions, type MySqlBundle, type NotificationRoutesConfig, OAUTH_STATE_COOKIE_NAME, type OAuthBundle, type PostgresBundle, type PushRoutesConfig, type RedisBundle, type S3Bundle, SESSION_COOKIE_NAME, ScaleMuleError, ServerConfig, type SessionCookieOptions, type SessionData, type SmtpBundle, USER_ID_COOKIE_NAME, apiHandler, buildClientContextHeaders, buildFlagContext, clearOAuthState, clearSession, configureBundles, configureSecrets, createAnalyticsRoutes, createAuthMiddleware, createAuthRoutes, createNotificationRoutes, createPushRoutes, errorCodeToStatus, extractClientContext, extractClientContextFromReq, generateCSRFToken, getAppSecret, getAppSecretOrDefault, getBootstrapFlags, getBundle, getCSRFToken, getMySqlBundle, getOAuthBundle, getPostgresBundle, getRedisBundle, getS3Bundle, getSession, getSessionFromRequest, getSmtpBundle, invalidateBundleCache, invalidateSecretCache, prefetchBundles, prefetchSecrets, requireAppSecret, requireBundle, requireSession, setOAuthState, unwrap, validateCSRFToken, validateCSRFTokenAsync, validateOAuthState, validateOAuthStateAsync, withAuth, withCSRFProtection, withCSRFToken, withSession };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { S as ServerConfig } from '../webhook-handler-
|
|
2
|
-
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-
|
|
3
|
-
import { p as ClientContext, A as ApiError } from '../index-
|
|
1
|
+
import { S as ServerConfig } from '../webhook-handler-CjSSCdvI.js';
|
|
2
|
+
export { a as ScaleMuleServer, V as VideoFailedEvent, b as VideoReadyEvent, c as VideoTranscodedEvent, d as VideoUploadedEvent, W as WebhookEvent, e as WebhookRoutesConfig, f as createServerClient, g as createWebhookHandler, h as createWebhookRoutes, p as parseWebhookEvent, r as registerVideoWebhook, i as resolveGatewayUrl, v as verifyWebhookSignature } from '../webhook-handler-CjSSCdvI.js';
|
|
3
|
+
import { p as ClientContext, A as ApiError } from '../index-BoENfro3.js';
|
|
4
4
|
import { NextRequest, NextResponse } from 'next/server';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -110,12 +110,6 @@ declare function buildFlagContext(clientContext: Pick<ClientContext, 'ip'> | und
|
|
|
110
110
|
*/
|
|
111
111
|
declare const SESSION_COOKIE_NAME = "sm_session";
|
|
112
112
|
declare const USER_ID_COOKIE_NAME = "sm_user_id";
|
|
113
|
-
/**
|
|
114
|
-
* Known accounts cookie — stores display metadata (email, name, avatar) for
|
|
115
|
-
* accounts that have logged in on this device. NOT httpOnly so client JS can
|
|
116
|
-
* read it to render the account switcher UI. Contains NO tokens or secrets.
|
|
117
|
-
*/
|
|
118
|
-
declare const KNOWN_ACCOUNTS_COOKIE_NAME = "sm_known_accounts";
|
|
119
113
|
interface SessionCookieOptions {
|
|
120
114
|
/** Cookie max age in seconds (default: 7 days) */
|
|
121
115
|
maxAge?: number;
|
|
@@ -187,51 +181,6 @@ declare function getSession(): Promise<SessionData | null>;
|
|
|
187
181
|
* Use this when you need to read cookies from a Request directly.
|
|
188
182
|
*/
|
|
189
183
|
declare function getSessionFromRequest(request: Request): SessionData | null;
|
|
190
|
-
/**
|
|
191
|
-
* Known account entry stored in cookie.
|
|
192
|
-
* Contains display metadata ONLY — no tokens, no secrets.
|
|
193
|
-
*/
|
|
194
|
-
interface KnownAccountEntry {
|
|
195
|
-
userId: string;
|
|
196
|
-
email?: string;
|
|
197
|
-
fullName?: string;
|
|
198
|
-
avatarUrl?: string;
|
|
199
|
-
provider?: string;
|
|
200
|
-
lastActiveAt: string;
|
|
201
|
-
displayLabel?: string;
|
|
202
|
-
colorIndex?: number;
|
|
203
|
-
}
|
|
204
|
-
type AccountSwitcherPrivacy = 'full' | 'masked' | 'minimal';
|
|
205
|
-
/**
|
|
206
|
-
* Add an account to the known accounts cookie.
|
|
207
|
-
* Called after successful login. The cookie is NOT httpOnly so client JS
|
|
208
|
-
* can read it to render the account switcher UI.
|
|
209
|
-
*
|
|
210
|
-
* Appends Set-Cookie headers to an existing Headers object.
|
|
211
|
-
*/
|
|
212
|
-
declare function appendKnownAccountCookie(headers: Headers, account: KnownAccountEntry, existingCookie: string | null, options?: SessionCookieOptions, privacy?: AccountSwitcherPrivacy): void;
|
|
213
|
-
/**
|
|
214
|
-
* Remove a specific account from the known accounts cookie.
|
|
215
|
-
*/
|
|
216
|
-
declare function removeKnownAccountFromCookie(headers: Headers, userId: string, existingCookie: string | null, options?: SessionCookieOptions): void;
|
|
217
|
-
/**
|
|
218
|
-
* Clear the known accounts cookie entirely.
|
|
219
|
-
*/
|
|
220
|
-
declare function clearKnownAccountsCookie(headers: Headers, options?: SessionCookieOptions): void;
|
|
221
|
-
/**
|
|
222
|
-
* Read known accounts from a Request's cookies.
|
|
223
|
-
*/
|
|
224
|
-
declare function getKnownAccountsFromRequest(request: Request): KnownAccountEntry[];
|
|
225
|
-
/**
|
|
226
|
-
* Read the raw known accounts cookie value from a Request.
|
|
227
|
-
*/
|
|
228
|
-
declare function getKnownAccountsCookieRaw(request: Request): string | null;
|
|
229
|
-
/**
|
|
230
|
-
* Normalize all entries in the known accounts cookie to the given privacy level.
|
|
231
|
-
* Returns a Set-Cookie header string if any entries changed, or null if nothing changed.
|
|
232
|
-
* Used on /me requests to migrate legacy full-PII cookies to the configured privacy level.
|
|
233
|
-
*/
|
|
234
|
-
declare function normalizeKnownAccountsCookie(request: Request, privacy: AccountSwitcherPrivacy | undefined, options?: SessionCookieOptions): string | null;
|
|
235
184
|
/**
|
|
236
185
|
* Require authentication - throws Response if not authenticated
|
|
237
186
|
*
|
|
@@ -271,19 +220,6 @@ interface AuthRoutesConfig {
|
|
|
271
220
|
cookies?: SessionCookieOptions;
|
|
272
221
|
/** Enable CSRF validation on state-changing requests (POST/DELETE/PATCH) */
|
|
273
222
|
csrf?: boolean;
|
|
274
|
-
/**
|
|
275
|
-
* Enable the account switcher — remembers which accounts have logged in on
|
|
276
|
-
* this device (metadata only, no tokens). Switching requires re-authentication.
|
|
277
|
-
* Adds routes: switch-account, forget-account, forget-all-accounts, known-accounts.
|
|
278
|
-
*/
|
|
279
|
-
enableAccountSwitcher?: boolean;
|
|
280
|
-
/**
|
|
281
|
-
* Privacy level for account switcher display metadata.
|
|
282
|
-
* - 'full': Store email, name, avatar as-is (default)
|
|
283
|
-
* - 'masked': Mask email, truncate name to initial
|
|
284
|
-
* - 'minimal': No PII — just a colored "Account" label
|
|
285
|
-
*/
|
|
286
|
-
accountSwitcherPrivacy?: 'full' | 'masked' | 'minimal';
|
|
287
223
|
/** Callbacks */
|
|
288
224
|
onLogin?: (user: {
|
|
289
225
|
id: string;
|
|
@@ -1075,4 +1011,4 @@ declare function invalidateBundleCache(key?: string): void;
|
|
|
1075
1011
|
*/
|
|
1076
1012
|
declare function prefetchBundles(keys: string[]): Promise<void>;
|
|
1077
1013
|
|
|
1078
|
-
export { type AnalyticsRoutesConfig, type AnalyticsTrackingGateConfig, type AuthMiddlewareConfig, type AuthRoutesConfig, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, type HandlerContext, type HandlerOptions,
|
|
1014
|
+
export { type AnalyticsRoutesConfig, type AnalyticsTrackingGateConfig, type AuthMiddlewareConfig, type AuthRoutesConfig, CSRF_COOKIE_NAME, CSRF_HEADER_NAME, type HandlerContext, type HandlerOptions, type MySqlBundle, type NotificationRoutesConfig, OAUTH_STATE_COOKIE_NAME, type OAuthBundle, type PostgresBundle, type PushRoutesConfig, type RedisBundle, type S3Bundle, SESSION_COOKIE_NAME, ScaleMuleError, ServerConfig, type SessionCookieOptions, type SessionData, type SmtpBundle, USER_ID_COOKIE_NAME, apiHandler, buildClientContextHeaders, buildFlagContext, clearOAuthState, clearSession, configureBundles, configureSecrets, createAnalyticsRoutes, createAuthMiddleware, createAuthRoutes, createNotificationRoutes, createPushRoutes, errorCodeToStatus, extractClientContext, extractClientContextFromReq, generateCSRFToken, getAppSecret, getAppSecretOrDefault, getBootstrapFlags, getBundle, getCSRFToken, getMySqlBundle, getOAuthBundle, getPostgresBundle, getRedisBundle, getS3Bundle, getSession, getSessionFromRequest, getSmtpBundle, invalidateBundleCache, invalidateSecretCache, prefetchBundles, prefetchSecrets, requireAppSecret, requireBundle, requireSession, setOAuthState, unwrap, validateCSRFToken, validateCSRFTokenAsync, validateOAuthState, validateOAuthStateAsync, withAuth, withCSRFProtection, withCSRFToken, withSession };
|