@miso.ai/server-sdk 0.6.5-beta.7 → 0.6.5-beta.8
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/cli/delete.js +1 -1
- package/cli/get.js +8 -3
- package/cli/hybrid-search.js +36 -0
- package/cli/ids-diff.js +2 -1
- package/cli/ids.js +3 -2
- package/cli/index.js +4 -0
- package/cli/merge.js +2 -1
- package/cli/search.js +30 -0
- package/cli/status.js +3 -2
- package/cli/upload.js +1 -1
- package/cli/utils.js +32 -0
- package/package.json +2 -2
- package/src/api/ask.js +13 -0
- package/src/api/index.js +2 -0
- package/src/axios.js +18 -2
- package/src/client.js +1 -1
- package/src/version.js +1 -1
package/cli/delete.js
CHANGED
|
@@ -49,7 +49,7 @@ const run = type => async ({
|
|
|
49
49
|
loglevel = (debug || progress) ? log.DEBUG : loglevel;
|
|
50
50
|
logFormat = progress ? logger.FORMAT.PROGRESS : logFormat;
|
|
51
51
|
|
|
52
|
-
const client = new MisoClient({ key, server });
|
|
52
|
+
const client = new MisoClient({ key, server, debug });
|
|
53
53
|
|
|
54
54
|
const deleteStream = client.api[type].deleteStream({
|
|
55
55
|
name,
|
package/cli/get.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MisoClient } from '../src/index.js';
|
|
2
|
+
import { formatError } from './utils.js';
|
|
2
3
|
|
|
3
4
|
const build = yargs => yargs;
|
|
4
5
|
|
|
@@ -8,9 +9,13 @@ const run = type => async ({
|
|
|
8
9
|
id,
|
|
9
10
|
debug,
|
|
10
11
|
}) => {
|
|
11
|
-
const client = new MisoClient({ key, server });
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
const client = new MisoClient({ key, server, debug });
|
|
13
|
+
try {
|
|
14
|
+
const entity = await client.api[type].get(id);
|
|
15
|
+
console.log(JSON.stringify(entity));
|
|
16
|
+
} catch (err) {
|
|
17
|
+
console.error(formatError(err));
|
|
18
|
+
}
|
|
14
19
|
};
|
|
15
20
|
|
|
16
21
|
export default function(type) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { stream } from '@miso.ai/server-commons';
|
|
3
|
+
import { MisoClient } from '../src/index.js';
|
|
4
|
+
import { buildForApi, buildForSearch } from './utils.js';
|
|
5
|
+
|
|
6
|
+
function build(yargs) {
|
|
7
|
+
return buildForSearch(buildForApi(yargs))
|
|
8
|
+
.positional('query', {
|
|
9
|
+
describe: 'Search query',
|
|
10
|
+
})
|
|
11
|
+
.option('answer', {
|
|
12
|
+
type: 'boolean',
|
|
13
|
+
describe: 'Return answer',
|
|
14
|
+
default: false,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function run({ query, fq, fl, rows, answer, key, server, debug }) {
|
|
19
|
+
const client = new MisoClient({ key, server, debug });
|
|
20
|
+
const { products } = await client.api.ask.search({ q: query, fq, fl, rows, answer });
|
|
21
|
+
const readStream = Readable.from(products);
|
|
22
|
+
const outputStream = new stream.OutputStream();
|
|
23
|
+
|
|
24
|
+
await stream.pipeline(
|
|
25
|
+
readStream,
|
|
26
|
+
outputStream,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default {
|
|
31
|
+
command: 'hybrid-search [query]',
|
|
32
|
+
aliases: ['hs'],
|
|
33
|
+
description: `Hybrid search records by a query.`,
|
|
34
|
+
builder: build,
|
|
35
|
+
handler: run,
|
|
36
|
+
};
|
package/cli/ids-diff.js
CHANGED
|
@@ -30,10 +30,11 @@ const run = type => async ({
|
|
|
30
30
|
output,
|
|
31
31
|
plus,
|
|
32
32
|
minus,
|
|
33
|
+
debug,
|
|
33
34
|
}) => {
|
|
34
35
|
output = output || (plus ? 'plus' : minus ? 'minus' : undefined);
|
|
35
36
|
|
|
36
|
-
const client = new MisoClient({ key, server });
|
|
37
|
+
const client = new MisoClient({ key, server, debug });
|
|
37
38
|
const misoIds = await client.api[type].ids();
|
|
38
39
|
|
|
39
40
|
const diffStream = new stream.DiffStream(misoIds, { output });
|
package/cli/ids.js
CHANGED
|
@@ -22,8 +22,9 @@ const run = type => async ({
|
|
|
22
22
|
key,
|
|
23
23
|
server,
|
|
24
24
|
type: recordType,
|
|
25
|
+
debug,
|
|
25
26
|
}) => {
|
|
26
|
-
const client = new MisoClient({ key, server });
|
|
27
|
+
const client = new MisoClient({ key, server, debug });
|
|
27
28
|
let ids;
|
|
28
29
|
try {
|
|
29
30
|
const options = recordType ? { type: recordType } : {};
|
|
@@ -45,7 +46,7 @@ const run = type => async ({
|
|
|
45
46
|
export default function(type) {
|
|
46
47
|
return {
|
|
47
48
|
command: 'ids',
|
|
48
|
-
description:
|
|
49
|
+
description: `Get all ids in the catalog`,
|
|
49
50
|
builder: build(type),
|
|
50
51
|
handler: run(type),
|
|
51
52
|
};
|
package/cli/index.js
CHANGED
|
@@ -9,6 +9,8 @@ import ids from './ids.js';
|
|
|
9
9
|
import transform from './transform.js';
|
|
10
10
|
import status from './status.js';
|
|
11
11
|
import get from './get.js';
|
|
12
|
+
import search from './search.js';
|
|
13
|
+
import hybridSearch from './hybrid-search.js';
|
|
12
14
|
|
|
13
15
|
const interactions = {
|
|
14
16
|
command: 'interactions',
|
|
@@ -68,5 +70,7 @@ yargs.build(yargs => {
|
|
|
68
70
|
.command(users)
|
|
69
71
|
.command(experiments)
|
|
70
72
|
.command(transform)
|
|
73
|
+
.command(search)
|
|
74
|
+
.command(hybridSearch)
|
|
71
75
|
.version(MisoClient.version);
|
|
72
76
|
});
|
package/cli/merge.js
CHANGED
|
@@ -27,11 +27,12 @@ const run = type => async ({
|
|
|
27
27
|
server,
|
|
28
28
|
file,
|
|
29
29
|
base,
|
|
30
|
+
debug,
|
|
30
31
|
...options
|
|
31
32
|
}) => {
|
|
32
33
|
const mergeFn = await getMergeFn(file);
|
|
33
34
|
const records = await buildBaseRecords(base);
|
|
34
|
-
const client = new MisoClient({ key, server });
|
|
35
|
+
const client = new MisoClient({ key, server, debug });
|
|
35
36
|
const mergeStream = client.api[type].mergeStream({ ...options, mergeFn, records });
|
|
36
37
|
const outputStream = new stream.OutputStream({ objectMode: true });
|
|
37
38
|
await stream.pipeline(
|
package/cli/search.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Readable } from 'stream';
|
|
2
|
+
import { stream } from '@miso.ai/server-commons';
|
|
3
|
+
import { MisoClient } from '../src/index.js';
|
|
4
|
+
import { buildForApi, buildForSearch } from './utils.js';
|
|
5
|
+
|
|
6
|
+
function build(yargs) {
|
|
7
|
+
return buildForSearch(buildForApi(yargs))
|
|
8
|
+
.positional('query', {
|
|
9
|
+
describe: 'Search query',
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function run({ query, fq, fl, rows, key, server, debug }) {
|
|
14
|
+
const client = new MisoClient({ key, server, debug });
|
|
15
|
+
const records = await client.api.search.search({ q: query, fq, fl, rows });
|
|
16
|
+
const readStream = Readable.from(records);
|
|
17
|
+
const outputStream = new stream.OutputStream();
|
|
18
|
+
|
|
19
|
+
await stream.pipeline(
|
|
20
|
+
readStream,
|
|
21
|
+
outputStream,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
command: 'search [query]',
|
|
27
|
+
description: `Search records by a query.`,
|
|
28
|
+
builder: build,
|
|
29
|
+
handler: run,
|
|
30
|
+
};
|
package/cli/status.js
CHANGED
|
@@ -10,8 +10,9 @@ const run = type => async ({
|
|
|
10
10
|
key,
|
|
11
11
|
server,
|
|
12
12
|
taskId,
|
|
13
|
+
debug,
|
|
13
14
|
}) => {
|
|
14
|
-
const client = new MisoClient({ key, server });
|
|
15
|
+
const client = new MisoClient({ key, server, debug });
|
|
15
16
|
if (taskId) {
|
|
16
17
|
runOne(client, type, taskId);
|
|
17
18
|
} else {
|
|
@@ -21,7 +22,7 @@ const run = type => async ({
|
|
|
21
22
|
|
|
22
23
|
async function runOne(client, type, taskId) {
|
|
23
24
|
try {
|
|
24
|
-
console.log(await client.api[type].status(taskId));
|
|
25
|
+
console.log(JSON.stringify(await client.api[type].status(taskId)));
|
|
25
26
|
} catch (err) {
|
|
26
27
|
console.error(err);
|
|
27
28
|
throw err;
|
package/cli/upload.js
CHANGED
|
@@ -61,7 +61,7 @@ const run = type => async ({
|
|
|
61
61
|
loglevel = (debug || progress) ? log.DEBUG : loglevel;
|
|
62
62
|
logFormat = progress ? logger.FORMAT.PROGRESS : logFormat;
|
|
63
63
|
|
|
64
|
-
const client = new MisoClient({ key, server });
|
|
64
|
+
const client = new MisoClient({ key, server, debug });
|
|
65
65
|
|
|
66
66
|
const uploadStreamObjectMode = lenient;
|
|
67
67
|
|
package/cli/utils.js
CHANGED
|
@@ -20,3 +20,35 @@ export function buildForApi(yargs) {
|
|
|
20
20
|
})
|
|
21
21
|
.demandOption(['key'], 'API key is required.');
|
|
22
22
|
}
|
|
23
|
+
|
|
24
|
+
export function buildForSearch(yargs) {
|
|
25
|
+
return yargs
|
|
26
|
+
.option('fq', {
|
|
27
|
+
type: 'string',
|
|
28
|
+
describe: 'Filter query',
|
|
29
|
+
})
|
|
30
|
+
.option('fl', {
|
|
31
|
+
type: 'array',
|
|
32
|
+
coerce: yargs.coerceToArray,
|
|
33
|
+
describe: 'Fields to return',
|
|
34
|
+
})
|
|
35
|
+
.option('rows', {
|
|
36
|
+
alias: ['n'],
|
|
37
|
+
type: 'number',
|
|
38
|
+
describe: 'Number of rows to return',
|
|
39
|
+
})
|
|
40
|
+
.option('start', {
|
|
41
|
+
alias: ['s'],
|
|
42
|
+
type: 'number',
|
|
43
|
+
describe: 'Start index',
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function formatError(err) {
|
|
48
|
+
const { response } = err;
|
|
49
|
+
if (response) {
|
|
50
|
+
const { data, status } = response;
|
|
51
|
+
return { errors: true, status, ...data };
|
|
52
|
+
}
|
|
53
|
+
return { errors: true, message: err.message };
|
|
54
|
+
}
|
package/package.json
CHANGED
|
@@ -16,12 +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.8",
|
|
20
20
|
"axios": "^1.6.2",
|
|
21
21
|
"axios-retry": "^4.5.0",
|
|
22
22
|
"dotenv": "^16.0.1",
|
|
23
23
|
"split2": "^4.1.0",
|
|
24
24
|
"yargs": "^17.5.1"
|
|
25
25
|
},
|
|
26
|
-
"version": "0.6.5-beta.
|
|
26
|
+
"version": "0.6.5-beta.8"
|
|
27
27
|
}
|
package/src/api/ask.js
ADDED
package/src/api/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import Products from './products.js';
|
|
|
2
2
|
import Users from './users.js';
|
|
3
3
|
import Interactions from './interactions.js';
|
|
4
4
|
import Experiments from './experiments.js';
|
|
5
|
+
import Ask from './ask.js';
|
|
5
6
|
import Search from './search.js';
|
|
6
7
|
import Recommendation from './recommendation.js';
|
|
7
8
|
|
|
@@ -12,6 +13,7 @@ export default class Api {
|
|
|
12
13
|
this.users = new Users(client);
|
|
13
14
|
this.interactions = new Interactions(client);
|
|
14
15
|
this.experiments = new Experiments(client);
|
|
16
|
+
this.ask = new Ask(client);
|
|
15
17
|
this.search = new Search(client);
|
|
16
18
|
this.recommendation = new Recommendation(client);
|
|
17
19
|
}
|
package/src/axios.js
CHANGED
|
@@ -11,17 +11,33 @@ const DEFAULT_RETRY_OPTIONS = {
|
|
|
11
11
|
},
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export function createAxios(options = {}) {
|
|
14
|
+
export function createAxios(options = {}, debug = false) {
|
|
15
15
|
if (typeof options.get === 'function' && typeof options.post === 'function') {
|
|
16
16
|
return options; // assume this is an axios instance already
|
|
17
17
|
}
|
|
18
18
|
const { retry } = options;
|
|
19
19
|
const instance = axios.create({
|
|
20
20
|
headers: {
|
|
21
|
-
'User-Agent': `
|
|
21
|
+
'User-Agent': `MisoNodeSDK/${version}`,
|
|
22
22
|
'Content-Type': 'application/json',
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
25
|
axiosRetry(instance, { ...DEFAULT_RETRY_OPTIONS, ...retry });
|
|
26
|
+
if (debug) {
|
|
27
|
+
instance.interceptors.request.use(config => {
|
|
28
|
+
explainAsCurl(config);
|
|
29
|
+
return config;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
26
32
|
return instance;
|
|
27
33
|
}
|
|
34
|
+
|
|
35
|
+
function explainAsCurl(config) {
|
|
36
|
+
// format into a curl command
|
|
37
|
+
const { method, url, data } = config;
|
|
38
|
+
let command = `curl -X ${method.toUpperCase()} '${url}'`;
|
|
39
|
+
if (data) {
|
|
40
|
+
command += ` -d '${typeof data === 'string' ? data : JSON.stringify(data)}'`;
|
|
41
|
+
}
|
|
42
|
+
console.log(`[Explain] ${command}`);
|
|
43
|
+
}
|
package/src/client.js
CHANGED
|
@@ -8,7 +8,7 @@ export default class MisoClient {
|
|
|
8
8
|
|
|
9
9
|
constructor(options = {}) {
|
|
10
10
|
this._options = options = normalizeOptions(options);
|
|
11
|
-
this._axios = createAxios(options.axios); // TODO: pass onRetry() for debug message
|
|
11
|
+
this._axios = createAxios(options.axios, options.debug); // TODO: pass onRetry() for debug message
|
|
12
12
|
this.version = version;
|
|
13
13
|
this.api = new Api(this);
|
|
14
14
|
}
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export default '0.6.5-beta.
|
|
1
|
+
export default '0.6.5-beta.8';
|