@miso.ai/client-sdk-core 1.6.0-beta.2 → 1.7.0-beta.0
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.
- package/dist/cjs/api/answers.js +69 -0
- package/dist/cjs/api/base.js +12 -13
- package/dist/cjs/api/helpers.js +3 -4
- package/dist/cjs/api/index.js +2 -0
- package/dist/cjs/version.js +1 -1
- package/dist/es/api/answers.js +61 -0
- package/dist/es/api/base.js +12 -13
- package/dist/es/api/helpers.js +4 -5
- package/dist/es/api/index.js +2 -0
- package/dist/es/version.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _commons = require("@miso.ai/commons");
|
|
8
|
+
var _base = _interopRequireDefault(require("./base"));
|
|
9
|
+
const _excluded = ["iterable"],
|
|
10
|
+
_excluded2 = ["pollingInternal"];
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
13
|
+
class Answers extends _base.default {
|
|
14
|
+
constructor(api) {
|
|
15
|
+
super(api, 'answers');
|
|
16
|
+
}
|
|
17
|
+
async answer(payload) {
|
|
18
|
+
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
19
|
+
let {
|
|
20
|
+
iterable = false
|
|
21
|
+
} = _ref,
|
|
22
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
23
|
+
return typeof payload === 'string' ? this._get(payload, options) : iterable ? this._iterable(payload, options) : this._answer(payload, options);
|
|
24
|
+
}
|
|
25
|
+
async _answer(payload, options) {
|
|
26
|
+
return this._run('questions', payload, options);
|
|
27
|
+
}
|
|
28
|
+
async _get(answerId, options) {
|
|
29
|
+
return this._run(`questions/${answerId}/answer`, undefined, Object.assign({}, options, {
|
|
30
|
+
method: 'GET'
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
_iterable(payload) {
|
|
34
|
+
try {
|
|
35
|
+
var _this = this;
|
|
36
|
+
let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
37
|
+
return async function* () {
|
|
38
|
+
let {
|
|
39
|
+
pollingInternal = 500
|
|
40
|
+
} = _ref2,
|
|
41
|
+
options = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
42
|
+
const response = await _this._answer(payload, options);
|
|
43
|
+
yield response;
|
|
44
|
+
const {
|
|
45
|
+
question_id,
|
|
46
|
+
finished
|
|
47
|
+
} = response;
|
|
48
|
+
if (finished) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const buffer = new _commons.ValueBuffer();
|
|
52
|
+
const intervalId = setInterval(async () => {
|
|
53
|
+
const response = await _this._get(question_id, options);
|
|
54
|
+
const {
|
|
55
|
+
finished
|
|
56
|
+
} = response;
|
|
57
|
+
buffer.update(response, finished);
|
|
58
|
+
if (response.finished) {
|
|
59
|
+
clearInterval(intervalId);
|
|
60
|
+
}
|
|
61
|
+
}, pollingInternal);
|
|
62
|
+
yield* buffer;
|
|
63
|
+
}();
|
|
64
|
+
} catch (e) {
|
|
65
|
+
return Promise.reject(e);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.default = Answers;
|
package/dist/cjs/api/base.js
CHANGED
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
|
+
const _excluded = ["bulk"];
|
|
9
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
8
10
|
class ApiBase extends _commons.Component {
|
|
9
11
|
// TODO: use private fields (may encounter issues with rollup)
|
|
10
12
|
|
|
@@ -17,7 +19,6 @@ class ApiBase extends _commons.Component {
|
|
|
17
19
|
}
|
|
18
20
|
async _run(apiName, payload) {
|
|
19
21
|
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
20
|
-
this.helpers.assertReady();
|
|
21
22
|
const {
|
|
22
23
|
bulk
|
|
23
24
|
} = options;
|
|
@@ -78,18 +79,16 @@ class ApiBase extends _commons.Component {
|
|
|
78
79
|
}
|
|
79
80
|
async _send(_ref3) {
|
|
80
81
|
let {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
} =
|
|
89
|
-
|
|
90
|
-
return bulk ? this.helpers.fetchForBulk(apiGroup, apiName, payload) : this.helpers.fetch(url, payload,
|
|
91
|
-
timeout
|
|
92
|
-
});
|
|
82
|
+
apiGroup,
|
|
83
|
+
apiName,
|
|
84
|
+
url,
|
|
85
|
+
payload,
|
|
86
|
+
options: {
|
|
87
|
+
bulk
|
|
88
|
+
} = {}
|
|
89
|
+
} = _ref3,
|
|
90
|
+
options = _objectWithoutPropertiesLoose(_ref3.options, _excluded);
|
|
91
|
+
return bulk ? this.helpers.fetchForBulk(apiGroup, apiName, payload) : this.helpers.fetch(url, payload, options);
|
|
93
92
|
}
|
|
94
93
|
_postprocess(_ref4) {
|
|
95
94
|
let {
|
package/dist/cjs/api/helpers.js
CHANGED
|
@@ -12,24 +12,23 @@ 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
|
-
assertReady() {}
|
|
16
15
|
async fetch(url, payload) {
|
|
17
16
|
let {
|
|
18
17
|
method = 'POST',
|
|
19
18
|
timeout
|
|
20
19
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
21
20
|
// TODO: organize arguments
|
|
22
|
-
const body = JSON.stringify(payload);
|
|
21
|
+
const body = method !== 'GET' && payload != undefined ? JSON.stringify(payload) : undefined;
|
|
23
22
|
const controller = timeout && new AbortController();
|
|
24
23
|
const signal = controller && controller.signal;
|
|
25
24
|
const timeoutId = controller && setTimeout(() => controller.abort(), timeout);
|
|
26
|
-
const res = await window.fetch(url, {
|
|
25
|
+
const res = await window.fetch(url, (0, _commons.trimObj)({
|
|
27
26
|
method,
|
|
28
27
|
body,
|
|
29
28
|
cache: 'no-cache',
|
|
30
29
|
mode: 'cors',
|
|
31
30
|
signal
|
|
32
|
-
});
|
|
31
|
+
}));
|
|
33
32
|
timeoutId && clearTimeout(timeoutId);
|
|
34
33
|
const resBody = await res.json();
|
|
35
34
|
if (res.status >= 400 || resBody.errors) {
|
package/dist/cjs/api/index.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.default = void 0;
|
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
8
|
var _helpers = _interopRequireDefault(require("./helpers"));
|
|
9
9
|
var _interactions = _interopRequireDefault(require("./interactions"));
|
|
10
|
+
var _answers = _interopRequireDefault(require("./answers"));
|
|
10
11
|
var _search = _interopRequireDefault(require("./search"));
|
|
11
12
|
var _recommendation = _interopRequireDefault(require("./recommendation"));
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -16,6 +17,7 @@ class Api extends _commons.Component {
|
|
|
16
17
|
this._client = client;
|
|
17
18
|
this.helpers = new _helpers.default(client, root);
|
|
18
19
|
this.interactions = new _interactions.default(this);
|
|
20
|
+
this.answers = new _answers.default(this);
|
|
19
21
|
this.search = new _search.default(this);
|
|
20
22
|
this.recommendation = new _recommendation.default(this);
|
|
21
23
|
}
|
package/dist/cjs/version.js
CHANGED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const _excluded = ["iterable"],
|
|
2
|
+
_excluded2 = ["pollingInternal"];
|
|
3
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
+
import { ValueBuffer } from '@miso.ai/commons';
|
|
5
|
+
import ApiBase from './base';
|
|
6
|
+
export default class Answers extends ApiBase {
|
|
7
|
+
constructor(api) {
|
|
8
|
+
super(api, 'answers');
|
|
9
|
+
}
|
|
10
|
+
async answer(payload) {
|
|
11
|
+
let _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
12
|
+
let {
|
|
13
|
+
iterable = false
|
|
14
|
+
} = _ref,
|
|
15
|
+
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
16
|
+
return typeof payload === 'string' ? this._get(payload, options) : iterable ? this._iterable(payload, options) : this._answer(payload, options);
|
|
17
|
+
}
|
|
18
|
+
async _answer(payload, options) {
|
|
19
|
+
return this._run('questions', payload, options);
|
|
20
|
+
}
|
|
21
|
+
async _get(answerId, options) {
|
|
22
|
+
return this._run(`questions/${answerId}/answer`, undefined, Object.assign({}, options, {
|
|
23
|
+
method: 'GET'
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
_iterable(payload) {
|
|
27
|
+
try {
|
|
28
|
+
var _this = this;
|
|
29
|
+
let _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30
|
+
return async function* () {
|
|
31
|
+
let {
|
|
32
|
+
pollingInternal = 500
|
|
33
|
+
} = _ref2,
|
|
34
|
+
options = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
35
|
+
const response = await _this._answer(payload, options);
|
|
36
|
+
yield response;
|
|
37
|
+
const {
|
|
38
|
+
question_id,
|
|
39
|
+
finished
|
|
40
|
+
} = response;
|
|
41
|
+
if (finished) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const buffer = new ValueBuffer();
|
|
45
|
+
const intervalId = setInterval(async () => {
|
|
46
|
+
const response = await _this._get(question_id, options);
|
|
47
|
+
const {
|
|
48
|
+
finished
|
|
49
|
+
} = response;
|
|
50
|
+
buffer.update(response, finished);
|
|
51
|
+
if (response.finished) {
|
|
52
|
+
clearInterval(intervalId);
|
|
53
|
+
}
|
|
54
|
+
}, pollingInternal);
|
|
55
|
+
yield* buffer;
|
|
56
|
+
}();
|
|
57
|
+
} catch (e) {
|
|
58
|
+
return Promise.reject(e);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
package/dist/es/api/base.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const _excluded = ["bulk"];
|
|
2
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
1
3
|
import { Component } from '@miso.ai/commons';
|
|
2
4
|
export default class ApiBase extends Component {
|
|
3
5
|
// TODO: use private fields (may encounter issues with rollup)
|
|
@@ -11,7 +13,6 @@ export default class ApiBase extends Component {
|
|
|
11
13
|
}
|
|
12
14
|
async _run(apiName, payload) {
|
|
13
15
|
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
14
|
-
this.helpers.assertReady();
|
|
15
16
|
const {
|
|
16
17
|
bulk
|
|
17
18
|
} = options;
|
|
@@ -72,18 +73,16 @@ export default class ApiBase extends Component {
|
|
|
72
73
|
}
|
|
73
74
|
async _send(_ref3) {
|
|
74
75
|
let {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} =
|
|
83
|
-
|
|
84
|
-
return bulk ? this.helpers.fetchForBulk(apiGroup, apiName, payload) : this.helpers.fetch(url, payload,
|
|
85
|
-
timeout
|
|
86
|
-
});
|
|
76
|
+
apiGroup,
|
|
77
|
+
apiName,
|
|
78
|
+
url,
|
|
79
|
+
payload,
|
|
80
|
+
options: {
|
|
81
|
+
bulk
|
|
82
|
+
} = {}
|
|
83
|
+
} = _ref3,
|
|
84
|
+
options = _objectWithoutPropertiesLoose(_ref3.options, _excluded);
|
|
85
|
+
return bulk ? this.helpers.fetchForBulk(apiGroup, apiName, payload) : this.helpers.fetch(url, payload, options);
|
|
87
86
|
}
|
|
88
87
|
_postprocess(_ref4) {
|
|
89
88
|
let {
|
package/dist/es/api/helpers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Bulk } from '@miso.ai/commons';
|
|
1
|
+
import { Bulk, trimObj } from '@miso.ai/commons';
|
|
2
2
|
import { API } from '../constants';
|
|
3
3
|
export default class ApiHelpers {
|
|
4
4
|
constructor(client, root) {
|
|
@@ -6,24 +6,23 @@ export default class ApiHelpers {
|
|
|
6
6
|
this._root = root;
|
|
7
7
|
this._bulk = new Bulk(this._runBulkFetch.bind(this), client._error.bind(client));
|
|
8
8
|
}
|
|
9
|
-
assertReady() {}
|
|
10
9
|
async fetch(url, payload) {
|
|
11
10
|
let {
|
|
12
11
|
method = 'POST',
|
|
13
12
|
timeout
|
|
14
13
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
15
14
|
// TODO: organize arguments
|
|
16
|
-
const body = JSON.stringify(payload);
|
|
15
|
+
const body = method !== 'GET' && payload != undefined ? JSON.stringify(payload) : undefined;
|
|
17
16
|
const controller = timeout && new AbortController();
|
|
18
17
|
const signal = controller && controller.signal;
|
|
19
18
|
const timeoutId = controller && setTimeout(() => controller.abort(), timeout);
|
|
20
|
-
const res = await window.fetch(url, {
|
|
19
|
+
const res = await window.fetch(url, trimObj({
|
|
21
20
|
method,
|
|
22
21
|
body,
|
|
23
22
|
cache: 'no-cache',
|
|
24
23
|
mode: 'cors',
|
|
25
24
|
signal
|
|
26
|
-
});
|
|
25
|
+
}));
|
|
27
26
|
timeoutId && clearTimeout(timeoutId);
|
|
28
27
|
const resBody = await res.json();
|
|
29
28
|
if (res.status >= 400 || resBody.errors) {
|
package/dist/es/api/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component } from '@miso.ai/commons';
|
|
2
2
|
import ApiHelpers from './helpers';
|
|
3
3
|
import Interactions from './interactions';
|
|
4
|
+
import Answers from './answers';
|
|
4
5
|
import Search from './search';
|
|
5
6
|
import Recommendation from './recommendation';
|
|
6
7
|
export default class Api extends Component {
|
|
@@ -9,6 +10,7 @@ export default class Api extends Component {
|
|
|
9
10
|
this._client = client;
|
|
10
11
|
this.helpers = new ApiHelpers(client, root);
|
|
11
12
|
this.interactions = new Interactions(this);
|
|
13
|
+
this.answers = new Answers(this);
|
|
12
14
|
this.search = new Search(this);
|
|
13
15
|
this.recommendation = new Recommendation(this);
|
|
14
16
|
}
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.
|
|
1
|
+
export default '1.7.0-beta.0';
|
package/package.json
CHANGED