@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.js
CHANGED
|
@@ -63,7 +63,7 @@ function useSecurityChallenge(recoveryUrl) {
|
|
|
63
63
|
event.preventDefault();
|
|
64
64
|
answer(null);
|
|
65
65
|
},
|
|
66
|
-
style: { border: "1px solid #d1d5db", borderRadius: 16, padding: 28, maxWidth: 420, width: "calc(100% - 48px)", color: "
|
|
66
|
+
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" },
|
|
67
67
|
children: /* @__PURE__ */ jsxRuntime.jsxs("form", { onSubmit: (event) => {
|
|
68
68
|
event.preventDefault();
|
|
69
69
|
if (code.trim()) answer(code.trim());
|
|
@@ -83,10 +83,10 @@ function useSecurityChallenge(recoveryUrl) {
|
|
|
83
83
|
onChange: (event) => setCode(event.target.value),
|
|
84
84
|
maxLength: 32,
|
|
85
85
|
required: true,
|
|
86
|
-
style: { display: "block", boxSizing: "border-box", width: "100%", margin: "8px 0 20px", padding: 12, fontSize: 22, border: "1px solid #9ca3af", borderRadius: 8 }
|
|
86
|
+
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 }
|
|
87
87
|
}
|
|
88
88
|
),
|
|
89
|
-
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "submit", style: { padding: "10px 20px", borderRadius: 8, border: 0, background: "#2563eb", color: "#fff", cursor: "pointer" }, children: "Continue" }),
|
|
89
|
+
/* @__PURE__ */ jsxRuntime.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" }),
|
|
90
90
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => answer(null), style: { marginLeft: 12 }, children: "Cancel" }),
|
|
91
91
|
challenge.method !== "totp" && /* @__PURE__ */ jsxRuntime.jsxs("p", { children: [
|
|
92
92
|
/* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", onClick: () => answer("resend"), children: "Send a new code" }),
|
|
@@ -113,8 +113,16 @@ async function withAdaptiveChallenge(attempt, prompt, mfa) {
|
|
|
113
113
|
const token = details.pending_token;
|
|
114
114
|
const method = details.mfa_method;
|
|
115
115
|
if (!token || !["totp", "email", "sms"].includes(method || "")) throw error;
|
|
116
|
-
if (method !== "totp") await mfa.send(token, method);
|
|
117
116
|
let mfaError;
|
|
117
|
+
if (method !== "totp") {
|
|
118
|
+
try {
|
|
119
|
+
await mfa.send(token, method);
|
|
120
|
+
} catch (failure) {
|
|
121
|
+
const failed = failure;
|
|
122
|
+
if (failed.code !== "CHALLENGE_RATE_LIMITED") throw failure;
|
|
123
|
+
mfaError = failed.message;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
118
126
|
for (; ; ) {
|
|
119
127
|
const code2 = await prompt({ method, error: mfaError });
|
|
120
128
|
if (code2 === null) throw { code: "LOGIN_CANCELLED", message: "Sign-in was cancelled." };
|
|
@@ -459,6 +467,7 @@ var ScaleMuleClient = class {
|
|
|
459
467
|
// The shared helper also single-flights at the storage-adapter level.
|
|
460
468
|
this.anonymousIdPromise = null;
|
|
461
469
|
this.refreshPromise = null;
|
|
470
|
+
this.cookieSession = config.cookieSession === true;
|
|
462
471
|
this.apiKey = config.apiKey;
|
|
463
472
|
this.applicationId = config.applicationId || null;
|
|
464
473
|
this.gatewayUrl = resolveGatewayUrl(config);
|
|
@@ -588,8 +597,13 @@ var ScaleMuleClient = class {
|
|
|
588
597
|
* Initialize client by loading persisted session
|
|
589
598
|
*/
|
|
590
599
|
async initialize() {
|
|
591
|
-
|
|
592
|
-
|
|
600
|
+
if (this.cookieSession) {
|
|
601
|
+
await this.storage.removeItem(SESSION_STORAGE_KEY);
|
|
602
|
+
await this.storage.removeItem(sdk.STORAGE_KEYS.SESSION_POOL);
|
|
603
|
+
await this.storage.removeItem(sdk.STORAGE_KEYS.ACTIVE_ACCOUNT);
|
|
604
|
+
}
|
|
605
|
+
const token = this.cookieSession ? null : await this.storage.getItem(SESSION_STORAGE_KEY);
|
|
606
|
+
const userId = this.cookieSession ? null : await this.storage.getItem(USER_ID_STORAGE_KEY);
|
|
593
607
|
if (token) this.sessionToken = token;
|
|
594
608
|
if (userId) this.userId = userId;
|
|
595
609
|
const wsId = await this.storage.getItem(WORKSPACE_STORAGE_KEY);
|
|
@@ -635,6 +649,11 @@ var ScaleMuleClient = class {
|
|
|
635
649
|
* Set session after login
|
|
636
650
|
*/
|
|
637
651
|
async setSession(token, userId) {
|
|
652
|
+
if (this.cookieSession) {
|
|
653
|
+
this.setCookieSession(userId);
|
|
654
|
+
await this.storage.removeItem(SESSION_STORAGE_KEY);
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
638
657
|
this.sessionToken = token;
|
|
639
658
|
this.userId = userId;
|
|
640
659
|
await this.storage.setItem(SESSION_STORAGE_KEY, token);
|
|
@@ -655,8 +674,17 @@ var ScaleMuleClient = class {
|
|
|
655
674
|
*
|
|
656
675
|
* Pass `null` to clear without touching userId/storage.
|
|
657
676
|
*/
|
|
677
|
+
setCookieSession(userId) {
|
|
678
|
+
if (!this.cookieSession) return;
|
|
679
|
+
this.sessionToken = null;
|
|
680
|
+
this.userId = userId;
|
|
681
|
+
this.resolveSessionPending();
|
|
682
|
+
}
|
|
683
|
+
usesCookieSession() {
|
|
684
|
+
return this.cookieSession;
|
|
685
|
+
}
|
|
658
686
|
setSessionToken(token) {
|
|
659
|
-
this.sessionToken = token;
|
|
687
|
+
this.sessionToken = this.cookieSession ? null : token;
|
|
660
688
|
if (this.debug) {
|
|
661
689
|
console.log("[ScaleMule] Session token", token ? "set (token-only)" : "cleared (token-only)");
|
|
662
690
|
}
|
|
@@ -691,7 +719,7 @@ var ScaleMuleClient = class {
|
|
|
691
719
|
* Check if client has an active session
|
|
692
720
|
*/
|
|
693
721
|
isAuthenticated() {
|
|
694
|
-
return this.sessionToken !== null && this.userId !== null;
|
|
722
|
+
return (this.cookieSession || this.sessionToken !== null) && this.userId !== null;
|
|
695
723
|
}
|
|
696
724
|
/**
|
|
697
725
|
* Build headers for a request
|
|
@@ -1129,6 +1157,7 @@ function ScaleMuleProvider({
|
|
|
1129
1157
|
storage,
|
|
1130
1158
|
analyticsProxyUrl,
|
|
1131
1159
|
authProxyUrl,
|
|
1160
|
+
sessionMode,
|
|
1132
1161
|
telemetryEndpoint,
|
|
1133
1162
|
publishableKey,
|
|
1134
1163
|
enableAccountSwitcher,
|
|
@@ -1148,6 +1177,9 @@ function ScaleMuleProvider({
|
|
|
1148
1177
|
const security = useSecurityChallenge(passwordRecoveryUrl);
|
|
1149
1178
|
const requestSecurityCode = onSecurityChallenge || security.prompt;
|
|
1150
1179
|
const memberMode = typeof getToken === "function";
|
|
1180
|
+
const cookieSession = !!authProxyUrl && !memberMode && sessionMode !== "bearer";
|
|
1181
|
+
const browserKey = cookieSession ? publishableKey || process.env.NEXT_PUBLIC_SCALEMULE_PUBLISHABLE_KEY || apiKey : apiKey;
|
|
1182
|
+
const browserGateway = cookieSession ? `${authProxyUrl.replace(/\/$/, "")}/client` : void 0;
|
|
1151
1183
|
const [user, setUser] = React.useState(null);
|
|
1152
1184
|
const [initializing, setInitializing] = React.useState(true);
|
|
1153
1185
|
const [error, setError] = React.useState(null);
|
|
@@ -1158,10 +1190,11 @@ function ScaleMuleProvider({
|
|
|
1158
1190
|
const resolvedGatewayUrl = gatewayUrl || (environment === "dev" ? "https://api-dev.scalemule.com" : "https://api.scalemule.com");
|
|
1159
1191
|
const client = React.useMemo(
|
|
1160
1192
|
() => createClient({
|
|
1161
|
-
apiKey,
|
|
1193
|
+
apiKey: browserKey,
|
|
1162
1194
|
applicationId,
|
|
1163
1195
|
environment,
|
|
1164
|
-
gatewayUrl: resolvedGatewayUrl,
|
|
1196
|
+
gatewayUrl: browserGateway || resolvedGatewayUrl,
|
|
1197
|
+
cookieSession,
|
|
1165
1198
|
debug,
|
|
1166
1199
|
storage,
|
|
1167
1200
|
// Make outbound API calls wait for the first token to land in any
|
|
@@ -1170,27 +1203,28 @@ function ScaleMuleProvider({
|
|
|
1170
1203
|
// getToken() callback. Resolved in the init effect below.
|
|
1171
1204
|
pendingSessionInit: !!authProxyUrl || memberMode
|
|
1172
1205
|
}),
|
|
1173
|
-
[
|
|
1206
|
+
[browserKey, applicationId, environment, resolvedGatewayUrl, browserGateway, cookieSession, debug, storage, authProxyUrl, memberMode]
|
|
1174
1207
|
);
|
|
1175
1208
|
const money$1 = React.useMemo(
|
|
1176
1209
|
() => money.createMoneyClient({
|
|
1177
|
-
apiKey,
|
|
1178
|
-
gatewayUrl: resolvedGatewayUrl,
|
|
1210
|
+
apiKey: browserKey,
|
|
1211
|
+
gatewayUrl: browserGateway || resolvedGatewayUrl,
|
|
1179
1212
|
environment,
|
|
1180
1213
|
accessToken: client.getSessionToken() || void 0,
|
|
1181
1214
|
fetch: globalThis.fetch.bind(globalThis)
|
|
1182
1215
|
}),
|
|
1183
|
-
[
|
|
1216
|
+
[browserKey, resolvedGatewayUrl, browserGateway, environment, client]
|
|
1184
1217
|
);
|
|
1185
1218
|
const baseClient = React.useMemo(() => {
|
|
1186
1219
|
return new sdk.ScaleMule({
|
|
1187
|
-
apiKey,
|
|
1220
|
+
apiKey: browserKey,
|
|
1188
1221
|
applicationId,
|
|
1189
|
-
baseUrl: resolvedGatewayUrl,
|
|
1222
|
+
baseUrl: browserGateway || resolvedGatewayUrl,
|
|
1223
|
+
realtimeUrl: cookieSession ? resolvedGatewayUrl : void 0,
|
|
1190
1224
|
environment,
|
|
1191
1225
|
debug
|
|
1192
1226
|
});
|
|
1193
|
-
}, [
|
|
1227
|
+
}, [browserKey, applicationId, environment, resolvedGatewayUrl, browserGateway, cookieSession, debug]);
|
|
1194
1228
|
const [fetchedPolicy, setFetchedPolicy] = React.useState(void 0);
|
|
1195
1229
|
const [tokenVersion, setTokenVersion] = React.useState(0);
|
|
1196
1230
|
React.useEffect(() => {
|
|
@@ -1280,18 +1314,21 @@ function ScaleMuleProvider({
|
|
|
1280
1314
|
const data = await response.json();
|
|
1281
1315
|
if (mounted) {
|
|
1282
1316
|
if (data.success && data.data?.user) {
|
|
1317
|
+
client.setCookieSession(data.data.user.id);
|
|
1283
1318
|
setUser(data.data.user);
|
|
1284
1319
|
setCachedUser(data.data.user);
|
|
1285
1320
|
if (data.data.sessionToken) {
|
|
1286
1321
|
await client.setSession(data.data.sessionToken, data.data.userId || "");
|
|
1287
1322
|
}
|
|
1288
1323
|
} else {
|
|
1324
|
+
client.setCookieSession(null);
|
|
1289
1325
|
setUser(null);
|
|
1290
1326
|
setCachedUser(null);
|
|
1291
1327
|
}
|
|
1292
1328
|
}
|
|
1293
1329
|
} catch {
|
|
1294
1330
|
if (mounted) {
|
|
1331
|
+
client.setCookieSession(null);
|
|
1295
1332
|
setUser(null);
|
|
1296
1333
|
setCachedUser(null);
|
|
1297
1334
|
if (debug) {
|
|
@@ -1378,13 +1415,15 @@ function ScaleMuleProvider({
|
|
|
1378
1415
|
}, [memberMode, memberTokenPollMs, getToken, client, baseClient, money$1, debug]);
|
|
1379
1416
|
const handleSetUser = React.useCallback(
|
|
1380
1417
|
(newUser) => {
|
|
1418
|
+
client.setCookieSession(newUser?.id || null);
|
|
1419
|
+
if (!newUser) baseClient.realtime.disconnect();
|
|
1381
1420
|
setUser(newUser);
|
|
1382
1421
|
setCachedUser(newUser);
|
|
1383
1422
|
if (newUser === null && onLogout) {
|
|
1384
1423
|
onLogout();
|
|
1385
1424
|
}
|
|
1386
1425
|
},
|
|
1387
|
-
[onLogout]
|
|
1426
|
+
[onLogout, client, baseClient]
|
|
1388
1427
|
);
|
|
1389
1428
|
const value = React.useMemo(
|
|
1390
1429
|
() => ({
|
|
@@ -1408,7 +1447,7 @@ function ScaleMuleProvider({
|
|
|
1408
1447
|
setError,
|
|
1409
1448
|
analyticsProxyUrl,
|
|
1410
1449
|
authProxyUrl,
|
|
1411
|
-
publishableKey,
|
|
1450
|
+
publishableKey: cookieSession ? browserKey : publishableKey,
|
|
1412
1451
|
apiKey,
|
|
1413
1452
|
gatewayUrl: resolvedGatewayUrl,
|
|
1414
1453
|
environment: environment || void 0,
|
|
@@ -1416,7 +1455,7 @@ function ScaleMuleProvider({
|
|
|
1416
1455
|
accountSwitcherPrivacy,
|
|
1417
1456
|
bootstrapFlags
|
|
1418
1457
|
}),
|
|
1419
|
-
[requestSecurityCode, client, money$1, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, apiKey, resolvedGatewayUrl, environment, enableAccountSwitcher, accountSwitcherPrivacy, bootstrapFlags, effectiveMediaPolicy]
|
|
1458
|
+
[requestSecurityCode, client, money$1, baseClient, user, handleSetUser, initializing, error, analyticsProxyUrl, authProxyUrl, publishableKey, browserKey, cookieSession, apiKey, resolvedGatewayUrl, environment, enableAccountSwitcher, accountSwitcherPrivacy, bootstrapFlags, effectiveMediaPolicy]
|
|
1420
1459
|
);
|
|
1421
1460
|
return /* @__PURE__ */ jsxRuntime.jsxs(ScaleMuleContext.Provider, { value, children: [
|
|
1422
1461
|
children,
|
|
@@ -1440,6 +1479,9 @@ function useMoneyClient() {
|
|
|
1440
1479
|
const { money } = useScaleMule();
|
|
1441
1480
|
return money;
|
|
1442
1481
|
}
|
|
1482
|
+
function cookieLoginResult(user) {
|
|
1483
|
+
return { authenticated: true, userId: user.id, user };
|
|
1484
|
+
}
|
|
1443
1485
|
function maskEmail(email) {
|
|
1444
1486
|
const [local, domain] = email.split("@");
|
|
1445
1487
|
if (!domain) return "***@***.***";
|
|
@@ -1495,7 +1537,7 @@ async function getProxyAnonymousId() {
|
|
|
1495
1537
|
}
|
|
1496
1538
|
async function proxyFetch(proxyUrl, path, options = {}) {
|
|
1497
1539
|
const method = options.method || "POST";
|
|
1498
|
-
const headers = {};
|
|
1540
|
+
const headers = { "Content-Type": "application/json" };
|
|
1499
1541
|
if (options.body) {
|
|
1500
1542
|
headers["Content-Type"] = "application/json";
|
|
1501
1543
|
}
|
|
@@ -1554,7 +1596,7 @@ function useAuth() {
|
|
|
1554
1596
|
if (response.data.sessionToken) {
|
|
1555
1597
|
await client.setSession(response.data.sessionToken, response.data.userId || response.data.user?.id || "");
|
|
1556
1598
|
}
|
|
1557
|
-
if (response.data.user) {
|
|
1599
|
+
if (response.data.user && response.data.authenticated !== false) {
|
|
1558
1600
|
setUser(response.data.user);
|
|
1559
1601
|
}
|
|
1560
1602
|
return response.data.user;
|
|
@@ -1604,15 +1646,16 @@ function useAuth() {
|
|
|
1604
1646
|
}
|
|
1605
1647
|
const loginData2 = response.data;
|
|
1606
1648
|
const responseUser = "user" in loginData2 ? loginData2.user : null;
|
|
1607
|
-
if (responseUser) {
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
if (sessionToken) {
|
|
1613
|
-
await client.setSession(sessionToken, userId || responseUser?.id || "");
|
|
1649
|
+
if (!responseUser) throw new ScaleMuleApiError({ code: "LOGIN_FAILED", message: "Sign-in did not return a user" });
|
|
1650
|
+
setUser(responseUser);
|
|
1651
|
+
if (client.usesCookieSession()) {
|
|
1652
|
+
client.setCookieSession(responseUser.id);
|
|
1653
|
+
return cookieLoginResult(responseUser);
|
|
1614
1654
|
}
|
|
1615
|
-
|
|
1655
|
+
const sessionToken = loginData2.sessionToken || loginData2.session_token;
|
|
1656
|
+
if (!sessionToken) throw new ScaleMuleApiError({ code: "LOGIN_FAILED", message: "Sign-in did not return a session" });
|
|
1657
|
+
await client.setSession(sessionToken, loginData2.userId || responseUser.id);
|
|
1658
|
+
return { ...loginData2, session_token: sessionToken };
|
|
1616
1659
|
}
|
|
1617
1660
|
let loginResult;
|
|
1618
1661
|
try {
|
|
@@ -1643,6 +1686,7 @@ function useAuth() {
|
|
|
1643
1686
|
await proxyFetch(authProxyUrl, "logout");
|
|
1644
1687
|
} catch {
|
|
1645
1688
|
}
|
|
1689
|
+
await client.clearSession();
|
|
1646
1690
|
setUser(null);
|
|
1647
1691
|
return;
|
|
1648
1692
|
}
|
|
@@ -1817,6 +1861,9 @@ function useAuth() {
|
|
|
1817
1861
|
setError(err);
|
|
1818
1862
|
throw err;
|
|
1819
1863
|
}
|
|
1864
|
+
if (!client.usesCookieSession() && response.data?.sessionToken && response.data.userId) {
|
|
1865
|
+
await client.setSession(response.data.sessionToken, response.data.userId);
|
|
1866
|
+
}
|
|
1820
1867
|
if (response.data?.user) {
|
|
1821
1868
|
setUser(response.data.user);
|
|
1822
1869
|
}
|
|
@@ -1897,7 +1944,8 @@ function useAuth() {
|
|
|
1897
1944
|
}
|
|
1898
1945
|
throw err;
|
|
1899
1946
|
}
|
|
1900
|
-
|
|
1947
|
+
if (client.usesCookieSession()) client.setCookieSession(callbackData.user.id);
|
|
1948
|
+
else if ("session_token" in callbackData) await client.setSession(callbackData.session_token, callbackData.user.id);
|
|
1901
1949
|
setUser(callbackData.user);
|
|
1902
1950
|
return callbackData;
|
|
1903
1951
|
},
|
|
@@ -1999,7 +2047,16 @@ function useAuth() {
|
|
|
1999
2047
|
if (authProxyUrl) {
|
|
2000
2048
|
const result = await proxyFetch(authProxyUrl, "mfa/verify", { body: { pending_token: challengeToken, code, method } });
|
|
2001
2049
|
if (!result.success || !result.data) throw result.error;
|
|
2002
|
-
|
|
2050
|
+
const sessionToken = result.data.sessionToken || result.data.session_token;
|
|
2051
|
+
if (client.usesCookieSession() && result.data.user) {
|
|
2052
|
+
client.setCookieSession(result.data.user.id);
|
|
2053
|
+
setUser(result.data.user);
|
|
2054
|
+
return cookieLoginResult(result.data.user);
|
|
2055
|
+
}
|
|
2056
|
+
if (!sessionToken) throw new ScaleMuleApiError({ code: "MFA_FAILED", message: "Sign-in did not return a session" });
|
|
2057
|
+
await client.setSession(sessionToken, result.data.user.id);
|
|
2058
|
+
setUser(result.data.user);
|
|
2059
|
+
return { ...result.data, session_token: sessionToken };
|
|
2003
2060
|
} else {
|
|
2004
2061
|
mfaResult = await client.post("/v1/auth/mfa/verify", { pending_token: challengeToken, code, method });
|
|
2005
2062
|
}
|
|
@@ -2131,15 +2188,16 @@ function useAuth() {
|
|
|
2131
2188
|
}
|
|
2132
2189
|
const loginData = response.data;
|
|
2133
2190
|
const responseUser = "user" in loginData ? loginData.user : null;
|
|
2134
|
-
if (responseUser) {
|
|
2135
|
-
|
|
2191
|
+
if (!responseUser) throw new ScaleMuleApiError({ code: "LOGIN_FAILED", message: "Sign-in did not return a user" });
|
|
2192
|
+
setUser(responseUser);
|
|
2193
|
+
if (client.usesCookieSession()) {
|
|
2194
|
+
client.setCookieSession(responseUser.id);
|
|
2195
|
+
return cookieLoginResult(responseUser);
|
|
2136
2196
|
}
|
|
2137
|
-
const sessionToken =
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
}
|
|
2142
|
-
return response.data;
|
|
2197
|
+
const sessionToken = loginData.sessionToken || loginData.session_token;
|
|
2198
|
+
if (!sessionToken) throw new ScaleMuleApiError({ code: "LOGIN_FAILED", message: "Sign-in did not return a session" });
|
|
2199
|
+
await client.setSession(sessionToken, loginData.userId || responseUser.id);
|
|
2200
|
+
return { ...loginData, session_token: sessionToken };
|
|
2143
2201
|
}
|
|
2144
2202
|
let phoneLoginData;
|
|
2145
2203
|
try {
|
|
@@ -2183,6 +2241,7 @@ function useAuth() {
|
|
|
2183
2241
|
if (!target) return null;
|
|
2184
2242
|
if (authProxyUrl) {
|
|
2185
2243
|
await proxyFetch(authProxyUrl, "switch-account");
|
|
2244
|
+
await client.clearSession();
|
|
2186
2245
|
} else {
|
|
2187
2246
|
const sessionToken = client.getSessionToken();
|
|
2188
2247
|
if (sessionToken) {
|
|
@@ -3929,6 +3988,34 @@ function useRealtime(options) {
|
|
|
3929
3988
|
return { status, lastMessage, disconnect, subscribe, publish };
|
|
3930
3989
|
}
|
|
3931
3990
|
|
|
3991
|
+
// src/url-privacy.ts
|
|
3992
|
+
function withoutAuthSecrets(value) {
|
|
3993
|
+
if (!value) return value;
|
|
3994
|
+
try {
|
|
3995
|
+
const absolute = /^[a-z][a-z0-9+.-]*:/i.test(value);
|
|
3996
|
+
const protocolRelative = value.startsWith("//");
|
|
3997
|
+
const url = new URL(value, "https://relative.invalid");
|
|
3998
|
+
if (!["http:", "https:"].includes(url.protocol)) return void 0;
|
|
3999
|
+
let changed = false;
|
|
4000
|
+
for (const name of [...url.searchParams.keys()]) {
|
|
4001
|
+
if (/^(token|code|state|password|new_password|access_token|refresh_token|id_token|api_key|client_secret|challenge_token|challenge_code)$/i.test(name)) {
|
|
4002
|
+
url.searchParams.delete(name);
|
|
4003
|
+
changed = true;
|
|
4004
|
+
}
|
|
4005
|
+
}
|
|
4006
|
+
if (url.hash) {
|
|
4007
|
+
url.hash = "";
|
|
4008
|
+
changed = true;
|
|
4009
|
+
}
|
|
4010
|
+
if (!changed) return value;
|
|
4011
|
+
if (absolute) return url.toString();
|
|
4012
|
+
if (protocolRelative) return url.toString().replace(/^https:/, "");
|
|
4013
|
+
return value.split(/[?#]/, 1)[0] + url.search;
|
|
4014
|
+
} catch {
|
|
4015
|
+
return void 0;
|
|
4016
|
+
}
|
|
4017
|
+
}
|
|
4018
|
+
|
|
3932
4019
|
// src/hooks/event-dedup.ts
|
|
3933
4020
|
var DEFAULT_EVENT_DEDUP_MS = 300;
|
|
3934
4021
|
var DEDUP_MAP_MAX = 200;
|
|
@@ -4198,19 +4285,20 @@ function useAnalytics(options = {}) {
|
|
|
4198
4285
|
if (utm) setUtmParams(utm);
|
|
4199
4286
|
}
|
|
4200
4287
|
if (!landingPage.current) {
|
|
4201
|
-
landingPage.current = window.location.href;
|
|
4288
|
+
landingPage.current = withoutAuthSecrets(window.location.href) || null;
|
|
4202
4289
|
}
|
|
4203
4290
|
const storage = typeof sessionStorage !== "undefined" ? sessionStorage : void 0;
|
|
4204
4291
|
const storedReferrer = getStorageItem(storage, SESSION_REFERRER_KEY);
|
|
4205
4292
|
if (storedReferrer) {
|
|
4206
|
-
originalReferrerRef.current = storedReferrer;
|
|
4293
|
+
originalReferrerRef.current = withoutAuthSecrets(storedReferrer) || null;
|
|
4294
|
+
setStorageItem(storage, SESSION_REFERRER_KEY, originalReferrerRef.current || "");
|
|
4207
4295
|
} else if (document.referrer) {
|
|
4208
4296
|
try {
|
|
4209
4297
|
const referrerUrl = new URL(document.referrer);
|
|
4210
4298
|
const currentUrl = new URL(window.location.href);
|
|
4211
4299
|
if (referrerUrl.hostname !== currentUrl.hostname) {
|
|
4212
|
-
originalReferrerRef.current = document.referrer;
|
|
4213
|
-
setStorageItem(storage, SESSION_REFERRER_KEY, document.referrer);
|
|
4300
|
+
originalReferrerRef.current = withoutAuthSecrets(document.referrer) || null;
|
|
4301
|
+
setStorageItem(storage, SESSION_REFERRER_KEY, withoutAuthSecrets(document.referrer) || "");
|
|
4214
4302
|
}
|
|
4215
4303
|
} catch {
|
|
4216
4304
|
}
|
|
@@ -4250,10 +4338,10 @@ function useAnalytics(options = {}) {
|
|
|
4250
4338
|
session_duration_seconds: Math.floor((Date.now() - sessionStartRef.current) / 1e3)
|
|
4251
4339
|
};
|
|
4252
4340
|
if (typeof window !== "undefined") {
|
|
4253
|
-
fullEvent.page_url = window.location.href;
|
|
4341
|
+
fullEvent.page_url = withoutAuthSecrets(window.location.href);
|
|
4254
4342
|
fullEvent.page_title = document.title;
|
|
4255
4343
|
fullEvent.referrer = originalReferrerRef.current || void 0;
|
|
4256
|
-
fullEvent.document_referrer = document.referrer || void 0;
|
|
4344
|
+
fullEvent.document_referrer = withoutAuthSecrets(document.referrer) || void 0;
|
|
4257
4345
|
}
|
|
4258
4346
|
return fullEvent;
|
|
4259
4347
|
},
|
|
@@ -4336,9 +4424,9 @@ function useAnalytics(options = {}) {
|
|
|
4336
4424
|
event_category: "navigation",
|
|
4337
4425
|
properties: {
|
|
4338
4426
|
...data?.properties || {},
|
|
4339
|
-
page_url: data?.page_url || (typeof window !== "undefined" ? window.location.href : void 0),
|
|
4427
|
+
page_url: withoutAuthSecrets(data?.page_url || (typeof window !== "undefined" ? window.location.href : void 0)),
|
|
4340
4428
|
page_title: data?.page_title || (typeof document !== "undefined" ? document.title : void 0),
|
|
4341
|
-
referrer: data?.referrer || originalReferrerRef.current || void 0
|
|
4429
|
+
referrer: withoutAuthSecrets(data?.referrer || originalReferrerRef.current || void 0)
|
|
4342
4430
|
}
|
|
4343
4431
|
};
|
|
4344
4432
|
return trackEvent(pageEvent);
|