@miso.ai/client-sdk-ui 1.13.0-beta.4 → 1.13.0-beta.6

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.
@@ -59,21 +59,6 @@ class Tracker {
59
59
  items: itemless ? undefined : items
60
60
  }, meta));
61
61
  }
62
- submit({
63
- value
64
- }) {
65
- this._syncSession();
66
- this._sendToHub({
67
- type: _constants.EVENT_TYPE.SUBMIT,
68
- value
69
- });
70
- }
71
- heartbeat() {
72
- this._syncSession();
73
- this._sendToHub({
74
- type: _constants.EVENT_TYPE.HEARTBEAT
75
- });
76
- }
77
62
  _sendToHub(args) {
78
63
  this._hub.trigger(fields.tracker(), Object.freeze((0, _commons.trimObj)(Object.assign({
79
64
  role: this._role
@@ -110,7 +95,15 @@ class Tracker {
110
95
  }
111
96
  exports.default = Tracker;
112
97
  for (const type of _constants.PERFORMANCE_EVENT_TYPES) {
113
- Tracker.prototype[type] = function (items, meta) {
98
+ Tracker.prototype[(0, _commons.snakeToLowerCamel)(type)] = function (items, meta) {
114
99
  this._trigger(type, items, meta);
115
100
  };
101
+ }
102
+ for (const type of _constants.DIRECT_TRACKING_EVENT_TYPES) {
103
+ Tracker.prototype[(0, _commons.snakeToLowerCamel)(type)] = function (args) {
104
+ this._syncSession();
105
+ this._sendToHub(Object.assign({}, args, {
106
+ type
107
+ }));
108
+ };
116
109
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.WORKFLOW_CONFIGURABLE = exports.TRACKING_STATUS = exports.TRACKING_EVENT_TYPES = exports.STATUS = exports.ROLE = exports.REQUEST_TYPE = exports.QUESTION_SOURCE = exports.PERFORMANCE_EVENT_TYPES = exports.EVENT_TYPE = exports.DEFAULT_UNIT_ID = exports.ATTR_DATA_MISO_UNIT_ID = exports.ATTR_DATA_MISO_PRODUCT_ID = void 0;
6
+ exports.WORKFLOW_CONFIGURABLE = exports.TRACKING_STATUS = exports.TRACKING_EVENT_TYPES = exports.STATUS = exports.ROLE = exports.REQUEST_TYPE = exports.QUESTION_SOURCE = exports.PERFORMANCE_EVENT_TYPES = exports.EVENT_TYPE = exports.DIRECT_TRACKING_EVENT_TYPES = 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.isPerformanceEventType = isPerformanceEventType;
9
9
  exports.isProductRole = isProductRole;
@@ -53,10 +53,12 @@ const EVENT_TYPE = exports.EVENT_TYPE = Object.freeze({
53
53
  CLICK: 'click',
54
54
  SUBMIT: 'submit',
55
55
  FEEDBACK: 'feedback',
56
- HEARTBEAT: 'heartbeat'
56
+ HEARTBEAT: 'heartbeat',
57
+ GENERIC_CLICK: 'generic_click'
57
58
  });
58
59
  const TRACKING_EVENT_TYPES = exports.TRACKING_EVENT_TYPES = [EVENT_TYPE.IMPRESSION, EVENT_TYPE.VIEWABLE, EVENT_TYPE.CLICK, EVENT_TYPE.SUBMIT, EVENT_TYPE.FEEDBACK, EVENT_TYPE.HEARTBEAT];
59
60
  const PERFORMANCE_EVENT_TYPES = exports.PERFORMANCE_EVENT_TYPES = [EVENT_TYPE.IMPRESSION, EVENT_TYPE.VIEWABLE, EVENT_TYPE.CLICK];
61
+ const DIRECT_TRACKING_EVENT_TYPES = exports.DIRECT_TRACKING_EVENT_TYPES = [EVENT_TYPE.SUBMIT, EVENT_TYPE.HEARTBEAT, EVENT_TYPE.GENERIC_CLICK];
60
62
  const PERFORMANCE_EVENT_TYPE_SET = new Set(PERFORMANCE_EVENT_TYPES);
61
63
  function isPerformanceEventType(type) {
62
64
  return PERFORMANCE_EVENT_TYPE_SET.has(type);
@@ -22,6 +22,6 @@ const keywords = exports.keywords = 'You searched for “${value}”';
22
22
  /**
23
23
  * The phrase to display <miso-total>
24
24
  */
25
- const total = exports.total = '${value} Results';
25
+ const total = exports.total = '${value}';
26
26
  const showMore = exports.showMore = 'Show more';
27
27
  const showLess = exports.showLess = 'Show less';
@@ -11,9 +11,7 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e
11
11
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
12
12
  const TYPE = 'text';
13
13
  const DEFAULT_CLASSNAME = 'miso-text';
14
- function root(layout, {
15
- value
16
- }) {
14
+ function root(layout, state) {
17
15
  const {
18
16
  className,
19
17
  role,
@@ -23,8 +21,13 @@ function root(layout, {
23
21
  }
24
22
  } = layout;
25
23
  const roleAttr = role ? `data-role="${role}"` : '';
26
- const content = value !== undefined ? (0, _commons.escapeHtml)(getFormatFunction(layout)(value)) : '';
27
- return raw ? content : `<${tag} class="${className}" ${roleAttr}>${content}</${tag}>`;
24
+ const text = layout.templates.content(layout, state);
25
+ return raw ? text : `<${tag} class="${className}" ${roleAttr}>${text}</${tag}>`;
26
+ }
27
+ function content(layout, {
28
+ value
29
+ }) {
30
+ return value !== undefined ? (0, _commons.escapeHtml)(getFormatFunction(layout)(value)) : '';
28
31
  }
29
32
  function getFormatFunction(layout) {
30
33
  let {
@@ -55,7 +58,8 @@ function getFormatFunction(layout) {
55
58
  }
56
59
  }
57
60
  const DEFAULT_TEMPLATES = Object.freeze({
58
- root
61
+ root,
62
+ content
59
63
  });
60
64
  class TextLayout extends _template.default {
61
65
  static get type() {
@@ -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.13.0-beta.4';
7
+ var _default = exports.default = '1.13.0-beta.6';
@@ -187,6 +187,7 @@ class Explore extends _unit.default {
187
187
  }));
188
188
  }
189
189
  _getSubmitUrl(args) {
190
+ // TODO: if trending_questions -> qs = '_trending'
190
191
  let url = _useLink.UseLinkMixin.prototype._getSubmitUrl.call(this, args);
191
192
  if (!args.generated || !this._productId) {
192
193
  return url;
@@ -35,7 +35,8 @@ exports.writeUnanswerableToMeta = writeUnanswerableToMeta;
35
35
  var _commons = require("@miso.ai/commons");
36
36
  var _constants = require("../constants.js");
37
37
  var _index = require("../actor/index.js");
38
- const _excluded = ["qs"];
38
+ const _excluded = ["qs"],
39
+ _excluded2 = ["role", "type", "items"];
39
40
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
40
41
  // role mappings //
41
42
  function mappingSortData(_, {
@@ -401,10 +402,11 @@ function carryOverQuestionIdToData(data, oldData) {
401
402
  // interactions //
402
403
  function buildBaseInteraction(args) {
403
404
  const {
404
- role,
405
- type,
406
- items
407
- } = args;
405
+ role,
406
+ type,
407
+ items
408
+ } = args,
409
+ rest = _objectWithoutPropertiesLoose(args, _excluded2);
408
410
  const payload = {
409
411
  type: type === 'viewable' ? 'viewable_impression' : type,
410
412
  context: {
@@ -433,6 +435,11 @@ function buildBaseInteraction(args) {
433
435
  payload.type = 'custom';
434
436
  payload.custom_action_name = 'heartbeat';
435
437
  break;
438
+ case _constants.EVENT_TYPE.GENERIC_CLICK:
439
+ payload.type = 'custom';
440
+ payload.custom_action_name = 'generic_click';
441
+ payload.context.custom_context.href = args.href;
442
+ break;
436
443
  }
437
444
  return (0, _commons.trimObj)(payload);
438
445
  }
@@ -22,6 +22,19 @@ const DEFAULT_API_OPTIONS = Object.freeze(Object.assign({}, _base.default.DEFAUL
22
22
  rows: DEFAULT_ROWS
23
23
  })
24
24
  }));
25
+ function totalContent(layout, {
26
+ value
27
+ }) {
28
+ if (value === undefined) {
29
+ return '';
30
+ }
31
+ const {
32
+ formatNumber
33
+ } = layout.templates.helpers;
34
+ const formatted = formatNumber(value);
35
+ const label = value === 1 ? 'result' : 'results';
36
+ return `${formatted} ${label}`;
37
+ }
25
38
  const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LAYOUTS, {
26
39
  [_constants.ROLE.QUERY]: [_index2.SearchBoxLayout.type],
27
40
  [_constants.ROLE.PRODUCTS]: [_index2.ListLayout.type, {
@@ -33,7 +46,9 @@ const DEFAULT_LAYOUTS = Object.freeze(Object.assign({}, _base.default.DEFAULT_LA
33
46
  }],
34
47
  [_constants.ROLE.TOTAL]: [_index2.TextLayout.type, {
35
48
  raw: true,
36
- format: 'number'
49
+ templates: {
50
+ content: totalContent
51
+ }
37
52
  }],
38
53
  [_constants.ROLE.FACETS]: [_index2.FacetsLayout.type],
39
54
  [_constants.ROLE.SORT]: [_index2.SelectLayout.type],
package/package.json CHANGED
@@ -16,7 +16,11 @@
16
16
  "build:cjs": "BABEL_ENV=cjs npx babel src --root-mode upward --out-dir dist/cjs",
17
17
  "build": "npm run build:clean && npm run build:cjs"
18
18
  },
19
- "repository": "MisoAI/miso-client-js-sdk",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/MisoAI/miso-client-js-sdk.git",
22
+ "directory": "packages/client-sdk-ui"
23
+ },
20
24
  "homepage": "https://misoai.github.io/miso-client-js-sdk/sdk",
21
25
  "license": "MIT",
22
26
  "contributors": [
@@ -26,7 +30,7 @@
26
30
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
27
31
  },
28
32
  "dependencies": {
29
- "@miso.ai/commons": "1.13.0-beta.4"
33
+ "@miso.ai/commons": "1.13.0-beta.6"
30
34
  },
31
- "version": "1.13.0-beta.4"
35
+ "version": "1.13.0-beta.6"
32
36
  }
@@ -9,7 +9,7 @@ export default class FeedbackActor {
9
9
  hub.on(fields.feedback(), state => this._trigger(state)),
10
10
  ];
11
11
  }
12
-
12
+
13
13
  _trigger(state) {
14
14
  this._hub.trigger(fields.tracker(), {
15
15
  type: EVENT_TYPE.FEEDBACK,
@@ -1,5 +1,5 @@
1
- import { asArray, trimObj } from '@miso.ai/commons';
2
- import { PERFORMANCE_EVENT_TYPES, TRACKING_STATUS, EVENT_TYPE, validateEventType } from '../constants.js';
1
+ import { asArray, trimObj, snakeToLowerCamel } from '@miso.ai/commons';
2
+ import { PERFORMANCE_EVENT_TYPES, DIRECT_TRACKING_EVENT_TYPES, TRACKING_STATUS, EVENT_TYPE, validateEventType } from '../constants.js';
3
3
  import * as fields from './fields.js';
4
4
  import States from '../util/states.js';
5
5
 
@@ -55,21 +55,6 @@ export default class Tracker {
55
55
  });
56
56
  }
57
57
 
58
- submit({ value }) {
59
- this._syncSession();
60
- this._sendToHub({
61
- type: EVENT_TYPE.SUBMIT,
62
- value,
63
- });
64
- }
65
-
66
- heartbeat() {
67
- this._syncSession();
68
- this._sendToHub({
69
- type: EVENT_TYPE.HEARTBEAT,
70
- });
71
- }
72
-
73
58
  _sendToHub(args) {
74
59
  this._hub.trigger(fields.tracker(), Object.freeze(trimObj({ role: this._role, ...args })));
75
60
  }
@@ -106,7 +91,14 @@ export default class Tracker {
106
91
  }
107
92
 
108
93
  for (const type of PERFORMANCE_EVENT_TYPES) {
109
- Tracker.prototype[type] = function(items, meta) {
94
+ Tracker.prototype[snakeToLowerCamel(type)] = function(items, meta) {
110
95
  this._trigger(type, items, meta);
111
96
  };
112
97
  }
98
+
99
+ for (const type of DIRECT_TRACKING_EVENT_TYPES) {
100
+ Tracker.prototype[snakeToLowerCamel(type)] = function(args) {
101
+ this._syncSession();
102
+ this._sendToHub({ ...args, type });
103
+ };
104
+ }
package/src/constants.js CHANGED
@@ -72,6 +72,7 @@ export const EVENT_TYPE = Object.freeze({
72
72
  SUBMIT: 'submit',
73
73
  FEEDBACK: 'feedback',
74
74
  HEARTBEAT: 'heartbeat',
75
+ GENERIC_CLICK: 'generic_click',
75
76
  });
76
77
 
77
78
  export const TRACKING_EVENT_TYPES = [
@@ -89,6 +90,12 @@ export const PERFORMANCE_EVENT_TYPES = [
89
90
  EVENT_TYPE.CLICK,
90
91
  ];
91
92
 
93
+ export const DIRECT_TRACKING_EVENT_TYPES = [
94
+ EVENT_TYPE.SUBMIT,
95
+ EVENT_TYPE.HEARTBEAT,
96
+ EVENT_TYPE.GENERIC_CLICK,
97
+ ];
98
+
92
99
  const PERFORMANCE_EVENT_TYPE_SET = new Set(PERFORMANCE_EVENT_TYPES);
93
100
 
94
101
  export function isPerformanceEventType(type) {
@@ -16,7 +16,7 @@ export const keywords = 'You searched for “${value}”';
16
16
  /**
17
17
  * The phrase to display <miso-total>
18
18
  */
19
- export const total = '${value} Results';
19
+ export const total = '${value}';
20
20
 
21
21
  export const showMore = 'Show more';
22
22
  export const showLess = 'Show less';
@@ -4,11 +4,15 @@ import TemplateBasedLayout from '../template.js';
4
4
  const TYPE = 'text';
5
5
  const DEFAULT_CLASSNAME = 'miso-text';
6
6
 
7
- function root(layout, { value }) {
7
+ function root(layout, state) {
8
8
  const { className, role, options: { raw = false, tag } } = layout;
9
9
  const roleAttr = role ? `data-role="${role}"` : '';
10
- const content = value !== undefined ? escapeHtml(getFormatFunction(layout)(value)) : '';
11
- return raw ? content : `<${tag} class="${className}" ${roleAttr}>${content}</${tag}>`;
10
+ const text = layout.templates.content(layout, state);
11
+ return raw ? text : `<${tag} class="${className}" ${roleAttr}>${text}</${tag}>`;
12
+ }
13
+
14
+ function content(layout, { value }) {
15
+ return value !== undefined ? escapeHtml(getFormatFunction(layout)(value)) : '';
12
16
  }
13
17
 
14
18
  function getFormatFunction(layout) {
@@ -37,6 +41,7 @@ function getFormatFunction(layout) {
37
41
 
38
42
  const DEFAULT_TEMPLATES = Object.freeze({
39
43
  root,
44
+ content,
40
45
  });
41
46
 
42
47
  export default class TextLayout extends TemplateBasedLayout {
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.13.0-beta.4';
1
+ export default '1.13.0-beta.6';
@@ -170,6 +170,7 @@ export default class Explore extends UnitWorkflow {
170
170
  }
171
171
 
172
172
  _getSubmitUrl(args) {
173
+ // TODO: if trending_questions -> qs = '_trending'
173
174
  let url = UseLinkMixin.prototype._getSubmitUrl.call(this, args);
174
175
  if (!args.generated || !this._productId) {
175
176
  return url;
@@ -302,7 +302,7 @@ export function carryOverQuestionIdToData(data, oldData) {
302
302
 
303
303
  // interactions //
304
304
  export function buildBaseInteraction(args) {
305
- const { role, type, items } = args;
305
+ const { role, type, items, ...rest } = args;
306
306
  const payload = {
307
307
  type: type === 'viewable' ? 'viewable_impression' : type,
308
308
  context: {
@@ -333,6 +333,11 @@ export function buildBaseInteraction(args) {
333
333
  payload.type = 'custom';
334
334
  payload.custom_action_name = 'heartbeat';
335
335
  break;
336
+ case EVENT_TYPE.GENERIC_CLICK:
337
+ payload.type = 'custom';
338
+ payload.custom_action_name = 'generic_click';
339
+ payload.context.custom_context.href = args.href;
340
+ break;
336
341
  }
337
342
 
338
343
  return trimObj(payload);
@@ -20,12 +20,22 @@ const DEFAULT_API_OPTIONS = Object.freeze({
20
20
  },
21
21
  });
22
22
 
23
+ function totalContent(layout, { value }) {
24
+ if (value === undefined) {
25
+ return '';
26
+ }
27
+ const { formatNumber } = layout.templates.helpers;
28
+ const formatted = formatNumber(value);
29
+ const label = value === 1 ? 'result' : 'results';
30
+ return `${formatted} ${label}`;
31
+ }
32
+
23
33
  const DEFAULT_LAYOUTS = Object.freeze({
24
34
  ...Workflow.DEFAULT_LAYOUTS,
25
35
  [ROLE.QUERY]: [SearchBoxLayout.type],
26
36
  [ROLE.PRODUCTS]: [ListLayout.type, { incremental: true, infiniteScroll: true }],
27
37
  [ROLE.KEYWORDS]: [TextLayout.type, { raw: true }],
28
- [ROLE.TOTAL]: [TextLayout.type, { raw: true, format: 'number' }],
38
+ [ROLE.TOTAL]: [TextLayout.type, { raw: true, templates: { content: totalContent } }],
29
39
  [ROLE.FACETS]: [FacetsLayout.type],
30
40
  [ROLE.SORT]: [SelectLayout.type],
31
41
  [ROLE.MORE]: [MoreButtonLayout.type],