@blotoutio/edgetag-sdk-js 0.10.4-beta.1 → 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.
Files changed (3) hide show
  1. package/index.cjs +8 -68
  2. package/index.esm.js +8 -50
  3. 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,6 +296,7 @@ const allowProviderWithConsent = (providers, providerId) => {
314
296
  const tagStorage = 'edgeTag';
315
297
  const consentKey = 'consent';
316
298
  const keyPrefix = `_worker`;
299
+ const cookieKey = 'tag_user_id';
317
300
 
318
301
  const initKey = `${keyPrefix}Store`;
319
302
  const saveDataPerKey = (persistType, provider, value, key) => {
@@ -492,17 +475,12 @@ const handleGetUserId = () => {
492
475
  if (initUserId) {
493
476
  return initUserId;
494
477
  }
495
- return getCookieValue('tag_user_id');
478
+ return getCookieValue(cookieKey);
496
479
  };
497
480
  const setUserId = (userId) => {
498
481
  initUserId = userId;
499
482
  };
500
483
 
501
- const getHeaders = () => ({
502
- 'Content-type': 'application/json; charset=utf-8',
503
- Accept: 'application/json; charset=utf-8',
504
- EdgeTagUserId: handleGetUserId(),
505
- });
506
484
  const beacon = (url, payload) => {
507
485
  try {
508
486
  let blob;
@@ -515,52 +493,14 @@ const beacon = (url, payload) => {
515
493
  return Promise.reject(new Error('Beacon not supported.'));
516
494
  }
517
495
  };
518
- const fallbackAjax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
519
- const https = yield Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('https')); });
520
- const options = {
521
- method,
522
- headers: getHeaders(),
523
- };
524
- return new Promise((resolve, reject) => {
525
- const req = https.request(url, options, (res) => {
526
- res.on('data', (data) => {
527
- try {
528
- data = JSON.parse(data);
529
- }
530
- catch (_a) {
531
- // do nothing
532
- }
533
- resolve({
534
- body: data,
535
- status: res.statusCode || 500,
536
- });
537
- });
538
- });
539
- req.on('error', (e) => {
540
- reject(new Error(e.message));
541
- });
542
- if (payload && method !== 'GET') {
543
- req.write(JSON.stringify(payload));
544
- }
545
- req.end();
546
- });
547
- });
548
496
  const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
549
- if (typeof fetch === 'undefined') {
550
- return yield fallbackAjax(method, url, payload)
551
- .then((data) => {
552
- if (data.status < 200 || data.status >= 300) {
553
- return Promise.reject(new Error(`Request failed with code ${data.status} occurred: ${JSON.stringify(data.body)}`));
554
- }
555
- return Promise.resolve(data.body);
556
- })
557
- .catch((error) => {
558
- return Promise.reject(new Error(error));
559
- });
560
- }
561
497
  return yield fetch(url, {
562
498
  method,
563
- headers: getHeaders(),
499
+ headers: {
500
+ 'Content-type': 'application/json; charset=utf-8',
501
+ Accept: 'application/json; charset=utf-8',
502
+ EdgeTagUserId: handleGetUserId(),
503
+ },
564
504
  body: JSON.stringify(payload),
565
505
  credentials: 'include',
566
506
  })
@@ -576,7 +516,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
576
516
  });
577
517
  });
578
518
  const getStandardPayload = (payload) => {
579
- const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.3" }, (payload || {}));
519
+ const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.4" }, (payload || {}));
580
520
  let storage = {};
581
521
  const session = getData$1('session');
582
522
  if (session) {
package/index.esm.js CHANGED
@@ -292,6 +292,7 @@ const allowProviderWithConsent = (providers, providerId) => {
292
292
  const tagStorage = 'edgeTag';
293
293
  const consentKey = 'consent';
294
294
  const keyPrefix = `_worker`;
295
+ const cookieKey = 'tag_user_id';
295
296
 
296
297
  const initKey = `${keyPrefix}Store`;
297
298
  const saveDataPerKey = (persistType, provider, value, key) => {
@@ -470,17 +471,12 @@ const handleGetUserId = () => {
470
471
  if (initUserId) {
471
472
  return initUserId;
472
473
  }
473
- return getCookieValue('tag_user_id');
474
+ return getCookieValue(cookieKey);
474
475
  };
475
476
  const setUserId = (userId) => {
476
477
  initUserId = userId;
477
478
  };
478
479
 
479
- const getHeaders = () => ({
480
- 'Content-type': 'application/json; charset=utf-8',
481
- Accept: 'application/json; charset=utf-8',
482
- EdgeTagUserId: handleGetUserId(),
483
- });
484
480
  const beacon = (url, payload) => {
485
481
  try {
486
482
  let blob;
@@ -493,52 +489,14 @@ const beacon = (url, payload) => {
493
489
  return Promise.reject(new Error('Beacon not supported.'));
494
490
  }
495
491
  };
496
- const fallbackAjax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
497
- const https = yield import('https');
498
- const options = {
499
- method,
500
- headers: getHeaders(),
501
- };
502
- return new Promise((resolve, reject) => {
503
- const req = https.request(url, options, (res) => {
504
- res.on('data', (data) => {
505
- try {
506
- data = JSON.parse(data);
507
- }
508
- catch (_a) {
509
- // do nothing
510
- }
511
- resolve({
512
- body: data,
513
- status: res.statusCode || 500,
514
- });
515
- });
516
- });
517
- req.on('error', (e) => {
518
- reject(new Error(e.message));
519
- });
520
- if (payload && method !== 'GET') {
521
- req.write(JSON.stringify(payload));
522
- }
523
- req.end();
524
- });
525
- });
526
492
  const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, function* () {
527
- if (typeof fetch === 'undefined') {
528
- return yield fallbackAjax(method, url, payload)
529
- .then((data) => {
530
- if (data.status < 200 || data.status >= 300) {
531
- return Promise.reject(new Error(`Request failed with code ${data.status} occurred: ${JSON.stringify(data.body)}`));
532
- }
533
- return Promise.resolve(data.body);
534
- })
535
- .catch((error) => {
536
- return Promise.reject(new Error(error));
537
- });
538
- }
539
493
  return yield fetch(url, {
540
494
  method,
541
- headers: getHeaders(),
495
+ headers: {
496
+ 'Content-type': 'application/json; charset=utf-8',
497
+ Accept: 'application/json; charset=utf-8',
498
+ EdgeTagUserId: handleGetUserId(),
499
+ },
542
500
  body: JSON.stringify(payload),
543
501
  credentials: 'include',
544
502
  })
@@ -554,7 +512,7 @@ const ajax = (method, url, payload) => __awaiter(void 0, void 0, void 0, functio
554
512
  });
555
513
  });
556
514
  const getStandardPayload = (payload) => {
557
- const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.3" }, (payload || {}));
515
+ const data = Object.assign({ pageUrl: getPageUrl(), pageTitle: getPageTitle(), userAgent: getUserAgent(), referrer: getReferrer(), search: getSearch(), sdkVersion: "0.10.4" }, (payload || {}));
558
516
  let storage = {};
559
517
  const session = getData$1('session');
560
518
  if (session) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "0.10.4-beta.1",
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",