@extn/segi-js 0.2.6 → 0.2.8

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.
@@ -370,7 +370,7 @@ async function activateReplay(args) {
370
370
  setTimeout(onIdle, 5e3);
371
371
  }
372
372
  };
373
- void Promise.resolve().then(() => _interopRequireWildcard(require("../rrweb-KAUSOLTH.js"))).then(
373
+ void Promise.resolve().then(() => _interopRequireWildcard(require("../rrweb-VXG3W6SS.js"))).then(
374
374
  ({ startRrweb }) => new Promise((resolve) => {
375
375
  scheduleRrwebStart(() => {
376
376
  startRrweb({
@@ -402,14 +402,6 @@ async function activateReplay(args) {
402
402
  },
403
403
  body: bodyStr
404
404
  });
405
- if (typeof console !== "undefined") {
406
- console.log(
407
- "[segi.replay] /replay POST",
408
- res.status,
409
- bodyStr.length,
410
- "bytes"
411
- );
412
- }
413
405
  if (res.status === 429) {
414
406
  if (active) {
415
407
  active.replayBlocked = true;
@@ -417,13 +409,7 @@ async function activateReplay(args) {
417
409
  active.rrweb = null;
418
410
  }
419
411
  }
420
- } catch (err) {
421
- if (typeof console !== "undefined") {
422
- console.log(
423
- "[segi.replay] /replay POST FETCH FAILED:",
424
- err.message
425
- );
426
- }
412
+ } catch (e13) {
427
413
  }
428
414
  }
429
415
  }).then(resolve, () => resolve(null));
@@ -455,22 +441,40 @@ async function activateReplay(args) {
455
441
  clickCount: active.clickCount
456
442
  });
457
443
  });
444
+ const MAX_SESSION_DURATION_MS = 30 * 6e4;
445
+ setTimeout(() => {
446
+ if (!active) return;
447
+ _optionalChain([active, 'access', _34 => _34.rrweb, 'optionalAccess', _35 => _35.flush, 'call', _36 => _36(true)]);
448
+ _optionalChain([active, 'access', _37 => _37.rrweb, 'optionalAccess', _38 => _38.stop, 'call', _39 => _39()]);
449
+ active.rrweb = null;
450
+ _optionalChain([active, 'access', _40 => _40.heatmap, 'optionalAccess', _41 => _41.stop, 'call', _42 => _42()]);
451
+ active.heatmap = null;
452
+ beaconTrace(active.config, "/session/end", {
453
+ sessionUid: active.sessionUid,
454
+ endedAt: (/* @__PURE__ */ new Date()).toISOString(),
455
+ durationMs: Date.now() - new Date(active.startedAt).getTime(),
456
+ pagesVisited: active.pagesVisited,
457
+ clickCount: active.clickCount
458
+ });
459
+ active.paused = true;
460
+ active.replayBlocked = true;
461
+ }, MAX_SESSION_DURATION_MS);
458
462
  }
459
463
  var replayApi = {
460
464
  pause() {
461
- _optionalChain([active, 'optionalAccess', _34 => _34.heatmap, 'optionalAccess', _35 => _35.pause, 'call', _36 => _36()]);
462
- _optionalChain([active, 'optionalAccess', _37 => _37.rrweb, 'optionalAccess', _38 => _38.pause, 'call', _39 => _39()]);
465
+ _optionalChain([active, 'optionalAccess', _43 => _43.heatmap, 'optionalAccess', _44 => _44.pause, 'call', _45 => _45()]);
466
+ _optionalChain([active, 'optionalAccess', _46 => _46.rrweb, 'optionalAccess', _47 => _47.pause, 'call', _48 => _48()]);
463
467
  if (active) active.paused = true;
464
468
  },
465
469
  resume() {
466
- _optionalChain([active, 'optionalAccess', _40 => _40.heatmap, 'optionalAccess', _41 => _41.resume, 'call', _42 => _42()]);
467
- _optionalChain([active, 'optionalAccess', _43 => _43.rrweb, 'optionalAccess', _44 => _44.resume, 'call', _45 => _45()]);
470
+ _optionalChain([active, 'optionalAccess', _49 => _49.heatmap, 'optionalAccess', _50 => _50.resume, 'call', _51 => _51()]);
471
+ _optionalChain([active, 'optionalAccess', _52 => _52.rrweb, 'optionalAccess', _53 => _53.resume, 'call', _54 => _54()]);
468
472
  if (active) active.paused = false;
469
473
  bumpSessionActivity();
470
474
  },
471
475
  setUser(user) {
472
476
  if (!active) return;
473
- active.userId = _nullishCoalesce(_optionalChain([user, 'optionalAccess', _46 => _46.id]), () => ( null));
477
+ active.userId = _nullishCoalesce(_optionalChain([user, 'optionalAccess', _55 => _55.id]), () => ( null));
474
478
  void postTrace(active.config, "/session/start", {
475
479
  sessionUid: active.sessionUid,
476
480
  anonId: getOrCreateAnonId(),
@@ -501,20 +505,23 @@ var replayApi = {
501
505
  * Bumps the page-views counter and emits a fresh page_view event.
502
506
  */
503
507
  notifyRouteChange(url, title) {
504
- if (!active || active.paused) return;
505
- if (isPathBlocked(active.options, location.pathname)) {
506
- _optionalChain([active, 'access', _47 => _47.heatmap, 'optionalAccess', _48 => _48.pause, 'call', _49 => _49()]);
507
- _optionalChain([active, 'access', _50 => _50.rrweb, 'optionalAccess', _51 => _51.pause, 'call', _52 => _52()]);
508
- active.paused = true;
508
+ if (!active) return;
509
+ const nowBlocked = isPathBlocked(active.options, location.pathname);
510
+ if (nowBlocked) {
511
+ if (!active.paused) {
512
+ _optionalChain([active, 'access', _56 => _56.heatmap, 'optionalAccess', _57 => _57.pause, 'call', _58 => _58()]);
513
+ _optionalChain([active, 'access', _59 => _59.rrweb, 'optionalAccess', _60 => _60.pause, 'call', _61 => _61()]);
514
+ active.paused = true;
515
+ }
509
516
  return;
510
517
  }
511
518
  if (active.paused) {
512
- _optionalChain([active, 'access', _53 => _53.heatmap, 'optionalAccess', _54 => _54.resume, 'call', _55 => _55()]);
513
- _optionalChain([active, 'access', _56 => _56.rrweb, 'optionalAccess', _57 => _57.resume, 'call', _58 => _58()]);
519
+ _optionalChain([active, 'access', _62 => _62.heatmap, 'optionalAccess', _63 => _63.resume, 'call', _64 => _64()]);
520
+ _optionalChain([active, 'access', _65 => _65.rrweb, 'optionalAccess', _66 => _66.resume, 'call', _67 => _67()]);
514
521
  active.paused = false;
515
522
  }
516
523
  active.pagesVisited += 1;
517
- _optionalChain([active, 'access', _59 => _59.rrweb, 'optionalAccess', _60 => _60.takeFullSnapshot, 'call', _61 => _61()]);
524
+ _optionalChain([active, 'access', _68 => _68.rrweb, 'optionalAccess', _69 => _69.takeFullSnapshot, 'call', _70 => _70()]);
518
525
  void postTrace(active.config, "/events", {
519
526
  events: [
520
527
  {
@@ -529,7 +536,7 @@ var replayApi = {
529
536
  },
530
537
  /** Test seam: returns null when replay was not activated for this session. */
531
538
  _sessionUid() {
532
- return _nullishCoalesce(_optionalChain([active, 'optionalAccess', _62 => _62.sessionUid]), () => ( null));
539
+ return _nullishCoalesce(_optionalChain([active, 'optionalAccess', _71 => _71.sessionUid]), () => ( null));
533
540
  }
534
541
  };
535
542
 
@@ -370,7 +370,7 @@ async function activateReplay(args) {
370
370
  setTimeout(onIdle, 5e3);
371
371
  }
372
372
  };
373
- void import("../rrweb-DCBIDQEX.mjs").then(
373
+ void import("../rrweb-O2KFXCVA.mjs").then(
374
374
  ({ startRrweb }) => new Promise((resolve) => {
375
375
  scheduleRrwebStart(() => {
376
376
  startRrweb({
@@ -402,14 +402,6 @@ async function activateReplay(args) {
402
402
  },
403
403
  body: bodyStr
404
404
  });
405
- if (typeof console !== "undefined") {
406
- console.log(
407
- "[segi.replay] /replay POST",
408
- res.status,
409
- bodyStr.length,
410
- "bytes"
411
- );
412
- }
413
405
  if (res.status === 429) {
414
406
  if (active) {
415
407
  active.replayBlocked = true;
@@ -417,13 +409,7 @@ async function activateReplay(args) {
417
409
  active.rrweb = null;
418
410
  }
419
411
  }
420
- } catch (err) {
421
- if (typeof console !== "undefined") {
422
- console.log(
423
- "[segi.replay] /replay POST FETCH FAILED:",
424
- err.message
425
- );
426
- }
412
+ } catch {
427
413
  }
428
414
  }
429
415
  }).then(resolve, () => resolve(null));
@@ -455,6 +441,24 @@ async function activateReplay(args) {
455
441
  clickCount: active.clickCount
456
442
  });
457
443
  });
444
+ const MAX_SESSION_DURATION_MS = 30 * 6e4;
445
+ setTimeout(() => {
446
+ if (!active) return;
447
+ active.rrweb?.flush(true);
448
+ active.rrweb?.stop();
449
+ active.rrweb = null;
450
+ active.heatmap?.stop();
451
+ active.heatmap = null;
452
+ beaconTrace(active.config, "/session/end", {
453
+ sessionUid: active.sessionUid,
454
+ endedAt: (/* @__PURE__ */ new Date()).toISOString(),
455
+ durationMs: Date.now() - new Date(active.startedAt).getTime(),
456
+ pagesVisited: active.pagesVisited,
457
+ clickCount: active.clickCount
458
+ });
459
+ active.paused = true;
460
+ active.replayBlocked = true;
461
+ }, MAX_SESSION_DURATION_MS);
458
462
  }
459
463
  var replayApi = {
460
464
  pause() {
@@ -501,11 +505,14 @@ var replayApi = {
501
505
  * Bumps the page-views counter and emits a fresh page_view event.
502
506
  */
503
507
  notifyRouteChange(url, title) {
504
- if (!active || active.paused) return;
505
- if (isPathBlocked(active.options, location.pathname)) {
506
- active.heatmap?.pause();
507
- active.rrweb?.pause();
508
- active.paused = true;
508
+ if (!active) return;
509
+ const nowBlocked = isPathBlocked(active.options, location.pathname);
510
+ if (nowBlocked) {
511
+ if (!active.paused) {
512
+ active.heatmap?.pause();
513
+ active.rrweb?.pause();
514
+ active.paused = true;
515
+ }
509
516
  return;
510
517
  }
511
518
  if (active.paused) {
@@ -48,39 +48,15 @@ async function startRrweb(args) {
48
48
  }, IDLE_CHECK_MS);
49
49
  function startRecorder() {
50
50
  if (stopFn) return;
51
- let emitCount = 0;
52
- const log = (...args2) => {
53
- if (typeof console !== "undefined") {
54
- console.log("[segi.replay]", ...args2);
55
- }
56
- };
57
- log("startRecorder() called, rrweb keys:", Object.keys(rrweb).slice(0, 12));
58
51
  const stop = rrweb.record({
59
52
  emit(event) {
60
- emitCount++;
61
- const e = event;
62
53
  if (paused || stopped) return;
63
54
  let serialized;
64
55
  try {
65
56
  serialized = JSON.stringify(event);
66
- } catch (err) {
67
- log(
68
- `emit #${emitCount} type:${e.type} source:${e.data?.source} STRINGIFY_FAILED:`,
69
- err.message
70
- );
57
+ } catch {
71
58
  return;
72
59
  }
73
- if (emitCount <= 10) {
74
- log(
75
- `emit #${emitCount}`,
76
- "type:",
77
- e.type,
78
- "source:",
79
- e.data?.source,
80
- "size:",
81
- serialized.length
82
- );
83
- }
84
60
  buffer.push(serialized);
85
61
  bufferBytes += serialized.length;
86
62
  if (bufferBytes >= FLUSH_BYTES) flush();
@@ -104,34 +80,21 @@ async function startRrweb(args) {
104
80
  // emit the FullSnapshot immediately and inline async-best-effort.
105
81
  });
106
82
  stopFn = typeof stop === "function" ? stop : null;
107
- log(
108
- "record() returned, stopFn:",
109
- typeof stop,
110
- "rrweb.record.takeFullSnapshot:",
111
- typeof rrweb.record.takeFullSnapshot,
112
- "rrweb.takeFullSnapshot:",
113
- typeof rrweb.takeFullSnapshot
114
- );
115
- const forceSnapshot = (label) => {
83
+ const forceSnapshot = () => {
116
84
  if (stopped || paused) return;
117
85
  try {
118
86
  const rrwebMod = rrweb;
119
87
  if (typeof rrwebMod.record.takeFullSnapshot === "function") {
120
- log(`forceSnapshot[${label}] via record.takeFullSnapshot`);
121
88
  rrwebMod.record.takeFullSnapshot(true);
122
89
  } else if (typeof rrwebMod.takeFullSnapshot === "function") {
123
- log(`forceSnapshot[${label}] via top-level takeFullSnapshot`);
124
90
  rrwebMod.takeFullSnapshot(true);
125
- } else {
126
- log(`forceSnapshot[${label}] no takeFullSnapshot found`);
127
91
  }
128
- } catch (err) {
129
- log(`forceSnapshot[${label}] threw:`, err);
92
+ } catch {
130
93
  }
131
94
  };
132
- setTimeout(() => forceSnapshot("100ms"), 100);
133
- setTimeout(() => forceSnapshot("500ms"), 500);
134
- setTimeout(() => forceSnapshot("2000ms"), 2e3);
95
+ setTimeout(forceSnapshot, 100);
96
+ setTimeout(forceSnapshot, 500);
97
+ setTimeout(forceSnapshot, 2e3);
135
98
  }
136
99
  function stopRrwebOnly() {
137
100
  try {
@@ -146,25 +109,6 @@ async function startRrweb(args) {
146
109
  const chunk = buffer;
147
110
  buffer = [];
148
111
  bufferBytes = 0;
149
- if (typeof console !== "undefined") {
150
- const totalSize = chunk.reduce((a, s) => a + s.length, 0);
151
- const types = {};
152
- for (const s of chunk) {
153
- const m = s.match(/^\{"type":(\d+)/);
154
- const t = m ? m[1] : "?";
155
- types[t] = (types[t] ?? 0) + 1;
156
- }
157
- console.log(
158
- "[segi.replay] flush:",
159
- chunk.length,
160
- "events,",
161
- totalSize,
162
- "bytes, types:",
163
- types,
164
- "useBeacon:",
165
- useBeacon
166
- );
167
- }
168
112
  try {
169
113
  args.sendChunk(chunk, useBeacon);
170
114
  } catch {
@@ -17,7 +17,7 @@ async function startRrweb(args) {
17
17
  let rrweb;
18
18
  try {
19
19
  rrweb = await Promise.resolve().then(() => _interopRequireWildcard(require("rrweb")));
20
- } catch (e2) {
20
+ } catch (e) {
21
21
  return null;
22
22
  }
23
23
  const maskClass = _nullishCoalesce(_optionalChain([args, 'access', _ => _.options, 'access', _2 => _2.mask, 'optionalAccess', _3 => _3.class]), () => ( "segi-mask"));
@@ -48,39 +48,15 @@ async function startRrweb(args) {
48
48
  }, IDLE_CHECK_MS);
49
49
  function startRecorder() {
50
50
  if (stopFn) return;
51
- let emitCount = 0;
52
- const log = (...args2) => {
53
- if (typeof console !== "undefined") {
54
- console.log("[segi.replay]", ...args2);
55
- }
56
- };
57
- log("startRecorder() called, rrweb keys:", Object.keys(rrweb).slice(0, 12));
58
51
  const stop = rrweb.record({
59
52
  emit(event) {
60
- emitCount++;
61
- const e = event;
62
53
  if (paused || stopped) return;
63
54
  let serialized;
64
55
  try {
65
56
  serialized = JSON.stringify(event);
66
- } catch (err) {
67
- log(
68
- `emit #${emitCount} type:${e.type} source:${_optionalChain([e, 'access', _7 => _7.data, 'optionalAccess', _8 => _8.source])} STRINGIFY_FAILED:`,
69
- err.message
70
- );
57
+ } catch (e2) {
71
58
  return;
72
59
  }
73
- if (emitCount <= 10) {
74
- log(
75
- `emit #${emitCount}`,
76
- "type:",
77
- e.type,
78
- "source:",
79
- _optionalChain([e, 'access', _9 => _9.data, 'optionalAccess', _10 => _10.source]),
80
- "size:",
81
- serialized.length
82
- );
83
- }
84
60
  buffer.push(serialized);
85
61
  bufferBytes += serialized.length;
86
62
  if (bufferBytes >= FLUSH_BYTES) flush();
@@ -104,38 +80,25 @@ async function startRrweb(args) {
104
80
  // emit the FullSnapshot immediately and inline async-best-effort.
105
81
  });
106
82
  stopFn = typeof stop === "function" ? stop : null;
107
- log(
108
- "record() returned, stopFn:",
109
- typeof stop,
110
- "rrweb.record.takeFullSnapshot:",
111
- typeof rrweb.record.takeFullSnapshot,
112
- "rrweb.takeFullSnapshot:",
113
- typeof rrweb.takeFullSnapshot
114
- );
115
- const forceSnapshot = (label) => {
83
+ const forceSnapshot = () => {
116
84
  if (stopped || paused) return;
117
85
  try {
118
86
  const rrwebMod = rrweb;
119
87
  if (typeof rrwebMod.record.takeFullSnapshot === "function") {
120
- log(`forceSnapshot[${label}] via record.takeFullSnapshot`);
121
88
  rrwebMod.record.takeFullSnapshot(true);
122
89
  } else if (typeof rrwebMod.takeFullSnapshot === "function") {
123
- log(`forceSnapshot[${label}] via top-level takeFullSnapshot`);
124
90
  rrwebMod.takeFullSnapshot(true);
125
- } else {
126
- log(`forceSnapshot[${label}] no takeFullSnapshot found`);
127
91
  }
128
- } catch (err) {
129
- log(`forceSnapshot[${label}] threw:`, err);
92
+ } catch (e3) {
130
93
  }
131
94
  };
132
- setTimeout(() => forceSnapshot("100ms"), 100);
133
- setTimeout(() => forceSnapshot("500ms"), 500);
134
- setTimeout(() => forceSnapshot("2000ms"), 2e3);
95
+ setTimeout(forceSnapshot, 100);
96
+ setTimeout(forceSnapshot, 500);
97
+ setTimeout(forceSnapshot, 2e3);
135
98
  }
136
99
  function stopRrwebOnly() {
137
100
  try {
138
- _optionalChain([stopFn, 'optionalCall', _11 => _11()]);
101
+ _optionalChain([stopFn, 'optionalCall', _7 => _7()]);
139
102
  } finally {
140
103
  stopFn = null;
141
104
  }
@@ -146,28 +109,9 @@ async function startRrweb(args) {
146
109
  const chunk = buffer;
147
110
  buffer = [];
148
111
  bufferBytes = 0;
149
- if (typeof console !== "undefined") {
150
- const totalSize = chunk.reduce((a, s) => a + s.length, 0);
151
- const types = {};
152
- for (const s of chunk) {
153
- const m = s.match(/^\{"type":(\d+)/);
154
- const t = m ? m[1] : "?";
155
- types[t] = (_nullishCoalesce(types[t], () => ( 0))) + 1;
156
- }
157
- console.log(
158
- "[segi.replay] flush:",
159
- chunk.length,
160
- "events,",
161
- totalSize,
162
- "bytes, types:",
163
- types,
164
- "useBeacon:",
165
- useBeacon
166
- );
167
- }
168
112
  try {
169
113
  args.sendChunk(chunk, useBeacon);
170
- } catch (e3) {
114
+ } catch (e4) {
171
115
  }
172
116
  }
173
117
  function onActivity() {
@@ -216,8 +160,8 @@ async function startRrweb(args) {
216
160
  if (stopped || paused) return;
217
161
  try {
218
162
  const rec = rrweb.record;
219
- _optionalChain([rec, 'access', _12 => _12.takeFullSnapshot, 'optionalCall', _13 => _13()]);
220
- } catch (e4) {
163
+ _optionalChain([rec, 'access', _8 => _8.takeFullSnapshot, 'optionalCall', _9 => _9()]);
164
+ } catch (e5) {
221
165
  }
222
166
  }
223
167
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extn/segi-js",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Browser JavaScript SDK for the segi error monitoring service",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",