@leanbase-giangnd/js 0.3.1 → 0.3.2

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.
@@ -2846,7 +2846,7 @@ var leanbase = (function () {
2846
2846
  }
2847
2847
  };
2848
2848
 
2849
- var version = "0.3.1";
2849
+ var version = "0.3.2";
2850
2850
  var packageInfo = {
2851
2851
  version: version};
2852
2852
 
@@ -6300,6 +6300,7 @@ var leanbase = (function () {
6300
6300
  this._stopRrweb = undefined;
6301
6301
  this._permanentlyDisabled = false;
6302
6302
  this._loggedPermanentlyDisabled = false;
6303
+ this._hasReportedRecordingInitialized = false;
6303
6304
  this._lastActivityTimestamp = Date.now();
6304
6305
  /**
6305
6306
  * and a queue - that contains rrweb events that we want to send to rrweb, but rrweb wasn't able to accept them yet
@@ -6735,7 +6736,13 @@ var leanbase = (function () {
6735
6736
  });
6736
6737
  }
6737
6738
  if (this.status === ACTIVE) {
6738
- this._reportStarted(startReason || 'recording_initialized');
6739
+ const reason = startReason || 'recording_initialized';
6740
+ if (reason !== 'recording_initialized' || !this._hasReportedRecordingInitialized) {
6741
+ if (reason === 'recording_initialized') {
6742
+ this._hasReportedRecordingInitialized = true;
6743
+ }
6744
+ this._reportStarted(reason);
6745
+ }
6739
6746
  }
6740
6747
  }
6741
6748
  stop() {
@@ -6768,6 +6775,7 @@ var leanbase = (function () {
6768
6775
  this._recording = undefined;
6769
6776
  this._stopRrweb = undefined;
6770
6777
  this._isFullyReady = false;
6778
+ this._hasReportedRecordingInitialized = false;
6771
6779
  logger.info('stopped');
6772
6780
  }
6773
6781
  _snapshotIngestionUrl() {
@@ -7067,7 +7075,12 @@ var leanbase = (function () {
7067
7075
  this._instance.registerForSession({
7068
7076
  $session_recording_start_reason: startReason
7069
7077
  });
7070
- logger.info(startReason.replace('_', ' '), tagPayload);
7078
+ const message = startReason.replace('_', ' ');
7079
+ if (typeof tagPayload === 'undefined') {
7080
+ logger.info(message);
7081
+ } else {
7082
+ logger.info(message, tagPayload);
7083
+ }
7071
7084
  if (!includes(['recording_initialized', 'session_id_changed'], startReason)) {
7072
7085
  this._tryAddCustomEvent(startReason, tagPayload);
7073
7086
  }
@@ -7534,6 +7547,39 @@ var leanbase = (function () {
7534
7547
  }
7535
7548
  }
7536
7549
 
7550
+ /**
7551
+ * Leanbase-local version of PostHog's RequestRouter.
7552
+ *
7553
+ * Browser SDK always has a requestRouter instance; Leanbase IIFE needs this too so
7554
+ * features like Session Replay can construct ingestion URLs.
7555
+ */
7556
+ class RequestRouter {
7557
+ // eslint-disable-next-line @typescript-eslint/naming-convention
7558
+ constructor(instance) {
7559
+ this.instance = instance;
7560
+ }
7561
+ get apiHost() {
7562
+ const configured = (this.instance.config.api_host || this.instance.config.host || '').trim();
7563
+ return configured.replace(/\/$/, '');
7564
+ }
7565
+ get uiHost() {
7566
+ const configured = this.instance.config.ui_host?.trim().replace(/\/$/, '');
7567
+ return configured || undefined;
7568
+ }
7569
+ endpointFor(target, path = '') {
7570
+ if (path) {
7571
+ path = path[0] === '/' ? path : `/${path}`;
7572
+ }
7573
+ if (target === 'ui') {
7574
+ const host = this.uiHost || this.apiHost;
7575
+ return host + path;
7576
+ }
7577
+ // Leanbase doesn't currently do region-based routing; default to apiHost.
7578
+ // Browser's router has special handling for assets; we keep parity in interface, not domains.
7579
+ return this.apiHost + path;
7580
+ }
7581
+ }
7582
+
7537
7583
  const defaultConfig = () => ({
7538
7584
  host: 'https://i.leanbase.co',
7539
7585
  token: '',
@@ -7591,6 +7637,8 @@ var leanbase = (function () {
7591
7637
  }));
7592
7638
  this.isLoaded = true;
7593
7639
  this.persistence = new LeanbasePersistence(this.config);
7640
+ // Browser SDK always has a requestRouter; session replay relies on it for $snapshot ingestion URLs.
7641
+ this.requestRouter = new RequestRouter(this);
7594
7642
  if (this.config.cookieless_mode !== 'always') {
7595
7643
  this.sessionManager = new SessionIdManager(this);
7596
7644
  this.sessionPropsManager = new SessionPropsManager(this, this.sessionManager, this.persistence);