@blotoutio/edgetag-sdk-js 0.72.0 → 1.1.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 +49 -35
- package/index.mjs +49 -35
- package/internal.d.ts +2 -0
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -42,25 +42,6 @@ const hasUserConsent = (consent, provider, tagName) => {
|
|
|
42
42
|
}
|
|
43
43
|
return allowed;
|
|
44
44
|
};
|
|
45
|
-
/**
|
|
46
|
-
* This function validates user consent for a given provider type, not based on tagName.
|
|
47
|
-
*/
|
|
48
|
-
const hasUserConsentForProvider = (consent, provider) => {
|
|
49
|
-
if (!isRecord(consent)) {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
let allowed = isBool(consent.all) ? consent.all : false;
|
|
53
|
-
if (provider in consent) {
|
|
54
|
-
const providerSpecific = consent[provider];
|
|
55
|
-
if (isBool(providerSpecific)) {
|
|
56
|
-
allowed = providerSpecific;
|
|
57
|
-
}
|
|
58
|
-
else if (isRecord(providerSpecific)) {
|
|
59
|
-
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return allowed;
|
|
63
|
-
};
|
|
64
45
|
/**
|
|
65
46
|
* This function validates provider allowance for a given provider and tag name.
|
|
66
47
|
* It should not be used to validate `UserConsent`.
|
|
@@ -564,6 +545,7 @@ const areEqual = (a, b) => {
|
|
|
564
545
|
|
|
565
546
|
const tagStorage = 'edgeTag';
|
|
566
547
|
const consentKey = 'consent';
|
|
548
|
+
const consentCategoriesKey = 'consentCategories';
|
|
567
549
|
const keyPrefix = `_worker`;
|
|
568
550
|
const cookieKey = 'tag_user_id';
|
|
569
551
|
const fallbackSessionKey = 'fallback_tag_user_id';
|
|
@@ -851,7 +833,7 @@ const getStandardPayload = (destination, payload) => {
|
|
|
851
833
|
referrer: getReferrer(destination),
|
|
852
834
|
search: getSearch(destination),
|
|
853
835
|
locale: getLocale(),
|
|
854
|
-
sdkVersion: "
|
|
836
|
+
sdkVersion: "1.1.0" ,
|
|
855
837
|
...(payload || {}),
|
|
856
838
|
};
|
|
857
839
|
let storage = {};
|
|
@@ -941,6 +923,13 @@ const getConsent$1 = (destination) => {
|
|
|
941
923
|
}
|
|
942
924
|
return getSetting(destination, 'consent');
|
|
943
925
|
};
|
|
926
|
+
const getConsentCategories = (destination) => {
|
|
927
|
+
const storageConsentCategories = getDataPerKey(destination, 'local', tagStorage, consentCategoriesKey);
|
|
928
|
+
if (storageConsentCategories) {
|
|
929
|
+
return storageConsentCategories;
|
|
930
|
+
}
|
|
931
|
+
return getSetting(destination, 'consentCategories');
|
|
932
|
+
};
|
|
944
933
|
|
|
945
934
|
const processStubs = (destination) => {
|
|
946
935
|
try {
|
|
@@ -1180,37 +1169,42 @@ const handleData = (data, providers, options) => {
|
|
|
1180
1169
|
});
|
|
1181
1170
|
};
|
|
1182
1171
|
|
|
1183
|
-
const handleConsent = (consent, options) => {
|
|
1172
|
+
const handleConsent = (consent, consentCategories, options) => {
|
|
1184
1173
|
if (options === null || options === void 0 ? void 0 : options.destination) {
|
|
1185
|
-
processConsent(options.destination, consent, options);
|
|
1174
|
+
processConsent(options.destination, consent, consentCategories, options);
|
|
1186
1175
|
return;
|
|
1187
1176
|
}
|
|
1188
1177
|
getInstances().forEach((destination) => {
|
|
1189
|
-
processConsent(destination, consent, options);
|
|
1178
|
+
processConsent(destination, consent, consentCategories, options);
|
|
1190
1179
|
});
|
|
1191
1180
|
};
|
|
1192
|
-
const saveConsent = (destination, consent) => {
|
|
1181
|
+
const saveConsent = (destination, consent, consentCategories) => {
|
|
1193
1182
|
setSetting(destination, {
|
|
1194
1183
|
consent,
|
|
1184
|
+
consentCategories,
|
|
1195
1185
|
});
|
|
1196
1186
|
savePerKey(destination, 'local', tagStorage, consent, consentKey);
|
|
1187
|
+
savePerKey(destination, 'local', tagStorage, consentCategories, consentCategoriesKey);
|
|
1197
1188
|
};
|
|
1198
|
-
const processConsent = (destination, consent, options) => {
|
|
1189
|
+
const processConsent = (destination, consent, consentCategories, options) => {
|
|
1199
1190
|
const existingConsent = getConsent$1(destination);
|
|
1200
|
-
|
|
1191
|
+
const existingConsentCategories = getConsentCategories(destination);
|
|
1192
|
+
if (areEqual(existingConsent, consent) &&
|
|
1193
|
+
areEqual(existingConsentCategories, consentCategories)) {
|
|
1201
1194
|
return;
|
|
1202
1195
|
}
|
|
1203
1196
|
if (!getSetting(destination, 'initialized')) {
|
|
1204
1197
|
addStub(destination, {
|
|
1205
1198
|
name: 'consent',
|
|
1206
|
-
arguments: [consent, options],
|
|
1199
|
+
arguments: [consent, consentCategories, options],
|
|
1207
1200
|
});
|
|
1208
1201
|
return;
|
|
1209
1202
|
}
|
|
1210
1203
|
const payload = {
|
|
1211
1204
|
consentString: consent,
|
|
1205
|
+
consentCategories: { ...consentCategories, necessary: true },
|
|
1212
1206
|
};
|
|
1213
|
-
saveConsent(destination, consent);
|
|
1207
|
+
saveConsent(destination, consent, consentCategories);
|
|
1214
1208
|
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
1215
1209
|
postRequest(getConsentURL(destination), payload).catch(logger.error);
|
|
1216
1210
|
}
|
|
@@ -1250,6 +1244,10 @@ const processConsent = (destination, consent, options) => {
|
|
|
1250
1244
|
executionContext,
|
|
1251
1245
|
session: null,
|
|
1252
1246
|
destination,
|
|
1247
|
+
consentData: {
|
|
1248
|
+
consent,
|
|
1249
|
+
categories: { ...consentCategories, necessary: true },
|
|
1250
|
+
},
|
|
1253
1251
|
});
|
|
1254
1252
|
}
|
|
1255
1253
|
}
|
|
@@ -1270,9 +1268,17 @@ const processConsent = (destination, consent, options) => {
|
|
|
1270
1268
|
if (!pkg || !pkg.name || !pkg.consent) {
|
|
1271
1269
|
continue;
|
|
1272
1270
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1271
|
+
const variables = getProviderVariables(destination, pkg.name);
|
|
1272
|
+
pkg.consent({
|
|
1273
|
+
consentData: {
|
|
1274
|
+
consent,
|
|
1275
|
+
categories: {
|
|
1276
|
+
...consentCategories,
|
|
1277
|
+
necessary: true,
|
|
1278
|
+
},
|
|
1279
|
+
},
|
|
1280
|
+
variables,
|
|
1281
|
+
});
|
|
1276
1282
|
}
|
|
1277
1283
|
};
|
|
1278
1284
|
|
|
@@ -1454,6 +1460,10 @@ const handleManifest = (destination, response) => {
|
|
|
1454
1460
|
keyName,
|
|
1455
1461
|
executionContext,
|
|
1456
1462
|
destination,
|
|
1463
|
+
consentData: {
|
|
1464
|
+
consent: response.consent,
|
|
1465
|
+
categories: response.consentCategories,
|
|
1466
|
+
},
|
|
1457
1467
|
});
|
|
1458
1468
|
}
|
|
1459
1469
|
}
|
|
@@ -1497,7 +1507,11 @@ const handleInit = (preferences) => {
|
|
|
1497
1507
|
const url = new URL(getInitURL(preferences.edgeURL));
|
|
1498
1508
|
if (preferences.disableConsentCheck) {
|
|
1499
1509
|
url.searchParams.set('consentDisabled', 'true');
|
|
1500
|
-
saveConsent(preferences.edgeURL, {
|
|
1510
|
+
saveConsent(preferences.edgeURL, {
|
|
1511
|
+
all: true,
|
|
1512
|
+
}, {
|
|
1513
|
+
all: true,
|
|
1514
|
+
});
|
|
1501
1515
|
}
|
|
1502
1516
|
if (preferences.userId) {
|
|
1503
1517
|
setSetting(preferences.edgeURL, { userId: preferences.userId });
|
|
@@ -1518,7 +1532,7 @@ const handleInit = (preferences) => {
|
|
|
1518
1532
|
return;
|
|
1519
1533
|
}
|
|
1520
1534
|
if (result.isNewUser && result.consent) {
|
|
1521
|
-
saveConsent(preferences.edgeURL, result.consent);
|
|
1535
|
+
saveConsent(preferences.edgeURL, result.consent, result.consentCategories);
|
|
1522
1536
|
}
|
|
1523
1537
|
const providers = {};
|
|
1524
1538
|
(_a = result.result) === null || _a === void 0 ? void 0 : _a.forEach((pkg) => {
|
|
@@ -1710,8 +1724,8 @@ const init = (preferences) => {
|
|
|
1710
1724
|
const tag = (name, data, providers, options) => {
|
|
1711
1725
|
handleTag(name, data, providers, options);
|
|
1712
1726
|
};
|
|
1713
|
-
const consent = (value, options) => {
|
|
1714
|
-
handleConsent(value, options);
|
|
1727
|
+
const consent = (value, consentCategories, options) => {
|
|
1728
|
+
handleConsent(value, consentCategories, options);
|
|
1715
1729
|
};
|
|
1716
1730
|
const user = (key, value, providers, options) => {
|
|
1717
1731
|
handleUser(key, value, providers, options);
|
package/index.mjs
CHANGED
|
@@ -40,25 +40,6 @@ const hasUserConsent = (consent, provider, tagName) => {
|
|
|
40
40
|
}
|
|
41
41
|
return allowed;
|
|
42
42
|
};
|
|
43
|
-
/**
|
|
44
|
-
* This function validates user consent for a given provider type, not based on tagName.
|
|
45
|
-
*/
|
|
46
|
-
const hasUserConsentForProvider = (consent, provider) => {
|
|
47
|
-
if (!isRecord(consent)) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
let allowed = isBool(consent.all) ? consent.all : false;
|
|
51
|
-
if (provider in consent) {
|
|
52
|
-
const providerSpecific = consent[provider];
|
|
53
|
-
if (isBool(providerSpecific)) {
|
|
54
|
-
allowed = providerSpecific;
|
|
55
|
-
}
|
|
56
|
-
else if (isRecord(providerSpecific)) {
|
|
57
|
-
return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return allowed;
|
|
61
|
-
};
|
|
62
43
|
/**
|
|
63
44
|
* This function validates provider allowance for a given provider and tag name.
|
|
64
45
|
* It should not be used to validate `UserConsent`.
|
|
@@ -562,6 +543,7 @@ const areEqual = (a, b) => {
|
|
|
562
543
|
|
|
563
544
|
const tagStorage = 'edgeTag';
|
|
564
545
|
const consentKey = 'consent';
|
|
546
|
+
const consentCategoriesKey = 'consentCategories';
|
|
565
547
|
const keyPrefix = `_worker`;
|
|
566
548
|
const cookieKey = 'tag_user_id';
|
|
567
549
|
const fallbackSessionKey = 'fallback_tag_user_id';
|
|
@@ -849,7 +831,7 @@ const getStandardPayload = (destination, payload) => {
|
|
|
849
831
|
referrer: getReferrer(destination),
|
|
850
832
|
search: getSearch(destination),
|
|
851
833
|
locale: getLocale(),
|
|
852
|
-
sdkVersion: "
|
|
834
|
+
sdkVersion: "1.1.0" ,
|
|
853
835
|
...(payload || {}),
|
|
854
836
|
};
|
|
855
837
|
let storage = {};
|
|
@@ -939,6 +921,13 @@ const getConsent$1 = (destination) => {
|
|
|
939
921
|
}
|
|
940
922
|
return getSetting(destination, 'consent');
|
|
941
923
|
};
|
|
924
|
+
const getConsentCategories = (destination) => {
|
|
925
|
+
const storageConsentCategories = getDataPerKey(destination, 'local', tagStorage, consentCategoriesKey);
|
|
926
|
+
if (storageConsentCategories) {
|
|
927
|
+
return storageConsentCategories;
|
|
928
|
+
}
|
|
929
|
+
return getSetting(destination, 'consentCategories');
|
|
930
|
+
};
|
|
942
931
|
|
|
943
932
|
const processStubs = (destination) => {
|
|
944
933
|
try {
|
|
@@ -1178,37 +1167,42 @@ const handleData = (data, providers, options) => {
|
|
|
1178
1167
|
});
|
|
1179
1168
|
};
|
|
1180
1169
|
|
|
1181
|
-
const handleConsent = (consent, options) => {
|
|
1170
|
+
const handleConsent = (consent, consentCategories, options) => {
|
|
1182
1171
|
if (options === null || options === void 0 ? void 0 : options.destination) {
|
|
1183
|
-
processConsent(options.destination, consent, options);
|
|
1172
|
+
processConsent(options.destination, consent, consentCategories, options);
|
|
1184
1173
|
return;
|
|
1185
1174
|
}
|
|
1186
1175
|
getInstances().forEach((destination) => {
|
|
1187
|
-
processConsent(destination, consent, options);
|
|
1176
|
+
processConsent(destination, consent, consentCategories, options);
|
|
1188
1177
|
});
|
|
1189
1178
|
};
|
|
1190
|
-
const saveConsent = (destination, consent) => {
|
|
1179
|
+
const saveConsent = (destination, consent, consentCategories) => {
|
|
1191
1180
|
setSetting(destination, {
|
|
1192
1181
|
consent,
|
|
1182
|
+
consentCategories,
|
|
1193
1183
|
});
|
|
1194
1184
|
savePerKey(destination, 'local', tagStorage, consent, consentKey);
|
|
1185
|
+
savePerKey(destination, 'local', tagStorage, consentCategories, consentCategoriesKey);
|
|
1195
1186
|
};
|
|
1196
|
-
const processConsent = (destination, consent, options) => {
|
|
1187
|
+
const processConsent = (destination, consent, consentCategories, options) => {
|
|
1197
1188
|
const existingConsent = getConsent$1(destination);
|
|
1198
|
-
|
|
1189
|
+
const existingConsentCategories = getConsentCategories(destination);
|
|
1190
|
+
if (areEqual(existingConsent, consent) &&
|
|
1191
|
+
areEqual(existingConsentCategories, consentCategories)) {
|
|
1199
1192
|
return;
|
|
1200
1193
|
}
|
|
1201
1194
|
if (!getSetting(destination, 'initialized')) {
|
|
1202
1195
|
addStub(destination, {
|
|
1203
1196
|
name: 'consent',
|
|
1204
|
-
arguments: [consent, options],
|
|
1197
|
+
arguments: [consent, consentCategories, options],
|
|
1205
1198
|
});
|
|
1206
1199
|
return;
|
|
1207
1200
|
}
|
|
1208
1201
|
const payload = {
|
|
1209
1202
|
consentString: consent,
|
|
1203
|
+
consentCategories: { ...consentCategories, necessary: true },
|
|
1210
1204
|
};
|
|
1211
|
-
saveConsent(destination, consent);
|
|
1205
|
+
saveConsent(destination, consent, consentCategories);
|
|
1212
1206
|
if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
|
|
1213
1207
|
postRequest(getConsentURL(destination), payload).catch(logger.error);
|
|
1214
1208
|
}
|
|
@@ -1248,6 +1242,10 @@ const processConsent = (destination, consent, options) => {
|
|
|
1248
1242
|
executionContext,
|
|
1249
1243
|
session: null,
|
|
1250
1244
|
destination,
|
|
1245
|
+
consentData: {
|
|
1246
|
+
consent,
|
|
1247
|
+
categories: { ...consentCategories, necessary: true },
|
|
1248
|
+
},
|
|
1251
1249
|
});
|
|
1252
1250
|
}
|
|
1253
1251
|
}
|
|
@@ -1268,9 +1266,17 @@ const processConsent = (destination, consent, options) => {
|
|
|
1268
1266
|
if (!pkg || !pkg.name || !pkg.consent) {
|
|
1269
1267
|
continue;
|
|
1270
1268
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1269
|
+
const variables = getProviderVariables(destination, pkg.name);
|
|
1270
|
+
pkg.consent({
|
|
1271
|
+
consentData: {
|
|
1272
|
+
consent,
|
|
1273
|
+
categories: {
|
|
1274
|
+
...consentCategories,
|
|
1275
|
+
necessary: true,
|
|
1276
|
+
},
|
|
1277
|
+
},
|
|
1278
|
+
variables,
|
|
1279
|
+
});
|
|
1274
1280
|
}
|
|
1275
1281
|
};
|
|
1276
1282
|
|
|
@@ -1452,6 +1458,10 @@ const handleManifest = (destination, response) => {
|
|
|
1452
1458
|
keyName,
|
|
1453
1459
|
executionContext,
|
|
1454
1460
|
destination,
|
|
1461
|
+
consentData: {
|
|
1462
|
+
consent: response.consent,
|
|
1463
|
+
categories: response.consentCategories,
|
|
1464
|
+
},
|
|
1455
1465
|
});
|
|
1456
1466
|
}
|
|
1457
1467
|
}
|
|
@@ -1495,7 +1505,11 @@ const handleInit = (preferences) => {
|
|
|
1495
1505
|
const url = new URL(getInitURL(preferences.edgeURL));
|
|
1496
1506
|
if (preferences.disableConsentCheck) {
|
|
1497
1507
|
url.searchParams.set('consentDisabled', 'true');
|
|
1498
|
-
saveConsent(preferences.edgeURL, {
|
|
1508
|
+
saveConsent(preferences.edgeURL, {
|
|
1509
|
+
all: true,
|
|
1510
|
+
}, {
|
|
1511
|
+
all: true,
|
|
1512
|
+
});
|
|
1499
1513
|
}
|
|
1500
1514
|
if (preferences.userId) {
|
|
1501
1515
|
setSetting(preferences.edgeURL, { userId: preferences.userId });
|
|
@@ -1516,7 +1530,7 @@ const handleInit = (preferences) => {
|
|
|
1516
1530
|
return;
|
|
1517
1531
|
}
|
|
1518
1532
|
if (result.isNewUser && result.consent) {
|
|
1519
|
-
saveConsent(preferences.edgeURL, result.consent);
|
|
1533
|
+
saveConsent(preferences.edgeURL, result.consent, result.consentCategories);
|
|
1520
1534
|
}
|
|
1521
1535
|
const providers = {};
|
|
1522
1536
|
(_a = result.result) === null || _a === void 0 ? void 0 : _a.forEach((pkg) => {
|
|
@@ -1708,8 +1722,8 @@ const init = (preferences) => {
|
|
|
1708
1722
|
const tag = (name, data, providers, options) => {
|
|
1709
1723
|
handleTag(name, data, providers, options);
|
|
1710
1724
|
};
|
|
1711
|
-
const consent = (value, options) => {
|
|
1712
|
-
handleConsent(value, options);
|
|
1725
|
+
const consent = (value, consentCategories, options) => {
|
|
1726
|
+
handleConsent(value, consentCategories, options);
|
|
1713
1727
|
};
|
|
1714
1728
|
const user = (key, value, providers, options) => {
|
|
1715
1729
|
handleUser(key, value, providers, options);
|
package/internal.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
Library,
|
|
4
4
|
ProvidersConfig,
|
|
5
5
|
UserConsent,
|
|
6
|
+
UserConsentCategories,
|
|
6
7
|
} from '@blotoutio/cdn/types'
|
|
7
8
|
import { UserKey, Data, Manifest } from './index'
|
|
8
9
|
|
|
@@ -51,6 +52,7 @@ type InitResponse = {
|
|
|
51
52
|
userId?: string
|
|
52
53
|
storageId?: number
|
|
53
54
|
consent: UserConsent
|
|
55
|
+
consentCategories: UserConsentCategories
|
|
54
56
|
consentSetting: ConsentSetting
|
|
55
57
|
isNewUser?: boolean
|
|
56
58
|
session: {
|