@codecademy/tracking 0.23.0 → 0.23.4

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 (46) hide show
  1. package/.eslintrc.json +30 -0
  2. package/CHANGELOG.md +77 -206
  3. package/babel.config.js +9 -3
  4. package/dist/events/__tests__/track.test.d.js +1 -0
  5. package/dist/events/__tests__/track.test.js +13 -14
  6. package/dist/events/__tests__/user.test.d.js +1 -0
  7. package/dist/events/__tests__/user.test.js +3 -7
  8. package/dist/events/track.js +27 -37
  9. package/dist/events/types.js +2 -0
  10. package/dist/events/user.js +5 -7
  11. package/dist/integrations/__tests__/conditionallyLoadAnalytics.test.js +97 -0
  12. package/dist/integrations/__tests__/fetchDestinationsForWriteKey.test.js +112 -0
  13. package/dist/integrations/__tests__/mapDestinations.test.js +120 -0
  14. package/dist/integrations/device.js +2 -0
  15. package/dist/integrations/fetchDestinationsForWriteKey.js +27 -24
  16. package/dist/integrations/index.js +4 -6
  17. package/dist/integrations/mapDestinations.js +19 -20
  18. package/dist/integrations/onetrust.js +7 -9
  19. package/dist/integrations/runSegmentSnippet.js +0 -1
  20. package/dist/integrations/types.js +2 -0
  21. package/dist/{events → libs/tracking/src/events}/index.d.ts +0 -0
  22. package/dist/{events → libs/tracking/src/events}/track.d.ts +0 -0
  23. package/dist/{events → libs/tracking/src/events}/types.d.ts +0 -0
  24. package/dist/{events → libs/tracking/src/events}/user.d.ts +0 -0
  25. package/dist/{index.d.ts → libs/tracking/src/index.d.ts} +0 -0
  26. package/dist/{integrations → libs/tracking/src/integrations}/conditionallyLoadAnalytics.d.ts +0 -0
  27. package/dist/{integrations → libs/tracking/src/integrations}/consent.d.ts +0 -0
  28. package/dist/{integrations → libs/tracking/src/integrations}/device.d.ts +0 -0
  29. package/dist/{integrations → libs/tracking/src/integrations}/fetchDestinationsForWriteKey.d.ts +0 -0
  30. package/dist/{integrations → libs/tracking/src/integrations}/index.d.ts +0 -0
  31. package/dist/{integrations → libs/tracking/src/integrations}/mapDestinations.d.ts +0 -0
  32. package/dist/{integrations → libs/tracking/src/integrations}/onetrust.d.ts +0 -0
  33. package/dist/{integrations → libs/tracking/src/integrations}/runSegmentSnippet.d.ts +0 -0
  34. package/dist/{integrations → libs/tracking/src/integrations}/types.d.ts +0 -0
  35. package/package.json +5 -27
  36. package/project.json +45 -0
  37. package/tsconfig.json +13 -4
  38. package/tsconfig.lib.json +10 -0
  39. package/tsconfig.spec.json +9 -0
  40. package/.turbo/turbo-build.log +0 -11
  41. package/dist/events/__tests__/track.test.d.ts +0 -1
  42. package/dist/events/__tests__/user.test.d.ts +0 -1
  43. package/dist/integrations/__tests__/conditionallyLoadAnalytics-test.d.ts +0 -1
  44. package/dist/integrations/__tests__/fetchDestinationsForWriteKey-test.d.ts +0 -1
  45. package/dist/integrations/__tests__/mapDestinations-test.d.ts +0 -1
  46. package/jest.config.js +0 -1
@@ -1,9 +1,5 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
1
+ import _asyncToGenerator from "/home/runner/work/mono/mono/node_modules/@babel/runtime/helpers/asyncToGenerator.js";
2
+ import _regeneratorRuntime from "/home/runner/work/mono/mono/node_modules/@babel/runtime/regenerator/index.js";
7
3
  import fetch from 'fetch-mock';
8
4
  import { fetchUser } from '../user';
9
5
  var apiBaseUrl = 'https://www.codecademy.com';
@@ -28,7 +24,7 @@ describe('fetchUser', function () {
28
24
  user = _context.sent;
29
25
  expect(user).toEqual(authUser);
30
26
  expect(fetch.calls().length).toEqual(1);
31
- expect(fetch.calls()[0][0]).toBe("".concat(apiBaseUrl, "/users/web"));
27
+ expect(fetch.calls()[0][0]).toBe(apiBaseUrl + "/users/web");
32
28
  expect(fetch.calls()[0][1].method).toBe('GET');
33
29
  expect(fetch.calls()[0][1].credentials).toBe('include');
34
30
 
@@ -1,23 +1,16 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
4
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
7
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
-
9
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
-
11
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
12
-
13
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
14
-
15
- function _iterableToArrayLimit(arr, i) { var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]); if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
16
-
17
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
18
-
1
+ import "core-js/modules/es.object.to-string.js";
2
+ import "core-js/modules/es.regexp.to-string.js";
3
+ import "core-js/modules/es.array.iterator.js";
4
+ import "core-js/modules/es.string.iterator.js";
5
+ import "core-js/modules/web.dom-collections.iterator.js";
6
+ import "core-js/modules/web.url.js";
7
+ import "core-js/modules/web.url-search-params.js";
8
+ import "core-js/modules/es.object.entries.js";
9
+ import "core-js/modules/es.promise.js";
10
+ import "core-js/modules/es.object.assign.js";
11
+ import "core-js/modules/es.regexp.exec.js";
12
+ import "core-js/modules/es.string.search.js";
19
13
  import { getClientType } from '../integrations/device';
20
- /* eslint-disable no-console */
21
14
 
22
15
  var browserSupportsKeepalive = function browserSupportsKeepalive() {
23
16
  return 'keepalive' in window.Request.prototype;
@@ -31,13 +24,10 @@ export var createTracker = function createTracker(_ref) {
31
24
  var uri = new URL(endpoint, apiBaseUrl).toString();
32
25
  var form = new FormData();
33
26
 
34
- for (var _i2 = 0, _Object$entries = Object.entries(data); _i2 < _Object$entries.length; _i2++) {
35
- var _ref4 = _Object$entries[_i2];
36
-
37
- var _ref3 = _slicedToArray(_ref4, 2);
38
-
39
- var k = _ref3[0];
40
- var v = _ref3[1];
27
+ for (var _i = 0, _Object$entries = Object.entries(data); _i < _Object$entries.length; _i++) {
28
+ var _Object$entries$_i = _Object$entries[_i],
29
+ k = _Object$entries$_i[0],
30
+ v = _Object$entries$_i[1];
41
31
  form.append(k, v.toString());
42
32
  }
43
33
 
@@ -45,17 +35,15 @@ export var createTracker = function createTracker(_ref) {
45
35
  // Firefox allows users to disable navigator.sendBeacon, and very old Safari versions don't have it.
46
36
  // [WEB-1700]: Additionally, Chrome 79-80 gives "Illegal invocation" with ?., so through 2022 we should support them.
47
37
  // It seems similar to this: https://github.com/vercel/next.js/issues/23856
48
- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
49
38
  if (navigator.sendBeacon && navigator.sendBeacon(uri, form)) {
50
39
  return;
51
40
  }
52
41
  } catch (_unused) {// Even with the proper scoping, Chrome 79-80 still gives "Illegal invocation" crashes. Sigh.
53
42
  } // Either way, we fall back to standard fetch if sendBeacon fails.
54
43
  // We don't mind this rejecting with an error because it's tracking, and we'll know if that starts to fail.
55
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
56
44
 
57
45
 
58
- window.fetch(uri, _objectSpread({
46
+ window.fetch(uri, Object.assign({
59
47
  method: 'POST',
60
48
  body: form
61
49
  }, browserSupportsKeepalive() && {
@@ -63,10 +51,12 @@ export var createTracker = function createTracker(_ref) {
63
51
  }));
64
52
  };
65
53
 
66
- var event = function event(category, _event, userData) {
67
- var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
54
+ var event = function event(category, _event, userData, options) {
55
+ if (options === void 0) {
56
+ options = {};
57
+ }
68
58
 
69
- var properties = _objectSpread(_objectSpread({}, userData), {}, {
59
+ var properties = Object.assign({}, userData, {
70
60
  fullpath: window.location.pathname + window.location.search,
71
61
  search: window.location.search,
72
62
  path: window.location.pathname,
@@ -77,7 +67,7 @@ export var createTracker = function createTracker(_ref) {
77
67
  });
78
68
 
79
69
  if (verbose) {
80
- console.groupCollapsed("%cTracking Event Fired: ".concat(category, ":").concat(_event), 'color: #4b35ef; font-style: italic;');
70
+ console.groupCollapsed("%cTracking Event Fired: " + category + ":" + _event, 'color: #4b35ef; font-style: italic;');
81
71
  console.log({
82
72
  category: category,
83
73
  event: _event,
@@ -88,11 +78,11 @@ export var createTracker = function createTracker(_ref) {
88
78
 
89
79
 
90
80
  var queryParams = window.location.search;
91
- beacon("/analytics/".concat(category).concat(queryParams), {
81
+ beacon("/analytics/" + category + queryParams, {
92
82
  category: category,
93
83
  event: _event,
94
84
  properties: JSON.stringify(properties),
95
- gdpr_safe: "".concat(options.gdprSafe)
85
+ gdpr_safe: "" + options.gdprSafe
96
86
  });
97
87
  };
98
88
 
@@ -108,9 +98,9 @@ export var createTracker = function createTracker(_ref) {
108
98
  return event('user', 'visit', data);
109
99
  },
110
100
  pushDataLayerEvent: function pushDataLayerEvent(eventName) {
111
- var _ref5;
101
+ var _ref2;
112
102
 
113
- ((_ref5 = window).dataLayer || (_ref5.dataLayer = [])).push({
103
+ ((_ref2 = window).dataLayer || (_ref2.dataLayer = [])).push({
114
104
  event: eventName
115
105
  });
116
106
  }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ export {};
@@ -1,9 +1,7 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
1
+ import _asyncToGenerator from "/home/runner/work/mono/mono/node_modules/@babel/runtime/helpers/asyncToGenerator.js";
2
+ import _regeneratorRuntime from "/home/runner/work/mono/mono/node_modules/@babel/runtime/regenerator/index.js";
3
+ import "core-js/modules/es.object.to-string.js";
4
+ import "core-js/modules/es.promise.js";
7
5
  export var fetchUser = /*#__PURE__*/function () {
8
6
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(apiBaseUrl) {
9
7
  var response;
@@ -12,7 +10,7 @@ export var fetchUser = /*#__PURE__*/function () {
12
10
  switch (_context.prev = _context.next) {
13
11
  case 0:
14
12
  _context.next = 2;
15
- return fetch("".concat(apiBaseUrl, "/users/web"), {
13
+ return fetch(apiBaseUrl + "/users/web", {
16
14
  method: 'GET',
17
15
  headers: {
18
16
  'Content-type': 'application/json',
@@ -0,0 +1,97 @@
1
+ import "core-js/modules/es.object.assign.js";
2
+ import { conditionallyLoadAnalytics } from '../conditionallyLoadAnalytics';
3
+ var mockClientType = jest.fn();
4
+ jest.mock('../../integrations/device', function () {
5
+ return {
6
+ get getClientType() {
7
+ return mockClientType;
8
+ }
9
+
10
+ };
11
+ });
12
+
13
+ var createMockSegmentAnalytics = function createMockSegmentAnalytics(overrides) {
14
+ return Object.assign({
15
+ identify: jest.fn(),
16
+ load: jest.fn(),
17
+ page: jest.fn()
18
+ }, overrides);
19
+ };
20
+
21
+ var createMockOptions = function createMockOptions(overrides) {
22
+ return Object.assign({
23
+ analytics: createMockSegmentAnalytics(),
24
+ destinationPreferences: {
25
+ destination: true
26
+ },
27
+ identifyPreferences: {
28
+ destination: true
29
+ },
30
+ writeKey: 'abc123'
31
+ }, overrides);
32
+ };
33
+
34
+ describe('conditionallyLoadAnalytics', function () {
35
+ it('does not call analytics.load or analytics.page when analytics.initialize is true', function () {
36
+ var options = createMockOptions({
37
+ analytics: createMockSegmentAnalytics({
38
+ initialize: true
39
+ })
40
+ });
41
+ conditionallyLoadAnalytics(options);
42
+ expect(options.analytics.load).not.toHaveBeenCalled();
43
+ });
44
+ it('calls analytics.load and analytics.page when analytics.initialize is false', function () {
45
+ var options = createMockOptions({
46
+ analytics: createMockSegmentAnalytics({
47
+ initialize: false
48
+ })
49
+ });
50
+ conditionallyLoadAnalytics(options);
51
+ expect(options.analytics.load).toHaveBeenCalledWith(options.writeKey, {
52
+ integrations: options.destinationPreferences
53
+ });
54
+ expect(options.analytics.page).toHaveBeenCalled();
55
+ });
56
+ it('does not call analytics.identify when there is no user', function () {
57
+ var options = createMockOptions({
58
+ user: undefined
59
+ });
60
+ conditionallyLoadAnalytics(options);
61
+ expect(options.analytics.identify).not.toHaveBeenCalled();
62
+ });
63
+ it('calls analytics.identify when there is a user with a default client', function () {
64
+ var user = {
65
+ email: 'test@test.com',
66
+ id: 'abc123'
67
+ };
68
+ var options = createMockOptions({
69
+ user: user
70
+ });
71
+ mockClientType.mockReturnValue('default');
72
+ conditionallyLoadAnalytics(options);
73
+ expect(options.analytics.identify).toHaveBeenCalledWith(user.id, {
74
+ email: user.email,
75
+ client: 'default'
76
+ }, {
77
+ integrations: options.identifyPreferences
78
+ });
79
+ });
80
+ it('sets client to PWA on analytics.identify when source is a PWA', function () {
81
+ var user = {
82
+ email: 'test@test.com',
83
+ id: 'abc123'
84
+ };
85
+ var options = createMockOptions({
86
+ user: user
87
+ });
88
+ mockClientType.mockReturnValue('pwa');
89
+ conditionallyLoadAnalytics(options);
90
+ expect(options.analytics.identify).toHaveBeenCalledWith(user.id, {
91
+ email: user.email,
92
+ client: 'pwa'
93
+ }, {
94
+ integrations: options.identifyPreferences
95
+ });
96
+ });
97
+ });
@@ -0,0 +1,112 @@
1
+ import _asyncToGenerator from "/home/runner/work/mono/mono/node_modules/@babel/runtime/helpers/asyncToGenerator.js";
2
+ import _regeneratorRuntime from "/home/runner/work/mono/mono/node_modules/@babel/runtime/regenerator/index.js";
3
+ import fetchMock from 'fetch-mock';
4
+ import { fetchDestinationsForWriteKey } from '../fetchDestinationsForWriteKey';
5
+ var settings = {
6
+ onError: jest.fn(),
7
+ writeKey: 'abc123'
8
+ };
9
+ describe('fetchDestinationsForWriteKey', function () {
10
+ beforeEach(function () {
11
+ return fetchMock.restore();
12
+ });
13
+ it('returns [] and logs an error when the integrations fetch is not ok', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
14
+ var error, destinations;
15
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
16
+ while (1) {
17
+ switch (_context.prev = _context.next) {
18
+ case 0:
19
+ error = 'Oh no';
20
+ fetchMock.get("https://cdn.segment.com/v1/projects/" + settings.writeKey + "/integrations", {
21
+ throws: error
22
+ });
23
+ _context.next = 4;
24
+ return fetchDestinationsForWriteKey(settings);
25
+
26
+ case 4:
27
+ destinations = _context.sent;
28
+ expect(destinations).toEqual([]);
29
+ expect(settings.onError).toHaveBeenCalledWith("Unknown error fetching Segment destinations for write key " + settings.writeKey + ": " + error);
30
+
31
+ case 7:
32
+ case "end":
33
+ return _context.stop();
34
+ }
35
+ }
36
+ }, _callee);
37
+ })));
38
+ it('returns [] and does not log an error when the integrations fetch is a known client issue', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
39
+ var destinations;
40
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
41
+ while (1) {
42
+ switch (_context2.prev = _context2.next) {
43
+ case 0:
44
+ fetchMock.get("https://cdn.segment.com/v1/projects/" + settings.writeKey + "/integrations", {
45
+ throws: 'Failed to fetch'
46
+ });
47
+ _context2.next = 3;
48
+ return fetchDestinationsForWriteKey(settings);
49
+
50
+ case 3:
51
+ destinations = _context2.sent;
52
+ expect(destinations).toEqual([]);
53
+ expect(settings.onError).not.toHaveBeenCalled();
54
+
55
+ case 6:
56
+ case "end":
57
+ return _context2.stop();
58
+ }
59
+ }
60
+ }, _callee2);
61
+ })));
62
+ it('returns [] when response.json() throws an error', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
63
+ var destinations;
64
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
65
+ while (1) {
66
+ switch (_context3.prev = _context3.next) {
67
+ case 0:
68
+ fetchMock.get("https://cdn.segment.com/v1/projects/" + settings.writeKey + "/integrations", {
69
+ body: 'invalid'
70
+ });
71
+ _context3.next = 3;
72
+ return fetchDestinationsForWriteKey(settings);
73
+
74
+ case 3:
75
+ destinations = _context3.sent;
76
+ expect(destinations).toEqual([]);
77
+
78
+ case 5:
79
+ case "end":
80
+ return _context3.stop();
81
+ }
82
+ }
83
+ }, _callee3);
84
+ })));
85
+ it('returns mapped destinations when response.json() succeeds', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
86
+ var destinations;
87
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
88
+ while (1) {
89
+ switch (_context4.prev = _context4.next) {
90
+ case 0:
91
+ fetchMock.get("https://cdn.segment.com/v1/projects/" + settings.writeKey + "/integrations", {
92
+ body: [{
93
+ creationName: 'my-destination'
94
+ }]
95
+ });
96
+ _context4.next = 3;
97
+ return fetchDestinationsForWriteKey(settings);
98
+
99
+ case 3:
100
+ destinations = _context4.sent;
101
+ expect(destinations).toEqual([{
102
+ id: 'my-destination'
103
+ }]);
104
+
105
+ case 5:
106
+ case "end":
107
+ return _context4.stop();
108
+ }
109
+ }
110
+ }, _callee4);
111
+ })));
112
+ });
@@ -0,0 +1,120 @@
1
+ import "core-js/modules/es.object.assign.js";
2
+ import { Consent } from '../consent';
3
+ import { mapDestinations } from '../mapDestinations';
4
+ describe('mapDestinations', function () {
5
+ describe('destinationPreferences', function () {
6
+ var testCase = function testCase(input, output) {
7
+ var _mapDestinations = mapDestinations(input),
8
+ destinationPreferences = _mapDestinations.destinationPreferences;
9
+
10
+ expect(destinationPreferences).toEqual(expect.objectContaining(output));
11
+ };
12
+
13
+ it('does not include Segment.io by default', function () {
14
+ testCase({
15
+ destinations: []
16
+ }, {
17
+ 'Segment.io': false
18
+ });
19
+ });
20
+ it('includes Segment.io when consent includes C0003', function () {
21
+ testCase({
22
+ consentDecision: [Consent.Functional],
23
+ destinations: []
24
+ }, {
25
+ 'Segment.io': true
26
+ });
27
+ });
28
+ it('does not allow a targeting destination when consent does not include C0004', function () {
29
+ testCase({
30
+ consentDecision: [],
31
+ destinations: [{
32
+ category: 'Advertising',
33
+ id: 'abc123'
34
+ }]
35
+ }, {
36
+ abc123: false
37
+ });
38
+ });
39
+ it('allows a targeting destination when consent includes C0004', function () {
40
+ testCase({
41
+ consentDecision: [Consent.Targeting],
42
+ destinations: [{
43
+ category: 'Advertising',
44
+ id: 'abc123'
45
+ }]
46
+ }, {
47
+ abc123: true
48
+ });
49
+ });
50
+ it('does not allow a performance destination when consent does not include C0002', function () {
51
+ testCase({
52
+ consentDecision: [],
53
+ destinations: [{
54
+ category: 'Analytics',
55
+ id: 'abc123'
56
+ }]
57
+ }, {
58
+ abc123: false
59
+ });
60
+ });
61
+ it('allows a performance destination when consent includes C0002', function () {
62
+ testCase({
63
+ consentDecision: [Consent.Performance],
64
+ destinations: [{
65
+ category: 'Analytics',
66
+ id: 'abc123'
67
+ }]
68
+ }, {
69
+ abc123: true
70
+ });
71
+ });
72
+ });
73
+ describe('identifyPreferences', function () {
74
+ var testCase = function testCase(input, output) {
75
+ var _mapDestinations2 = mapDestinations(Object.assign({
76
+ destinations: []
77
+ }, input)),
78
+ identifyPreferences = _mapDestinations2.identifyPreferences;
79
+
80
+ expect(identifyPreferences).toEqual(expect.objectContaining(output));
81
+ };
82
+
83
+ it('does not include FullStory when consent does not include C0003', function () {
84
+ testCase({}, {
85
+ FullStory: false
86
+ });
87
+ });
88
+ it('includes FullStory when consent includes C0002', function () {
89
+ testCase({
90
+ consentDecision: [Consent.Performance]
91
+ }, {
92
+ FullStory: true
93
+ });
94
+ });
95
+ it('does not include Hindsight when consent does not include C0004', function () {
96
+ testCase({}, {
97
+ Hindsight: false
98
+ });
99
+ });
100
+ it('includes Hindsight when consent includes C0004', function () {
101
+ testCase({
102
+ consentDecision: [Consent.Targeting]
103
+ }, {
104
+ Hindsight: true
105
+ });
106
+ });
107
+ it('does not include UserLeap when consent does not include C0002', function () {
108
+ testCase({}, {
109
+ UserLeap: false
110
+ });
111
+ });
112
+ it('includes UserLeap when consent includes C0002', function () {
113
+ testCase({
114
+ consentDecision: [Consent.Performance]
115
+ }, {
116
+ UserLeap: true
117
+ });
118
+ });
119
+ });
120
+ });
@@ -1,3 +1,5 @@
1
+ import "core-js/modules/es.regexp.exec.js";
2
+
1
3
  /**
2
4
  * @returns Whether the site is running both in ChromeOS and in PWA mode.
3
5
  */
@@ -1,15 +1,25 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
1
+ import _asyncToGenerator from "/home/runner/work/mono/mono/node_modules/@babel/runtime/helpers/asyncToGenerator.js";
2
+ import _regeneratorRuntime from "/home/runner/work/mono/mono/node_modules/@babel/runtime/regenerator/index.js";
2
3
 
3
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
4
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
5
 
5
6
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
7
 
7
8
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8
9
 
9
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
10
-
11
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
12
-
10
+ import "core-js/modules/es.object.to-string.js";
11
+ import "core-js/modules/es.array.includes.js";
12
+ import "core-js/modules/es.string.includes.js";
13
+ import "core-js/modules/es.promise.js";
14
+ import "core-js/modules/es.array.slice.js";
15
+ import "core-js/modules/es.array.from.js";
16
+ import "core-js/modules/es.string.iterator.js";
17
+ import "core-js/modules/es.regexp.exec.js";
18
+ import "core-js/modules/es.symbol.js";
19
+ import "core-js/modules/es.symbol.description.js";
20
+ import "core-js/modules/es.symbol.iterator.js";
21
+ import "core-js/modules/es.array.iterator.js";
22
+ import "core-js/modules/web.dom-collections.iterator.js";
13
23
  var knownFetchFailures = ['Failed to fetch', 'Load failed', 'NetworkError when attempting to fetch resource', 'Resource blocked by content blocker'];
14
24
  export var fetchDestinationsForWriteKey = /*#__PURE__*/function () {
15
25
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
@@ -31,7 +41,7 @@ export var fetchDestinationsForWriteKey = /*#__PURE__*/function () {
31
41
 
32
42
  _context.prev = 2;
33
43
  _context.next = 5;
34
- return fetch("https://cdn.segment.com/v1/projects/".concat(writeKey, "/integrations"));
44
+ return fetch("https://cdn.segment.com/v1/projects/" + writeKey + "/integrations");
35
45
 
36
46
  case 5:
37
47
  response = _context.sent;
@@ -41,7 +51,7 @@ export var fetchDestinationsForWriteKey = /*#__PURE__*/function () {
41
51
  break;
42
52
  }
43
53
 
44
- filteredOnError("Failed to fetch integrations for write key ".concat(writeKey, ": HTTP ").concat(response.status, " ").concat(response.statusText));
54
+ filteredOnError("Failed to fetch integrations for write key " + writeKey + ": HTTP " + response.status + " " + response.statusText);
45
55
  return _context.abrupt("return", []);
46
56
 
47
57
  case 9:
@@ -50,34 +60,27 @@ export var fetchDestinationsForWriteKey = /*#__PURE__*/function () {
50
60
 
51
61
  case 11:
52
62
  destinations = _context.sent;
53
- _iterator = _createForOfIteratorHelper(destinations);
54
63
 
55
- try {
56
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
57
- destination = _step.value;
58
- destination.id = destination.creationName;
59
- delete destination.creationName;
60
- }
61
- } catch (err) {
62
- _iterator.e(err);
63
- } finally {
64
- _iterator.f();
64
+ for (_iterator = _createForOfIteratorHelperLoose(destinations); !(_step = _iterator()).done;) {
65
+ destination = _step.value;
66
+ destination.id = destination.creationName;
67
+ delete destination.creationName;
65
68
  }
66
69
 
67
70
  return _context.abrupt("return", destinations);
68
71
 
69
- case 17:
70
- _context.prev = 17;
72
+ case 16:
73
+ _context.prev = 16;
71
74
  _context.t0 = _context["catch"](2);
72
- filteredOnError("Unknown error fetching Segment destinations for write key ".concat(writeKey, ": ").concat(_context.t0));
75
+ filteredOnError("Unknown error fetching Segment destinations for write key " + writeKey + ": " + _context.t0);
73
76
  return _context.abrupt("return", []);
74
77
 
75
- case 21:
78
+ case 20:
76
79
  case "end":
77
80
  return _context.stop();
78
81
  }
79
82
  }
80
- }, _callee, null, [[2, 17]]);
83
+ }, _callee, null, [[2, 16]]);
81
84
  }));
82
85
 
83
86
  return function fetchDestinationsForWriteKey(_x) {
@@ -1,9 +1,7 @@
1
- import _regeneratorRuntime from "@babel/runtime/regenerator";
2
-
3
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
-
5
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
-
1
+ import _asyncToGenerator from "/home/runner/work/mono/mono/node_modules/@babel/runtime/helpers/asyncToGenerator.js";
2
+ import _regeneratorRuntime from "/home/runner/work/mono/mono/node_modules/@babel/runtime/regenerator/index.js";
3
+ import "core-js/modules/es.object.to-string.js";
4
+ import "core-js/modules/es.promise.js";
7
5
  import { conditionallyLoadAnalytics } from './conditionallyLoadAnalytics';
8
6
  import { fetchDestinationsForWriteKey } from './fetchDestinationsForWriteKey';
9
7
  import { mapDestinations } from './mapDestinations';