@leanbase-giangnd/js 0.1.2 → 0.1.5
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 +168 -778
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +169 -779
- package/dist/index.mjs.map +1 -1
- package/dist/leanbase.iife.js +169 -780
- package/dist/leanbase.iife.js.map +1 -1
- package/package.json +1 -1
- package/src/extensions/replay/extension-shim.ts +15 -4
- package/src/extensions/replay/external/lazy-loaded-session-recorder.ts +25 -5
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { window as win } from '../../utils'
|
|
2
2
|
import { record as rrwebRecord } from '@rrweb/record'
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
// Delay importing heavy modules to avoid circular dependencies at build time.
|
|
4
|
+
// They will be required lazily when used at runtime.
|
|
5
|
+
// We avoid requiring the lazy-loaded recorder here to prevent circular dependencies during bundling.
|
|
6
|
+
// Instead, `LazyLoadedSessionRecording` will register a factory on the global under
|
|
7
|
+
// `__PosthogExtensions__._initSessionRecordingFactory` when it loads.
|
|
8
|
+
type InitSessionRecordingFactory = (instance: any) => any
|
|
5
9
|
|
|
6
10
|
// Use a safe global target (prefer `win`, fallback to globalThis)
|
|
7
11
|
const _target: any = (win as any) ?? (globalThis as any)
|
|
@@ -17,7 +21,13 @@ _target.__PosthogExtensions__.rrweb = _target.__PosthogExtensions__.rrweb || {
|
|
|
17
21
|
_target.__PosthogExtensions__.initSessionRecording =
|
|
18
22
|
_target.__PosthogExtensions__.initSessionRecording ||
|
|
19
23
|
((instance: any) => {
|
|
20
|
-
|
|
24
|
+
const factory: InitSessionRecordingFactory | undefined =
|
|
25
|
+
_target.__PosthogExtensions__._initSessionRecordingFactory
|
|
26
|
+
if (factory) {
|
|
27
|
+
return factory(instance)
|
|
28
|
+
}
|
|
29
|
+
// If no factory is registered yet, return undefined — callers should handle lazy-loading.
|
|
30
|
+
return undefined
|
|
21
31
|
})
|
|
22
32
|
|
|
23
33
|
// Provide a no-op loadExternalDependency that calls the callback immediately (since rrweb is bundled)
|
|
@@ -29,7 +39,8 @@ _target.__PosthogExtensions__.loadExternalDependency =
|
|
|
29
39
|
|
|
30
40
|
// Provide rrwebPlugins object with network plugin factory if not present
|
|
31
41
|
_target.__PosthogExtensions__.rrwebPlugins = _target.__PosthogExtensions__.rrwebPlugins || {}
|
|
42
|
+
// Default to undefined; the lazy-loaded recorder will register the real factory when it initializes.
|
|
32
43
|
_target.__PosthogExtensions__.rrwebPlugins.getRecordNetworkPlugin =
|
|
33
|
-
_target.__PosthogExtensions__.rrwebPlugins.getRecordNetworkPlugin || (() =>
|
|
44
|
+
_target.__PosthogExtensions__.rrwebPlugins.getRecordNetworkPlugin || (() => undefined)
|
|
34
45
|
|
|
35
46
|
export {}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable posthog-js/no-direct-function-check */
|
|
1
2
|
import { record as rrwebRecord } from '@rrweb/record'
|
|
2
3
|
import '../extension-shim'
|
|
3
4
|
import { clampToRange, includes, isBoolean, isNullish, isNumber, isObject, isString, isUndefined } from '@posthog/core'
|
|
@@ -11,7 +12,7 @@ import {
|
|
|
11
12
|
RecordPlugin,
|
|
12
13
|
} from '../types/rrweb-types'
|
|
13
14
|
import { buildNetworkRequestOptions } from './config'
|
|
14
|
-
|
|
15
|
+
// network plugin factory will be provided via __PosthogExtensions__.rrwebPlugins.getRecordNetworkPlugin
|
|
15
16
|
import {
|
|
16
17
|
ACTIVE,
|
|
17
18
|
allMatchSessionRecordingStatus,
|
|
@@ -72,6 +73,21 @@ const FIVE_MINUTES = ONE_MINUTE * 5
|
|
|
72
73
|
|
|
73
74
|
export const RECORDING_IDLE_THRESHOLD_MS = FIVE_MINUTES
|
|
74
75
|
|
|
76
|
+
// Register a factory on the global extensions object so the extension shim can
|
|
77
|
+
// instantiate a LazyLoadedSessionRecording without importing this module directly.
|
|
78
|
+
try {
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
80
|
+
const ext = (globalThis as any).__PosthogExtensions__
|
|
81
|
+
if (ext) {
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
83
|
+
ext._initSessionRecordingFactory =
|
|
84
|
+
ext._initSessionRecordingFactory || ((instance: any) => new LazyLoadedSessionRecording(instance))
|
|
85
|
+
}
|
|
86
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87
|
+
} catch (e) {
|
|
88
|
+
// ignore
|
|
89
|
+
}
|
|
90
|
+
|
|
75
91
|
export const RECORDING_MAX_EVENT_SIZE = ONE_KB * ONE_KB * 0.9 // ~1mb (with some wiggle room)
|
|
76
92
|
export const RECORDING_BUFFER_TIMEOUT = 2000 // 2 seconds
|
|
77
93
|
export const SESSION_RECORDING_BATCH_KEY = 'recordings'
|
|
@@ -468,11 +484,15 @@ export class LazyLoadedSessionRecording {
|
|
|
468
484
|
const canRecordNetwork = !isLocalhost() || this._forceAllowLocalhostNetworkCapture
|
|
469
485
|
|
|
470
486
|
if (canRecordNetwork) {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
487
|
+
const assignableWindow: any = globalThis
|
|
488
|
+
const networkFactory = assignableWindow.__PosthogExtensions__?.rrwebPlugins?.getRecordNetworkPlugin?.()
|
|
489
|
+
if (typeof networkFactory === 'function') {
|
|
490
|
+
plugins.push(
|
|
491
|
+
networkFactory(buildNetworkRequestOptions(this._instance.config, this._networkPayloadCapture))
|
|
474
492
|
)
|
|
475
|
-
|
|
493
|
+
} else {
|
|
494
|
+
logger.info('Network plugin factory not available yet; skipping network plugin')
|
|
495
|
+
}
|
|
476
496
|
} else {
|
|
477
497
|
logger.info('NetworkCapture not started because we are on localhost.')
|
|
478
498
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.1.
|
|
1
|
+
export const version = '0.1.5'
|