@miso.ai/client-sdk-ui 1.13.0-beta.5 → 1.13.0-beta.7

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);
@@ -166,7 +166,11 @@ class Ui {
166
166
  return this.recommendations.get(); // get default recommendation unit
167
167
  }
168
168
  get search() {
169
- return this._search || (this._search = new _index.Search(this._plugin, this._client));
169
+ if (!this._search) {
170
+ this._search = new _index.Search(this._plugin, this._client);
171
+ this._client._events.emit('postworkflow', this._search);
172
+ }
173
+ return this._search;
170
174
  }
171
175
  get asks() {
172
176
  return this._asks || (this._asks = this._plugin._getAsks(this._client));
@@ -175,7 +179,11 @@ class Ui {
175
179
  return this.asks.root;
176
180
  }
177
181
  get hybridSearch() {
178
- return this._hybridSearch || (this._hybridSearch = new _index.HybridSearch(this._plugin, this._client));
182
+ if (!this._hybridSearch) {
183
+ this._hybridSearch = new _index.HybridSearch(this._plugin, this._client);
184
+ this._client._events.emit('postworkflow', this._hybridSearch);
185
+ }
186
+ return this._hybridSearch;
179
187
  }
180
188
  get explores() {
181
189
  return this._explores || (this._explores = this._plugin._getExplores(this._client));
@@ -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.5';
7
+ var _default = exports.default = '1.13.0-beta.7';
@@ -39,6 +39,7 @@ class Asks extends _context.default {
39
39
  this._byQid = new Map();
40
40
  this._byPqid = new Map();
41
41
  this._root = new _ask.default(this); // initialize with default workflow
42
+ client._events.emit('postworkflow', this._root);
42
43
  this._events.on('*', event => this._createNextIfNecessary(event));
43
44
  this._events.on('loading', event => this._setActive(event.workflow));
44
45
  this._events.on('destroy', () => this._requestEmitAfterDestroy());
@@ -73,6 +74,7 @@ class Asks extends _context.default {
73
74
  let workflow = this._byPqid.get(parentQuestionId);
74
75
  if (!workflow && autoCreate) {
75
76
  workflow = new _ask.default(this, parentQuestionId);
77
+ this._client._events.emit('postworkflow', workflow);
76
78
  }
77
79
  return workflow;
78
80
  }
@@ -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
  }
@@ -19,7 +19,7 @@ class UnitWorkflowContext extends _context.default {
19
19
  if (this._members.has(unitId)) {
20
20
  throw new Error(`Unit already exists: ${unitId}`);
21
21
  }
22
- return this._create(unitId);
22
+ return this._createAndEmit(unitId);
23
23
  }
24
24
  has(unitId = _constants.DEFAULT_UNIT_ID) {
25
25
  return this._members.has(unitId);
@@ -28,7 +28,12 @@ class UnitWorkflowContext extends _context.default {
28
28
  if (typeof unitId !== 'string') {
29
29
  throw new Error(`Required unit ID to be a string: ${unitId}`);
30
30
  }
31
- return this._members.get(unitId) || this._create(unitId);
31
+ return this._members.get(unitId) || this._createAndEmit(unitId);
32
+ }
33
+ _createAndEmit(unitId) {
34
+ const workflow = this._create(unitId);
35
+ this._client._events.emit('postworkflow', workflow);
36
+ return workflow;
32
37
  }
33
38
  _create(unitId) {
34
39
  throw new Error('Not implemented');
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
31
31
  },
32
32
  "dependencies": {
33
- "@miso.ai/commons": "1.13.0-beta.5"
33
+ "@miso.ai/commons": "1.13.0-beta.7"
34
34
  },
35
- "version": "1.13.0-beta.5"
35
+ "version": "1.13.0-beta.7"
36
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) {
package/src/plugin.js CHANGED
@@ -176,7 +176,11 @@ class Ui {
176
176
  }
177
177
 
178
178
  get search() {
179
- return this._search || (this._search = new Search(this._plugin, this._client));
179
+ if (!this._search) {
180
+ this._search = new Search(this._plugin, this._client);
181
+ this._client._events.emit('postworkflow', this._search);
182
+ }
183
+ return this._search;
180
184
  }
181
185
 
182
186
  get asks() {
@@ -188,7 +192,11 @@ class Ui {
188
192
  }
189
193
 
190
194
  get hybridSearch() {
191
- return this._hybridSearch || (this._hybridSearch = new HybridSearch(this._plugin, this._client));
195
+ if (!this._hybridSearch) {
196
+ this._hybridSearch = new HybridSearch(this._plugin, this._client);
197
+ this._client._events.emit('postworkflow', this._hybridSearch);
198
+ }
199
+ return this._hybridSearch;
192
200
  }
193
201
 
194
202
  get explores() {
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.13.0-beta.5';
1
+ export default '1.13.0-beta.7';
@@ -30,6 +30,8 @@ export default class Asks extends WorkflowContext {
30
30
  this._byQid = new Map();
31
31
  this._byPqid = new Map();
32
32
  this._root = new Ask(this); // initialize with default workflow
33
+ client._events.emit('postworkflow', this._root);
34
+
33
35
  this._events.on('*', event => this._createNextIfNecessary(event));
34
36
  this._events.on('loading', event => this._setActive(event.workflow));
35
37
  this._events.on('destroy', () => this._requestEmitAfterDestroy());
@@ -67,6 +69,7 @@ export default class Asks extends WorkflowContext {
67
69
  let workflow = this._byPqid.get(parentQuestionId);
68
70
  if (!workflow && autoCreate) {
69
71
  workflow = new Ask(this, parentQuestionId);
72
+ this._client._events.emit('postworkflow', workflow);
70
73
  }
71
74
  return workflow;
72
75
  }
@@ -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);
@@ -16,7 +16,7 @@ export default class UnitWorkflowContext extends WorkflowContext {
16
16
  if (this._members.has(unitId)) {
17
17
  throw new Error(`Unit already exists: ${unitId}`);
18
18
  }
19
- return this._create(unitId);
19
+ return this._createAndEmit(unitId);
20
20
  }
21
21
 
22
22
  has(unitId = DEFAULT_UNIT_ID) {
@@ -27,7 +27,13 @@ export default class UnitWorkflowContext extends WorkflowContext {
27
27
  if (typeof unitId !== 'string') {
28
28
  throw new Error(`Required unit ID to be a string: ${unitId}`);
29
29
  }
30
- return this._members.get(unitId) || this._create(unitId);
30
+ return this._members.get(unitId) || this._createAndEmit(unitId);
31
+ }
32
+
33
+ _createAndEmit(unitId) {
34
+ const workflow = this._create(unitId);
35
+ this._client._events.emit('postworkflow', workflow);
36
+ return workflow;
31
37
  }
32
38
 
33
39
  _create(unitId) {