@blotoutio/edgetag-sdk-browser 0.72.0 → 1.0.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.
Files changed (2) hide show
  1. package/index.js +49 -35
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -43,25 +43,6 @@
43
43
  }
44
44
  return allowed;
45
45
  };
46
- /**
47
- * This function validates user consent for a given provider type, not based on tagName.
48
- */
49
- const hasUserConsentForProvider = (consent, provider) => {
50
- if (!isRecord(consent)) {
51
- return false;
52
- }
53
- let allowed = isBool(consent.all) ? consent.all : false;
54
- if (provider in consent) {
55
- const providerSpecific = consent[provider];
56
- if (isBool(providerSpecific)) {
57
- allowed = providerSpecific;
58
- }
59
- else if (isRecord(providerSpecific)) {
60
- return Object.keys(providerSpecific).some((instance) => providerSpecific[instance] === true);
61
- }
62
- }
63
- return allowed;
64
- };
65
46
  /**
66
47
  * This function validates provider allowance for a given provider and tag name.
67
48
  * It should not be used to validate `UserConsent`.
@@ -565,6 +546,7 @@
565
546
 
566
547
  const tagStorage = 'edgeTag';
567
548
  const consentKey = 'consent';
549
+ const consentCategoriesKey = 'consentCategories';
568
550
  const keyPrefix = `_worker`;
569
551
  const cookieKey = 'tag_user_id';
570
552
  const fallbackSessionKey = 'fallback_tag_user_id';
@@ -852,7 +834,7 @@
852
834
  referrer: getReferrer(destination),
853
835
  search: getSearch(destination),
854
836
  locale: getLocale(),
855
- sdkVersion: "0.72.0" ,
837
+ sdkVersion: "1.0.0" ,
856
838
  ...(payload || {}),
857
839
  };
858
840
  let storage = {};
@@ -942,6 +924,13 @@
942
924
  }
943
925
  return getSetting(destination, 'consent');
944
926
  };
927
+ const getConsentCategories = (destination) => {
928
+ const storageConsentCategories = getDataPerKey(destination, 'local', tagStorage, consentCategoriesKey);
929
+ if (storageConsentCategories) {
930
+ return storageConsentCategories;
931
+ }
932
+ return getSetting(destination, 'consentCategories');
933
+ };
945
934
 
946
935
  const processStubs = (destination) => {
947
936
  try {
@@ -1181,37 +1170,42 @@
1181
1170
  });
1182
1171
  };
1183
1172
 
1184
- const handleConsent = (consent, options) => {
1173
+ const handleConsent = (consent, consentCategories, options) => {
1185
1174
  if (options === null || options === void 0 ? void 0 : options.destination) {
1186
- processConsent(options.destination, consent, options);
1175
+ processConsent(options.destination, consent, consentCategories, options);
1187
1176
  return;
1188
1177
  }
1189
1178
  getInstances().forEach((destination) => {
1190
- processConsent(destination, consent, options);
1179
+ processConsent(destination, consent, consentCategories, options);
1191
1180
  });
1192
1181
  };
1193
- const saveConsent = (destination, consent) => {
1182
+ const saveConsent = (destination, consent, consentCategories) => {
1194
1183
  setSetting(destination, {
1195
1184
  consent,
1185
+ consentCategories,
1196
1186
  });
1197
1187
  savePerKey(destination, 'local', tagStorage, consent, consentKey);
1188
+ savePerKey(destination, 'local', tagStorage, consentCategories, consentCategoriesKey);
1198
1189
  };
1199
- const processConsent = (destination, consent, options) => {
1190
+ const processConsent = (destination, consent, consentCategories, options) => {
1200
1191
  const existingConsent = getConsent$1(destination);
1201
- if (areEqual(existingConsent, consent)) {
1192
+ const existingConsentCategories = getConsentCategories(destination);
1193
+ if (areEqual(existingConsent, consent) &&
1194
+ areEqual(existingConsentCategories, consentCategories)) {
1202
1195
  return;
1203
1196
  }
1204
1197
  if (!getSetting(destination, 'initialized')) {
1205
1198
  addStub(destination, {
1206
1199
  name: 'consent',
1207
- arguments: [consent, options],
1200
+ arguments: [consent, consentCategories, options],
1208
1201
  });
1209
1202
  return;
1210
1203
  }
1211
1204
  const payload = {
1212
1205
  consentString: consent,
1206
+ consentCategories: { ...consentCategories, necessary: true },
1213
1207
  };
1214
- saveConsent(destination, consent);
1208
+ saveConsent(destination, consent, consentCategories);
1215
1209
  if (!(options === null || options === void 0 ? void 0 : options.localSave)) {
1216
1210
  postRequest(getConsentURL(destination), payload).catch(logger.error);
1217
1211
  }
@@ -1251,6 +1245,10 @@
1251
1245
  executionContext,
1252
1246
  session: null,
1253
1247
  destination,
1248
+ consentData: {
1249
+ consent,
1250
+ categories: { ...consentCategories, necessary: true },
1251
+ },
1254
1252
  });
1255
1253
  }
1256
1254
  }
@@ -1271,9 +1269,17 @@
1271
1269
  if (!pkg || !pkg.name || !pkg.consent) {
1272
1270
  continue;
1273
1271
  }
1274
- /* Returns True if any one instance of given provider has consent */
1275
- const hasConsent = hasUserConsentForProvider(consent, pkg.name);
1276
- pkg.consent({ hasConsent });
1272
+ const variables = getProviderVariables(destination, pkg.name);
1273
+ pkg.consent({
1274
+ consentData: {
1275
+ consent,
1276
+ categories: {
1277
+ ...consentCategories,
1278
+ necessary: true,
1279
+ },
1280
+ },
1281
+ variables,
1282
+ });
1277
1283
  }
1278
1284
  };
1279
1285
 
@@ -1455,6 +1461,10 @@
1455
1461
  keyName,
1456
1462
  executionContext,
1457
1463
  destination,
1464
+ consentData: {
1465
+ consent: response.consent,
1466
+ categories: response.consentCategories,
1467
+ },
1458
1468
  });
1459
1469
  }
1460
1470
  }
@@ -1498,7 +1508,11 @@
1498
1508
  const url = new URL(getInitURL(preferences.edgeURL));
1499
1509
  if (preferences.disableConsentCheck) {
1500
1510
  url.searchParams.set('consentDisabled', 'true');
1501
- saveConsent(preferences.edgeURL, { all: true });
1511
+ saveConsent(preferences.edgeURL, {
1512
+ all: true,
1513
+ }, {
1514
+ all: true,
1515
+ });
1502
1516
  }
1503
1517
  if (preferences.userId) {
1504
1518
  setSetting(preferences.edgeURL, { userId: preferences.userId });
@@ -1519,7 +1533,7 @@
1519
1533
  return;
1520
1534
  }
1521
1535
  if (result.isNewUser && result.consent) {
1522
- saveConsent(preferences.edgeURL, result.consent);
1536
+ saveConsent(preferences.edgeURL, result.consent, result.consentCategories);
1523
1537
  }
1524
1538
  const providers = {};
1525
1539
  (_a = result.result) === null || _a === void 0 ? void 0 : _a.forEach((pkg) => {
@@ -1711,8 +1725,8 @@
1711
1725
  const tag = (name, data, providers, options) => {
1712
1726
  handleTag(name, data, providers, options);
1713
1727
  };
1714
- const consent = (value, options) => {
1715
- handleConsent(value, options);
1728
+ const consent = (value, consentCategories, options) => {
1729
+ handleConsent(value, consentCategories, options);
1716
1730
  };
1717
1731
  const user = (key, value, providers, options) => {
1718
1732
  handleUser(key, value, providers, options);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "0.72.0",
3
+ "version": "1.0.0",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",