@miso.ai/client-sdk-dev-tool 1.4.6-beta.0 → 1.5.0-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/dist/cjs/debug.js +168 -0
- package/dist/cjs/dry-run.js +43 -0
- package/dist/cjs/index.js +23 -0
- package/dist/es/debug.js +17 -13
- package/package.json +5 -4
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
const _excluded = ["groupName", "apiName", "url", "bulk"];
|
|
8
|
+
|
|
9
|
+
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; }
|
|
10
|
+
|
|
11
|
+
const TAG = '%cMiso';
|
|
12
|
+
const STYLE = 'color: #fff; background-color: #334cbb; padding: 2px 2px 1px 4px;';
|
|
13
|
+
const ID = 'std:debug';
|
|
14
|
+
|
|
15
|
+
const _log = function (path, name) {
|
|
16
|
+
for (var _len = arguments.length, data = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
17
|
+
data[_key - 2] = arguments[_key];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return console.log(TAG, STYLE, _path(path), _name(name), ...data);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function _logw(path, name, data) {
|
|
24
|
+
if (data === undefined) {
|
|
25
|
+
_log(path, name);
|
|
26
|
+
} else if (Array.isArray(data)) {
|
|
27
|
+
_log(path, name, ...data.map(_wrapObj));
|
|
28
|
+
} else {
|
|
29
|
+
_log(path, name, _wrapObj(data));
|
|
30
|
+
}
|
|
31
|
+
} // format path
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
function _path(path) {
|
|
35
|
+
return `<${typeof path === 'string' ? path : path.filter(v => v).join('/')}>`;
|
|
36
|
+
} // format event name
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
function _name(name) {
|
|
40
|
+
return `[${name}]`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function _wrapObj(value) {
|
|
44
|
+
const type = typeof value;
|
|
45
|
+
return type === 'function' || type === 'object' && !Array.isArray(value) ? [value] : value;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class DebugPlugin {
|
|
49
|
+
constructor() {
|
|
50
|
+
this._log = console.log.bind(console, TAG, STYLE);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static get id() {
|
|
54
|
+
return ID;
|
|
55
|
+
} // TODO: config({ active })
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
install(MisoClient) {
|
|
59
|
+
this._injectComponents(MisoClient);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
_injectComponents(component) {
|
|
63
|
+
let treePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
64
|
+
component.on('child', c => this._injectComponents(c, treePath));
|
|
65
|
+
component.on('subtree', c => this._injectComponents(c, treePath.concat(component.meta.path)));
|
|
66
|
+
component.on('*', (data, meta) => this._handleEvent(component, meta, data, treePath));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
_handleEvent(component, _ref, data) {
|
|
70
|
+
let {
|
|
71
|
+
name
|
|
72
|
+
} = _ref;
|
|
73
|
+
let treePath = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
74
|
+
|
|
75
|
+
if (name === 'child' || name === 'subtree') {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const path = treePath.concat(component.meta.path);
|
|
80
|
+
|
|
81
|
+
if (!path.length) {
|
|
82
|
+
switch (name) {
|
|
83
|
+
case 'create':
|
|
84
|
+
this._handleCreateClient(name, data);
|
|
85
|
+
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
switch (path[0]) {
|
|
91
|
+
case 'client':
|
|
92
|
+
switch (path[1]) {
|
|
93
|
+
case 'api':
|
|
94
|
+
this._handleApiEvent(name, Object.assign({}, data, {
|
|
95
|
+
groupName: path[2]
|
|
96
|
+
}));
|
|
97
|
+
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
break;
|
|
102
|
+
|
|
103
|
+
case 'plugins':
|
|
104
|
+
if (path.length === 1) {
|
|
105
|
+
this._handlePluginsEvent(name, data);
|
|
106
|
+
} else {
|
|
107
|
+
this._handlePluginSpecificEvent(path[1], path.slice(2), name, data);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
_logw(path.join('.'), name, data);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
_handleCreateClient(eventName, data) {
|
|
117
|
+
_logw('client', eventName, data);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
_handleApiEvent(eventName, _ref2) {
|
|
121
|
+
let {
|
|
122
|
+
groupName,
|
|
123
|
+
url,
|
|
124
|
+
bulk
|
|
125
|
+
} = _ref2,
|
|
126
|
+
data = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
127
|
+
|
|
128
|
+
const pathname = new URL(url).pathname;
|
|
129
|
+
const args = ['api', eventName];
|
|
130
|
+
bulk && args.push(`(bulk ${bulk.bulkId})`);
|
|
131
|
+
args.push(`POST ${pathname}`);
|
|
132
|
+
|
|
133
|
+
if (groupName === 'interactions') {
|
|
134
|
+
// TODO: handle multiple interactions
|
|
135
|
+
const {
|
|
136
|
+
type
|
|
137
|
+
} = data.payload.data[0];
|
|
138
|
+
args.push(type);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
args.push([Object.assign({}, data, {
|
|
142
|
+
url
|
|
143
|
+
})]);
|
|
144
|
+
|
|
145
|
+
_log.apply(undefined, args);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
_handlePluginsEvent(eventName, plugin) {
|
|
149
|
+
_log('plugins', eventName, `${plugin.id || '(anonymous)'}`, [plugin]);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
_handlePluginSpecificEvent(pluginId, path, name, data) {
|
|
153
|
+
_logw([pluginId, path.join('.')], name, data);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
_getPath(component) {
|
|
157
|
+
const path = [];
|
|
158
|
+
|
|
159
|
+
for (let c = component; c; c = c.meta.parent) {
|
|
160
|
+
c.meta.name && path.push(c.meta.name);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return path.reverse();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
exports.default = DebugPlugin;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _commons = require("@miso.ai/commons");
|
|
9
|
+
|
|
10
|
+
const ID = 'std:dry-run';
|
|
11
|
+
|
|
12
|
+
class DryRunPlugin {
|
|
13
|
+
constructor() {
|
|
14
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
15
|
+
this._options = options;
|
|
16
|
+
this.id = 'std:dry-run';
|
|
17
|
+
this.name = 'dry-run';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static get id() {
|
|
21
|
+
return ID;
|
|
22
|
+
} // TODO: config({ active })
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
install(_, _ref) {
|
|
26
|
+
let {
|
|
27
|
+
addUrlPass
|
|
28
|
+
} = _ref;
|
|
29
|
+
addUrlPass(this._modifyUrl.bind(this));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_modifyUrl(_ref2) {
|
|
33
|
+
let {
|
|
34
|
+
apiGroup,
|
|
35
|
+
apiName,
|
|
36
|
+
url
|
|
37
|
+
} = _ref2;
|
|
38
|
+
return apiGroup === 'interactions' && apiName === 'upload' ? (0, _commons.addUrlParameter)(url, 'dry_run', '1') : url;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.default = DryRunPlugin;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "DebugPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _debug.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "DryRunPlugin", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _dryRun.default;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
var _debug = _interopRequireDefault(require("./debug"));
|
|
20
|
+
|
|
21
|
+
var _dryRun = _interopRequireDefault(require("./dry-run"));
|
|
22
|
+
|
|
23
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/dist/es/debug.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
const _excluded = ["groupName", "apiName", "url", "bulk"];
|
|
2
|
+
|
|
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
|
+
|
|
1
5
|
const TAG = '%cMiso';
|
|
2
6
|
const STYLE = 'color: #fff; background-color: #334cbb; padding: 2px 2px 1px 4px;';
|
|
3
7
|
const ID = 'std:debug';
|
|
@@ -22,12 +26,12 @@ function _logw(path, name, data) {
|
|
|
22
26
|
|
|
23
27
|
|
|
24
28
|
function _path(path) {
|
|
25
|
-
return
|
|
29
|
+
return `<${typeof path === 'string' ? path : path.filter(v => v).join('/')}>`;
|
|
26
30
|
} // format event name
|
|
27
31
|
|
|
28
32
|
|
|
29
33
|
function _name(name) {
|
|
30
|
-
return
|
|
34
|
+
return `[${name}]`;
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
function _wrapObj(value) {
|
|
@@ -81,9 +85,9 @@ export default class DebugPlugin {
|
|
|
81
85
|
case 'client':
|
|
82
86
|
switch (path[1]) {
|
|
83
87
|
case 'api':
|
|
84
|
-
this._handleApiEvent(name, {
|
|
88
|
+
this._handleApiEvent(name, Object.assign({}, data, {
|
|
85
89
|
groupName: path[2]
|
|
86
|
-
});
|
|
90
|
+
}));
|
|
87
91
|
|
|
88
92
|
return;
|
|
89
93
|
}
|
|
@@ -110,15 +114,15 @@ export default class DebugPlugin {
|
|
|
110
114
|
_handleApiEvent(eventName, _ref2) {
|
|
111
115
|
let {
|
|
112
116
|
groupName,
|
|
113
|
-
apiName,
|
|
114
117
|
url,
|
|
115
|
-
bulk
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
bulk
|
|
119
|
+
} = _ref2,
|
|
120
|
+
data = _objectWithoutPropertiesLoose(_ref2, _excluded);
|
|
121
|
+
|
|
118
122
|
const pathname = new URL(url).pathname;
|
|
119
123
|
const args = ['api', eventName];
|
|
120
|
-
bulk && args.push(
|
|
121
|
-
args.push(
|
|
124
|
+
bulk && args.push(`(bulk ${bulk.bulkId})`);
|
|
125
|
+
args.push(`POST ${pathname}`);
|
|
122
126
|
|
|
123
127
|
if (groupName === 'interactions') {
|
|
124
128
|
// TODO: handle multiple interactions
|
|
@@ -128,15 +132,15 @@ export default class DebugPlugin {
|
|
|
128
132
|
args.push(type);
|
|
129
133
|
}
|
|
130
134
|
|
|
131
|
-
args.push([{
|
|
135
|
+
args.push([Object.assign({}, data, {
|
|
132
136
|
url
|
|
133
|
-
}]);
|
|
137
|
+
})]);
|
|
134
138
|
|
|
135
139
|
_log.apply(undefined, args);
|
|
136
140
|
}
|
|
137
141
|
|
|
138
142
|
_handlePluginsEvent(eventName, plugin) {
|
|
139
|
-
_log('plugins', eventName,
|
|
143
|
+
_log('plugins', eventName, `${plugin.id || '(anonymous)'}`, [plugin]);
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
_handlePluginSpecificEvent(pluginId, path, name, data) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@miso.ai/client-sdk-dev-tool",
|
|
3
3
|
"description": "Dev tool plugins for Miso JavaScript client SDK.",
|
|
4
|
-
"main": "dist/
|
|
4
|
+
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/es/index.js",
|
|
6
6
|
"files": [
|
|
7
7
|
"dist/*"
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
"start": "npx babel src --root-mode upward --out-dir dist/es --watch",
|
|
14
14
|
"build:clean": "npx rimraf dist",
|
|
15
15
|
"build:esm": "npx babel src --root-mode upward --out-dir dist/es",
|
|
16
|
-
"build": "
|
|
16
|
+
"build:cjs": "BABEL_ENV=cjs npx babel src --root-mode upward --out-dir dist/cjs",
|
|
17
|
+
"build": "npm run build:clean && npm run build:esm && npm run build:cjs"
|
|
17
18
|
},
|
|
18
19
|
"repository": "MisoAI/miso-client-js-sdk",
|
|
19
20
|
"homepage": "https://misoai.github.io/miso-client-js-sdk",
|
|
@@ -25,7 +26,7 @@
|
|
|
25
26
|
"url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
|
|
26
27
|
},
|
|
27
28
|
"dependencies": {
|
|
28
|
-
"@miso.ai/commons": "1.
|
|
29
|
+
"@miso.ai/commons": "1.5.0-beta.1"
|
|
29
30
|
},
|
|
30
|
-
"version": "1.
|
|
31
|
+
"version": "1.5.0-beta.1"
|
|
31
32
|
}
|