@mushi-mushi/web 1.33.8 → 1.34.0
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 +1 -1
- package/dist/chunks/journey-recording-6HACWEOF.js +47 -0
- package/dist/chunks/journey-recording-6HACWEOF.js.map +1 -0
- package/dist/index.cjs +84 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +30 -3
- package/dist/index.js.map +1 -1
- package/dist/mushi.loader.global.js +20 -20
- package/dist/test-utils.cjs +48 -0
- package/dist/test-utils.cjs.map +1 -1
- package/dist/test-utils.js +48 -0
- package/dist/test-utils.js.map +1 -1
- package/package.json +10 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @mushi-mushi/web
|
|
2
2
|
|
|
3
|
-
> **Your AI
|
|
3
|
+
> **Your AI built it. Mushi Mushi makes it better.**
|
|
4
4
|
|
|
5
5
|
A bug widget for any website. When a user reports a problem, it sends a screenshot, the route, their note and the last console and network events to [Mushi Mushi](https://github.com/kensaurus/mushi-mushi). Mushi Mushi explains the cause in plain English and hands your editor a fix. It renders in a Shadow DOM, so your CSS and the widget's never mix.
|
|
6
6
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/journey-recording.ts
|
|
2
|
+
var JOURNEY_URL_PARAM = "mushi_journeys";
|
|
3
|
+
var tabKey = (projectId) => `mushi:journeys:tab:${projectId}`;
|
|
4
|
+
var drawKey = (projectId) => `mushi:journeys:draw:${projectId}`;
|
|
5
|
+
function journeyRecordingDecision(input) {
|
|
6
|
+
if (input.mode === false) return false;
|
|
7
|
+
if (input.mode !== "on-demand") return true;
|
|
8
|
+
if (input.tabOptIn) return true;
|
|
9
|
+
const w = input.window;
|
|
10
|
+
if (!w) return false;
|
|
11
|
+
const until = Date.parse(w.recordUntil);
|
|
12
|
+
if (!Number.isFinite(until) || until <= input.now) return false;
|
|
13
|
+
const rate = Number.isFinite(w.sampleRate) ? Math.min(1, Math.max(0, w.sampleRate)) : 0;
|
|
14
|
+
return input.draw < rate;
|
|
15
|
+
}
|
|
16
|
+
function readTabOptIn(projectId) {
|
|
17
|
+
if (typeof window === "undefined") return false;
|
|
18
|
+
let fromUrl = null;
|
|
19
|
+
try {
|
|
20
|
+
fromUrl = new URL(window.location.href).searchParams.get(JOURNEY_URL_PARAM);
|
|
21
|
+
} catch {
|
|
22
|
+
fromUrl = null;
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
if (fromUrl === "1" || fromUrl === "true") window.sessionStorage.setItem(tabKey(projectId), "1");
|
|
26
|
+
else if (fromUrl === "0" || fromUrl === "false") window.sessionStorage.removeItem(tabKey(projectId));
|
|
27
|
+
return window.sessionStorage.getItem(tabKey(projectId)) === "1";
|
|
28
|
+
} catch {
|
|
29
|
+
return fromUrl === "1" || fromUrl === "true";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function deviceDraw(projectId, random = Math.random) {
|
|
33
|
+
if (typeof window === "undefined") return random();
|
|
34
|
+
try {
|
|
35
|
+
const saved = Number(window.localStorage.getItem(drawKey(projectId)));
|
|
36
|
+
if (window.localStorage.getItem(drawKey(projectId)) !== null && Number.isFinite(saved) && saved >= 0 && saved < 1) return saved;
|
|
37
|
+
const fresh = random();
|
|
38
|
+
window.localStorage.setItem(drawKey(projectId), String(fresh));
|
|
39
|
+
return fresh;
|
|
40
|
+
} catch {
|
|
41
|
+
return random();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { deviceDraw, journeyRecordingDecision, readTabOptIn };
|
|
46
|
+
//# sourceMappingURL=journey-recording-6HACWEOF.js.map
|
|
47
|
+
//# sourceMappingURL=journey-recording-6HACWEOF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/journey-recording.ts"],"names":[],"mappings":";AAwBA,IAAM,iBAAA,GAAoB,gBAAA;AAE1B,IAAM,MAAA,GAAS,CAAC,SAAA,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* In on-demand mode the session tracker sends nothing until one of:\n * - this tab opted in with `?mushi_journeys=1` in the URL (kept for the tab\n * in sessionStorage; `?mushi_journeys=0` opts out again), for the owner or\n * a tester walking the app on purpose;\n * - the console opened a recording window (`/v1/sdk/config` → `journeys`)\n * and this device falls inside its sample. The draw is one random number\n * kept per device, so the same visitor is in or out for the whole window.\n *\n * Real visitors outside a window pay nothing: no session, heartbeat or\n * page-view request. Deciding needs only the runtime config the SDK already\n * fetches on every load.\n */\n\ntype TrackSessionsMode = boolean | 'on-demand';\n\ninterface JourneyRecordingWindow {\n recordUntil: string;\n sampleRate: number;\n}\n\nconst JOURNEY_URL_PARAM = 'mushi_journeys';\n\nconst tabKey = (projectId: string) => `mushi:journeys:tab:${projectId}`;\nconst drawKey = (projectId: string) => `mushi:journeys:draw:${projectId}`;\n\n/** Pure: should this visit be recorded? */\nexport function journeyRecordingDecision(input: {\n mode: TrackSessionsMode | undefined;\n tabOptIn: boolean;\n window: JourneyRecordingWindow | null | undefined;\n /** This device's stable draw in [0, 1). */\n draw: number;\n now: number;\n}): boolean {\n if (input.mode === false) return false;\n if (input.mode !== 'on-demand') return true;\n if (input.tabOptIn) return true;\n const w = input.window;\n if (!w) return false;\n const until = Date.parse(w.recordUntil);\n if (!Number.isFinite(until) || until <= input.now) return false;\n const rate = Number.isFinite(w.sampleRate) ? Math.min(1, Math.max(0, w.sampleRate)) : 0;\n return input.draw < rate;\n}\n\n/**\n * Read (and persist) this tab's URL opt-in. `?mushi_journeys=1` turns it on\n * for the tab, `?mushi_journeys=0` off; without the parameter the tab keeps\n * what it had. Storage failures (private mode, blocked) fall back to the URL.\n */\nexport function readTabOptIn(projectId: string): boolean {\n if (typeof window === 'undefined') return false;\n let fromUrl: string | null = null;\n try {\n fromUrl = new URL(window.location.href).searchParams.get(JOURNEY_URL_PARAM);\n } catch {\n fromUrl = null;\n }\n try {\n if (fromUrl === '1' || fromUrl === 'true') window.sessionStorage.setItem(tabKey(projectId), '1');\n else if (fromUrl === '0' || fromUrl === 'false') window.sessionStorage.removeItem(tabKey(projectId));\n return window.sessionStorage.getItem(tabKey(projectId)) === '1';\n } catch {\n return fromUrl === '1' || fromUrl === 'true';\n }\n}\n\n/** This device's stable random draw in [0, 1), created once and kept. */\nexport function deviceDraw(projectId: string, random: () => number = Math.random): number {\n if (typeof window === 'undefined') return random();\n try {\n const saved = Number(window.localStorage.getItem(drawKey(projectId)));\n if (window.localStorage.getItem(drawKey(projectId)) !== null && Number.isFinite(saved) && saved >= 0 && saved < 1) return saved;\n const fresh = random();\n window.localStorage.setItem(drawKey(projectId), String(fresh));\n return fresh;\n } catch {\n return random();\n }\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -253,6 +253,61 @@ var init_widget_views = __esm({
|
|
|
253
253
|
}
|
|
254
254
|
});
|
|
255
255
|
|
|
256
|
+
// src/journey-recording.ts
|
|
257
|
+
var journey_recording_exports = {};
|
|
258
|
+
__export(journey_recording_exports, {
|
|
259
|
+
deviceDraw: () => deviceDraw,
|
|
260
|
+
journeyRecordingDecision: () => journeyRecordingDecision,
|
|
261
|
+
readTabOptIn: () => readTabOptIn
|
|
262
|
+
});
|
|
263
|
+
function journeyRecordingDecision(input) {
|
|
264
|
+
if (input.mode === false) return false;
|
|
265
|
+
if (input.mode !== "on-demand") return true;
|
|
266
|
+
if (input.tabOptIn) return true;
|
|
267
|
+
const w = input.window;
|
|
268
|
+
if (!w) return false;
|
|
269
|
+
const until = Date.parse(w.recordUntil);
|
|
270
|
+
if (!Number.isFinite(until) || until <= input.now) return false;
|
|
271
|
+
const rate = Number.isFinite(w.sampleRate) ? Math.min(1, Math.max(0, w.sampleRate)) : 0;
|
|
272
|
+
return input.draw < rate;
|
|
273
|
+
}
|
|
274
|
+
function readTabOptIn(projectId) {
|
|
275
|
+
if (typeof window === "undefined") return false;
|
|
276
|
+
let fromUrl = null;
|
|
277
|
+
try {
|
|
278
|
+
fromUrl = new URL(window.location.href).searchParams.get(JOURNEY_URL_PARAM);
|
|
279
|
+
} catch {
|
|
280
|
+
fromUrl = null;
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
if (fromUrl === "1" || fromUrl === "true") window.sessionStorage.setItem(tabKey(projectId), "1");
|
|
284
|
+
else if (fromUrl === "0" || fromUrl === "false") window.sessionStorage.removeItem(tabKey(projectId));
|
|
285
|
+
return window.sessionStorage.getItem(tabKey(projectId)) === "1";
|
|
286
|
+
} catch {
|
|
287
|
+
return fromUrl === "1" || fromUrl === "true";
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
function deviceDraw(projectId, random = Math.random) {
|
|
291
|
+
if (typeof window === "undefined") return random();
|
|
292
|
+
try {
|
|
293
|
+
const saved = Number(window.localStorage.getItem(drawKey(projectId)));
|
|
294
|
+
if (window.localStorage.getItem(drawKey(projectId)) !== null && Number.isFinite(saved) && saved >= 0 && saved < 1) return saved;
|
|
295
|
+
const fresh = random();
|
|
296
|
+
window.localStorage.setItem(drawKey(projectId), String(fresh));
|
|
297
|
+
return fresh;
|
|
298
|
+
} catch {
|
|
299
|
+
return random();
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
var JOURNEY_URL_PARAM, tabKey, drawKey;
|
|
303
|
+
var init_journey_recording = __esm({
|
|
304
|
+
"src/journey-recording.ts"() {
|
|
305
|
+
JOURNEY_URL_PARAM = "mushi_journeys";
|
|
306
|
+
tabKey = (projectId) => `mushi:journeys:tab:${projectId}`;
|
|
307
|
+
drawKey = (projectId) => `mushi:journeys:draw:${projectId}`;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
|
|
256
311
|
// src/capture/display-capture.ts
|
|
257
312
|
var display_capture_exports = {};
|
|
258
313
|
__export(display_capture_exports, {
|
|
@@ -6779,7 +6834,7 @@ function createProactiveManager(config = {}) {
|
|
|
6779
6834
|
|
|
6780
6835
|
// src/version.ts
|
|
6781
6836
|
var MUSHI_SDK_PACKAGE = "@mushi-mushi/web";
|
|
6782
|
-
var MUSHI_SDK_VERSION = "1.
|
|
6837
|
+
var MUSHI_SDK_VERSION = "1.34.0" ;
|
|
6783
6838
|
function resolveReportAppVersion(config, environment) {
|
|
6784
6839
|
if (config.appVersion) return config.appVersion;
|
|
6785
6840
|
const vercelId = config.integrations?.vercel?.analyticsId;
|
|
@@ -6844,7 +6899,10 @@ function createInstance(config) {
|
|
|
6844
6899
|
sdkVersion: MUSHI_SDK_VERSION
|
|
6845
6900
|
});
|
|
6846
6901
|
let unsubPageViewHistory = null;
|
|
6847
|
-
|
|
6902
|
+
let sessionTrackingStarted = false;
|
|
6903
|
+
function startSessionTracking() {
|
|
6904
|
+
if (sessionTrackingStarted) return;
|
|
6905
|
+
sessionTrackingStarted = true;
|
|
6848
6906
|
core.initSessionTracker({
|
|
6849
6907
|
client: apiClient2,
|
|
6850
6908
|
sdkVersion: MUSHI_SDK_VERSION,
|
|
@@ -6867,6 +6925,29 @@ function createInstance(config) {
|
|
|
6867
6925
|
} catch {
|
|
6868
6926
|
}
|
|
6869
6927
|
}
|
|
6928
|
+
const trackSessionsMode = bootstrapConfig.trackSessions;
|
|
6929
|
+
const journeyRecording = trackSessionsMode === "on-demand" ? Promise.resolve().then(() => (init_journey_recording(), journey_recording_exports)) : null;
|
|
6930
|
+
const journeyTabOptIn = journeyRecording?.then((m) => m.readTabOptIn(bootstrapConfig.projectId));
|
|
6931
|
+
function maybeStartSessionTracking(recording) {
|
|
6932
|
+
if (sessionTrackingStarted || trackSessionsMode === false) return;
|
|
6933
|
+
if (!journeyRecording) {
|
|
6934
|
+
startSessionTracking();
|
|
6935
|
+
return;
|
|
6936
|
+
}
|
|
6937
|
+
void Promise.all([journeyRecording, journeyTabOptIn]).then(([m, tabOptIn]) => {
|
|
6938
|
+
if (sessionTrackingStarted) return;
|
|
6939
|
+
const record = m.journeyRecordingDecision({
|
|
6940
|
+
mode: trackSessionsMode,
|
|
6941
|
+
tabOptIn: tabOptIn === true,
|
|
6942
|
+
window: recording,
|
|
6943
|
+
draw: recording ? m.deviceDraw(bootstrapConfig.projectId) : 1,
|
|
6944
|
+
now: Date.now()
|
|
6945
|
+
});
|
|
6946
|
+
if (record) startSessionTracking();
|
|
6947
|
+
}).catch(() => {
|
|
6948
|
+
});
|
|
6949
|
+
}
|
|
6950
|
+
maybeStartSessionTracking(null);
|
|
6870
6951
|
const preFilter = core.createPreFilter(bootstrapConfig.preFilter);
|
|
6871
6952
|
const offlineQueue = core.createOfflineQueue(bootstrapConfig.offline);
|
|
6872
6953
|
const rateLimiter = core.createRateLimiter({ maxBurst: 10, refillRate: 1, refillIntervalMs: 5e3 });
|
|
@@ -7624,6 +7705,7 @@ function createInstance(config) {
|
|
|
7624
7705
|
});
|
|
7625
7706
|
function applyRuntimeConfig(runtime) {
|
|
7626
7707
|
runtimeConfigLoaded = true;
|
|
7708
|
+
if (runtime.enabled !== false) maybeStartSessionTracking(runtime.journeys ?? null);
|
|
7627
7709
|
reporterNotificationsEnabled = runtime.reporterNotificationsEnabled !== false;
|
|
7628
7710
|
reporterOffer = runtime.enabled === false ? null : runtime.reporter ?? null;
|
|
7629
7711
|
syncReporterChannels();
|