crexperium-sdk 1.1.0 → 1.2.0

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.mjs CHANGED
@@ -130,22 +130,17 @@ class NetworkError extends CRMError {
130
130
  const isBrowser$1 = typeof window !== 'undefined';
131
131
  // Get fetch implementation
132
132
  function getFetch() {
133
+ // Browser environment
133
134
  if (isBrowser$1 && typeof window.fetch !== 'undefined') {
134
135
  return window.fetch.bind(window);
135
136
  }
136
- // In Node.js, use global fetch if available (Node 18+) or require node-fetch
137
+ // Node.js 18+ with native fetch
137
138
  if (typeof globalThis.fetch !== 'undefined') {
138
139
  return globalThis.fetch.bind(globalThis);
139
140
  }
140
- // Fallback to require node-fetch for older Node.js versions
141
- try {
142
- // eslint-disable-next-line @typescript-eslint/no-var-requires
143
- const nodeFetch = require('node-fetch');
144
- return nodeFetch.default || nodeFetch;
145
- }
146
- catch {
147
- throw new Error('Fetch is not available. Please upgrade to Node.js 18+ or install node-fetch.');
148
- }
141
+ // Node.js <18 without fetch - throw helpful error
142
+ throw new Error('Fetch is not available. Please upgrade to Node.js 18+ which includes native fetch support. ' +
143
+ 'Alternatively, install and configure a polyfill.');
149
144
  }
150
145
  class HTTPClient {
151
146
  constructor(config) {
@@ -13190,10 +13185,14 @@ class SessionReplayPlugin {
13190
13185
  */
13191
13186
  async init() {
13192
13187
  try {
13188
+ console.log('[SessionReplay] Initializing session replay...');
13193
13189
  // Start session on backend
13194
13190
  await this.startSession();
13191
+ console.log('[SessionReplay] Session started on backend, sessionId:', this.session?.sessionId);
13195
13192
  // Start rrweb recording
13193
+ console.log('[SessionReplay] Starting rrweb recording...');
13196
13194
  this.startRrwebRecording();
13195
+ console.log('[SessionReplay] rrweb recording started');
13197
13196
  // Intercept console methods
13198
13197
  if (this.config.telemetry?.captureConsole) {
13199
13198
  this.interceptConsole();
@@ -13265,9 +13264,18 @@ class SessionReplayPlugin {
13265
13264
  startRrwebRecording() {
13266
13265
  this.stopRecording = record({
13267
13266
  emit: (event) => {
13267
+ // Debug: Log event types
13268
+ if (event.type === 4) {
13269
+ console.log('[SessionReplay] Captured Meta event (type 4)');
13270
+ }
13271
+ else if (event.type === 2) {
13272
+ console.log('[SessionReplay] Captured Full Snapshot event (type 2)');
13273
+ }
13268
13274
  this.eventBuffer.push(event);
13275
+ console.log(`[SessionReplay] Event buffered. Type: ${event.type}, Buffer size: ${this.eventBuffer.length}`);
13269
13276
  // Auto-flush if buffer reaches max size
13270
13277
  if (this.eventBuffer.length >= (this.config.buffering?.maxBufferSize || 100)) {
13278
+ console.log('[SessionReplay] Buffer full, flushing...');
13271
13279
  this.flush();
13272
13280
  }
13273
13281
  },
@@ -13609,9 +13617,16 @@ class SessionReplayPlugin {
13609
13617
  * Flush buffered events to backend
13610
13618
  */
13611
13619
  async flush() {
13612
- if (!this.session || (this.eventBuffer.length === 0 && this.telemetryBuffer.length === 0)) {
13620
+ console.log(`[SessionReplay] flush() called. Session: ${!!this.session}, Event buffer: ${this.eventBuffer.length}, Telemetry buffer: ${this.telemetryBuffer.length}`);
13621
+ if (!this.session) {
13622
+ console.warn('[SessionReplay] flush() skipped - no session yet!');
13623
+ return;
13624
+ }
13625
+ if (this.eventBuffer.length === 0 && this.telemetryBuffer.length === 0) {
13626
+ console.log('[SessionReplay] flush() skipped - buffers empty');
13613
13627
  return;
13614
13628
  }
13629
+ console.log(`[SessionReplay] Flushing ${this.eventBuffer.length} events to backend...`);
13615
13630
  const eventsToSend = [...this.eventBuffer];
13616
13631
  const telemetryToSend = [...this.telemetryBuffer];
13617
13632
  // Clear buffers