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