@scalemule/nextjs 0.1.51 → 0.1.52

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/index.js CHANGED
@@ -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." };
@@ -1999,7 +2007,9 @@ function useAuth() {
1999
2007
  if (authProxyUrl) {
2000
2008
  const result = await proxyFetch(authProxyUrl, "mfa/verify", { body: { pending_token: challengeToken, code, method } });
2001
2009
  if (!result.success || !result.data) throw result.error;
2002
- mfaResult = result.data;
2010
+ const sessionToken = result.data.sessionToken || result.data.session_token;
2011
+ if (!sessionToken) throw new ScaleMuleApiError({ code: "MFA_FAILED", message: "Sign-in did not return a session" });
2012
+ mfaResult = { ...result.data, session_token: sessionToken };
2003
2013
  } else {
2004
2014
  mfaResult = await client.post("/v1/auth/mfa/verify", { pending_token: challengeToken, code, method });
2005
2015
  }
@@ -3929,6 +3939,34 @@ function useRealtime(options) {
3929
3939
  return { status, lastMessage, disconnect, subscribe, publish };
3930
3940
  }
3931
3941
 
3942
+ // src/url-privacy.ts
3943
+ function withoutAuthSecrets(value) {
3944
+ if (!value) return value;
3945
+ try {
3946
+ const absolute = /^[a-z][a-z0-9+.-]*:/i.test(value);
3947
+ const protocolRelative = value.startsWith("//");
3948
+ const url = new URL(value, "https://relative.invalid");
3949
+ if (!["http:", "https:"].includes(url.protocol)) return void 0;
3950
+ let changed = false;
3951
+ for (const name of [...url.searchParams.keys()]) {
3952
+ if (/^(token|code|state|password|new_password|access_token|refresh_token|id_token|api_key|client_secret|challenge_token|challenge_code)$/i.test(name)) {
3953
+ url.searchParams.delete(name);
3954
+ changed = true;
3955
+ }
3956
+ }
3957
+ if (url.hash) {
3958
+ url.hash = "";
3959
+ changed = true;
3960
+ }
3961
+ if (!changed) return value;
3962
+ if (absolute) return url.toString();
3963
+ if (protocolRelative) return url.toString().replace(/^https:/, "");
3964
+ return value.split(/[?#]/, 1)[0] + url.search;
3965
+ } catch {
3966
+ return void 0;
3967
+ }
3968
+ }
3969
+
3932
3970
  // src/hooks/event-dedup.ts
3933
3971
  var DEFAULT_EVENT_DEDUP_MS = 300;
3934
3972
  var DEDUP_MAP_MAX = 200;
@@ -4198,19 +4236,20 @@ function useAnalytics(options = {}) {
4198
4236
  if (utm) setUtmParams(utm);
4199
4237
  }
4200
4238
  if (!landingPage.current) {
4201
- landingPage.current = window.location.href;
4239
+ landingPage.current = withoutAuthSecrets(window.location.href) || null;
4202
4240
  }
4203
4241
  const storage = typeof sessionStorage !== "undefined" ? sessionStorage : void 0;
4204
4242
  const storedReferrer = getStorageItem(storage, SESSION_REFERRER_KEY);
4205
4243
  if (storedReferrer) {
4206
- originalReferrerRef.current = storedReferrer;
4244
+ originalReferrerRef.current = withoutAuthSecrets(storedReferrer) || null;
4245
+ setStorageItem(storage, SESSION_REFERRER_KEY, originalReferrerRef.current || "");
4207
4246
  } else if (document.referrer) {
4208
4247
  try {
4209
4248
  const referrerUrl = new URL(document.referrer);
4210
4249
  const currentUrl = new URL(window.location.href);
4211
4250
  if (referrerUrl.hostname !== currentUrl.hostname) {
4212
- originalReferrerRef.current = document.referrer;
4213
- setStorageItem(storage, SESSION_REFERRER_KEY, document.referrer);
4251
+ originalReferrerRef.current = withoutAuthSecrets(document.referrer) || null;
4252
+ setStorageItem(storage, SESSION_REFERRER_KEY, withoutAuthSecrets(document.referrer) || "");
4214
4253
  }
4215
4254
  } catch {
4216
4255
  }
@@ -4250,10 +4289,10 @@ function useAnalytics(options = {}) {
4250
4289
  session_duration_seconds: Math.floor((Date.now() - sessionStartRef.current) / 1e3)
4251
4290
  };
4252
4291
  if (typeof window !== "undefined") {
4253
- fullEvent.page_url = window.location.href;
4292
+ fullEvent.page_url = withoutAuthSecrets(window.location.href);
4254
4293
  fullEvent.page_title = document.title;
4255
4294
  fullEvent.referrer = originalReferrerRef.current || void 0;
4256
- fullEvent.document_referrer = document.referrer || void 0;
4295
+ fullEvent.document_referrer = withoutAuthSecrets(document.referrer) || void 0;
4257
4296
  }
4258
4297
  return fullEvent;
4259
4298
  },
@@ -4336,9 +4375,9 @@ function useAnalytics(options = {}) {
4336
4375
  event_category: "navigation",
4337
4376
  properties: {
4338
4377
  ...data?.properties || {},
4339
- page_url: data?.page_url || (typeof window !== "undefined" ? window.location.href : void 0),
4378
+ page_url: withoutAuthSecrets(data?.page_url || (typeof window !== "undefined" ? window.location.href : void 0)),
4340
4379
  page_title: data?.page_title || (typeof document !== "undefined" ? document.title : void 0),
4341
- referrer: data?.referrer || originalReferrerRef.current || void 0
4380
+ referrer: withoutAuthSecrets(data?.referrer || originalReferrerRef.current || void 0)
4342
4381
  }
4343
4382
  };
4344
4383
  return trackEvent(pageEvent);
package/dist/index.mjs CHANGED
@@ -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." };
@@ -1979,7 +1987,9 @@ function useAuth() {
1979
1987
  if (authProxyUrl) {
1980
1988
  const result = await proxyFetch(authProxyUrl, "mfa/verify", { body: { pending_token: challengeToken, code, method } });
1981
1989
  if (!result.success || !result.data) throw result.error;
1982
- mfaResult = result.data;
1990
+ const sessionToken = result.data.sessionToken || result.data.session_token;
1991
+ if (!sessionToken) throw new ScaleMuleApiError({ code: "MFA_FAILED", message: "Sign-in did not return a session" });
1992
+ mfaResult = { ...result.data, session_token: sessionToken };
1983
1993
  } else {
1984
1994
  mfaResult = await client.post("/v1/auth/mfa/verify", { pending_token: challengeToken, code, method });
1985
1995
  }
@@ -3909,6 +3919,34 @@ function useRealtime(options) {
3909
3919
  return { status, lastMessage, disconnect, subscribe, publish };
3910
3920
  }
3911
3921
 
3922
+ // src/url-privacy.ts
3923
+ function withoutAuthSecrets(value) {
3924
+ if (!value) return value;
3925
+ try {
3926
+ const absolute = /^[a-z][a-z0-9+.-]*:/i.test(value);
3927
+ const protocolRelative = value.startsWith("//");
3928
+ const url = new URL(value, "https://relative.invalid");
3929
+ if (!["http:", "https:"].includes(url.protocol)) return void 0;
3930
+ let changed = false;
3931
+ for (const name of [...url.searchParams.keys()]) {
3932
+ if (/^(token|code|state|password|new_password|access_token|refresh_token|id_token|api_key|client_secret|challenge_token|challenge_code)$/i.test(name)) {
3933
+ url.searchParams.delete(name);
3934
+ changed = true;
3935
+ }
3936
+ }
3937
+ if (url.hash) {
3938
+ url.hash = "";
3939
+ changed = true;
3940
+ }
3941
+ if (!changed) return value;
3942
+ if (absolute) return url.toString();
3943
+ if (protocolRelative) return url.toString().replace(/^https:/, "");
3944
+ return value.split(/[?#]/, 1)[0] + url.search;
3945
+ } catch {
3946
+ return void 0;
3947
+ }
3948
+ }
3949
+
3912
3950
  // src/hooks/event-dedup.ts
3913
3951
  var DEFAULT_EVENT_DEDUP_MS = 300;
3914
3952
  var DEDUP_MAP_MAX = 200;
@@ -4178,19 +4216,20 @@ function useAnalytics(options = {}) {
4178
4216
  if (utm) setUtmParams(utm);
4179
4217
  }
4180
4218
  if (!landingPage.current) {
4181
- landingPage.current = window.location.href;
4219
+ landingPage.current = withoutAuthSecrets(window.location.href) || null;
4182
4220
  }
4183
4221
  const storage = typeof sessionStorage !== "undefined" ? sessionStorage : void 0;
4184
4222
  const storedReferrer = getStorageItem(storage, SESSION_REFERRER_KEY);
4185
4223
  if (storedReferrer) {
4186
- originalReferrerRef.current = storedReferrer;
4224
+ originalReferrerRef.current = withoutAuthSecrets(storedReferrer) || null;
4225
+ setStorageItem(storage, SESSION_REFERRER_KEY, originalReferrerRef.current || "");
4187
4226
  } else if (document.referrer) {
4188
4227
  try {
4189
4228
  const referrerUrl = new URL(document.referrer);
4190
4229
  const currentUrl = new URL(window.location.href);
4191
4230
  if (referrerUrl.hostname !== currentUrl.hostname) {
4192
- originalReferrerRef.current = document.referrer;
4193
- setStorageItem(storage, SESSION_REFERRER_KEY, document.referrer);
4231
+ originalReferrerRef.current = withoutAuthSecrets(document.referrer) || null;
4232
+ setStorageItem(storage, SESSION_REFERRER_KEY, withoutAuthSecrets(document.referrer) || "");
4194
4233
  }
4195
4234
  } catch {
4196
4235
  }
@@ -4230,10 +4269,10 @@ function useAnalytics(options = {}) {
4230
4269
  session_duration_seconds: Math.floor((Date.now() - sessionStartRef.current) / 1e3)
4231
4270
  };
4232
4271
  if (typeof window !== "undefined") {
4233
- fullEvent.page_url = window.location.href;
4272
+ fullEvent.page_url = withoutAuthSecrets(window.location.href);
4234
4273
  fullEvent.page_title = document.title;
4235
4274
  fullEvent.referrer = originalReferrerRef.current || void 0;
4236
- fullEvent.document_referrer = document.referrer || void 0;
4275
+ fullEvent.document_referrer = withoutAuthSecrets(document.referrer) || void 0;
4237
4276
  }
4238
4277
  return fullEvent;
4239
4278
  },
@@ -4316,9 +4355,9 @@ function useAnalytics(options = {}) {
4316
4355
  event_category: "navigation",
4317
4356
  properties: {
4318
4357
  ...data?.properties || {},
4319
- page_url: data?.page_url || (typeof window !== "undefined" ? window.location.href : void 0),
4358
+ page_url: withoutAuthSecrets(data?.page_url || (typeof window !== "undefined" ? window.location.href : void 0)),
4320
4359
  page_title: data?.page_title || (typeof document !== "undefined" ? document.title : void 0),
4321
- referrer: data?.referrer || originalReferrerRef.current || void 0
4360
+ referrer: withoutAuthSecrets(data?.referrer || originalReferrerRef.current || void 0)
4322
4361
  }
4323
4362
  };
4324
4363
  return trackEvent(pageEvent);
@@ -18,6 +18,34 @@ var ScaleMuleApiError = class extends Error {
18
18
  }
19
19
  };
20
20
 
21
+ // src/url-privacy.ts
22
+ function withoutAuthSecrets(value) {
23
+ if (!value) return value;
24
+ try {
25
+ const absolute = /^[a-z][a-z0-9+.-]*:/i.test(value);
26
+ const protocolRelative = value.startsWith("//");
27
+ const url = new URL(value, "https://relative.invalid");
28
+ if (!["http:", "https:"].includes(url.protocol)) return void 0;
29
+ let changed = false;
30
+ for (const name of [...url.searchParams.keys()]) {
31
+ if (/^(token|code|state|password|new_password|access_token|refresh_token|id_token|api_key|client_secret|challenge_token|challenge_code)$/i.test(name)) {
32
+ url.searchParams.delete(name);
33
+ changed = true;
34
+ }
35
+ }
36
+ if (url.hash) {
37
+ url.hash = "";
38
+ changed = true;
39
+ }
40
+ if (!changed) return value;
41
+ if (absolute) return url.toString();
42
+ if (protocolRelative) return url.toString().replace(/^https:/, "");
43
+ return value.split(/[?#]/, 1)[0] + url.search;
44
+ } catch {
45
+ return void 0;
46
+ }
47
+ }
48
+
21
49
  // src/server/context.ts
22
50
  function validateIP(ip) {
23
51
  if (!ip) return void 0;
@@ -76,7 +104,7 @@ function extractClientContext(request) {
76
104
  }
77
105
  const userAgent = headers2.get("user-agent") || void 0;
78
106
  const deviceFingerprint = headers2.get("x-device-fingerprint") || void 0;
79
- const referrer = headers2.get("referer") || void 0;
107
+ const referrer = withoutAuthSecrets(headers2.get("referer") || void 0);
80
108
  const anonymousId = headers2.get("x-anonymous-id") || void 0;
81
109
  return {
82
110
  ip,
@@ -16,6 +16,34 @@ var ScaleMuleApiError = class extends Error {
16
16
  }
17
17
  };
18
18
 
19
+ // src/url-privacy.ts
20
+ function withoutAuthSecrets(value) {
21
+ if (!value) return value;
22
+ try {
23
+ const absolute = /^[a-z][a-z0-9+.-]*:/i.test(value);
24
+ const protocolRelative = value.startsWith("//");
25
+ const url = new URL(value, "https://relative.invalid");
26
+ if (!["http:", "https:"].includes(url.protocol)) return void 0;
27
+ let changed = false;
28
+ for (const name of [...url.searchParams.keys()]) {
29
+ if (/^(token|code|state|password|new_password|access_token|refresh_token|id_token|api_key|client_secret|challenge_token|challenge_code)$/i.test(name)) {
30
+ url.searchParams.delete(name);
31
+ changed = true;
32
+ }
33
+ }
34
+ if (url.hash) {
35
+ url.hash = "";
36
+ changed = true;
37
+ }
38
+ if (!changed) return value;
39
+ if (absolute) return url.toString();
40
+ if (protocolRelative) return url.toString().replace(/^https:/, "");
41
+ return value.split(/[?#]/, 1)[0] + url.search;
42
+ } catch {
43
+ return void 0;
44
+ }
45
+ }
46
+
19
47
  // src/server/context.ts
20
48
  function validateIP(ip) {
21
49
  if (!ip) return void 0;
@@ -74,7 +102,7 @@ function extractClientContext(request) {
74
102
  }
75
103
  const userAgent = headers2.get("user-agent") || void 0;
76
104
  const deviceFingerprint = headers2.get("x-device-fingerprint") || void 0;
77
- const referrer = headers2.get("referer") || void 0;
105
+ const referrer = withoutAuthSecrets(headers2.get("referer") || void 0);
78
106
  const anonymousId = headers2.get("x-anonymous-id") || void 0;
79
107
  return {
80
108
  ip,
@@ -23,6 +23,34 @@ var ScaleMuleApiError = class extends Error {
23
23
  }
24
24
  };
25
25
 
26
+ // src/url-privacy.ts
27
+ function withoutAuthSecrets(value) {
28
+ if (!value) return value;
29
+ try {
30
+ const absolute = /^[a-z][a-z0-9+.-]*:/i.test(value);
31
+ const protocolRelative = value.startsWith("//");
32
+ const url = new URL(value, "https://relative.invalid");
33
+ if (!["http:", "https:"].includes(url.protocol)) return void 0;
34
+ let changed = false;
35
+ for (const name of [...url.searchParams.keys()]) {
36
+ if (/^(token|code|state|password|new_password|access_token|refresh_token|id_token|api_key|client_secret|challenge_token|challenge_code)$/i.test(name)) {
37
+ url.searchParams.delete(name);
38
+ changed = true;
39
+ }
40
+ }
41
+ if (url.hash) {
42
+ url.hash = "";
43
+ changed = true;
44
+ }
45
+ if (!changed) return value;
46
+ if (absolute) return url.toString();
47
+ if (protocolRelative) return url.toString().replace(/^https:/, "");
48
+ return value.split(/[?#]/, 1)[0] + url.search;
49
+ } catch {
50
+ return void 0;
51
+ }
52
+ }
53
+
26
54
  // src/server/context.ts
27
55
  function validateIP(ip) {
28
56
  if (!ip) return void 0;
@@ -81,7 +109,7 @@ function extractClientContext(request) {
81
109
  }
82
110
  const userAgent = headers3.get("user-agent") || void 0;
83
111
  const deviceFingerprint = headers3.get("x-device-fingerprint") || void 0;
84
- const referrer = headers3.get("referer") || void 0;
112
+ const referrer = withoutAuthSecrets(headers3.get("referer") || void 0);
85
113
  const anonymousId = headers3.get("x-anonymous-id") || void 0;
86
114
  return {
87
115
  ip,
@@ -143,7 +171,7 @@ function extractClientContextFromReq(req) {
143
171
  }
144
172
  const userAgent = getHeader("user-agent");
145
173
  const deviceFingerprint = getHeader("x-device-fingerprint");
146
- const referrer = getHeader("referer");
174
+ const referrer = withoutAuthSecrets(getHeader("referer"));
147
175
  const anonymousId = getHeader("x-anonymous-id");
148
176
  return {
149
177
  ip,
@@ -21,6 +21,34 @@ var ScaleMuleApiError = class extends Error {
21
21
  }
22
22
  };
23
23
 
24
+ // src/url-privacy.ts
25
+ function withoutAuthSecrets(value) {
26
+ if (!value) return value;
27
+ try {
28
+ const absolute = /^[a-z][a-z0-9+.-]*:/i.test(value);
29
+ const protocolRelative = value.startsWith("//");
30
+ const url = new URL(value, "https://relative.invalid");
31
+ if (!["http:", "https:"].includes(url.protocol)) return void 0;
32
+ let changed = false;
33
+ for (const name of [...url.searchParams.keys()]) {
34
+ if (/^(token|code|state|password|new_password|access_token|refresh_token|id_token|api_key|client_secret|challenge_token|challenge_code)$/i.test(name)) {
35
+ url.searchParams.delete(name);
36
+ changed = true;
37
+ }
38
+ }
39
+ if (url.hash) {
40
+ url.hash = "";
41
+ changed = true;
42
+ }
43
+ if (!changed) return value;
44
+ if (absolute) return url.toString();
45
+ if (protocolRelative) return url.toString().replace(/^https:/, "");
46
+ return value.split(/[?#]/, 1)[0] + url.search;
47
+ } catch {
48
+ return void 0;
49
+ }
50
+ }
51
+
24
52
  // src/server/context.ts
25
53
  function validateIP(ip) {
26
54
  if (!ip) return void 0;
@@ -79,7 +107,7 @@ function extractClientContext(request) {
79
107
  }
80
108
  const userAgent = headers3.get("user-agent") || void 0;
81
109
  const deviceFingerprint = headers3.get("x-device-fingerprint") || void 0;
82
- const referrer = headers3.get("referer") || void 0;
110
+ const referrer = withoutAuthSecrets(headers3.get("referer") || void 0);
83
111
  const anonymousId = headers3.get("x-anonymous-id") || void 0;
84
112
  return {
85
113
  ip,
@@ -141,7 +169,7 @@ function extractClientContextFromReq(req) {
141
169
  }
142
170
  const userAgent = getHeader("user-agent");
143
171
  const deviceFingerprint = getHeader("x-device-fingerprint");
144
- const referrer = getHeader("referer");
172
+ const referrer = withoutAuthSecrets(getHeader("referer"));
145
173
  const anonymousId = getHeader("x-anonymous-id");
146
174
  return {
147
175
  ip,
@@ -11,7 +11,7 @@ React at runtime. Existing `AudioPlayer` and `NarrationPlayer` APIs are unchange
11
11
  | Client-side navigation under the same provider | The same audio element continues playing. |
12
12
  | Leaving the narrated article | Highlighting is destroyed; audio continues. |
13
13
  | Returning to that article | Highlighting resumes at the current clock if enabled. |
14
- | Moving the reader tab to another participating domain | A previously opened network player window keeps playing. The destination bar reconnects. |
14
+ | Following a network link in the original reader tab to another participating domain | A previously opened network player window keeps playing. The destination bar reconnects. |
15
15
  | Full navigation/reload without a network window | The old audio stops. An optional checkpoint restores the queue and position paused. |
16
16
  | Closing the network window | The reader restores the latest reported queue and position paused, with a Play prompt. |
17
17
  | Closing the reader tab | The network window can continue independently. |
@@ -24,8 +24,11 @@ policy. Once playing, navigation of its original reader tab does not replace its
24
24
  audio element. Browser/OS suspension can still interrupt media, especially on
25
25
  mobile. Test supported browsers before promising uninterrupted listening.
26
26
 
27
- This implementation reconnects the **original reader tab** across navigation.
28
- It does not discover unrelated tabs or synchronize devices. COOP headers that
27
+ This implementation reconnects the **original reader tab** when readers follow
28
+ links between participating sites. Direct address-bar or browser-initiated
29
+ cross-site navigation can sever the window relationship: audio continues in the
30
+ player window, but the destination bar may not reconnect. Use the player window's
31
+ controls in that case. It does not discover unrelated tabs or synchronize devices. COOP headers that
29
32
  sever `window.opener`, sandbox restrictions and popup blockers can prevent the
30
33
  connection. Failed initial connections preserve local playback and show a notice.
31
34
  An unresponsive remote player never triggers automatic local playback, which
@@ -205,8 +208,10 @@ The automated suite covers article unmounts, highlighting cleanup/return, queue
205
208
  advancement, publication identity, stale/aborted requests, signed URL refresh,
206
209
  autoplay denial, bounded recovery, blocked popups, exact origin/source checks,
207
210
  remote reconnect and host closure. Also test real media in supported browsers:
208
- start in the reader, open the network window, navigate the original tab to another
209
- allowed origin, control playback from the destination, and close the host.
211
+ start in the reader, open the network window, follow an actual network link in
212
+ the original tab to another allowed origin, control playback from the destination,
213
+ and close the host. Browser automation that changes the address directly does not
214
+ exercise the same window relationship as clicking a site link.
210
215
  Verify ad consent and publication authorization in the actual applications.
211
216
  Release the SDK, integrate layouts/routes/resolvers in the participating sites,
212
217
  then deploy through their existing release process. These SDK changes alone do
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scalemule/nextjs",
3
- "version": "0.1.51",
3
+ "version": "0.1.52",
4
4
  "description": "ScaleMule SDK for Next.js applications - authentication, storage, and user management",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",