@blotoutio/edgetag-sdk-browser 1.4.0 → 1.6.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 +111 -18
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -379,24 +379,111 @@
379
379
  ['ZM', 'Zambia'],
380
380
  ['ZW', 'Zimbabwe'],
381
381
  ]);
382
- new Set(isoCountries.keys());
382
+ /**
383
+ * ISO-3166 US state ISO codes
384
+ * @see https://en.wikipedia.org/wiki/ISO_3166-2:US
385
+ * */
386
+ const usStates = new Map([
387
+ ['US-AL', 'Alabama'],
388
+ ['US-AK', 'Alaska'],
389
+ ['US-AZ', 'Arizona'],
390
+ ['US-AR', 'Arkansas'],
391
+ ['US-CA', 'California'],
392
+ ['US-CO', 'Colorado'],
393
+ ['US-CT', 'Connecticut'],
394
+ ['US-DE', 'Delaware'],
395
+ ['US-FL', 'Florida'],
396
+ ['US-GA', 'Georgia'],
397
+ ['US-HI', 'Hawaii'],
398
+ ['US-ID', 'Idaho'],
399
+ ['US-IL', 'Illinois'],
400
+ ['US-IN', 'Indiana'],
401
+ ['US-IA', 'Iowa'],
402
+ ['US-KS', 'Kansas'],
403
+ ['US-KY', 'Kentucky'],
404
+ ['US-LA', 'Louisiana'],
405
+ ['US-ME', 'Maine'],
406
+ ['US-MD', 'Maryland'],
407
+ ['US-MA', 'Massachusetts'],
408
+ ['US-MI', 'Michigan'],
409
+ ['US-MN', 'Minnesota'],
410
+ ['US-MS', 'Mississippi'],
411
+ ['US-MO', 'Missouri'],
412
+ ['US-MT', 'Montana'],
413
+ ['US-NE', 'Nebraska'],
414
+ ['US-NV', 'Nevada'],
415
+ ['US-NH', 'New Hampshire'],
416
+ ['US-NJ', 'New Jersey'],
417
+ ['US-NM', 'New Mexico'],
418
+ ['US-NY', 'New York'],
419
+ ['US-NC', 'North Carolina'],
420
+ ['US-ND', 'North Dakota'],
421
+ ['US-OH', 'Ohio'],
422
+ ['US-OK', 'Oklahoma'],
423
+ ['US-OR', 'Oregon'],
424
+ ['US-PA', 'Pennsylvania'],
425
+ ['US-RI', 'Rhode Island'],
426
+ ['US-SC', 'South Carolina'],
427
+ ['US-SD', 'South Dakota'],
428
+ ['US-TN', 'Tennessee'],
429
+ ['US-TX', 'Texas'],
430
+ ['US-UT', 'Utah'],
431
+ ['US-VT', 'Vermont'],
432
+ ['US-VA', 'Virginia'],
433
+ ['US-WA', 'Washington'],
434
+ ['US-WV', 'West Virginia'],
435
+ ['US-WI', 'Wisconsin'],
436
+ ['US-WY', 'Wyoming'],
437
+ ['US-DC', 'District of Columbia'],
438
+ ['US-AS', 'American Samoa'],
439
+ ['US-GU', 'Guam'],
440
+ ['US-MP', 'Northern Mariana Islands'],
441
+ ['US-PR', 'Puerto Rico'],
442
+ ['US-UM', 'United States Minor Outlying Islands'],
443
+ ['US-VI', 'Virgin Islands, U.S.'],
444
+ ]);
445
+ new Set([...isoCountries.keys(), ...usStates.keys()]);
383
446
  const parseCache = new Map();
384
- const doesGeoRequestMatchList = (requestRegion, isEUCountry, geoRegions) => {
385
- if (!requestRegion || !geoRegions) {
447
+ const parseRegions = (regionString) => {
448
+ const include = new Set();
449
+ const exclude = new Set();
450
+ if (regionString) {
451
+ const [a = '', b = ''] = regionString.split('|');
452
+ for (const item of a.split(',')) {
453
+ if (item) {
454
+ include.add(item);
455
+ }
456
+ }
457
+ for (const item of b.split(',')) {
458
+ if (item) {
459
+ exclude.add(item);
460
+ }
461
+ }
462
+ }
463
+ return { include, exclude };
464
+ };
465
+ const doesGeoRequestMatchList = (requestCountry, requestRegion, isEUCountry, geoRegions) => {
466
+ if (!requestCountry || !geoRegions) {
386
467
  return true;
387
468
  }
388
- let parsedRegions = parseCache.get(geoRegions);
389
- if (!parsedRegions) {
390
- parsedRegions = new Set((geoRegions !== null && geoRegions !== void 0 ? geoRegions : '').split(','));
391
- parseCache.set(geoRegions, parsedRegions);
469
+ let parsed = parseCache.get(geoRegions);
470
+ if (!parsed) {
471
+ parsed = parseRegions(geoRegions);
472
+ parseCache.set(geoRegions, parsed);
392
473
  }
393
- if (parsedRegions.size == 0) {
394
- return true;
474
+ const entries = [requestCountry, `${requestCountry}-${requestRegion}`];
475
+ if (isEUCountry) {
476
+ entries.push('EU');
395
477
  }
396
- if (isEUCountry && parsedRegions.has('EU')) {
397
- return true;
478
+ if (parsed.include.size &&
479
+ entries.every((entry) => !parsed.include.has(entry))) {
480
+ return false;
398
481
  }
399
- return parsedRegions.has(requestRegion);
482
+ if (parsed.exclude.size &&
483
+ entries.some((entry) => parsed.exclude.has(entry))) {
484
+ return false;
485
+ }
486
+ return true;
400
487
  };
401
488
 
402
489
  // eslint-disable-next-line @nx/enforce-module-boundaries
@@ -411,6 +498,7 @@
411
498
  stubs: [],
412
499
  browserPackages: [],
413
500
  channels: new Map(),
501
+ geoCountry: null,
414
502
  geoRegion: null,
415
503
  isEURequest: false,
416
504
  ...options,
@@ -834,7 +922,7 @@
834
922
  referrer: getReferrer(destination),
835
923
  search: getSearch(destination),
836
924
  locale: getLocale(),
837
- sdkVersion: "1.4.0" ,
925
+ sdkVersion: "1.6.0" ,
838
926
  ...(payload || {}),
839
927
  };
840
928
  let storage = {};
@@ -1009,6 +1097,7 @@
1009
1097
  const providerPackages = getSetting(destination, 'browserPackages');
1010
1098
  const configuredTags = getSetting(destination, 'channels');
1011
1099
  const skipZeroPurchaseEvent = getSetting(destination, 'skipZeroPurchaseEvent') || false;
1100
+ const requestCountry = getSetting(destination, 'geoCountry') || null;
1012
1101
  const requestRegion = getSetting(destination, 'geoRegion') || null;
1013
1102
  const isEURequest = getSetting(destination, 'isEURequest') || false;
1014
1103
  const userId = getUserId$1(destination);
@@ -1038,7 +1127,7 @@
1038
1127
  logger.log(`Consent is missing (${pkg.name}: ${variable.tagName})`);
1039
1128
  continue;
1040
1129
  }
1041
- if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
1130
+ if (!doesGeoRequestMatchList(requestCountry, requestRegion, isEURequest, variable.geoRegions)) {
1042
1131
  logger.log('GEO request region does not match the filter, skiping');
1043
1132
  continue;
1044
1133
  }
@@ -1123,6 +1212,7 @@
1123
1212
  const configuredTags = getSetting(destination, 'channels');
1124
1213
  const userId = getUserId$1(destination);
1125
1214
  const consent = getConsent$1(destination);
1215
+ const requestCountry = getSetting(destination, 'geoCountry') || null;
1126
1216
  const requestRegion = getSetting(destination, 'geoRegion') || null;
1127
1217
  const isEURequest = getSetting(destination, 'isEURequest') || false;
1128
1218
  for (const pkg of providerPackages) {
@@ -1143,7 +1233,7 @@
1143
1233
  logger.log(`Consent is missing for ${pkg.name} (${variable.tagName})`);
1144
1234
  continue;
1145
1235
  }
1146
- if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
1236
+ if (!doesGeoRequestMatchList(requestCountry, requestRegion, isEURequest, variable.geoRegions)) {
1147
1237
  logger.log(`GEO request region does not match list, skipping`);
1148
1238
  continue;
1149
1239
  }
@@ -1212,6 +1302,7 @@
1212
1302
  const userId = getUserId$1(destination);
1213
1303
  const providerPackages = getSetting(destination, 'browserPackages');
1214
1304
  const executionContext = new Map();
1305
+ const requestCountry = getSetting(destination, 'geoCountry') || null;
1215
1306
  const requestRegion = getSetting(destination, 'geoRegion') || null;
1216
1307
  const isEURequest = getSetting(destination, 'isEURequest') || false;
1217
1308
  /* Calling Init for all provider instances based on consent check */
@@ -1225,7 +1316,7 @@
1225
1316
  if (!hasConsent) {
1226
1317
  continue;
1227
1318
  }
1228
- if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
1319
+ if (!doesGeoRequestMatchList(requestCountry, requestRegion, isEURequest, variable.geoRegions)) {
1229
1320
  continue;
1230
1321
  }
1231
1322
  pkg.init({
@@ -1448,7 +1539,7 @@
1448
1539
  /* this defines if the consent is given for a specific instance of a provider */
1449
1540
  const hasConsent = hasUserConsent(getSetting(destination, 'consent'), pkg.name, provider.tagName);
1450
1541
  if (hasConsent &&
1451
- doesGeoRequestMatchList(response.geoRegion, response.isEURequest, provider.geoRegions)) {
1542
+ doesGeoRequestMatchList(response.geoCountry, response.geoRegion, response.isEURequest, provider.geoRegions)) {
1452
1543
  pkg.init({
1453
1544
  userId,
1454
1545
  isNewUser: !!response.isNewUser,
@@ -1552,6 +1643,7 @@
1552
1643
  storageId: result.storageId,
1553
1644
  currency: result.currency,
1554
1645
  skipZeroPurchaseEvent: result.skipZeroPurchaseEvent,
1646
+ geoCountry: result.geoCountry,
1555
1647
  geoRegion: result.geoRegion,
1556
1648
  isEURequest: result.isEURequest,
1557
1649
  });
@@ -1586,6 +1678,7 @@
1586
1678
  const configuredTags = getSetting(destination, 'channels');
1587
1679
  const consent = getConsent$1(destination);
1588
1680
  const userId = getUserId$1(destination);
1681
+ const requestCountry = getSetting(destination, 'geoCountry') || null;
1589
1682
  const requestRegion = getSetting(destination, 'geoRegion') || null;
1590
1683
  const isEURequest = getSetting(destination, 'isEURequest') || false;
1591
1684
  for (const pkg of providerPackages) {
@@ -1606,7 +1699,7 @@
1606
1699
  logger.log(`User do not have consent for ${pkg.name} (${variable.tagName})`);
1607
1700
  continue;
1608
1701
  }
1609
- if (!doesGeoRequestMatchList(requestRegion, isEURequest, variable.geoRegions)) {
1702
+ if (!doesGeoRequestMatchList(requestCountry, requestRegion, isEURequest, variable.geoRegions)) {
1610
1703
  logger.log(`GEO request region does not match list, skipping`);
1611
1704
  continue;
1612
1705
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/edgetag-sdk-browser",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",