@zaplier/sdk 1.1.8 → 1.2.0
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 +121 -117
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +121 -117
- package/dist/index.esm.js.map +1 -1
- package/dist/sdk.js +121 -117
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.min.js +1 -1
- package/dist/src/modules/anti-adblock.d.ts +20 -4
- package/dist/src/modules/anti-adblock.d.ts.map +1 -1
- package/dist/src/sdk.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,112 @@ 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, token) {
|
|
6217
|
+
this.name = 'elysia-websocket';
|
|
6218
|
+
this.available = typeof WebSocket !== 'undefined';
|
|
6219
|
+
this.connected = false;
|
|
6220
|
+
this.baseUrl = baseUrl;
|
|
6221
|
+
this.token = token;
|
|
6222
|
+
}
|
|
6223
|
+
async send(data, endpoint) {
|
|
6224
|
+
const start = Date.now();
|
|
6225
|
+
try {
|
|
6226
|
+
if (!this.token) {
|
|
6227
|
+
throw new Error('Missing token for WebSocket connection');
|
|
6228
|
+
}
|
|
6229
|
+
await this.connect();
|
|
6230
|
+
if (!this.ws || !this.connected) {
|
|
6231
|
+
throw new Error('WebSocket not connected');
|
|
6232
|
+
}
|
|
6233
|
+
return new Promise((resolve, reject) => {
|
|
6234
|
+
const messageHandler = (event) => {
|
|
6235
|
+
try {
|
|
6236
|
+
const response = JSON.parse(event.data);
|
|
6237
|
+
this.ws?.removeEventListener('message', messageHandler);
|
|
6238
|
+
resolve({
|
|
6239
|
+
success: response.success || false,
|
|
6240
|
+
method: this.name,
|
|
6241
|
+
latency: Date.now() - start
|
|
6242
|
+
});
|
|
6243
|
+
}
|
|
6244
|
+
catch (error) {
|
|
6245
|
+
this.ws?.removeEventListener('message', messageHandler);
|
|
6246
|
+
reject(new Error('Failed to parse WebSocket response'));
|
|
6247
|
+
}
|
|
6248
|
+
};
|
|
6249
|
+
this.ws?.addEventListener('message', messageHandler);
|
|
6250
|
+
// Send the tracking data
|
|
6251
|
+
this.ws?.send(JSON.stringify({
|
|
6252
|
+
eventId: data.eventId || crypto.randomUUID(),
|
|
6253
|
+
sessionId: data.sessionId || data.s,
|
|
6254
|
+
eventType: data.eventType || data.type || 'websocket_event',
|
|
6255
|
+
eventName: data.eventName || data.name,
|
|
6256
|
+
url: data.url,
|
|
6257
|
+
userAgent: data.userAgent || navigator.userAgent,
|
|
6258
|
+
timestamp: new Date().toISOString()
|
|
6259
|
+
}));
|
|
6260
|
+
// Timeout after 5 seconds
|
|
6261
|
+
setTimeout(() => {
|
|
6262
|
+
this.ws?.removeEventListener('message', messageHandler);
|
|
6263
|
+
reject(new Error('WebSocket response timeout'));
|
|
6264
|
+
}, 5000);
|
|
6265
|
+
});
|
|
6266
|
+
}
|
|
6267
|
+
catch (error) {
|
|
6268
|
+
return {
|
|
6269
|
+
success: false,
|
|
6270
|
+
method: this.name,
|
|
6271
|
+
latency: Date.now() - start,
|
|
6272
|
+
error: error instanceof Error ? error.message : String(error)
|
|
6273
|
+
};
|
|
6274
|
+
}
|
|
6275
|
+
}
|
|
6276
|
+
async connect() {
|
|
6277
|
+
if (this.connected && this.ws?.readyState === WebSocket.OPEN) {
|
|
6278
|
+
return;
|
|
6279
|
+
}
|
|
6280
|
+
return new Promise((resolve, reject) => {
|
|
6281
|
+
try {
|
|
6282
|
+
// Convert HTTP/HTTPS to WS/WSS
|
|
6283
|
+
const url = new URL(this.baseUrl);
|
|
6284
|
+
const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
6285
|
+
const wsUrl = `${protocol}//${url.host}/ws/track?token=${encodeURIComponent(this.token)}`;
|
|
6286
|
+
this.ws = new WebSocket(wsUrl);
|
|
6287
|
+
this.ws.onopen = () => {
|
|
6288
|
+
this.connected = true;
|
|
6289
|
+
resolve();
|
|
6290
|
+
};
|
|
6291
|
+
this.ws.onerror = () => {
|
|
6292
|
+
this.connected = false;
|
|
6293
|
+
reject(new Error('WebSocket connection failed'));
|
|
6294
|
+
};
|
|
6295
|
+
this.ws.onclose = () => {
|
|
6296
|
+
this.connected = false;
|
|
6297
|
+
};
|
|
6298
|
+
// Timeout after 5 seconds
|
|
6299
|
+
setTimeout(() => {
|
|
6300
|
+
if (!this.connected) {
|
|
6301
|
+
this.ws?.close();
|
|
6302
|
+
reject(new Error('WebSocket connection timeout'));
|
|
6303
|
+
}
|
|
6304
|
+
}, 5000);
|
|
6305
|
+
}
|
|
6306
|
+
catch (error) {
|
|
6307
|
+
reject(error);
|
|
6308
|
+
}
|
|
6309
|
+
});
|
|
6310
|
+
}
|
|
6311
|
+
cleanup() {
|
|
6312
|
+
if (this.ws) {
|
|
6313
|
+
this.ws.close();
|
|
6314
|
+
this.connected = false;
|
|
6315
|
+
}
|
|
6316
|
+
}
|
|
6317
|
+
}
|
|
6318
6318
|
/**
|
|
6319
6319
|
* Socket.io Transport (Real-time bidirectional communication for anti-adblock)
|
|
6320
6320
|
*/
|
|
@@ -6325,7 +6325,7 @@ class SocketIOTransport {
|
|
|
6325
6325
|
this.connected = false;
|
|
6326
6326
|
this.baseUrl = baseUrl;
|
|
6327
6327
|
}
|
|
6328
|
-
async send(data,
|
|
6328
|
+
async send(data, _endpoint) {
|
|
6329
6329
|
const start = Date.now();
|
|
6330
6330
|
if (!this.available) {
|
|
6331
6331
|
return { success: false, method: this.name, error: 'WebRTC not available' };
|
|
@@ -6376,12 +6376,14 @@ class SocketIOTransport {
|
|
|
6376
6376
|
try {
|
|
6377
6377
|
// Use dynamic import to load socket.io-client only when needed
|
|
6378
6378
|
Promise.resolve().then(function () { return index; }).then(({ io }) => {
|
|
6379
|
-
// Extract domain from baseUrl -
|
|
6379
|
+
// Extract domain from baseUrl - preserve protocol (HTTP/HTTPS)
|
|
6380
6380
|
const url = new URL(this.baseUrl);
|
|
6381
|
-
const socketUrl =
|
|
6381
|
+
const socketUrl = `${url.protocol}//${url.host}`;
|
|
6382
6382
|
this.socket = io(socketUrl, {
|
|
6383
|
-
transports: ['
|
|
6384
|
-
timeout: 5000
|
|
6383
|
+
transports: ['polling', 'websocket'], // Try polling first for better proxy compatibility
|
|
6384
|
+
timeout: 5000,
|
|
6385
|
+
upgrade: true,
|
|
6386
|
+
rememberUpgrade: false
|
|
6385
6387
|
});
|
|
6386
6388
|
this.socket.on('connect', () => {
|
|
6387
6389
|
this.connected = true;
|
|
@@ -6416,7 +6418,7 @@ class WebRTCTransport {
|
|
|
6416
6418
|
this.available = typeof globalThis.RTCPeerConnection !== 'undefined';
|
|
6417
6419
|
this.connected = false;
|
|
6418
6420
|
}
|
|
6419
|
-
async send(data,
|
|
6421
|
+
async send(data, _endpoint) {
|
|
6420
6422
|
const start = Date.now();
|
|
6421
6423
|
if (!this.available) {
|
|
6422
6424
|
return { success: false, method: this.name, error: 'WebRTC not available' };
|
|
@@ -6488,7 +6490,7 @@ class WebRTCTransport {
|
|
|
6488
6490
|
* Main Anti-Adblock Manager
|
|
6489
6491
|
*/
|
|
6490
6492
|
class AntiAdblockManager {
|
|
6491
|
-
constructor(baseUrl, config = {}) {
|
|
6493
|
+
constructor(baseUrl, token, config = {}) {
|
|
6492
6494
|
this.transports = [];
|
|
6493
6495
|
this.stats = {
|
|
6494
6496
|
totalRequests: 0,
|
|
@@ -6497,9 +6499,10 @@ class AntiAdblockManager {
|
|
|
6497
6499
|
methodFailures: new Map()
|
|
6498
6500
|
};
|
|
6499
6501
|
this.baseUrl = baseUrl;
|
|
6502
|
+
this.token = token;
|
|
6500
6503
|
this.config = {
|
|
6501
6504
|
enabled: true,
|
|
6502
|
-
methods: ['
|
|
6505
|
+
methods: ['elysia-websocket', 'fetch', 'resource'], // Elysia WebSocket as primary
|
|
6503
6506
|
fallbackDelay: 100,
|
|
6504
6507
|
maxRetries: 2,
|
|
6505
6508
|
debug: false,
|
|
@@ -6509,9 +6512,9 @@ class AntiAdblockManager {
|
|
|
6509
6512
|
}
|
|
6510
6513
|
initializeTransports() {
|
|
6511
6514
|
const transportMap = {
|
|
6515
|
+
'elysia-websocket': () => new ElysiaWebSocketTransport(this.baseUrl, this.token),
|
|
6512
6516
|
socketio: () => new SocketIOTransport(this.baseUrl),
|
|
6513
6517
|
fetch: () => new FetchTransport(),
|
|
6514
|
-
websocket: () => new WebSocketTransport(this.baseUrl),
|
|
6515
6518
|
resource: () => new ResourceSpoofTransport(this.baseUrl),
|
|
6516
6519
|
webrtc: () => new WebRTCTransport()
|
|
6517
6520
|
};
|
|
@@ -7755,9 +7758,10 @@ class ZaplierSDK {
|
|
|
7755
7758
|
*/
|
|
7756
7759
|
initializeAntiAdblock() {
|
|
7757
7760
|
try {
|
|
7758
|
-
this.antiAdblockManager = new AntiAdblockManager(this.config.apiEndpoint,
|
|
7761
|
+
this.antiAdblockManager = new AntiAdblockManager(this.config.apiEndpoint, this.config.token, // Pass token to anti-adblock manager
|
|
7762
|
+
{
|
|
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,
|