@blotoutio/edgetag-sdk-js 0.7.3 → 0.8.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 CHANGED
@@ -320,29 +320,6 @@ const consentKey = 'consent';
320
320
  const keyPrefix = `_worker`;
321
321
 
322
322
  const initKey = `${keyPrefix}Store`;
323
- const getCookieValue = (key) => {
324
- try {
325
- if (!document || !document.cookie) {
326
- return '';
327
- }
328
- const name = `${key}=`;
329
- const decodedCookie = decodeURIComponent(document.cookie);
330
- const ca = decodedCookie.split(';');
331
- for (let i = 0; i < ca.length; i++) {
332
- let c = ca[i];
333
- while (c.charAt(0) === ' ') {
334
- c = c.substring(1);
335
- }
336
- if (c.indexOf(name) === 0) {
337
- return c.substring(name.length, c.length);
338
- }
339
- }
340
- return '';
341
- }
342
- catch (_a) {
343
- return '';
344
- }
345
- };
346
323
  const saveDataPerKey = (persistType, provider, value, key) => {
347
324
  const storage = getData$1(persistType);
348
325
  if (!storage['data']) {
@@ -446,6 +423,48 @@ const getSession = (key) => {
446
423
  }
447
424
  };
448
425
 
426
+ const encodeString = (name) => {
427
+ if (typeof btoa === 'undefined') {
428
+ return Buffer.from(name).toString('base64');
429
+ }
430
+ return btoa(name);
431
+ };
432
+ const generateEventId = (name) => {
433
+ let time = Date.now().toString();
434
+ if (typeof performance !== 'undefined' &&
435
+ typeof performance.now === 'function') {
436
+ const perf = performance.now();
437
+ if (perf) {
438
+ time = perf.toFixed(4);
439
+ }
440
+ }
441
+ return `${encodeString(name)}-${uuid.v4()}-${time}`;
442
+ };
443
+
444
+ const getCookieValue = (key) => {
445
+ try {
446
+ if (!document || !document.cookie) {
447
+ return '';
448
+ }
449
+ const name = `${key}=`;
450
+ const decodedCookie = decodeURIComponent(document.cookie);
451
+ const ca = decodedCookie.split(';');
452
+ for (let i = 0; i < ca.length; i++) {
453
+ let c = ca[i];
454
+ while (c.charAt(0) === ' ') {
455
+ c = c.substring(1);
456
+ }
457
+ if (c.indexOf(name) === 0) {
458
+ return c.substring(name.length, c.length);
459
+ }
460
+ }
461
+ return '';
462
+ }
463
+ catch (_a) {
464
+ return '';
465
+ }
466
+ };
467
+
449
468
  let initUserId = '';
450
469
  const handleGetUserId = () => {
451
470
  if (initUserId) {
@@ -597,24 +616,6 @@ const getConsent = () => {
597
616
  return memoryConsent;
598
617
  };
599
618
 
600
- const encodeString = (name) => {
601
- if (typeof btoa === 'undefined') {
602
- return Buffer.from(name).toString('base64');
603
- }
604
- return btoa(name);
605
- };
606
- const generateEventId = (name) => {
607
- let time = Date.now().toString();
608
- if (typeof performance !== 'undefined' &&
609
- typeof performance.now === 'function') {
610
- const perf = performance.now();
611
- if (perf) {
612
- time = perf.toFixed(4);
613
- }
614
- }
615
- return `${encodeString(name)}-${uuid.v4()}-${time}`;
616
- };
617
-
618
619
  const manifestVariables = {};
619
620
  const addProviderVariable = (name, variables) => {
620
621
  manifestVariables[name] = variables;
@@ -708,12 +709,25 @@ const handleTag = (eventName, data = {}, providers, options) => {
708
709
  });
709
710
  };
710
711
 
711
- const handleData = (data, options) => {
712
+ const handleData = (data, providers, options) => {
712
713
  if (!data || Object.keys(data).length === 0) {
713
714
  error('Provide data for data API.');
714
715
  return;
715
716
  }
716
717
  saveKV(data);
718
+ const providerPackages = getProvidersPackage();
719
+ const userId = handleGetUserId();
720
+ if (providerPackages) {
721
+ Object.values(providerPackages).forEach((pkg) => {
722
+ if (!pkg || !pkg.user || !allowProviderWithConsent(providers, pkg.name)) {
723
+ return;
724
+ }
725
+ pkg.user({
726
+ userId,
727
+ data,
728
+ });
729
+ });
730
+ }
717
731
  postRequest(getDataURL(), { data }, options).catch(error);
718
732
  };
719
733
 
@@ -799,6 +813,18 @@ const handleCapture = (provider, params) => {
799
813
  });
800
814
  };
801
815
 
816
+ const handleGetData = (keys, callback) => {
817
+ if (!keys || keys.length === 0) {
818
+ error('Provide keys for get data API.');
819
+ return;
820
+ }
821
+ getRequest(getGetDataURL(keys))
822
+ .then((result) => {
823
+ callback((result === null || result === void 0 ? void 0 : result.result) || {});
824
+ })
825
+ .catch(error);
826
+ };
827
+
802
828
  const handleManifest = (manifest) => {
803
829
  const providerPackages = getProvidersPackage();
804
830
  const userId = handleGetUserId();
@@ -818,7 +844,15 @@ const handleManifest = (manifest) => {
818
844
  if (providerPackages) {
819
845
  const pkg = providerPackages[provider.package];
820
846
  if (pkg && pkg.init && allowProvider(pkg.name)) {
821
- pkg.init({ userId, manifest: provider, sendTag });
847
+ const initData = {
848
+ userId,
849
+ manifest: provider,
850
+ sendTag,
851
+ sendEdgeData: handleData,
852
+ getEdgeData: handleGetData,
853
+ keyName: `${keyPrefix}Store`,
854
+ };
855
+ pkg.init(initData);
822
856
  }
823
857
  }
824
858
  });
@@ -854,7 +888,7 @@ const handleInit = (preferences) => {
854
888
  .catch(error);
855
889
  };
856
890
 
857
- const handleUser = (key, value, options) => {
891
+ const handleUser = (key, value, providers, options) => {
858
892
  if (!key || !value) {
859
893
  error('Key or Value is missing in user API.');
860
894
  return;
@@ -862,24 +896,25 @@ const handleUser = (key, value, options) => {
862
896
  saveKV({
863
897
  [key]: value,
864
898
  });
899
+ const providerPackages = getProvidersPackage();
900
+ const userId = handleGetUserId();
901
+ if (providerPackages) {
902
+ Object.values(providerPackages).forEach((pkg) => {
903
+ if (!pkg || !pkg.user || !allowProviderWithConsent(providers, pkg.name)) {
904
+ return;
905
+ }
906
+ pkg.user({
907
+ userId,
908
+ data: { [key]: value },
909
+ });
910
+ });
911
+ }
865
912
  postRequest(getUserURL(), {
866
913
  key,
867
914
  value,
868
915
  }, options).catch(error);
869
916
  };
870
917
 
871
- const handleGetData = (keys, callback) => {
872
- if (!keys || keys.length === 0) {
873
- error('Provide keys for get data API.');
874
- return;
875
- }
876
- getRequest(getGetDataURL(keys))
877
- .then((result) => {
878
- callback((result === null || result === void 0 ? void 0 : result.result) || {});
879
- })
880
- .catch(error);
881
- };
882
-
883
918
  const handleKeys = (callback) => {
884
919
  getRequest(getKeysURL())
885
920
  .then((result) => {
@@ -897,11 +932,11 @@ const tag = (name, data, providers, options) => {
897
932
  const consent = (consent) => {
898
933
  handleConsent(consent);
899
934
  };
900
- const user = (key, value, options) => {
901
- handleUser(key, value, options);
935
+ const user = (key, value, providers, options) => {
936
+ handleUser(key, value, providers, options);
902
937
  };
903
- const data = (data, options) => {
904
- handleData(data, options);
938
+ const data = (data, providers, options) => {
939
+ handleData(data, providers, options);
905
940
  };
906
941
  const getData = (keys, callback) => {
907
942
  handleGetData(keys, callback);
package/index.d.ts CHANGED
@@ -87,9 +87,18 @@ export declare const tag: (
87
87
 
88
88
  export declare const consent: (consent: Data) => void
89
89
 
90
- export declare const user: (key: UserKey, value: string) => void
90
+ export declare const user: (
91
+ key: UserKey,
92
+ value: string,
93
+ providers?: Data,
94
+ options?: EventOptions
95
+ ) => void
91
96
 
92
- export declare const data: (data: Record<string, string>) => void
97
+ export declare const data: (
98
+ data: Record<string, string>,
99
+ providers?: Data,
100
+ options?: EventOptions
101
+ ) => void
93
102
 
94
103
  export declare const getData: (
95
104
  keys: string[],
package/index.esm.js CHANGED
@@ -298,29 +298,6 @@ const consentKey = 'consent';
298
298
  const keyPrefix = `_worker`;
299
299
 
300
300
  const initKey = `${keyPrefix}Store`;
301
- const getCookieValue = (key) => {
302
- try {
303
- if (!document || !document.cookie) {
304
- return '';
305
- }
306
- const name = `${key}=`;
307
- const decodedCookie = decodeURIComponent(document.cookie);
308
- const ca = decodedCookie.split(';');
309
- for (let i = 0; i < ca.length; i++) {
310
- let c = ca[i];
311
- while (c.charAt(0) === ' ') {
312
- c = c.substring(1);
313
- }
314
- if (c.indexOf(name) === 0) {
315
- return c.substring(name.length, c.length);
316
- }
317
- }
318
- return '';
319
- }
320
- catch (_a) {
321
- return '';
322
- }
323
- };
324
301
  const saveDataPerKey = (persistType, provider, value, key) => {
325
302
  const storage = getData$1(persistType);
326
303
  if (!storage['data']) {
@@ -424,6 +401,48 @@ const getSession = (key) => {
424
401
  }
425
402
  };
426
403
 
404
+ const encodeString = (name) => {
405
+ if (typeof btoa === 'undefined') {
406
+ return Buffer.from(name).toString('base64');
407
+ }
408
+ return btoa(name);
409
+ };
410
+ const generateEventId = (name) => {
411
+ let time = Date.now().toString();
412
+ if (typeof performance !== 'undefined' &&
413
+ typeof performance.now === 'function') {
414
+ const perf = performance.now();
415
+ if (perf) {
416
+ time = perf.toFixed(4);
417
+ }
418
+ }
419
+ return `${encodeString(name)}-${v4()}-${time}`;
420
+ };
421
+
422
+ const getCookieValue = (key) => {
423
+ try {
424
+ if (!document || !document.cookie) {
425
+ return '';
426
+ }
427
+ const name = `${key}=`;
428
+ const decodedCookie = decodeURIComponent(document.cookie);
429
+ const ca = decodedCookie.split(';');
430
+ for (let i = 0; i < ca.length; i++) {
431
+ let c = ca[i];
432
+ while (c.charAt(0) === ' ') {
433
+ c = c.substring(1);
434
+ }
435
+ if (c.indexOf(name) === 0) {
436
+ return c.substring(name.length, c.length);
437
+ }
438
+ }
439
+ return '';
440
+ }
441
+ catch (_a) {
442
+ return '';
443
+ }
444
+ };
445
+
427
446
  let initUserId = '';
428
447
  const handleGetUserId = () => {
429
448
  if (initUserId) {
@@ -575,24 +594,6 @@ const getConsent = () => {
575
594
  return memoryConsent;
576
595
  };
577
596
 
578
- const encodeString = (name) => {
579
- if (typeof btoa === 'undefined') {
580
- return Buffer.from(name).toString('base64');
581
- }
582
- return btoa(name);
583
- };
584
- const generateEventId = (name) => {
585
- let time = Date.now().toString();
586
- if (typeof performance !== 'undefined' &&
587
- typeof performance.now === 'function') {
588
- const perf = performance.now();
589
- if (perf) {
590
- time = perf.toFixed(4);
591
- }
592
- }
593
- return `${encodeString(name)}-${v4()}-${time}`;
594
- };
595
-
596
597
  const manifestVariables = {};
597
598
  const addProviderVariable = (name, variables) => {
598
599
  manifestVariables[name] = variables;
@@ -686,12 +687,25 @@ const handleTag = (eventName, data = {}, providers, options) => {
686
687
  });
687
688
  };
688
689
 
689
- const handleData = (data, options) => {
690
+ const handleData = (data, providers, options) => {
690
691
  if (!data || Object.keys(data).length === 0) {
691
692
  error('Provide data for data API.');
692
693
  return;
693
694
  }
694
695
  saveKV(data);
696
+ const providerPackages = getProvidersPackage();
697
+ const userId = handleGetUserId();
698
+ if (providerPackages) {
699
+ Object.values(providerPackages).forEach((pkg) => {
700
+ if (!pkg || !pkg.user || !allowProviderWithConsent(providers, pkg.name)) {
701
+ return;
702
+ }
703
+ pkg.user({
704
+ userId,
705
+ data,
706
+ });
707
+ });
708
+ }
695
709
  postRequest(getDataURL(), { data }, options).catch(error);
696
710
  };
697
711
 
@@ -777,6 +791,18 @@ const handleCapture = (provider, params) => {
777
791
  });
778
792
  };
779
793
 
794
+ const handleGetData = (keys, callback) => {
795
+ if (!keys || keys.length === 0) {
796
+ error('Provide keys for get data API.');
797
+ return;
798
+ }
799
+ getRequest(getGetDataURL(keys))
800
+ .then((result) => {
801
+ callback((result === null || result === void 0 ? void 0 : result.result) || {});
802
+ })
803
+ .catch(error);
804
+ };
805
+
780
806
  const handleManifest = (manifest) => {
781
807
  const providerPackages = getProvidersPackage();
782
808
  const userId = handleGetUserId();
@@ -796,7 +822,15 @@ const handleManifest = (manifest) => {
796
822
  if (providerPackages) {
797
823
  const pkg = providerPackages[provider.package];
798
824
  if (pkg && pkg.init && allowProvider(pkg.name)) {
799
- pkg.init({ userId, manifest: provider, sendTag });
825
+ const initData = {
826
+ userId,
827
+ manifest: provider,
828
+ sendTag,
829
+ sendEdgeData: handleData,
830
+ getEdgeData: handleGetData,
831
+ keyName: `${keyPrefix}Store`,
832
+ };
833
+ pkg.init(initData);
800
834
  }
801
835
  }
802
836
  });
@@ -832,7 +866,7 @@ const handleInit = (preferences) => {
832
866
  .catch(error);
833
867
  };
834
868
 
835
- const handleUser = (key, value, options) => {
869
+ const handleUser = (key, value, providers, options) => {
836
870
  if (!key || !value) {
837
871
  error('Key or Value is missing in user API.');
838
872
  return;
@@ -840,24 +874,25 @@ const handleUser = (key, value, options) => {
840
874
  saveKV({
841
875
  [key]: value,
842
876
  });
877
+ const providerPackages = getProvidersPackage();
878
+ const userId = handleGetUserId();
879
+ if (providerPackages) {
880
+ Object.values(providerPackages).forEach((pkg) => {
881
+ if (!pkg || !pkg.user || !allowProviderWithConsent(providers, pkg.name)) {
882
+ return;
883
+ }
884
+ pkg.user({
885
+ userId,
886
+ data: { [key]: value },
887
+ });
888
+ });
889
+ }
843
890
  postRequest(getUserURL(), {
844
891
  key,
845
892
  value,
846
893
  }, options).catch(error);
847
894
  };
848
895
 
849
- const handleGetData = (keys, callback) => {
850
- if (!keys || keys.length === 0) {
851
- error('Provide keys for get data API.');
852
- return;
853
- }
854
- getRequest(getGetDataURL(keys))
855
- .then((result) => {
856
- callback((result === null || result === void 0 ? void 0 : result.result) || {});
857
- })
858
- .catch(error);
859
- };
860
-
861
896
  const handleKeys = (callback) => {
862
897
  getRequest(getKeysURL())
863
898
  .then((result) => {
@@ -875,11 +910,11 @@ const tag = (name, data, providers, options) => {
875
910
  const consent = (consent) => {
876
911
  handleConsent(consent);
877
912
  };
878
- const user = (key, value, options) => {
879
- handleUser(key, value, options);
913
+ const user = (key, value, providers, options) => {
914
+ handleUser(key, value, providers, options);
880
915
  };
881
- const data = (data, options) => {
882
- handleData(data, options);
916
+ const data = (data, providers, options) => {
917
+ handleData(data, providers, options);
883
918
  };
884
919
  const getData = (keys, callback) => {
885
920
  handleGetData(keys, callback);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "0.7.3",
3
+ "version": "0.8.0",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",