@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/package.json
CHANGED
|
@@ -324,6 +324,7 @@ export class LazyLoadedSessionRecording {
|
|
|
324
324
|
private _stopRrweb: listenerHandler | undefined = undefined
|
|
325
325
|
private _permanentlyDisabled: boolean = false
|
|
326
326
|
private _loggedPermanentlyDisabled: boolean = false
|
|
327
|
+
private _hasReportedRecordingInitialized: boolean = false
|
|
327
328
|
private _lastActivityTimestamp: number = Date.now()
|
|
328
329
|
/**
|
|
329
330
|
* if pageview capture is disabled,
|
|
@@ -886,7 +887,13 @@ export class LazyLoadedSessionRecording {
|
|
|
886
887
|
}
|
|
887
888
|
|
|
888
889
|
if (this.status === ACTIVE) {
|
|
889
|
-
|
|
890
|
+
const reason = startReason || 'recording_initialized'
|
|
891
|
+
if (reason !== 'recording_initialized' || !this._hasReportedRecordingInitialized) {
|
|
892
|
+
if (reason === 'recording_initialized') {
|
|
893
|
+
this._hasReportedRecordingInitialized = true
|
|
894
|
+
}
|
|
895
|
+
this._reportStarted(reason)
|
|
896
|
+
}
|
|
890
897
|
}
|
|
891
898
|
}
|
|
892
899
|
|
|
@@ -942,6 +949,7 @@ export class LazyLoadedSessionRecording {
|
|
|
942
949
|
this._recording = undefined
|
|
943
950
|
this._stopRrweb = undefined
|
|
944
951
|
this._isFullyReady = false
|
|
952
|
+
this._hasReportedRecordingInitialized = false
|
|
945
953
|
|
|
946
954
|
logger.info('stopped')
|
|
947
955
|
}
|
|
@@ -1315,7 +1323,12 @@ export class LazyLoadedSessionRecording {
|
|
|
1315
1323
|
this._instance.registerForSession({
|
|
1316
1324
|
$session_recording_start_reason: startReason,
|
|
1317
1325
|
})
|
|
1318
|
-
|
|
1326
|
+
const message = startReason.replace('_', ' ')
|
|
1327
|
+
if (typeof tagPayload === 'undefined') {
|
|
1328
|
+
logger.info(message)
|
|
1329
|
+
} else {
|
|
1330
|
+
logger.info(message, tagPayload)
|
|
1331
|
+
}
|
|
1319
1332
|
if (!includes(['recording_initialized', 'session_id_changed'], startReason)) {
|
|
1320
1333
|
this._tryAddCustomEvent(startReason, tagPayload)
|
|
1321
1334
|
}
|
package/src/leanbase.ts
CHANGED
|
@@ -43,7 +43,7 @@ import { PageViewManager } from './page-view'
|
|
|
43
43
|
import { ScrollManager } from './scroll-manager'
|
|
44
44
|
import { isLikelyBot } from './utils/blocked-uas'
|
|
45
45
|
import { SessionRecording } from './extensions/replay/session-recording'
|
|
46
|
-
import
|
|
46
|
+
import { RequestRouter } from './utils/request-router'
|
|
47
47
|
import type { ConsentManager } from '../../browser/lib/src/consent'
|
|
48
48
|
|
|
49
49
|
const defaultConfig = (): LeanbaseConfig => ({
|
|
@@ -124,6 +124,9 @@ export class Leanbase extends PostHogCore {
|
|
|
124
124
|
this.isLoaded = true
|
|
125
125
|
this.persistence = new LeanbasePersistence(this.config)
|
|
126
126
|
|
|
127
|
+
// Browser SDK always has a requestRouter; session replay relies on it for $snapshot ingestion URLs.
|
|
128
|
+
this.requestRouter = new RequestRouter(this)
|
|
129
|
+
|
|
127
130
|
if (this.config.cookieless_mode !== 'always') {
|
|
128
131
|
this.sessionManager = new SessionIdManager(this)
|
|
129
132
|
this.sessionPropsManager = new SessionPropsManager(this, this.sessionManager, this.persistence)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Leanbase } from '../leanbase'
|
|
2
|
+
|
|
3
|
+
export type RequestRouterTarget = 'api' | 'ui' | 'assets'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Leanbase-local version of PostHog's RequestRouter.
|
|
7
|
+
*
|
|
8
|
+
* Browser SDK always has a requestRouter instance; Leanbase IIFE needs this too so
|
|
9
|
+
* features like Session Replay can construct ingestion URLs.
|
|
10
|
+
*/
|
|
11
|
+
export class RequestRouter {
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
13
|
+
constructor(private readonly instance: Leanbase) {}
|
|
14
|
+
|
|
15
|
+
get apiHost(): string {
|
|
16
|
+
const configured = (this.instance.config.api_host || this.instance.config.host || '').trim()
|
|
17
|
+
return configured.replace(/\/$/, '')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get uiHost(): string | undefined {
|
|
21
|
+
const configured = this.instance.config.ui_host?.trim().replace(/\/$/, '')
|
|
22
|
+
return configured || undefined
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
endpointFor(target: RequestRouterTarget, path: string = ''): string {
|
|
26
|
+
if (path) {
|
|
27
|
+
path = path[0] === '/' ? path : `/${path}`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (target === 'ui') {
|
|
31
|
+
const host = this.uiHost || this.apiHost
|
|
32
|
+
return host + path
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Leanbase doesn't currently do region-based routing; default to apiHost.
|
|
36
|
+
// Browser's router has special handling for assets; we keep parity in interface, not domains.
|
|
37
|
+
return this.apiHost + path
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.3.
|
|
1
|
+
export const version = '0.3.2'
|