@blotoutio/edgetag-sdk-browser 0.10.3 → 0.10.4
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/index.js +7 -64
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -295,7 +295,6 @@
|
|
|
295
295
|
const tagStorage = 'edgeTag';
|
|
296
296
|
const consentKey = 'consent';
|
|
297
297
|
const keyPrefix = `_worker`;
|
|
298
|
-
const backupCookieKey = `cookieId`;
|
|
299
298
|
const cookieKey = 'tag_user_id';
|
|
300
299
|
|
|
301
300
|
const initKey = `${keyPrefix}Store`;
|
|
@@ -475,28 +474,12 @@
|
|
|
475
474
|
if (initUserId) {
|
|
476
475
|
return initUserId;
|
|
477
476
|
}
|
|
478
|
-
|
|
479
|
-
if (!data || data.length < 10) {
|
|
480
|
-
return getCookieValue(cookieKey);
|
|
481
|
-
}
|
|
482
|
-
return data;
|
|
477
|
+
return getCookieValue(cookieKey);
|
|
483
478
|
};
|
|
484
479
|
const setUserId = (userId) => {
|
|
485
480
|
initUserId = userId;
|
|
486
481
|
};
|
|
487
482
|
|
|
488
|
-
const getHeaders = () => ({
|
|
489
|
-
'Content-type': 'application/json; charset=utf-8',
|
|
490
|
-
Accept: 'application/json; charset=utf-8',
|
|
491
|
-
EdgeTagUserId: handleGetUserId(),
|
|
492
|
-
});
|
|
493
|
-
const cookieIdFallback = () => {
|
|
494
|
-
const data = getDataPerKey('local', tagStorage, backupCookieKey);
|
|
495
|
-
if (data) {
|
|
496
|
-
return;
|
|
497
|
-
}
|
|
498
|
-
savePerKey('local', tagStorage, getCookieValue(cookieKey), backupCookieKey);
|
|
499
|
-
};
|
|
500
483
|
const beacon = (url, payload) => {
|
|
501
484
|
try {
|
|
502
485
|
let blob;
|
|
@@ -509,53 +492,14 @@
|
|
|
509
492
|
return Promise.reject(new Error('Beacon not supported.'));
|
|
510
493
|
}
|
|
511
494
|
};
|
|
512
|
-
const fallbackAjax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
513
|
-
const https = yield import('https');
|
|
514
|
-
const options = {
|
|
515
|
-
method,
|
|
516
|
-
headers: getHeaders(),
|
|
517
|
-
};
|
|
518
|
-
return new Promise((resolve, reject) => {
|
|
519
|
-
const req = https.request(url, options, (res) => {
|
|
520
|
-
res.on('data', (data) => {
|
|
521
|
-
cookieIdFallback();
|
|
522
|
-
try {
|
|
523
|
-
data = JSON.parse(data);
|
|
524
|
-
}
|
|
525
|
-
catch (_a) {
|
|
526
|
-
// do nothing
|
|
527
|
-
}
|
|
528
|
-
resolve({
|
|
529
|
-
body: data,
|
|
530
|
-
status: res.statusCode || 500,
|
|
531
|
-
});
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
req.on('error', (e) => {
|
|
535
|
-
reject(new Error(e.message));
|
|
536
|
-
});
|
|
537
|
-
if (payload && method !== 'GET') {
|
|
538
|
-
req.write(JSON.stringify(payload));
|
|
539
|
-
}
|
|
540
|
-
req.end();
|
|
541
|
-
});
|
|
542
|
-
});
|
|
543
495
|
const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
544
|
-
if (typeof fetch === 'undefined') {
|
|
545
|
-
return yield fallbackAjax(method, url, payload)
|
|
546
|
-
.then((data) => {
|
|
547
|
-
if (data.status < 200 || data.status >= 300) {
|
|
548
|
-
return Promise.reject(new Error(`Request failed with code ${data.status} occurred: ${JSON.stringify(data.body)}`));
|
|
549
|
-
}
|
|
550
|
-
return Promise.resolve(data.body);
|
|
551
|
-
})
|
|
552
|
-
.catch((error) => {
|
|
553
|
-
return Promise.reject(new Error(error));
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
496
|
return yield fetch(url, {
|
|
557
497
|
method,
|
|
558
|
-
headers:
|
|
498
|
+
headers: {
|
|
499
|
+
'Content-type': 'application/json; charset=utf-8',
|
|
500
|
+
Accept: 'application/json; charset=utf-8',
|
|
501
|
+
EdgeTagUserId: handleGetUserId(),
|
|
502
|
+
},
|
|
559
503
|
body: JSON.stringify(payload),
|
|
560
504
|
credentials: 'include',
|
|
561
505
|
})
|
|
@@ -564,7 +508,6 @@
|
|
|
564
508
|
if (data.status < 200 || data.status >= 300) {
|
|
565
509
|
return Promise.reject(new Error(`Request failed with code ${data.status}: ${JSON.stringify(data.body)}`));
|
|
566
510
|
}
|
|
567
|
-
cookieIdFallback();
|
|
568
511
|
return Promise.resolve(data.body);
|
|
569
512
|
})
|
|
570
513
|
.catch((error) => {
|
|
@@ -572,7 +515,7 @@
|
|
|
572
515
|
});
|
|
573
516
|
});
|
|
574
517
|
const getStandardPayload = (payload) => {
|
|
575
|
-
const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.
|
|
518
|
+
const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.4" }, (payload || {}));
|
|
576
519
|
let storage = {};
|
|
577
520
|
const session = getData$1('session');
|
|
578
521
|
if (session) {
|