@miso.ai/client-sdk-ui 1.10.0-beta.2 → 1.10.0-beta.3

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 (49) hide show
  1. package/dist/cjs/actor/data.js +1 -1
  2. package/dist/cjs/actor/tracker.js +1 -1
  3. package/dist/cjs/actor/view.js +1 -1
  4. package/dist/cjs/affiliation/index.js +99 -0
  5. package/dist/cjs/combo/ask/options.js +1 -1
  6. package/dist/cjs/combo/base.js +1 -1
  7. package/dist/cjs/constants.js +3 -1
  8. package/dist/cjs/defaults/ask/controls.js +1 -1
  9. package/dist/cjs/defaults/ask/templates.js +14 -4
  10. package/dist/cjs/element/role/index.js +7 -0
  11. package/dist/cjs/element/role/miso-affiliation.js +20 -0
  12. package/dist/cjs/layout/affiliation/affiliation.js +109 -0
  13. package/dist/cjs/layout/banner/banner.js +1 -1
  14. package/dist/cjs/layout/container/container.js +1 -1
  15. package/dist/cjs/layout/error/error.js +1 -1
  16. package/dist/cjs/layout/index.js +7 -0
  17. package/dist/cjs/layout/input/option-list.js +1 -1
  18. package/dist/cjs/layout/input/search-box.js +1 -1
  19. package/dist/cjs/layout/list/cards.js +1 -1
  20. package/dist/cjs/layout/list/carousel.js +1 -1
  21. package/dist/cjs/layout/list/collection.js +7 -1
  22. package/dist/cjs/layout/list/list.js +1 -1
  23. package/dist/cjs/layout/radio/feedback.js +1 -1
  24. package/dist/cjs/layout/radio/radio.js +1 -1
  25. package/dist/cjs/layout/raf.js +1 -1
  26. package/dist/cjs/layout/template.js +1 -1
  27. package/dist/cjs/layout/templates.js +123 -44
  28. package/dist/cjs/layout/text/text.js +1 -1
  29. package/dist/cjs/layout/text/typewriter/index.js +1 -1
  30. package/dist/cjs/plugin.js +1 -1
  31. package/dist/cjs/util/tracker.js +1 -1
  32. package/dist/cjs/version.js +1 -1
  33. package/dist/cjs/workflow/ask.js +12 -2
  34. package/dist/cjs/workflow/asks.js +1 -1
  35. package/dist/cjs/workflow/base.js +1 -1
  36. package/dist/cjs/workflow/explore.js +1 -1
  37. package/dist/cjs/workflow/options.js +1 -1
  38. package/package.json +2 -2
  39. package/src/affiliation/index.js +83 -0
  40. package/src/constants.js +3 -0
  41. package/src/defaults/ask/templates.js +14 -2
  42. package/src/element/role/index.js +1 -0
  43. package/src/element/role/miso-affiliation.js +16 -0
  44. package/src/layout/affiliation/affiliation.js +84 -0
  45. package/src/layout/index.js +1 -0
  46. package/src/layout/list/collection.js +7 -1
  47. package/src/layout/templates.js +92 -26
  48. package/src/version.js +1 -1
  49. package/src/workflow/ask.js +6 -1
@@ -3,15 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.affiliation = affiliation;
7
+ exports.affiliationInfoBlock = affiliationInfoBlock;
6
8
  exports.article = article;
7
9
  exports.articleInfoBlock = articleInfoBlock;
10
+ exports.brandBlock = brandBlock;
11
+ exports.cta = cta;
12
+ exports.ctaBlock = ctaBlock;
13
+ exports.dateBlock = dateBlock;
14
+ exports.descriptionBlock = descriptionBlock;
8
15
  exports.helpers = void 0;
9
16
  exports.imageBlock = imageBlock;
10
17
  exports.indexBlock = indexBlock;
18
+ exports.priceBlock = priceBlock;
11
19
  exports.product = product;
12
20
  exports.productInfoBlock = productInfoBlock;
13
21
  exports.question = question;
14
22
  exports.requiresImplementation = requiresImplementation;
23
+ exports.titleBlock = titleBlock;
15
24
  exports.unimplemented = unimplemented;
16
25
  var _commons = require("@miso.ai/commons");
17
26
  var _constants = require("../constants.js");
@@ -47,92 +56,162 @@ function article(layout, state, data, meta) {
47
56
  const [openTag, closeTag] = tagPair(layout, data);
48
57
  return [openTag, (templates.imageBlock || imageBlock)(layout, data, meta), (templates.infoBlock || templates.articleInfoBlock || articleInfoBlock)(layout, data, meta), (templates.indexBlock || indexBlock)(layout, data, meta), closeTag].join('');
49
58
  }
50
- function productInfoBlock(_ref, _ref2) {
59
+ function affiliation(layout, state, data, meta) {
60
+ const {
61
+ templates
62
+ } = layout;
63
+ const [openTag, closeTag] = tagPair(layout, data);
64
+ return [openTag, (templates.infoBlock || templates.affiliationInfoBlock || affiliationInfoBlock)(layout, data, meta), (templates.imageBlock || imageBlock)(layout, data, meta), (templates.brandBlock || brandBlock)(layout, data, meta), closeTag].join('');
65
+ }
66
+ function affiliationInfoBlock(layout, data, meta) {
67
+ const {
68
+ className,
69
+ templates
70
+ } = layout;
71
+ return `<div class="${className}__item-info-container">${[(templates.titleBlock || titleBlock)(layout, data, meta), (templates.descriptionBlock || descriptionBlock)(layout, data, meta), (templates.priceBlock || priceBlock)(layout, data, meta), (templates.ctaBlock || ctaBlock)(layout, data, meta)].join('')}</div>`;
72
+ }
73
+ function productInfoBlock(layout, data, meta) {
74
+ const {
75
+ className,
76
+ templates
77
+ } = layout;
78
+ return `<div class="${className}__item-info-container">${[(templates.titleBlock || titleBlock)(layout, data, meta), (templates.descriptionBlock || descriptionBlock)(layout, data, meta), (templates.priceBlock || priceBlock)(layout, data, meta)].join('')}</div>`;
79
+ }
80
+ function articleInfoBlock(layout, data, meta) {
81
+ const {
82
+ className,
83
+ templates
84
+ } = layout;
85
+ return `<div class="${className}__item-info-container">${[(templates.titleBlock || titleBlock)(layout, data, meta), (templates.dateBlock || dateBlock)(layout, data, meta), (templates.descriptionBlock || descriptionBlock)(layout, data, meta), (templates.ctaBlock || ctaBlock)(layout, data, meta)].join('')}</div>`;
86
+ }
87
+ function titleBlock(_ref, _ref2) {
51
88
  let {
52
89
  className
53
90
  } = _ref;
54
91
  let {
55
- title,
56
- description,
57
- sale_price,
58
- original_price
92
+ title
59
93
  } = _ref2;
60
- let content = '';
61
- if (title) {
62
- content += `<div class="${className}__item-title">${(0, _commons.escapeHtml)(title)}</div>`;
63
- }
64
- if (description) {
65
- content += `<div class="${className}__item-desc">${(0, _commons.escapeHtml)(description)}</div>`;
66
- }
67
- const price = sale_price || original_price;
68
- if (price) {
69
- content += `<hr><div class="${className}__item-price">${price}</div>`;
70
- // TODO: enhance this
94
+ return title ? `<div class="${className}__item-title">${(0, _commons.escapeHtml)(title)}</div>` : '';
95
+ }
96
+ function brandBlock(_ref3, _ref4) {
97
+ let {
98
+ className
99
+ } = _ref3;
100
+ let {
101
+ brand,
102
+ brand_logo
103
+ } = _ref4;
104
+ if (!brand && !brand_logo) {
105
+ return '';
71
106
  }
72
- return `<div class="${className}__item-info-container">${content}</div>`;
107
+ brand_logo = undefined;
108
+ const content = brand_logo ? `<img class="${className}__item-brand-logo" src="${brand_logo}"${brand ? ` alt="${brand}"` : ''}>` : `<div class="${className}__item-brand">${brand}</div>`;
109
+ return `<div class="${className}__item-brand-container">${content}</div>`;
73
110
  }
74
- function articleInfoBlock(_ref3, _ref4) {
111
+ function descriptionBlock(_ref5, _ref6) {
112
+ let {
113
+ className
114
+ } = _ref5;
115
+ let {
116
+ snippet,
117
+ description
118
+ } = _ref6;
119
+ return snippet ? `<div class="${className}__item-snippet">${snippet}</div>` : description ? `<div class="${className}__item-desc">${(0, _commons.escapeHtml)(description)}</div>` : '';
120
+ }
121
+ function dateBlock(_ref7, _ref8) {
75
122
  let {
76
123
  className,
77
124
  templates
78
- } = _ref3;
125
+ } = _ref7;
79
126
  let {
80
- title,
81
- snippet,
82
- description,
83
127
  created_at,
84
128
  updated_at,
85
129
  published_at
86
- } = _ref4;
130
+ } = _ref8;
87
131
  const date = published_at || created_at || updated_at;
88
- let content = '';
89
- if (title) {
90
- content += `<div class="${className}__item-title">${(0, _commons.escapeHtml)(title)}</div>`;
132
+ return date ? `<div class="${className}__item-date">${formatDate(date, templates.date)}</div>` : '';
133
+ }
134
+ function priceBlock(_ref9, _ref10) {
135
+ let {
136
+ className
137
+ } = _ref9;
138
+ let {
139
+ sale_price,
140
+ original_price,
141
+ discount_rate_percent,
142
+ currency = 'USD'
143
+ } = _ref10;
144
+ const price = sale_price || original_price;
145
+ if (!price) {
146
+ return '';
91
147
  }
92
- if (date) {
93
- content += `<div class="${className}__item-date">${formatDate(date, templates.date)}</div>`;
148
+ const has_price_difference = original_price !== undefined && sale_price !== undefined && sale_price < original_price;
149
+ discount_rate_percent = discount_rate_percent || (has_price_difference ? Math.floor((1 - sale_price / original_price) * 100) : undefined);
150
+ let content = '';
151
+ if (has_price_difference) {
152
+ content += `<span class="${className}__item-original-price miso-price" data-currency="${currency}">${original_price}</span><br>`;
94
153
  }
95
- if (snippet) {
96
- content += `<div class="${className}__item-snippet">${snippet}</div>`;
97
- } else if (description) {
98
- content += `<div class="${className}__item-desc">${(0, _commons.escapeHtml)(description)}</div>`;
154
+ content += `<span class="${className}__item-price miso-price" data-currency="${currency}">${price}</span>`;
155
+ if (discount_rate_percent) {
156
+ content += `<span class="${className}__item-discount-rate"> (${discount_rate_percent}% off)</span>`;
99
157
  }
100
- return `<div class="${className}__item-info-container">${content}</div>`;
158
+ return `<div class="${className}__item-price-container">${content}</div>`;
101
159
  }
102
- function imageBlock(_ref5, _ref6) {
160
+ function imageBlock(_ref11, _ref12) {
103
161
  let {
104
162
  className
105
- } = _ref5;
163
+ } = _ref11;
106
164
  let {
107
165
  cover_image
108
- } = _ref6;
166
+ } = _ref12;
109
167
  if (!cover_image) {
110
168
  return '';
111
169
  }
112
170
  const img = `<img class="${className}__item-cover-image" src="${cover_image}">`;
113
171
  return `<div class="${className}__item-cover-image-container">${img}</div>`;
114
172
  }
115
- function indexBlock(_ref7, data, _ref8) {
173
+ function indexBlock(_ref13, data, _ref14) {
116
174
  let {
117
175
  className
118
- } = _ref7;
176
+ } = _ref13;
119
177
  let {
120
178
  index
121
- } = _ref8;
122
- const i = index + 1;
123
- return `<div class="${className}__item-index-container"><span class="${className}__item-index miso-citation-index" data-index="${i}"></span></div>`;
179
+ } = _ref14;
180
+ return `<div class="${className}__item-index-container"><span class="${className}__item-index miso-citation-index" data-index="${index + 1}"></span></div>`;
181
+ }
182
+ function ctaBlock(layout, data, meta) {
183
+ const {
184
+ className,
185
+ templates
186
+ } = layout;
187
+ let _cta = templates.cta || cta;
188
+ if (typeof _cta === 'function') {
189
+ _cta = _cta(layout, data, meta);
190
+ }
191
+ return _cta ? `<div class="${className}__item-cta-container">${_cta}</div>` : '';
192
+ }
193
+ function cta(layout, data, meta) {
194
+ const {
195
+ className,
196
+ templates
197
+ } = layout;
198
+ let text = templates.ctaText;
199
+ if (typeof text === 'function') {
200
+ text = text(layout, data, meta);
201
+ }
202
+ return text ? `<div class="${className}__item-cta">${text}</div>` : '';
124
203
  }
125
204
 
126
205
  // helpers //
127
- function tagPair(_ref9, _ref10) {
206
+ function tagPair(_ref15, _ref16) {
128
207
  let {
129
208
  className,
130
209
  options = {}
131
- } = _ref9;
210
+ } = _ref15;
132
211
  let {
133
212
  product_id,
134
213
  url
135
- } = _ref10;
214
+ } = _ref16;
136
215
  let {
137
216
  classSuffix = 'item-body',
138
217
  role = 'item'
@@ -9,7 +9,7 @@ var _constants = require("../../constants.js");
9
9
  var _template = _interopRequireDefault(require("../template.js"));
10
10
  const _excluded = ["className", "templates", "tag"];
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
  const TYPE = 'text';
14
14
  const DEFAULT_CLASSNAME = 'miso-text';
15
15
  function root(layout, state) {
@@ -12,7 +12,7 @@ var _plaintext = _interopRequireDefault(require("./plaintext.js"));
12
12
  var _utils = require("./utils.js");
13
13
  const _excluded = ["className", "tag", "format", "tooltip"];
14
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
  const TYPE = 'typewriter';
17
17
  const DEFAULT_CLASSNAME = 'miso-typewriter';
18
18
  class TypewriterLayout extends _progressive.default {
@@ -19,7 +19,7 @@ const _excluded = ["containers", "roles", "combos"];
19
19
  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); }
20
20
  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; }
21
21
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
22
- 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; }
22
+ 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; }
23
23
  const PLUGIN_ID = 'std:ui';
24
24
  class UiPlugin extends _commons.Component {
25
25
  static get id() {
@@ -12,7 +12,7 @@ var _proxy = _interopRequireDefault(require("./proxy.js"));
12
12
  const _excluded = ["impression", "viewable", "click"],
13
13
  _excluded2 = ["proxyElement", "element", "sessionId", "active", "bindings"];
14
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
  const {
17
17
  IMPRESSION,
18
18
  VIEWABLE,
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = exports.default = '1.10.0-beta.2';
7
+ var _default = exports.default = '1.10.0-beta.3';
@@ -11,11 +11,12 @@ var sources = _interopRequireWildcard(require("../source/index.js"));
11
11
  var _index2 = require("../actor/index.js");
12
12
  var _constants = require("../constants.js");
13
13
  var _index3 = require("../layout/index.js");
14
+ var _index4 = require("../affiliation/index.js");
14
15
  const _excluded = ["q", "qs"];
15
16
  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
17
  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
18
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
- 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; }
19
+ 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; }
19
20
  const DEFAULT_API_OPTIONS = Object.freeze({
20
21
  group: _commons.API.GROUP.ASK,
21
22
  name: _commons.API.NAME.QUESTIONS,
@@ -54,7 +55,13 @@ const DEFAULT_LAYOUTS = Object.freeze({
54
55
  incremental: true,
55
56
  itemType: 'article'
56
57
  }],
57
- [_constants.ROLE.QUERY_SUGGESTIONS]: _index3.OptionListLayout.type
58
+ [_constants.ROLE.QUERY_SUGGESTIONS]: _index3.OptionListLayout.type,
59
+ [_constants.ROLE.AFFILIATION]: [_index3.AffiliationLayout.type, {
60
+ itemType: 'affiliation',
61
+ link: {
62
+ rel: 'noopener nofollow'
63
+ }
64
+ }]
58
65
  });
59
66
  const DEFAULT_TRACKERS = Object.freeze({
60
67
  [_constants.ROLE.SOURCES]: {},
@@ -251,6 +258,9 @@ class Ask extends _base.default {
251
258
  }
252
259
  }
253
260
 
261
+ // affiliation
262
+ data = (0, _index4.processData)(data);
263
+
254
264
  // 1. put answer_stage to meta
255
265
  // 2. mark ongoing flag
256
266
  return Object.assign({}, data, {
@@ -8,7 +8,7 @@ var _context = _interopRequireDefault(require("./context.js"));
8
8
  var _ask = _interopRequireDefault(require("./ask.js"));
9
9
  const _excluded = ["root", "events"];
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
  class Asks extends _context.default {
13
13
  constructor(plugin, client) {
14
14
  super('asks', plugin, client);
@@ -16,7 +16,7 @@ const _excluded = ["layouts", "interactions"],
16
16
  _excluded3 = ["context"];
17
17
  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); }
18
18
  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; }
19
- 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; }
19
+ 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; }
20
20
  const DEFAULT_LAYOUTS = Object.freeze({
21
21
  [_constants.ROLE.CONTAINER]: _index3.ContainerLayout.type,
22
22
  [_constants.ROLE.ERROR]: _index3.ErrorLayout.type
@@ -12,7 +12,7 @@ var _constants = require("../constants.js");
12
12
  var _index2 = require("../layout/index.js");
13
13
  const _excluded = ["value"];
14
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
  const DEFAULT_API_OPTIONS = Object.freeze({
17
17
  group: _commons.API.GROUP.ASK,
18
18
  name: _commons.API.NAME.RELATED_QUESTIONS
@@ -19,7 +19,7 @@ exports.normalizeLayoutsOptions = normalizeLayoutsOptions;
19
19
  exports.normalizeTrackers = normalizeTrackers;
20
20
  var _commons = require("@miso.ai/commons");
21
21
  var _constants = require("../constants.js");
22
- 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; }
22
+ 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; }
23
23
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
24
24
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
25
25
  // normalize //
package/package.json CHANGED
@@ -26,7 +26,7 @@
26
26
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@miso.ai/commons": "1.10.0-beta.2"
29
+ "@miso.ai/commons": "1.10.0-beta.3"
30
30
  },
31
- "version": "1.10.0-beta.2"
31
+ "version": "1.10.0-beta.3"
32
32
  }
@@ -0,0 +1,83 @@
1
+ import { trimObj } from '@miso.ai/commons';
2
+
3
+ export function processData(data) {
4
+ if (!data || !data.value) {
5
+ return data;
6
+ }
7
+ const { value } = data;
8
+ return {
9
+ ...data,
10
+ value: processValue(value)
11
+ };
12
+ }
13
+
14
+ function processValue(value) {
15
+ if (value.sovrn_aff) {
16
+ const { sovrn_aff, ...rest } = value;
17
+ return {
18
+ ...rest,
19
+ affiliation: processSovrnData(sovrn_aff),
20
+ }
21
+ }
22
+ return value;
23
+ }
24
+
25
+ function processSovrnData({ products, ...sovrn_aff }) {
26
+ return {
27
+ channel: 'sovrn',
28
+ ...sovrn_aff,
29
+ products: products.map(processSovrnProduct),
30
+ };
31
+ }
32
+
33
+ export function processSovrnProduct({
34
+ id,
35
+ deeplink: url,
36
+ name: title,
37
+ headline: description,
38
+ currency,
39
+ retailPrice: original_price,
40
+ salePrice: sale_price,
41
+ discountRate: discount_rate_percent,
42
+ image: cover_image,
43
+ thumbnail,
44
+ merchant,
45
+ ...product
46
+ }) {
47
+ const brand = merchant && merchant.name;
48
+ const brand_logo = merchant && merchant.logo;
49
+ return trimObj({
50
+ id: `sovrn-${id}`,
51
+ channel: 'sovrn',
52
+ title,
53
+ description,
54
+ cover_image,
55
+ url,
56
+ currency,
57
+ original_price,
58
+ sale_price,
59
+ discount_rate_percent,
60
+ brand,
61
+ brand_logo,
62
+ custom_attributes: flatten({
63
+ sovrn_id: id,
64
+ thumbnail,
65
+ merchant,
66
+ ...product,
67
+ }),
68
+ });
69
+ }
70
+
71
+ function flatten(obj, prefix = '') {
72
+ return Object.keys(obj).reduce((acc, key) => {
73
+ const value = obj[key];
74
+ if (value === undefined) {
75
+ return acc;
76
+ }
77
+ const prefixedKey = prefix ? `${prefix}_${key}` : key;
78
+ if (typeof value === 'object') {
79
+ return { ...acc, ...flatten(value, prefixedKey) };
80
+ }
81
+ return { ...acc, [prefixedKey]: value };
82
+ }, {});
83
+ }
package/src/constants.js CHANGED
@@ -19,6 +19,7 @@ export const ROLE = Object.freeze({
19
19
  RELATED_RESOURCES: 'related_resources',
20
20
  QUERY_SUGGESTIONS: 'query_suggestions',
21
21
  RELATED_QUESTIONS: 'related_questions',
22
+ AFFILIATION: 'affiliation',
22
23
  ERROR: 'error',
23
24
  });
24
25
 
@@ -34,6 +35,7 @@ const DATA_ROLE_SET = new Set([
34
35
  ROLE.RELATED_RESOURCES,
35
36
  ROLE.QUERY_SUGGESTIONS,
36
37
  ROLE.RELATED_QUESTIONS,
38
+ ROLE.AFFILIATION,
37
39
  ]);
38
40
 
39
41
  export function isDataRole(role) {
@@ -47,6 +49,7 @@ export const LAYOUT_CATEGORY = Object.freeze({
47
49
  QUERY: 'query',
48
50
  RADIO: 'radio',
49
51
  TEXT: 'text',
52
+ AFFILIATION: 'affiliation',
50
53
  ERROR: 'error',
51
54
  });
52
55
 
@@ -106,6 +106,7 @@ function querySuggestions(options) {
106
106
  function answerGroup(options) {
107
107
  return [
108
108
  answer(options),
109
+ affiliation(options),
109
110
  sources(options),
110
111
  container(options, { name: 'bottom-spacing', visibleWhen: 'ongoing' }),
111
112
  ];
@@ -119,7 +120,7 @@ function answer(options) {
119
120
  '<miso-answer></miso-answer>',
120
121
  '<miso-feedback></miso-feedback>',
121
122
  ]);
122
- };
123
+ }
123
124
 
124
125
  function sources(options) {
125
126
  return container(options, { name: 'sources', visibleWhen: 'nonempty' }, [
@@ -127,7 +128,18 @@ function sources(options) {
127
128
  phrase(options, { name: 'sources', tag: 'h3' }),
128
129
  '<miso-sources></miso-sources>',
129
130
  ]);
130
- };
131
+ }
132
+
133
+ function affiliation(options) {
134
+ const { affiliation = true } = options || {};
135
+ if (!affiliation) {
136
+ return '';
137
+ }
138
+ return container(options, { name: 'affiliation', visibleWhen: 'nonempty' }, [
139
+ '<hr>',
140
+ '<miso-affiliation></miso-affiliation>',
141
+ ]);
142
+ }
131
143
 
132
144
  function phrase(options, { name, tag = 'div' }) {
133
145
  const { classPrefix } = options;
@@ -9,4 +9,5 @@ export { default as MisoAnswerElement } from './miso-answer.js';
9
9
  export { default as MisoSourcesElement } from './miso-sources.js';
10
10
  export { default as MisoRelatedResourcesElement } from './miso-related-resources.js';
11
11
  export { default as MisoRelatedQuestionsElement } from './miso-related-questions.js';
12
+ export { default as MisoSovrnAffiliationElement } from './miso-affiliation.js';
12
13
  export { default as MisoErrorElement } from './miso-error.js';
@@ -0,0 +1,16 @@
1
+ import MisoComponentElement from './miso-component.js';
2
+ import { ROLE } from '../../constants.js';
3
+
4
+ export default class MisoAffiliationElement extends MisoComponentElement {
5
+
6
+ constructor() {
7
+ super({
8
+ role: ROLE.AFFILIATION,
9
+ });
10
+ }
11
+
12
+ static get tagName() {
13
+ return 'miso-affiliation';
14
+ }
15
+
16
+ }
@@ -0,0 +1,84 @@
1
+ import { STATUS, LAYOUT_CATEGORY } from '../../constants.js';
2
+ import CollectionLayout from '../list/collection.js';
3
+ import { affiliation } from '../templates.js';
4
+
5
+ const TYPE = 'affiliation';
6
+ const DEFAULT_CLASSNAME = 'miso-affiliation';
7
+
8
+ function root(layout, state) {
9
+ const { className, role, templates } = layout;
10
+ const { status } = state;
11
+ const roleAttr = role ? ` data-role="${role}"` : '';
12
+ const data = state.value || {};
13
+ const channelAttr = data.channel ? ` data-channel="${data.channel}"` : '';
14
+ return `<div class="${className} ${status}"${roleAttr}${channelAttr}>${status === STATUS.READY ? templates[status](layout, state) : ''}</div>`;
15
+ }
16
+
17
+ function ready(layout, state) {
18
+ const { templates } = layout;
19
+ const { products } = state.value || {};
20
+
21
+ if (products && products.length > 0) {
22
+ return templates.body(layout, state);
23
+ } else {
24
+ return templates.empty(layout, state);
25
+ }
26
+ }
27
+
28
+ function body(layout, state) {
29
+ const { className, templates } = layout;
30
+ let { channel, products } = state.value;
31
+ products = products.map(product => ({ channel, ...product }));
32
+ return `<div class="${className}__body">${templates.header(layout, state)}${templates.list(layout, state, products)}</div>`;
33
+ }
34
+
35
+ function header(layout, state) {
36
+ const { className, templates } = layout;
37
+ let { headerText } = templates;
38
+ if (typeof headerText === 'function') {
39
+ headerText = headerText(layout, state);
40
+ }
41
+ if (!headerText) {
42
+ return '';
43
+ }
44
+ return `<div class="${className}__header"><div class="${className}__header-tab">${headerText}</div></div>`;
45
+ }
46
+
47
+ const DEFAULT_TEMPLATES = Object.freeze({
48
+ root,
49
+ [STATUS.READY]: ready,
50
+ body,
51
+ header,
52
+ affiliation,
53
+ ctaText: 'View',
54
+ headerText: 'Featured',
55
+ });
56
+
57
+ const INHERITED_DEFAULT_TEMPLATES = Object.freeze({
58
+ ...CollectionLayout.defaultTemplates,
59
+ ...DEFAULT_TEMPLATES,
60
+ });
61
+
62
+ export default class AffiliationLayout extends CollectionLayout {
63
+
64
+ static get category() {
65
+ return LAYOUT_CATEGORY.AFFILIATION;
66
+ }
67
+
68
+ static get type() {
69
+ return TYPE;
70
+ }
71
+
72
+ static get defaultTemplates() {
73
+ return INHERITED_DEFAULT_TEMPLATES;
74
+ }
75
+
76
+ static get defaultClassName() {
77
+ return DEFAULT_CLASSNAME;
78
+ }
79
+
80
+ constructor({ className = DEFAULT_CLASSNAME, templates, ...options } = {}) {
81
+ super({ className, itemType: 'affiliation', templates: { ...DEFAULT_TEMPLATES, ...templates }, ...options });
82
+ }
83
+
84
+ }
@@ -11,3 +11,4 @@ export { default as OptionListLayout } from './input/option-list.js';
11
11
  export { default as FeedbackLayout } from './radio/feedback.js';
12
12
  export { default as TextLayout } from './text/text.js';
13
13
  export { default as TypewriterLayout } from './text/typewriter/index.js';
14
+ export { default as AffiliationLayout } from './affiliation/affiliation.js';
@@ -1,7 +1,7 @@
1
1
  import { defineValues } from '@miso.ai/commons';
2
2
  import { STATUS, LAYOUT_CATEGORY } from '../../constants.js';
3
3
  import TemplateBasedLayout from '../template.js';
4
- import { product, article, question, productInfoBlock, articleInfoBlock, imageBlock, indexBlock, helpers } from '../templates.js';
4
+ import { product, article, question, productInfoBlock, articleInfoBlock, titleBlock, brandBlock, descriptionBlock, dateBlock, priceBlock, ctaBlock, cta, imageBlock, indexBlock, helpers } from '../templates.js';
5
5
 
6
6
  const VALUE = Symbol.for('miso.value');
7
7
 
@@ -59,6 +59,12 @@ const DEFAULT_TEMPLATES = Object.freeze({
59
59
  item,
60
60
  productInfoBlock,
61
61
  articleInfoBlock,
62
+ titleBlock,
63
+ descriptionBlock,
64
+ dateBlock,
65
+ priceBlock,
66
+ ctaBlock,
67
+ cta,
62
68
  imageBlock,
63
69
  indexBlock,
64
70
  helpers,