@blotoutio/edgetag-sdk-js 0.35.2 → 0.36.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 +118 -54
- package/index.d.ts +16 -63
- package/index.mjs +118 -54
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -335,7 +335,7 @@ const getStandardPayload = (payload) => {
|
|
|
335
335
|
referrer: getReferrer(),
|
|
336
336
|
search: getSearch(),
|
|
337
337
|
locale: getLocale(),
|
|
338
|
-
sdkVersion: "0.
|
|
338
|
+
sdkVersion: "0.36.0" ,
|
|
339
339
|
...(payload || {}),
|
|
340
340
|
};
|
|
341
341
|
let storage = {};
|
|
@@ -422,31 +422,6 @@ const getKeysURL = () => {
|
|
|
422
422
|
return generateUrl(`/keys`);
|
|
423
423
|
};
|
|
424
424
|
|
|
425
|
-
let memoryConsent;
|
|
426
|
-
const saveConsent = (consent) => {
|
|
427
|
-
setConsent(consent);
|
|
428
|
-
savePerKey('local', tagStorage, consent, consentKey);
|
|
429
|
-
};
|
|
430
|
-
const handleConsent = (consent, options) => {
|
|
431
|
-
const payload = {
|
|
432
|
-
consentString: consent,
|
|
433
|
-
};
|
|
434
|
-
saveConsent(consent);
|
|
435
|
-
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
436
|
-
postRequest(getConsentURL(), payload).catch(error);
|
|
437
|
-
}
|
|
438
|
-
};
|
|
439
|
-
const setConsent = (newConsent) => {
|
|
440
|
-
memoryConsent = newConsent;
|
|
441
|
-
};
|
|
442
|
-
const getConsent$1 = () => {
|
|
443
|
-
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
|
|
444
|
-
if (storageConsent) {
|
|
445
|
-
return storageConsent;
|
|
446
|
-
}
|
|
447
|
-
return memoryConsent;
|
|
448
|
-
};
|
|
449
|
-
|
|
450
425
|
const isBool = (v) => typeof v == 'boolean';
|
|
451
426
|
const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
|
|
452
427
|
/**
|
|
@@ -474,6 +449,25 @@ const hasUserConsent = (consent, provider, tagName) => {
|
|
|
474
449
|
}
|
|
475
450
|
return allowed;
|
|
476
451
|
};
|
|
452
|
+
/**
|
|
453
|
+
* This function validates user consent for a given provider type, not based on tagName.
|
|
454
|
+
*/
|
|
455
|
+
const hasUserConsentForProvider = (consent, provider) => {
|
|
456
|
+
if (!isRecord(consent)) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
let allowed = isBool(consent.all) ? consent.all : false;
|
|
460
|
+
if (provider in consent) {
|
|
461
|
+
const providerSpecific = consent[provider];
|
|
462
|
+
if (isBool(providerSpecific)) {
|
|
463
|
+
allowed = providerSpecific;
|
|
464
|
+
}
|
|
465
|
+
else if (isRecord(providerSpecific)) {
|
|
466
|
+
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return allowed;
|
|
470
|
+
};
|
|
477
471
|
/**
|
|
478
472
|
* This function validates provider allowance for a given provider and tag name.
|
|
479
473
|
* It should not be used to validate `UserConsent`.
|
|
@@ -673,6 +667,18 @@ const hasAllowedManifestTags = (tags, consent, providersConfig) => {
|
|
|
673
667
|
return false;
|
|
674
668
|
};
|
|
675
669
|
|
|
670
|
+
const handleGetData = (keys, callback) => {
|
|
671
|
+
if (!keys || keys.length === 0) {
|
|
672
|
+
error('Provide keys for get data API.');
|
|
673
|
+
return;
|
|
674
|
+
}
|
|
675
|
+
getRequest(getGetDataURL(keys))
|
|
676
|
+
.then((result) => {
|
|
677
|
+
callback((result === null || result === void 0 ? void 0 : result.result) || {});
|
|
678
|
+
})
|
|
679
|
+
.catch(error);
|
|
680
|
+
};
|
|
681
|
+
|
|
676
682
|
const handleData = (data, providers, options) => {
|
|
677
683
|
if (!data || Object.keys(data).length === 0) {
|
|
678
684
|
error('Provide data for data API.');
|
|
@@ -711,7 +717,72 @@ const handleData = (data, providers, options) => {
|
|
|
711
717
|
postRequest(getDataURL(), { data, providers }, options).catch(error);
|
|
712
718
|
};
|
|
713
719
|
|
|
720
|
+
let memoryConsent;
|
|
721
|
+
const saveConsent = (consent) => {
|
|
722
|
+
setConsent(consent);
|
|
723
|
+
savePerKey('local', tagStorage, consent, consentKey);
|
|
724
|
+
};
|
|
725
|
+
const handleConsent = (consent, options) => {
|
|
726
|
+
const payload = {
|
|
727
|
+
consentString: consent,
|
|
728
|
+
};
|
|
729
|
+
saveConsent(consent);
|
|
730
|
+
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
731
|
+
postRequest(getConsentURL(), payload).catch(error);
|
|
732
|
+
}
|
|
733
|
+
const userId = handleGetUserId();
|
|
734
|
+
const providerPackages = getProvidersPackage();
|
|
735
|
+
const executionContext = new Map();
|
|
736
|
+
/* Calling Init for all provider instances based on consent check */
|
|
737
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
738
|
+
if (!pkg || !pkg.name || !pkg.init) {
|
|
739
|
+
continue;
|
|
740
|
+
}
|
|
741
|
+
const variables = getProviderVariables(pkg.name);
|
|
742
|
+
const providerVariables = Object.entries(variables);
|
|
743
|
+
for (const [tagName, variablesSet] of providerVariables) {
|
|
744
|
+
const hasConsent = hasUserConsent(consent, pkg.name, tagName);
|
|
745
|
+
if (!hasConsent) {
|
|
746
|
+
continue;
|
|
747
|
+
}
|
|
748
|
+
pkg.init({
|
|
749
|
+
userId,
|
|
750
|
+
manifest: {
|
|
751
|
+
tagName,
|
|
752
|
+
variables: variablesSet,
|
|
753
|
+
package: pkg.name,
|
|
754
|
+
},
|
|
755
|
+
sendTag,
|
|
756
|
+
sendEdgeData: handleData,
|
|
757
|
+
getEdgeData: handleGetData,
|
|
758
|
+
keyName: `${keyPrefix}Store`,
|
|
759
|
+
executionContext,
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
/* Calling Consent for all providers, not on instance level */
|
|
764
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
765
|
+
if (!pkg || !pkg.name || !pkg.consent) {
|
|
766
|
+
continue;
|
|
767
|
+
}
|
|
768
|
+
/* Returns True if any one instance of given provider has consent */
|
|
769
|
+
const hasConsent = hasUserConsentForProvider(consent, pkg.name);
|
|
770
|
+
pkg.consent({ hasConsent });
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
const setConsent = (newConsent) => {
|
|
774
|
+
memoryConsent = newConsent;
|
|
775
|
+
};
|
|
776
|
+
const getConsent$1 = () => {
|
|
777
|
+
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
|
|
778
|
+
if (storageConsent) {
|
|
779
|
+
return storageConsent;
|
|
780
|
+
}
|
|
781
|
+
return memoryConsent;
|
|
782
|
+
};
|
|
783
|
+
|
|
714
784
|
const cacheKey = `${keyPrefix}Cache`;
|
|
785
|
+
const identity = (v) => v;
|
|
715
786
|
const saveDataToEdge = (key, value, provider) => {
|
|
716
787
|
if (!value) {
|
|
717
788
|
return;
|
|
@@ -727,7 +798,7 @@ const saveDataToEdge = (key, value, provider) => {
|
|
|
727
798
|
}
|
|
728
799
|
handleData({ [`${provider}::${key}`]: value });
|
|
729
800
|
};
|
|
730
|
-
const handleCaptureQuery = (provider, key, persistType) => {
|
|
801
|
+
const handleCaptureQuery = (provider, key, persistType, map) => {
|
|
731
802
|
try {
|
|
732
803
|
if (!window) {
|
|
733
804
|
return;
|
|
@@ -740,7 +811,7 @@ const handleCaptureQuery = (provider, key, persistType) => {
|
|
|
740
811
|
if (!params || !params.get(key)) {
|
|
741
812
|
return;
|
|
742
813
|
}
|
|
743
|
-
const data = params.get(key);
|
|
814
|
+
const data = (map !== null && map !== void 0 ? map : identity)(params.get(key));
|
|
744
815
|
if (!data) {
|
|
745
816
|
return;
|
|
746
817
|
}
|
|
@@ -765,82 +836,74 @@ const saveToCache = (persistType, provider, key, value) => {
|
|
|
765
836
|
}
|
|
766
837
|
saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
|
|
767
838
|
};
|
|
768
|
-
const handleCaptureStorage = (provider, key, persistType, location) => {
|
|
839
|
+
const handleCaptureStorage = (provider, key, persistType, location, map) => {
|
|
769
840
|
let data;
|
|
770
841
|
try {
|
|
771
842
|
switch (location) {
|
|
772
843
|
case 'cookie': {
|
|
773
|
-
data = getCookieValue(key);
|
|
844
|
+
data = (map !== null && map !== void 0 ? map : identity)(getCookieValue(key));
|
|
774
845
|
break;
|
|
775
846
|
}
|
|
776
847
|
case 'local': {
|
|
777
|
-
data = localStorage.getItem(key);
|
|
848
|
+
data = (map !== null && map !== void 0 ? map : identity)(localStorage.getItem(key));
|
|
778
849
|
break;
|
|
779
850
|
}
|
|
780
851
|
case 'session': {
|
|
781
|
-
data = sessionStorage.getItem(key);
|
|
852
|
+
data = (map !== null && map !== void 0 ? map : identity)(sessionStorage.getItem(key));
|
|
782
853
|
}
|
|
783
854
|
}
|
|
784
855
|
}
|
|
785
856
|
catch {
|
|
786
857
|
return;
|
|
787
858
|
}
|
|
788
|
-
const cachedValue = getFromCache(persistType, provider, key);
|
|
789
|
-
saveToCache(persistType, provider, key, data);
|
|
790
859
|
if (!data) {
|
|
791
860
|
return;
|
|
792
861
|
}
|
|
862
|
+
const cachedKey = `${handleGetUserId()}/${key}`;
|
|
863
|
+
const cachedValue = getFromCache(persistType, provider, cachedKey);
|
|
793
864
|
if (persistType === 'edge' && cachedValue !== data) {
|
|
794
865
|
saveDataToEdge(key, data, provider);
|
|
866
|
+
saveToCache(persistType, provider, cachedKey, data);
|
|
795
867
|
return;
|
|
796
868
|
}
|
|
797
869
|
saveDataPerKey(persistType, provider, data, key);
|
|
798
870
|
};
|
|
799
|
-
const handleCapture = (provider, params) => {
|
|
871
|
+
const handleCapture = (provider, params, capture) => {
|
|
800
872
|
params.forEach((param) => {
|
|
801
873
|
switch (param.type) {
|
|
802
874
|
case 'query': {
|
|
803
|
-
handleCaptureQuery(provider, param.key, param.persist);
|
|
875
|
+
handleCaptureQuery(provider, param.key, param.persist, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
|
|
804
876
|
break;
|
|
805
877
|
}
|
|
806
878
|
case 'storage': {
|
|
807
|
-
handleCaptureStorage(provider, param.key, param.persist, param.location);
|
|
879
|
+
handleCaptureStorage(provider, param.key, param.persist, param.location, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
|
|
808
880
|
break;
|
|
809
881
|
}
|
|
810
882
|
}
|
|
811
883
|
});
|
|
812
884
|
};
|
|
813
885
|
|
|
814
|
-
const
|
|
815
|
-
if (!keys || keys.length === 0) {
|
|
816
|
-
error('Provide keys for get data API.');
|
|
817
|
-
return;
|
|
818
|
-
}
|
|
819
|
-
getRequest(getGetDataURL(keys))
|
|
820
|
-
.then((result) => {
|
|
821
|
-
callback((result === null || result === void 0 ? void 0 : result.result) || {});
|
|
822
|
-
})
|
|
823
|
-
.catch(error);
|
|
824
|
-
};
|
|
825
|
-
|
|
826
|
-
const handleManifest = (manifest) => {
|
|
886
|
+
const handleManifest = (manifest, consent) => {
|
|
827
887
|
const providerPackages = getProvidersPackage();
|
|
828
888
|
const userId = handleGetUserId();
|
|
889
|
+
const executionContext = new Map();
|
|
829
890
|
manifest.forEach((provider) => {
|
|
830
891
|
addConfiguredTag(provider.package, provider.tagName);
|
|
831
892
|
addProviderVariable(provider.package, provider.variables, provider.tagName);
|
|
893
|
+
const pkg = providerPackages[provider.package];
|
|
832
894
|
if (provider.rules) {
|
|
833
895
|
Object.entries(provider.rules).forEach(([name, recipe]) => {
|
|
834
896
|
switch (name) {
|
|
835
897
|
case 'capture': {
|
|
836
|
-
handleCapture(provider.package, recipe);
|
|
898
|
+
handleCapture(provider.package, recipe, pkg === null || pkg === void 0 ? void 0 : pkg.capture);
|
|
837
899
|
return;
|
|
838
900
|
}
|
|
839
901
|
}
|
|
840
902
|
});
|
|
841
903
|
}
|
|
842
|
-
|
|
843
|
-
|
|
904
|
+
/* this defines if the consent is given for a specific instance of a provider */
|
|
905
|
+
const hasConsent = hasUserConsent(consent, pkg.name, provider.tagName);
|
|
906
|
+
if (pkg && pkg.name && pkg.init && hasConsent) {
|
|
844
907
|
pkg.init({
|
|
845
908
|
userId,
|
|
846
909
|
manifest: provider,
|
|
@@ -848,6 +911,7 @@ const handleManifest = (manifest) => {
|
|
|
848
911
|
sendEdgeData: handleData,
|
|
849
912
|
getEdgeData: handleGetData,
|
|
850
913
|
keyName: `${keyPrefix}Store`,
|
|
914
|
+
executionContext,
|
|
851
915
|
});
|
|
852
916
|
}
|
|
853
917
|
});
|
|
@@ -885,7 +949,7 @@ const handleInit = (preferences) => {
|
|
|
885
949
|
if (result.consent && !consent) {
|
|
886
950
|
saveConsent(result.consent);
|
|
887
951
|
}
|
|
888
|
-
handleManifest(result.result);
|
|
952
|
+
handleManifest(result.result, consent || result.consent);
|
|
889
953
|
})
|
|
890
954
|
.catch(error);
|
|
891
955
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,64 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export type
|
|
15
|
-
eventName: string
|
|
16
|
-
eventId: string
|
|
17
|
-
data: Data
|
|
18
|
-
providerData?: Partial<Record<Library, Record<string, Data>>>
|
|
19
|
-
providers?: Possibly<ProvidersConfig>
|
|
20
|
-
options?: EventOptions
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
type ManifestRule = {
|
|
24
|
-
type: string
|
|
25
|
-
key: string
|
|
26
|
-
persist: PersistType
|
|
27
|
-
location?: string
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
type Manifest = {
|
|
31
|
-
package: Library
|
|
32
|
-
tagName: string
|
|
33
|
-
variables?: Record<string, string>
|
|
34
|
-
rules: Record<string, ManifestRule[]>
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
type InitParams = {
|
|
38
|
-
userId: string
|
|
39
|
-
manifest: Manifest
|
|
40
|
-
sendTag: (params: SendTag) => void
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
type TagParams = {
|
|
44
|
-
userId: string
|
|
45
|
-
eventId: string
|
|
46
|
-
eventName: string
|
|
47
|
-
data: Data
|
|
48
|
-
manifestVariables: Record<string, string>
|
|
49
|
-
sendTag: (params: SendTag) => void
|
|
50
|
-
executionContext: Map<string, unknown>
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
type ProviderInit = {
|
|
54
|
-
name?: Library
|
|
55
|
-
init?: (params: InitParams) => void
|
|
56
|
-
tag?: (params: TagParams) => unknown
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// end TODO
|
|
60
|
-
|
|
61
|
-
type UserKey =
|
|
1
|
+
import { ProvidersConfig } from '@blotoutio/cdn/types'
|
|
2
|
+
export {
|
|
3
|
+
InitParams,
|
|
4
|
+
TagParams,
|
|
5
|
+
ManifestRule,
|
|
6
|
+
Manifest,
|
|
7
|
+
ProviderInit,
|
|
8
|
+
SendTag,
|
|
9
|
+
Data,
|
|
10
|
+
EventOptions,
|
|
11
|
+
PersistType,
|
|
12
|
+
} from '@blotoutio/shared/utility-sdk'
|
|
13
|
+
|
|
14
|
+
export type UserKey =
|
|
62
15
|
| 'email'
|
|
63
16
|
| 'phone'
|
|
64
17
|
| 'firstName'
|
|
@@ -71,9 +24,9 @@ type UserKey =
|
|
|
71
24
|
| 'zip'
|
|
72
25
|
| 'address'
|
|
73
26
|
|
|
74
|
-
type Stub = { name: string; arguments: unknown[] }
|
|
27
|
+
export type Stub = { name: string; arguments: unknown[] }
|
|
75
28
|
|
|
76
|
-
type InitPreferences = {
|
|
29
|
+
export type InitPreferences = {
|
|
77
30
|
edgeURL: string
|
|
78
31
|
disableConsentCheck?: boolean
|
|
79
32
|
userId?: string
|
package/index.mjs
CHANGED
|
@@ -333,7 +333,7 @@ const getStandardPayload = (payload) => {
|
|
|
333
333
|
referrer: getReferrer(),
|
|
334
334
|
search: getSearch(),
|
|
335
335
|
locale: getLocale(),
|
|
336
|
-
sdkVersion: "0.
|
|
336
|
+
sdkVersion: "0.36.0" ,
|
|
337
337
|
...(payload || {}),
|
|
338
338
|
};
|
|
339
339
|
let storage = {};
|
|
@@ -420,31 +420,6 @@ const getKeysURL = () => {
|
|
|
420
420
|
return generateUrl(`/keys`);
|
|
421
421
|
};
|
|
422
422
|
|
|
423
|
-
let memoryConsent;
|
|
424
|
-
const saveConsent = (consent) => {
|
|
425
|
-
setConsent(consent);
|
|
426
|
-
savePerKey('local', tagStorage, consent, consentKey);
|
|
427
|
-
};
|
|
428
|
-
const handleConsent = (consent, options) => {
|
|
429
|
-
const payload = {
|
|
430
|
-
consentString: consent,
|
|
431
|
-
};
|
|
432
|
-
saveConsent(consent);
|
|
433
|
-
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
434
|
-
postRequest(getConsentURL(), payload).catch(error);
|
|
435
|
-
}
|
|
436
|
-
};
|
|
437
|
-
const setConsent = (newConsent) => {
|
|
438
|
-
memoryConsent = newConsent;
|
|
439
|
-
};
|
|
440
|
-
const getConsent$1 = () => {
|
|
441
|
-
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
|
|
442
|
-
if (storageConsent) {
|
|
443
|
-
return storageConsent;
|
|
444
|
-
}
|
|
445
|
-
return memoryConsent;
|
|
446
|
-
};
|
|
447
|
-
|
|
448
423
|
const isBool = (v) => typeof v == 'boolean';
|
|
449
424
|
const isRecord = (v) => !!v && typeof v == 'object' && !Array.isArray(v);
|
|
450
425
|
/**
|
|
@@ -472,6 +447,25 @@ const hasUserConsent = (consent, provider, tagName) => {
|
|
|
472
447
|
}
|
|
473
448
|
return allowed;
|
|
474
449
|
};
|
|
450
|
+
/**
|
|
451
|
+
* This function validates user consent for a given provider type, not based on tagName.
|
|
452
|
+
*/
|
|
453
|
+
const hasUserConsentForProvider = (consent, provider) => {
|
|
454
|
+
if (!isRecord(consent)) {
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
let allowed = isBool(consent.all) ? consent.all : false;
|
|
458
|
+
if (provider in consent) {
|
|
459
|
+
const providerSpecific = consent[provider];
|
|
460
|
+
if (isBool(providerSpecific)) {
|
|
461
|
+
allowed = providerSpecific;
|
|
462
|
+
}
|
|
463
|
+
else if (isRecord(providerSpecific)) {
|
|
464
|
+
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
return allowed;
|
|
468
|
+
};
|
|
475
469
|
/**
|
|
476
470
|
* This function validates provider allowance for a given provider and tag name.
|
|
477
471
|
* It should not be used to validate `UserConsent`.
|
|
@@ -671,6 +665,18 @@ const hasAllowedManifestTags = (tags, consent, providersConfig) => {
|
|
|
671
665
|
return false;
|
|
672
666
|
};
|
|
673
667
|
|
|
668
|
+
const handleGetData = (keys, callback) => {
|
|
669
|
+
if (!keys || keys.length === 0) {
|
|
670
|
+
error('Provide keys for get data API.');
|
|
671
|
+
return;
|
|
672
|
+
}
|
|
673
|
+
getRequest(getGetDataURL(keys))
|
|
674
|
+
.then((result) => {
|
|
675
|
+
callback((result === null || result === void 0 ? void 0 : result.result) || {});
|
|
676
|
+
})
|
|
677
|
+
.catch(error);
|
|
678
|
+
};
|
|
679
|
+
|
|
674
680
|
const handleData = (data, providers, options) => {
|
|
675
681
|
if (!data || Object.keys(data).length === 0) {
|
|
676
682
|
error('Provide data for data API.');
|
|
@@ -709,7 +715,72 @@ const handleData = (data, providers, options) => {
|
|
|
709
715
|
postRequest(getDataURL(), { data, providers }, options).catch(error);
|
|
710
716
|
};
|
|
711
717
|
|
|
718
|
+
let memoryConsent;
|
|
719
|
+
const saveConsent = (consent) => {
|
|
720
|
+
setConsent(consent);
|
|
721
|
+
savePerKey('local', tagStorage, consent, consentKey);
|
|
722
|
+
};
|
|
723
|
+
const handleConsent = (consent, options) => {
|
|
724
|
+
const payload = {
|
|
725
|
+
consentString: consent,
|
|
726
|
+
};
|
|
727
|
+
saveConsent(consent);
|
|
728
|
+
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
729
|
+
postRequest(getConsentURL(), payload).catch(error);
|
|
730
|
+
}
|
|
731
|
+
const userId = handleGetUserId();
|
|
732
|
+
const providerPackages = getProvidersPackage();
|
|
733
|
+
const executionContext = new Map();
|
|
734
|
+
/* Calling Init for all provider instances based on consent check */
|
|
735
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
736
|
+
if (!pkg || !pkg.name || !pkg.init) {
|
|
737
|
+
continue;
|
|
738
|
+
}
|
|
739
|
+
const variables = getProviderVariables(pkg.name);
|
|
740
|
+
const providerVariables = Object.entries(variables);
|
|
741
|
+
for (const [tagName, variablesSet] of providerVariables) {
|
|
742
|
+
const hasConsent = hasUserConsent(consent, pkg.name, tagName);
|
|
743
|
+
if (!hasConsent) {
|
|
744
|
+
continue;
|
|
745
|
+
}
|
|
746
|
+
pkg.init({
|
|
747
|
+
userId,
|
|
748
|
+
manifest: {
|
|
749
|
+
tagName,
|
|
750
|
+
variables: variablesSet,
|
|
751
|
+
package: pkg.name,
|
|
752
|
+
},
|
|
753
|
+
sendTag,
|
|
754
|
+
sendEdgeData: handleData,
|
|
755
|
+
getEdgeData: handleGetData,
|
|
756
|
+
keyName: `${keyPrefix}Store`,
|
|
757
|
+
executionContext,
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
/* Calling Consent for all providers, not on instance level */
|
|
762
|
+
for (const pkg of Object.values(providerPackages)) {
|
|
763
|
+
if (!pkg || !pkg.name || !pkg.consent) {
|
|
764
|
+
continue;
|
|
765
|
+
}
|
|
766
|
+
/* Returns True if any one instance of given provider has consent */
|
|
767
|
+
const hasConsent = hasUserConsentForProvider(consent, pkg.name);
|
|
768
|
+
pkg.consent({ hasConsent });
|
|
769
|
+
}
|
|
770
|
+
};
|
|
771
|
+
const setConsent = (newConsent) => {
|
|
772
|
+
memoryConsent = newConsent;
|
|
773
|
+
};
|
|
774
|
+
const getConsent$1 = () => {
|
|
775
|
+
const storageConsent = getDataPerKey('local', tagStorage, consentKey);
|
|
776
|
+
if (storageConsent) {
|
|
777
|
+
return storageConsent;
|
|
778
|
+
}
|
|
779
|
+
return memoryConsent;
|
|
780
|
+
};
|
|
781
|
+
|
|
712
782
|
const cacheKey = `${keyPrefix}Cache`;
|
|
783
|
+
const identity = (v) => v;
|
|
713
784
|
const saveDataToEdge = (key, value, provider) => {
|
|
714
785
|
if (!value) {
|
|
715
786
|
return;
|
|
@@ -725,7 +796,7 @@ const saveDataToEdge = (key, value, provider) => {
|
|
|
725
796
|
}
|
|
726
797
|
handleData({ [`${provider}::${key}`]: value });
|
|
727
798
|
};
|
|
728
|
-
const handleCaptureQuery = (provider, key, persistType) => {
|
|
799
|
+
const handleCaptureQuery = (provider, key, persistType, map) => {
|
|
729
800
|
try {
|
|
730
801
|
if (!window) {
|
|
731
802
|
return;
|
|
@@ -738,7 +809,7 @@ const handleCaptureQuery = (provider, key, persistType) => {
|
|
|
738
809
|
if (!params || !params.get(key)) {
|
|
739
810
|
return;
|
|
740
811
|
}
|
|
741
|
-
const data = params.get(key);
|
|
812
|
+
const data = (map !== null && map !== void 0 ? map : identity)(params.get(key));
|
|
742
813
|
if (!data) {
|
|
743
814
|
return;
|
|
744
815
|
}
|
|
@@ -763,82 +834,74 @@ const saveToCache = (persistType, provider, key, value) => {
|
|
|
763
834
|
}
|
|
764
835
|
saveData(persistType === 'edge' ? 'local' : persistType, cache, cacheKey);
|
|
765
836
|
};
|
|
766
|
-
const handleCaptureStorage = (provider, key, persistType, location) => {
|
|
837
|
+
const handleCaptureStorage = (provider, key, persistType, location, map) => {
|
|
767
838
|
let data;
|
|
768
839
|
try {
|
|
769
840
|
switch (location) {
|
|
770
841
|
case 'cookie': {
|
|
771
|
-
data = getCookieValue(key);
|
|
842
|
+
data = (map !== null && map !== void 0 ? map : identity)(getCookieValue(key));
|
|
772
843
|
break;
|
|
773
844
|
}
|
|
774
845
|
case 'local': {
|
|
775
|
-
data = localStorage.getItem(key);
|
|
846
|
+
data = (map !== null && map !== void 0 ? map : identity)(localStorage.getItem(key));
|
|
776
847
|
break;
|
|
777
848
|
}
|
|
778
849
|
case 'session': {
|
|
779
|
-
data = sessionStorage.getItem(key);
|
|
850
|
+
data = (map !== null && map !== void 0 ? map : identity)(sessionStorage.getItem(key));
|
|
780
851
|
}
|
|
781
852
|
}
|
|
782
853
|
}
|
|
783
854
|
catch {
|
|
784
855
|
return;
|
|
785
856
|
}
|
|
786
|
-
const cachedValue = getFromCache(persistType, provider, key);
|
|
787
|
-
saveToCache(persistType, provider, key, data);
|
|
788
857
|
if (!data) {
|
|
789
858
|
return;
|
|
790
859
|
}
|
|
860
|
+
const cachedKey = `${handleGetUserId()}/${key}`;
|
|
861
|
+
const cachedValue = getFromCache(persistType, provider, cachedKey);
|
|
791
862
|
if (persistType === 'edge' && cachedValue !== data) {
|
|
792
863
|
saveDataToEdge(key, data, provider);
|
|
864
|
+
saveToCache(persistType, provider, cachedKey, data);
|
|
793
865
|
return;
|
|
794
866
|
}
|
|
795
867
|
saveDataPerKey(persistType, provider, data, key);
|
|
796
868
|
};
|
|
797
|
-
const handleCapture = (provider, params) => {
|
|
869
|
+
const handleCapture = (provider, params, capture) => {
|
|
798
870
|
params.forEach((param) => {
|
|
799
871
|
switch (param.type) {
|
|
800
872
|
case 'query': {
|
|
801
|
-
handleCaptureQuery(provider, param.key, param.persist);
|
|
873
|
+
handleCaptureQuery(provider, param.key, param.persist, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
|
|
802
874
|
break;
|
|
803
875
|
}
|
|
804
876
|
case 'storage': {
|
|
805
|
-
handleCaptureStorage(provider, param.key, param.persist, param.location);
|
|
877
|
+
handleCaptureStorage(provider, param.key, param.persist, param.location, capture === null || capture === void 0 ? void 0 : capture.bind(null, param));
|
|
806
878
|
break;
|
|
807
879
|
}
|
|
808
880
|
}
|
|
809
881
|
});
|
|
810
882
|
};
|
|
811
883
|
|
|
812
|
-
const
|
|
813
|
-
if (!keys || keys.length === 0) {
|
|
814
|
-
error('Provide keys for get data API.');
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
|
-
getRequest(getGetDataURL(keys))
|
|
818
|
-
.then((result) => {
|
|
819
|
-
callback((result === null || result === void 0 ? void 0 : result.result) || {});
|
|
820
|
-
})
|
|
821
|
-
.catch(error);
|
|
822
|
-
};
|
|
823
|
-
|
|
824
|
-
const handleManifest = (manifest) => {
|
|
884
|
+
const handleManifest = (manifest, consent) => {
|
|
825
885
|
const providerPackages = getProvidersPackage();
|
|
826
886
|
const userId = handleGetUserId();
|
|
887
|
+
const executionContext = new Map();
|
|
827
888
|
manifest.forEach((provider) => {
|
|
828
889
|
addConfiguredTag(provider.package, provider.tagName);
|
|
829
890
|
addProviderVariable(provider.package, provider.variables, provider.tagName);
|
|
891
|
+
const pkg = providerPackages[provider.package];
|
|
830
892
|
if (provider.rules) {
|
|
831
893
|
Object.entries(provider.rules).forEach(([name, recipe]) => {
|
|
832
894
|
switch (name) {
|
|
833
895
|
case 'capture': {
|
|
834
|
-
handleCapture(provider.package, recipe);
|
|
896
|
+
handleCapture(provider.package, recipe, pkg === null || pkg === void 0 ? void 0 : pkg.capture);
|
|
835
897
|
return;
|
|
836
898
|
}
|
|
837
899
|
}
|
|
838
900
|
});
|
|
839
901
|
}
|
|
840
|
-
|
|
841
|
-
|
|
902
|
+
/* this defines if the consent is given for a specific instance of a provider */
|
|
903
|
+
const hasConsent = hasUserConsent(consent, pkg.name, provider.tagName);
|
|
904
|
+
if (pkg && pkg.name && pkg.init && hasConsent) {
|
|
842
905
|
pkg.init({
|
|
843
906
|
userId,
|
|
844
907
|
manifest: provider,
|
|
@@ -846,6 +909,7 @@ const handleManifest = (manifest) => {
|
|
|
846
909
|
sendEdgeData: handleData,
|
|
847
910
|
getEdgeData: handleGetData,
|
|
848
911
|
keyName: `${keyPrefix}Store`,
|
|
912
|
+
executionContext,
|
|
849
913
|
});
|
|
850
914
|
}
|
|
851
915
|
});
|
|
@@ -883,7 +947,7 @@ const handleInit = (preferences) => {
|
|
|
883
947
|
if (result.consent && !consent) {
|
|
884
948
|
saveConsent(result.consent);
|
|
885
949
|
}
|
|
886
|
-
handleManifest(result.result);
|
|
950
|
+
handleManifest(result.result, consent || result.consent);
|
|
887
951
|
})
|
|
888
952
|
.catch(error);
|
|
889
953
|
};
|