@leanbase-giangnd/js 0.1.0 → 0.1.1

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.
@@ -2863,7 +2863,7 @@ var leanbase = (function (record) {
2863
2863
  }
2864
2864
  };
2865
2865
 
2866
- var version = "0.1.0";
2866
+ var version = "0.1.1";
2867
2867
  var packageInfo = {
2868
2868
  version: version};
2869
2869
 
@@ -4801,89 +4801,6 @@ var leanbase = (function (record) {
4801
4801
  // It would be very bad if posthog-js caused a permission prompt to appear on every page load.
4802
4802
  };
4803
4803
 
4804
- // Type definitions copied from @rrweb/types@2.0.0-alpha.17 and rrweb-snapshot@2.0.0-alpha.17
4805
- // Both packages are MIT licensed: https://github.com/rrweb-io/rrweb
4806
- //
4807
- // These types are copied here to avoid requiring users to install peer dependencies
4808
- // solely for TypeScript type information.
4809
- //
4810
- // Original sources:
4811
- // - @rrweb/types: https://github.com/rrweb-io/rrweb/tree/main/packages/@rrweb/types
4812
- // - rrweb-snapshot: https://github.com/rrweb-io/rrweb/tree/main/packages/rrweb-snapshot
4813
- var NodeType;
4814
- (function (NodeType) {
4815
- NodeType[NodeType["Document"] = 0] = "Document";
4816
- NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
4817
- NodeType[NodeType["Element"] = 2] = "Element";
4818
- NodeType[NodeType["Text"] = 3] = "Text";
4819
- NodeType[NodeType["CDATA"] = 4] = "CDATA";
4820
- NodeType[NodeType["Comment"] = 5] = "Comment";
4821
- })(NodeType || (NodeType = {}));
4822
- var EventType;
4823
- (function (EventType) {
4824
- EventType[EventType["DomContentLoaded"] = 0] = "DomContentLoaded";
4825
- EventType[EventType["Load"] = 1] = "Load";
4826
- EventType[EventType["FullSnapshot"] = 2] = "FullSnapshot";
4827
- EventType[EventType["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
4828
- EventType[EventType["Meta"] = 4] = "Meta";
4829
- EventType[EventType["Custom"] = 5] = "Custom";
4830
- EventType[EventType["Plugin"] = 6] = "Plugin";
4831
- })(EventType || (EventType = {}));
4832
- var IncrementalSource;
4833
- (function (IncrementalSource) {
4834
- IncrementalSource[IncrementalSource["Mutation"] = 0] = "Mutation";
4835
- IncrementalSource[IncrementalSource["MouseMove"] = 1] = "MouseMove";
4836
- IncrementalSource[IncrementalSource["MouseInteraction"] = 2] = "MouseInteraction";
4837
- IncrementalSource[IncrementalSource["Scroll"] = 3] = "Scroll";
4838
- IncrementalSource[IncrementalSource["ViewportResize"] = 4] = "ViewportResize";
4839
- IncrementalSource[IncrementalSource["Input"] = 5] = "Input";
4840
- IncrementalSource[IncrementalSource["TouchMove"] = 6] = "TouchMove";
4841
- IncrementalSource[IncrementalSource["MediaInteraction"] = 7] = "MediaInteraction";
4842
- IncrementalSource[IncrementalSource["StyleSheetRule"] = 8] = "StyleSheetRule";
4843
- IncrementalSource[IncrementalSource["CanvasMutation"] = 9] = "CanvasMutation";
4844
- IncrementalSource[IncrementalSource["Font"] = 10] = "Font";
4845
- IncrementalSource[IncrementalSource["Log"] = 11] = "Log";
4846
- IncrementalSource[IncrementalSource["Drag"] = 12] = "Drag";
4847
- IncrementalSource[IncrementalSource["StyleDeclaration"] = 13] = "StyleDeclaration";
4848
- IncrementalSource[IncrementalSource["Selection"] = 14] = "Selection";
4849
- IncrementalSource[IncrementalSource["AdoptedStyleSheet"] = 15] = "AdoptedStyleSheet";
4850
- IncrementalSource[IncrementalSource["CustomElement"] = 16] = "CustomElement";
4851
- })(IncrementalSource || (IncrementalSource = {}));
4852
- var MouseInteractions;
4853
- (function (MouseInteractions) {
4854
- MouseInteractions[MouseInteractions["MouseUp"] = 0] = "MouseUp";
4855
- MouseInteractions[MouseInteractions["MouseDown"] = 1] = "MouseDown";
4856
- MouseInteractions[MouseInteractions["Click"] = 2] = "Click";
4857
- MouseInteractions[MouseInteractions["ContextMenu"] = 3] = "ContextMenu";
4858
- MouseInteractions[MouseInteractions["DblClick"] = 4] = "DblClick";
4859
- MouseInteractions[MouseInteractions["Focus"] = 5] = "Focus";
4860
- MouseInteractions[MouseInteractions["Blur"] = 6] = "Blur";
4861
- MouseInteractions[MouseInteractions["TouchStart"] = 7] = "TouchStart";
4862
- MouseInteractions[MouseInteractions["TouchMove_Departed"] = 8] = "TouchMove_Departed";
4863
- MouseInteractions[MouseInteractions["TouchEnd"] = 9] = "TouchEnd";
4864
- MouseInteractions[MouseInteractions["TouchCancel"] = 10] = "TouchCancel";
4865
- })(MouseInteractions || (MouseInteractions = {}));
4866
- var PointerTypes;
4867
- (function (PointerTypes) {
4868
- PointerTypes[PointerTypes["Mouse"] = 0] = "Mouse";
4869
- PointerTypes[PointerTypes["Pen"] = 1] = "Pen";
4870
- PointerTypes[PointerTypes["Touch"] = 2] = "Touch";
4871
- })(PointerTypes || (PointerTypes = {}));
4872
- var MediaInteractions;
4873
- (function (MediaInteractions) {
4874
- MediaInteractions[MediaInteractions["Play"] = 0] = "Play";
4875
- MediaInteractions[MediaInteractions["Pause"] = 1] = "Pause";
4876
- MediaInteractions[MediaInteractions["Seeked"] = 2] = "Seeked";
4877
- MediaInteractions[MediaInteractions["VolumeChange"] = 3] = "VolumeChange";
4878
- MediaInteractions[MediaInteractions["RateChange"] = 4] = "RateChange";
4879
- })(MediaInteractions || (MediaInteractions = {}));
4880
- var CanvasContext;
4881
- (function (CanvasContext) {
4882
- CanvasContext[CanvasContext["2D"] = 0] = "2D";
4883
- CanvasContext[CanvasContext["WebGL"] = 1] = "WebGL";
4884
- CanvasContext[CanvasContext["WebGL2"] = 2] = "WebGL2";
4885
- })(CanvasContext || (CanvasContext = {}));
4886
-
4887
4804
  const _createLogger = prefix => {
4888
4805
  return {
4889
4806
  info: (...args) => logger$3.info(prefix, ...args),
@@ -4899,6 +4816,69 @@ var leanbase = (function (record) {
4899
4816
  const logger$2 = _createLogger('[Leanbase]');
4900
4817
  const createLogger = _createLogger;
4901
4818
 
4819
+ function patch(source, name, replacement) {
4820
+ try {
4821
+ if (!(name in source)) {
4822
+ return () => {
4823
+ //
4824
+ };
4825
+ }
4826
+ const original = source[name];
4827
+ const wrapped = replacement(original);
4828
+ if (isFunction(wrapped)) {
4829
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
4830
+ wrapped.prototype = wrapped.prototype || {};
4831
+ Object.defineProperties(wrapped, {
4832
+ __posthog_wrapped__: {
4833
+ enumerable: false,
4834
+ value: true
4835
+ }
4836
+ });
4837
+ }
4838
+ source[name] = wrapped;
4839
+ return () => {
4840
+ source[name] = original;
4841
+ };
4842
+ } catch {
4843
+ return () => {
4844
+ //
4845
+ };
4846
+ }
4847
+ }
4848
+
4849
+ function hostnameFromURL(url) {
4850
+ try {
4851
+ if (typeof url === 'string') {
4852
+ return new URL(url).hostname;
4853
+ }
4854
+ if ('url' in url) {
4855
+ return new URL(url.url).hostname;
4856
+ }
4857
+ return url.hostname;
4858
+ } catch {
4859
+ return null;
4860
+ }
4861
+ }
4862
+ function isHostOnDenyList(url, options) {
4863
+ const hostname = hostnameFromURL(url);
4864
+ const defaultNotDenied = {
4865
+ hostname,
4866
+ isHostDenied: false
4867
+ };
4868
+ if (!options.payloadHostDenyList?.length || !hostname?.trim().length) {
4869
+ return defaultNotDenied;
4870
+ }
4871
+ for (const deny of options.payloadHostDenyList) {
4872
+ if (hostname.endsWith(deny)) {
4873
+ return {
4874
+ hostname,
4875
+ isHostDenied: true
4876
+ };
4877
+ }
4878
+ }
4879
+ return defaultNotDenied;
4880
+ }
4881
+
4902
4882
  const LOGGER_PREFIX$2 = '[SessionRecording]';
4903
4883
  const REDACTED = 'redacted';
4904
4884
  const defaultNetworkOptions = {
@@ -5055,69 +5035,6 @@ var leanbase = (function (record) {
5055
5035
  };
5056
5036
  };
5057
5037
 
5058
- function patch(source, name, replacement) {
5059
- try {
5060
- if (!(name in source)) {
5061
- return () => {
5062
- //
5063
- };
5064
- }
5065
- const original = source[name];
5066
- const wrapped = replacement(original);
5067
- if (isFunction(wrapped)) {
5068
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
5069
- wrapped.prototype = wrapped.prototype || {};
5070
- Object.defineProperties(wrapped, {
5071
- __posthog_wrapped__: {
5072
- enumerable: false,
5073
- value: true
5074
- }
5075
- });
5076
- }
5077
- source[name] = wrapped;
5078
- return () => {
5079
- source[name] = original;
5080
- };
5081
- } catch {
5082
- return () => {
5083
- //
5084
- };
5085
- }
5086
- }
5087
-
5088
- function hostnameFromURL(url) {
5089
- try {
5090
- if (typeof url === 'string') {
5091
- return new URL(url).hostname;
5092
- }
5093
- if ('url' in url) {
5094
- return new URL(url.url).hostname;
5095
- }
5096
- return url.hostname;
5097
- } catch {
5098
- return null;
5099
- }
5100
- }
5101
- function isHostOnDenyList(url, options) {
5102
- const hostname = hostnameFromURL(url);
5103
- const defaultNotDenied = {
5104
- hostname,
5105
- isHostDenied: false
5106
- };
5107
- if (!options.payloadHostDenyList?.length || !hostname?.trim().length) {
5108
- return defaultNotDenied;
5109
- }
5110
- for (const deny of options.payloadHostDenyList) {
5111
- if (hostname.endsWith(deny)) {
5112
- return {
5113
- hostname,
5114
- isHostDenied: true
5115
- };
5116
- }
5117
- }
5118
- return defaultNotDenied;
5119
- }
5120
-
5121
5038
  /// <reference lib="dom" />
5122
5039
  const logger$1 = createLogger('[Recorder]');
5123
5040
  const isNavigationTiming = entry => entry.entryType === 'navigation';
@@ -5676,6 +5593,108 @@ var leanbase = (function (record) {
5676
5593
  };
5677
5594
  // rrweb/networ@1 ends
5678
5595
 
5596
+ // Use a safe global target (prefer `win`, fallback to globalThis)
5597
+ const _target = win ?? globalThis;
5598
+ _target.__PosthogExtensions__ = _target.__PosthogExtensions__ || {};
5599
+ // Expose rrweb.record under the same contract
5600
+ _target.__PosthogExtensions__.rrweb = _target.__PosthogExtensions__.rrweb || {
5601
+ record: record.record
5602
+ };
5603
+ // Provide initSessionRecording if not present — return a new LazyLoadedSessionRecording when called
5604
+ _target.__PosthogExtensions__.initSessionRecording = _target.__PosthogExtensions__.initSessionRecording || (instance => {
5605
+ return new LazyLoadedSessionRecording(instance);
5606
+ });
5607
+ // Provide a no-op loadExternalDependency that calls the callback immediately (since rrweb is bundled)
5608
+ _target.__PosthogExtensions__.loadExternalDependency = _target.__PosthogExtensions__.loadExternalDependency || ((instance, scriptName, cb) => {
5609
+ if (cb) cb(undefined);
5610
+ });
5611
+ // Provide rrwebPlugins object with network plugin factory if not present
5612
+ _target.__PosthogExtensions__.rrwebPlugins = _target.__PosthogExtensions__.rrwebPlugins || {};
5613
+ _target.__PosthogExtensions__.rrwebPlugins.getRecordNetworkPlugin = _target.__PosthogExtensions__.rrwebPlugins.getRecordNetworkPlugin || (() => getRecordNetworkPlugin);
5614
+
5615
+ // Type definitions copied from @rrweb/types@2.0.0-alpha.17 and rrweb-snapshot@2.0.0-alpha.17
5616
+ // Both packages are MIT licensed: https://github.com/rrweb-io/rrweb
5617
+ //
5618
+ // These types are copied here to avoid requiring users to install peer dependencies
5619
+ // solely for TypeScript type information.
5620
+ //
5621
+ // Original sources:
5622
+ // - @rrweb/types: https://github.com/rrweb-io/rrweb/tree/main/packages/@rrweb/types
5623
+ // - rrweb-snapshot: https://github.com/rrweb-io/rrweb/tree/main/packages/rrweb-snapshot
5624
+ var NodeType;
5625
+ (function (NodeType) {
5626
+ NodeType[NodeType["Document"] = 0] = "Document";
5627
+ NodeType[NodeType["DocumentType"] = 1] = "DocumentType";
5628
+ NodeType[NodeType["Element"] = 2] = "Element";
5629
+ NodeType[NodeType["Text"] = 3] = "Text";
5630
+ NodeType[NodeType["CDATA"] = 4] = "CDATA";
5631
+ NodeType[NodeType["Comment"] = 5] = "Comment";
5632
+ })(NodeType || (NodeType = {}));
5633
+ var EventType;
5634
+ (function (EventType) {
5635
+ EventType[EventType["DomContentLoaded"] = 0] = "DomContentLoaded";
5636
+ EventType[EventType["Load"] = 1] = "Load";
5637
+ EventType[EventType["FullSnapshot"] = 2] = "FullSnapshot";
5638
+ EventType[EventType["IncrementalSnapshot"] = 3] = "IncrementalSnapshot";
5639
+ EventType[EventType["Meta"] = 4] = "Meta";
5640
+ EventType[EventType["Custom"] = 5] = "Custom";
5641
+ EventType[EventType["Plugin"] = 6] = "Plugin";
5642
+ })(EventType || (EventType = {}));
5643
+ var IncrementalSource;
5644
+ (function (IncrementalSource) {
5645
+ IncrementalSource[IncrementalSource["Mutation"] = 0] = "Mutation";
5646
+ IncrementalSource[IncrementalSource["MouseMove"] = 1] = "MouseMove";
5647
+ IncrementalSource[IncrementalSource["MouseInteraction"] = 2] = "MouseInteraction";
5648
+ IncrementalSource[IncrementalSource["Scroll"] = 3] = "Scroll";
5649
+ IncrementalSource[IncrementalSource["ViewportResize"] = 4] = "ViewportResize";
5650
+ IncrementalSource[IncrementalSource["Input"] = 5] = "Input";
5651
+ IncrementalSource[IncrementalSource["TouchMove"] = 6] = "TouchMove";
5652
+ IncrementalSource[IncrementalSource["MediaInteraction"] = 7] = "MediaInteraction";
5653
+ IncrementalSource[IncrementalSource["StyleSheetRule"] = 8] = "StyleSheetRule";
5654
+ IncrementalSource[IncrementalSource["CanvasMutation"] = 9] = "CanvasMutation";
5655
+ IncrementalSource[IncrementalSource["Font"] = 10] = "Font";
5656
+ IncrementalSource[IncrementalSource["Log"] = 11] = "Log";
5657
+ IncrementalSource[IncrementalSource["Drag"] = 12] = "Drag";
5658
+ IncrementalSource[IncrementalSource["StyleDeclaration"] = 13] = "StyleDeclaration";
5659
+ IncrementalSource[IncrementalSource["Selection"] = 14] = "Selection";
5660
+ IncrementalSource[IncrementalSource["AdoptedStyleSheet"] = 15] = "AdoptedStyleSheet";
5661
+ IncrementalSource[IncrementalSource["CustomElement"] = 16] = "CustomElement";
5662
+ })(IncrementalSource || (IncrementalSource = {}));
5663
+ var MouseInteractions;
5664
+ (function (MouseInteractions) {
5665
+ MouseInteractions[MouseInteractions["MouseUp"] = 0] = "MouseUp";
5666
+ MouseInteractions[MouseInteractions["MouseDown"] = 1] = "MouseDown";
5667
+ MouseInteractions[MouseInteractions["Click"] = 2] = "Click";
5668
+ MouseInteractions[MouseInteractions["ContextMenu"] = 3] = "ContextMenu";
5669
+ MouseInteractions[MouseInteractions["DblClick"] = 4] = "DblClick";
5670
+ MouseInteractions[MouseInteractions["Focus"] = 5] = "Focus";
5671
+ MouseInteractions[MouseInteractions["Blur"] = 6] = "Blur";
5672
+ MouseInteractions[MouseInteractions["TouchStart"] = 7] = "TouchStart";
5673
+ MouseInteractions[MouseInteractions["TouchMove_Departed"] = 8] = "TouchMove_Departed";
5674
+ MouseInteractions[MouseInteractions["TouchEnd"] = 9] = "TouchEnd";
5675
+ MouseInteractions[MouseInteractions["TouchCancel"] = 10] = "TouchCancel";
5676
+ })(MouseInteractions || (MouseInteractions = {}));
5677
+ var PointerTypes;
5678
+ (function (PointerTypes) {
5679
+ PointerTypes[PointerTypes["Mouse"] = 0] = "Mouse";
5680
+ PointerTypes[PointerTypes["Pen"] = 1] = "Pen";
5681
+ PointerTypes[PointerTypes["Touch"] = 2] = "Touch";
5682
+ })(PointerTypes || (PointerTypes = {}));
5683
+ var MediaInteractions;
5684
+ (function (MediaInteractions) {
5685
+ MediaInteractions[MediaInteractions["Play"] = 0] = "Play";
5686
+ MediaInteractions[MediaInteractions["Pause"] = 1] = "Pause";
5687
+ MediaInteractions[MediaInteractions["Seeked"] = 2] = "Seeked";
5688
+ MediaInteractions[MediaInteractions["VolumeChange"] = 3] = "VolumeChange";
5689
+ MediaInteractions[MediaInteractions["RateChange"] = 4] = "RateChange";
5690
+ })(MediaInteractions || (MediaInteractions = {}));
5691
+ var CanvasContext;
5692
+ (function (CanvasContext) {
5693
+ CanvasContext[CanvasContext["2D"] = 0] = "2D";
5694
+ CanvasContext[CanvasContext["WebGL"] = 1] = "WebGL";
5695
+ CanvasContext[CanvasContext["WebGL2"] = 2] = "WebGL2";
5696
+ })(CanvasContext || (CanvasContext = {}));
5697
+
5679
5698
  const DISABLED = 'disabled';
5680
5699
  const SAMPLED = 'sampled';
5681
5700
  const ACTIVE = 'active';
@@ -6716,6 +6735,15 @@ var leanbase = (function (record) {
6716
6735
  attempt: 1
6717
6736
  });
6718
6737
  function getRRWebRecord() {
6738
+ try {
6739
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6740
+ const ext = globalThis.__PosthogExtensions__;
6741
+ if (ext && ext.rrweb && ext.rrweb.record) {
6742
+ return ext.rrweb.record;
6743
+ }
6744
+ } catch {
6745
+ // ignore
6746
+ }
6719
6747
  return record.record;
6720
6748
  }
6721
6749
  function gzipToString(data) {
@@ -7427,7 +7455,7 @@ var leanbase = (function (record) {
7427
7455
  _captureSnapshot(properties) {
7428
7456
  // :TRICKY: Make sure we batch these requests, use a custom endpoint and don't truncate the strings.
7429
7457
  this._instance.capture('$snapshot', properties, {
7430
- _url: this._snapshotUrl(),
7458
+ _url: this._instance.requestRouter.endpointFor('api', this._endpoint),
7431
7459
  _noTruncate: true,
7432
7460
  _batchKey: SESSION_RECORDING_BATCH_KEY,
7433
7461
  skip_client_rate_limiting: true
@@ -7759,35 +7787,22 @@ var leanbase = (function (record) {
7759
7787
  }
7760
7788
  }
7761
7789
  get _isRecordingEnabled() {
7762
- if (!win) {
7763
- return false;
7764
- }
7765
- if (!this._serverRecordingEnabled) {
7766
- return false;
7767
- }
7768
- if (this._instance.config.disable_session_recording) {
7769
- return false;
7770
- }
7771
- return true;
7790
+ const enabled_server_side = !!this._instance.get_property(SESSION_RECORDING_REMOTE_CONFIG)?.enabled;
7791
+ const enabled_client_side = !this._instance.config.disable_session_recording;
7792
+ const isDisabled = this._instance.config.disable_session_recording || this._instance.consent?.isOptedOut?.();
7793
+ return win && enabled_server_side && enabled_client_side && !isDisabled;
7772
7794
  }
7773
7795
  startIfEnabledOrStop(startReason) {
7774
- const canRunReplay = !isUndefined(Object.assign) && !isUndefined(Array.from);
7775
- if (!this._isRecordingEnabled || !canRunReplay) {
7776
- this.stopRecording();
7796
+ if (this._isRecordingEnabled && this._lazyLoadedSessionRecording?.isStarted) {
7777
7797
  return;
7778
7798
  }
7779
- if (this._lazyLoadedSessionRecording?.isStarted) {
7780
- return;
7799
+ const canRunReplay = !isUndefined(Object.assign) && !isUndefined(Array.from);
7800
+ if (this._isRecordingEnabled && canRunReplay) {
7801
+ this._lazyLoadAndStart(startReason);
7802
+ log.info('starting');
7803
+ } else {
7804
+ this.stopRecording();
7781
7805
  }
7782
- // According to the rrweb docs, rrweb is not supported on IE11 and below:
7783
- // "rrweb does not support IE11 and below because it uses the MutationObserver API, which was supported by these browsers."
7784
- // https://github.com/rrweb-io/rrweb/blob/master/guide.md#compatibility-note
7785
- //
7786
- // However, MutationObserver does exist on IE11, it just doesn't work well and does not detect all changes.
7787
- // Instead, when we load "recorder.js", the first JS error is about "Object.assign" and "Array.from" being undefined.
7788
- // Thus instead of MutationObserver, we look for this function and block recording if it's undefined.
7789
- this._lazyLoadAndStart(startReason);
7790
- log.info('starting');
7791
7806
  }
7792
7807
  /**
7793
7808
  * session recording waits until it receives remote config before loading the script
@@ -8092,6 +8107,9 @@ var leanbase = (function (record) {
8092
8107
  };
8093
8108
  if (isObject(config)) {
8094
8109
  extend(this.config, config);
8110
+ if (!this.config.api_host && this.config.host) {
8111
+ this.config.api_host = this.config.host;
8112
+ }
8095
8113
  this.persistence?.update_config(this.config, oldConfig);
8096
8114
  this.replayAutocapture?.startIfEnabled();
8097
8115
  this.sessionRecording?.startIfEnabledOrStop();