@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.
package/dist/index.cjs CHANGED
@@ -1171,7 +1171,7 @@ const detectDeviceType = function (user_agent) {
1171
1171
  }
1172
1172
  };
1173
1173
 
1174
- var version = "0.3.1";
1174
+ var version = "0.3.2";
1175
1175
  var packageInfo = {
1176
1176
  version: version};
1177
1177
 
@@ -4041,6 +4041,7 @@ class LazyLoadedSessionRecording {
4041
4041
  this._stopRrweb = undefined;
4042
4042
  this._permanentlyDisabled = false;
4043
4043
  this._loggedPermanentlyDisabled = false;
4044
+ this._hasReportedRecordingInitialized = false;
4044
4045
  this._lastActivityTimestamp = Date.now();
4045
4046
  /**
4046
4047
  * and a queue - that contains rrweb events that we want to send to rrweb, but rrweb wasn't able to accept them yet
@@ -4476,7 +4477,13 @@ class LazyLoadedSessionRecording {
4476
4477
  });
4477
4478
  }
4478
4479
  if (this.status === ACTIVE) {
4479
- this._reportStarted(startReason || 'recording_initialized');
4480
+ const reason = startReason || 'recording_initialized';
4481
+ if (reason !== 'recording_initialized' || !this._hasReportedRecordingInitialized) {
4482
+ if (reason === 'recording_initialized') {
4483
+ this._hasReportedRecordingInitialized = true;
4484
+ }
4485
+ this._reportStarted(reason);
4486
+ }
4480
4487
  }
4481
4488
  }
4482
4489
  stop() {
@@ -4509,6 +4516,7 @@ class LazyLoadedSessionRecording {
4509
4516
  this._recording = undefined;
4510
4517
  this._stopRrweb = undefined;
4511
4518
  this._isFullyReady = false;
4519
+ this._hasReportedRecordingInitialized = false;
4512
4520
  logger.info('stopped');
4513
4521
  }
4514
4522
  _snapshotIngestionUrl() {
@@ -4808,7 +4816,12 @@ class LazyLoadedSessionRecording {
4808
4816
  this._instance.registerForSession({
4809
4817
  $session_recording_start_reason: startReason
4810
4818
  });
4811
- logger.info(startReason.replace('_', ' '), tagPayload);
4819
+ const message = startReason.replace('_', ' ');
4820
+ if (typeof tagPayload === 'undefined') {
4821
+ logger.info(message);
4822
+ } else {
4823
+ logger.info(message, tagPayload);
4824
+ }
4812
4825
  if (!core.includes(['recording_initialized', 'session_id_changed'], startReason)) {
4813
4826
  this._tryAddCustomEvent(startReason, tagPayload);
4814
4827
  }
@@ -5275,6 +5288,39 @@ class SessionRecording {
5275
5288
  }
5276
5289
  }
5277
5290
 
5291
+ /**
5292
+ * Leanbase-local version of PostHog's RequestRouter.
5293
+ *
5294
+ * Browser SDK always has a requestRouter instance; Leanbase IIFE needs this too so
5295
+ * features like Session Replay can construct ingestion URLs.
5296
+ */
5297
+ class RequestRouter {
5298
+ // eslint-disable-next-line @typescript-eslint/naming-convention
5299
+ constructor(instance) {
5300
+ this.instance = instance;
5301
+ }
5302
+ get apiHost() {
5303
+ const configured = (this.instance.config.api_host || this.instance.config.host || '').trim();
5304
+ return configured.replace(/\/$/, '');
5305
+ }
5306
+ get uiHost() {
5307
+ const configured = this.instance.config.ui_host?.trim().replace(/\/$/, '');
5308
+ return configured || undefined;
5309
+ }
5310
+ endpointFor(target, path = '') {
5311
+ if (path) {
5312
+ path = path[0] === '/' ? path : `/${path}`;
5313
+ }
5314
+ if (target === 'ui') {
5315
+ const host = this.uiHost || this.apiHost;
5316
+ return host + path;
5317
+ }
5318
+ // Leanbase doesn't currently do region-based routing; default to apiHost.
5319
+ // Browser's router has special handling for assets; we keep parity in interface, not domains.
5320
+ return this.apiHost + path;
5321
+ }
5322
+ }
5323
+
5278
5324
  const defaultConfig = () => ({
5279
5325
  host: 'https://i.leanbase.co',
5280
5326
  token: '',
@@ -5332,6 +5378,8 @@ class Leanbase extends core.PostHogCore {
5332
5378
  }));
5333
5379
  this.isLoaded = true;
5334
5380
  this.persistence = new LeanbasePersistence(this.config);
5381
+ // Browser SDK always has a requestRouter; session replay relies on it for $snapshot ingestion URLs.
5382
+ this.requestRouter = new RequestRouter(this);
5335
5383
  if (this.config.cookieless_mode !== 'always') {
5336
5384
  this.sessionManager = new SessionIdManager(this);
5337
5385
  this.sessionPropsManager = new SessionPropsManager(this, this.sessionManager, this.persistence);