@miso.ai/client-sdk-dev-tool 1.4.7-beta.0 → 1.5.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.
@@ -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/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/es/index.js",
4
+ "main": "dist/cjs/index.js",
5
5
  "module": "dist/es/index.js",
6
6
  "files": [
7
7
  "dist/*"
@@ -14,7 +14,7 @@
14
14
  "build:clean": "npx rimraf dist",
15
15
  "build:esm": "npx babel src --root-mode upward --out-dir dist/es",
16
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"
17
+ "build": "npm run build:clean && npm run build:esm && npm run build:cjs"
18
18
  },
19
19
  "repository": "MisoAI/miso-client-js-sdk",
20
20
  "homepage": "https://misoai.github.io/miso-client-js-sdk",
@@ -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.4.7-beta.0"
29
+ "@miso.ai/commons": "1.5.0-beta.2"
30
30
  },
31
- "version": "1.4.7-beta.0"
31
+ "version": "1.5.0-beta.2"
32
32
  }