@zaplier/sdk 1.1.7 → 1.1.9
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.cjs +116 -112
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +116 -112
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +116 -112
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/modules/anti-adblock.d.ts +16 -1
- package/dist/src/modules/anti-adblock.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -6147,112 +6147,6 @@ class FetchTransport {
|
|
|
6147
6147
|
}
|
|
6148
6148
|
}
|
|
6149
6149
|
}
|
|
6150
|
-
/**
|
|
6151
|
-
* WebSocket Transport
|
|
6152
|
-
*/
|
|
6153
|
-
class WebSocketTransport {
|
|
6154
|
-
constructor(baseUrl) {
|
|
6155
|
-
this.name = 'websocket';
|
|
6156
|
-
this.available = typeof WebSocket !== 'undefined';
|
|
6157
|
-
this.connected = false;
|
|
6158
|
-
this.messageQueue = [];
|
|
6159
|
-
this.baseUrl = baseUrl.replace(/^http/, 'ws');
|
|
6160
|
-
}
|
|
6161
|
-
async connect() {
|
|
6162
|
-
if (this.connected || !this.available)
|
|
6163
|
-
return;
|
|
6164
|
-
return new Promise((resolve, reject) => {
|
|
6165
|
-
try {
|
|
6166
|
-
this.ws = new WebSocket(`${this.baseUrl}/ws/track`);
|
|
6167
|
-
this.ws.onopen = () => {
|
|
6168
|
-
this.connected = true;
|
|
6169
|
-
this.processQueue();
|
|
6170
|
-
resolve();
|
|
6171
|
-
};
|
|
6172
|
-
this.ws.onerror = () => {
|
|
6173
|
-
reject(new Error('WebSocket connection failed'));
|
|
6174
|
-
};
|
|
6175
|
-
this.ws.onclose = () => {
|
|
6176
|
-
this.connected = false;
|
|
6177
|
-
// Try to reconnect after 5 seconds
|
|
6178
|
-
setTimeout(() => this.connect().catch(() => { }), 5000);
|
|
6179
|
-
};
|
|
6180
|
-
}
|
|
6181
|
-
catch (error) {
|
|
6182
|
-
reject(error);
|
|
6183
|
-
}
|
|
6184
|
-
});
|
|
6185
|
-
}
|
|
6186
|
-
processQueue() {
|
|
6187
|
-
while (this.messageQueue.length > 0 && this.connected) {
|
|
6188
|
-
const item = this.messageQueue.shift();
|
|
6189
|
-
if (item && this.ws) {
|
|
6190
|
-
try {
|
|
6191
|
-
this.ws.send(JSON.stringify(item.data));
|
|
6192
|
-
item.resolve({ success: true, method: this.name });
|
|
6193
|
-
}
|
|
6194
|
-
catch (error) {
|
|
6195
|
-
item.resolve({
|
|
6196
|
-
success: false,
|
|
6197
|
-
method: this.name,
|
|
6198
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6199
|
-
});
|
|
6200
|
-
}
|
|
6201
|
-
}
|
|
6202
|
-
}
|
|
6203
|
-
}
|
|
6204
|
-
async send(data, endpoint) {
|
|
6205
|
-
const start = Date.now();
|
|
6206
|
-
if (!this.available) {
|
|
6207
|
-
return { success: false, method: this.name, error: 'WebSocket not available' };
|
|
6208
|
-
}
|
|
6209
|
-
// Try to connect if not connected
|
|
6210
|
-
if (!this.connected) {
|
|
6211
|
-
try {
|
|
6212
|
-
await this.connect();
|
|
6213
|
-
}
|
|
6214
|
-
catch (error) {
|
|
6215
|
-
return {
|
|
6216
|
-
success: false,
|
|
6217
|
-
method: this.name,
|
|
6218
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6219
|
-
};
|
|
6220
|
-
}
|
|
6221
|
-
}
|
|
6222
|
-
return new Promise((resolve) => {
|
|
6223
|
-
if (this.connected && this.ws) {
|
|
6224
|
-
try {
|
|
6225
|
-
this.ws.send(JSON.stringify(data));
|
|
6226
|
-
resolve({
|
|
6227
|
-
success: true,
|
|
6228
|
-
method: this.name,
|
|
6229
|
-
latency: Date.now() - start
|
|
6230
|
-
});
|
|
6231
|
-
}
|
|
6232
|
-
catch (error) {
|
|
6233
|
-
resolve({
|
|
6234
|
-
success: false,
|
|
6235
|
-
method: this.name,
|
|
6236
|
-
error: error instanceof Error ? error.message : String(error)
|
|
6237
|
-
});
|
|
6238
|
-
}
|
|
6239
|
-
}
|
|
6240
|
-
else {
|
|
6241
|
-
// Queue message for later
|
|
6242
|
-
this.messageQueue.push({ data, resolve: (response) => resolve({
|
|
6243
|
-
...response,
|
|
6244
|
-
latency: Date.now() - start
|
|
6245
|
-
}) });
|
|
6246
|
-
}
|
|
6247
|
-
});
|
|
6248
|
-
}
|
|
6249
|
-
destroy() {
|
|
6250
|
-
if (this.ws) {
|
|
6251
|
-
this.ws.close();
|
|
6252
|
-
this.connected = false;
|
|
6253
|
-
}
|
|
6254
|
-
}
|
|
6255
|
-
}
|
|
6256
6150
|
/**
|
|
6257
6151
|
* Resource Spoofing Transport (GET requests disguised as assets)
|
|
6258
6152
|
*/
|
|
@@ -6315,6 +6209,114 @@ class ResourceSpoofTransport {
|
|
|
6315
6209
|
}
|
|
6316
6210
|
}
|
|
6317
6211
|
}
|
|
6212
|
+
/**
|
|
6213
|
+
* Elysia WebSocket Transport (Native WebSocket for anti-adblock)
|
|
6214
|
+
*/
|
|
6215
|
+
class ElysiaWebSocketTransport {
|
|
6216
|
+
constructor(baseUrl) {
|
|
6217
|
+
this.name = 'elysia-websocket';
|
|
6218
|
+
this.available = typeof WebSocket !== 'undefined';
|
|
6219
|
+
this.connected = false;
|
|
6220
|
+
this.token = '';
|
|
6221
|
+
this.baseUrl = baseUrl;
|
|
6222
|
+
}
|
|
6223
|
+
async send(data, endpoint) {
|
|
6224
|
+
const start = Date.now();
|
|
6225
|
+
try {
|
|
6226
|
+
// Extract token from data (passed from SDK)
|
|
6227
|
+
this.token = data.token || '';
|
|
6228
|
+
if (!this.token) {
|
|
6229
|
+
throw new Error('Missing token for WebSocket connection');
|
|
6230
|
+
}
|
|
6231
|
+
await this.connect();
|
|
6232
|
+
if (!this.ws || !this.connected) {
|
|
6233
|
+
throw new Error('WebSocket not connected');
|
|
6234
|
+
}
|
|
6235
|
+
return new Promise((resolve, reject) => {
|
|
6236
|
+
const messageHandler = (event) => {
|
|
6237
|
+
try {
|
|
6238
|
+
const response = JSON.parse(event.data);
|
|
6239
|
+
this.ws?.removeEventListener('message', messageHandler);
|
|
6240
|
+
resolve({
|
|
6241
|
+
success: response.success || false,
|
|
6242
|
+
method: this.name,
|
|
6243
|
+
latency: Date.now() - start
|
|
6244
|
+
});
|
|
6245
|
+
}
|
|
6246
|
+
catch (error) {
|
|
6247
|
+
this.ws?.removeEventListener('message', messageHandler);
|
|
6248
|
+
reject(new Error('Failed to parse WebSocket response'));
|
|
6249
|
+
}
|
|
6250
|
+
};
|
|
6251
|
+
this.ws?.addEventListener('message', messageHandler);
|
|
6252
|
+
// Send the tracking data
|
|
6253
|
+
this.ws?.send(JSON.stringify({
|
|
6254
|
+
eventId: data.eventId || crypto.randomUUID(),
|
|
6255
|
+
sessionId: data.sessionId || data.s,
|
|
6256
|
+
eventType: data.eventType || data.type || 'websocket_event',
|
|
6257
|
+
eventName: data.eventName || data.name,
|
|
6258
|
+
url: data.url,
|
|
6259
|
+
userAgent: data.userAgent || navigator.userAgent,
|
|
6260
|
+
timestamp: new Date().toISOString()
|
|
6261
|
+
}));
|
|
6262
|
+
// Timeout after 5 seconds
|
|
6263
|
+
setTimeout(() => {
|
|
6264
|
+
this.ws?.removeEventListener('message', messageHandler);
|
|
6265
|
+
reject(new Error('WebSocket response timeout'));
|
|
6266
|
+
}, 5000);
|
|
6267
|
+
});
|
|
6268
|
+
}
|
|
6269
|
+
catch (error) {
|
|
6270
|
+
return {
|
|
6271
|
+
success: false,
|
|
6272
|
+
method: this.name,
|
|
6273
|
+
latency: Date.now() - start,
|
|
6274
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6275
|
+
};
|
|
6276
|
+
}
|
|
6277
|
+
}
|
|
6278
|
+
async connect() {
|
|
6279
|
+
if (this.connected && this.ws?.readyState === WebSocket.OPEN) {
|
|
6280
|
+
return;
|
|
6281
|
+
}
|
|
6282
|
+
return new Promise((resolve, reject) => {
|
|
6283
|
+
try {
|
|
6284
|
+
// Convert HTTP/HTTPS to WS/WSS
|
|
6285
|
+
const url = new URL(this.baseUrl);
|
|
6286
|
+
const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
6287
|
+
const wsUrl = `${protocol}//${url.host}/ws/track?token=${encodeURIComponent(this.token)}`;
|
|
6288
|
+
this.ws = new WebSocket(wsUrl);
|
|
6289
|
+
this.ws.onopen = () => {
|
|
6290
|
+
this.connected = true;
|
|
6291
|
+
resolve();
|
|
6292
|
+
};
|
|
6293
|
+
this.ws.onerror = (error) => {
|
|
6294
|
+
this.connected = false;
|
|
6295
|
+
reject(new Error('WebSocket connection failed'));
|
|
6296
|
+
};
|
|
6297
|
+
this.ws.onclose = () => {
|
|
6298
|
+
this.connected = false;
|
|
6299
|
+
};
|
|
6300
|
+
// Timeout after 5 seconds
|
|
6301
|
+
setTimeout(() => {
|
|
6302
|
+
if (!this.connected) {
|
|
6303
|
+
this.ws?.close();
|
|
6304
|
+
reject(new Error('WebSocket connection timeout'));
|
|
6305
|
+
}
|
|
6306
|
+
}, 5000);
|
|
6307
|
+
}
|
|
6308
|
+
catch (error) {
|
|
6309
|
+
reject(error);
|
|
6310
|
+
}
|
|
6311
|
+
});
|
|
6312
|
+
}
|
|
6313
|
+
cleanup() {
|
|
6314
|
+
if (this.ws) {
|
|
6315
|
+
this.ws.close();
|
|
6316
|
+
this.connected = false;
|
|
6317
|
+
}
|
|
6318
|
+
}
|
|
6319
|
+
}
|
|
6318
6320
|
/**
|
|
6319
6321
|
* Socket.io Transport (Real-time bidirectional communication for anti-adblock)
|
|
6320
6322
|
*/
|
|
@@ -6376,12 +6378,14 @@ class SocketIOTransport {
|
|
|
6376
6378
|
try {
|
|
6377
6379
|
// Use dynamic import to load socket.io-client only when needed
|
|
6378
6380
|
Promise.resolve().then(function () { return index; }).then(({ io }) => {
|
|
6379
|
-
// Extract domain from baseUrl -
|
|
6381
|
+
// Extract domain from baseUrl - preserve protocol (HTTP/HTTPS)
|
|
6380
6382
|
const url = new URL(this.baseUrl);
|
|
6381
6383
|
const socketUrl = `${url.protocol}//${url.host}`;
|
|
6382
6384
|
this.socket = io(socketUrl, {
|
|
6383
|
-
transports: ['
|
|
6384
|
-
timeout: 5000
|
|
6385
|
+
transports: ['polling', 'websocket'], // Try polling first for better proxy compatibility
|
|
6386
|
+
timeout: 5000,
|
|
6387
|
+
upgrade: true,
|
|
6388
|
+
rememberUpgrade: false
|
|
6385
6389
|
});
|
|
6386
6390
|
this.socket.on('connect', () => {
|
|
6387
6391
|
this.connected = true;
|
|
@@ -6499,7 +6503,7 @@ class AntiAdblockManager {
|
|
|
6499
6503
|
this.baseUrl = baseUrl;
|
|
6500
6504
|
this.config = {
|
|
6501
6505
|
enabled: true,
|
|
6502
|
-
methods: ['
|
|
6506
|
+
methods: ['elysia-websocket', 'fetch', 'resource'], // Elysia WebSocket as primary
|
|
6503
6507
|
fallbackDelay: 100,
|
|
6504
6508
|
maxRetries: 2,
|
|
6505
6509
|
debug: false,
|
|
@@ -6509,9 +6513,9 @@ class AntiAdblockManager {
|
|
|
6509
6513
|
}
|
|
6510
6514
|
initializeTransports() {
|
|
6511
6515
|
const transportMap = {
|
|
6516
|
+
'elysia-websocket': () => new ElysiaWebSocketTransport(this.baseUrl),
|
|
6512
6517
|
socketio: () => new SocketIOTransport(this.baseUrl),
|
|
6513
6518
|
fetch: () => new FetchTransport(),
|
|
6514
|
-
websocket: () => new WebSocketTransport(this.baseUrl),
|
|
6515
6519
|
resource: () => new ResourceSpoofTransport(this.baseUrl),
|
|
6516
6520
|
webrtc: () => new WebRTCTransport()
|
|
6517
6521
|
};
|
|
@@ -7757,7 +7761,7 @@ class ZaplierSDK {
|
|
|
7757
7761
|
try {
|
|
7758
7762
|
this.antiAdblockManager = new AntiAdblockManager(this.config.apiEndpoint, {
|
|
7759
7763
|
enabled: true,
|
|
7760
|
-
methods: ["
|
|
7764
|
+
methods: ["elysia-websocket", "fetch", "resource"], // Elysia WebSocket as primary
|
|
7761
7765
|
fallbackDelay: 100,
|
|
7762
7766
|
maxRetries: 2,
|
|
7763
7767
|
debug: this.config.debug,
|