@blotoutio/edgetag-sdk-js 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.cjs +7 -82
- package/index.esm.js +7 -64
- package/package.json +4 -1
package/index.cjs
CHANGED
|
@@ -2,24 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function _interopNamespace(e) {
|
|
6
|
-
if (e && e.__esModule) return e;
|
|
7
|
-
var n = Object.create(null);
|
|
8
|
-
if (e) {
|
|
9
|
-
Object.keys(e).forEach(function (k) {
|
|
10
|
-
if (k !== 'default') {
|
|
11
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () { return e[k]; }
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
n["default"] = e;
|
|
20
|
-
return Object.freeze(n);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
5
|
var api = /*#__PURE__*/Object.freeze({
|
|
24
6
|
__proto__: null,
|
|
25
7
|
get init () { return init; },
|
|
@@ -314,7 +296,6 @@ const allowProviderWithConsent = (providers, providerId) => {
|
|
|
314
296
|
const tagStorage = 'edgeTag';
|
|
315
297
|
const consentKey = 'consent';
|
|
316
298
|
const keyPrefix = `_worker`;
|
|
317
|
-
const backupCookieKey = `cookieId`;
|
|
318
299
|
const cookieKey = 'tag_user_id';
|
|
319
300
|
|
|
320
301
|
const initKey = `${keyPrefix}Store`;
|
|
@@ -494,28 +475,12 @@ const handleGetUserId = () => {
|
|
|
494
475
|
if (initUserId) {
|
|
495
476
|
return initUserId;
|
|
496
477
|
}
|
|
497
|
-
|
|
498
|
-
if (!data || data.length < 10) {
|
|
499
|
-
return getCookieValue(cookieKey);
|
|
500
|
-
}
|
|
501
|
-
return data;
|
|
478
|
+
return getCookieValue(cookieKey);
|
|
502
479
|
};
|
|
503
480
|
const setUserId = (userId) => {
|
|
504
481
|
initUserId = userId;
|
|
505
482
|
};
|
|
506
483
|
|
|
507
|
-
const getHeaders = () => ({
|
|
508
|
-
'Content-type': 'application/json; charset=utf-8',
|
|
509
|
-
Accept: 'application/json; charset=utf-8',
|
|
510
|
-
EdgeTagUserId: handleGetUserId(),
|
|
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
|
-
};
|
|
519
484
|
const beacon = (url, payload) => {
|
|
520
485
|
try {
|
|
521
486
|
let blob;
|
|
@@ -528,53 +493,14 @@ const beacon = (url, payload) => {
|
|
|
528
493
|
return Promise.reject(new Error('Beacon not supported.'));
|
|
529
494
|
}
|
|
530
495
|
};
|
|
531
|
-
const fallbackAjax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
532
|
-
const https = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('https')); });
|
|
533
|
-
const options = {
|
|
534
|
-
method,
|
|
535
|
-
headers: getHeaders(),
|
|
536
|
-
};
|
|
537
|
-
return new Promise((resolve, reject) => {
|
|
538
|
-
const req = https.request(url, options, (res) => {
|
|
539
|
-
res.on('data', (data) => {
|
|
540
|
-
cookieIdFallback();
|
|
541
|
-
try {
|
|
542
|
-
data = JSON.parse(data);
|
|
543
|
-
}
|
|
544
|
-
catch (_a) {
|
|
545
|
-
// do nothing
|
|
546
|
-
}
|
|
547
|
-
resolve({
|
|
548
|
-
body: data,
|
|
549
|
-
status: res.statusCode || 500,
|
|
550
|
-
});
|
|
551
|
-
});
|
|
552
|
-
});
|
|
553
|
-
req.on('error', (e) => {
|
|
554
|
-
reject(new Error(e.message));
|
|
555
|
-
});
|
|
556
|
-
if (payload && method !== 'GET') {
|
|
557
|
-
req.write(JSON.stringify(payload));
|
|
558
|
-
}
|
|
559
|
-
req.end();
|
|
560
|
-
});
|
|
561
|
-
});
|
|
562
496
|
const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
563
|
-
if (typeof fetch === 'undefined') {
|
|
564
|
-
return yield fallbackAjax(method, url, payload)
|
|
565
|
-
.then((data) => {
|
|
566
|
-
if (data.status < 200 || data.status >= 300) {
|
|
567
|
-
return Promise.reject(new Error(`Request failed with code ${data.status} occurred: ${JSON.stringify(data.body)}`));
|
|
568
|
-
}
|
|
569
|
-
return Promise.resolve(data.body);
|
|
570
|
-
})
|
|
571
|
-
.catch((error) => {
|
|
572
|
-
return Promise.reject(new Error(error));
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
497
|
return yield fetch(url, {
|
|
576
498
|
method,
|
|
577
|
-
headers:
|
|
499
|
+
headers: {
|
|
500
|
+
'Content-type': 'application/json; charset=utf-8',
|
|
501
|
+
Accept: 'application/json; charset=utf-8',
|
|
502
|
+
EdgeTagUserId: handleGetUserId(),
|
|
503
|
+
},
|
|
578
504
|
body: JSON.stringify(payload),
|
|
579
505
|
credentials: 'include',
|
|
580
506
|
})
|
|
@@ -583,7 +509,6 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
583
509
|
if (data.status < 200 || data.status >= 300) {
|
|
584
510
|
return Promise.reject(new Error(`Request failed with code ${data.status}: ${JSON.stringify(data.body)}`));
|
|
585
511
|
}
|
|
586
|
-
cookieIdFallback();
|
|
587
512
|
return Promise.resolve(data.body);
|
|
588
513
|
})
|
|
589
514
|
.catch((error) => {
|
|
@@ -591,7 +516,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
591
516
|
});
|
|
592
517
|
});
|
|
593
518
|
const getStandardPayload = (payload) => {
|
|
594
|
-
const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.
|
|
519
|
+
const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.4" }, (payload || {}));
|
|
595
520
|
let storage = {};
|
|
596
521
|
const session = getData$1('session');
|
|
597
522
|
if (session) {
|
package/index.esm.js
CHANGED
|
@@ -292,7 +292,6 @@ const allowProviderWithConsent = (providers, providerId) => {
|
|
|
292
292
|
const tagStorage = 'edgeTag';
|
|
293
293
|
const consentKey = 'consent';
|
|
294
294
|
const keyPrefix = `_worker`;
|
|
295
|
-
const backupCookieKey = `cookieId`;
|
|
296
295
|
const cookieKey = 'tag_user_id';
|
|
297
296
|
|
|
298
297
|
const initKey = `${keyPrefix}Store`;
|
|
@@ -472,28 +471,12 @@ const handleGetUserId = () => {
|
|
|
472
471
|
if (initUserId) {
|
|
473
472
|
return initUserId;
|
|
474
473
|
}
|
|
475
|
-
|
|
476
|
-
if (!data || data.length < 10) {
|
|
477
|
-
return getCookieValue(cookieKey);
|
|
478
|
-
}
|
|
479
|
-
return data;
|
|
474
|
+
return getCookieValue(cookieKey);
|
|
480
475
|
};
|
|
481
476
|
const setUserId = (userId) => {
|
|
482
477
|
initUserId = userId;
|
|
483
478
|
};
|
|
484
479
|
|
|
485
|
-
const getHeaders = () => ({
|
|
486
|
-
'Content-type': 'application/json; charset=utf-8',
|
|
487
|
-
Accept: 'application/json; charset=utf-8',
|
|
488
|
-
EdgeTagUserId: handleGetUserId(),
|
|
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
|
-
};
|
|
497
480
|
const beacon = (url, payload) => {
|
|
498
481
|
try {
|
|
499
482
|
let blob;
|
|
@@ -506,53 +489,14 @@ const beacon = (url, payload) => {
|
|
|
506
489
|
return Promise.reject(new Error('Beacon not supported.'));
|
|
507
490
|
}
|
|
508
491
|
};
|
|
509
|
-
const fallbackAjax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
510
|
-
const https = yield import('https');
|
|
511
|
-
const options = {
|
|
512
|
-
method,
|
|
513
|
-
headers: getHeaders(),
|
|
514
|
-
};
|
|
515
|
-
return new Promise((resolve, reject) => {
|
|
516
|
-
const req = https.request(url, options, (res) => {
|
|
517
|
-
res.on('data', (data) => {
|
|
518
|
-
cookieIdFallback();
|
|
519
|
-
try {
|
|
520
|
-
data = JSON.parse(data);
|
|
521
|
-
}
|
|
522
|
-
catch (_a) {
|
|
523
|
-
// do nothing
|
|
524
|
-
}
|
|
525
|
-
resolve({
|
|
526
|
-
body: data,
|
|
527
|
-
status: res.statusCode || 500,
|
|
528
|
-
});
|
|
529
|
-
});
|
|
530
|
-
});
|
|
531
|
-
req.on('error', (e) => {
|
|
532
|
-
reject(new Error(e.message));
|
|
533
|
-
});
|
|
534
|
-
if (payload && method !== 'GET') {
|
|
535
|
-
req.write(JSON.stringify(payload));
|
|
536
|
-
}
|
|
537
|
-
req.end();
|
|
538
|
-
});
|
|
539
|
-
});
|
|
540
492
|
const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
|
|
541
|
-
if (typeof fetch === 'undefined') {
|
|
542
|
-
return yield fallbackAjax(method, url, payload)
|
|
543
|
-
.then((data) => {
|
|
544
|
-
if (data.status < 200 || data.status >= 300) {
|
|
545
|
-
return Promise.reject(new Error(`Request failed with code ${data.status} occurred: ${JSON.stringify(data.body)}`));
|
|
546
|
-
}
|
|
547
|
-
return Promise.resolve(data.body);
|
|
548
|
-
})
|
|
549
|
-
.catch((error) => {
|
|
550
|
-
return Promise.reject(new Error(error));
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
493
|
return yield fetch(url, {
|
|
554
494
|
method,
|
|
555
|
-
headers:
|
|
495
|
+
headers: {
|
|
496
|
+
'Content-type': 'application/json; charset=utf-8',
|
|
497
|
+
Accept: 'application/json; charset=utf-8',
|
|
498
|
+
EdgeTagUserId: handleGetUserId(),
|
|
499
|
+
},
|
|
556
500
|
body: JSON.stringify(payload),
|
|
557
501
|
credentials: 'include',
|
|
558
502
|
})
|
|
@@ -561,7 +505,6 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
561
505
|
if (data.status < 200 || data.status >= 300) {
|
|
562
506
|
return Promise.reject(new Error(`Request failed with code ${data.status}: ${JSON.stringify(data.body)}`));
|
|
563
507
|
}
|
|
564
|
-
cookieIdFallback();
|
|
565
508
|
return Promise.resolve(data.body);
|
|
566
509
|
})
|
|
567
510
|
.catch((error) => {
|
|
@@ -569,7 +512,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
|
|
|
569
512
|
});
|
|
570
513
|
});
|
|
571
514
|
const getStandardPayload = (payload) => {
|
|
572
|
-
const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.
|
|
515
|
+
const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.4" }, (payload || {}));
|
|
573
516
|
let storage = {};
|
|
574
517
|
const session = getData$1('session');
|
|
575
518
|
if (session) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blotoutio/edgetag-sdk-js",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "JS SDK for EdgeTag",
|
|
5
5
|
"author": "Blotout",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "git+https://github.com/blotoutio/edgetag-sdk.git"
|
|
15
15
|
},
|
|
16
|
+
"engines": {
|
|
17
|
+
"node": ">=17.5.0"
|
|
18
|
+
},
|
|
16
19
|
"files": [
|
|
17
20
|
"index.cjs",
|
|
18
21
|
"index.d.ts",
|