@miso.ai/client-sdk-core 1.7.4-beta.0 → 1.7.4-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.
- package/README.md +3 -2
- package/dist/cjs/api/base.js +5 -3
- package/dist/cjs/api/helpers.js +24 -9
- package/dist/cjs/api/interactions.js +5 -3
- package/dist/cjs/client.js +2 -1
- package/dist/cjs/version.js +1 -1
- package/dist/es/api/base.js +5 -3
- package/dist/es/api/helpers.js +24 -9
- package/dist/es/api/interactions.js +5 -3
- package/dist/es/client.js +2 -1
- package/dist/es/version.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Miso SDK for JavaScript: Core
|
|
2
|
-
The core module of the SDK.
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
The core module of the Miso JavaScipt SDK.
|
|
4
|
+
|
|
5
|
+
Visit [Documentation](https://misoai.github.io/miso-client-js-sdk/sdk) for details.
|
package/dist/cjs/api/base.js
CHANGED
|
@@ -68,13 +68,15 @@ class ApiBase extends _commons.Component {
|
|
|
68
68
|
_url(_ref2) {
|
|
69
69
|
let {
|
|
70
70
|
apiGroup,
|
|
71
|
-
apiName
|
|
71
|
+
apiName,
|
|
72
|
+
options
|
|
72
73
|
} = _ref2;
|
|
73
|
-
const url = this.helpers.url(apiGroup, apiName);
|
|
74
|
+
const url = this.helpers.url([apiGroup, apiName], options);
|
|
74
75
|
return this.helpers.applyUrlPasses(this, {
|
|
75
76
|
apiGroup,
|
|
76
77
|
apiName,
|
|
77
|
-
url
|
|
78
|
+
url,
|
|
79
|
+
options
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
async _send(_ref3) {
|
package/dist/cjs/api/helpers.js
CHANGED
|
@@ -15,14 +15,28 @@ class ApiHelpers {
|
|
|
15
15
|
async fetch(url, payload) {
|
|
16
16
|
let {
|
|
17
17
|
method = 'POST',
|
|
18
|
-
|
|
18
|
+
headers,
|
|
19
|
+
timeout,
|
|
20
|
+
sendApiKeyByHeader
|
|
19
21
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
22
|
+
const {
|
|
23
|
+
apiKey,
|
|
24
|
+
request = {}
|
|
25
|
+
} = this._client.options;
|
|
26
|
+
timeout = timeout || request.timeout;
|
|
27
|
+
sendApiKeyByHeader = sendApiKeyByHeader || request.sendApiKeyByHeader;
|
|
28
|
+
if (sendApiKeyByHeader) {
|
|
29
|
+
headers = Object.assign({}, headers, {
|
|
30
|
+
'X-API-KEY': apiKey
|
|
31
|
+
});
|
|
32
|
+
}
|
|
20
33
|
// TODO: external abort signal
|
|
21
34
|
// TODO: organize arguments
|
|
22
35
|
const body = method !== 'GET' && payload != undefined ? JSON.stringify(payload) : undefined;
|
|
23
36
|
const signal = timeout ? AbortSignal.timeout(timeout) : undefined;
|
|
24
37
|
const res = await window.fetch(url, (0, _commons.trimObj)({
|
|
25
38
|
method,
|
|
39
|
+
headers,
|
|
26
40
|
body,
|
|
27
41
|
cache: 'no-cache',
|
|
28
42
|
mode: 'cors',
|
|
@@ -54,7 +68,8 @@ class ApiHelpers {
|
|
|
54
68
|
});
|
|
55
69
|
}
|
|
56
70
|
async _runBulkFetch(requests) {
|
|
57
|
-
|
|
71
|
+
// TODO: request options?
|
|
72
|
+
const url = this.url(['bulk']);
|
|
58
73
|
const payload = {
|
|
59
74
|
requests: requests.map(_ref => {
|
|
60
75
|
let {
|
|
@@ -103,16 +118,16 @@ class ApiHelpers {
|
|
|
103
118
|
throw new Error(`Send beacon unsuccessful: ${url}`);
|
|
104
119
|
}
|
|
105
120
|
}
|
|
106
|
-
url() {
|
|
121
|
+
url(paths) {
|
|
122
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
107
123
|
const {
|
|
108
|
-
apiKey
|
|
124
|
+
apiKey,
|
|
125
|
+
request = {}
|
|
109
126
|
} = this._client.options;
|
|
110
|
-
|
|
111
|
-
paths[_key] = arguments[_key];
|
|
112
|
-
}
|
|
127
|
+
const sendApiKeyByHeader = options.sendApiKeyByHeader || request.sendApiKeyByHeader;
|
|
113
128
|
const apiName = paths.filter(s => s).join('/');
|
|
114
|
-
|
|
115
|
-
return `${
|
|
129
|
+
const url = `${this.getApiEndpoint(apiName)}/${apiName}`;
|
|
130
|
+
return sendApiKeyByHeader ? url : `${url}?api_key=${window.encodeURIComponent(apiKey)}`;
|
|
116
131
|
}
|
|
117
132
|
getApiEndpoint(apiName) {
|
|
118
133
|
const {
|
|
@@ -27,13 +27,15 @@ class Interactions extends _base.default {
|
|
|
27
27
|
_url(_ref) {
|
|
28
28
|
let {
|
|
29
29
|
apiGroup,
|
|
30
|
-
apiName
|
|
30
|
+
apiName,
|
|
31
|
+
options
|
|
31
32
|
} = _ref;
|
|
32
|
-
const url = this.helpers.url(this._apiPath);
|
|
33
|
+
const url = this.helpers.url([this._apiPath], options);
|
|
33
34
|
return this.helpers.applyUrlPasses(this, {
|
|
34
35
|
apiGroup,
|
|
35
36
|
apiName,
|
|
36
|
-
url
|
|
37
|
+
url,
|
|
38
|
+
options
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
41
|
_preprocess(_ref2) {
|
package/dist/cjs/client.js
CHANGED
|
@@ -26,7 +26,8 @@ class MisoClient extends _commons.Component {
|
|
|
26
26
|
_config(options) {
|
|
27
27
|
this.options = Object.freeze(this._normalizeOptions(options));
|
|
28
28
|
}
|
|
29
|
-
_normalizeOptions(
|
|
29
|
+
_normalizeOptions() {
|
|
30
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
30
31
|
if (typeof options === 'string') {
|
|
31
32
|
options = {
|
|
32
33
|
apiKey: options
|
package/dist/cjs/version.js
CHANGED
package/dist/es/api/base.js
CHANGED
|
@@ -62,13 +62,15 @@ export default class ApiBase extends Component {
|
|
|
62
62
|
_url(_ref2) {
|
|
63
63
|
let {
|
|
64
64
|
apiGroup,
|
|
65
|
-
apiName
|
|
65
|
+
apiName,
|
|
66
|
+
options
|
|
66
67
|
} = _ref2;
|
|
67
|
-
const url = this.helpers.url(apiGroup, apiName);
|
|
68
|
+
const url = this.helpers.url([apiGroup, apiName], options);
|
|
68
69
|
return this.helpers.applyUrlPasses(this, {
|
|
69
70
|
apiGroup,
|
|
70
71
|
apiName,
|
|
71
|
-
url
|
|
72
|
+
url,
|
|
73
|
+
options
|
|
72
74
|
});
|
|
73
75
|
}
|
|
74
76
|
async _send(_ref3) {
|
package/dist/es/api/helpers.js
CHANGED
|
@@ -9,14 +9,28 @@ export default class ApiHelpers {
|
|
|
9
9
|
async fetch(url, payload) {
|
|
10
10
|
let {
|
|
11
11
|
method = 'POST',
|
|
12
|
-
|
|
12
|
+
headers,
|
|
13
|
+
timeout,
|
|
14
|
+
sendApiKeyByHeader
|
|
13
15
|
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
16
|
+
const {
|
|
17
|
+
apiKey,
|
|
18
|
+
request = {}
|
|
19
|
+
} = this._client.options;
|
|
20
|
+
timeout = timeout || request.timeout;
|
|
21
|
+
sendApiKeyByHeader = sendApiKeyByHeader || request.sendApiKeyByHeader;
|
|
22
|
+
if (sendApiKeyByHeader) {
|
|
23
|
+
headers = Object.assign({}, headers, {
|
|
24
|
+
'X-API-KEY': apiKey
|
|
25
|
+
});
|
|
26
|
+
}
|
|
14
27
|
// TODO: external abort signal
|
|
15
28
|
// TODO: organize arguments
|
|
16
29
|
const body = method !== 'GET' && payload != undefined ? JSON.stringify(payload) : undefined;
|
|
17
30
|
const signal = timeout ? AbortSignal.timeout(timeout) : undefined;
|
|
18
31
|
const res = await window.fetch(url, trimObj({
|
|
19
32
|
method,
|
|
33
|
+
headers,
|
|
20
34
|
body,
|
|
21
35
|
cache: 'no-cache',
|
|
22
36
|
mode: 'cors',
|
|
@@ -48,7 +62,8 @@ export default class ApiHelpers {
|
|
|
48
62
|
});
|
|
49
63
|
}
|
|
50
64
|
async _runBulkFetch(requests) {
|
|
51
|
-
|
|
65
|
+
// TODO: request options?
|
|
66
|
+
const url = this.url(['bulk']);
|
|
52
67
|
const payload = {
|
|
53
68
|
requests: requests.map(_ref => {
|
|
54
69
|
let {
|
|
@@ -97,16 +112,16 @@ export default class ApiHelpers {
|
|
|
97
112
|
throw new Error(`Send beacon unsuccessful: ${url}`);
|
|
98
113
|
}
|
|
99
114
|
}
|
|
100
|
-
url() {
|
|
115
|
+
url(paths) {
|
|
116
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
101
117
|
const {
|
|
102
|
-
apiKey
|
|
118
|
+
apiKey,
|
|
119
|
+
request = {}
|
|
103
120
|
} = this._client.options;
|
|
104
|
-
|
|
105
|
-
paths[_key] = arguments[_key];
|
|
106
|
-
}
|
|
121
|
+
const sendApiKeyByHeader = options.sendApiKeyByHeader || request.sendApiKeyByHeader;
|
|
107
122
|
const apiName = paths.filter(s => s).join('/');
|
|
108
|
-
|
|
109
|
-
return `${
|
|
123
|
+
const url = `${this.getApiEndpoint(apiName)}/${apiName}`;
|
|
124
|
+
return sendApiKeyByHeader ? url : `${url}?api_key=${window.encodeURIComponent(apiKey)}`;
|
|
110
125
|
}
|
|
111
126
|
getApiEndpoint(apiName) {
|
|
112
127
|
const {
|
|
@@ -20,13 +20,15 @@ export default class Interactions extends ApiBase {
|
|
|
20
20
|
_url(_ref) {
|
|
21
21
|
let {
|
|
22
22
|
apiGroup,
|
|
23
|
-
apiName
|
|
23
|
+
apiName,
|
|
24
|
+
options
|
|
24
25
|
} = _ref;
|
|
25
|
-
const url = this.helpers.url(this._apiPath);
|
|
26
|
+
const url = this.helpers.url([this._apiPath], options);
|
|
26
27
|
return this.helpers.applyUrlPasses(this, {
|
|
27
28
|
apiGroup,
|
|
28
29
|
apiName,
|
|
29
|
-
url
|
|
30
|
+
url,
|
|
31
|
+
options
|
|
30
32
|
});
|
|
31
33
|
}
|
|
32
34
|
_preprocess(_ref2) {
|
package/dist/es/client.js
CHANGED
|
@@ -17,7 +17,8 @@ class MisoClient extends Component {
|
|
|
17
17
|
_config(options) {
|
|
18
18
|
this.options = Object.freeze(this._normalizeOptions(options));
|
|
19
19
|
}
|
|
20
|
-
_normalizeOptions(
|
|
20
|
+
_normalizeOptions() {
|
|
21
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
21
22
|
if (typeof options === 'string') {
|
|
22
23
|
options = {
|
|
23
24
|
apiKey: options
|
package/dist/es/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '1.7.4-beta.
|
|
1
|
+
export default '1.7.4-beta.1';
|
package/package.json
CHANGED