@blotoutio/edgetag-sdk-js 0.60.1 → 0.61.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.
Files changed (3) hide show
  1. package/index.cjs.js +25 -14
  2. package/index.mjs +25 -14
  3. package/package.json +1 -1
package/index.cjs.js CHANGED
@@ -468,28 +468,39 @@ const generateEventId = (name) => {
468
468
  };
469
469
 
470
470
  const getCookieValue = (key) => {
471
+ var _a;
471
472
  try {
472
473
  if (!document || !document.cookie) {
473
474
  return '';
474
475
  }
475
- const name = `${key}=`;
476
- const decodedCookie = decodeURIComponent(document.cookie);
477
- const ca = decodedCookie.split(';');
478
- for (let i = 0; i < ca.length; i++) {
479
- let c = ca[i];
480
- while (c.charAt(0) === ' ') {
481
- c = c.substring(1);
482
- }
483
- if (c.indexOf(name) === 0) {
484
- return c.substring(name.length, c.length);
485
- }
486
- }
487
- return '';
476
+ const cookies = parseCookies(document.cookie);
477
+ return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
488
478
  }
489
479
  catch {
490
480
  return '';
491
481
  }
492
482
  };
483
+ const parseCookies = (cookie) => {
484
+ return Object.fromEntries(cookie
485
+ .split(/;\s+/)
486
+ .map((r) => r.split('=').map((str) => str.trim()))
487
+ .map(([cookieKey, cookieValue]) => {
488
+ if (!cookieKey) {
489
+ return [];
490
+ }
491
+ let decodedValue = '';
492
+ if (cookieValue) {
493
+ try {
494
+ decodedValue = decodeURIComponent(cookieValue);
495
+ }
496
+ catch (e) {
497
+ console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
498
+ decodedValue = cookieValue;
499
+ }
500
+ }
501
+ return [cookieKey, decodedValue];
502
+ }));
503
+ };
493
504
 
494
505
  const getUserId$1 = (destination) => {
495
506
  const userId = getSetting(destination, 'userId');
@@ -549,7 +560,7 @@ const getStandardPayload = (destination, payload) => {
549
560
  referrer: getReferrer(destination),
550
561
  search: getSearch(destination),
551
562
  locale: getLocale(),
552
- sdkVersion: "0.60.1" ,
563
+ sdkVersion: "0.61.0" ,
553
564
  ...(payload || {}),
554
565
  };
555
566
  let storage = {};
package/index.mjs CHANGED
@@ -466,28 +466,39 @@ const generateEventId = (name) => {
466
466
  };
467
467
 
468
468
  const getCookieValue = (key) => {
469
+ var _a;
469
470
  try {
470
471
  if (!document || !document.cookie) {
471
472
  return '';
472
473
  }
473
- const name = `${key}=`;
474
- const decodedCookie = decodeURIComponent(document.cookie);
475
- const ca = decodedCookie.split(';');
476
- for (let i = 0; i < ca.length; i++) {
477
- let c = ca[i];
478
- while (c.charAt(0) === ' ') {
479
- c = c.substring(1);
480
- }
481
- if (c.indexOf(name) === 0) {
482
- return c.substring(name.length, c.length);
483
- }
484
- }
485
- return '';
474
+ const cookies = parseCookies(document.cookie);
475
+ return (_a = cookies[key]) !== null && _a !== void 0 ? _a : '';
486
476
  }
487
477
  catch {
488
478
  return '';
489
479
  }
490
480
  };
481
+ const parseCookies = (cookie) => {
482
+ return Object.fromEntries(cookie
483
+ .split(/;\s+/)
484
+ .map((r) => r.split('=').map((str) => str.trim()))
485
+ .map(([cookieKey, cookieValue]) => {
486
+ if (!cookieKey) {
487
+ return [];
488
+ }
489
+ let decodedValue = '';
490
+ if (cookieValue) {
491
+ try {
492
+ decodedValue = decodeURIComponent(cookieValue);
493
+ }
494
+ catch (e) {
495
+ console.log(`Unable to decode cookie ${cookieKey}: ${e}`);
496
+ decodedValue = cookieValue;
497
+ }
498
+ }
499
+ return [cookieKey, decodedValue];
500
+ }));
501
+ };
491
502
 
492
503
  const getUserId$1 = (destination) => {
493
504
  const userId = getSetting(destination, 'userId');
@@ -547,7 +558,7 @@ const getStandardPayload = (destination, payload) => {
547
558
  referrer: getReferrer(destination),
548
559
  search: getSearch(destination),
549
560
  locale: getLocale(),
550
- sdkVersion: "0.60.1" ,
561
+ sdkVersion: "0.61.0" ,
551
562
  ...(payload || {}),
552
563
  };
553
564
  let storage = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "0.60.1",
3
+ "version": "0.61.0",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",