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