@blotoutio/edgetag-sdk-js 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.
package/index.cjs.js CHANGED
@@ -4,6 +4,7 @@ var api = /*#__PURE__*/Object.freeze({
4
4
  __proto__: null,
5
5
  get consent () { return consent; },
6
6
  get data () { return data; },
7
+ get getConsent () { return getConsent; },
7
8
  get getData () { return getData; },
8
9
  get getUserId () { return getUserId; },
9
10
  get init () { return init; },
@@ -334,7 +335,7 @@ const getStandardPayload = (payload) => {
334
335
  referrer: getReferrer(),
335
336
  search: getSearch(),
336
337
  locale: getLocale(),
337
- sdkVersion: "0.33.0" ,
338
+ sdkVersion: "0.35.0" ,
338
339
  ...(payload || {}),
339
340
  };
340
341
  let storage = {};
@@ -395,8 +396,12 @@ const setUrl = (url) => {
395
396
  }
396
397
  endpointUrl = url;
397
398
  };
398
- const getTagURL = () => {
399
- return generateUrl('/tag');
399
+ const getTagURL = (options) => {
400
+ const url = new URL(generateUrl('/tag'));
401
+ if (options === null || options === void 0 ? void 0 : options.sync) {
402
+ url.searchParams.set('sync', 'true');
403
+ }
404
+ return url.toString();
400
405
  };
401
406
  const getInitURL = () => {
402
407
  return generateUrl('/init');
@@ -434,7 +439,7 @@ const handleConsent = (consent, options) => {
434
439
  const setConsent = (newConsent) => {
435
440
  memoryConsent = newConsent;
436
441
  };
437
- const getConsent = () => {
442
+ const getConsent$1 = () => {
438
443
  const storageConsent = getDataPerKey('local', tagStorage, consentKey);
439
444
  if (storageConsent) {
440
445
  return storageConsent;
@@ -592,7 +597,7 @@ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }
592
597
  if (providers) {
593
598
  payload.providers = providers;
594
599
  }
595
- postRequest(getTagURL(), payload, options).catch(error);
600
+ postRequest(getTagURL(options), payload, options).catch(error);
596
601
  };
597
602
  const handleTag = (eventName, data = {}, providers, options) => {
598
603
  if (!isInitialized()) {
@@ -610,7 +615,7 @@ const handleTag = (eventName, data = {}, providers, options) => {
610
615
  const configuredTags = getConfiguredTags();
611
616
  const userId = handleGetUserId();
612
617
  const providerData = {};
613
- const consent = getConsent();
618
+ const consent = getConsent$1();
614
619
  for (const pkg of Object.values(providerPackages)) {
615
620
  if (!pkg || !pkg.name || !pkg.tag) {
616
621
  continue;
@@ -677,7 +682,7 @@ const handleData = (data, providers, options) => {
677
682
  const providerPackages = getProvidersPackage();
678
683
  const configuredTags = getConfiguredTags();
679
684
  const userId = handleGetUserId();
680
- const consent = getConsent();
685
+ const consent = getConsent$1();
681
686
  for (const pkg of Object.values(providerPackages)) {
682
687
  if (!pkg || !pkg.user || !pkg.name) {
683
688
  continue;
@@ -706,6 +711,7 @@ const handleData = (data, providers, options) => {
706
711
  postRequest(getDataURL(), { data, providers }, options).catch(error);
707
712
  };
708
713
 
714
+ const cacheKey = `${keyPrefix}Cache`;
709
715
  const saveDataToEdge = (key, value, provider) => {
710
716
  if (!value) {
711
717
  return;
@@ -744,6 +750,21 @@ const handleCaptureQuery = (provider, key, persistType) => {
744
750
  }
745
751
  saveDataPerKey(persistType, provider, data, key);
746
752
  };
753
+ const getFromCache = (persistType, provider, key) => {
754
+ var _a;
755
+ const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
756
+ return (_a = cache[provider]) === null || _a === void 0 ? void 0 : _a[key];
757
+ };
758
+ const saveToCache = (persistType, provider, key, value) => {
759
+ const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
760
+ if (!cache[provider]) {
761
+ cache[provider] = { [key]: value };
762
+ }
763
+ else {
764
+ cache[provider][key] = value;
765
+ }
766
+ saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
767
+ };
747
768
  const handleCaptureStorage = (provider, key, persistType, location) => {
748
769
  let data;
749
770
  try {
@@ -764,10 +785,12 @@ const handleCaptureStorage = (provider, key, persistType, location) => {
764
785
  catch {
765
786
  return;
766
787
  }
788
+ const cachedValue = getFromCache(persistType, provider, key);
789
+ saveToCache(persistType, provider, key, data);
767
790
  if (!data) {
768
791
  return;
769
792
  }
770
- if (persistType === 'edge') {
793
+ if (persistType === 'edge' && cachedValue !== data) {
771
794
  saveDataToEdge(key, data, provider);
772
795
  return;
773
796
  }
@@ -858,7 +881,7 @@ const handleInit = (preferences) => {
858
881
  if (result.userId) {
859
882
  setUserId(result.userId);
860
883
  }
861
- const consent = getConsent();
884
+ const consent = getConsent$1();
862
885
  if (result.consent && !consent) {
863
886
  saveConsent(result.consent);
864
887
  }
@@ -877,7 +900,7 @@ const handleUser = (key, value, providers, options) => {
877
900
  });
878
901
  const providerPackages = getProvidersPackage();
879
902
  const configuredTags = getConfiguredTags();
880
- const consent = getConsent();
903
+ const consent = getConsent$1();
881
904
  const userId = handleGetUserId();
882
905
  for (const pkg of Object.values(providerPackages)) {
883
906
  if (!pkg || !pkg.name || !pkg.user) {
@@ -919,6 +942,24 @@ const handleKeys = (callback) => {
919
942
  .catch(error);
920
943
  };
921
944
 
945
+ const handleGetConsent = (callback) => {
946
+ getRequest(getConsentURL())
947
+ .then((result) => {
948
+ // this will try to return the consent data stored in Edge
949
+ return result === null || result === void 0 ? void 0 : result.result;
950
+ })
951
+ .catch(() => undefined)
952
+ .then((result) => {
953
+ 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
954
+ if (consent) {
955
+ callback(consent);
956
+ }
957
+ else {
958
+ callback(null, new Error('Consent not found for Current User!'));
959
+ }
960
+ });
961
+ };
962
+
922
963
  const init = (preferences) => {
923
964
  handleInit(preferences);
924
965
  };
@@ -943,9 +984,13 @@ const keys = (callback) => {
943
984
  const getUserId = () => {
944
985
  return handleGetUserId();
945
986
  };
987
+ const getConsent = (callback) => {
988
+ handleGetConsent(callback);
989
+ };
946
990
 
947
991
  exports.consent = consent;
948
992
  exports.data = data;
993
+ exports.getConsent = getConsent;
949
994
  exports.getData = getData;
950
995
  exports.getUserId = getUserId;
951
996
  exports.init = init;
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
@@ -2,6 +2,7 @@ var api = /*#__PURE__*/Object.freeze({
2
2
  __proto__: null,
3
3
  get consent () { return consent; },
4
4
  get data () { return data; },
5
+ get getConsent () { return getConsent; },
5
6
  get getData () { return getData; },
6
7
  get getUserId () { return getUserId; },
7
8
  get init () { return init; },
@@ -332,7 +333,7 @@ const getStandardPayload = (payload) => {
332
333
  referrer: getReferrer(),
333
334
  search: getSearch(),
334
335
  locale: getLocale(),
335
- sdkVersion: "0.33.0" ,
336
+ sdkVersion: "0.35.0" ,
336
337
  ...(payload || {}),
337
338
  };
338
339
  let storage = {};
@@ -393,8 +394,12 @@ const setUrl = (url) => {
393
394
  }
394
395
  endpointUrl = url;
395
396
  };
396
- const getTagURL = () => {
397
- return generateUrl('/tag');
397
+ const getTagURL = (options) => {
398
+ const url = new URL(generateUrl('/tag'));
399
+ if (options === null || options === void 0 ? void 0 : options.sync) {
400
+ url.searchParams.set('sync', 'true');
401
+ }
402
+ return url.toString();
398
403
  };
399
404
  const getInitURL = () => {
400
405
  return generateUrl('/init');
@@ -432,7 +437,7 @@ const handleConsent = (consent, options) => {
432
437
  const setConsent = (newConsent) => {
433
438
  memoryConsent = newConsent;
434
439
  };
435
- const getConsent = () => {
440
+ const getConsent$1 = () => {
436
441
  const storageConsent = getDataPerKey('local', tagStorage, consentKey);
437
442
  if (storageConsent) {
438
443
  return storageConsent;
@@ -590,7 +595,7 @@ const sendTag = ({ eventName, eventId, data, providerData, providers, options, }
590
595
  if (providers) {
591
596
  payload.providers = providers;
592
597
  }
593
- postRequest(getTagURL(), payload, options).catch(error);
598
+ postRequest(getTagURL(options), payload, options).catch(error);
594
599
  };
595
600
  const handleTag = (eventName, data = {}, providers, options) => {
596
601
  if (!isInitialized()) {
@@ -608,7 +613,7 @@ const handleTag = (eventName, data = {}, providers, options) => {
608
613
  const configuredTags = getConfiguredTags();
609
614
  const userId = handleGetUserId();
610
615
  const providerData = {};
611
- const consent = getConsent();
616
+ const consent = getConsent$1();
612
617
  for (const pkg of Object.values(providerPackages)) {
613
618
  if (!pkg || !pkg.name || !pkg.tag) {
614
619
  continue;
@@ -675,7 +680,7 @@ const handleData = (data, providers, options) => {
675
680
  const providerPackages = getProvidersPackage();
676
681
  const configuredTags = getConfiguredTags();
677
682
  const userId = handleGetUserId();
678
- const consent = getConsent();
683
+ const consent = getConsent$1();
679
684
  for (const pkg of Object.values(providerPackages)) {
680
685
  if (!pkg || !pkg.user || !pkg.name) {
681
686
  continue;
@@ -704,6 +709,7 @@ const handleData = (data, providers, options) => {
704
709
  postRequest(getDataURL(), { data, providers }, options).catch(error);
705
710
  };
706
711
 
712
+ const cacheKey = `${keyPrefix}Cache`;
707
713
  const saveDataToEdge = (key, value, provider) => {
708
714
  if (!value) {
709
715
  return;
@@ -742,6 +748,21 @@ const handleCaptureQuery = (provider, key, persistType) => {
742
748
  }
743
749
  saveDataPerKey(persistType, provider, data, key);
744
750
  };
751
+ const getFromCache = (persistType, provider, key) => {
752
+ var _a;
753
+ const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
754
+ return (_a = cache[provider]) === null || _a === void 0 ? void 0 : _a[key];
755
+ };
756
+ const saveToCache = (persistType, provider, key, value) => {
757
+ const cache = getData$1(persistType === 'edge' ? 'local' : persistType, cacheKey);
758
+ if (!cache[provider]) {
759
+ cache[provider] = { [key]: value };
760
+ }
761
+ else {
762
+ cache[provider][key] = value;
763
+ }
764
+ saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
765
+ };
745
766
  const handleCaptureStorage = (provider, key, persistType, location) => {
746
767
  let data;
747
768
  try {
@@ -762,10 +783,12 @@ const handleCaptureStorage = (provider, key, persistType, location) => {
762
783
  catch {
763
784
  return;
764
785
  }
786
+ const cachedValue = getFromCache(persistType, provider, key);
787
+ saveToCache(persistType, provider, key, data);
765
788
  if (!data) {
766
789
  return;
767
790
  }
768
- if (persistType === 'edge') {
791
+ if (persistType === 'edge' && cachedValue !== data) {
769
792
  saveDataToEdge(key, data, provider);
770
793
  return;
771
794
  }
@@ -856,7 +879,7 @@ const handleInit = (preferences) => {
856
879
  if (result.userId) {
857
880
  setUserId(result.userId);
858
881
  }
859
- const consent = getConsent();
882
+ const consent = getConsent$1();
860
883
  if (result.consent && !consent) {
861
884
  saveConsent(result.consent);
862
885
  }
@@ -875,7 +898,7 @@ const handleUser = (key, value, providers, options) => {
875
898
  });
876
899
  const providerPackages = getProvidersPackage();
877
900
  const configuredTags = getConfiguredTags();
878
- const consent = getConsent();
901
+ const consent = getConsent$1();
879
902
  const userId = handleGetUserId();
880
903
  for (const pkg of Object.values(providerPackages)) {
881
904
  if (!pkg || !pkg.name || !pkg.user) {
@@ -917,6 +940,24 @@ const handleKeys = (callback) => {
917
940
  .catch(error);
918
941
  };
919
942
 
943
+ const handleGetConsent = (callback) => {
944
+ getRequest(getConsentURL())
945
+ .then((result) => {
946
+ // this will try to return the consent data stored in Edge
947
+ return result === null || result === void 0 ? void 0 : result.result;
948
+ })
949
+ .catch(() => undefined)
950
+ .then((result) => {
951
+ 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
952
+ if (consent) {
953
+ callback(consent);
954
+ }
955
+ else {
956
+ callback(null, new Error('Consent not found for Current User!'));
957
+ }
958
+ });
959
+ };
960
+
920
961
  const init = (preferences) => {
921
962
  handleInit(preferences);
922
963
  };
@@ -941,5 +982,8 @@ const keys = (callback) => {
941
982
  const getUserId = () => {
942
983
  return handleGetUserId();
943
984
  };
985
+ const getConsent = (callback) => {
986
+ handleGetConsent(callback);
987
+ };
944
988
 
945
- export { consent, data, getData, getUserId, init, keys, tag, user };
989
+ export { consent, data, getConsent, getData, getUserId, init, keys, tag, user };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",