@scalemule/nextjs 0.1.51 → 0.1.53
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/README.md +51 -5
- package/dist/client.d.mts +6 -1
- package/dist/client.d.ts +6 -1
- package/dist/client.js +24 -4
- package/dist/client.mjs +24 -4
- package/dist/{index-BQgmT53x.d.mts → index-2PnO4RAF.d.mts} +19 -5
- package/dist/{index-BQgmT53x.d.ts → index-2PnO4RAF.d.ts} +19 -5
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +136 -48
- package/dist/index.mjs +136 -48
- package/dist/server/auth.d.mts +7 -2
- package/dist/server/auth.d.ts +7 -2
- package/dist/server/auth.js +260 -39
- package/dist/server/auth.mjs +260 -40
- package/dist/server/index.d.mts +24 -5
- package/dist/server/index.d.ts +24 -5
- package/dist/server/index.js +286 -66
- package/dist/server/index.mjs +286 -66
- 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-44RRJH-r.d.ts → webhook-handler-1nnrmWT0.d.ts} +11 -1
- package/dist/{webhook-handler-DKt6H8FB.d.mts → webhook-handler-DNpCXDDA.d.mts} +11 -1
- package/docs/network-audio.md +10 -5
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -43,7 +43,7 @@ function useSecurityChallenge(recoveryUrl) {
|
|
|
43
43
|
event.preventDefault();
|
|
44
44
|
answer(null);
|
|
45
45
|
},
|
|
46
|
-
style: { border: "1px solid #d1d5db", borderRadius: 16, padding: 28, maxWidth: 420, width: "calc(100% - 48px)", color: "
|
|
46
|
+
style: { border: "1px solid var(--sm-security-border, var(--site-hairline, #d1d5db))", borderRadius: 16, padding: 28, maxWidth: 420, width: "calc(100% - 48px)", color: "var(--sm-security-text, var(--site-ink, CanvasText))", background: "var(--sm-security-background, var(--site-bg-elevated, Canvas))", colorScheme: "light dark", boxSizing: "border-box" },
|
|
47
47
|
children: /* @__PURE__ */ jsxs("form", { onSubmit: (event) => {
|
|
48
48
|
event.preventDefault();
|
|
49
49
|
if (code.trim()) answer(code.trim());
|
|
@@ -63,10 +63,10 @@ function useSecurityChallenge(recoveryUrl) {
|
|
|
63
63
|
onChange: (event) => setCode(event.target.value),
|
|
64
64
|
maxLength: 32,
|
|
65
65
|
required: true,
|
|
66
|
-
style: { display: "block", boxSizing: "border-box", width: "100%", margin: "8px 0 20px", padding: 12, fontSize: 22, border: "1px solid #9ca3af", borderRadius: 8 }
|
|
66
|
+
style: { display: "block", boxSizing: "border-box", width: "100%", margin: "8px 0 20px", padding: 12, fontSize: 22, border: "1px solid var(--sm-security-border, var(--site-hairline-strong, #9ca3af))", background: "inherit", color: "inherit", borderRadius: 8 }
|
|
67
67
|
}
|
|
68
68
|
),
|
|
69
|
-
/* @__PURE__ */ jsx("button", { type: "submit", style: { padding: "10px 20px", borderRadius: 8, border: 0, background: "#2563eb", color: "#fff", cursor: "pointer" }, children: "Continue" }),
|
|
69
|
+
/* @__PURE__ */ jsx("button", { type: "submit", style: { padding: "10px 20px", borderRadius: 8, border: 0, background: "var(--sm-security-accent, var(--site-accent, #2563eb))", color: "#fff", cursor: "pointer" }, children: "Continue" }),
|
|
70
70
|
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => answer(null), style: { marginLeft: 12 }, children: "Cancel" }),
|
|
71
71
|
challenge.method !== "totp" && /* @__PURE__ */ jsxs("p", { children: [
|
|
72
72
|
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => answer("resend"), children: "Send a new code" }),
|
|
@@ -93,8 +93,16 @@ async function withAdaptiveChallenge(attempt, prompt, mfa) {
|
|
|
93
93
|
const token = details.pending_token;
|
|
94
94
|
const method = details.mfa_method;
|
|
95
95
|
if (!token || !["totp", "email", "sms"].includes(method || "")) throw error;
|
|
96
|
-
if (method !== "totp") await mfa.send(token, method);
|
|
97
96
|
let mfaError;
|
|
97
|
+
if (method !== "totp") {
|
|
98
|
+
try {
|
|
99
|
+
await mfa.send(token, method);
|
|
100
|
+
} catch (failure) {
|
|
101
|
+
const failed = failure;
|
|
102
|
+
if (failed.code !== "CHALLENGE_RATE_LIMITED") throw failure;
|
|
103
|
+
mfaError = failed.message;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
98
106
|
for (; ; ) {
|
|
99
107
|
const code2 = await prompt({ method, error: mfaError });
|
|
100
108
|
if (code2 === null) throw { code: "LOGIN_CANCELLED", message: "Sign-in was cancelled." };
|
|
@@ -439,6 +447,7 @@ var ScaleMuleClient = class {
|
|
|
439
447
|
// The shared helper also single-flights at the storage-adapter level.
|
|
440
448
|
this.anonymousIdPromise = null;
|
|
441
449
|
this.refreshPromise = null;
|
|
450
|
+
this.cookieSession = config.cookieSession === true;
|
|
442
451
|
this.apiKey = config.apiKey;
|
|
443
452
|
this.applicationId = config.applicationId || null;
|
|
444
453
|
this.gatewayUrl = resolveGatewayUrl(config);
|
|
@@ -568,8 +577,13 @@ var ScaleMuleClient = class {
|
|
|
568
577
|
* Initialize client by loading persisted session
|
|
569
578
|
*/
|
|
570
579
|
async initialize() {
|
|
571
|
-
|
|
572
|
-
|
|
580
|
+
if (this.cookieSession) {
|
|
581
|
+
await this.storage.removeItem(SESSION_STORAGE_KEY);
|
|
582
|
+
await this.storage.removeItem(STORAGE_KEYS.SESSION_POOL);
|
|
583
|
+
await this.storage.removeItem(STORAGE_KEYS.ACTIVE_ACCOUNT);
|
|
584
|
+
}
|
|
585
|
+
const token = this.cookieSession ? null : await this.storage.getItem(SESSION_STORAGE_KEY);
|
|
586
|
+
const userId = this.cookieSession ? null : await this.storage.getItem(USER_ID_STORAGE_KEY);
|
|
573
587
|
if (token) this.sessionToken = token;
|
|
574
588
|
if (userId) this.userId = userId;
|
|
575
589
|
const wsId = await this.storage.getItem(WORKSPACE_STORAGE_KEY);
|
|
@@ -615,6 +629,11 @@ var ScaleMuleClient = class {
|
|
|
615
629
|
* Set session after login
|
|
616
630
|
*/
|
|
617
631
|
async setSession(token, userId) {
|
|
632
|
+
if (this.cookieSession) {
|
|
633
|
+
this.setCookieSession(userId);
|
|
634
|
+
await this.storage.removeItem(SESSION_STORAGE_KEY);
|
|
635
|
+
return;
|
|
636
|
+
}
|
|
618
637
|
this.sessionToken = token;
|
|
619
638
|
this.userId = userId;
|
|
620
639
|
await this.storage.setItem(SESSION_STORAGE_KEY, token);
|
|
@@ -635,8 +654,17 @@ var ScaleMuleClient = class {
|
|
|
635
654
|
*
|
|
636
655
|
* Pass `null` to clear without touching userId/storage.
|
|
637
656
|
*/
|
|
657
|
+
setCookieSession(userId) {
|
|
658
|
+
if (!this.cookieSession) return;
|
|
659
|
+
this.sessionToken = null;
|
|
660
|
+
this.userId = userId;
|
|
661
|
+
this.resolveSessionPending();
|
|
662
|
+
}
|
|
663
|
+
usesCookieSession() {
|
|
664
|
+
return this.cookieSession;
|
|
665
|
+
}
|
|
638
666
|
setSessionToken(token) {
|
|
639
|
-
this.sessionToken = token;
|
|
667
|
+
this.sessionToken = this.cookieSession ? null : token;
|
|
640
668
|
if (this.debug) {
|
|
641
669
|
console.log("[ScaleMule] Session token", token ? "set (token-only)" : "cleared (token-only)");
|
|
642
670
|
}
|
|
@@ -671,7 +699,7 @@ var ScaleMuleClient = class {
|
|
|
671
699
|
* Check if client has an active session
|
|
672
700
|
*/
|
|
673
701
|
isAuthenticated() {
|
|
674
|
-
return this.sessionToken !== null && this.userId !== null;
|
|
702
|
+
return (this.cookieSession || this.sessionToken !== null) && this.userId !== null;
|
|
675
703
|
}
|
|
676
704
|
/**
|
|
677
705
|
* Build headers for a request
|
|
@@ -1109,6 +1137,7 @@ function ScaleMuleProvider({
|
|
|
1109
1137
|
storage,
|
|
1110
1138
|
analyticsProxyUrl,
|
|
1111
1139
|
authProxyUrl,
|
|
1140
|
+
sessionMode,
|
|
1112
1141
|
telemetryEndpoint,
|
|
1113
1142
|
publishableKey,
|
|
1114
1143
|
enableAccountSwitcher,
|
|
@@ -1128,6 +1157,9 @@ function ScaleMuleProvider({
|
|
|
1128
1157
|
const security = useSecurityChallenge(passwordRecoveryUrl);
|
|
1129
1158
|
const requestSecurityCode = onSecurityChallenge || security.prompt;
|
|
1130
1159
|
const memberMode = typeof getToken === "function";
|
|
1160
|
+
const cookieSession = !!authProxyUrl && !memberMode && sessionMode !== "bearer";
|
|
1161
|
+
const browserKey = cookieSession ? publishableKey || process.env.NEXT_PUBLIC_SCALEMULE_PUBLISHABLE_KEY || apiKey : apiKey;
|
|
1162
|
+
const browserGateway = cookieSession ? `${authProxyUrl.replace(/\/$/, "")}/client` : void 0;
|
|
1131
1163
|
const [user, setUser] = useState(null);
|
|
1132
1164
|
const [initializing, setInitializing] = useState(true);
|
|
1133
1165
|
const [error, setError] = useState(null);
|
|
@@ -1138,10 +1170,11 @@ function ScaleMuleProvider({
|
|
|
1138
1170
|
const resolvedGatewayUrl = gatewayUrl || (environment === "dev" ? "https://api-dev.scalemule.com" : "https://api.scalemule.com");
|
|
1139
1171
|
const client = useMemo(
|
|
1140
1172
|
() => createClient({
|
|
1141
|
-
apiKey,
|
|
1173
|
+
apiKey: browserKey,
|
|
1142
1174
|
applicationId,
|
|
1143
1175
|
environment,
|
|
1144
|
-
gatewayUrl: resolvedGatewayUrl,
|
|
1176
|
+
gatewayUrl: browserGateway || resolvedGatewayUrl,
|
|
1177
|
+
cookieSession,
|
|
1145
1178
|
debug,
|
|
1146
1179
|
storage,
|
|
1147
1180
|
// Make outbound API calls wait for the first token to land in any
|
|
@@ -1150,27 +1183,28 @@ function ScaleMuleProvider({
|
|
|
1150
1183
|
// getToken() callback. Resolved in the init effect below.
|
|
1151
1184
|
pendingSessionInit: !!authProxyUrl || memberMode
|
|
1152
1185
|
}),
|
|
1153
|
-
[
|
|
1186
|
+
[browserKey, applicationId, environment, resolvedGatewayUrl, browserGateway, cookieSession, debug, storage, authProxyUrl, memberMode]
|
|
1154
1187
|
);
|
|
1155
1188
|
const money = useMemo(
|
|
1156
1189
|
() => createMoneyClient({
|
|
1157
|
-
apiKey,
|
|
1158
|
-
gatewayUrl: resolvedGatewayUrl,
|
|
1190
|
+
apiKey: browserKey,
|
|
1191
|
+
gatewayUrl: browserGateway || resolvedGatewayUrl,
|
|
1159
1192
|
environment,
|
|
1160
1193
|
accessToken: client.getSessionToken() || void 0,
|
|
1161
1194
|
fetch: globalThis.fetch.bind(globalThis)
|
|
1162
1195
|
}),
|
|
1163
|
-
[
|
|
1196
|
+
[browserKey, resolvedGatewayUrl, browserGateway, environment, client]
|
|
1164
1197
|
);
|
|
1165
1198
|
const baseClient = useMemo(() => {
|
|
1166
1199
|
return new ScaleMule({
|
|
1167
|
-
apiKey,
|
|
1200
|
+
apiKey: browserKey,
|
|
1168
1201
|
applicationId,
|
|
1169
|
-
baseUrl: resolvedGatewayUrl,
|
|
1202
|
+
baseUrl: browserGateway || resolvedGatewayUrl,
|
|
1203
|
+
realtimeUrl: cookieSession ? resolvedGatewayUrl : void 0,
|
|
1170
1204
|
environment,
|
|
1171
1205
|
debug
|
|
1172
1206
|
});
|
|
1173
|
-
}, [
|
|
1207
|
+
}, [browserKey, applicationId, environment, resolvedGatewayUrl, browserGateway, cookieSession, debug]);
|
|
1174
1208
|
const [fetchedPolicy, setFetchedPolicy] = useState(void 0);
|
|
1175
1209
|
const [tokenVersion, setTokenVersion] = useState(0);
|
|
1176
1210
|
useEffect(() => {
|
|
@@ -1260,18 +1294,21 @@ function ScaleMuleProvider({
|
|
|
1260
1294
|
const data = await response.json();
|
|
1261
1295
|
if (mounted) {
|
|
1262
1296
|
if (data.success && data.data?.user) {
|
|
1297
|
+
client.setCookieSession(data.data.user.id);
|
|
1263
1298
|
setUser(data.data.user);
|
|
1264
1299
|
setCachedUser(data.data.user);
|
|
1265
1300
|
if (data.data.sessionToken) {
|
|
1266
1301
|
await client.setSession(data.data.sessionToken, data.data.userId || "");
|
|
1267
1302
|
}
|
|
1268
1303
|
} else {
|
|
1304
|
+
client.setCookieSession(null);
|
|
1269
1305
|
setUser(null);
|
|
1270
1306
|
setCachedUser(null);
|
|
1271
1307
|
}
|
|
1272
1308
|
}
|
|
1273
1309
|
} catch {
|
|
1274
1310
|
if (mounted) {
|
|
1311
|
+
client.setCookieSession(null);
|
|
1275
1312
|
setUser(null);
|
|
1276
1313
|
setCachedUser(null);
|
|
1277
1314
|
if (debug) {
|
|
@@ -1358,13 +1395,15 @@ function ScaleMuleProvider({
|
|
|
1358
1395
|
}, [memberMode, memberTokenPollMs, getToken, client, baseClient, money, debug]);
|
|
1359
1396
|
const handleSetUser = useCallback(
|
|
1360
1397
|
(newUser) => {
|
|
1398
|
+
client.setCookieSession(newUser?.id || null);
|
|
1399
|
+
if (!newUser) baseClient.realtime.disconnect();
|
|
1361
1400
|
setUser(newUser);
|
|
1362
1401
|
setCachedUser(newUser);
|
|
1363
1402
|
if (newUser === null && onLogout) {
|
|
1364
1403
|
onLogout();
|
|
1365
1404
|
}
|
|
1366
1405
|
},
|
|
1367
|
-
[onLogout]
|
|
1406
|
+
[onLogout, client, baseClient]
|
|
1368
1407
|
);
|
|
1369
1408
|
const value = useMemo(
|
|
1370
1409
|
() => ({
|
|
@@ -1388,7 +1427,7 @@ function ScaleMuleProvider({
|
|
|
1388
1427
|
setError,
|
|
1389
1428
|
analyticsProxyUrl,
|
|
1390
1429
|
authProxyUrl,
|
|
1391
|
-
publishableKey,
|
|
1430
|
+
publishableKey: cookieSession ? browserKey : publishableKey,
|
|
1392
1431
|
apiKey,
|
|
1393
1432
|
gatewayUrl: resolvedGatewayUrl,
|
|
1394
1433
|
environment: environment || void 0,
|
|
@@ -1396,7 +1435,7 @@ function ScaleMuleProvider({
|
|
|
1396
1435
|
accountSwitcherPrivacy,
|
|
1397
1436
|
bootstrapFlags
|
|
1398
1437
|
}),
|
|
1399
|
-
[requestSecurityCode, client, money, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, apiKey, resolvedGatewayUrl, environment, enableAccountSwitcher, accountSwitcherPrivacy, bootstrapFlags, effectiveMediaPolicy]
|
|
1438
|
+
[requestSecurityCode, client, money, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, browserKey, cookieSession, apiKey, resolvedGatewayUrl, environment, enableAccountSwitcher, accountSwitcherPrivacy, bootstrapFlags, effectiveMediaPolicy]
|
|
1400
1439
|
);
|
|
1401
1440
|
return /* @__PURE__ */ jsxs(ScaleMuleContext.Provider, { value, children: [
|
|
1402
1441
|
children,
|
|
@@ -1420,6 +1459,9 @@ function useMoneyClient() {
|
|
|
1420
1459
|
const { money } = useScaleMule();
|
|
1421
1460
|
return money;
|
|
1422
1461
|
}
|
|
1462
|
+
function cookieLoginResult(user) {
|
|
1463
|
+
return { authenticated: true, userId: user.id, user };
|
|
1464
|
+
}
|
|
1423
1465
|
function maskEmail(email) {
|
|
1424
1466
|
const [local, domain] = email.split("@");
|
|
1425
1467
|
if (!domain) return "***@***.***";
|
|
@@ -1475,7 +1517,7 @@ async function getProxyAnonymousId() {
|
|
|
1475
1517
|
}
|
|
1476
1518
|
async function proxyFetch(proxyUrl, path, options = {}) {
|
|
1477
1519
|
const method = options.method || "POST";
|
|
1478
|
-
const headers = {};
|
|
1520
|
+
const headers = { "Content-Type": "application/json" };
|
|
1479
1521
|
if (options.body) {
|
|
1480
1522
|
headers["Content-Type"] = "application/json";
|
|
1481
1523
|
}
|
|
@@ -1534,7 +1576,7 @@ function useAuth() {
|
|
|
1534
1576
|
if (response.data.sessionToken) {
|
|
1535
1577
|
await client.setSession(response.data.sessionToken, response.data.userId || response.data.user?.id || "");
|
|
1536
1578
|
}
|
|
1537
|
-
if (response.data.user) {
|
|
1579
|
+
if (response.data.user && response.data.authenticated !== false) {
|
|
1538
1580
|
setUser(response.data.user);
|
|
1539
1581
|
}
|
|
1540
1582
|
return response.data.user;
|
|
@@ -1584,15 +1626,16 @@ function useAuth() {
|
|
|
1584
1626
|
}
|
|
1585
1627
|
const loginData2 = response.data;
|
|
1586
1628
|
const responseUser = "user" in loginData2 ? loginData2.user : null;
|
|
1587
|
-
if (responseUser) {
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
if (sessionToken) {
|
|
1593
|
-
await client.setSession(sessionToken, userId || responseUser?.id || "");
|
|
1629
|
+
if (!responseUser) throw new ScaleMuleApiError({ code: "LOGIN_FAILED", message: "Sign-in did not return a user" });
|
|
1630
|
+
setUser(responseUser);
|
|
1631
|
+
if (client.usesCookieSession()) {
|
|
1632
|
+
client.setCookieSession(responseUser.id);
|
|
1633
|
+
return cookieLoginResult(responseUser);
|
|
1594
1634
|
}
|
|
1595
|
-
|
|
1635
|
+
const sessionToken = loginData2.sessionToken || loginData2.session_token;
|
|
1636
|
+
if (!sessionToken) throw new ScaleMuleApiError({ code: "LOGIN_FAILED", message: "Sign-in did not return a session" });
|
|
1637
|
+
await client.setSession(sessionToken, loginData2.userId || responseUser.id);
|
|
1638
|
+
return { ...loginData2, session_token: sessionToken };
|
|
1596
1639
|
}
|
|
1597
1640
|
let loginResult;
|
|
1598
1641
|
try {
|
|
@@ -1623,6 +1666,7 @@ function useAuth() {
|
|
|
1623
1666
|
await proxyFetch(authProxyUrl, "logout");
|
|
1624
1667
|
} catch {
|
|
1625
1668
|
}
|
|
1669
|
+
await client.clearSession();
|
|
1626
1670
|
setUser(null);
|
|
1627
1671
|
return;
|
|
1628
1672
|
}
|
|
@@ -1797,6 +1841,9 @@ function useAuth() {
|
|
|
1797
1841
|
setError(err);
|
|
1798
1842
|
throw err;
|
|
1799
1843
|
}
|
|
1844
|
+
if (!client.usesCookieSession() && response.data?.sessionToken && response.data.userId) {
|
|
1845
|
+
await client.setSession(response.data.sessionToken, response.data.userId);
|
|
1846
|
+
}
|
|
1800
1847
|
if (response.data?.user) {
|
|
1801
1848
|
setUser(response.data.user);
|
|
1802
1849
|
}
|
|
@@ -1877,7 +1924,8 @@ function useAuth() {
|
|
|
1877
1924
|
}
|
|
1878
1925
|
throw err;
|
|
1879
1926
|
}
|
|
1880
|
-
|
|
1927
|
+
if (client.usesCookieSession()) client.setCookieSession(callbackData.user.id);
|
|
1928
|
+
else if ("session_token" in callbackData) await client.setSession(callbackData.session_token, callbackData.user.id);
|
|
1881
1929
|
setUser(callbackData.user);
|
|
1882
1930
|
return callbackData;
|
|
1883
1931
|
},
|
|
@@ -1979,7 +2027,16 @@ function useAuth() {
|
|
|
1979
2027
|
if (authProxyUrl) {
|
|
1980
2028
|
const result = await proxyFetch(authProxyUrl, "mfa/verify", { body: { pending_token: challengeToken, code, method } });
|
|
1981
2029
|
if (!result.success || !result.data) throw result.error;
|
|
1982
|
-
|
|
2030
|
+
const sessionToken = result.data.sessionToken || result.data.session_token;
|
|
2031
|
+
if (client.usesCookieSession() && result.data.user) {
|
|
2032
|
+
client.setCookieSession(result.data.user.id);
|
|
2033
|
+
setUser(result.data.user);
|
|
2034
|
+
return cookieLoginResult(result.data.user);
|
|
2035
|
+
}
|
|
2036
|
+
if (!sessionToken) throw new ScaleMuleApiError({ code: "MFA_FAILED", message: "Sign-in did not return a session" });
|
|
2037
|
+
await client.setSession(sessionToken, result.data.user.id);
|
|
2038
|
+
setUser(result.data.user);
|
|
2039
|
+
return { ...result.data, session_token: sessionToken };
|
|
1983
2040
|
} else {
|
|
1984
2041
|
mfaResult = await client.post("/v1/auth/mfa/verify", { pending_token: challengeToken, code, method });
|
|
1985
2042
|
}
|
|
@@ -2111,15 +2168,16 @@ function useAuth() {
|
|
|
2111
2168
|
}
|
|
2112
2169
|
const loginData = response.data;
|
|
2113
2170
|
const responseUser = "user" in loginData ? loginData.user : null;
|
|
2114
|
-
if (responseUser) {
|
|
2115
|
-
|
|
2171
|
+
if (!responseUser) throw new ScaleMuleApiError({ code: "LOGIN_FAILED", message: "Sign-in did not return a user" });
|
|
2172
|
+
setUser(responseUser);
|
|
2173
|
+
if (client.usesCookieSession()) {
|
|
2174
|
+
client.setCookieSession(responseUser.id);
|
|
2175
|
+
return cookieLoginResult(responseUser);
|
|
2116
2176
|
}
|
|
2117
|
-
const sessionToken =
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
}
|
|
2122
|
-
return response.data;
|
|
2177
|
+
const sessionToken = loginData.sessionToken || loginData.session_token;
|
|
2178
|
+
if (!sessionToken) throw new ScaleMuleApiError({ code: "LOGIN_FAILED", message: "Sign-in did not return a session" });
|
|
2179
|
+
await client.setSession(sessionToken, loginData.userId || responseUser.id);
|
|
2180
|
+
return { ...loginData, session_token: sessionToken };
|
|
2123
2181
|
}
|
|
2124
2182
|
let phoneLoginData;
|
|
2125
2183
|
try {
|
|
@@ -2163,6 +2221,7 @@ function useAuth() {
|
|
|
2163
2221
|
if (!target) return null;
|
|
2164
2222
|
if (authProxyUrl) {
|
|
2165
2223
|
await proxyFetch(authProxyUrl, "switch-account");
|
|
2224
|
+
await client.clearSession();
|
|
2166
2225
|
} else {
|
|
2167
2226
|
const sessionToken = client.getSessionToken();
|
|
2168
2227
|
if (sessionToken) {
|
|
@@ -3909,6 +3968,34 @@ function useRealtime(options) {
|
|
|
3909
3968
|
return { status, lastMessage, disconnect, subscribe, publish };
|
|
3910
3969
|
}
|
|
3911
3970
|
|
|
3971
|
+
// src/url-privacy.ts
|
|
3972
|
+
function withoutAuthSecrets(value) {
|
|
3973
|
+
if (!value) return value;
|
|
3974
|
+
try {
|
|
3975
|
+
const absolute = /^[a-z][a-z0-9+.-]*:/i.test(value);
|
|
3976
|
+
const protocolRelative = value.startsWith("//");
|
|
3977
|
+
const url = new URL(value, "https://relative.invalid");
|
|
3978
|
+
if (!["http:", "https:"].includes(url.protocol)) return void 0;
|
|
3979
|
+
let changed = false;
|
|
3980
|
+
for (const name of [...url.searchParams.keys()]) {
|
|
3981
|
+
if (/^(token|code|state|password|new_password|access_token|refresh_token|id_token|api_key|client_secret|challenge_token|challenge_code)$/i.test(name)) {
|
|
3982
|
+
url.searchParams.delete(name);
|
|
3983
|
+
changed = true;
|
|
3984
|
+
}
|
|
3985
|
+
}
|
|
3986
|
+
if (url.hash) {
|
|
3987
|
+
url.hash = "";
|
|
3988
|
+
changed = true;
|
|
3989
|
+
}
|
|
3990
|
+
if (!changed) return value;
|
|
3991
|
+
if (absolute) return url.toString();
|
|
3992
|
+
if (protocolRelative) return url.toString().replace(/^https:/, "");
|
|
3993
|
+
return value.split(/[?#]/, 1)[0] + url.search;
|
|
3994
|
+
} catch {
|
|
3995
|
+
return void 0;
|
|
3996
|
+
}
|
|
3997
|
+
}
|
|
3998
|
+
|
|
3912
3999
|
// src/hooks/event-dedup.ts
|
|
3913
4000
|
var DEFAULT_EVENT_DEDUP_MS = 300;
|
|
3914
4001
|
var DEDUP_MAP_MAX = 200;
|
|
@@ -4178,19 +4265,20 @@ function useAnalytics(options = {}) {
|
|
|
4178
4265
|
if (utm) setUtmParams(utm);
|
|
4179
4266
|
}
|
|
4180
4267
|
if (!landingPage.current) {
|
|
4181
|
-
landingPage.current = window.location.href;
|
|
4268
|
+
landingPage.current = withoutAuthSecrets(window.location.href) || null;
|
|
4182
4269
|
}
|
|
4183
4270
|
const storage = typeof sessionStorage !== "undefined" ? sessionStorage : void 0;
|
|
4184
4271
|
const storedReferrer = getStorageItem(storage, SESSION_REFERRER_KEY);
|
|
4185
4272
|
if (storedReferrer) {
|
|
4186
|
-
originalReferrerRef.current = storedReferrer;
|
|
4273
|
+
originalReferrerRef.current = withoutAuthSecrets(storedReferrer) || null;
|
|
4274
|
+
setStorageItem(storage, SESSION_REFERRER_KEY, originalReferrerRef.current || "");
|
|
4187
4275
|
} else if (document.referrer) {
|
|
4188
4276
|
try {
|
|
4189
4277
|
const referrerUrl = new URL(document.referrer);
|
|
4190
4278
|
const currentUrl = new URL(window.location.href);
|
|
4191
4279
|
if (referrerUrl.hostname !== currentUrl.hostname) {
|
|
4192
|
-
originalReferrerRef.current = document.referrer;
|
|
4193
|
-
setStorageItem(storage, SESSION_REFERRER_KEY, document.referrer);
|
|
4280
|
+
originalReferrerRef.current = withoutAuthSecrets(document.referrer) || null;
|
|
4281
|
+
setStorageItem(storage, SESSION_REFERRER_KEY, withoutAuthSecrets(document.referrer) || "");
|
|
4194
4282
|
}
|
|
4195
4283
|
} catch {
|
|
4196
4284
|
}
|
|
@@ -4230,10 +4318,10 @@ function useAnalytics(options = {}) {
|
|
|
4230
4318
|
session_duration_seconds: Math.floor((Date.now() - sessionStartRef.current) / 1e3)
|
|
4231
4319
|
};
|
|
4232
4320
|
if (typeof window !== "undefined") {
|
|
4233
|
-
fullEvent.page_url = window.location.href;
|
|
4321
|
+
fullEvent.page_url = withoutAuthSecrets(window.location.href);
|
|
4234
4322
|
fullEvent.page_title = document.title;
|
|
4235
4323
|
fullEvent.referrer = originalReferrerRef.current || void 0;
|
|
4236
|
-
fullEvent.document_referrer = document.referrer || void 0;
|
|
4324
|
+
fullEvent.document_referrer = withoutAuthSecrets(document.referrer) || void 0;
|
|
4237
4325
|
}
|
|
4238
4326
|
return fullEvent;
|
|
4239
4327
|
},
|
|
@@ -4316,9 +4404,9 @@ function useAnalytics(options = {}) {
|
|
|
4316
4404
|
event_category: "navigation",
|
|
4317
4405
|
properties: {
|
|
4318
4406
|
...data?.properties || {},
|
|
4319
|
-
page_url: data?.page_url || (typeof window !== "undefined" ? window.location.href : void 0),
|
|
4407
|
+
page_url: withoutAuthSecrets(data?.page_url || (typeof window !== "undefined" ? window.location.href : void 0)),
|
|
4320
4408
|
page_title: data?.page_title || (typeof document !== "undefined" ? document.title : void 0),
|
|
4321
|
-
referrer: data?.referrer || originalReferrerRef.current || void 0
|
|
4409
|
+
referrer: withoutAuthSecrets(data?.referrer || originalReferrerRef.current || void 0)
|
|
4322
4410
|
}
|
|
4323
4411
|
};
|
|
4324
4412
|
return trackEvent(pageEvent);
|
package/dist/server/auth.d.mts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Usage in your Next.js app:
|
|
5
5
|
* ```ts
|
|
6
6
|
* // app/api/auth/[...scalemule]/route.ts
|
|
7
|
-
* export { GET, POST, DELETE, PATCH } from '@scalemule/nextjs/server/auth'
|
|
7
|
+
* export { GET, POST, DELETE, PATCH, PUT } from '@scalemule/nextjs/server/auth'
|
|
8
8
|
* ```
|
|
9
9
|
*
|
|
10
10
|
* Configuration via environment variables:
|
|
@@ -34,5 +34,10 @@ declare const PATCH: (request: Request, context: {
|
|
|
34
34
|
scalemule?: string[];
|
|
35
35
|
}>;
|
|
36
36
|
}) => Promise<Response>;
|
|
37
|
+
declare const PUT: (request: Request, context: {
|
|
38
|
+
params: Promise<{
|
|
39
|
+
scalemule?: string[];
|
|
40
|
+
}>;
|
|
41
|
+
}) => Promise<Response>;
|
|
37
42
|
|
|
38
|
-
export { DELETE, GET, PATCH, POST };
|
|
43
|
+
export { DELETE, GET, PATCH, POST, PUT };
|
package/dist/server/auth.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Usage in your Next.js app:
|
|
5
5
|
* ```ts
|
|
6
6
|
* // app/api/auth/[...scalemule]/route.ts
|
|
7
|
-
* export { GET, POST, DELETE, PATCH } from '@scalemule/nextjs/server/auth'
|
|
7
|
+
* export { GET, POST, DELETE, PATCH, PUT } from '@scalemule/nextjs/server/auth'
|
|
8
8
|
* ```
|
|
9
9
|
*
|
|
10
10
|
* Configuration via environment variables:
|
|
@@ -34,5 +34,10 @@ declare const PATCH: (request: Request, context: {
|
|
|
34
34
|
scalemule?: string[];
|
|
35
35
|
}>;
|
|
36
36
|
}) => Promise<Response>;
|
|
37
|
+
declare const PUT: (request: Request, context: {
|
|
38
|
+
params: Promise<{
|
|
39
|
+
scalemule?: string[];
|
|
40
|
+
}>;
|
|
41
|
+
}) => Promise<Response>;
|
|
37
42
|
|
|
38
|
-
export { DELETE, GET, PATCH, POST };
|
|
43
|
+
export { DELETE, GET, PATCH, POST, PUT };
|