@leanbase-giangnd/js 0.0.4 → 0.0.7

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.d.ts CHANGED
@@ -1,508 +1,5 @@
1
1
  import { PostHogCoreOptions, FeatureFlagValue, JsonType, PostHogCore, PostHogFetchOptions, PostHogFetchResponse, PostHogPersistedProperty, PostHogEventProperties } from '@posthog/core';
2
2
 
3
- interface IMirror<TNode> {
4
- getId(n: TNode | undefined | null): number;
5
- getNode(id: number): TNode | null;
6
- getIds(): number[];
7
- getMeta(n: TNode): serializedNodeWithId | null;
8
- removeNodeFromMap(n: TNode): void;
9
- has(id: number): boolean;
10
- hasNode(node: TNode): boolean;
11
- add(n: TNode, meta: serializedNodeWithId): void;
12
- replace(id: number, n: TNode): void;
13
- reset(): void;
14
- }
15
- declare class Mirror implements IMirror<Node> {
16
- private idNodeMap;
17
- private nodeMetaMap;
18
- getId(n: Node | undefined | null): number;
19
- getNode(id: number): Node | null;
20
- getIds(): number[];
21
- getMeta(n: Node): serializedNodeWithId | null;
22
- removeNodeFromMap(n: Node): void;
23
- has(id: number): boolean;
24
- hasNode(node: Node): boolean;
25
- add(n: Node, meta: serializedNodeWithId): void;
26
- replace(id: number, n: Node): void;
27
- reset(): void;
28
- }
29
- type attributes = {
30
- [key: string]: string | number | true | null;
31
- };
32
- declare enum NodeType {
33
- Document = 0,
34
- DocumentType = 1,
35
- Element = 2,
36
- Text = 3,
37
- CDATA = 4,
38
- Comment = 5
39
- }
40
- type documentNode = {
41
- type: NodeType.Document;
42
- childNodes: serializedNodeWithId[];
43
- compatMode?: string;
44
- };
45
- type documentTypeNode = {
46
- type: NodeType.DocumentType;
47
- name: string;
48
- publicId: string;
49
- systemId: string;
50
- };
51
- type elementNode = {
52
- type: NodeType.Element;
53
- tagName: string;
54
- attributes: attributes;
55
- childNodes: serializedNodeWithId[];
56
- isSVG?: true;
57
- needBlock?: boolean;
58
- isCustom?: true;
59
- };
60
- type textNode = {
61
- type: NodeType.Text;
62
- textContent: string;
63
- isStyle?: true;
64
- };
65
- type cdataNode = {
66
- type: NodeType.CDATA;
67
- textContent: '';
68
- };
69
- type commentNode = {
70
- type: NodeType.Comment;
71
- textContent: string;
72
- };
73
- type serializedNode = (documentNode | documentTypeNode | elementNode | textNode | cdataNode | commentNode) & {
74
- rootId?: number;
75
- isShadowHost?: boolean;
76
- isShadow?: boolean;
77
- };
78
- type serializedNodeWithId = serializedNode & {
79
- id: number;
80
- };
81
- type blockClass = string | RegExp;
82
- type maskTextClass = string | RegExp;
83
- type IWindow = Window & typeof globalThis;
84
- type listenerHandler = () => void;
85
- type KeepIframeSrcFn = (src: string) => boolean;
86
- type PackFn = (event: eventWithTime) => string;
87
- declare enum EventType {
88
- DomContentLoaded = 0,
89
- Load = 1,
90
- FullSnapshot = 2,
91
- IncrementalSnapshot = 3,
92
- Meta = 4,
93
- Custom = 5,
94
- Plugin = 6
95
- }
96
- declare enum IncrementalSource {
97
- Mutation = 0,
98
- MouseMove = 1,
99
- MouseInteraction = 2,
100
- Scroll = 3,
101
- ViewportResize = 4,
102
- Input = 5,
103
- TouchMove = 6,
104
- MediaInteraction = 7,
105
- StyleSheetRule = 8,
106
- CanvasMutation = 9,
107
- Font = 10,
108
- Log = 11,
109
- Drag = 12,
110
- StyleDeclaration = 13,
111
- Selection = 14,
112
- AdoptedStyleSheet = 15,
113
- CustomElement = 16
114
- }
115
- type domContentLoadedEvent = {
116
- type: EventType.DomContentLoaded;
117
- data: unknown;
118
- };
119
- type loadedEvent = {
120
- type: EventType.Load;
121
- data: unknown;
122
- };
123
- type fullSnapshotEvent = {
124
- type: EventType.FullSnapshot;
125
- data: {
126
- node: serializedNodeWithId;
127
- initialOffset: {
128
- top: number;
129
- left: number;
130
- };
131
- };
132
- };
133
- type metaEvent = {
134
- type: EventType.Meta;
135
- data: {
136
- href: string;
137
- width: number;
138
- height: number;
139
- };
140
- };
141
- type customEvent<T = unknown> = {
142
- type: EventType.Custom;
143
- data: {
144
- tag: string;
145
- payload: T;
146
- };
147
- };
148
- type pluginEvent<T = unknown> = {
149
- type: EventType.Plugin;
150
- data: {
151
- plugin: string;
152
- payload: T;
153
- };
154
- };
155
- type styleOMValue = {
156
- [key: string]: styleValueWithPriority | string | false;
157
- };
158
- type styleValueWithPriority = [string, string];
159
- type textMutation = {
160
- id: number;
161
- value: string | null;
162
- };
163
- type attributeMutation = {
164
- id: number;
165
- attributes: {
166
- [key: string]: string | styleOMValue | null;
167
- };
168
- };
169
- type removedNodeMutation = {
170
- parentId: number;
171
- id: number;
172
- isShadow?: boolean;
173
- };
174
- type addedNodeMutation = {
175
- parentId: number;
176
- previousId?: number | null;
177
- nextId: number | null;
178
- node: serializedNodeWithId;
179
- };
180
- type mutationCallbackParam = {
181
- texts: textMutation[];
182
- attributes: attributeMutation[];
183
- removes: removedNodeMutation[];
184
- adds: addedNodeMutation[];
185
- isAttachIframe?: true;
186
- };
187
- type mutationData = {
188
- source: IncrementalSource.Mutation;
189
- } & mutationCallbackParam;
190
- type mousePosition = {
191
- x: number;
192
- y: number;
193
- id: number;
194
- timeOffset: number;
195
- };
196
- declare enum MouseInteractions {
197
- MouseUp = 0,
198
- MouseDown = 1,
199
- Click = 2,
200
- ContextMenu = 3,
201
- DblClick = 4,
202
- Focus = 5,
203
- Blur = 6,
204
- TouchStart = 7,
205
- TouchMove_Departed = 8,
206
- TouchEnd = 9,
207
- TouchCancel = 10
208
- }
209
- declare enum PointerTypes {
210
- Mouse = 0,
211
- Pen = 1,
212
- Touch = 2
213
- }
214
- type mouseInteractionParam = {
215
- type: MouseInteractions;
216
- id: number;
217
- x?: number;
218
- y?: number;
219
- pointerType?: PointerTypes;
220
- };
221
- type mouseInteractionData = {
222
- source: IncrementalSource.MouseInteraction;
223
- } & mouseInteractionParam;
224
- type mousemoveData = {
225
- source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag;
226
- positions: mousePosition[];
227
- };
228
- type scrollPosition = {
229
- id: number;
230
- x: number;
231
- y: number;
232
- };
233
- type scrollData = {
234
- source: IncrementalSource.Scroll;
235
- } & scrollPosition;
236
- type viewportResizeDimension = {
237
- width: number;
238
- height: number;
239
- };
240
- type viewportResizeData = {
241
- source: IncrementalSource.ViewportResize;
242
- } & viewportResizeDimension;
243
- type inputValue = {
244
- text: string;
245
- isChecked: boolean;
246
- userTriggered?: boolean;
247
- };
248
- type inputData = {
249
- source: IncrementalSource.Input;
250
- id: number;
251
- } & inputValue;
252
- declare enum MediaInteractions {
253
- Play = 0,
254
- Pause = 1,
255
- Seeked = 2,
256
- VolumeChange = 3,
257
- RateChange = 4
258
- }
259
- type mediaInteractionParam = {
260
- type: MediaInteractions;
261
- id: number;
262
- currentTime?: number;
263
- volume?: number;
264
- muted?: boolean;
265
- loop?: boolean;
266
- playbackRate?: number;
267
- };
268
- type mediaInteractionData = {
269
- source: IncrementalSource.MediaInteraction;
270
- } & mediaInteractionParam;
271
- type styleSheetAddRule = {
272
- rule: string;
273
- index?: number | number[];
274
- };
275
- type styleSheetDeleteRule = {
276
- index: number | number[];
277
- };
278
- type styleSheetRuleParam = {
279
- id?: number;
280
- styleId?: number;
281
- removes?: styleSheetDeleteRule[];
282
- adds?: styleSheetAddRule[];
283
- replace?: string;
284
- replaceSync?: string;
285
- };
286
- type styleSheetRuleData = {
287
- source: IncrementalSource.StyleSheetRule;
288
- } & styleSheetRuleParam;
289
- declare enum CanvasContext {
290
- '2D' = 0,
291
- WebGL = 1,
292
- WebGL2 = 2
293
- }
294
- type canvasMutationCommand = {
295
- property: string;
296
- args: Array<unknown>;
297
- setter?: true;
298
- };
299
- type canvasMutationParam = {
300
- id: number;
301
- type: CanvasContext;
302
- commands: canvasMutationCommand[];
303
- } | ({
304
- id: number;
305
- type: CanvasContext;
306
- } & canvasMutationCommand);
307
- type canvasMutationData = {
308
- source: IncrementalSource.CanvasMutation;
309
- } & canvasMutationParam;
310
- type fontParam = {
311
- family: string;
312
- fontSource: string;
313
- buffer: boolean;
314
- descriptors?: FontFaceDescriptors;
315
- };
316
- type fontData = {
317
- source: IncrementalSource.Font;
318
- } & fontParam;
319
- type SelectionRange = {
320
- start: number;
321
- startOffset: number;
322
- end: number;
323
- endOffset: number;
324
- };
325
- type selectionParam = {
326
- ranges: Array<SelectionRange>;
327
- };
328
- type selectionData = {
329
- source: IncrementalSource.Selection;
330
- } & selectionParam;
331
- type styleDeclarationParam = {
332
- id?: number;
333
- styleId?: number;
334
- index: number[];
335
- set?: {
336
- property: string;
337
- value: string | null;
338
- priority: string | undefined;
339
- };
340
- remove?: {
341
- property: string;
342
- };
343
- };
344
- type styleDeclarationData = {
345
- source: IncrementalSource.StyleDeclaration;
346
- } & styleDeclarationParam;
347
- type adoptedStyleSheetParam = {
348
- id: number;
349
- styles?: {
350
- styleId: number;
351
- rules: styleSheetAddRule[];
352
- }[];
353
- styleIds: number[];
354
- };
355
- type adoptedStyleSheetData = {
356
- source: IncrementalSource.AdoptedStyleSheet;
357
- } & adoptedStyleSheetParam;
358
- type customElementParam = {
359
- define?: {
360
- name: string;
361
- };
362
- };
363
- type customElementData = {
364
- source: IncrementalSource.CustomElement;
365
- } & customElementParam;
366
- type incrementalData = mutationData | mousemoveData | mouseInteractionData | scrollData | viewportResizeData | inputData | mediaInteractionData | styleSheetRuleData | canvasMutationData | fontData | selectionData | styleDeclarationData | adoptedStyleSheetData | customElementData;
367
- type incrementalSnapshotEvent = {
368
- type: EventType.IncrementalSnapshot;
369
- data: incrementalData;
370
- };
371
- type eventWithoutTime = domContentLoadedEvent | loadedEvent | fullSnapshotEvent | incrementalSnapshotEvent | metaEvent | customEvent | pluginEvent;
372
- type eventWithTime = eventWithoutTime & {
373
- timestamp: number;
374
- delay?: number;
375
- };
376
- type mutationCallBack = (m: mutationCallbackParam) => void;
377
- type mousemoveCallBack = (p: mousePosition[], source: IncrementalSource.MouseMove | IncrementalSource.TouchMove | IncrementalSource.Drag) => void;
378
- type mouseInteractionCallBack = (d: mouseInteractionParam) => void;
379
- type scrollCallback = (p: scrollPosition) => void;
380
- type viewportResizeCallback = (d: viewportResizeDimension) => void;
381
- type inputCallback = (v: inputValue & {
382
- id: number;
383
- }) => void;
384
- type mediaInteractionCallback = (p: mediaInteractionParam) => void;
385
- type styleSheetRuleCallback = (s: styleSheetRuleParam) => void;
386
- type styleDeclarationCallback = (s: styleDeclarationParam) => void;
387
- type canvasMutationCallback = (p: canvasMutationParam) => void;
388
- type fontCallback = (p: fontParam) => void;
389
- type selectionCallback = (p: selectionParam) => void;
390
- type customElementCallback = (c: customElementParam) => void;
391
- type hooksParam = {
392
- mutation?: mutationCallBack;
393
- mousemove?: mousemoveCallBack;
394
- mouseInteraction?: mouseInteractionCallBack;
395
- scroll?: scrollCallback;
396
- viewportResize?: viewportResizeCallback;
397
- input?: inputCallback;
398
- mediaInteaction?: mediaInteractionCallback;
399
- styleSheetRule?: styleSheetRuleCallback;
400
- styleDeclaration?: styleDeclarationCallback;
401
- canvasMutation?: canvasMutationCallback;
402
- font?: fontCallback;
403
- selection?: selectionCallback;
404
- customElement?: customElementCallback;
405
- };
406
- type SamplingStrategy = Partial<{
407
- mousemove: boolean | number;
408
- mousemoveCallback: number;
409
- mouseInteraction: boolean | Record<string, boolean | undefined>;
410
- scroll: number;
411
- media: number;
412
- input: 'all' | 'last';
413
- canvas: 'all' | number;
414
- }>;
415
- interface ICrossOriginIframeMirror {
416
- getId(iframe: HTMLIFrameElement, remoteId: number, parentToRemoteMap?: Map<number, number>, remoteToParentMap?: Map<number, number>): number;
417
- getIds(iframe: HTMLIFrameElement, remoteId: number[]): number[];
418
- getRemoteId(iframe: HTMLIFrameElement, parentId: number, map?: Map<number, number>): number;
419
- getRemoteIds(iframe: HTMLIFrameElement, parentId: number[]): number[];
420
- reset(iframe?: HTMLIFrameElement): void;
421
- }
422
- type RecordPlugin<TOptions = unknown> = {
423
- name: string;
424
- observer?: (cb: (...args: Array<unknown>) => void, win: IWindow, options: TOptions) => listenerHandler;
425
- eventProcessor?: <TExtend>(event: eventWithTime) => eventWithTime & TExtend;
426
- getMirror?: (mirrors: {
427
- nodeMirror: Mirror;
428
- crossOriginIframeMirror: ICrossOriginIframeMirror;
429
- crossOriginIframeStyleMirror: ICrossOriginIframeMirror;
430
- }) => void;
431
- options: TOptions;
432
- };
433
-
434
- type MaskInputOptions = Partial<{
435
- color: boolean;
436
- date: boolean;
437
- 'datetime-local': boolean;
438
- email: boolean;
439
- month: boolean;
440
- number: boolean;
441
- range: boolean;
442
- search: boolean;
443
- tel: boolean;
444
- text: boolean;
445
- time: boolean;
446
- url: boolean;
447
- week: boolean;
448
- textarea: boolean;
449
- select: boolean;
450
- password: boolean;
451
- }>;
452
- type MaskInputFn = (text: string, element: HTMLElement) => string;
453
- type MaskTextFn = (text: string, element: HTMLElement | null) => string;
454
- type SlimDOMOptions = Partial<{
455
- script: boolean;
456
- comment: boolean;
457
- headFavicon: boolean;
458
- headWhitespace: boolean;
459
- headMetaDescKeywords: boolean;
460
- headMetaSocial: boolean;
461
- headMetaRobots: boolean;
462
- headMetaHttpEquiv: boolean;
463
- headMetaAuthorship: boolean;
464
- headMetaVerification: boolean;
465
- headTitleMutations: boolean;
466
- }>;
467
- type DataURLOptions = Partial<{
468
- type: string;
469
- quality: number;
470
- }>;
471
- type ErrorHandler = (error: unknown) => void | boolean;
472
- type recordOptions = {
473
- emit?: (e: eventWithTime, isCheckout?: boolean) => void;
474
- checkoutEveryNth?: number;
475
- checkoutEveryNms?: number;
476
- blockClass?: blockClass;
477
- blockSelector?: string;
478
- ignoreClass?: string;
479
- ignoreSelector?: string;
480
- maskTextClass?: maskTextClass;
481
- maskTextSelector?: string;
482
- maskAllInputs?: boolean;
483
- maskInputOptions?: MaskInputOptions;
484
- maskInputFn?: MaskInputFn;
485
- maskTextFn?: MaskTextFn;
486
- slimDOMOptions?: SlimDOMOptions | 'all' | true;
487
- ignoreCSSAttributes?: Set<string>;
488
- inlineStylesheet?: boolean;
489
- hooks?: hooksParam;
490
- packFn?: PackFn;
491
- sampling?: SamplingStrategy;
492
- dataURLOptions?: DataURLOptions;
493
- recordDOM?: boolean;
494
- recordCanvas?: boolean;
495
- recordCrossOriginIframes?: boolean;
496
- recordAfter?: 'DOMContentLoaded' | 'load';
497
- userTriggeredOnInput?: boolean;
498
- collectFonts?: boolean;
499
- inlineImages?: boolean;
500
- plugins?: RecordPlugin[];
501
- mousemoveWait?: number;
502
- keepIframeSrcFn?: KeepIframeSrcFn;
503
- errorHandler?: ErrorHandler;
504
- };
505
-
506
3
  type Property = any;
507
4
  type Properties = Record<string, Property>;
508
5
  type AutocaptureCompatibleElement = 'a' | 'button' | 'form' | 'input' | 'select' | 'textarea' | 'label';
@@ -587,6 +84,11 @@ interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
587
84
  * @default 'https://i.leanbase.co'
588
85
  */
589
86
  host?: string;
87
+ /**
88
+ * Backwards-compatible alias expected by replay code
89
+ */
90
+ api_host: string;
91
+ ui_host?: string | null;
590
92
  /**
591
93
  * The token for your Leanbase project.
592
94
  * It should NOT be provided manually in the config, but rather passed as the first parameter to `leanbase.init()`.
@@ -605,19 +107,6 @@ interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
605
107
  * @default true
606
108
  */
607
109
  autocapture: boolean | AutocaptureConfig;
608
- /**
609
- * Enables or disables session recording. When true, session recording is disabled on the client.
610
- * @default false
611
- */
612
- disable_session_recording?: boolean;
613
- /**
614
- * Session recording configuration
615
- */
616
- session_recording?: SessionRecordingOptions;
617
- /**
618
- * Enable console.log recording for session replay (can be controlled remotely). Undefined defers to server.
619
- */
620
- enable_recording_console_log?: boolean;
621
110
  /**
622
111
  * Determines whether Leanbase should capture pageview events automatically.
623
112
  * Can be:
@@ -628,12 +117,6 @@ interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
628
117
  * @default true
629
118
  */
630
119
  capture_pageview: boolean | 'history_change';
631
- /**
632
- * Enables performance capture. When true, network performance timing can be forwarded to replay when enabled.
633
- */
634
- capture_performance?: boolean | {
635
- network_timing?: boolean;
636
- };
637
120
  /**
638
121
  * Determines the session idle timeout in seconds.
639
122
  * Any new event that's happened after this timeout will create a new session.
@@ -683,6 +166,25 @@ interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
683
166
  * @default ''
684
167
  */
685
168
  persistence_name: string;
169
+ /**
170
+ * Session recording options (browser parity)
171
+ */
172
+ session_recording: SessionRecordingOptions;
173
+ /**
174
+ * Backwards-compatible flag to disable session recording
175
+ */
176
+ disable_session_recording?: boolean;
177
+ /**
178
+ * Controls performance capture options used by replay/network tracing
179
+ */
180
+ capture_performance?: boolean | {
181
+ network_timing?: boolean;
182
+ web_vitals?: boolean;
183
+ };
184
+ /**
185
+ * Enable recording of console logs for session replay
186
+ */
187
+ enable_recording_console_log?: boolean;
686
188
  /**
687
189
  * Prevent autocapture from capturing any attribute names on elements.
688
190
  *
@@ -809,61 +311,11 @@ interface LeanbaseConfig extends Partial<PostHogCoreOptions> {
809
311
  * @param instance - The Leanbase instance that has been loaded.
810
312
  */
811
313
  loaded: (instance: Leanbase) => void;
812
- }
813
- type SessionRecordingCanvasOptions = {
814
- recordCanvas?: boolean | null;
815
- canvasFps?: number | null;
816
- canvasQuality?: string | null;
817
- };
818
- interface SessionRecordingOptions {
819
- blockClass?: string | RegExp;
820
- blockSelector?: string | null;
821
- ignoreClass?: string | RegExp;
822
- maskTextClass?: string | RegExp;
823
- maskTextSelector?: string | null;
824
- maskTextFn?: ((text: string, element?: HTMLElement) => string) | null;
825
- maskAllInputs?: boolean;
826
- maskInputOptions?: recordOptions['maskInputOptions'];
827
- maskInputFn?: ((text: string, element?: HTMLElement) => string) | null;
828
- slimDOMOptions?: recordOptions['slimDOMOptions'];
829
- collectFonts?: boolean;
830
- inlineStylesheet?: boolean;
831
- recordCrossOriginIframes?: boolean;
832
- recordHeaders?: boolean;
833
- recordBody?: boolean;
834
- captureCanvas?: SessionRecordingCanvasOptions;
835
- maskCapturedNetworkRequestFn?: ((data: CapturedNetworkRequest) => CapturedNetworkRequest | null | undefined) | null;
836
- maskNetworkRequestFn?: ((data: NetworkRequest) => NetworkRequest | null | undefined) | null;
837
- full_snapshot_interval_millis?: number;
838
- compress_events?: boolean;
839
- session_idle_threshold_ms?: number;
840
- __mutationThrottlerRefillRate?: number;
841
- __mutationThrottlerBucketSize?: number;
842
314
  /**
843
- * Force-enable session recording locally even if remote config disables it.
844
- * Useful for dev/testing when the backend has sessionRecording set to false.
315
+ * Hook to allow preparing external dependency stylesheet before injection
845
316
  */
846
- forceClientRecording?: boolean;
317
+ prepare_external_dependency_stylesheet?: (stylesheet: HTMLStyleElement) => HTMLStyleElement | null | undefined;
847
318
  }
848
- type SessionRecordingRemoteConfig = SessionRecordingCanvasOptions & {
849
- endpoint?: string;
850
- consoleLogRecordingEnabled?: boolean;
851
- sampleRate?: string | null;
852
- minimumDurationMilliseconds?: number;
853
- linkedFlag?: string | {
854
- flag: string;
855
- variant: string;
856
- } | null;
857
- networkPayloadCapture?: Pick<NetworkRecordOptions, 'recordBody' | 'recordHeaders' | 'payloadHostDenyList'>;
858
- masking?: Pick<SessionRecordingOptions, 'maskAllInputs' | 'maskTextSelector' | 'blockSelector'>;
859
- urlTriggers?: SessionRecordingUrlTrigger[];
860
- scriptConfig?: {
861
- script?: string | undefined;
862
- };
863
- urlBlocklist?: SessionRecordingUrlTrigger[];
864
- eventTriggers?: string[];
865
- triggerMatchType?: 'any' | 'all';
866
- };
867
319
  interface RageclickConfig {
868
320
  /**
869
321
  * List of CSS selectors to ignore rageclicks on
@@ -982,10 +434,6 @@ interface RemoteConfig {
982
434
  autocaptureExceptions?: boolean | {
983
435
  endpoint?: string;
984
436
  };
985
- /**
986
- * Session recording configuration options
987
- */
988
- sessionRecording?: SessionRecordingRemoteConfig | false;
989
437
  /**
990
438
  * @deprecated, moved to toolbarParams
991
439
  */
@@ -994,6 +442,10 @@ interface RemoteConfig {
994
442
  * Whether the user is authenticated
995
443
  */
996
444
  isAuthenticated: boolean;
445
+ /**
446
+ * Session recording remote config (when available)
447
+ */
448
+ sessionRecording?: SessionRecordingRemoteConfig;
997
449
  /**
998
450
  * List of site apps with their IDs and URLs
999
451
  */
@@ -1048,28 +500,7 @@ interface RequestWithOptions {
1048
500
  next?: NextOptions;
1049
501
  };
1050
502
  }
1051
- type InitiatorType = 'audio' | 'beacon' | 'body' | 'css' | 'early-hints' | 'embed' | 'fetch' | 'frame' | 'iframe' | 'image' | 'img' | 'input' | 'link' | 'navigation' | 'object' | 'ping' | 'script' | 'track' | 'video' | 'xmlhttprequest';
1052
- type NetworkRecordOptions = {
1053
- initiatorTypes?: InitiatorType[];
1054
- maskRequestFn?: (data: CapturedNetworkRequest) => CapturedNetworkRequest | undefined;
1055
- recordHeaders?: boolean | {
1056
- request: boolean;
1057
- response: boolean;
1058
- };
1059
- recordBody?: boolean | string[] | {
1060
- request: boolean | string[];
1061
- response: boolean | string[];
1062
- };
1063
- recordInitialRequests?: boolean;
1064
- recordPerformance?: boolean;
1065
- performanceEntryTypeToObserve: string[];
1066
- payloadSizeLimitBytes: number;
1067
- payloadHostDenyList?: string[];
1068
- };
1069
- type NetworkRequest = {
1070
- url: string;
1071
- };
1072
- type Headers = Record<string, any>;
503
+ type InitiatorType = 'audio' | 'beacon' | 'body' | 'css' | 'early-hint' | 'embed' | 'fetch' | 'frame' | 'iframe' | 'icon' | 'image' | 'img' | 'input' | 'link' | 'navigation' | 'object' | 'ping' | 'script' | 'track' | 'video' | 'xmlhttprequest';
1073
504
  type Writable<T> = {
1074
505
  -readonly [P in keyof T]: T[P];
1075
506
  };
@@ -1087,16 +518,47 @@ type CapturedNetworkRequest = Writable<Omit<PerformanceEntry, 'toJSON'>> & {
1087
518
  responseBody?: string | null;
1088
519
  isInitial?: boolean;
1089
520
  };
1090
- interface SessionRecordingUrlTrigger {
521
+ type Headers = Record<string, string>;
522
+ /** @deprecated - use CapturedNetworkRequest instead */
523
+ type NetworkRequest = {
1091
524
  url: string;
1092
- matching: 'regex';
1093
- }
1094
- type SessionStartReason = 'sampling_overridden' | 'recording_initialized' | 'linked_flag_matched' | 'linked_flag_overridden' | 'sampled' | 'session_id_changed' | 'url_trigger_matched' | 'event_trigger_matched';
525
+ };
1095
526
  type SessionIdChangedCallback = (sessionId: string, windowId: string | null | undefined, changeReason?: {
1096
527
  noSessionId: boolean;
1097
528
  activityTimeout: boolean;
1098
529
  sessionPastMaximumLength: boolean;
1099
530
  }) => void;
531
+ type SessionRecordingCanvasOptions = {
532
+ recordCanvas?: boolean | null;
533
+ canvasFps?: number | null;
534
+ canvasQuality?: string | null;
535
+ };
536
+ type SessionRecordingOptions = {
537
+ __mutationThrottlerBucketSize?: number;
538
+ __mutationThrottlerRefillRate?: number;
539
+ blockClass?: string | RegExp;
540
+ blockSelector?: string | null;
541
+ captureCanvas?: SessionRecordingCanvasOptions;
542
+ collectFonts?: boolean;
543
+ compress_events?: boolean;
544
+ full_snapshot_interval_millis?: number;
545
+ ignoreClass?: string | RegExp;
546
+ inlineStylesheet?: boolean;
547
+ maskAllInputs?: boolean;
548
+ maskCapturedNetworkRequestFn?: ((data: CapturedNetworkRequest) => CapturedNetworkRequest | null | undefined) | null;
549
+ maskInputFn?: ((text: string, element?: HTMLElement) => string) | null;
550
+ maskInputOptions?: any;
551
+ maskNetworkRequestFn?: ((data: NetworkRequest) => NetworkRequest | null | undefined) | null;
552
+ maskTextClass?: string | RegExp;
553
+ maskTextFn?: ((text: string, element?: HTMLElement) => string) | null;
554
+ maskTextSelector?: string | null;
555
+ recordBody?: boolean;
556
+ recordCrossOriginIframes?: boolean;
557
+ recordHeaders?: boolean;
558
+ session_idle_threshold_ms?: number;
559
+ slimDOMOptions?: any;
560
+ };
561
+ type SessionRecordingRemoteConfig = any;
1100
562
  type LeanbasegCaptureOptions = {
1101
563
  /** If provided overrides the auto-generated event ID */
1102
564
  uuid?: string;
@@ -1310,6 +772,29 @@ declare class SessionPropsManager {
1310
772
  getSessionProps(): Record<string, any>;
1311
773
  }
1312
774
 
775
+ type PostHog = Leanbase & {
776
+ onFeatureFlags?: (cb: (...args: any[]) => void) => () => void;
777
+ consent?: {
778
+ isOptedOut?: () => boolean;
779
+ };
780
+ };
781
+
782
+ declare enum RequestRouterRegion {
783
+ US = "us",
784
+ EU = "eu",
785
+ CUSTOM = "custom"
786
+ }
787
+ type RequestRouterTarget = 'api' | 'ui' | 'assets';
788
+ declare class RequestRouter {
789
+ instance: PostHog;
790
+ private _regionCache;
791
+ constructor(instance: PostHog);
792
+ get apiHost(): string;
793
+ get uiHost(): string | undefined;
794
+ get region(): RequestRouterRegion;
795
+ endpointFor(target: RequestRouterTarget, path?: string): string;
796
+ }
797
+
1313
798
  interface PageViewEventProperties {
1314
799
  $pageview_id?: string;
1315
800
  $prev_pageview_id?: string;
@@ -1359,85 +844,6 @@ declare class ScrollManager {
1359
844
  scrollX(): number;
1360
845
  }
1361
846
 
1362
- type TriggerType = 'url' | 'event';
1363
- /**
1364
- * Session recording starts in buffering mode while waiting for "flags response".
1365
- * Once the response is received, it might be disabled, active or sampled.
1366
- * When "sampled" that means a sample rate is set, and the last time the session ID rotated
1367
- * the sample rate determined this session should be sent to the server.
1368
- */
1369
- declare const sessionRecordingStatuses: readonly ["disabled", "sampled", "active", "buffering", "paused", "lazy_loading"];
1370
- type SessionRecordingStatus = (typeof sessionRecordingStatuses)[number];
1371
-
1372
- declare class SessionRecording {
1373
- private readonly _instance;
1374
- _forceAllowLocalhostNetworkCapture: boolean;
1375
- private _receivedFlags;
1376
- private _serverRecordingEnabled;
1377
- private _persistFlagsOnSessionListener;
1378
- private _lazyLoadedSessionRecording;
1379
- get started(): boolean;
1380
- /**
1381
- * defaults to buffering mode until a flags response is received
1382
- * once a flags response is received status can be disabled, active or sampled
1383
- */
1384
- get status(): SessionRecordingStatus;
1385
- constructor(_instance: Leanbase);
1386
- private get _isRecordingEnabled();
1387
- startIfEnabledOrStop(startReason?: SessionStartReason): void;
1388
- /**
1389
- * session recording waits until it receives remote config before loading the script
1390
- * this is to ensure we can control the script name remotely
1391
- * and because we wait until we have local and remote config to determine if we should start at all
1392
- * if start is called and there is no remote config then we wait until there is
1393
- */
1394
- private _lazyLoadAndStart;
1395
- stopRecording(): void;
1396
- private _resetSampling;
1397
- private _persistRemoteConfig;
1398
- private _clearRemoteConfig;
1399
- onRemoteConfig(response: RemoteConfig): void;
1400
- log(message: string, level?: 'log' | 'warn' | 'error'): void;
1401
- private _onScriptLoaded;
1402
- /**
1403
- * this is maintained on the public API only because it has always been on the public API
1404
- * if you are calling this directly you are certainly doing something wrong
1405
- * @deprecated
1406
- */
1407
- onRRwebEmit(rawEvent: eventWithTime): void;
1408
- /**
1409
- * this ignores the linked flag config and (if other conditions are met) causes capture to start
1410
- *
1411
- * It is not usual to call this directly,
1412
- * instead call `posthog.startSessionRecording({linked_flag: true})`
1413
- * */
1414
- overrideLinkedFlag(): void;
1415
- /**
1416
- * this ignores the sampling config and (if other conditions are met) causes capture to start
1417
- *
1418
- * It is not usual to call this directly,
1419
- * instead call `posthog.startSessionRecording({sampling: true})`
1420
- * */
1421
- overrideSampling(): void;
1422
- /**
1423
- * this ignores the URL/Event trigger config and (if other conditions are met) causes capture to start
1424
- *
1425
- * It is not usual to call this directly,
1426
- * instead call `posthog.startSessionRecording({trigger: 'url' | 'event'})`
1427
- * */
1428
- overrideTrigger(triggerType: TriggerType): void;
1429
- get sdkDebugProperties(): Properties;
1430
- /**
1431
- * This adds a custom event to the session recording
1432
- *
1433
- * It is not intended for arbitrary public use - playback only displays known custom events
1434
- * And is exposed on the public interface only so that other parts of the SDK are able to use it
1435
- *
1436
- * if you are calling this from client code, you're probably looking for `posthog.capture('$custom_event', {...})`
1437
- */
1438
- tryAddCustomEvent(tag: string, payload: any): boolean;
1439
- }
1440
-
1441
847
  declare class Leanbase extends PostHogCore {
1442
848
  config: LeanbaseConfig;
1443
849
  scrollManager: ScrollManager;
@@ -1447,7 +853,8 @@ declare class Leanbase extends PostHogCore {
1447
853
  sessionPersistence?: LeanbasePersistence;
1448
854
  sessionManager?: SessionIdManager;
1449
855
  sessionPropsManager?: SessionPropsManager;
1450
- sessionRecording?: SessionRecording;
856
+ sessionRecording?: any;
857
+ requestRouter: RequestRouter;
1451
858
  isRemoteConfigLoaded?: boolean;
1452
859
  personProcessingSetOncePropertiesSent: boolean;
1453
860
  isLoaded: boolean;
@@ -1465,8 +872,11 @@ declare class Leanbase extends PostHogCore {
1465
872
  getLibraryVersion(): string;
1466
873
  getCustomUserAgent(): void;
1467
874
  getPersistedProperty<T>(key: PostHogPersistedProperty): T | undefined;
1468
- get_property<T = any>(key: string): T | undefined;
1469
875
  setPersistedProperty<T>(key: PostHogPersistedProperty, value: T | null): void;
876
+ get_property(key: string): any;
877
+ set_property(key: string, value: any): void;
878
+ register_for_session(properties: Record<string, any>): void;
879
+ unregister_for_session(property: string): void;
1470
880
  calculateEventProperties(eventName: string, eventProperties: PostHogEventProperties, timestamp: Date, uuid: string, readOnly?: boolean): Properties;
1471
881
  isIdentified(): boolean;
1472
882
  /**