@blotoutio/edgetag-sdk-browser 0.33.0 → 0.35.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 (2) hide show
  1. package/index.js +58 -10
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -5,6 +5,7 @@
5
5
  __proto__: null,
6
6
  get consent () { return consent; },
7
7
  get data () { return data; },
8
+ get getConsent () { return getConsent; },
8
9
  get getData () { return getData; },
9
10
  get getUserId () { return getUserId; },
10
11
  get init () { return init; },
@@ -335,7 +336,7 @@
335
336
  referrer: getReferrer(),
336
337
  search: getSearch(),
337
338
  locale: getLocale(),
338
- sdkVersion: "0.33.0" ,
339
+ sdkVersion: "0.35.0" ,
339
340
  ...(payload || {}),
340
341
  };
341
342
  let storage = {};
@@ -396,8 +397,12 @@
396
397
  }
397
398
  endpointUrl = url;
398
399
  };
399
- const getTagURL = () => {
400
- return generateUrl('/tag');
400
+ const getTagURL = (options) => {
401
+ const url = new URL(generateUrl('/tag'));
402
+ if (options === null || options === void 0 ? void 0 : options.sync) {
403
+ url.searchParams.set('sync', 'true');
404
+ }
405
+ return url.toString();
401
406
  };
402
407
  const getInitURL = () => {
403
408
  return generateUrl('/init');
@@ -435,7 +440,7 @@
435
440
  const setConsent = (newConsent) => {
436
441
  memoryConsent = newConsent;
437
442
  };
438
- const getConsent = () => {
443
+ const getConsent$1 = () => {
439
444
  const storageConsent = getDataPerKey('local', tagStorage, consentKey);
440
445
  if (storageConsent) {
441
446
  return storageConsent;
@@ -593,7 +598,7 @@
593
598
  if (providers) {
594
599
  payload.providers = providers;
595
600
  }
596
- postRequest(getTagURL(), payload, options).catch(error);
601
+ postRequest(getTagURL(options), payload, options).catch(error);
597
602
  };
598
603
  const handleTag = (eventName, data = {}, providers, options) => {
599
604
  if (!isInitialized()) {
@@ -611,7 +616,7 @@
611
616
  const configuredTags = getConfiguredTags();
612
617
  const userId = handleGetUserId();
613
618
  const providerData = {};
614
- const consent = getConsent();
619
+ const consent = getConsent$1();
615
620
  for (const pkg of Object.values(providerPackages)) {
616
621
  if (!pkg || !pkg.name || !pkg.tag) {
617
622
  continue;
@@ -678,7 +683,7 @@
678
683
  const providerPackages = getProvidersPackage();
679
684
  const configuredTags = getConfiguredTags();
680
685
  const userId = handleGetUserId();
681
- const consent = getConsent();
686
+ const consent = getConsent$1();
682
687
  for (const pkg of Object.values(providerPackages)) {
683
688
  if (!pkg || !pkg.user || !pkg.name) {
684
689
  continue;
@@ -707,6 +712,7 @@
707
712
  postRequest(getDataURL(), { data, providers }, options).catch(error);
708
713
  };
709
714
 
715
+ const cacheKey = `${keyPrefix}Cache`;
710
716
  const saveDataToEdge = (key, value, provider) => {
711
717
  if (!value) {
712
718
  return;
@@ -745,6 +751,21 @@
745
751
  }
746
752
  saveDataPerKey(persistType, provider, data, key);
747
753
  };
754
+ const getFromCache = (persistType, provider, key) => {
755
+ var _a;
756
+ const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
757
+ return (_a = cache[provider]) === null || _a === void 0 ? void 0 : _a[key];
758
+ };
759
+ const saveToCache = (persistType, provider, key, value) => {
760
+ const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
761
+ if (!cache[provider]) {
762
+ cache[provider] = { [key]: value };
763
+ }
764
+ else {
765
+ cache[provider][key] = value;
766
+ }
767
+ saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
768
+ };
748
769
  const handleCaptureStorage = (provider, key, persistType, location) => {
749
770
  let data;
750
771
  try {
@@ -765,10 +786,12 @@
765
786
  catch {
766
787
  return;
767
788
  }
789
+ const cachedValue = getFromCache(persistType, provider, key);
790
+ saveToCache(persistType, provider, key, data);
768
791
  if (!data) {
769
792
  return;
770
793
  }
771
- if (persistType === 'edge') {
794
+ if (persistType === 'edge' && cachedValue !== data) {
772
795
  saveDataToEdge(key, data, provider);
773
796
  return;
774
797
  }
@@ -859,7 +882,7 @@
859
882
  if (result.userId) {
860
883
  setUserId(result.userId);
861
884
  }
862
- const consent = getConsent();
885
+ const consent = getConsent$1();
863
886
  if (result.consent && !consent) {
864
887
  saveConsent(result.consent);
865
888
  }
@@ -878,7 +901,7 @@
878
901
  });
879
902
  const providerPackages = getProvidersPackage();
880
903
  const configuredTags = getConfiguredTags();
881
- const consent = getConsent();
904
+ const consent = getConsent$1();
882
905
  const userId = handleGetUserId();
883
906
  for (const pkg of Object.values(providerPackages)) {
884
907
  if (!pkg || !pkg.name || !pkg.user) {
@@ -920,6 +943,24 @@
920
943
  .catch(error);
921
944
  };
922
945
 
946
+ const handleGetConsent = (callback) => {
947
+ getRequest(getConsentURL())
948
+ .then((result) => {
949
+ // this will try to return the consent data stored in Edge
950
+ return result === null || result === void 0 ? void 0 : result.result;
951
+ })
952
+ .catch(() => undefined)
953
+ .then((result) => {
954
+ const consent = result !== null && result !== void 0 ? result : getConsent$1(); // this is a default value i.e. value from local storage and memory incase Edge doesn't have consent
955
+ if (consent) {
956
+ callback(consent);
957
+ }
958
+ else {
959
+ callback(null, new Error('Consent not found for Current User!'));
960
+ }
961
+ });
962
+ };
963
+
923
964
  const init = (preferences) => {
924
965
  handleInit(preferences);
925
966
  };
@@ -944,6 +985,9 @@
944
985
  const getUserId = () => {
945
986
  return handleGetUserId();
946
987
  };
988
+ const getConsent = (callback) => {
989
+ handleGetConsent(callback);
990
+ };
947
991
 
948
992
  // TODO https://github.com/blotoutio/solutions/issues/826
949
993
 
@@ -979,6 +1023,10 @@
979
1023
  getUserId() {
980
1024
  return getUserId()
981
1025
  }
1026
+
1027
+ getConsent(callback, error) {
1028
+ getConsent(callback);
1029
+ }
982
1030
  }
983
1031
 
984
1032
  var api = new API();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",