@miso.ai/client-sdk-core 1.11.6-beta.0 → 1.11.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.
@@ -16,8 +16,7 @@ class Ask extends _base.default {
16
16
  constructor(api) {
17
17
  super(api, GROUP.ASK);
18
18
  }
19
- async questions(payload) {
20
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
19
+ async questions(payload, options = {}) {
21
20
  if (isId(payload)) {
22
21
  return new Answer(this, payload, options);
23
22
  }
@@ -32,12 +31,13 @@ class Ask extends _base.default {
32
31
  method: 'GET'
33
32
  }));
34
33
  }
35
- async relatedQuestions(payload) {
36
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
34
+ async relatedQuestions(payload, options = {}) {
37
35
  return this._run(NAME.RELATED_QUESTIONS, payload, options);
38
36
  }
39
- async search(payload) {
40
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
37
+ async trendingQuestions(payload, options = {}) {
38
+ return this._run(NAME.TRENDING_QUESTIONS, payload, options);
39
+ }
40
+ async search(payload, options = {}) {
41
41
  const response = await this._run(NAME.SEARCH, payload, options);
42
42
  return response.question_id ? new SearchResult(this, response, options) : response;
43
43
  }
@@ -55,8 +55,7 @@ class Ask extends _base.default {
55
55
  }
56
56
  exports.default = Ask;
57
57
  class Answer extends _iterable.IdBasedIterableApiStub {
58
- constructor(api, response) {
59
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
58
+ constructor(api, response, options = {}) {
60
59
  super(api, '_questionGet', response.question_id, options);
61
60
  this._response = response;
62
61
  }
@@ -65,8 +64,7 @@ class Answer extends _iterable.IdBasedIterableApiStub {
65
64
  }
66
65
  }
67
66
  class SearchResult extends _iterable.IdBasedIterableApiStub {
68
- constructor(api, response) {
69
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
67
+ constructor(api, response, options = {}) {
70
68
  super(api, '_searchGet', response.question_id, options);
71
69
  (0, _commons.defineValues)(this, response);
72
70
  this._response = response;
@@ -17,8 +17,7 @@ class ApiBase extends _commons.Component {
17
17
  this.clientOptions = api._client.options;
18
18
  this.context = api._client.context;
19
19
  }
20
- async _run(apiName, payload) {
21
- let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
20
+ async _run(apiName, payload, options = {}) {
22
21
  const {
23
22
  bulk
24
23
  } = options;
@@ -53,24 +52,22 @@ class ApiBase extends _commons.Component {
53
52
  this._events.emit('response', Object.assign({}, responseData, bulkInfo));
54
53
  return this._postprocess(responseData);
55
54
  }
56
- _preprocess(_ref) {
57
- let {
58
- apiGroup,
59
- apiName,
60
- payload
61
- } = _ref;
55
+ _preprocess({
56
+ apiGroup,
57
+ apiName,
58
+ payload
59
+ }) {
62
60
  return this.helpers.applyPayloadPasses(this, {
63
61
  apiGroup,
64
62
  apiName,
65
63
  payload
66
64
  });
67
65
  }
68
- _url(_ref2) {
69
- let {
70
- apiGroup,
71
- apiName,
72
- options
73
- } = _ref2;
66
+ _url({
67
+ apiGroup,
68
+ apiName,
69
+ options
70
+ }) {
74
71
  const url = this.helpers.url([apiGroup, apiName], options);
75
72
  return this.helpers.applyUrlPasses(this, {
76
73
  apiGroup,
@@ -79,7 +76,7 @@ class ApiBase extends _commons.Component {
79
76
  options
80
77
  });
81
78
  }
82
- async _send(_ref3) {
79
+ async _send(_ref) {
83
80
  let {
84
81
  apiGroup,
85
82
  apiName,
@@ -88,14 +85,13 @@ class ApiBase extends _commons.Component {
88
85
  options: {
89
86
  bulk
90
87
  } = {}
91
- } = _ref3,
92
- options = _objectWithoutPropertiesLoose(_ref3.options, _excluded);
88
+ } = _ref,
89
+ options = _objectWithoutPropertiesLoose(_ref.options, _excluded);
93
90
  return bulk ? this.helpers.fetchForBulk(apiGroup, apiName, payload) : this.helpers.fetch(url, payload, options);
94
91
  }
95
- _postprocess(_ref4) {
96
- let {
97
- response
98
- } = _ref4;
92
+ _postprocess({
93
+ response
94
+ }) {
99
95
  // TODO: we can introduce response passes
100
96
  return response.data;
101
97
  }
@@ -12,13 +12,12 @@ class ApiHelpers {
12
12
  this._root = root;
13
13
  this._bulk = new _commons.Bulk(this._runBulkFetch.bind(this), client._error.bind(client));
14
14
  }
15
- async fetch(url, payload) {
16
- let {
17
- method = 'POST',
18
- headers,
19
- timeout,
20
- sendApiKeyByHeader
21
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
15
+ async fetch(url, payload, {
16
+ method = 'POST',
17
+ headers,
18
+ timeout,
19
+ sendApiKeyByHeader
20
+ } = {}) {
22
21
  const {
23
22
  apiKey,
24
23
  request = {}
@@ -54,10 +53,9 @@ class ApiHelpers {
54
53
  get bulkInfo() {
55
54
  return this._bulk.info;
56
55
  }
57
- async fetchForBulk(apiGroup, apiName, payload) {
58
- let {
59
- method
60
- } = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
56
+ async fetchForBulk(apiGroup, apiName, payload, {
57
+ method
58
+ } = {}) {
61
59
  if (method && method !== 'POST') {
62
60
  throw new Error(`Non-POST API is not supported in bulk mode: ${url}`);
63
61
  }
@@ -71,19 +69,16 @@ class ApiHelpers {
71
69
  // TODO: request options?
72
70
  const url = this.url(['bulk']);
73
71
  const payload = {
74
- requests: requests.map(_ref => {
75
- let {
76
- action: {
77
- apiGroup,
78
- apiName,
79
- payload
80
- }
81
- } = _ref;
82
- return {
83
- api_name: `${apiGroup}/${apiName}`,
84
- body: payload
85
- };
86
- })
72
+ requests: requests.map(({
73
+ action: {
74
+ apiGroup,
75
+ apiName,
76
+ payload
77
+ }
78
+ }) => ({
79
+ api_name: `${apiGroup}/${apiName}`,
80
+ body: payload
81
+ }))
87
82
  };
88
83
  const {
89
84
  data: responses
@@ -107,10 +102,9 @@ class ApiHelpers {
107
102
  }
108
103
  }
109
104
  }
110
- sendBeacon(url, payload) {
111
- let {
112
- method
113
- } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
105
+ sendBeacon(url, payload, {
106
+ method
107
+ } = {}) {
114
108
  if (method && method !== 'POST') {
115
109
  throw new Error(`Non-POST API is not supported in useBeacon mode: ${url}`);
116
110
  }
@@ -119,8 +113,7 @@ class ApiHelpers {
119
113
  throw new Error(`Send beacon unsuccessful: ${url}`);
120
114
  }
121
115
  }
122
- url(paths) {
123
- let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
116
+ url(paths, options = {}) {
124
117
  const {
125
118
  apiKey,
126
119
  request = {}
@@ -137,12 +130,11 @@ class ApiHelpers {
137
130
  } = this._client.options;
138
131
  return apiName === 'interactions' ? eventEndpoint : dataEndpoint;
139
132
  }
140
- applyUrlPasses(component, _ref2) {
141
- let {
142
- apiGroup,
143
- apiName,
144
- url
145
- } = _ref2;
133
+ applyUrlPasses(component, {
134
+ apiGroup,
135
+ apiName,
136
+ url
137
+ }) {
146
138
  const client = this._client;
147
139
  for (const pass of this._root._urlPasses) {
148
140
  try {
@@ -158,12 +150,11 @@ class ApiHelpers {
158
150
  }
159
151
  return url;
160
152
  }
161
- applyPayloadPasses(component, _ref3) {
162
- let {
163
- apiGroup,
164
- apiName,
165
- payload
166
- } = _ref3;
153
+ applyPayloadPasses(component, {
154
+ apiGroup,
155
+ apiName,
156
+ payload
157
+ }) {
167
158
  const client = this._client;
168
159
  for (const pass of this._root._payloadPasses) {
169
160
  try {
@@ -29,12 +29,11 @@ class Interactions extends _base.default {
29
29
  }
30
30
  }
31
31
  }
32
- _url(_ref) {
33
- let {
34
- apiGroup,
35
- apiName,
36
- options
37
- } = _ref;
32
+ _url({
33
+ apiGroup,
34
+ apiName,
35
+ options
36
+ }) {
38
37
  const url = this.helpers.url([this._apiPath], options);
39
38
  return this.helpers.applyUrlPasses(this, {
40
39
  apiGroup,
@@ -43,12 +42,11 @@ class Interactions extends _base.default {
43
42
  options
44
43
  });
45
44
  }
46
- _preprocess(_ref2) {
47
- let {
48
- apiGroup,
49
- apiName,
50
- payload
51
- } = _ref2;
45
+ _preprocess({
46
+ apiGroup,
47
+ apiName,
48
+ payload
49
+ }) {
52
50
  if (apiName === NAME.UPLOAD) {
53
51
  payload = this._normalizeUploadPayload(payload);
54
52
  }
@@ -70,14 +68,14 @@ class Interactions extends _base.default {
70
68
  data: payload
71
69
  };
72
70
  }
73
- async _send(_ref3) {
71
+ async _send(_ref) {
74
72
  let {
75
73
  options: {
76
74
  useBeacon = true
77
75
  } = {}
78
- } = _ref3,
79
- options = _objectWithoutPropertiesLoose(_ref3.options, _excluded),
80
- args = _objectWithoutPropertiesLoose(_ref3, _excluded2);
76
+ } = _ref,
77
+ options = _objectWithoutPropertiesLoose(_ref.options, _excluded),
78
+ args = _objectWithoutPropertiesLoose(_ref, _excluded2);
81
79
  if (useBeacon) {
82
80
  const {
83
81
  url,
@@ -8,8 +8,7 @@ var _commons = require("@miso.ai/commons");
8
8
  const _excluded = ["pollingInterval", "signal", "stallTimeout"];
9
9
  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; }
10
10
  class IterableApiStub {
11
- constructor() {
12
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
11
+ constructor(options = {}) {
13
12
  this._ac = new AbortController();
14
13
  this._options = options;
15
14
  }
@@ -23,14 +22,12 @@ class IterableApiStub {
23
22
  this._ac.abort(reason);
24
23
  }
25
24
  [Symbol.asyncIterator]() {
26
- var _this = this;
27
- const fetch = async function () {
28
- let {
29
- signal
30
- } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25
+ const fetch = async ({
26
+ signal
27
+ } = {}) => {
31
28
  // TODO: pass signal
32
- const response = await _this.get();
33
- return [response, _this._isFinished(response), _this._revisionOf(response)];
29
+ const response = await this.get();
30
+ return [response, this._isFinished(response), this._revisionOf(response)];
34
31
  };
35
32
  let _this$_options = this._options,
36
33
  {
@@ -7,8 +7,7 @@ exports.default = void 0;
7
7
  var api = _interopRequireWildcard(require("./api/index.js"));
8
8
  var _context = _interopRequireDefault(require("./context.js"));
9
9
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
- 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; }
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
11
  var _default = exports.default = {
13
12
  api,
14
13
  context: {
@@ -9,8 +9,7 @@ var _root = require("./root.js");
9
9
  var _index = require("./api/index.js");
10
10
  var _context = _interopRequireDefault(require("./context.js"));
11
11
  var helpers = _interopRequireWildcard(require("./utils.js"));
12
- 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
- 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 _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
14
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
14
  const {
16
15
  currentScript
@@ -43,8 +42,7 @@ class MisoClient extends _commons.Component {
43
42
  _config(options) {
44
43
  this.options = Object.freeze(this._normalizeOptions(options));
45
44
  }
46
- _normalizeOptions() {
47
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
45
+ _normalizeOptions(options = {}) {
48
46
  if (typeof options === 'string') {
49
47
  options = {
50
48
  apiKey: options
@@ -27,11 +27,10 @@ class ApiPlugin extends _commons.Component {
27
27
  payload = _objectWithoutPropertiesLoose(args.payload, _excluded);
28
28
  return payload;
29
29
  }
30
- _shallSuppressMetaObject(_ref) {
31
- let {
32
- apiGroup,
33
- apiName
34
- } = _ref;
30
+ _shallSuppressMetaObject({
31
+ apiGroup,
32
+ apiName
33
+ }) {
35
34
  switch (apiGroup) {
36
35
  case _commons.API.GROUP.SEARCH:
37
36
  case _commons.API.GROUP.RECOMMENDATION:
@@ -24,13 +24,12 @@ class AutoEventsPlugin extends _commons.Component {
24
24
  this._contexts.set(client, context);
25
25
  client.autoEvents = context.interface;
26
26
  }
27
- _captureApiRequest(_ref) {
28
- let {
29
- client,
30
- apiGroup,
31
- apiName,
32
- payload
33
- } = _ref;
27
+ _captureApiRequest({
28
+ client,
29
+ apiGroup,
30
+ apiName,
31
+ payload
32
+ }) {
34
33
  switch (apiGroup) {
35
34
  case _commons.API.GROUP.SEARCH:
36
35
  switch (apiName) {
@@ -41,10 +40,9 @@ class AutoEventsPlugin extends _commons.Component {
41
40
  break;
42
41
  }
43
42
  }
44
- _captureSearchApiRequest(client, _ref2) {
45
- let {
46
- q: keywords
47
- } = _ref2;
43
+ _captureSearchApiRequest(client, {
44
+ q: keywords
45
+ }) {
48
46
  if (!keywords || keywords === '*') {
49
47
  // might be a facet search without real keywords
50
48
  return;
@@ -77,8 +75,7 @@ class AutoEventsContext {
77
75
  config: this.config.bind(this)
78
76
  });
79
77
  }
80
- config() {
81
- let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
78
+ config(options = {}) {
82
79
  if (typeof options !== 'object') {
83
80
  throw new Error(`Config options must be an object or undefined: ${options}`);
84
81
  }
@@ -13,24 +13,21 @@ class InteractionsPlugin {
13
13
  return ID;
14
14
  }
15
15
  constructor() {}
16
- install(_, _ref) {
17
- let {
18
- addPayloadPass
19
- } = _ref;
16
+ install(_, {
17
+ addPayloadPass
18
+ }) {
20
19
  addPayloadPass(this._modifyPayload.bind(this));
21
20
  }
22
- _modifyPayload(_ref2) {
23
- let {
24
- apiGroup,
25
- apiName,
26
- payload
27
- } = _ref2;
21
+ _modifyPayload({
22
+ apiGroup,
23
+ apiName,
24
+ payload
25
+ }) {
28
26
  return apiGroup === 'interactions' && apiName === 'upload' ? this._modifyPayloadForInteractions(payload) : payload;
29
27
  }
30
- _modifyPayloadForInteractions(_ref3) {
31
- let {
32
- data
33
- } = _ref3;
28
+ _modifyPayloadForInteractions({
29
+ data
30
+ }) {
34
31
  return {
35
32
  data: data.map(modifyInteractionRecord)
36
33
  };
@@ -11,24 +11,21 @@ class PageInfoPlugin {
11
11
  return ID;
12
12
  }
13
13
  constructor() {}
14
- install(_, _ref) {
15
- let {
16
- addPayloadPass
17
- } = _ref;
14
+ install(_, {
15
+ addPayloadPass
16
+ }) {
18
17
  addPayloadPass(this._modifyPayload.bind(this));
19
18
  }
20
- _modifyPayload(_ref2) {
21
- let {
22
- apiGroup,
23
- apiName,
24
- payload
25
- } = _ref2;
19
+ _modifyPayload({
20
+ apiGroup,
21
+ apiName,
22
+ payload
23
+ }) {
26
24
  return apiGroup === 'interactions' && apiName === 'upload' ? this._modifyPayloadForInteractions(payload) : payload;
27
25
  }
28
- _modifyPayloadForInteractions(_ref3) {
29
- let {
30
- data
31
- } = _ref3;
26
+ _modifyPayloadForInteractions({
27
+ data
28
+ }) {
32
29
  data = data.map(obj => Object.assign({}, obj, {
33
30
  context: Object.assign({}, getPayloadContext(), obj.context)
34
31
  }));
@@ -110,6 +110,18 @@ class PluginRoot extends _commons.Registry {
110
110
  }
111
111
  this._root._customSendBeacon = sendBeacon;
112
112
  }
113
+ onHubUpdate(callback) {
114
+ if (typeof callback !== 'function') {
115
+ throw new Error(`Expect parameter to be a function: ${callback}`);
116
+ }
117
+ this._root._hubUpdateCallbacks.push(callback);
118
+ }
119
+ onHubEmit(callback) {
120
+ if (typeof callback !== 'function') {
121
+ throw new Error(`Expect parameter to be a function: ${callback}`);
122
+ }
123
+ this._root._hubEmitCallbacks.push(callback);
124
+ }
113
125
  _tryConfig(instance, options) {
114
126
  if (options === undefined) {
115
127
  return;
@@ -221,7 +233,7 @@ class PluginRoot extends _commons.Registry {
221
233
  exports.default = PluginRoot;
222
234
  class PluginContext {
223
235
  constructor(root, classes) {
224
- (0, _commons.delegateGetters)(this, root, ['getPluginClass', 'addSubtree', 'addPayloadPass', 'addUrlPass', 'setCustomFetch', 'setCustomSendBeacon', 'whenInstalled', 'whenRegistered']);
236
+ (0, _commons.delegateGetters)(this, root, ['getPluginClass', 'addSubtree', 'addPayloadPass', 'addUrlPass', 'setCustomFetch', 'setCustomSendBeacon', 'onHubUpdate', 'onHubEmit', 'whenInstalled', 'whenRegistered']);
225
237
  (0, _commons.defineValues)(this, {
226
238
  classes
227
239
  });
@@ -28,13 +28,12 @@ class UserPlugin extends _commons.Component {
28
28
  this._contexts.set(client, context);
29
29
  (0, _commons.delegateProperties)(client.context, context, ['anonymous_id', 'user_id', 'user_hash', 'user_type']);
30
30
  }
31
- _modifyPayload(_ref) {
32
- let {
33
- client,
34
- apiGroup,
35
- apiName,
36
- payload
37
- } = _ref;
31
+ _modifyPayload({
32
+ client,
33
+ apiGroup,
34
+ apiName,
35
+ payload
36
+ }) {
38
37
  if (apiGroup === GROUP.INTERACTIONS && apiName === NAME.UPLOAD) {
39
38
  return this._modifyPayloadForInteractions(client, payload);
40
39
  }
@@ -75,10 +74,9 @@ class UserPlugin extends _commons.Component {
75
74
  }
76
75
  return Object.assign({}, userInfo, payload);
77
76
  }
78
- _modifyPayloadForInteractions(client, _ref2) {
79
- let {
80
- data
81
- } = _ref2;
77
+ _modifyPayloadForInteractions(client, {
78
+ data
79
+ }) {
82
80
  const {
83
81
  anonymous_id,
84
82
  user_id
package/dist/cjs/root.js CHANGED
@@ -24,6 +24,8 @@ class Root extends _commons.Component {
24
24
  this._urlPasses = [];
25
25
  this._customFetch = undefined;
26
26
  this._customSendBeacon = undefined;
27
+ this._hubUpdateCallbacks = [];
28
+ this._hubEmitCallbacks = [];
27
29
  this.version = _version.default || 'dev';
28
30
  this._cmdRes = new _commons.Resolution();
29
31
  }
@@ -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.11.6-beta.0';
7
+ var _default = exports.default = '1.11.6';
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@miso.ai/commons": "1.11.6-beta.0"
32
+ "@miso.ai/commons": "1.11.6"
33
33
  },
34
- "version": "1.11.6-beta.0"
34
+ "version": "1.11.6"
35
35
  }
package/src/api/ask.js CHANGED
@@ -30,6 +30,10 @@ export default class Ask extends ApiBase {
30
30
  return this._run(NAME.RELATED_QUESTIONS, payload, options);
31
31
  }
32
32
 
33
+ async trendingQuestions(payload, options = {}) {
34
+ return this._run(NAME.TRENDING_QUESTIONS, payload, options);
35
+ }
36
+
33
37
  async search(payload, options = {}) {
34
38
  const response = await this._run(NAME.SEARCH, payload, options);
35
39
  return response.question_id ? new SearchResult(this, response, options) : response;
@@ -115,6 +115,20 @@ export default class PluginRoot extends Registry {
115
115
  this._root._customSendBeacon = sendBeacon;
116
116
  }
117
117
 
118
+ onHubUpdate(callback) {
119
+ if (typeof callback !== 'function') {
120
+ throw new Error(`Expect parameter to be a function: ${callback}`);
121
+ }
122
+ this._root._hubUpdateCallbacks.push(callback);
123
+ }
124
+
125
+ onHubEmit(callback) {
126
+ if (typeof callback !== 'function') {
127
+ throw new Error(`Expect parameter to be a function: ${callback}`);
128
+ }
129
+ this._root._hubEmitCallbacks.push(callback);
130
+ }
131
+
118
132
  _tryConfig(instance, options) {
119
133
  if (options === undefined) {
120
134
  return;
@@ -229,7 +243,7 @@ export default class PluginRoot extends Registry {
229
243
  class PluginContext {
230
244
 
231
245
  constructor(root, classes) {
232
- delegateGetters(this, root, ['getPluginClass', 'addSubtree', 'addPayloadPass', 'addUrlPass', 'setCustomFetch', 'setCustomSendBeacon', 'whenInstalled', 'whenRegistered']);
246
+ delegateGetters(this, root, ['getPluginClass', 'addSubtree', 'addPayloadPass', 'addUrlPass', 'setCustomFetch', 'setCustomSendBeacon', 'onHubUpdate', 'onHubEmit', 'whenInstalled', 'whenRegistered']);
233
247
  defineValues(this, { classes });
234
248
  }
235
249
 
package/src/root.js CHANGED
@@ -16,6 +16,8 @@ class Root extends Component {
16
16
  this._urlPasses = [];
17
17
  this._customFetch = undefined;
18
18
  this._customSendBeacon = undefined;
19
+ this._hubUpdateCallbacks = [];
20
+ this._hubEmitCallbacks = [];
19
21
  this.version = version || 'dev';
20
22
  this._cmdRes = new Resolution();
21
23
  }
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.11.6-beta.0';
1
+ export default '1.11.6';
package/dist/cjs/cmd.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = _default;
7
- function execute(onError, fn) {
8
- try {
9
- fn();
10
- } catch (e) {
11
- onError(e);
12
- }
13
- }
14
- function _default(key) {
15
- let onError = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : e => console.error(e);
16
- const cmds = window[key] || (window[key] = []);
17
- if (cmds._processed) {
18
- return;
19
- }
20
- cmds._processed = true;
21
- const exec = fn => execute(onError, fn);
22
-
23
- // overrides push function so future commands are executed immediately
24
- Object.defineProperty(cmds, 'push', {
25
- value: exec
26
- });
27
-
28
- // process existing miso commands
29
- for (const fn of cmds) {
30
- exec(fn);
31
- }
32
- }
package/src/cmd.js DELETED
@@ -1,25 +0,0 @@
1
- function execute(onError, fn) {
2
- try {
3
- fn();
4
- } catch (e) {
5
- onError(e);
6
- }
7
- }
8
-
9
- export default function(key, onError = e => console.error(e)) {
10
- const cmds = window[key] || (window[key] = []);
11
- if (cmds._processed) {
12
- return;
13
- }
14
- cmds._processed = true;
15
-
16
- const exec = fn => execute(onError, fn);
17
-
18
- // overrides push function so future commands are executed immediately
19
- Object.defineProperty(cmds, 'push', { value: exec });
20
-
21
- // process existing miso commands
22
- for (const fn of cmds) {
23
- exec(fn);
24
- }
25
- }