crexperium-sdk 1.2.2 → 1.2.4

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
@@ -449,11 +449,43 @@ class EventsResource extends BaseResource {
449
449
  */
450
450
  class ContactsResource extends BaseResource {
451
451
  /**
452
- * Identify a contact (create or update)
452
+ * Identify a contact (create or update by multiple identifiers)
453
+ *
454
+ * Accepts at least ONE of: externalId, visitorId, email, or phone
455
+ * Priority: externalId > visitorId > email > phone
456
+ *
457
+ * @example
458
+ * // Identify by external ID (after login)
459
+ * await client.contacts.identify({
460
+ * externalId: 'user_123',
461
+ * email: 'user@example.com',
462
+ * firstName: 'John'
463
+ * });
464
+ *
465
+ * @example
466
+ * // Identify by visitor ID (anonymous → known)
467
+ * await client.contacts.identify({
468
+ * visitorId: client.visitorId.getVisitorId(),
469
+ * email: 'user@example.com'
470
+ * });
471
+ *
472
+ * @example
473
+ * // Identify by email only
474
+ * await client.contacts.identify({
475
+ * email: 'user@example.com',
476
+ * firstName: 'John'
477
+ * });
478
+ *
479
+ * @example
480
+ * // Identify by phone only
481
+ * await client.contacts.identify({
482
+ * phone: '+1234567890'
483
+ * });
453
484
  */
454
485
  async identify(options) {
455
- if (!options.externalId) {
456
- throw new Error('externalId is required');
486
+ // Validate that at least one identifier is provided
487
+ if (!options.externalId && !options.visitorId && !options.email && !options.phone) {
488
+ throw new Error('At least one identifier is required: externalId, visitorId, email, or phone');
457
489
  }
458
490
  const data = this.cleanObject(this.toSnakeCase(options));
459
491
  return this.http.post('/api/v1/contacts/identify/', data);
@@ -13185,18 +13217,13 @@ class SessionReplayPlugin {
13185
13217
  */
13186
13218
  async init() {
13187
13219
  try {
13188
- console.log('[SessionReplay] Initializing session replay...');
13189
13220
  // Start session on backend
13190
13221
  await this.startSession();
13191
- console.log('[SessionReplay] Session started on backend, sessionId:', this.session?.sessionId);
13192
13222
  // Start rrweb recording
13193
- console.log('[SessionReplay] Starting rrweb recording...');
13194
13223
  this.startRrwebRecording();
13195
- console.log('[SessionReplay] rrweb recording started');
13196
13224
  // IMPORTANT: Flush initial events (Type 4 Meta + Type 2 Full Snapshot) immediately
13197
13225
  // so the session is playable right away, don't wait for the 5s flush interval
13198
13226
  setTimeout(() => {
13199
- console.log('[SessionReplay] Performing initial flush of critical events...');
13200
13227
  this.flush();
13201
13228
  }, 100); // Small delay to ensure rrweb events are captured
13202
13229
  // Intercept console methods
@@ -13271,17 +13298,9 @@ class SessionReplayPlugin {
13271
13298
  this.stopRecording = record({
13272
13299
  emit: (event) => {
13273
13300
  // Debug: Log event types
13274
- if (event.type === 4) {
13275
- console.log('[SessionReplay] Captured Meta event (type 4)');
13276
- }
13277
- else if (event.type === 2) {
13278
- console.log('[SessionReplay] Captured Full Snapshot event (type 2)');
13279
- }
13280
13301
  this.eventBuffer.push(event);
13281
- console.log(`[SessionReplay] Event buffered. Type: ${event.type}, Buffer size: ${this.eventBuffer.length}`);
13282
13302
  // Auto-flush if buffer reaches max size
13283
13303
  if (this.eventBuffer.length >= (this.config.buffering?.maxBufferSize || 100)) {
13284
- console.log('[SessionReplay] Buffer full, flushing...');
13285
13304
  this.flush();
13286
13305
  }
13287
13306
  },
@@ -13623,16 +13642,12 @@ class SessionReplayPlugin {
13623
13642
  * Flush buffered events to backend
13624
13643
  */
13625
13644
  async flush() {
13626
- console.log(`[SessionReplay] flush() called. Session: ${!!this.session}, Event buffer: ${this.eventBuffer.length}, Telemetry buffer: ${this.telemetryBuffer.length}`);
13627
13645
  if (!this.session) {
13628
- console.warn('[SessionReplay] flush() skipped - no session yet!');
13629
13646
  return;
13630
13647
  }
13631
13648
  if (this.eventBuffer.length === 0 && this.telemetryBuffer.length === 0) {
13632
- console.log('[SessionReplay] flush() skipped - buffers empty');
13633
13649
  return;
13634
13650
  }
13635
- console.log(`[SessionReplay] Flushing ${this.eventBuffer.length} events to backend...`);
13636
13651
  const eventsToSend = [...this.eventBuffer];
13637
13652
  const telemetryToSend = [...this.telemetryBuffer];
13638
13653
  // Clear buffers