@miso.ai/client-sdk-dev-tool 1.13.2-beta.1 → 1.14.0-beta.2
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/debug.js +6 -1
- package/dist/cjs/dry-run.js +23 -1
- package/dist/cjs/lorem.js +18 -3
- package/package.json +6 -6
- package/src/debug.js +3 -1
- package/src/dry-run.js +16 -2
- package/src/lorem.js +15 -2
package/dist/cjs/debug.js
CHANGED
|
@@ -80,7 +80,12 @@ class DebugPlugin {
|
|
|
80
80
|
const pathname = new URL(url).pathname;
|
|
81
81
|
const args = ['api', eventName];
|
|
82
82
|
bulk && args.push(`(bulk ${bulk.bulkId})`);
|
|
83
|
-
|
|
83
|
+
|
|
84
|
+
// the api helpers' fetch defaults to POST when no method is specified
|
|
85
|
+
const {
|
|
86
|
+
method = 'POST'
|
|
87
|
+
} = data.options || {};
|
|
88
|
+
args.push(`${method} ${pathname}`);
|
|
84
89
|
if (groupName === 'interactions') {
|
|
85
90
|
// TODO: handle multiple interactions
|
|
86
91
|
const record = data.payload.data[0];
|
package/dist/cjs/dry-run.js
CHANGED
|
@@ -5,6 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _commons = require("@miso.ai/commons");
|
|
8
|
+
const {
|
|
9
|
+
GROUP,
|
|
10
|
+
NAME
|
|
11
|
+
} = _commons.API;
|
|
8
12
|
const ID = 'std:dry-run';
|
|
9
13
|
class DryRunPlugin {
|
|
10
14
|
constructor(options = {}) {
|
|
@@ -19,9 +23,11 @@ class DryRunPlugin {
|
|
|
19
23
|
// TODO: config({ active })
|
|
20
24
|
|
|
21
25
|
install(_, {
|
|
22
|
-
addUrlPass
|
|
26
|
+
addUrlPass,
|
|
27
|
+
addPayloadPass
|
|
23
28
|
}) {
|
|
24
29
|
addUrlPass(this._modifyUrl.bind(this));
|
|
30
|
+
addPayloadPass(this._modifyPayload.bind(this));
|
|
25
31
|
}
|
|
26
32
|
_modifyUrl({
|
|
27
33
|
apiGroup,
|
|
@@ -30,5 +36,21 @@ class DryRunPlugin {
|
|
|
30
36
|
}) {
|
|
31
37
|
return apiGroup === 'interactions' && apiName === 'upload' ? (0, _commons.addUrlParameter)(url, 'dry_run', '1') : url;
|
|
32
38
|
}
|
|
39
|
+
_modifyPayload({
|
|
40
|
+
apiGroup,
|
|
41
|
+
apiName,
|
|
42
|
+
payload
|
|
43
|
+
}) {
|
|
44
|
+
if (!payload) {
|
|
45
|
+
return payload; // the GET request
|
|
46
|
+
}
|
|
47
|
+
// questions (ask) and search (hybrid search) only, for now
|
|
48
|
+
if (apiGroup === GROUP.ASK && (apiName === NAME.QUESTIONS || apiName === NAME.SEARCH)) {
|
|
49
|
+
return Object.assign({}, payload, {
|
|
50
|
+
with_request_history: false
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return payload;
|
|
54
|
+
}
|
|
33
55
|
}
|
|
34
56
|
exports.default = DryRunPlugin;
|
package/dist/cjs/lorem.js
CHANGED
|
@@ -8,7 +8,8 @@ var _commons = require("@miso.ai/commons");
|
|
|
8
8
|
var _lorem = require("@miso.ai/lorem");
|
|
9
9
|
var _api = _interopRequireDefault(require("@miso.ai/doggoganger/src/api.js"));
|
|
10
10
|
var _fetch = _interopRequireDefault(require("@miso.ai/doggoganger/src/fetch.js"));
|
|
11
|
-
|
|
11
|
+
var _utils = require("@miso.ai/doggoganger/src/utils.js");
|
|
12
|
+
const _excluded = ["seed", "latency"];
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
14
15
|
const PLUGIN_ID = 'std:lorem';
|
|
@@ -20,14 +21,22 @@ class LoremPlugin {
|
|
|
20
21
|
this._lorem = (0, _lorem.lorem)();
|
|
21
22
|
this._api = (0, _api.default)();
|
|
22
23
|
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* `latency` adds a mock request latency to every api call, in the manner
|
|
27
|
+
* of the doggoganger server's latency middleware: a number of milliseconds
|
|
28
|
+
* (e.g. 500), or `{ min, max }` for a randomized roll.
|
|
29
|
+
*/
|
|
23
30
|
config(_ref = {}) {
|
|
24
31
|
let {
|
|
25
|
-
seed
|
|
32
|
+
seed,
|
|
33
|
+
latency
|
|
26
34
|
} = _ref,
|
|
27
35
|
options = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
28
36
|
this._lorem = (0, _lorem.lorem)({
|
|
29
37
|
seed
|
|
30
38
|
});
|
|
39
|
+
this._latency = latency;
|
|
31
40
|
this._api = (0, _api.default)(options);
|
|
32
41
|
}
|
|
33
42
|
get api() {
|
|
@@ -56,8 +65,14 @@ class LoremPlugin {
|
|
|
56
65
|
}));
|
|
57
66
|
};
|
|
58
67
|
}
|
|
59
|
-
_fetch(url, options) {
|
|
68
|
+
async _fetch(url, options) {
|
|
69
|
+
// the seed is captured before the delay, so the generated content stays
|
|
70
|
+
// tied to the request order, not the completion order
|
|
60
71
|
const seed = this._lorem.prng.seed();
|
|
72
|
+
const latency = this._latency;
|
|
73
|
+
if (latency) {
|
|
74
|
+
await (0, _utils.delay)(typeof latency === 'number' ? latency : (0, _utils.rollLatency)(latency.min || 0, latency.max || 0));
|
|
75
|
+
}
|
|
61
76
|
return (0, _fetch.default)(this._api, url, Object.assign({
|
|
62
77
|
seed
|
|
63
78
|
}, options));
|
package/package.json
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
"access": "public"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
-
"build:clean": "
|
|
16
|
-
"build:cjs": "BABEL_ENV=cjs
|
|
15
|
+
"build:clean": "rimraf dist",
|
|
16
|
+
"build:cjs": "BABEL_ENV=cjs babel src --root-mode upward --out-dir dist/cjs",
|
|
17
17
|
"build": "npm run build:clean && npm run build:cjs"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@miso.ai/commons": "1.
|
|
34
|
-
"@miso.ai/doggoganger": "^0.10.0-beta.
|
|
35
|
-
"@miso.ai/lorem": "^0.10.0-beta.
|
|
33
|
+
"@miso.ai/commons": "1.14.0-beta.2",
|
|
34
|
+
"@miso.ai/doggoganger": "^0.10.0-beta.16",
|
|
35
|
+
"@miso.ai/lorem": "^0.10.0-beta.16"
|
|
36
36
|
},
|
|
37
|
-
"version": "1.
|
|
37
|
+
"version": "1.14.0-beta.2"
|
|
38
38
|
}
|
package/src/debug.js
CHANGED
|
@@ -77,7 +77,9 @@ export default class DebugPlugin {
|
|
|
77
77
|
|
|
78
78
|
bulk && args.push(`(bulk ${bulk.bulkId})`);
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
// the api helpers' fetch defaults to POST when no method is specified
|
|
81
|
+
const { method = 'POST' } = data.options || {};
|
|
82
|
+
args.push(`${method} ${pathname}`);
|
|
81
83
|
|
|
82
84
|
if (groupName === 'interactions') {
|
|
83
85
|
// TODO: handle multiple interactions
|
package/src/dry-run.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { addUrlParameter } from '@miso.ai/commons';
|
|
1
|
+
import { API, addUrlParameter } from '@miso.ai/commons';
|
|
2
|
+
|
|
3
|
+
const { GROUP, NAME } = API;
|
|
2
4
|
|
|
3
5
|
const ID = 'std:dry-run';
|
|
4
6
|
|
|
@@ -16,12 +18,24 @@ export default class DryRunPlugin {
|
|
|
16
18
|
|
|
17
19
|
// TODO: config({ active })
|
|
18
20
|
|
|
19
|
-
install(_, { addUrlPass }) {
|
|
21
|
+
install(_, { addUrlPass, addPayloadPass }) {
|
|
20
22
|
addUrlPass(this._modifyUrl.bind(this));
|
|
23
|
+
addPayloadPass(this._modifyPayload.bind(this));
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
_modifyUrl({ apiGroup, apiName, url }) {
|
|
24
27
|
return apiGroup === 'interactions' && apiName === 'upload' ? addUrlParameter(url, 'dry_run', '1') : url;
|
|
25
28
|
}
|
|
26
29
|
|
|
30
|
+
_modifyPayload({ apiGroup, apiName, payload }) {
|
|
31
|
+
if (!payload) {
|
|
32
|
+
return payload; // the GET request
|
|
33
|
+
}
|
|
34
|
+
// questions (ask) and search (hybrid search) only, for now
|
|
35
|
+
if (apiGroup === GROUP.ASK && (apiName === NAME.QUESTIONS || apiName === NAME.SEARCH)) {
|
|
36
|
+
return { ...payload, with_request_history: false };
|
|
37
|
+
}
|
|
38
|
+
return payload;
|
|
39
|
+
}
|
|
40
|
+
|
|
27
41
|
}
|
package/src/lorem.js
CHANGED
|
@@ -2,6 +2,7 @@ import { isInBrowser } from '@miso.ai/commons';
|
|
|
2
2
|
import { lorem } from '@miso.ai/lorem';
|
|
3
3
|
import buildApi from '@miso.ai/doggoganger/src/api.js';
|
|
4
4
|
import fetch from '@miso.ai/doggoganger/src/fetch.js';
|
|
5
|
+
import { delay, rollLatency } from '@miso.ai/doggoganger/src/utils.js';
|
|
5
6
|
|
|
6
7
|
const PLUGIN_ID = 'std:lorem';
|
|
7
8
|
|
|
@@ -16,8 +17,14 @@ export default class LoremPlugin {
|
|
|
16
17
|
this._api = buildApi();
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
/**
|
|
21
|
+
* `latency` adds a mock request latency to every api call, in the manner
|
|
22
|
+
* of the doggoganger server's latency middleware: a number of milliseconds
|
|
23
|
+
* (e.g. 500), or `{ min, max }` for a randomized roll.
|
|
24
|
+
*/
|
|
25
|
+
config({ seed, latency, ...options } = {}) {
|
|
20
26
|
this._lorem = lorem({ seed });
|
|
27
|
+
this._latency = latency;
|
|
21
28
|
this._api = buildApi(options);
|
|
22
29
|
}
|
|
23
30
|
|
|
@@ -45,8 +52,14 @@ export default class LoremPlugin {
|
|
|
45
52
|
};
|
|
46
53
|
}
|
|
47
54
|
|
|
48
|
-
_fetch(url, options) {
|
|
55
|
+
async _fetch(url, options) {
|
|
56
|
+
// the seed is captured before the delay, so the generated content stays
|
|
57
|
+
// tied to the request order, not the completion order
|
|
49
58
|
const seed = this._lorem.prng.seed();
|
|
59
|
+
const latency = this._latency;
|
|
60
|
+
if (latency) {
|
|
61
|
+
await delay(typeof latency === 'number' ? latency : rollLatency(latency.min || 0, latency.max || 0));
|
|
62
|
+
}
|
|
50
63
|
return fetch(this._api, url, { seed, ...options });
|
|
51
64
|
}
|
|
52
65
|
|