@blotoutio/edgetag-sdk-js 0.10.1 → 0.10.2-beta.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/index.cjs +16 -1
- package/index.esm.js +16 -1
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -314,6 +314,8 @@ const allowProviderWithConsent = (providers, providerId) => {
|
|
|
314
314
|
const tagStorage = 'edgeTag';
|
|
315
315
|
const consentKey = 'consent';
|
|
316
316
|
const keyPrefix = `_worker`;
|
|
317
|
+
const backupCookieKey = `cookieId`;
|
|
318
|
+
const cookieKey = 'tag_user_id';
|
|
317
319
|
|
|
318
320
|
const initKey = `${keyPrefix}Store`;
|
|
319
321
|
const saveDataPerKey = (persistType, provider, value, key) => {
|
|
@@ -492,7 +494,11 @@ const handleGetUserId = () => {
|
|
|
492
494
|
if (initUserId) {
|
|
493
495
|
return initUserId;
|
|
494
496
|
}
|
|
495
|
-
|
|
497
|
+
const data = getDataPerKey('local', tagStorage, backupCookieKey);
|
|
498
|
+
if (!data || data.length < 10) {
|
|
499
|
+
return getCookieValue('tag_user_id');
|
|
500
|
+
}
|
|
501
|
+
return data;
|
|
496
502
|
};
|
|
497
503
|
const setUserId = (userId) => {
|
|
498
504
|
initUserId = userId;
|
|
@@ -503,6 +509,13 @@ const getHeaders = () => ({
|
|
|
503
509
|
Accept: 'application/json; charset=utf-8',
|
|
504
510
|
EdgeTagUserId: handleGetUserId(),
|
|
505
511
|
});
|
|
512
|
+
const cookieIdFallback = () => {
|
|
513
|
+
const data = getDataPerKey('local', tagStorage, backupCookieKey);
|
|
514
|
+
if (data) {
|
|
515
|
+
return;
|
|
516
|
+
}
|
|
517
|
+
savePerKey('local', tagStorage, getCookieValue(cookieKey), backupCookieKey);
|
|
518
|
+
};
|
|
506
519
|
const beacon = (url, payload) => {
|
|
507
520
|
try {
|
|
508
521
|
let blob;
|
|
@@ -524,6 +537,7 @@ const fallbackAjax = (method, url, payload) => __awaiter(void 0, void 0, void 0,
|
|
|
524
537
|
return new Promise((resolve, reject) => {
|
|
525
538
|
const req = https.request(url, options, (res) => {
|
|
526
539
|
res.on('data', (data) => {
|
|
540
|
+
cookieIdFallback();
|
|
527
541
|
try {
|
|
528
542
|
data = JSON.parse(data);
|
|
529
543
|
}
|
|
@@ -569,6 +583,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
569
583
|
if (data.status < 200 || data.status >= 300) {
|
|
570
584
|
return Promise.reject(new Error(`Request failed with code ${data.status}: ${JSON.stringify(data.body)}`));
|
|
571
585
|
}
|
|
586
|
+
cookieIdFallback();
|
|
572
587
|
return Promise.resolve(data.body);
|
|
573
588
|
})
|
|
574
589
|
.catch((error) => {
|
package/index.esm.js
CHANGED
|
@@ -292,6 +292,8 @@ const allowProviderWithConsent = (providers, providerId) => {
|
|
|
292
292
|
const tagStorage = 'edgeTag';
|
|
293
293
|
const consentKey = 'consent';
|
|
294
294
|
const keyPrefix = `_worker`;
|
|
295
|
+
const backupCookieKey = `cookieId`;
|
|
296
|
+
const cookieKey = 'tag_user_id';
|
|
295
297
|
|
|
296
298
|
const initKey = `${keyPrefix}Store`;
|
|
297
299
|
const saveDataPerKey = (persistType, provider, value, key) => {
|
|
@@ -470,7 +472,11 @@ const handleGetUserId = () => {
|
|
|
470
472
|
if (initUserId) {
|
|
471
473
|
return initUserId;
|
|
472
474
|
}
|
|
473
|
-
|
|
475
|
+
const data = getDataPerKey('local', tagStorage, backupCookieKey);
|
|
476
|
+
if (!data || data.length < 10) {
|
|
477
|
+
return getCookieValue('tag_user_id');
|
|
478
|
+
}
|
|
479
|
+
return data;
|
|
474
480
|
};
|
|
475
481
|
const setUserId = (userId) => {
|
|
476
482
|
initUserId = userId;
|
|
@@ -481,6 +487,13 @@ const getHeaders = () => ({
|
|
|
481
487
|
Accept: 'application/json; charset=utf-8',
|
|
482
488
|
EdgeTagUserId: handleGetUserId(),
|
|
483
489
|
});
|
|
490
|
+
const cookieIdFallback = () => {
|
|
491
|
+
const data = getDataPerKey('local', tagStorage, backupCookieKey);
|
|
492
|
+
if (data) {
|
|
493
|
+
return;
|
|
494
|
+
}
|
|
495
|
+
savePerKey('local', tagStorage, getCookieValue(cookieKey), backupCookieKey);
|
|
496
|
+
};
|
|
484
497
|
const beacon = (url, payload) => {
|
|
485
498
|
try {
|
|
486
499
|
let blob;
|
|
@@ -502,6 +515,7 @@ const fallbackAjax = (method, url, payload) => __awaiter(void 0, void 0, void 0,
|
|
|
502
515
|
return new Promise((resolve, reject) => {
|
|
503
516
|
const req = https.request(url, options, (res) => {
|
|
504
517
|
res.on('data', (data) => {
|
|
518
|
+
cookieIdFallback();
|
|
505
519
|
try {
|
|
506
520
|
data = JSON.parse(data);
|
|
507
521
|
}
|
|
@@ -547,6 +561,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
547
561
|
if (data.status < 200 || data.status >= 300) {
|
|
548
562
|
return Promise.reject(new Error(`Request failed with code ${data.status}: ${JSON.stringify(data.body)}`));
|
|
549
563
|
}
|
|
564
|
+
cookieIdFallback();
|
|
550
565
|
return Promise.resolve(data.body);
|
|
551
566
|
})
|
|
552
567
|
.catch((error) => {
|