@blotoutio/edgetag-sdk-js 1.36.0 → 1.36.2

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 +26 -7
  2. package/index.mjs +26 -7
  3. package/package.json +1 -1
package/index.cjs.js CHANGED
@@ -131,6 +131,18 @@ new Set([
131
131
  ...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
132
132
  ]);
133
133
 
134
+ function tryParse(json, fallbackValue) {
135
+ try {
136
+ if (json) {
137
+ return JSON.parse(json);
138
+ }
139
+ }
140
+ catch {
141
+ /* do nothing */
142
+ }
143
+ return fallbackValue;
144
+ }
145
+
134
146
  const isZeroPurchaseEvent = (payload) => {
135
147
  var _a;
136
148
  if (payload.eventName != 'Purchase') {
@@ -808,6 +820,13 @@ const evaluateEventRules = (rules, payload, providers, userData = {}) => {
808
820
  };
809
821
  };
810
822
 
823
+ /** This function will create a deep copy using JSON stringify/parse
824
+ * that will also remove all methods from the incoming objects. Use
825
+ * this function when cloning user-provided objects since structuredClone
826
+ * will throw an error if given an object with functions.
827
+ */
828
+ const jsonClone = (json) => tryParse(JSON.stringify(json), undefined);
829
+
811
830
  // eslint-disable-next-line @nx/enforce-module-boundaries
812
831
  const getGlobalSettings = () => {
813
832
  var _a;
@@ -1264,7 +1283,7 @@ const getStandardPayload = (destination, payload) => {
1264
1283
  referrer: getReferrer(destination),
1265
1284
  search: getSearch(destination),
1266
1285
  locale: getLocale(),
1267
- sdkVersion: "1.36.0" ,
1286
+ sdkVersion: "1.36.2" ,
1268
1287
  ...(payload || {}),
1269
1288
  };
1270
1289
  let storage = {};
@@ -1482,11 +1501,11 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
1482
1501
  if (skipZeroPurchaseEvent && isZeroPurchaseEvent({ eventName, data })) {
1483
1502
  return;
1484
1503
  }
1485
- const originalData = structuredClone(data);
1486
- const originalProviders = structuredClone(providers);
1504
+ const originalData = jsonClone(data);
1505
+ const originalProviders = jsonClone(providers);
1487
1506
  const rules = (getSetting(destination, 'configuratorSetting') ||
1488
1507
  []);
1489
- const rulesResult = evaluateEventRules(rules, structuredClone({ eventName, data }), providers !== null && providers !== void 0 ? providers : undefined, userProperties || {});
1508
+ const rulesResult = evaluateEventRules(rules, jsonClone({ eventName, data }), providers !== null && providers !== void 0 ? providers : undefined, userProperties || {});
1490
1509
  if (!rulesResult.skipEvent) {
1491
1510
  if (rulesResult.updatedPayload) {
1492
1511
  // eslint-disable-next-line no-param-reassign
@@ -1497,7 +1516,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
1497
1516
  providers = rulesResult.updatedProviders;
1498
1517
  }
1499
1518
  if (!rulesResult.skipBrowserEvent) {
1500
- const conversion = preparePayloadWithConversion(JSON.parse(JSON.stringify(data)), getSetting(destination, 'currency'));
1519
+ const conversion = preparePayloadWithConversion(jsonClone(data), getSetting(destination, 'currency'));
1501
1520
  for (const pkg of providerPackages) {
1502
1521
  if (!pkg || !pkg.name || !pkg.tag) {
1503
1522
  continue;
@@ -1531,7 +1550,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
1531
1550
  sessionId,
1532
1551
  eventName,
1533
1552
  eventId,
1534
- data: JSON.parse(JSON.stringify(payload)),
1553
+ data: jsonClone(payload),
1535
1554
  sendTag: sendTag.bind(null, destination),
1536
1555
  getEdgeData: processGetData.bind(null, destination),
1537
1556
  manifestVariables: variable.variableSet,
@@ -1563,7 +1582,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
1563
1582
  }
1564
1583
  const additionalEvents = rulesResult.additionalEvents || [];
1565
1584
  for (const additionalEventName of additionalEvents) {
1566
- handleTag(additionalEventName, structuredClone(originalData || {}), originalProviders, options);
1585
+ handleTag(additionalEventName, jsonClone(originalData || {}), originalProviders, options);
1567
1586
  }
1568
1587
  };
1569
1588
  const handleTag = (eventName, data = {}, providers, options) => {
package/index.mjs CHANGED
@@ -129,6 +129,18 @@ new Set([
129
129
  ...expand('911,921,922,923,924,926,927,932,933,935,942,944,946,950,953,955,957-958,960-969,974,975,976,977,981-982,987,988,990-999'),
130
130
  ]);
131
131
 
132
+ function tryParse(json, fallbackValue) {
133
+ try {
134
+ if (json) {
135
+ return JSON.parse(json);
136
+ }
137
+ }
138
+ catch {
139
+ /* do nothing */
140
+ }
141
+ return fallbackValue;
142
+ }
143
+
132
144
  const isZeroPurchaseEvent = (payload) => {
133
145
  var _a;
134
146
  if (payload.eventName != 'Purchase') {
@@ -806,6 +818,13 @@ const evaluateEventRules = (rules, payload, providers, userData = {}) => {
806
818
  };
807
819
  };
808
820
 
821
+ /** This function will create a deep copy using JSON stringify/parse
822
+ * that will also remove all methods from the incoming objects. Use
823
+ * this function when cloning user-provided objects since structuredClone
824
+ * will throw an error if given an object with functions.
825
+ */
826
+ const jsonClone = (json) => tryParse(JSON.stringify(json), undefined);
827
+
809
828
  // eslint-disable-next-line @nx/enforce-module-boundaries
810
829
  const getGlobalSettings = () => {
811
830
  var _a;
@@ -1262,7 +1281,7 @@ const getStandardPayload = (destination, payload) => {
1262
1281
  referrer: getReferrer(destination),
1263
1282
  search: getSearch(destination),
1264
1283
  locale: getLocale(),
1265
- sdkVersion: "1.36.0" ,
1284
+ sdkVersion: "1.36.2" ,
1266
1285
  ...(payload || {}),
1267
1286
  };
1268
1287
  let storage = {};
@@ -1480,11 +1499,11 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
1480
1499
  if (skipZeroPurchaseEvent && isZeroPurchaseEvent({ eventName, data })) {
1481
1500
  return;
1482
1501
  }
1483
- const originalData = structuredClone(data);
1484
- const originalProviders = structuredClone(providers);
1502
+ const originalData = jsonClone(data);
1503
+ const originalProviders = jsonClone(providers);
1485
1504
  const rules = (getSetting(destination, 'configuratorSetting') ||
1486
1505
  []);
1487
- const rulesResult = evaluateEventRules(rules, structuredClone({ eventName, data }), providers !== null && providers !== void 0 ? providers : undefined, userProperties || {});
1506
+ const rulesResult = evaluateEventRules(rules, jsonClone({ eventName, data }), providers !== null && providers !== void 0 ? providers : undefined, userProperties || {});
1488
1507
  if (!rulesResult.skipEvent) {
1489
1508
  if (rulesResult.updatedPayload) {
1490
1509
  // eslint-disable-next-line no-param-reassign
@@ -1495,7 +1514,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
1495
1514
  providers = rulesResult.updatedProviders;
1496
1515
  }
1497
1516
  if (!rulesResult.skipBrowserEvent) {
1498
- const conversion = preparePayloadWithConversion(JSON.parse(JSON.stringify(data)), getSetting(destination, 'currency'));
1517
+ const conversion = preparePayloadWithConversion(jsonClone(data), getSetting(destination, 'currency'));
1499
1518
  for (const pkg of providerPackages) {
1500
1519
  if (!pkg || !pkg.name || !pkg.tag) {
1501
1520
  continue;
@@ -1529,7 +1548,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
1529
1548
  sessionId,
1530
1549
  eventName,
1531
1550
  eventId,
1532
- data: JSON.parse(JSON.stringify(payload)),
1551
+ data: jsonClone(payload),
1533
1552
  sendTag: sendTag.bind(null, destination),
1534
1553
  getEdgeData: processGetData.bind(null, destination),
1535
1554
  manifestVariables: variable.variableSet,
@@ -1561,7 +1580,7 @@ const processTag = (destination, eventName, data = {}, providers, options) => {
1561
1580
  }
1562
1581
  const additionalEvents = rulesResult.additionalEvents || [];
1563
1582
  for (const additionalEventName of additionalEvents) {
1564
- handleTag(additionalEventName, structuredClone(originalData || {}), originalProviders, options);
1583
+ handleTag(additionalEventName, jsonClone(originalData || {}), originalProviders, options);
1565
1584
  }
1566
1585
  };
1567
1586
  const handleTag = (eventName, data = {}, providers, options) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "1.36.0",
3
+ "version": "1.36.2",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",