@miso.ai/client-sdk-ui 1.10.0-beta.8 → 1.10.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 (51) hide show
  1. package/dist/cjs/actor/index.js +0 -7
  2. package/dist/cjs/actor/tracker.js +47 -97
  3. package/dist/cjs/actor/utils.js +3 -1
  4. package/dist/cjs/actor/view.js +12 -1
  5. package/dist/cjs/actor/views.js +24 -2
  6. package/dist/cjs/affiliation/index.js +26 -10
  7. package/dist/cjs/asset/svgs.js +14 -4
  8. package/dist/cjs/constants.js +3 -2
  9. package/dist/cjs/layout/affiliation/affiliation.js +263 -13
  10. package/dist/cjs/layout/input/option-list.js +34 -49
  11. package/dist/cjs/layout/list/collection.js +24 -45
  12. package/dist/cjs/layout/templates.js +54 -32
  13. package/dist/cjs/layout/text/typewriter/index.js +12 -7
  14. package/dist/cjs/layout/trackable.js +124 -0
  15. package/dist/cjs/util/bindings.js +58 -110
  16. package/dist/cjs/util/states.js +31 -24
  17. package/dist/cjs/util/trackers.js +75 -0
  18. package/dist/cjs/util/viewables.js +55 -0
  19. package/dist/cjs/version.js +1 -1
  20. package/dist/cjs/workflow/ask.js +1 -2
  21. package/dist/cjs/workflow/base.js +2 -7
  22. package/dist/cjs/workflow/recommendation.js +2 -0
  23. package/package.json +2 -2
  24. package/src/actor/index.js +0 -1
  25. package/src/actor/tracker.js +37 -88
  26. package/src/actor/utils.js +3 -1
  27. package/src/actor/view.js +14 -1
  28. package/src/actor/views.js +30 -1
  29. package/src/affiliation/index.js +25 -8
  30. package/src/asset/svgs.js +13 -2
  31. package/src/constants.js +7 -1
  32. package/src/layout/affiliation/affiliation.js +247 -14
  33. package/src/layout/input/option-list.js +35 -43
  34. package/src/layout/list/collection.js +22 -40
  35. package/src/layout/templates.js +25 -19
  36. package/src/layout/text/typewriter/index.js +8 -6
  37. package/src/layout/trackable.js +106 -0
  38. package/src/util/bindings.js +47 -103
  39. package/src/util/states.js +26 -20
  40. package/src/util/trackers.js +69 -0
  41. package/src/util/viewables.js +47 -0
  42. package/src/version.js +1 -1
  43. package/src/workflow/ask.js +1 -2
  44. package/src/workflow/base.js +3 -5
  45. package/src/workflow/recommendation.js +1 -0
  46. package/dist/cjs/actor/trackers.js +0 -51
  47. package/dist/cjs/layout/text/typewriter/progress.js +0 -45
  48. package/dist/cjs/util/tracker.js +0 -348
  49. package/src/actor/trackers.js +0 -45
  50. package/src/layout/text/typewriter/progress.js +0 -33
  51. package/src/util/tracker.js +0 -318
@@ -39,12 +39,6 @@ Object.defineProperty(exports, "SessionMaker", {
39
39
  return _sessions.default;
40
40
  }
41
41
  });
42
- Object.defineProperty(exports, "Trackers", {
43
- enumerable: true,
44
- get: function () {
45
- return _trackers.default;
46
- }
47
- });
48
42
  Object.defineProperty(exports, "ViewsActor", {
49
43
  enumerable: true,
50
44
  get: function () {
@@ -58,7 +52,6 @@ var _hub = _interopRequireDefault(require("./hub.js"));
58
52
  var _sessions = _interopRequireDefault(require("./sessions.js"));
59
53
  var _data = _interopRequireDefault(require("./data.js"));
60
54
  var _views = _interopRequireDefault(require("./views.js"));
61
- var _trackers = _interopRequireDefault(require("./trackers.js"));
62
55
  var _feedback = _interopRequireDefault(require("./feedback.js"));
63
56
  var _autocomplete = _interopRequireDefault(require("./autocomplete.js"));
64
57
  var _interactions = _interopRequireDefault(require("./interactions.js"));
@@ -4,98 +4,61 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _commons = require("@miso.ai/commons");
7
8
  var _constants = require("../constants.js");
8
9
  var fields = _interopRequireWildcard(require("./fields.js"));
9
- var _tracker = _interopRequireDefault(require("../util/tracker.js"));
10
- var _bindings = require("../util/bindings.js");
10
+ var _states = _interopRequireDefault(require("../util/states.js"));
11
11
  var _utils = require("./utils.js");
12
- const _excluded = ["active", "bindings"];
13
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
15
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
16
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
17
- function isReady(viewState) {
18
- return viewState && viewState.status === _constants.STATUS.READY;
19
- }
20
15
  class Tracker {
21
- constructor(hub, view) {
22
- let _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
23
- let {
24
- active,
25
- bindings
26
- } = _ref,
27
- options = _objectWithoutPropertiesLoose(_ref, _excluded);
28
- this._hub = hub;
16
+ constructor(view) {
29
17
  this._view = view;
30
- this._bindings = bindings;
31
- const role = this._role = view.role;
18
+ this._role = view.role;
32
19
  // TODO: know item type
33
20
 
34
- this._tracker = new _tracker.default(Object.assign({
35
- bindings: {
36
- list: element => this._listBindingsFn()(element)
37
- },
38
- proxyElement: view.proxyElement,
39
- sessionId: () => this._getSessionId(),
40
- active: active || (() => this._isViewReady())
41
- }, options));
42
- this._unsubscribes = [this._tracker.on('*', data => this._handleEvent(data)), hub.on(fields.view(role), () => this.refresh())];
43
- this.refresh();
44
- }
45
- config(options) {
46
- this._tracker.config(options);
47
- }
48
- start() {
49
- throw new Error(`workflow.tracker.start() is deprecated. Use workflow.startTracker() instead.`);
50
- }
51
- refresh() {
52
- this._tracker.refresh();
21
+ this._states = new _states.default(this._getSessionId());
53
22
  }
54
- impression(productIds, options) {
55
- this._assertViewReady();
56
- this._tracker.impression(productIds.map(product_id => ({
57
- product_id
58
- })), options);
23
+ get options() {
24
+ return this._view._getTrackerOptions();
59
25
  }
60
- viewable(productIds, options) {
61
- this._assertViewReady();
62
- this._tracker.viewable(productIds.map(product_id => ({
63
- product_id
64
- })), options);
26
+ getState(item) {
27
+ return this._states.getFullState(item);
65
28
  }
66
- click(productIds, options) {
67
- this._assertViewReady();
68
- this._tracker.click(productIds.map(product_id => ({
69
- product_id
70
- })), options);
71
- }
72
- _listBindingsFn() {
73
- if (this._bindings && typeof this._bindings.list === 'function') {
74
- return this._bindings.list;
75
- }
76
- const {
77
- layout
78
- } = this._view;
79
- if (layout && layout.bindings && typeof layout.bindings.list === 'function') {
80
- return layout.bindings.list;
29
+ _trigger(type, items) {
30
+ let meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
31
+ (0, _constants.validateEventType)(type);
32
+ this._syncSession();
33
+ items = this._states.untriggered((0, _commons.asArray)(items), type);
34
+ if (items.length === 0) {
35
+ return;
81
36
  }
82
- // TODO: only if item is product typed
83
- return (0, _bindings.fallbackListFunction)(_constants.ATTR_DATA_MISO_PRODUCT_ID);
84
- }
85
- _assertViewReady() {
86
- if (!this._hub.active) {
87
- throw new Error(`Workflow is not active. Call workflow.start() to activate it.`);
37
+ this._states.set(items, type, _constants.TRACKING_STATUS.TRIGGERED);
38
+ const property = this._role === 'results' ? 'products' : this._role; // TODO: ad-hoc, see #83
39
+ const misoId = this._getMisoId();
40
+ const request = this._getRequestPayload();
41
+
42
+ // TODO: should trigger 'tracker' and let workflow translate to interactions
43
+ this._view.hub.trigger(fields.interaction(), (0, _utils.toInteraction)({
44
+ property,
45
+ misoId,
46
+ request
47
+ }, {
48
+ event: type,
49
+ values: items,
50
+ meta
51
+ }));
52
+ }
53
+ _syncSession() {
54
+ const sessionId = this._getSessionId();
55
+ if (!sessionId) {
56
+ return;
88
57
  }
89
- if (!isReady(this._getViewState())) {
90
- throw new Error(`Workflow is not rendered yet. If you handle rendering by yourself, call workflow.notifyViewUpdate() when DOM is ready.`);
58
+ if (!this._states || sessionId !== this._states.sessionId) {
59
+ this._states = new _states.default(sessionId);
91
60
  }
92
61
  }
93
- _getViewState() {
94
- return this._hub.states[fields.view(this._role)];
95
- }
96
- _isViewReady() {
97
- return this._hub.active && isReady(this._getViewState());
98
- }
99
62
  _getSessionId() {
100
63
  const {
101
64
  session
@@ -104,7 +67,7 @@ class Tracker {
104
67
  }
105
68
  _getMisoId() {
106
69
  const state = this._getViewState();
107
- return state && state.meta && state.meta.miso_id || this._element && this._element.getAttribute('miso-id') || undefined;
70
+ return state && state.meta && state.meta.miso_id || undefined;
108
71
  }
109
72
  _getRequestPayload() {
110
73
  const {
@@ -112,26 +75,13 @@ class Tracker {
112
75
  } = this._getViewState() || {};
113
76
  return request && request.payload;
114
77
  }
115
- getState(productId) {
116
- return this._tracker.getState(productId);
117
- }
118
- _handleEvent(data) {
119
- const property = this._role === 'results' ? 'products' : this._role; // TODO: ad-hoc, see #83
120
- const misoId = this._getMisoId();
121
- const request = this._getRequestPayload();
122
- // TODO: should trigger 'tracker' and let workflow translate to interactions
123
- this._hub.trigger(fields.interaction(), (0, _utils.toInteraction)({
124
- property,
125
- misoId,
126
- request
127
- }, data));
128
- }
129
- _destroy() {
130
- for (const unsubscribe of this._unsubscribes) {
131
- unsubscribe();
132
- }
133
- this._unsubscribes = [];
134
- this._tracker.destroy();
78
+ _getViewState() {
79
+ return this._view.hub.states[fields.view(this._role)];
135
80
  }
136
81
  }
137
- exports.default = Tracker;
82
+ exports.default = Tracker;
83
+ for (const type of _constants.TRACKING_EVENT_TYPES) {
84
+ Tracker.prototype[type] = function (items, meta) {
85
+ this._trigger(type, items, meta);
86
+ };
87
+ }
@@ -34,9 +34,10 @@ function toInteraction(_ref, _ref2) {
34
34
  // TODO: ad-hoc
35
35
  const question_source = request && request._meta && request._meta.question_source;
36
36
  const isProductType = isProduct(property);
37
- const product_ids = isProductType ? values.map(v => v.product_id).filter(v => v) : [];
37
+ const product_ids = isProductType ? values.map(v => typeof v === 'string' ? v : v.product_id).filter(v => v) : [];
38
38
  const items = isProductType ? undefined : values.map(v => v.text || v.id || v);
39
39
  const channel = property === _constants.ROLE.AFFILIATION ? values[0] && values[0].channel : undefined;
40
+ const positions = property === _constants.ROLE.AFFILIATION ? values.map(v => v.position) : undefined;
40
41
  const payload = (0, _commons.trimObj)({
41
42
  type: event === 'viewable' ? 'viewable_impression' : event,
42
43
  product_ids,
@@ -47,6 +48,7 @@ function toInteraction(_ref, _ref2) {
47
48
  property,
48
49
  channel,
49
50
  items,
51
+ positions,
50
52
  trigger: manual ? 'manual' : 'auto',
51
53
  question_source
52
54
  })
@@ -8,6 +8,7 @@ var _commons = require("@miso.ai/commons");
8
8
  var _constants = require("../constants.js");
9
9
  var fields = _interopRequireWildcard(require("./fields.js"));
10
10
  var _proxy = _interopRequireDefault(require("../util/proxy.js"));
11
+ var _tracker = _interopRequireDefault(require("./tracker.js"));
11
12
  const _excluded = ["value", "error", "status", "meta"];
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
@@ -88,6 +89,12 @@ class ViewActor {
88
89
  force: true
89
90
  });
90
91
  }
92
+ get tracker() {
93
+ if (!this._tracker) {
94
+ this._tracker = new _tracker.default(this);
95
+ }
96
+ return this._tracker;
97
+ }
91
98
  async refresh() {
92
99
  var _this = this;
93
100
  let {
@@ -182,6 +189,10 @@ class ViewActor {
182
189
  silent
183
190
  });
184
191
  }
192
+ _getTrackerOptions() {
193
+ // used by tracker to expose tracker options to layout
194
+ return this._views._getTrackerOptions(this.role);
195
+ }
185
196
  _sliceData(_ref2) {
186
197
  let {
187
198
  value,
@@ -258,6 +269,6 @@ class ViewActor {
258
269
  exports.default = ViewActor;
259
270
  class View {
260
271
  constructor(actor) {
261
- (0, _commons.delegateGetters)(this, actor, ['role', 'layout', 'element', 'proxyElement', 'refresh', 'on']);
272
+ (0, _commons.delegateGetters)(this, actor, ['role', 'layout', 'element', 'proxyElement', 'refresh', 'on', 'tracker']);
262
273
  }
263
274
  }
@@ -8,6 +8,7 @@ var _commons = require("@miso.ai/commons");
8
8
  var _constants = require("../constants.js");
9
9
  var fields = _interopRequireWildcard(require("./fields.js"));
10
10
  var _view = _interopRequireDefault(require("./view.js"));
11
+ var _trackers = require("../util/trackers.js");
11
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
@@ -27,6 +28,7 @@ class ViewsActor {
27
28
  this._options = options;
28
29
  this._containers = new Map();
29
30
  this._views = {};
31
+ this._trackers = new Trackers(this, roles);
30
32
  for (const role of roles) {
31
33
  this._views[role] = new _view.default(this, role);
32
34
  }
@@ -35,9 +37,13 @@ class ViewsActor {
35
37
  });
36
38
  const syncSize = () => this.syncSize();
37
39
  window.addEventListener('resize', syncSize);
38
- this._unsubscribes = [() => window.removeEventListener('resize', syncSize), hub.on(fields.data(), () => this.refresh()), options.on('layouts', () => this._syncLayouts())];
40
+ this._unsubscribes = [() => window.removeEventListener('resize', syncSize), hub.on(fields.data(), () => this.refresh()), options.on('trackers', () => this._syncTrackers()), options.on('layouts', () => this._syncLayouts())];
41
+ this._syncTrackers();
39
42
  this._syncLayouts();
40
43
  }
44
+ get trackers() {
45
+ return this._trackers;
46
+ }
41
47
 
42
48
  // elements //
43
49
  addContainer(element) {
@@ -190,6 +196,12 @@ class ViewsActor {
190
196
  }
191
197
  return this._data;
192
198
  }
199
+ _syncTrackers() {
200
+ this._trackerOptions = this._options.resolved.trackers;
201
+ }
202
+ _getTrackerOptions(role) {
203
+ return (0, _trackers.normalizeTrackerOptions)(this._trackerOptions && this._trackerOptions[role] || false);
204
+ }
193
205
  _error(e) {
194
206
  // TODO: hub trigger error event
195
207
  console.error(e);
@@ -213,7 +225,7 @@ exports.default = ViewsActor;
213
225
  class Views {
214
226
  constructor(actor) {
215
227
  this._actor = actor;
216
- (0, _commons.delegateGetters)(this, actor, ['syncSize', 'refresh']);
228
+ (0, _commons.delegateGetters)(this, actor, ['syncSize', 'refresh', 'trackers']);
217
229
  }
218
230
  get(role) {
219
231
  return this._actor.get(role).interface;
@@ -221,4 +233,14 @@ class Views {
221
233
  get all() {
222
234
  return this._actor.views.map(view => view.interface);
223
235
  }
236
+ }
237
+ class Trackers {
238
+ constructor(views, roles) {
239
+ this._views = views;
240
+ for (const role of roles) {
241
+ Object.defineProperty(this, role, {
242
+ get: () => views.get(role).tracker
243
+ });
244
+ }
245
+ }
224
246
  }
@@ -31,24 +31,41 @@ function processValue(value) {
31
31
  affiliation: processSovrnData(sovrn_aff)
32
32
  });
33
33
  }
34
-
35
- // put channel info to items
34
+ return postProcessValue(value);
35
+ }
36
+ function postProcessValue(value) {
36
37
  const {
37
- channel
38
+ affiliation
38
39
  } = value;
39
- if (channel) {
40
- value.products = value.products.map(product => Object.assign({
41
- channel
42
- }, product));
40
+ if (!affiliation) {
41
+ return value;
42
+ }
43
+ let {
44
+ channel,
45
+ products
46
+ } = affiliation;
47
+ if (!products) {
48
+ return value;
43
49
  }
44
- return value;
50
+ products = products.map(product => Object.assign({}, product));
51
+ let i = 0;
52
+ for (const product of products) {
53
+ if (channel) {
54
+ product.channel = channel;
55
+ }
56
+ product.position = i++;
57
+ }
58
+ return Object.assign({}, value, {
59
+ affiliation: Object.assign({}, affiliation, {
60
+ products
61
+ })
62
+ });
45
63
  }
46
64
  function processSovrnData(_ref) {
47
65
  let {
48
66
  products
49
67
  } = _ref,
50
68
  sovrn_aff = _objectWithoutPropertiesLoose(_ref, _excluded2);
51
- products = products.slice(0, 1);
52
69
  return Object.assign({
53
70
  channel: 'sovrn'
54
71
  }, sovrn_aff, {
@@ -74,7 +91,6 @@ function processSovrnProduct(_ref2) {
74
91
  const brand_logo = merchant && merchant.logo;
75
92
  return (0, _commons.trimObj)({
76
93
  id: `sovrn-${id}`,
77
- channel: 'sovrn',
78
94
  title,
79
95
  description,
80
96
  cover_image,
@@ -3,16 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.SEND = exports.SEARCH = void 0;
6
+ exports.TRIANGLE = exports.SEND = exports.SEARCH = void 0;
7
7
  var _version = _interopRequireDefault(require("../version.js"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function trianglePath(r) {
10
+ const l = 100;
11
+ const d = r * Math.tan(3 * Math.PI / 8);
12
+ const e = d * Math.sin(Math.PI / 4);
13
+ return `M${r} 0L${l - d} 0A${r} ${r} 0 0 1 ${l - e} ${e}L${e} ${l - e}A${r} ${r} 0 0 1 0 ${l - d}L0 ${r}Z`;
14
+ }
9
15
  const PREFIX = 'miso-ui-icon';
10
16
  const ID = `${PREFIX}-svg-${_version.default.replaceAll('.', '_')}`;
11
17
 
12
- // all are CC0 SVGs
18
+ // CC0 SVGs
13
19
  const ICON_SEND = `<symbol id="${PREFIX}-send" viewBox="0 0 32 32"><path fill="currentColor" d="M11.499,19.173l5.801,-5.849c0.389,-0.392 1.022,-0.394 1.414,-0.006c0.392,0.389 0.395,1.022 0.006,1.414l-5.798,5.847l5.306,8.002c0.207,0.313 0.572,0.483 0.945,0.441c0.373,-0.042 0.691,-0.289 0.824,-0.64l9.024,-23.904c0.138,-0.366 0.05,-0.78 -0.226,-1.058c-0.276,-0.278 -0.689,-0.369 -1.057,-0.233l-24.004,8.892c-0.353,0.13 -0.602,0.448 -0.646,0.821c-0.044,0.373 0.125,0.74 0.438,0.948l7.973,5.325Z"/></symbol>`;
14
20
  const ICON_SEARCH = `<symbol id="${PREFIX}-search" viewBox="0 0 24 24"><path fill="currentColor" d="M4 11C4 7.13401 7.13401 4 11 4C14.866 4 18 7.13401 18 11C18 14.866 14.866 18 11 18C7.13401 18 4 14.866 4 11ZM11 2C6.02944 2 2 6.02944 2 11C2 15.9706 6.02944 20 11 20C13.125 20 15.078 19.2635 16.6177 18.0319L20.2929 21.7071C20.6834 22.0976 21.3166 22.0976 21.7071 21.7071C22.0976 21.3166 22.0976 20.6834 21.7071 20.2929L18.0319 16.6177C19.2635 15.078 20 13.125 20 11C20 6.02944 15.9706 2 11 2Z"/></symbol>`;
15
- const ICONS = [ICON_SEND, ICON_SEARCH];
21
+
22
+ // Custom SVGs
23
+ const ICON_TRIANGLE = `<symbol id="${PREFIX}-triangle" viewBox="-5 -5 105 105"><path d="${trianglePath(5)}"/></symbol>`;
24
+ const ICONS = [ICON_SEND, ICON_SEARCH, ICON_TRIANGLE];
16
25
  const SPRITES_SVG = `<svg id="${ID}" style="display:none;">${ICONS.join('')}</svg>`;
17
26
  let loaded = false;
18
27
  function loadSvgSprites() {
@@ -27,4 +36,5 @@ function getSvg(name) {
27
36
  return `<svg class="miso-ui-icon miso-ui-icon-${name}"><use href="#${PREFIX}-${name}"></use></svg>`;
28
37
  }
29
38
  const SEND = exports.SEND = getSvg('send');
30
- const SEARCH = exports.SEARCH = getSvg('search');
39
+ const SEARCH = exports.SEARCH = getSvg('search');
40
+ const TRIANGLE = exports.TRIANGLE = getSvg('triangle');
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TRACKING_STATUS = exports.STATUS = exports.ROLE = exports.ORGANIC_QUESTION_SOURCE = exports.LAYOUT_CATEGORY = exports.EVENT_TYPE = exports.DEFAULT_UNIT_ID = exports.ATTR_DATA_MISO_UNIT_ID = exports.ATTR_DATA_MISO_PRODUCT_ID = void 0;
6
+ exports.TRACKING_STATUS = exports.TRACKING_EVENT_TYPES = exports.STATUS = exports.ROLE = exports.ORGANIC_QUESTION_SOURCE = exports.LAYOUT_CATEGORY = exports.EVENT_TYPE = exports.DEFAULT_UNIT_ID = exports.ATTR_DATA_MISO_UNIT_ID = exports.ATTR_DATA_MISO_PRODUCT_ID = void 0;
7
7
  exports.isDataRole = isDataRole;
8
8
  exports.validateEventType = validateEventType;
9
9
  exports.validateTrackingStatus = validateTrackingStatus;
@@ -49,6 +49,7 @@ const EVENT_TYPE = exports.EVENT_TYPE = Object.freeze({
49
49
  VIEWABLE: 'viewable',
50
50
  CLICK: 'click'
51
51
  });
52
+ const TRACKING_EVENT_TYPES = exports.TRACKING_EVENT_TYPES = [EVENT_TYPE.IMPRESSION, EVENT_TYPE.VIEWABLE, EVENT_TYPE.CLICK];
52
53
  const TRACKING_STATUS = exports.TRACKING_STATUS = Object.freeze({
53
54
  UNTRACKED: 'untracked',
54
55
  TRACKING: 'tracking',
@@ -65,7 +66,7 @@ const STATUS = exports.STATUS = Object.freeze({
65
66
  NONEMPTY: 'nonempty'
66
67
  });
67
68
  function validateEventType(value) {
68
- if (value !== EVENT_TYPE.IMPRESSION && value !== EVENT_TYPE.VIEWABLE && value !== EVENT_TYPE.CLICK) {
69
+ if (TRACKING_EVENT_TYPES.indexOf(value) < 0) {
69
70
  throw new Error(`Unrecognized event type: ${value}`);
70
71
  }
71
72
  }