@extn/segi-js 0.2.4 → 0.2.5

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.
@@ -367,7 +367,7 @@ async function activateReplay(args) {
367
367
  setTimeout(onIdle, 5e3);
368
368
  }
369
369
  };
370
- void Promise.resolve().then(() => _interopRequireWildcard(require("../rrweb-5RF4GJUU.js"))).then(
370
+ void Promise.resolve().then(() => _interopRequireWildcard(require("../rrweb-KAUSOLTH.js"))).then(
371
371
  ({ startRrweb }) => new Promise((resolve) => {
372
372
  scheduleRrwebStart(() => {
373
373
  startRrweb({
@@ -375,19 +375,52 @@ async function activateReplay(args) {
375
375
  options,
376
376
  sendChunk: async (chunk, useBeacon) => {
377
377
  if (!active || active.replayBlocked) return;
378
+ const bodyStr = `{"sessionUid":${JSON.stringify(sessionUid)},"chunk":[${chunk.join(",")}]}`;
379
+ const base = (transportCfg.endpoint || "https://segiapi.extn.ai").replace(/\/+$/, "").replace(/\/api\/ingest\/events$/, "").replace(/\/api\/ingest$/, "").replace(/\/api$/, "");
378
380
  if (useBeacon) {
379
- beaconTrace(transportCfg, "/replay", { sessionUid, chunk });
381
+ try {
382
+ const url = `${base}/api/trace/replay?pk=${encodeURIComponent(transportCfg.projectKey)}`;
383
+ const blob = new Blob([bodyStr], {
384
+ type: "application/json"
385
+ });
386
+ if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
387
+ navigator.sendBeacon(url, blob);
388
+ }
389
+ } catch (e12) {
390
+ }
380
391
  return;
381
392
  }
382
- const res = await postTrace(transportCfg, "/replay", {
383
- sessionUid,
384
- chunk
385
- });
386
- if (res && res.status === 429) {
387
- if (active) {
388
- active.replayBlocked = true;
389
- _optionalChain([active, 'access', _28 => _28.rrweb, 'optionalAccess', _29 => _29.stop, 'call', _30 => _30()]);
390
- active.rrweb = null;
393
+ try {
394
+ const res = await fetch(`${base}/api/trace/replay`, {
395
+ method: "POST",
396
+ headers: {
397
+ "Content-Type": "application/json",
398
+ "X-Segi-Project-Key": transportCfg.projectKey
399
+ },
400
+ body: bodyStr,
401
+ keepalive: true
402
+ });
403
+ if (typeof console !== "undefined") {
404
+ console.log(
405
+ "[segi.replay] /replay POST",
406
+ res.status,
407
+ bodyStr.length,
408
+ "bytes"
409
+ );
410
+ }
411
+ if (res.status === 429) {
412
+ if (active) {
413
+ active.replayBlocked = true;
414
+ _optionalChain([active, 'access', _28 => _28.rrweb, 'optionalAccess', _29 => _29.stop, 'call', _30 => _30()]);
415
+ active.rrweb = null;
416
+ }
417
+ }
418
+ } catch (err) {
419
+ if (typeof console !== "undefined") {
420
+ console.log(
421
+ "[segi.replay] /replay POST FETCH FAILED:",
422
+ err.message
423
+ );
391
424
  }
392
425
  }
393
426
  }
@@ -367,7 +367,7 @@ async function activateReplay(args) {
367
367
  setTimeout(onIdle, 5e3);
368
368
  }
369
369
  };
370
- void import("../rrweb-7F2GWQCE.mjs").then(
370
+ void import("../rrweb-DCBIDQEX.mjs").then(
371
371
  ({ startRrweb }) => new Promise((resolve) => {
372
372
  scheduleRrwebStart(() => {
373
373
  startRrweb({
@@ -375,19 +375,52 @@ async function activateReplay(args) {
375
375
  options,
376
376
  sendChunk: async (chunk, useBeacon) => {
377
377
  if (!active || active.replayBlocked) return;
378
+ const bodyStr = `{"sessionUid":${JSON.stringify(sessionUid)},"chunk":[${chunk.join(",")}]}`;
379
+ const base = (transportCfg.endpoint || "https://segiapi.extn.ai").replace(/\/+$/, "").replace(/\/api\/ingest\/events$/, "").replace(/\/api\/ingest$/, "").replace(/\/api$/, "");
378
380
  if (useBeacon) {
379
- beaconTrace(transportCfg, "/replay", { sessionUid, chunk });
381
+ try {
382
+ const url = `${base}/api/trace/replay?pk=${encodeURIComponent(transportCfg.projectKey)}`;
383
+ const blob = new Blob([bodyStr], {
384
+ type: "application/json"
385
+ });
386
+ if (typeof navigator !== "undefined" && typeof navigator.sendBeacon === "function") {
387
+ navigator.sendBeacon(url, blob);
388
+ }
389
+ } catch {
390
+ }
380
391
  return;
381
392
  }
382
- const res = await postTrace(transportCfg, "/replay", {
383
- sessionUid,
384
- chunk
385
- });
386
- if (res && res.status === 429) {
387
- if (active) {
388
- active.replayBlocked = true;
389
- active.rrweb?.stop();
390
- active.rrweb = null;
393
+ try {
394
+ const res = await fetch(`${base}/api/trace/replay`, {
395
+ method: "POST",
396
+ headers: {
397
+ "Content-Type": "application/json",
398
+ "X-Segi-Project-Key": transportCfg.projectKey
399
+ },
400
+ body: bodyStr,
401
+ keepalive: true
402
+ });
403
+ if (typeof console !== "undefined") {
404
+ console.log(
405
+ "[segi.replay] /replay POST",
406
+ res.status,
407
+ bodyStr.length,
408
+ "bytes"
409
+ );
410
+ }
411
+ if (res.status === 429) {
412
+ if (active) {
413
+ active.replayBlocked = true;
414
+ active.rrweb?.stop();
415
+ active.rrweb = null;
416
+ }
417
+ }
418
+ } catch (err) {
419
+ if (typeof console !== "undefined") {
420
+ console.log(
421
+ "[segi.replay] /replay POST FETCH FAILED:",
422
+ err.message
423
+ );
391
424
  }
392
425
  }
393
426
  }
@@ -59,6 +59,17 @@ async function startRrweb(args) {
59
59
  emit(event) {
60
60
  emitCount++;
61
61
  const e = event;
62
+ if (paused || stopped) return;
63
+ let serialized;
64
+ try {
65
+ 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
+ );
71
+ return;
72
+ }
62
73
  if (emitCount <= 10) {
63
74
  log(
64
75
  `emit #${emitCount}`,
@@ -66,18 +77,12 @@ async function startRrweb(args) {
66
77
  e.type,
67
78
  "source:",
68
79
  e.data?.source,
69
- "paused:",
70
- paused,
71
- "stopped:",
72
- stopped
80
+ "size:",
81
+ serialized.length
73
82
  );
74
83
  }
75
- if (paused || stopped) return;
76
- buffer.push(event);
77
- try {
78
- bufferBytes += JSON.stringify(event).length;
79
- } catch {
80
- }
84
+ buffer.push(serialized);
85
+ bufferBytes += serialized.length;
81
86
  if (bufferBytes >= FLUSH_BYTES) flush();
82
87
  },
83
88
  // `input: "last"` emits only the final value of each keystroke
@@ -141,6 +146,25 @@ async function startRrweb(args) {
141
146
  const chunk = buffer;
142
147
  buffer = [];
143
148
  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
+ }
144
168
  try {
145
169
  args.sendChunk(chunk, useBeacon);
146
170
  } catch {
@@ -59,25 +59,30 @@ async function startRrweb(args) {
59
59
  emit(event) {
60
60
  emitCount++;
61
61
  const e = event;
62
+ if (paused || stopped) return;
63
+ let serialized;
64
+ try {
65
+ 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
+ );
71
+ return;
72
+ }
62
73
  if (emitCount <= 10) {
63
74
  log(
64
75
  `emit #${emitCount}`,
65
76
  "type:",
66
77
  e.type,
67
78
  "source:",
68
- _optionalChain([e, 'access', _7 => _7.data, 'optionalAccess', _8 => _8.source]),
69
- "paused:",
70
- paused,
71
- "stopped:",
72
- stopped
79
+ _optionalChain([e, 'access', _9 => _9.data, 'optionalAccess', _10 => _10.source]),
80
+ "size:",
81
+ serialized.length
73
82
  );
74
83
  }
75
- if (paused || stopped) return;
76
- buffer.push(event);
77
- try {
78
- bufferBytes += JSON.stringify(event).length;
79
- } catch (e3) {
80
- }
84
+ buffer.push(serialized);
85
+ bufferBytes += serialized.length;
81
86
  if (bufferBytes >= FLUSH_BYTES) flush();
82
87
  },
83
88
  // `input: "last"` emits only the final value of each keystroke
@@ -130,7 +135,7 @@ async function startRrweb(args) {
130
135
  }
131
136
  function stopRrwebOnly() {
132
137
  try {
133
- _optionalChain([stopFn, 'optionalCall', _9 => _9()]);
138
+ _optionalChain([stopFn, 'optionalCall', _11 => _11()]);
134
139
  } finally {
135
140
  stopFn = null;
136
141
  }
@@ -141,9 +146,28 @@ async function startRrweb(args) {
141
146
  const chunk = buffer;
142
147
  buffer = [];
143
148
  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
+ }
144
168
  try {
145
169
  args.sendChunk(chunk, useBeacon);
146
- } catch (e4) {
170
+ } catch (e3) {
147
171
  }
148
172
  }
149
173
  function onActivity() {
@@ -192,8 +216,8 @@ async function startRrweb(args) {
192
216
  if (stopped || paused) return;
193
217
  try {
194
218
  const rec = rrweb.record;
195
- _optionalChain([rec, 'access', _10 => _10.takeFullSnapshot, 'optionalCall', _11 => _11()]);
196
- } catch (e5) {
219
+ _optionalChain([rec, 'access', _12 => _12.takeFullSnapshot, 'optionalCall', _13 => _13()]);
220
+ } catch (e4) {
197
221
  }
198
222
  }
199
223
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extn/segi-js",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "Browser JavaScript SDK for the segi error monitoring service",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",