@blotoutio/edgetag-sdk-js 0.32.0 → 0.34.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.js CHANGED
@@ -334,7 +334,7 @@ const getStandardPayload = (payload) => {
334
334
  referrer: getReferrer(),
335
335
  search: getSearch(),
336
336
  locale: getLocale(),
337
- sdkVersion: "0.32.0" ,
337
+ sdkVersion: "0.34.0" ,
338
338
  ...(payload || {}),
339
339
  };
340
340
  let storage = {};
@@ -395,8 +395,12 @@ const setUrl = (url) => {
395
395
  }
396
396
  endpointUrl = url;
397
397
  };
398
- const getTagURL = () => {
399
- return generateUrl('/tag');
398
+ const getTagURL = (options) => {
399
+ const url = new URL(generateUrl('/tag'));
400
+ if (options === null || options === void 0 ? void 0 : options.sync) {
401
+ url.searchParams.set('sync', 'true');
402
+ }
403
+ return url.toString();
400
404
  };
401
405
  const getInitURL = () => {
402
406
  return generateUrl('/init');
@@ -592,7 +596,7 @@ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }
592
596
  if (providers) {
593
597
  payload.providers = providers;
594
598
  }
595
- postRequest(getTagURL(), payload, options).catch(error);
599
+ postRequest(getTagURL(options), payload, options).catch(error);
596
600
  };
597
601
  const handleTag = (eventName, data = {}, providers, options) => {
598
602
  if (!isInitialized()) {
@@ -706,6 +710,7 @@ const handleData = (data, providers, options) => {
706
710
  postRequest(getDataURL(), { data, providers }, options).catch(error);
707
711
  };
708
712
 
713
+ const cacheKey = `${keyPrefix}Cache`;
709
714
  const saveDataToEdge = (key, value, provider) => {
710
715
  if (!value) {
711
716
  return;
@@ -744,6 +749,21 @@ const handleCaptureQuery = (provider, key, persistType) => {
744
749
  }
745
750
  saveDataPerKey(persistType, provider, data, key);
746
751
  };
752
+ const getFromCache = (persistType, provider, key) => {
753
+ var _a;
754
+ const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
755
+ return (_a = cache[provider]) === null || _a === void 0 ? void 0 : _a[key];
756
+ };
757
+ const saveToCache = (persistType, provider, key, value) => {
758
+ const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
759
+ if (!cache[provider]) {
760
+ cache[provider] = { [key]: value };
761
+ }
762
+ else {
763
+ cache[provider][key] = value;
764
+ }
765
+ saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
766
+ };
747
767
  const handleCaptureStorage = (provider, key, persistType, location) => {
748
768
  let data;
749
769
  try {
@@ -764,10 +784,12 @@ const handleCaptureStorage = (provider, key, persistType, location) => {
764
784
  catch {
765
785
  return;
766
786
  }
787
+ const cachedValue = getFromCache(persistType, provider, key);
788
+ saveToCache(persistType, provider, key, data);
767
789
  if (!data) {
768
790
  return;
769
791
  }
770
- if (persistType === 'edge') {
792
+ if (persistType === 'edge' && cachedValue !== data) {
771
793
  saveDataToEdge(key, data, provider);
772
794
  return;
773
795
  }
package/index.d.ts CHANGED
@@ -6,6 +6,7 @@ type PersistType = 'local' | 'session' | 'edge'
6
6
 
7
7
  type EventOptions = {
8
8
  method?: 'beacon'
9
+ sync?: boolean
9
10
  }
10
11
 
11
12
  type Data = Record<string, unknown>
package/index.mjs CHANGED
@@ -332,7 +332,7 @@ const getStandardPayload = (payload) => {
332
332
  referrer: getReferrer(),
333
333
  search: getSearch(),
334
334
  locale: getLocale(),
335
- sdkVersion: "0.32.0" ,
335
+ sdkVersion: "0.34.0" ,
336
336
  ...(payload || {}),
337
337
  };
338
338
  let storage = {};
@@ -393,8 +393,12 @@ const setUrl = (url) => {
393
393
  }
394
394
  endpointUrl = url;
395
395
  };
396
- const getTagURL = () => {
397
- return generateUrl('/tag');
396
+ const getTagURL = (options) => {
397
+ const url = new URL(generateUrl('/tag'));
398
+ if (options === null || options === void 0 ? void 0 : options.sync) {
399
+ url.searchParams.set('sync', 'true');
400
+ }
401
+ return url.toString();
398
402
  };
399
403
  const getInitURL = () => {
400
404
  return generateUrl('/init');
@@ -590,7 +594,7 @@ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }
590
594
  if (providers) {
591
595
  payload.providers = providers;
592
596
  }
593
- postRequest(getTagURL(), payload, options).catch(error);
597
+ postRequest(getTagURL(options), payload, options).catch(error);
594
598
  };
595
599
  const handleTag = (eventName, data = {}, providers, options) => {
596
600
  if (!isInitialized()) {
@@ -704,6 +708,7 @@ const handleData = (data, providers, options) => {
704
708
  postRequest(getDataURL(), { data, providers }, options).catch(error);
705
709
  };
706
710
 
711
+ const cacheKey = `${keyPrefix}Cache`;
707
712
  const saveDataToEdge = (key, value, provider) => {
708
713
  if (!value) {
709
714
  return;
@@ -742,6 +747,21 @@ const handleCaptureQuery = (provider, key, persistType) => {
742
747
  }
743
748
  saveDataPerKey(persistType, provider, data, key);
744
749
  };
750
+ const getFromCache = (persistType, provider, key) => {
751
+ var _a;
752
+ const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
753
+ return (_a = cache[provider]) === null || _a === void 0 ? void 0 : _a[key];
754
+ };
755
+ const saveToCache = (persistType, provider, key, value) => {
756
+ const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
757
+ if (!cache[provider]) {
758
+ cache[provider] = { [key]: value };
759
+ }
760
+ else {
761
+ cache[provider][key] = value;
762
+ }
763
+ saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
764
+ };
745
765
  const handleCaptureStorage = (provider, key, persistType, location) => {
746
766
  let data;
747
767
  try {
@@ -762,10 +782,12 @@ const handleCaptureStorage = (provider, key, persistType, location) => {
762
782
  catch {
763
783
  return;
764
784
  }
785
+ const cachedValue = getFromCache(persistType, provider, key);
786
+ saveToCache(persistType, provider, key, data);
765
787
  if (!data) {
766
788
  return;
767
789
  }
768
- if (persistType === 'edge') {
790
+ if (persistType === 'edge' && cachedValue !== data) {
769
791
  saveDataToEdge(key, data, provider);
770
792
  return;
771
793
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "0.32.0",
3
+ "version": "0.34.0",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",