@blotoutio/edgetag-sdk-js 0.26.0 → 0.26.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 +151 -153
  2. package/index.esm.js +151 -153
  3. package/package.json +1 -1
package/index.cjs CHANGED
@@ -323,7 +323,7 @@ const getStandardPayload = (payload) => {
323
323
  referrer: getReferrer(),
324
324
  search: getSearch(),
325
325
  locale: getLocale(),
326
- sdkVersion: "0.26.0" ,
326
+ sdkVersion: "0.26.2" ,
327
327
  ...(payload || {}),
328
328
  };
329
329
  let storage = {};
@@ -431,7 +431,64 @@ const getConsent = () => {
431
431
  return memoryConsent;
432
432
  };
433
433
 
434
- const allowedProvider = new Set();
434
+ const isBool = (v) => typeof v == 'boolean';
435
+ const isRecord = (v) => !!v && typeof v == 'object';
436
+ /**
437
+ * This function validates user consent for a given provider and tag name.
438
+ * It should be used in conjunction with `UserConsent`, not `ProvidersConfig`.
439
+ */
440
+ const hasUserConsent = (consent, provider, tagName) => {
441
+ if (!isRecord(consent)) {
442
+ return false;
443
+ }
444
+ let allowed = isBool(consent.all) ? consent.all : false;
445
+ if (provider in consent) {
446
+ const providerSpecific = consent[provider];
447
+ if (isBool(providerSpecific)) {
448
+ allowed = providerSpecific;
449
+ }
450
+ else if (isRecord(providerSpecific)) {
451
+ if ('all' in providerSpecific && isBool(providerSpecific.all)) {
452
+ allowed = providerSpecific.all;
453
+ }
454
+ if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
455
+ allowed = providerSpecific[tagName];
456
+ }
457
+ }
458
+ }
459
+ return allowed;
460
+ };
461
+ /**
462
+ * This function validates provider allowance for a given provider and tag name.
463
+ * It should not be used to validate `UserConsent`.
464
+ */
465
+ const isProviderInstanceAllowed = (providersConfig, provider, tagName) => {
466
+ if (!isRecord(providersConfig)) {
467
+ return true;
468
+ }
469
+ let allowed = isBool(providersConfig.all) ? providersConfig.all : true;
470
+ if (provider in providersConfig) {
471
+ const providerSpecific = providersConfig[provider];
472
+ if (isBool(providerSpecific)) {
473
+ allowed = providerSpecific;
474
+ }
475
+ else if (isRecord(providerSpecific)) {
476
+ if ('all' in providerSpecific && isBool(providerSpecific.all)) {
477
+ allowed = providerSpecific.all;
478
+ }
479
+ if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
480
+ allowed = providerSpecific[tagName];
481
+ }
482
+ }
483
+ }
484
+ return allowed;
485
+ };
486
+
487
+ const upsert = (map, key, update, createDefault) => {
488
+ const currentValue = map.has(key) ? map.get(key) : createDefault();
489
+ return map.set(key, update(currentValue));
490
+ };
491
+
435
492
  let initialized = false;
436
493
  const providersPackages = {};
437
494
  const setPreferences = (preferences) => {
@@ -471,12 +528,9 @@ const isInitialized = () => initialized;
471
528
  const setInitialized = () => {
472
529
  initialized = true;
473
530
  };
474
- const getAllowedProviders = () => allowedProvider;
475
- const setAllowedProviders = (providers) => {
476
- for (const provider of providers) {
477
- allowedProvider.add(provider);
478
- }
479
- };
531
+ const configuredTags = new Map();
532
+ const addConfiguredTag = (pkg, tagName) => upsert(configuredTags, pkg, (names) => names.add(tagName), () => new Set());
533
+ const getConfiguredTags = () => configuredTags;
480
534
 
481
535
  const manifestVariables = {};
482
536
  const addProviderVariable = (name, variables, tagName) => {
@@ -511,59 +565,6 @@ const processStubs = () => {
511
565
  }
512
566
  };
513
567
 
514
- const isBool = (v) => typeof v == 'boolean';
515
- const isRecord = (v) => !!v && typeof v == 'object';
516
- /**
517
- * This function validates user consent for a given provider and tag name.
518
- * It should be used in conjunction with `UserConsent`, not `ProvidersConfig`.
519
- */
520
- const hasUserConsent = (consent, provider, tagName) => {
521
- if (!isRecord(consent)) {
522
- return false;
523
- }
524
- let allowed = isBool(consent.all) ? consent.all : false;
525
- if (provider in consent) {
526
- const providerSpecific = consent[provider];
527
- if (isBool(providerSpecific)) {
528
- allowed = providerSpecific;
529
- }
530
- else if (isRecord(providerSpecific)) {
531
- if ('all' in providerSpecific && isBool(providerSpecific.all)) {
532
- allowed = providerSpecific.all;
533
- }
534
- if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
535
- allowed = providerSpecific[tagName];
536
- }
537
- }
538
- }
539
- return allowed;
540
- };
541
- /**
542
- * This function validates provider allowance for a given provider and tag name.
543
- * It should not be used to validate `UserConsent`.
544
- */
545
- const isProviderInstanceAllowed = (providersConfig, provider, tagName) => {
546
- if (!isRecord(providersConfig)) {
547
- return true;
548
- }
549
- let allowed = isBool(providersConfig.all) ? providersConfig.all : true;
550
- if (provider in providersConfig) {
551
- const providerSpecific = providersConfig[provider];
552
- if (isBool(providerSpecific)) {
553
- allowed = providerSpecific;
554
- }
555
- else if (isRecord(providerSpecific)) {
556
- if ('all' in providerSpecific && isBool(providerSpecific.all)) {
557
- allowed = providerSpecific.all;
558
- }
559
- if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
560
- allowed = providerSpecific[tagName];
561
- }
562
- }
563
- }
564
- return allowed;
565
- };
566
-
567
568
  const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
568
569
  const payload = {
569
570
  eventName,
@@ -590,48 +591,43 @@ const handleTag = (eventName, data = {}, providers, options) => {
590
591
  eventId = generateEventId(eventName);
591
592
  }
592
593
  const providerPackages = getProvidersPackage();
594
+ const configuredTags = getConfiguredTags();
593
595
  const userId = handleGetUserId();
594
596
  const providerData = {};
595
597
  const consent = getConsent();
596
- const allowedProviders = getAllowedProviders();
597
- let anyProviderCalled = false;
598
- if (providerPackages) {
599
- for (const pkg of Object.values(providerPackages)) {
600
- if (!pkg || !pkg.name || !pkg.tag) {
598
+ for (const pkg of Object.values(providerPackages)) {
599
+ if (!pkg || !pkg.name || !pkg.tag) {
600
+ continue;
601
+ }
602
+ if (!configuredTags.has(pkg.name)) {
603
+ continue;
604
+ }
605
+ const variables = getProviderVariables(pkg.name);
606
+ const result = {};
607
+ const providerVariables = Object.entries(variables);
608
+ const executionContext = new Map();
609
+ for (const [tagName, variableSet] of providerVariables) {
610
+ if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
611
+ log(`Provider instance is not allowed (${pkg.name}: ${tagName})`);
601
612
  continue;
602
613
  }
603
- if (!allowedProviders.has(pkg.name)) {
604
- log(`Provider ${pkg.name} is not in allow list`);
614
+ if (!hasUserConsent(consent, pkg.name, tagName)) {
615
+ log(`Consent is missing (${pkg.name}: ${tagName})`);
605
616
  continue;
606
617
  }
607
- const variables = getProviderVariables(pkg.name);
608
- const result = {};
609
- const providerVariables = Object.entries(variables);
610
- const executionContext = new Map();
611
- for (const [tagName, variableSet] of providerVariables) {
612
- if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
613
- log(`Provider instance is not allowed (${pkg.name}: ${tagName})`);
614
- continue;
615
- }
616
- if (!hasUserConsent(consent, pkg.name, tagName)) {
617
- log(`Consent is missing (${pkg.name}: ${tagName})`);
618
- continue;
619
- }
620
- anyProviderCalled = true;
621
- result[tagName] = pkg.tag({
622
- userId,
623
- eventName,
624
- eventId,
625
- data: JSON.parse(JSON.stringify(data)),
626
- sendTag,
627
- manifestVariables: variableSet,
628
- executionContext,
629
- });
630
- }
631
- providerData[pkg.name] = result;
618
+ result[tagName] = pkg.tag({
619
+ userId,
620
+ eventName,
621
+ eventId,
622
+ data: JSON.parse(JSON.stringify(data)),
623
+ sendTag,
624
+ manifestVariables: variableSet,
625
+ executionContext,
626
+ });
632
627
  }
628
+ providerData[pkg.name] = result;
633
629
  }
634
- if (!anyProviderCalled) {
630
+ if (!hasAllowedManifestTags(configuredTags, consent, providers)) {
635
631
  return;
636
632
  }
637
633
  sendTag({
@@ -643,6 +639,17 @@ const handleTag = (eventName, data = {}, providers, options) => {
643
639
  options,
644
640
  });
645
641
  };
642
+ const hasAllowedManifestTags = (tags, consent, providersConfig) => {
643
+ for (const [pkg, tagNames] of tags) {
644
+ for (const tagName of tagNames) {
645
+ if (hasUserConsent(consent, pkg, tagName) &&
646
+ isProviderInstanceAllowed(providersConfig, pkg, tagName)) {
647
+ return true;
648
+ }
649
+ }
650
+ }
651
+ return false;
652
+ };
646
653
 
647
654
  const handleData = (data, providers, options) => {
648
655
  if (!data || Object.keys(data).length === 0) {
@@ -651,34 +658,31 @@ const handleData = (data, providers, options) => {
651
658
  }
652
659
  saveKV(data);
653
660
  const providerPackages = getProvidersPackage();
661
+ const configuredTags = getConfiguredTags();
654
662
  const userId = handleGetUserId();
655
663
  const consent = getConsent();
656
- const allowedProviders = getAllowedProviders();
657
- if (providerPackages) {
658
- for (const pkg of Object.values(providerPackages)) {
659
- if (!pkg || !pkg.user || !pkg.name) {
664
+ for (const pkg of Object.values(providerPackages)) {
665
+ if (!pkg || !pkg.user || !pkg.name) {
666
+ continue;
667
+ }
668
+ if (!configuredTags.has(pkg.name)) {
669
+ continue;
670
+ }
671
+ const variables = getProviderVariables(pkg.name);
672
+ for (const [tagName, variableSet] of Object.entries(variables)) {
673
+ if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
674
+ log(`Data not allowed for ${pkg.name} (${tagName})`);
660
675
  continue;
661
676
  }
662
- if (!allowedProviders.has(pkg.name)) {
663
- log(`Provider ${pkg.name} is not in allow list`);
677
+ if (!hasUserConsent(consent, pkg.name, tagName)) {
678
+ log(`Consent is missing for ${pkg.name} (${tagName})`);
664
679
  continue;
665
680
  }
666
- const variables = getProviderVariables(pkg.name);
667
- for (const [tagName, variableSet] of Object.entries(variables)) {
668
- if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
669
- log(`Data not allowed for ${pkg.name} (${tagName})`);
670
- continue;
671
- }
672
- if (!hasUserConsent(consent, pkg.name, tagName)) {
673
- log(`Consent is missing for ${pkg.name} (${tagName})`);
674
- continue;
675
- }
676
- pkg.user({
677
- userId,
678
- data,
679
- manifestVariables: variableSet,
680
- });
681
- }
681
+ pkg.user({
682
+ userId,
683
+ data,
684
+ manifestVariables: variableSet,
685
+ });
682
686
  }
683
687
  }
684
688
  postRequest(getDataURL(), { data, providers }, options).catch(error);
@@ -781,8 +785,8 @@ const handleGetData = (keys, callback) => {
781
785
  const handleManifest = (manifest) => {
782
786
  const providerPackages = getProvidersPackage();
783
787
  const userId = handleGetUserId();
784
- setAllowedProviders(manifest.map((provider) => provider.package));
785
788
  manifest.forEach((provider) => {
789
+ addConfiguredTag(provider.package, provider.tagName);
786
790
  addProviderVariable(provider.package, provider.variables, provider.tagName);
787
791
  if (provider.rules) {
788
792
  Object.entries(provider.rules).forEach(([name, recipe]) => {
@@ -794,18 +798,16 @@ const handleManifest = (manifest) => {
794
798
  }
795
799
  });
796
800
  }
797
- if (providerPackages) {
798
- const pkg = providerPackages[provider.package];
799
- if (pkg && pkg.name && pkg.init) {
800
- pkg.init({
801
- userId,
802
- manifest: provider,
803
- sendTag,
804
- sendEdgeData: handleData,
805
- getEdgeData: handleGetData,
806
- keyName: `${keyPrefix}Store`,
807
- });
808
- }
801
+ const pkg = providerPackages[provider.package];
802
+ if (pkg && pkg.name && pkg.init) {
803
+ pkg.init({
804
+ userId,
805
+ manifest: provider,
806
+ sendTag,
807
+ sendEdgeData: handleData,
808
+ getEdgeData: handleGetData,
809
+ keyName: `${keyPrefix}Store`,
810
+ });
809
811
  }
810
812
  });
811
813
  setInitialized();
@@ -855,36 +857,32 @@ const handleUser = (key, value, providers, options) => {
855
857
  saveKV({
856
858
  [key]: value,
857
859
  });
858
- const consent = getConsent();
859
- const allowedProviders = getAllowedProviders();
860
860
  const providerPackages = getProvidersPackage();
861
+ const configuredTags = getConfiguredTags();
862
+ const consent = getConsent();
861
863
  const userId = handleGetUserId();
862
- if (providerPackages) {
863
- for (const pkg of Object.values(providerPackages)) {
864
- if (!pkg || !pkg.name || !pkg.user) {
864
+ for (const pkg of Object.values(providerPackages)) {
865
+ if (!pkg || !pkg.name || !pkg.user) {
866
+ continue;
867
+ }
868
+ if (!configuredTags.has(pkg.name)) {
869
+ continue;
870
+ }
871
+ const variables = getProviderVariables(pkg.name);
872
+ for (const [tagName, variableSet] of Object.entries(variables)) {
873
+ if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
874
+ log(`User not allowed for ${pkg.name} (${tagName})`);
865
875
  continue;
866
876
  }
867
- if (!allowedProviders.has(pkg.name)) {
868
- log(`Provider ${pkg.name} is not in allow list`);
877
+ if (!hasUserConsent(consent, pkg.name, tagName)) {
878
+ log(`User doesn't have consent for ${pkg.name} (${tagName})`);
869
879
  continue;
870
880
  }
871
- const variables = getProviderVariables(pkg.name);
872
- for (const [tagName, variableSet] of Object.entries(variables)) {
873
- if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
874
- // should we be logging this?
875
- log(`User not allowed for ${pkg.name} (${tagName})`);
876
- continue;
877
- }
878
- if (!hasUserConsent(consent, pkg.name, tagName)) {
879
- log(`User doesn't have consent for ${pkg.name} (${tagName})`);
880
- continue;
881
- }
882
- pkg.user({
883
- userId,
884
- data: { [key]: value },
885
- manifestVariables: variableSet,
886
- });
887
- }
881
+ pkg.user({
882
+ userId,
883
+ data: { [key]: value },
884
+ manifestVariables: variableSet,
885
+ });
888
886
  }
889
887
  }
890
888
  postRequest(getUserURL(), {
package/index.esm.js CHANGED
@@ -321,7 +321,7 @@ const getStandardPayload = (payload) => {
321
321
  referrer: getReferrer(),
322
322
  search: getSearch(),
323
323
  locale: getLocale(),
324
- sdkVersion: "0.26.0" ,
324
+ sdkVersion: "0.26.2" ,
325
325
  ...(payload || {}),
326
326
  };
327
327
  let storage = {};
@@ -429,7 +429,64 @@ const getConsent = () => {
429
429
  return memoryConsent;
430
430
  };
431
431
 
432
- const allowedProvider = new Set();
432
+ const isBool = (v) => typeof v == 'boolean';
433
+ const isRecord = (v) => !!v && typeof v == 'object';
434
+ /**
435
+ * This function validates user consent for a given provider and tag name.
436
+ * It should be used in conjunction with `UserConsent`, not `ProvidersConfig`.
437
+ */
438
+ const hasUserConsent = (consent, provider, tagName) => {
439
+ if (!isRecord(consent)) {
440
+ return false;
441
+ }
442
+ let allowed = isBool(consent.all) ? consent.all : false;
443
+ if (provider in consent) {
444
+ const providerSpecific = consent[provider];
445
+ if (isBool(providerSpecific)) {
446
+ allowed = providerSpecific;
447
+ }
448
+ else if (isRecord(providerSpecific)) {
449
+ if ('all' in providerSpecific && isBool(providerSpecific.all)) {
450
+ allowed = providerSpecific.all;
451
+ }
452
+ if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
453
+ allowed = providerSpecific[tagName];
454
+ }
455
+ }
456
+ }
457
+ return allowed;
458
+ };
459
+ /**
460
+ * This function validates provider allowance for a given provider and tag name.
461
+ * It should not be used to validate `UserConsent`.
462
+ */
463
+ const isProviderInstanceAllowed = (providersConfig, provider, tagName) => {
464
+ if (!isRecord(providersConfig)) {
465
+ return true;
466
+ }
467
+ let allowed = isBool(providersConfig.all) ? providersConfig.all : true;
468
+ if (provider in providersConfig) {
469
+ const providerSpecific = providersConfig[provider];
470
+ if (isBool(providerSpecific)) {
471
+ allowed = providerSpecific;
472
+ }
473
+ else if (isRecord(providerSpecific)) {
474
+ if ('all' in providerSpecific && isBool(providerSpecific.all)) {
475
+ allowed = providerSpecific.all;
476
+ }
477
+ if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
478
+ allowed = providerSpecific[tagName];
479
+ }
480
+ }
481
+ }
482
+ return allowed;
483
+ };
484
+
485
+ const upsert = (map, key, update, createDefault) => {
486
+ const currentValue = map.has(key) ? map.get(key) : createDefault();
487
+ return map.set(key, update(currentValue));
488
+ };
489
+
433
490
  let initialized = false;
434
491
  const providersPackages = {};
435
492
  const setPreferences = (preferences) => {
@@ -469,12 +526,9 @@ const isInitialized = () => initialized;
469
526
  const setInitialized = () => {
470
527
  initialized = true;
471
528
  };
472
- const getAllowedProviders = () => allowedProvider;
473
- const setAllowedProviders = (providers) => {
474
- for (const provider of providers) {
475
- allowedProvider.add(provider);
476
- }
477
- };
529
+ const configuredTags = new Map();
530
+ const addConfiguredTag = (pkg, tagName) => upsert(configuredTags, pkg, (names) => names.add(tagName), () => new Set());
531
+ const getConfiguredTags = () => configuredTags;
478
532
 
479
533
  const manifestVariables = {};
480
534
  const addProviderVariable = (name, variables, tagName) => {
@@ -509,59 +563,6 @@ const processStubs = () => {
509
563
  }
510
564
  };
511
565
 
512
- const isBool = (v) => typeof v == 'boolean';
513
- const isRecord = (v) => !!v && typeof v == 'object';
514
- /**
515
- * This function validates user consent for a given provider and tag name.
516
- * It should be used in conjunction with `UserConsent`, not `ProvidersConfig`.
517
- */
518
- const hasUserConsent = (consent, provider, tagName) => {
519
- if (!isRecord(consent)) {
520
- return false;
521
- }
522
- let allowed = isBool(consent.all) ? consent.all : false;
523
- if (provider in consent) {
524
- const providerSpecific = consent[provider];
525
- if (isBool(providerSpecific)) {
526
- allowed = providerSpecific;
527
- }
528
- else if (isRecord(providerSpecific)) {
529
- if ('all' in providerSpecific && isBool(providerSpecific.all)) {
530
- allowed = providerSpecific.all;
531
- }
532
- if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
533
- allowed = providerSpecific[tagName];
534
- }
535
- }
536
- }
537
- return allowed;
538
- };
539
- /**
540
- * This function validates provider allowance for a given provider and tag name.
541
- * It should not be used to validate `UserConsent`.
542
- */
543
- const isProviderInstanceAllowed = (providersConfig, provider, tagName) => {
544
- if (!isRecord(providersConfig)) {
545
- return true;
546
- }
547
- let allowed = isBool(providersConfig.all) ? providersConfig.all : true;
548
- if (provider in providersConfig) {
549
- const providerSpecific = providersConfig[provider];
550
- if (isBool(providerSpecific)) {
551
- allowed = providerSpecific;
552
- }
553
- else if (isRecord(providerSpecific)) {
554
- if ('all' in providerSpecific && isBool(providerSpecific.all)) {
555
- allowed = providerSpecific.all;
556
- }
557
- if (tagName in providerSpecific && isBool(providerSpecific[tagName])) {
558
- allowed = providerSpecific[tagName];
559
- }
560
- }
561
- }
562
- return allowed;
563
- };
564
-
565
566
  const sendTag = ({ eventName, eventId, data, providerData, providers, options, }) => {
566
567
  const payload = {
567
568
  eventName,
@@ -588,48 +589,43 @@ const handleTag = (eventName, data = {}, providers, options) => {
588
589
  eventId = generateEventId(eventName);
589
590
  }
590
591
  const providerPackages = getProvidersPackage();
592
+ const configuredTags = getConfiguredTags();
591
593
  const userId = handleGetUserId();
592
594
  const providerData = {};
593
595
  const consent = getConsent();
594
- const allowedProviders = getAllowedProviders();
595
- let anyProviderCalled = false;
596
- if (providerPackages) {
597
- for (const pkg of Object.values(providerPackages)) {
598
- if (!pkg || !pkg.name || !pkg.tag) {
596
+ for (const pkg of Object.values(providerPackages)) {
597
+ if (!pkg || !pkg.name || !pkg.tag) {
598
+ continue;
599
+ }
600
+ if (!configuredTags.has(pkg.name)) {
601
+ continue;
602
+ }
603
+ const variables = getProviderVariables(pkg.name);
604
+ const result = {};
605
+ const providerVariables = Object.entries(variables);
606
+ const executionContext = new Map();
607
+ for (const [tagName, variableSet] of providerVariables) {
608
+ if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
609
+ log(`Provider instance is not allowed (${pkg.name}: ${tagName})`);
599
610
  continue;
600
611
  }
601
- if (!allowedProviders.has(pkg.name)) {
602
- log(`Provider ${pkg.name} is not in allow list`);
612
+ if (!hasUserConsent(consent, pkg.name, tagName)) {
613
+ log(`Consent is missing (${pkg.name}: ${tagName})`);
603
614
  continue;
604
615
  }
605
- const variables = getProviderVariables(pkg.name);
606
- const result = {};
607
- const providerVariables = Object.entries(variables);
608
- const executionContext = new Map();
609
- for (const [tagName, variableSet] of providerVariables) {
610
- if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
611
- log(`Provider instance is not allowed (${pkg.name}: ${tagName})`);
612
- continue;
613
- }
614
- if (!hasUserConsent(consent, pkg.name, tagName)) {
615
- log(`Consent is missing (${pkg.name}: ${tagName})`);
616
- continue;
617
- }
618
- anyProviderCalled = true;
619
- result[tagName] = pkg.tag({
620
- userId,
621
- eventName,
622
- eventId,
623
- data: JSON.parse(JSON.stringify(data)),
624
- sendTag,
625
- manifestVariables: variableSet,
626
- executionContext,
627
- });
628
- }
629
- providerData[pkg.name] = result;
616
+ result[tagName] = pkg.tag({
617
+ userId,
618
+ eventName,
619
+ eventId,
620
+ data: JSON.parse(JSON.stringify(data)),
621
+ sendTag,
622
+ manifestVariables: variableSet,
623
+ executionContext,
624
+ });
630
625
  }
626
+ providerData[pkg.name] = result;
631
627
  }
632
- if (!anyProviderCalled) {
628
+ if (!hasAllowedManifestTags(configuredTags, consent, providers)) {
633
629
  return;
634
630
  }
635
631
  sendTag({
@@ -641,6 +637,17 @@ const handleTag = (eventName, data = {}, providers, options) => {
641
637
  options,
642
638
  });
643
639
  };
640
+ const hasAllowedManifestTags = (tags, consent, providersConfig) => {
641
+ for (const [pkg, tagNames] of tags) {
642
+ for (const tagName of tagNames) {
643
+ if (hasUserConsent(consent, pkg, tagName) &&
644
+ isProviderInstanceAllowed(providersConfig, pkg, tagName)) {
645
+ return true;
646
+ }
647
+ }
648
+ }
649
+ return false;
650
+ };
644
651
 
645
652
  const handleData = (data, providers, options) => {
646
653
  if (!data || Object.keys(data).length === 0) {
@@ -649,34 +656,31 @@ const handleData = (data, providers, options) => {
649
656
  }
650
657
  saveKV(data);
651
658
  const providerPackages = getProvidersPackage();
659
+ const configuredTags = getConfiguredTags();
652
660
  const userId = handleGetUserId();
653
661
  const consent = getConsent();
654
- const allowedProviders = getAllowedProviders();
655
- if (providerPackages) {
656
- for (const pkg of Object.values(providerPackages)) {
657
- if (!pkg || !pkg.user || !pkg.name) {
662
+ for (const pkg of Object.values(providerPackages)) {
663
+ if (!pkg || !pkg.user || !pkg.name) {
664
+ continue;
665
+ }
666
+ if (!configuredTags.has(pkg.name)) {
667
+ continue;
668
+ }
669
+ const variables = getProviderVariables(pkg.name);
670
+ for (const [tagName, variableSet] of Object.entries(variables)) {
671
+ if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
672
+ log(`Data not allowed for ${pkg.name} (${tagName})`);
658
673
  continue;
659
674
  }
660
- if (!allowedProviders.has(pkg.name)) {
661
- log(`Provider ${pkg.name} is not in allow list`);
675
+ if (!hasUserConsent(consent, pkg.name, tagName)) {
676
+ log(`Consent is missing for ${pkg.name} (${tagName})`);
662
677
  continue;
663
678
  }
664
- const variables = getProviderVariables(pkg.name);
665
- for (const [tagName, variableSet] of Object.entries(variables)) {
666
- if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
667
- log(`Data not allowed for ${pkg.name} (${tagName})`);
668
- continue;
669
- }
670
- if (!hasUserConsent(consent, pkg.name, tagName)) {
671
- log(`Consent is missing for ${pkg.name} (${tagName})`);
672
- continue;
673
- }
674
- pkg.user({
675
- userId,
676
- data,
677
- manifestVariables: variableSet,
678
- });
679
- }
679
+ pkg.user({
680
+ userId,
681
+ data,
682
+ manifestVariables: variableSet,
683
+ });
680
684
  }
681
685
  }
682
686
  postRequest(getDataURL(), { data, providers }, options).catch(error);
@@ -779,8 +783,8 @@ const handleGetData = (keys, callback) => {
779
783
  const handleManifest = (manifest) => {
780
784
  const providerPackages = getProvidersPackage();
781
785
  const userId = handleGetUserId();
782
- setAllowedProviders(manifest.map((provider) => provider.package));
783
786
  manifest.forEach((provider) => {
787
+ addConfiguredTag(provider.package, provider.tagName);
784
788
  addProviderVariable(provider.package, provider.variables, provider.tagName);
785
789
  if (provider.rules) {
786
790
  Object.entries(provider.rules).forEach(([name, recipe]) => {
@@ -792,18 +796,16 @@ const handleManifest = (manifest) => {
792
796
  }
793
797
  });
794
798
  }
795
- if (providerPackages) {
796
- const pkg = providerPackages[provider.package];
797
- if (pkg && pkg.name && pkg.init) {
798
- pkg.init({
799
- userId,
800
- manifest: provider,
801
- sendTag,
802
- sendEdgeData: handleData,
803
- getEdgeData: handleGetData,
804
- keyName: `${keyPrefix}Store`,
805
- });
806
- }
799
+ const pkg = providerPackages[provider.package];
800
+ if (pkg && pkg.name && pkg.init) {
801
+ pkg.init({
802
+ userId,
803
+ manifest: provider,
804
+ sendTag,
805
+ sendEdgeData: handleData,
806
+ getEdgeData: handleGetData,
807
+ keyName: `${keyPrefix}Store`,
808
+ });
807
809
  }
808
810
  });
809
811
  setInitialized();
@@ -853,36 +855,32 @@ const handleUser = (key, value, providers, options) => {
853
855
  saveKV({
854
856
  [key]: value,
855
857
  });
856
- const consent = getConsent();
857
- const allowedProviders = getAllowedProviders();
858
858
  const providerPackages = getProvidersPackage();
859
+ const configuredTags = getConfiguredTags();
860
+ const consent = getConsent();
859
861
  const userId = handleGetUserId();
860
- if (providerPackages) {
861
- for (const pkg of Object.values(providerPackages)) {
862
- if (!pkg || !pkg.name || !pkg.user) {
862
+ for (const pkg of Object.values(providerPackages)) {
863
+ if (!pkg || !pkg.name || !pkg.user) {
864
+ continue;
865
+ }
866
+ if (!configuredTags.has(pkg.name)) {
867
+ continue;
868
+ }
869
+ const variables = getProviderVariables(pkg.name);
870
+ for (const [tagName, variableSet] of Object.entries(variables)) {
871
+ if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
872
+ log(`User not allowed for ${pkg.name} (${tagName})`);
863
873
  continue;
864
874
  }
865
- if (!allowedProviders.has(pkg.name)) {
866
- log(`Provider ${pkg.name} is not in allow list`);
875
+ if (!hasUserConsent(consent, pkg.name, tagName)) {
876
+ log(`User doesn't have consent for ${pkg.name} (${tagName})`);
867
877
  continue;
868
878
  }
869
- const variables = getProviderVariables(pkg.name);
870
- for (const [tagName, variableSet] of Object.entries(variables)) {
871
- if (!isProviderInstanceAllowed(providers, pkg.name, tagName)) {
872
- // should we be logging this?
873
- log(`User not allowed for ${pkg.name} (${tagName})`);
874
- continue;
875
- }
876
- if (!hasUserConsent(consent, pkg.name, tagName)) {
877
- log(`User doesn't have consent for ${pkg.name} (${tagName})`);
878
- continue;
879
- }
880
- pkg.user({
881
- userId,
882
- data: { [key]: value },
883
- manifestVariables: variableSet,
884
- });
885
- }
879
+ pkg.user({
880
+ userId,
881
+ data: { [key]: value },
882
+ manifestVariables: variableSet,
883
+ });
886
884
  }
887
885
  }
888
886
  postRequest(getUserURL(), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-js",
3
- "version": "0.26.0",
3
+ "version": "0.26.2",
4
4
  "description": "JS SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",