@miso.ai/client-sdk-core 1.8.0-beta.9 → 1.8.1-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/api.js +25 -0
- package/dist/cjs/api/ask.js +11 -6
- package/dist/cjs/api/constants.js +28 -0
- package/dist/cjs/api/helpers.js +2 -2
- package/dist/cjs/api/index.js +54 -19
- package/dist/cjs/api/interactions.js +5 -4
- package/dist/cjs/api/recommendation.js +9 -8
- package/dist/cjs/api/search.js +6 -5
- package/dist/cjs/classes.js +5 -15
- package/dist/cjs/client.js +2 -2
- package/dist/cjs/constants.js +2 -2
- package/dist/cjs/index.js +39 -5
- package/dist/cjs/plugin/auto-events.js +3 -2
- package/dist/cjs/plugin/index.js +3 -3
- package/dist/cjs/plugin/plugin-root.js +13 -4
- package/dist/cjs/root.js +3 -2
- package/dist/cjs/version.js +1 -1
- package/package.json +9 -9
- package/{dist/es/api/index.js → src/api/api.js} +9 -6
- package/src/api/ask.js +80 -0
- package/src/api/base.js +47 -0
- package/src/api/constants.js +21 -0
- package/{dist/es → src}/api/helpers.js +48 -92
- package/src/api/index.js +8 -0
- package/src/api/interactions.js +55 -0
- package/src/api/recommendation.js +34 -0
- package/src/api/search.js +22 -0
- package/src/classes.js +7 -0
- package/{dist/es → src}/client.js +25 -10
- package/{dist/es → src}/cmd.js +7 -8
- package/src/constants.js +4 -0
- package/{dist/es → src}/context.js +4 -1
- package/src/index.js +4 -0
- package/{dist/es → src}/plugin/anonymous.js +5 -4
- package/{dist/es → src}/plugin/auto-events.js +27 -27
- package/src/plugin/index.js +3 -0
- package/{dist/es → src}/plugin/page-info.js +28 -24
- package/{dist/es → src}/plugin/plugin-root.js +48 -23
- package/{dist/es → src}/plugin/urls.js +2 -1
- package/{dist/es → src}/plugin/user.js +32 -37
- package/{dist/es → src}/root.js +11 -4
- package/src/utils.js +1 -0
- package/src/version.js +1 -0
- package/dist/es/api/ask.js +0 -85
- package/dist/es/api/base.js +0 -96
- package/dist/es/api/interactions.js +0 -82
- package/dist/es/api/recommendation.js +0 -24
- package/dist/es/api/search.js +0 -15
- package/dist/es/classes.js +0 -20
- package/dist/es/constants.js +0 -4
- package/dist/es/index.js +0 -2
- package/dist/es/plugin/index.js +0 -3
- package/dist/es/utils.js +0 -1
- package/dist/es/version.js +0 -1
package/dist/es/api/base.js
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
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; }
|
|
3
|
-
import { Component } from '@miso.ai/commons';
|
|
4
|
-
export default class ApiBase extends Component {
|
|
5
|
-
// TODO: use private fields (may encounter issues with rollup)
|
|
6
|
-
|
|
7
|
-
constructor(api, apiPath) {
|
|
8
|
-
super(apiPath, api);
|
|
9
|
-
this._apiPath = apiPath;
|
|
10
|
-
this.helpers = api.helpers;
|
|
11
|
-
this.clientOptions = api._client.options;
|
|
12
|
-
this.context = api._client.context;
|
|
13
|
-
}
|
|
14
|
-
async _run(apiName, payload) {
|
|
15
|
-
let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
16
|
-
const {
|
|
17
|
-
bulk
|
|
18
|
-
} = options;
|
|
19
|
-
const bulkInfo = bulk ? {
|
|
20
|
-
bulk: this.helpers.bulkInfo
|
|
21
|
-
} : undefined;
|
|
22
|
-
const apiGroup = this._apiPath;
|
|
23
|
-
const url = this._url({
|
|
24
|
-
apiGroup,
|
|
25
|
-
apiName,
|
|
26
|
-
payload,
|
|
27
|
-
options
|
|
28
|
-
});
|
|
29
|
-
payload = this._preprocess({
|
|
30
|
-
apiGroup,
|
|
31
|
-
apiName,
|
|
32
|
-
payload,
|
|
33
|
-
options
|
|
34
|
-
});
|
|
35
|
-
const requestData = {
|
|
36
|
-
apiGroup,
|
|
37
|
-
apiName,
|
|
38
|
-
payload,
|
|
39
|
-
url,
|
|
40
|
-
options
|
|
41
|
-
};
|
|
42
|
-
this._events.emit('request', Object.assign({}, requestData, bulkInfo));
|
|
43
|
-
const response = await this._send(requestData);
|
|
44
|
-
const responseData = Object.assign({}, requestData, {
|
|
45
|
-
response
|
|
46
|
-
});
|
|
47
|
-
this._events.emit('response', Object.assign({}, responseData, bulkInfo));
|
|
48
|
-
return this._postprocess(responseData);
|
|
49
|
-
}
|
|
50
|
-
_preprocess(_ref) {
|
|
51
|
-
let {
|
|
52
|
-
apiGroup,
|
|
53
|
-
apiName,
|
|
54
|
-
payload
|
|
55
|
-
} = _ref;
|
|
56
|
-
return this.helpers.applyPayloadPasses(this, {
|
|
57
|
-
apiGroup,
|
|
58
|
-
apiName,
|
|
59
|
-
payload
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
_url(_ref2) {
|
|
63
|
-
let {
|
|
64
|
-
apiGroup,
|
|
65
|
-
apiName,
|
|
66
|
-
options
|
|
67
|
-
} = _ref2;
|
|
68
|
-
const url = this.helpers.url([apiGroup, apiName], options);
|
|
69
|
-
return this.helpers.applyUrlPasses(this, {
|
|
70
|
-
apiGroup,
|
|
71
|
-
apiName,
|
|
72
|
-
url,
|
|
73
|
-
options
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
async _send(_ref3) {
|
|
77
|
-
let {
|
|
78
|
-
apiGroup,
|
|
79
|
-
apiName,
|
|
80
|
-
url,
|
|
81
|
-
payload,
|
|
82
|
-
options: {
|
|
83
|
-
bulk
|
|
84
|
-
} = {}
|
|
85
|
-
} = _ref3,
|
|
86
|
-
options = _objectWithoutPropertiesLoose(_ref3.options, _excluded);
|
|
87
|
-
return bulk ? this.helpers.fetchForBulk(apiGroup, apiName, payload) : this.helpers.fetch(url, payload, options);
|
|
88
|
-
}
|
|
89
|
-
_postprocess(_ref4) {
|
|
90
|
-
let {
|
|
91
|
-
response
|
|
92
|
-
} = _ref4;
|
|
93
|
-
// TODO: we can introduce response passes
|
|
94
|
-
return response.data;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
const _excluded = ["useBeacon"],
|
|
2
|
-
_excluded2 = ["options"];
|
|
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 ApiBase from './base';
|
|
5
|
-
export default class Interactions extends ApiBase {
|
|
6
|
-
constructor(api) {
|
|
7
|
-
super(api, 'interactions');
|
|
8
|
-
}
|
|
9
|
-
async upload(payload, options) {
|
|
10
|
-
try {
|
|
11
|
-
return await this._run('upload', payload, options);
|
|
12
|
-
} catch (e) {
|
|
13
|
-
if (e.status === 400 && e.message && e.message.toLowerCase().indexOf('playground') > -1) {
|
|
14
|
-
this._warn(`Ignore interactions uploaded to playground app.`);
|
|
15
|
-
} else {
|
|
16
|
-
throw e;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
_url(_ref) {
|
|
21
|
-
let {
|
|
22
|
-
apiGroup,
|
|
23
|
-
apiName,
|
|
24
|
-
options
|
|
25
|
-
} = _ref;
|
|
26
|
-
const url = this.helpers.url([this._apiPath], options);
|
|
27
|
-
return this.helpers.applyUrlPasses(this, {
|
|
28
|
-
apiGroup,
|
|
29
|
-
apiName,
|
|
30
|
-
url,
|
|
31
|
-
options
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
_preprocess(_ref2) {
|
|
35
|
-
let {
|
|
36
|
-
apiGroup,
|
|
37
|
-
apiName,
|
|
38
|
-
payload
|
|
39
|
-
} = _ref2;
|
|
40
|
-
if (apiName === 'upload') {
|
|
41
|
-
payload = this._normalizeUploadPayload(payload);
|
|
42
|
-
}
|
|
43
|
-
return super._preprocess({
|
|
44
|
-
apiGroup,
|
|
45
|
-
apiName,
|
|
46
|
-
payload
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
_normalizeUploadPayload(payload) {
|
|
50
|
-
// TODO: accept string as a shortcut of { type: payload } as well
|
|
51
|
-
if (typeof payload !== 'object') {
|
|
52
|
-
throw new Error(`Interactions payload has to be either an object or an array of objects: ${payload}`);
|
|
53
|
-
}
|
|
54
|
-
if (!Array.isArray(payload)) {
|
|
55
|
-
payload = [payload];
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
data: payload
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
async _send(_ref3) {
|
|
62
|
-
let {
|
|
63
|
-
options: {
|
|
64
|
-
useBeacon = true
|
|
65
|
-
} = {}
|
|
66
|
-
} = _ref3,
|
|
67
|
-
options = _objectWithoutPropertiesLoose(_ref3.options, _excluded),
|
|
68
|
-
args = _objectWithoutPropertiesLoose(_ref3, _excluded2);
|
|
69
|
-
if (useBeacon) {
|
|
70
|
-
const {
|
|
71
|
-
url,
|
|
72
|
-
payload
|
|
73
|
-
} = args;
|
|
74
|
-
this.helpers.sendBeacon(url, payload, options);
|
|
75
|
-
return {};
|
|
76
|
-
} else {
|
|
77
|
-
return super._send(Object.assign({}, args, {
|
|
78
|
-
options
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import ApiBase from './base';
|
|
2
|
-
export default class Recommendation extends ApiBase {
|
|
3
|
-
constructor(api) {
|
|
4
|
-
super(api, 'recommendation');
|
|
5
|
-
}
|
|
6
|
-
async userToProducts(payload, options) {
|
|
7
|
-
return this._run('user_to_products', payload, options);
|
|
8
|
-
}
|
|
9
|
-
async userToCategories(payload, options) {
|
|
10
|
-
return this._run('user_to_categories', payload, options);
|
|
11
|
-
}
|
|
12
|
-
async userToAttributes(payload, options) {
|
|
13
|
-
return this._run('user_to_attributes', payload, options);
|
|
14
|
-
}
|
|
15
|
-
async userToTrending(payload, options) {
|
|
16
|
-
return this._run('user_to_trending', payload, options);
|
|
17
|
-
}
|
|
18
|
-
async userToHistory(payload, options) {
|
|
19
|
-
return this._run('user_to_history', payload, options);
|
|
20
|
-
}
|
|
21
|
-
async productToProducts(payload, options) {
|
|
22
|
-
return this._run('product_to_products', payload, options);
|
|
23
|
-
}
|
|
24
|
-
}
|
package/dist/es/api/search.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import ApiBase from './base';
|
|
2
|
-
export default class Search extends ApiBase {
|
|
3
|
-
constructor(api) {
|
|
4
|
-
super(api, 'search');
|
|
5
|
-
}
|
|
6
|
-
async search(payload, options) {
|
|
7
|
-
return this._run('search', payload, options);
|
|
8
|
-
}
|
|
9
|
-
async autocomplete(payload, options) {
|
|
10
|
-
return this._run('autocomplete', payload, options);
|
|
11
|
-
}
|
|
12
|
-
async multipleGet(payload, options) {
|
|
13
|
-
return this._run('mget', payload, options);
|
|
14
|
-
}
|
|
15
|
-
}
|
package/dist/es/classes.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import Api from './api';
|
|
2
|
-
import ApiBase from './api/base';
|
|
3
|
-
import ApiHelpers from './api/helpers';
|
|
4
|
-
import Interactions from './api/interactions';
|
|
5
|
-
import Recommendation from './api/recommendation';
|
|
6
|
-
import Search from './api/search';
|
|
7
|
-
import Context from './context';
|
|
8
|
-
export default {
|
|
9
|
-
api: {
|
|
10
|
-
Api,
|
|
11
|
-
ApiBase,
|
|
12
|
-
ApiHelpers,
|
|
13
|
-
Interactions,
|
|
14
|
-
Recommendation,
|
|
15
|
-
Search
|
|
16
|
-
},
|
|
17
|
-
context: {
|
|
18
|
-
Context
|
|
19
|
-
}
|
|
20
|
-
};
|
package/dist/es/constants.js
DELETED
package/dist/es/index.js
DELETED
package/dist/es/plugin/index.js
DELETED
package/dist/es/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { viewable } from '@miso.ai/commons';
|
package/dist/es/version.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default '1.8.0-beta.9';
|