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