@miso.ai/server-sdk 0.6.5-beta.3 → 0.6.5-beta.5
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/package.json +3 -2
- package/src/api/base.js +4 -5
- package/src/api/experiments.js +1 -2
- package/src/api/helpers.js +2 -8
- package/src/axios.js +27 -0
- package/src/client.js +3 -1
- package/src/stream/delete.js +1 -1
- package/src/version.js +1 -1
package/package.json
CHANGED
|
@@ -16,11 +16,12 @@
|
|
|
16
16
|
"simonpai <simon.pai@askmiso.com>"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@miso.ai/server-commons": "0.6.5-beta.
|
|
19
|
+
"@miso.ai/server-commons": "0.6.5-beta.5",
|
|
20
20
|
"axios": "^1.6.2",
|
|
21
|
+
"axios-retry": "^4.5.0",
|
|
21
22
|
"dotenv": "^16.0.1",
|
|
22
23
|
"split2": "^4.1.0",
|
|
23
24
|
"yargs": "^17.5.1"
|
|
24
25
|
},
|
|
25
|
-
"version": "0.6.5-beta.
|
|
26
|
+
"version": "0.6.5-beta.5"
|
|
26
27
|
}
|
package/src/api/base.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
1
|
import { asArray } from '@miso.ai/server-commons';
|
|
3
2
|
import { upload, merge, batchDelete, buildUrl } from './helpers.js';
|
|
4
3
|
import UploadStream from '../stream/upload.js';
|
|
@@ -16,7 +15,7 @@ export class Queries {
|
|
|
16
15
|
async _run(path, payload, options) {
|
|
17
16
|
// TODO: options
|
|
18
17
|
const url = buildUrl(this._client, `${this._group}/${path}`);
|
|
19
|
-
return (await
|
|
18
|
+
return (await this._client._axios.post(url, payload)).data.data;
|
|
20
19
|
}
|
|
21
20
|
|
|
22
21
|
}
|
|
@@ -46,13 +45,13 @@ export class Entities extends Writable {
|
|
|
46
45
|
|
|
47
46
|
async get(id) {
|
|
48
47
|
const url = buildUrl(this._client, `${this._type}/${id}`);
|
|
49
|
-
return (await
|
|
48
|
+
return (await this._client._axios.get(url)).data.data;
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
async ids({ type } = {}) {
|
|
53
52
|
const options = type ? { params: { type } } : {};
|
|
54
53
|
const url = buildUrl(this._client, `${this._type}/_ids`, options);
|
|
55
|
-
return (await
|
|
54
|
+
return (await this._client._axios.get(url)).data.data.ids;
|
|
56
55
|
}
|
|
57
56
|
|
|
58
57
|
async delete(ids, options = {}) {
|
|
@@ -65,7 +64,7 @@ export class Entities extends Writable {
|
|
|
65
64
|
|
|
66
65
|
async status(taskId) {
|
|
67
66
|
const url = buildUrl(this._client, `${this._type}/_status/${taskId}`);
|
|
68
|
-
return (await
|
|
67
|
+
return (await this._client._axios.get(url)).data;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
statusStream() {
|
package/src/api/experiments.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
1
|
import { buildUrl } from './helpers.js';
|
|
3
2
|
|
|
4
3
|
export default class Experiments {
|
|
@@ -12,7 +11,7 @@ export default class Experiments {
|
|
|
12
11
|
const url = buildUrl(this._client, `experiments/${experimentId}/events`);
|
|
13
12
|
// TODO: make content type header global
|
|
14
13
|
const headers = { 'Content-Type': 'application/json' };
|
|
15
|
-
const response = await
|
|
14
|
+
const response = await this._client._axios.post(url, record, { headers });
|
|
16
15
|
// 200 response body does not have .data layer
|
|
17
16
|
return response.data ? response : { data: response };
|
|
18
17
|
}
|
package/src/api/helpers.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { asArray, trimObj, computeIfAbsent } from '@miso.ai/server-commons';
|
|
2
|
-
import axios from 'axios';
|
|
3
2
|
import { Buffer } from 'buffer';
|
|
4
3
|
|
|
5
4
|
export async function upload(client, type, records, options = {}) {
|
|
6
5
|
const url = buildUrl(client, type, { ...options, async: true });
|
|
7
6
|
const payload = buildUploadPayload(records);
|
|
8
|
-
return
|
|
7
|
+
return client._axios.post(url, payload);
|
|
9
8
|
}
|
|
10
9
|
|
|
11
10
|
export async function merge(client, type, record, { mergeFn = defaultMerge } = {}) {
|
|
@@ -98,12 +97,7 @@ export function process422ResponseBody(payload, { data } = {}) {
|
|
|
98
97
|
export async function batchDelete(client, type, ids, options = {}) {
|
|
99
98
|
const url = buildUrl(client, `${type}/_delete`, { ...options, async: true });
|
|
100
99
|
const payload = buildBatchDeletePayload(type, ids);
|
|
101
|
-
|
|
102
|
-
const { data } = await axios.post(url, payload, {
|
|
103
|
-
headers: {
|
|
104
|
-
'Content-Type': 'application/json',
|
|
105
|
-
},
|
|
106
|
-
});
|
|
100
|
+
const { data } = await client._axios.post(url, payload);
|
|
107
101
|
return data;
|
|
108
102
|
}
|
|
109
103
|
|
package/src/axios.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import axiosRetry from 'axios-retry';
|
|
3
|
+
import version from './version.js';
|
|
4
|
+
|
|
5
|
+
const DEFAULT_RETRY_OPTIONS = {
|
|
6
|
+
retries: 3,
|
|
7
|
+
retryDelay: count => count * 300,
|
|
8
|
+
retryCondition: (error) => {
|
|
9
|
+
// Only retry on 5xx server errors
|
|
10
|
+
return error.response && error.response.status >= 500 && error.response.status < 600;
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export function createAxios(options = {}) {
|
|
15
|
+
if (typeof options.get === 'function' && typeof options.post === 'function') {
|
|
16
|
+
return options; // assume this is an axios instance already
|
|
17
|
+
}
|
|
18
|
+
const { retry } = options;
|
|
19
|
+
const instance = axios.create({
|
|
20
|
+
headers: {
|
|
21
|
+
'User-Agent': `MisoNodeJSSDK/${version}`,
|
|
22
|
+
'Content-Type': 'application/json',
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
axiosRetry(instance, { ...DEFAULT_RETRY_OPTIONS, ...retry });
|
|
26
|
+
return instance;
|
|
27
|
+
}
|
package/src/client.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import version from './version.js';
|
|
2
2
|
import Api from './api/index.js';
|
|
3
|
+
import { createAxios } from './axios.js';
|
|
3
4
|
|
|
4
5
|
export default class MisoClient {
|
|
5
6
|
|
|
6
7
|
static version = version;
|
|
7
8
|
|
|
8
|
-
constructor(options) {
|
|
9
|
+
constructor({ axios, ...options } = {}) {
|
|
9
10
|
this._options = normalizeOptions(options);
|
|
11
|
+
this._axios = createAxios({ ...axios }); // TODO: pass onRetry() for debug message
|
|
10
12
|
this.version = version;
|
|
11
13
|
this.api = new Api(this);
|
|
12
14
|
}
|
package/src/stream/delete.js
CHANGED
|
@@ -68,7 +68,7 @@ export default class DeleteStream extends stream.BufferedWriteStream {
|
|
|
68
68
|
const output = super._output(message, args);
|
|
69
69
|
|
|
70
70
|
// if upload fails, emit extracted payload at response event
|
|
71
|
-
if (message.event === 'response' && args.
|
|
71
|
+
if (message.event === 'response' && args.payload) {
|
|
72
72
|
output.payload = JSON.parse(args.payload);
|
|
73
73
|
}
|
|
74
74
|
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '0.6.5-beta.
|
|
1
|
+
export default '0.6.5-beta.5';
|