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