@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 +51 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +58 -43
- package/dist/index.mjs +51 -3
- package/dist/index.mjs.map +1 -1
- package/dist/leanbase.iife.js +51 -3
- package/dist/leanbase.iife.js.map +1 -1
- package/package.json +1 -1
- package/src/extensions/replay/external/lazy-loaded-session-recorder.ts +15 -2
- package/src/leanbase.ts +4 -1
- package/src/utils/request-router.ts +39 -0
- package/src/version.ts +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1409,6 +1409,21 @@ declare class SessionRecording$1 {
|
|
|
1409
1409
|
tryAddCustomEvent(tag: string, payload: any): boolean;
|
|
1410
1410
|
}
|
|
1411
1411
|
|
|
1412
|
+
type RequestRouterTarget$1 = 'api' | 'ui' | 'assets';
|
|
1413
|
+
/**
|
|
1414
|
+
* Leanbase-local version of PostHog's RequestRouter.
|
|
1415
|
+
*
|
|
1416
|
+
* Browser SDK always has a requestRouter instance; Leanbase IIFE needs this too so
|
|
1417
|
+
* features like Session Replay can construct ingestion URLs.
|
|
1418
|
+
*/
|
|
1419
|
+
declare class RequestRouter$1 {
|
|
1420
|
+
private readonly instance;
|
|
1421
|
+
constructor(instance: Leanbase);
|
|
1422
|
+
get apiHost(): string;
|
|
1423
|
+
get uiHost(): string | undefined;
|
|
1424
|
+
endpointFor(target: RequestRouterTarget$1, path?: string): string;
|
|
1425
|
+
}
|
|
1426
|
+
|
|
1412
1427
|
declare class RageClick {
|
|
1413
1428
|
clicks: {
|
|
1414
1429
|
x: number;
|
|
@@ -3722,31 +3737,6 @@ declare class Autocapture {
|
|
|
3722
3737
|
isBrowserSupported(): boolean;
|
|
3723
3738
|
}
|
|
3724
3739
|
|
|
3725
|
-
declare enum ConsentStatus {
|
|
3726
|
-
PENDING = -1,
|
|
3727
|
-
DENIED = 0,
|
|
3728
|
-
GRANTED = 1
|
|
3729
|
-
}
|
|
3730
|
-
/**
|
|
3731
|
-
* ConsentManager provides tools for managing user consent as configured by the application.
|
|
3732
|
-
*/
|
|
3733
|
-
declare class ConsentManager {
|
|
3734
|
-
private _instance;
|
|
3735
|
-
private _persistentStore?;
|
|
3736
|
-
constructor(_instance: PostHog);
|
|
3737
|
-
private get _config();
|
|
3738
|
-
get consent(): ConsentStatus;
|
|
3739
|
-
isOptedOut(): boolean;
|
|
3740
|
-
isOptedIn(): boolean;
|
|
3741
|
-
isExplicitlyOptedOut(): boolean;
|
|
3742
|
-
optInOut(isOptedIn: boolean): void;
|
|
3743
|
-
reset(): void;
|
|
3744
|
-
private get _storageKey();
|
|
3745
|
-
private get _storedConsent();
|
|
3746
|
-
private get _storage();
|
|
3747
|
-
private _getDnt;
|
|
3748
|
-
}
|
|
3749
|
-
|
|
3750
3740
|
declare class SessionIdManager {
|
|
3751
3741
|
private readonly _sessionIdGenerator;
|
|
3752
3742
|
private readonly _windowIdGenerator;
|
|
@@ -4410,6 +4400,27 @@ declare class SiteApps {
|
|
|
4410
4400
|
onRemoteConfig(response: RemoteConfig): void;
|
|
4411
4401
|
}
|
|
4412
4402
|
|
|
4403
|
+
/**
|
|
4404
|
+
* The request router helps simplify the logic to determine which endpoints should be called for which things
|
|
4405
|
+
* The basic idea is that for a given region (US or EU), we have a set of endpoints that we should call depending
|
|
4406
|
+
* on the type of request (events, replays, flags, etc.) and handle overrides that may come from configs or the flags endpoint
|
|
4407
|
+
*/
|
|
4408
|
+
declare enum RequestRouterRegion {
|
|
4409
|
+
US = "us",
|
|
4410
|
+
EU = "eu",
|
|
4411
|
+
CUSTOM = "custom"
|
|
4412
|
+
}
|
|
4413
|
+
type RequestRouterTarget = 'api' | 'ui' | 'assets';
|
|
4414
|
+
declare class RequestRouter {
|
|
4415
|
+
instance: PostHog;
|
|
4416
|
+
private _regionCache;
|
|
4417
|
+
constructor(instance: PostHog);
|
|
4418
|
+
get apiHost(): string;
|
|
4419
|
+
get uiHost(): string | undefined;
|
|
4420
|
+
get region(): RequestRouterRegion;
|
|
4421
|
+
endpointFor(target: RequestRouterTarget, path?: string): string;
|
|
4422
|
+
}
|
|
4423
|
+
|
|
4413
4424
|
interface WebExperimentTransform {
|
|
4414
4425
|
attributes?: {
|
|
4415
4426
|
name: string;
|
|
@@ -6055,25 +6066,29 @@ declare class PostHog {
|
|
|
6055
6066
|
private _checkLocalStorageForDebug;
|
|
6056
6067
|
}
|
|
6057
6068
|
|
|
6069
|
+
declare enum ConsentStatus {
|
|
6070
|
+
PENDING = -1,
|
|
6071
|
+
DENIED = 0,
|
|
6072
|
+
GRANTED = 1
|
|
6073
|
+
}
|
|
6058
6074
|
/**
|
|
6059
|
-
*
|
|
6060
|
-
* The basic idea is that for a given region (US or EU), we have a set of endpoints that we should call depending
|
|
6061
|
-
* on the type of request (events, replays, flags, etc.) and handle overrides that may come from configs or the flags endpoint
|
|
6075
|
+
* ConsentManager provides tools for managing user consent as configured by the application.
|
|
6062
6076
|
*/
|
|
6063
|
-
declare
|
|
6064
|
-
|
|
6065
|
-
|
|
6066
|
-
|
|
6067
|
-
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
|
|
6072
|
-
|
|
6073
|
-
|
|
6074
|
-
get
|
|
6075
|
-
get
|
|
6076
|
-
|
|
6077
|
+
declare class ConsentManager {
|
|
6078
|
+
private _instance;
|
|
6079
|
+
private _persistentStore?;
|
|
6080
|
+
constructor(_instance: PostHog);
|
|
6081
|
+
private get _config();
|
|
6082
|
+
get consent(): ConsentStatus;
|
|
6083
|
+
isOptedOut(): boolean;
|
|
6084
|
+
isOptedIn(): boolean;
|
|
6085
|
+
isExplicitlyOptedOut(): boolean;
|
|
6086
|
+
optInOut(isOptedIn: boolean): void;
|
|
6087
|
+
reset(): void;
|
|
6088
|
+
private get _storageKey();
|
|
6089
|
+
private get _storedConsent();
|
|
6090
|
+
private get _storage();
|
|
6091
|
+
private _getDnt;
|
|
6077
6092
|
}
|
|
6078
6093
|
|
|
6079
6094
|
declare class Leanbase extends PostHogCore {
|
|
@@ -6085,7 +6100,7 @@ declare class Leanbase extends PostHogCore {
|
|
|
6085
6100
|
sessionPersistence?: LeanbasePersistence;
|
|
6086
6101
|
sessionManager?: SessionIdManager$1;
|
|
6087
6102
|
sessionPropsManager?: SessionPropsManager$1;
|
|
6088
|
-
requestRouter: RequestRouter;
|
|
6103
|
+
requestRouter: RequestRouter$1;
|
|
6089
6104
|
consent: ConsentManager;
|
|
6090
6105
|
sessionRecording?: SessionRecording$1;
|
|
6091
6106
|
isRemoteConfigLoaded?: boolean;
|
package/dist/index.mjs
CHANGED
|
@@ -1169,7 +1169,7 @@ const detectDeviceType = function (user_agent) {
|
|
|
1169
1169
|
}
|
|
1170
1170
|
};
|
|
1171
1171
|
|
|
1172
|
-
var version = "0.3.
|
|
1172
|
+
var version = "0.3.2";
|
|
1173
1173
|
var packageInfo = {
|
|
1174
1174
|
version: version};
|
|
1175
1175
|
|
|
@@ -4039,6 +4039,7 @@ class LazyLoadedSessionRecording {
|
|
|
4039
4039
|
this._stopRrweb = undefined;
|
|
4040
4040
|
this._permanentlyDisabled = false;
|
|
4041
4041
|
this._loggedPermanentlyDisabled = false;
|
|
4042
|
+
this._hasReportedRecordingInitialized = false;
|
|
4042
4043
|
this._lastActivityTimestamp = Date.now();
|
|
4043
4044
|
/**
|
|
4044
4045
|
* and a queue - that contains rrweb events that we want to send to rrweb, but rrweb wasn't able to accept them yet
|
|
@@ -4474,7 +4475,13 @@ class LazyLoadedSessionRecording {
|
|
|
4474
4475
|
});
|
|
4475
4476
|
}
|
|
4476
4477
|
if (this.status === ACTIVE) {
|
|
4477
|
-
|
|
4478
|
+
const reason = startReason || 'recording_initialized';
|
|
4479
|
+
if (reason !== 'recording_initialized' || !this._hasReportedRecordingInitialized) {
|
|
4480
|
+
if (reason === 'recording_initialized') {
|
|
4481
|
+
this._hasReportedRecordingInitialized = true;
|
|
4482
|
+
}
|
|
4483
|
+
this._reportStarted(reason);
|
|
4484
|
+
}
|
|
4478
4485
|
}
|
|
4479
4486
|
}
|
|
4480
4487
|
stop() {
|
|
@@ -4507,6 +4514,7 @@ class LazyLoadedSessionRecording {
|
|
|
4507
4514
|
this._recording = undefined;
|
|
4508
4515
|
this._stopRrweb = undefined;
|
|
4509
4516
|
this._isFullyReady = false;
|
|
4517
|
+
this._hasReportedRecordingInitialized = false;
|
|
4510
4518
|
logger.info('stopped');
|
|
4511
4519
|
}
|
|
4512
4520
|
_snapshotIngestionUrl() {
|
|
@@ -4806,7 +4814,12 @@ class LazyLoadedSessionRecording {
|
|
|
4806
4814
|
this._instance.registerForSession({
|
|
4807
4815
|
$session_recording_start_reason: startReason
|
|
4808
4816
|
});
|
|
4809
|
-
|
|
4817
|
+
const message = startReason.replace('_', ' ');
|
|
4818
|
+
if (typeof tagPayload === 'undefined') {
|
|
4819
|
+
logger.info(message);
|
|
4820
|
+
} else {
|
|
4821
|
+
logger.info(message, tagPayload);
|
|
4822
|
+
}
|
|
4810
4823
|
if (!includes(['recording_initialized', 'session_id_changed'], startReason)) {
|
|
4811
4824
|
this._tryAddCustomEvent(startReason, tagPayload);
|
|
4812
4825
|
}
|
|
@@ -5273,6 +5286,39 @@ class SessionRecording {
|
|
|
5273
5286
|
}
|
|
5274
5287
|
}
|
|
5275
5288
|
|
|
5289
|
+
/**
|
|
5290
|
+
* Leanbase-local version of PostHog's RequestRouter.
|
|
5291
|
+
*
|
|
5292
|
+
* Browser SDK always has a requestRouter instance; Leanbase IIFE needs this too so
|
|
5293
|
+
* features like Session Replay can construct ingestion URLs.
|
|
5294
|
+
*/
|
|
5295
|
+
class RequestRouter {
|
|
5296
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5297
|
+
constructor(instance) {
|
|
5298
|
+
this.instance = instance;
|
|
5299
|
+
}
|
|
5300
|
+
get apiHost() {
|
|
5301
|
+
const configured = (this.instance.config.api_host || this.instance.config.host || '').trim();
|
|
5302
|
+
return configured.replace(/\/$/, '');
|
|
5303
|
+
}
|
|
5304
|
+
get uiHost() {
|
|
5305
|
+
const configured = this.instance.config.ui_host?.trim().replace(/\/$/, '');
|
|
5306
|
+
return configured || undefined;
|
|
5307
|
+
}
|
|
5308
|
+
endpointFor(target, path = '') {
|
|
5309
|
+
if (path) {
|
|
5310
|
+
path = path[0] === '/' ? path : `/${path}`;
|
|
5311
|
+
}
|
|
5312
|
+
if (target === 'ui') {
|
|
5313
|
+
const host = this.uiHost || this.apiHost;
|
|
5314
|
+
return host + path;
|
|
5315
|
+
}
|
|
5316
|
+
// Leanbase doesn't currently do region-based routing; default to apiHost.
|
|
5317
|
+
// Browser's router has special handling for assets; we keep parity in interface, not domains.
|
|
5318
|
+
return this.apiHost + path;
|
|
5319
|
+
}
|
|
5320
|
+
}
|
|
5321
|
+
|
|
5276
5322
|
const defaultConfig = () => ({
|
|
5277
5323
|
host: 'https://i.leanbase.co',
|
|
5278
5324
|
token: '',
|
|
@@ -5330,6 +5376,8 @@ class Leanbase extends PostHogCore {
|
|
|
5330
5376
|
}));
|
|
5331
5377
|
this.isLoaded = true;
|
|
5332
5378
|
this.persistence = new LeanbasePersistence(this.config);
|
|
5379
|
+
// Browser SDK always has a requestRouter; session replay relies on it for $snapshot ingestion URLs.
|
|
5380
|
+
this.requestRouter = new RequestRouter(this);
|
|
5333
5381
|
if (this.config.cookieless_mode !== 'always') {
|
|
5334
5382
|
this.sessionManager = new SessionIdManager(this);
|
|
5335
5383
|
this.sessionPropsManager = new SessionPropsManager(this, this.sessionManager, this.persistence);
|