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