@zaplier/sdk 1.0.0 → 1.0.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.
package/dist/index.esm.js CHANGED
@@ -4830,7 +4830,7 @@ class ResourceSpoofTransport {
4830
4830
  class WebRTCTransport {
4831
4831
  constructor() {
4832
4832
  this.name = 'webrtc';
4833
- this.available = typeof RTCPeerConnection !== 'undefined';
4833
+ this.available = typeof globalThis.RTCPeerConnection !== 'undefined';
4834
4834
  this.connected = false;
4835
4835
  }
4836
4836
  async send(data, endpoint) {
@@ -4869,7 +4869,7 @@ class WebRTCTransport {
4869
4869
  return;
4870
4870
  return new Promise((resolve, reject) => {
4871
4871
  try {
4872
- this.pc = new RTCPeerConnection({
4872
+ this.pc = new globalThis.RTCPeerConnection({
4873
4873
  iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
4874
4874
  });
4875
4875
  this.dataChannel = this.pc.createDataChannel('tracking', {
@@ -6303,30 +6303,9 @@ class ZaplierSDK {
6303
6303
  * Make HTTP request to backend using anti-adblock system
6304
6304
  */
6305
6305
  async makeRequest(endpoint, data, method = "POST") {
6306
- // Use anti-adblock manager if available
6307
- if (this.antiAdblockManager && method === "POST") {
6308
- try {
6309
- const result = await this.antiAdblockManager.send(data, endpoint);
6310
- if (result.success) {
6311
- if (this.config.debug) {
6312
- console.log(`[Zaplier] Request sent via ${result.method} (${result.latency}ms)`);
6313
- }
6314
- // Return success response for compatibility
6315
- return { success: true, method: result.method };
6316
- }
6317
- else {
6318
- throw new Error(`Anti-adblock failed: ${result.error}`);
6319
- }
6320
- }
6321
- catch (error) {
6322
- if (this.config.debug) {
6323
- console.warn("[Zaplier] Anti-adblock failed, falling back to standard fetch");
6324
- }
6325
- // Fall through to standard fetch
6326
- }
6327
- }
6328
- // Fallback to standard fetch
6329
6306
  const url = `${this.config.apiEndpoint}${endpoint}`;
6307
+ // Always use standard fetch to get the response JSON (which contains visitorId)
6308
+ // Use anti-adblock as a parallel fallback method if standard fetch fails
6330
6309
  const options = {
6331
6310
  method,
6332
6311
  headers: {
@@ -6336,11 +6315,46 @@ class ZaplierSDK {
6336
6315
  if (method === "POST" && data) {
6337
6316
  options.body = JSON.stringify(data);
6338
6317
  }
6339
- const response = await fetch(url, options);
6340
- if (!response.ok) {
6341
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
6318
+ try {
6319
+ const response = await fetch(url, options);
6320
+ if (!response.ok) {
6321
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
6322
+ }
6323
+ const jsonResponse = await response.json();
6324
+ // If anti-adblock is enabled, also send via anti-adblock as a backup
6325
+ // (but don't wait for it or use its response)
6326
+ if (this.antiAdblockManager && method === "POST") {
6327
+ // Send in parallel without blocking
6328
+ this.antiAdblockManager.send(data, endpoint).catch(() => {
6329
+ // Silently fail - we already got the response from standard fetch
6330
+ });
6331
+ }
6332
+ return jsonResponse;
6333
+ }
6334
+ catch (error) {
6335
+ // If standard fetch fails, try anti-adblock as fallback
6336
+ if (this.antiAdblockManager && method === "POST") {
6337
+ try {
6338
+ const result = await this.antiAdblockManager.send(data, endpoint);
6339
+ if (result.success) {
6340
+ if (this.config.debug) {
6341
+ console.log(`[Zaplier] Request sent via ${result.method} (${result.latency}ms) as fallback`);
6342
+ }
6343
+ // Try to get response from a separate request
6344
+ // Note: This is a limitation - we can't get visitorId from anti-adblock transports
6345
+ // But at least the event was sent
6346
+ return { success: true, method: result.method };
6347
+ }
6348
+ }
6349
+ catch (antiAdblockError) {
6350
+ if (this.config.debug) {
6351
+ console.warn("[Zaplier] Both standard fetch and anti-adblock failed");
6352
+ }
6353
+ }
6354
+ }
6355
+ // Re-throw original error if all methods failed
6356
+ throw error;
6342
6357
  }
6343
- return response.json();
6344
6358
  }
6345
6359
  /**
6346
6360
  * Process queued events