@miso.ai/client-sdk-core 1.8.0 → 1.8.1-beta.1

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.
@@ -32,6 +32,10 @@ class Ask extends _base.default {
32
32
  method: 'GET'
33
33
  }));
34
34
  }
35
+ async relatedQuestions(payload) {
36
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
37
+ return this._run(_constants.NAME.RELATED_QUESTIONS, payload, options);
38
+ }
35
39
  }
36
40
  exports.default = Ask;
37
41
  class Answer {
@@ -13,6 +13,7 @@ const GROUP = Object.freeze({
13
13
  exports.GROUP = GROUP;
14
14
  const NAME = Object.freeze({
15
15
  QUESTIONS: 'questions',
16
+ RELATED_QUESTIONS: 'related_questions',
16
17
  SEARCH: 'search',
17
18
  AUTOCOMPLETE: 'autocomplete',
18
19
  MGET: 'mget',
@@ -34,7 +34,7 @@ class ApiHelpers {
34
34
  // TODO: organize arguments
35
35
  const body = method !== 'GET' && payload != undefined ? JSON.stringify(payload) : undefined;
36
36
  const signal = timeout ? AbortSignal.timeout(timeout) : undefined;
37
- const res = await window.fetch(url, (0, _commons.trimObj)({
37
+ const res = await (this._root._customFetch || window.fetch)(url, (0, _commons.trimObj)({
38
38
  method,
39
39
  headers,
40
40
  body,
@@ -71,6 +71,9 @@ class PluginRoot extends _commons.Registry {
71
71
  return this.whenInstalled(plugin);
72
72
  }
73
73
  async whenInstalled(id) {
74
+ if (typeof id === 'function' && id.id && typeof id.id === 'string') {
75
+ id = id.id;
76
+ }
74
77
  if (this.isInstalled(id)) {
75
78
  return this.get(id);
76
79
  }
@@ -95,6 +98,12 @@ class PluginRoot extends _commons.Registry {
95
98
  }
96
99
  this._root._urlPasses.push(pass);
97
100
  }
101
+ setCustomFetch(fetch) {
102
+ if (typeof fetch !== 'function') {
103
+ throw new Error(`Expect parameter to be a function: ${fetch}`);
104
+ }
105
+ this._root._customFetch = fetch;
106
+ }
98
107
  _tryConfig(instance, options) {
99
108
  if (options === undefined) {
100
109
  return;
@@ -206,7 +215,7 @@ class PluginRoot extends _commons.Registry {
206
215
  exports.default = PluginRoot;
207
216
  class PluginContext {
208
217
  constructor(root, classes) {
209
- (0, _commons.delegateGetters)(this, root, ['getPluginClass', 'addSubtree', 'addPayloadPass', 'addUrlPass', 'whenInstalled', 'whenRegistered']);
218
+ (0, _commons.delegateGetters)(this, root, ['getPluginClass', 'addSubtree', 'addPayloadPass', 'addUrlPass', 'setCustomFetch', 'whenInstalled', 'whenRegistered']);
210
219
  (0, _commons.defineValues)(this, {
211
220
  classes
212
221
  });
package/dist/cjs/root.js CHANGED
@@ -21,6 +21,7 @@ class Root extends _commons.Component {
21
21
  this._clients = [];
22
22
  this._payloadPasses = [];
23
23
  this._urlPasses = [];
24
+ this._customFetch = undefined;
24
25
  this.version = _version.default || 'dev';
25
26
  }
26
27
  get instances() {
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '1.8.0';
7
+ var _default = '1.8.1-beta.1';
8
8
  exports.default = _default;
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.8.0"
32
+ "@miso.ai/commons": "1.8.1-beta.1"
33
33
  },
34
- "version": "1.8.0"
34
+ "version": "1.8.1-beta.1"
35
35
  }
package/src/api/ask.js CHANGED
@@ -24,6 +24,10 @@ export default class Ask extends ApiBase {
24
24
  return this._run(`${NAME.QUESTIONS}/${questionId}/answer`, undefined, { ...options, method: 'GET' });
25
25
  }
26
26
 
27
+ async relatedQuestions(payload, options = {}) {
28
+ return this._run(NAME.RELATED_QUESTIONS, payload, options);
29
+ }
30
+
27
31
  }
28
32
 
29
33
  class Answer {
@@ -7,6 +7,7 @@ export const GROUP = Object.freeze({
7
7
 
8
8
  export const NAME = Object.freeze({
9
9
  QUESTIONS: 'questions',
10
+ RELATED_QUESTIONS: 'related_questions',
10
11
  SEARCH: 'search',
11
12
  AUTOCOMPLETE: 'autocomplete',
12
13
  MGET: 'mget',
@@ -28,7 +28,7 @@ export default class ApiHelpers {
28
28
 
29
29
  const signal = timeout ? AbortSignal.timeout(timeout) : undefined;
30
30
 
31
- const res = await window.fetch(url, trimObj({
31
+ const res = await (this._root._customFetch || window.fetch)(url, trimObj({
32
32
  method,
33
33
  headers,
34
34
  body,
@@ -72,6 +72,9 @@ export default class PluginRoot extends Registry {
72
72
  }
73
73
 
74
74
  async whenInstalled(id) {
75
+ if (typeof id === 'function' && id.id && typeof id.id === 'string') {
76
+ id = id.id;
77
+ }
75
78
  if (this.isInstalled(id)) {
76
79
  return this.get(id);
77
80
  }
@@ -98,6 +101,13 @@ export default class PluginRoot extends Registry {
98
101
  this._root._urlPasses.push(pass);
99
102
  }
100
103
 
104
+ setCustomFetch(fetch) {
105
+ if (typeof fetch !== 'function') {
106
+ throw new Error(`Expect parameter to be a function: ${fetch}`);
107
+ }
108
+ this._root._customFetch = fetch;
109
+ }
110
+
101
111
  _tryConfig(instance, options) {
102
112
  if (options === undefined) {
103
113
  return;
@@ -212,7 +222,7 @@ export default class PluginRoot extends Registry {
212
222
  class PluginContext {
213
223
 
214
224
  constructor(root, classes) {
215
- delegateGetters(this, root, ['getPluginClass', 'addSubtree', 'addPayloadPass', 'addUrlPass', 'whenInstalled', 'whenRegistered']);
225
+ delegateGetters(this, root, ['getPluginClass', 'addSubtree', 'addPayloadPass', 'addUrlPass', 'setCustomFetch', 'whenInstalled', 'whenRegistered']);
216
226
  defineValues(this, { classes });
217
227
  }
218
228
 
package/src/root.js CHANGED
@@ -14,6 +14,7 @@ class Root extends Component {
14
14
  this._clients = [];
15
15
  this._payloadPasses = [];
16
16
  this._urlPasses = [];
17
+ this._customFetch = undefined;
17
18
  this.version = version || 'dev';
18
19
  }
19
20
 
package/src/version.js CHANGED
@@ -1 +1 @@
1
- export default '1.8.0';
1
+ export default '1.8.1-beta.1';