@miso.ai/client-sdk-ui 1.10.0-beta.1 → 1.10.0-beta.10

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 (78) hide show
  1. package/dist/cjs/actor/data.js +1 -1
  2. package/dist/cjs/actor/tracker.js +46 -70
  3. package/dist/cjs/actor/trackers.js +5 -1
  4. package/dist/cjs/actor/utils.js +6 -2
  5. package/dist/cjs/actor/view.js +14 -3
  6. package/dist/cjs/actor/views.js +9 -1
  7. package/dist/cjs/affiliation/index.js +126 -0
  8. package/dist/cjs/combo/ask/options.js +1 -1
  9. package/dist/cjs/combo/base.js +1 -1
  10. package/dist/cjs/constants.js +6 -3
  11. package/dist/cjs/defaults/ask/controls.js +1 -1
  12. package/dist/cjs/defaults/ask/phrases.js +1 -1
  13. package/dist/cjs/defaults/ask/templates.js +14 -4
  14. package/dist/cjs/element/role/index.js +7 -0
  15. package/dist/cjs/element/role/miso-affiliation.js +20 -0
  16. package/dist/cjs/layout/affiliation/affiliation.js +330 -0
  17. package/dist/cjs/layout/banner/banner.js +1 -1
  18. package/dist/cjs/layout/container/container.js +1 -1
  19. package/dist/cjs/layout/error/error.js +1 -1
  20. package/dist/cjs/layout/index.js +7 -0
  21. package/dist/cjs/layout/input/option-list.js +35 -50
  22. package/dist/cjs/layout/input/search-box.js +17 -5
  23. package/dist/cjs/layout/list/cards.js +1 -1
  24. package/dist/cjs/layout/list/carousel.js +5 -3
  25. package/dist/cjs/layout/list/collection.js +38 -48
  26. package/dist/cjs/layout/list/list.js +1 -1
  27. package/dist/cjs/layout/radio/feedback.js +1 -1
  28. package/dist/cjs/layout/radio/radio.js +1 -1
  29. package/dist/cjs/layout/raf.js +1 -1
  30. package/dist/cjs/layout/template.js +1 -1
  31. package/dist/cjs/layout/templates.js +135 -44
  32. package/dist/cjs/layout/text/text.js +1 -1
  33. package/dist/cjs/layout/text/typewriter/index.js +3 -3
  34. package/dist/cjs/layout/trackable.js +124 -0
  35. package/dist/cjs/plugin.js +1 -1
  36. package/dist/cjs/util/bindings.js +58 -110
  37. package/dist/cjs/util/states.js +31 -24
  38. package/dist/cjs/util/trackers.js +75 -0
  39. package/dist/cjs/util/viewables.js +55 -0
  40. package/dist/cjs/version.js +1 -1
  41. package/dist/cjs/workflow/ask.js +14 -5
  42. package/dist/cjs/workflow/asks.js +1 -1
  43. package/dist/cjs/workflow/base.js +5 -5
  44. package/dist/cjs/workflow/explore.js +1 -1
  45. package/dist/cjs/workflow/options.js +6 -1
  46. package/dist/cjs/workflow/recommendation.js +2 -0
  47. package/package.json +2 -2
  48. package/src/actor/tracker.js +39 -62
  49. package/src/actor/trackers.js +3 -1
  50. package/src/actor/utils.js +6 -2
  51. package/src/actor/view.js +12 -1
  52. package/src/actor/views.js +11 -0
  53. package/src/affiliation/index.js +108 -0
  54. package/src/constants.js +10 -1
  55. package/src/defaults/ask/phrases.js +1 -1
  56. package/src/defaults/ask/templates.js +13 -2
  57. package/src/element/role/index.js +1 -0
  58. package/src/element/role/miso-affiliation.js +16 -0
  59. package/src/layout/affiliation/affiliation.js +295 -0
  60. package/src/layout/index.js +1 -0
  61. package/src/layout/input/option-list.js +35 -43
  62. package/src/layout/input/search-box.js +7 -2
  63. package/src/layout/list/carousel.js +4 -2
  64. package/src/layout/list/collection.js +37 -43
  65. package/src/layout/templates.js +101 -26
  66. package/src/layout/text/typewriter/index.js +2 -2
  67. package/src/layout/trackable.js +106 -0
  68. package/src/util/bindings.js +47 -103
  69. package/src/util/states.js +26 -20
  70. package/src/util/trackers.js +69 -0
  71. package/src/util/viewables.js +47 -0
  72. package/src/version.js +1 -1
  73. package/src/workflow/ask.js +7 -3
  74. package/src/workflow/base.js +1 -1
  75. package/src/workflow/options.js +5 -1
  76. package/src/workflow/recommendation.js +1 -0
  77. package/dist/cjs/util/tracker.js +0 -348
  78. package/src/util/tracker.js +0 -318
@@ -9,7 +9,7 @@ var _utils = require("./utils.js");
9
9
  const _excluded = ["session"];
10
10
  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); }
11
11
  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; }
12
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
12
+ 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; }
13
13
  class DataActor {
14
14
  constructor(hub, _ref) {
15
15
  let {
@@ -4,97 +4,62 @@ 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
+ var _trackers = require("../util/trackers.js");
11
12
  var _utils = require("./utils.js");
12
13
  const _excluded = ["active", "bindings"];
13
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
14
15
  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
16
  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.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
17
- function isReady(viewState) {
18
- return viewState && viewState.status === _constants.STATUS.READY;
19
- }
17
+ 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; }
18
+ const {
19
+ IMPRESSION,
20
+ VIEWABLE,
21
+ CLICK
22
+ } = _constants.EVENT_TYPE;
20
23
  class Tracker {
21
24
  constructor(hub, view) {
22
25
  let _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
23
- let {
24
- active,
25
- bindings
26
- } = _ref,
27
- options = _objectWithoutPropertiesLoose(_ref, _excluded);
26
+ let options = _objectWithoutPropertiesLoose(_ref, _excluded);
28
27
  this._hub = hub;
29
28
  this._view = view;
30
- this._bindings = bindings;
31
- const role = this._role = view.role;
29
+ this._role = view.role;
32
30
  // TODO: know item type
33
31
 
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();
32
+ this._states = undefined;
33
+ this.config(options);
34
+ this._unsubscribes = [..._constants.TRACKING_EVENT_TYPES.map(type => this._view.trackingEvents.on(type, values => this._trigger(type, values))), hub.on(fields.view(view.role), () => this._syncSession())];
35
+ this._syncSession();
44
36
  }
45
37
  config(options) {
46
- this._tracker.config(options);
38
+ this._options = (0, _trackers.normalizeTrackerOptions)(options);
47
39
  }
48
40
  start() {
49
41
  throw new Error(`workflow.tracker.start() is deprecated. Use workflow.startTracker() instead.`);
50
42
  }
51
- refresh() {
52
- this._tracker.refresh();
53
- }
54
- impression(productIds, options) {
55
- this._assertViewReady();
56
- this._tracker.impression(productIds.map(product_id => ({
57
- product_id
58
- })), options);
43
+ impression(items, options) {
44
+ this._trigger(IMPRESSION, items, true);
59
45
  }
60
- viewable(productIds, options) {
61
- this._assertViewReady();
62
- this._tracker.viewable(productIds.map(product_id => ({
63
- product_id
64
- })), options);
46
+ viewable(items, options) {
47
+ this._trigger(VIEWABLE, items, true);
65
48
  }
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;
81
- }
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.`);
88
- }
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.`);
91
- }
49
+ click(items, options) {
50
+ this._trigger(CLICK, items, true);
92
51
  }
93
52
  _getViewState() {
94
53
  return this._hub.states[fields.view(this._role)];
95
54
  }
96
- _isViewReady() {
97
- return this._hub.active && isReady(this._getViewState());
55
+ _syncSession() {
56
+ const sessionId = this._getSessionId();
57
+ if (!sessionId) {
58
+ return;
59
+ }
60
+ if (!this._states || sessionId !== this._states.sessionId) {
61
+ this._states = new _states.default(sessionId);
62
+ }
98
63
  }
99
64
  _getSessionId() {
100
65
  const {
@@ -112,26 +77,37 @@ class Tracker {
112
77
  } = this._getViewState() || {};
113
78
  return request && request.payload;
114
79
  }
115
- getState(productId) {
116
- return this._tracker.getState(productId);
80
+ getState(item) {
81
+ return this._states.getFullState(item);
117
82
  }
118
- _handleEvent(data) {
83
+ _trigger(type, items) {
84
+ let manual = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
85
+ (0, _constants.validateEventType)(type);
86
+ items = this._states.untriggered((0, _commons.asArray)(items), type);
87
+ if (items.length === 0) {
88
+ return;
89
+ }
90
+ this._states.set(items, type, _constants.TRACKING_STATUS.TRIGGERED);
119
91
  const property = this._role === 'results' ? 'products' : this._role; // TODO: ad-hoc, see #83
120
92
  const misoId = this._getMisoId();
121
93
  const request = this._getRequestPayload();
94
+
122
95
  // TODO: should trigger 'tracker' and let workflow translate to interactions
123
96
  this._hub.trigger(fields.interaction(), (0, _utils.toInteraction)({
124
97
  property,
125
98
  misoId,
126
99
  request
127
- }, data));
100
+ }, {
101
+ event: type,
102
+ values: items,
103
+ manual
104
+ }));
128
105
  }
129
106
  _destroy() {
130
107
  for (const unsubscribe of this._unsubscribes) {
131
108
  unsubscribe();
132
109
  }
133
110
  this._unsubscribes = [];
134
- this._tracker.destroy();
135
111
  }
136
112
  }
137
113
  exports.default = Tracker;
@@ -20,7 +20,11 @@ class Trackers {
20
20
  this._syncConfig();
21
21
  }
22
22
  _syncConfig() {
23
- for (const [role, options] of Object.entries(this._options.resolved.trackers)) {
23
+ // TODO: trackers itself can be falsy
24
+ const {
25
+ trackers
26
+ } = this._options.resolved;
27
+ for (const [role, options] of Object.entries(trackers)) {
24
28
  this._createOrConfigTracker(role, options);
25
29
  }
26
30
  }
@@ -34,8 +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) : [];
38
- const items = isProductType ? undefined : values.map(v => v.text || v);
37
+ const product_ids = isProductType ? values.map(v => typeof v === 'string' ? v : v.product_id).filter(v => v) : [];
38
+ const items = isProductType ? undefined : values.map(v => v.text || v.id || v);
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;
39
41
  const payload = (0, _commons.trimObj)({
40
42
  type: event === 'viewable' ? 'viewable_impression' : event,
41
43
  product_ids,
@@ -44,7 +46,9 @@ function toInteraction(_ref, _ref2) {
44
46
  custom_context: (0, _commons.trimObj)({
45
47
  api_ts,
46
48
  property,
49
+ channel,
47
50
  items,
51
+ positions,
48
52
  trigger: manual ? 'manual' : 'auto',
49
53
  question_source
50
54
  })
@@ -12,7 +12,7 @@ const _excluded = ["value", "error", "status", "meta"];
12
12
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
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); }
14
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; }
15
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
15
+ 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; }
16
16
  function statesEqual(a, b) {
17
17
  return a === b || a && b && a.status === b.status && a.error === b.error && a.value === b.value &&
18
18
  // skip deep equals
@@ -27,9 +27,14 @@ class ViewActor {
27
27
  target: this
28
28
  });
29
29
  this._views = views;
30
+ const trackingEvents = {};
31
+ this._trackingEvents = new _commons.EventEmitter({
32
+ target: trackingEvents
33
+ });
30
34
  (0, _commons.defineValues)(this, {
31
35
  role,
32
- interface: new View(this)
36
+ interface: new View(this),
37
+ trackingEvents
33
38
  });
34
39
  }
35
40
  get hub() {
@@ -182,6 +187,12 @@ class ViewActor {
182
187
  silent
183
188
  });
184
189
  }
190
+ get trackerOptions() {
191
+ return this._views._getTrackerOptions(this.role);
192
+ }
193
+ _track(type, items) {
194
+ this._trackingEvents.emit(type, items);
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', 'trackingEvents']);
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; }
@@ -35,7 +36,8 @@ class ViewsActor {
35
36
  });
36
37
  const syncSize = () => this.syncSize();
37
38
  window.addEventListener('resize', syncSize);
38
- this._unsubscribes = [() => window.removeEventListener('resize', syncSize), hub.on(fields.data(), () => this.refresh()), options.on('layouts', () => this._syncLayouts())];
39
+ this._unsubscribes = [() => window.removeEventListener('resize', syncSize), hub.on(fields.data(), () => this.refresh()), options.on('trackers', () => this._syncTrackers()), options.on('layouts', () => this._syncLayouts())];
40
+ this._syncTrackers();
39
41
  this._syncLayouts();
40
42
  }
41
43
 
@@ -190,6 +192,12 @@ class ViewsActor {
190
192
  }
191
193
  return this._data;
192
194
  }
195
+ _syncTrackers() {
196
+ this._trackerOptions = this._options.resolved.trackers;
197
+ }
198
+ _getTrackerOptions(role) {
199
+ return (0, _trackers.normalizeTrackerOptions)(this._trackerOptions && this._trackerOptions[role] || false);
200
+ }
193
201
  _error(e) {
194
202
  // TODO: hub trigger error event
195
203
  console.error(e);
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.processData = processData;
7
+ exports.processSovrnProduct = processSovrnProduct;
8
+ var _commons = require("@miso.ai/commons");
9
+ const _excluded = ["sovrn_aff"],
10
+ _excluded2 = ["products"],
11
+ _excluded3 = ["id", "deeplink", "headline", "description", "currency", "retailPrice", "salePrice", "discountRate", "image", "thumbnail", "merchant"];
12
+ 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; }
13
+ function processData(data) {
14
+ if (!data || !data.value) {
15
+ return data;
16
+ }
17
+ const {
18
+ value
19
+ } = data;
20
+ return Object.assign({}, data, {
21
+ value: processValue(value)
22
+ });
23
+ }
24
+ function processValue(value) {
25
+ if (value.sovrn_aff) {
26
+ const {
27
+ sovrn_aff
28
+ } = value,
29
+ rest = _objectWithoutPropertiesLoose(value, _excluded);
30
+ value = Object.assign({}, rest, {
31
+ affiliation: processSovrnData(sovrn_aff)
32
+ });
33
+ }
34
+ return postProcessValue(value);
35
+ }
36
+ function postProcessValue(value) {
37
+ const {
38
+ affiliation
39
+ } = value;
40
+ if (!affiliation) {
41
+ return value;
42
+ }
43
+ let {
44
+ channel,
45
+ products
46
+ } = affiliation;
47
+ if (!products) {
48
+ return value;
49
+ }
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
+ });
63
+ }
64
+ function processSovrnData(_ref) {
65
+ let {
66
+ products
67
+ } = _ref,
68
+ sovrn_aff = _objectWithoutPropertiesLoose(_ref, _excluded2);
69
+ return Object.assign({
70
+ channel: 'sovrn'
71
+ }, sovrn_aff, {
72
+ products: products.map(processSovrnProduct)
73
+ });
74
+ }
75
+ function processSovrnProduct(_ref2) {
76
+ let {
77
+ id,
78
+ deeplink: url,
79
+ headline: title,
80
+ description,
81
+ currency,
82
+ retailPrice: original_price,
83
+ salePrice: sale_price,
84
+ discountRate: discount_rate_percent,
85
+ image: cover_image,
86
+ thumbnail,
87
+ merchant
88
+ } = _ref2,
89
+ product = _objectWithoutPropertiesLoose(_ref2, _excluded3);
90
+ const brand = merchant && merchant.name;
91
+ const brand_logo = merchant && merchant.logo;
92
+ return (0, _commons.trimObj)({
93
+ id: `sovrn-${id}`,
94
+ title,
95
+ description,
96
+ cover_image,
97
+ url,
98
+ currency,
99
+ original_price,
100
+ sale_price,
101
+ discount_rate_percent,
102
+ brand,
103
+ brand_logo,
104
+ custom_attributes: flatten(Object.assign({
105
+ sovrn_id: id,
106
+ thumbnail,
107
+ merchant
108
+ }, product))
109
+ });
110
+ }
111
+ function flatten(obj) {
112
+ let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
113
+ return Object.keys(obj).reduce((acc, key) => {
114
+ const value = obj[key];
115
+ if (value === undefined) {
116
+ return acc;
117
+ }
118
+ const prefixedKey = prefix ? `${prefix}_${key}` : key;
119
+ if (typeof value === 'object') {
120
+ return Object.assign({}, acc, flatten(value, prefixedKey));
121
+ }
122
+ return Object.assign({}, acc, {
123
+ [prefixedKey]: value
124
+ });
125
+ }, {});
126
+ }
@@ -8,7 +8,7 @@ exports.mergeOptions = mergeOptions;
8
8
  var _commons = require("@miso.ai/commons");
9
9
  var _index = require("../../defaults/ask/index.js");
10
10
  const _excluded = ["api_key", "api_host", "templates", "phrases"];
11
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
11
+ 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; }
12
12
  // TODO: generalize
13
13
 
14
14
  const {
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
8
  const _excluded = ["name", "plugin", "MisoClient"];
9
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
9
+ 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; }
10
10
  class Combo extends _commons.Component {
11
11
  constructor(_ref) {
12
12
  let {
@@ -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;
@@ -27,9 +27,10 @@ const ROLE = exports.ROLE = Object.freeze({
27
27
  RELATED_RESOURCES: 'related_resources',
28
28
  QUERY_SUGGESTIONS: 'query_suggestions',
29
29
  RELATED_QUESTIONS: 'related_questions',
30
+ AFFILIATION: 'affiliation',
30
31
  ERROR: 'error'
31
32
  });
32
- const DATA_ROLE_SET = new Set([ROLE.PRODUCTS, ROLE.CATEGORIES, ROLE.ATTRIBUTES, ROLE.RESULTS, ROLE.ITEMS, ROLE.QUESTION, ROLE.ANSWER, ROLE.SOURCES, ROLE.RELATED_RESOURCES, ROLE.QUERY_SUGGESTIONS, ROLE.RELATED_QUESTIONS]);
33
+ const DATA_ROLE_SET = new Set([ROLE.PRODUCTS, ROLE.CATEGORIES, ROLE.ATTRIBUTES, ROLE.RESULTS, ROLE.ITEMS, ROLE.QUESTION, ROLE.ANSWER, ROLE.SOURCES, ROLE.RELATED_RESOURCES, ROLE.QUERY_SUGGESTIONS, ROLE.RELATED_QUESTIONS, ROLE.AFFILIATION]);
33
34
  function isDataRole(role) {
34
35
  return DATA_ROLE_SET.has(role);
35
36
  }
@@ -40,6 +41,7 @@ const LAYOUT_CATEGORY = exports.LAYOUT_CATEGORY = Object.freeze({
40
41
  QUERY: 'query',
41
42
  RADIO: 'radio',
42
43
  TEXT: 'text',
44
+ AFFILIATION: 'affiliation',
43
45
  ERROR: 'error'
44
46
  });
45
47
  const EVENT_TYPE = exports.EVENT_TYPE = Object.freeze({
@@ -47,6 +49,7 @@ const EVENT_TYPE = exports.EVENT_TYPE = Object.freeze({
47
49
  VIEWABLE: 'viewable',
48
50
  CLICK: 'click'
49
51
  });
52
+ const TRACKING_EVENT_TYPES = exports.TRACKING_EVENT_TYPES = [EVENT_TYPE.IMPRESSION, EVENT_TYPE.VIEWABLE, EVENT_TYPE.CLICK];
50
53
  const TRACKING_STATUS = exports.TRACKING_STATUS = Object.freeze({
51
54
  UNTRACKED: 'untracked',
52
55
  TRACKING: 'tracking',
@@ -63,7 +66,7 @@ const STATUS = exports.STATUS = Object.freeze({
63
66
  NONEMPTY: 'nonempty'
64
67
  });
65
68
  function validateEventType(value) {
66
- if (value !== EVENT_TYPE.IMPRESSION && value !== EVENT_TYPE.VIEWABLE && value !== EVENT_TYPE.CLICK) {
69
+ if (TRACKING_EVENT_TYPES.indexOf(value) < 0) {
67
70
  throw new Error(`Unrecognized event type: ${value}`);
68
71
  }
69
72
  }
@@ -7,7 +7,7 @@ exports.wireFollowUps = wireFollowUps;
7
7
  exports.wireRelatedResources = wireRelatedResources;
8
8
  var _templates = require("./templates.js");
9
9
  const _excluded = ["template"];
10
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
10
+ 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; }
11
11
  function wireFollowUps(client, element) {
12
12
  let _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
13
13
  let {
@@ -12,7 +12,7 @@ const question = exports.question = 'You asked...';
12
12
  /**
13
13
  * The phrase displayed right before <miso-sources>
14
14
  */
15
- const sources = exports.sources = 'My reply is based on the following';
15
+ const sources = exports.sources = 'This reply is based on the following articles';
16
16
 
17
17
  /**
18
18
  * The phrase displayed right before <miso-query-suggestions>
@@ -14,7 +14,7 @@ const _excluded = ["classPrefix", "circledCitationIndex", "phrases"],
14
14
  _excluded2 = ["classes"];
15
15
  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); }
16
16
  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; }
17
- function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
17
+ 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; }
18
18
  // TODO: rename classPrefix -> rootClass?
19
19
  // TODO: placeholder
20
20
 
@@ -134,7 +134,7 @@ function querySuggestions(options) {
134
134
  }), '<miso-query-suggestions></miso-query-suggestions>']);
135
135
  }
136
136
  function answerGroup(options) {
137
- return [answer(options), sources(options), container(options, {
137
+ return [answer(options), affiliation(options), sources(options), container(options, {
138
138
  name: 'bottom-spacing',
139
139
  visibleWhen: 'ongoing'
140
140
  })];
@@ -148,7 +148,6 @@ function answer(options) {
148
148
  tag: 'div'
149
149
  }), '<miso-question></miso-question>', '<miso-answer></miso-answer>', '<miso-feedback></miso-feedback>']);
150
150
  }
151
- ;
152
151
  function sources(options) {
153
152
  return container(options, {
154
153
  name: 'sources',
@@ -158,7 +157,18 @@ function sources(options) {
158
157
  tag: 'h3'
159
158
  }), '<miso-sources></miso-sources>']);
160
159
  }
161
- ;
160
+ function affiliation(options) {
161
+ const {
162
+ affiliation = true
163
+ } = options || {};
164
+ if (!affiliation) {
165
+ return '';
166
+ }
167
+ return container(options, {
168
+ name: 'affiliation',
169
+ visibleWhen: 'nonempty'
170
+ }, ['<miso-affiliation></miso-affiliation>']);
171
+ }
162
172
  function phrase(options, _ref2) {
163
173
  let {
164
174
  name,
@@ -75,6 +75,12 @@ Object.defineProperty(exports, "MisoSourcesElement", {
75
75
  return _misoSources.default;
76
76
  }
77
77
  });
78
+ Object.defineProperty(exports, "MisoSovrnAffiliationElement", {
79
+ enumerable: true,
80
+ get: function () {
81
+ return _misoAffiliation.default;
82
+ }
83
+ });
78
84
  var _misoComponent = _interopRequireDefault(require("./miso-component.js"));
79
85
  var _misoQuery = _interopRequireDefault(require("./miso-query.js"));
80
86
  var _misoQuerySuggestions = _interopRequireDefault(require("./miso-query-suggestions.js"));
@@ -86,5 +92,6 @@ var _misoAnswer = _interopRequireDefault(require("./miso-answer.js"));
86
92
  var _misoSources = _interopRequireDefault(require("./miso-sources.js"));
87
93
  var _misoRelatedResources = _interopRequireDefault(require("./miso-related-resources.js"));
88
94
  var _misoRelatedQuestions = _interopRequireDefault(require("./miso-related-questions.js"));
95
+ var _misoAffiliation = _interopRequireDefault(require("./miso-affiliation.js"));
89
96
  var _misoError = _interopRequireDefault(require("./miso-error.js"));
90
97
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _misoComponent = _interopRequireDefault(require("./miso-component.js"));
8
+ var _constants = require("../../constants.js");
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
+ class MisoAffiliationElement extends _misoComponent.default {
11
+ constructor() {
12
+ super({
13
+ role: _constants.ROLE.AFFILIATION
14
+ });
15
+ }
16
+ static get tagName() {
17
+ return 'miso-affiliation';
18
+ }
19
+ }
20
+ exports.default = MisoAffiliationElement;