@extn/segi-js 0.2.7 → 0.2.9

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
@@ -55,7 +55,18 @@ function buildEvent(state2, base) {
55
55
  }
56
56
 
57
57
  // src/transport.ts
58
+
59
+
60
+
58
61
  var _segishared = require('@extn/segi-shared');
62
+ function resolveIngestUrl(endpoint) {
63
+ const raw = endpoint && endpoint.trim() || _segishared.SEGI_DEFAULT_INGEST_ENDPOINT;
64
+ if (/\/api\/ingest\/events\/?$/.test(raw)) {
65
+ return raw.replace(/\/+$/, "");
66
+ }
67
+ const base = raw.replace(/\/+$/, "").replace(/\/api\/ingest$/, "").replace(/\/api$/, "");
68
+ return `${base || _segishared.SEGI_DEFAULT_API_BASE}/api/ingest/events`;
69
+ }
59
70
  var warnedKeys = /* @__PURE__ */ new Set();
60
71
  function warnOnce(key, message) {
61
72
  if (warnedKeys.has(key)) return;
@@ -74,7 +85,7 @@ function describeStatus(status) {
74
85
  return "ingest returned a non-2xx response";
75
86
  }
76
87
  function send(endpoint, projectKey, event) {
77
- const url = endpoint || _segishared.SEGI_DEFAULT_INGEST_ENDPOINT;
88
+ const url = resolveIngestUrl(endpoint);
78
89
  if (!url || !projectKey) {
79
90
  warnOnce(
80
91
  "missing-config",
package/dist/index.mjs CHANGED
@@ -55,7 +55,18 @@ function buildEvent(state2, base) {
55
55
  }
56
56
 
57
57
  // src/transport.ts
58
- import { SEGI_DEFAULT_INGEST_ENDPOINT } from "@extn/segi-shared";
58
+ import {
59
+ SEGI_DEFAULT_API_BASE,
60
+ SEGI_DEFAULT_INGEST_ENDPOINT
61
+ } from "@extn/segi-shared";
62
+ function resolveIngestUrl(endpoint) {
63
+ const raw = endpoint && endpoint.trim() || SEGI_DEFAULT_INGEST_ENDPOINT;
64
+ if (/\/api\/ingest\/events\/?$/.test(raw)) {
65
+ return raw.replace(/\/+$/, "");
66
+ }
67
+ const base = raw.replace(/\/+$/, "").replace(/\/api\/ingest$/, "").replace(/\/api$/, "");
68
+ return `${base || SEGI_DEFAULT_API_BASE}/api/ingest/events`;
69
+ }
59
70
  var warnedKeys = /* @__PURE__ */ new Set();
60
71
  function warnOnce(key, message) {
61
72
  if (warnedKeys.has(key)) return;
@@ -74,7 +85,7 @@ function describeStatus(status) {
74
85
  return "ingest returned a non-2xx response";
75
86
  }
76
87
  function send(endpoint, projectKey, event) {
77
- const url = endpoint || SEGI_DEFAULT_INGEST_ENDPOINT;
88
+ const url = resolveIngestUrl(endpoint);
78
89
  if (!url || !projectKey) {
79
90
  warnOnce(
80
91
  "missing-config",
@@ -441,22 +441,40 @@ async function activateReplay(args) {
441
441
  clickCount: active.clickCount
442
442
  });
443
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);
444
462
  }
445
463
  var replayApi = {
446
464
  pause() {
447
- _optionalChain([active, 'optionalAccess', _34 => _34.heatmap, 'optionalAccess', _35 => _35.pause, 'call', _36 => _36()]);
448
- _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()]);
449
467
  if (active) active.paused = true;
450
468
  },
451
469
  resume() {
452
- _optionalChain([active, 'optionalAccess', _40 => _40.heatmap, 'optionalAccess', _41 => _41.resume, 'call', _42 => _42()]);
453
- _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()]);
454
472
  if (active) active.paused = false;
455
473
  bumpSessionActivity();
456
474
  },
457
475
  setUser(user) {
458
476
  if (!active) return;
459
- active.userId = _nullishCoalesce(_optionalChain([user, 'optionalAccess', _46 => _46.id]), () => ( null));
477
+ active.userId = _nullishCoalesce(_optionalChain([user, 'optionalAccess', _55 => _55.id]), () => ( null));
460
478
  void postTrace(active.config, "/session/start", {
461
479
  sessionUid: active.sessionUid,
462
480
  anonId: getOrCreateAnonId(),
@@ -491,19 +509,19 @@ var replayApi = {
491
509
  const nowBlocked = isPathBlocked(active.options, location.pathname);
492
510
  if (nowBlocked) {
493
511
  if (!active.paused) {
494
- _optionalChain([active, 'access', _47 => _47.heatmap, 'optionalAccess', _48 => _48.pause, 'call', _49 => _49()]);
495
- _optionalChain([active, 'access', _50 => _50.rrweb, 'optionalAccess', _51 => _51.pause, 'call', _52 => _52()]);
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()]);
496
514
  active.paused = true;
497
515
  }
498
516
  return;
499
517
  }
500
518
  if (active.paused) {
501
- _optionalChain([active, 'access', _53 => _53.heatmap, 'optionalAccess', _54 => _54.resume, 'call', _55 => _55()]);
502
- _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()]);
503
521
  active.paused = false;
504
522
  }
505
523
  active.pagesVisited += 1;
506
- _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()]);
507
525
  void postTrace(active.config, "/events", {
508
526
  events: [
509
527
  {
@@ -518,7 +536,7 @@ var replayApi = {
518
536
  },
519
537
  /** Test seam: returns null when replay was not activated for this session. */
520
538
  _sessionUid() {
521
- return _nullishCoalesce(_optionalChain([active, 'optionalAccess', _62 => _62.sessionUid]), () => ( null));
539
+ return _nullishCoalesce(_optionalChain([active, 'optionalAccess', _71 => _71.sessionUid]), () => ( null));
522
540
  }
523
541
  };
524
542
 
@@ -441,6 +441,24 @@ async function activateReplay(args) {
441
441
  clickCount: active.clickCount
442
442
  });
443
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);
444
462
  }
445
463
  var replayApi = {
446
464
  pause() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@extn/segi-js",
3
- "version": "0.2.7",
3
+ "version": "0.2.9",
4
4
  "description": "Browser JavaScript SDK for the segi error monitoring service",
5
5
  "license": "UNLICENSED",
6
6
  "main": "./dist/index.js",