@miso.ai/client-sdk-core 1.7.6 → 1.8.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.
@@ -13,6 +13,17 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
13
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
  class MisoClient extends _commons.Component {
16
+ static attach() {
17
+ (window.MisoClients || (window.MisoClients = [])).push(MisoClient);
18
+ if (window.MisoClient) {
19
+ if (window.MisoClient !== MisoClient) {
20
+ // TODO: check version as well
21
+ console.warn(`Use already defined window.MisoClient (${window.MisoClient.version}).`);
22
+ }
23
+ return;
24
+ }
25
+ window.MisoClient = MisoClient;
26
+ }
16
27
  constructor(options) {
17
28
  super('client', _root.root);
18
29
  this._config(options);
@@ -54,5 +65,8 @@ class MisoClient extends _commons.Component {
54
65
  }
55
66
  }
56
67
  MisoClient.helpers = helpers;
57
- var _default = MisoClient;
68
+ (0, _commons.defineValues)(MisoClient, {
69
+ uuid: (0, _commons.uuidv4)()
70
+ });
71
+ var _default = (0, _root.init)(MisoClient);
58
72
  exports.default = _default;
package/dist/cjs/index.js CHANGED
@@ -5,21 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _client = _interopRequireDefault(require("./client"));
8
- var _root = require("./root");
9
- var _cmd = _interopRequireDefault(require("./cmd"));
10
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- if (!window.MisoClient) {
12
- // gaurantee to execute init() only once globally (across different script sources)
13
- window.MisoClient = (0, _root.init)(_client.default);
14
-
15
- // kick off misodev execution
16
- (0, _cmd.default)('misodev');
17
-
18
- // do misocmd with setTimeout, so they will be executed after plugins are installed.
19
- setTimeout(() => (0, _cmd.default)('misocmd'));
20
- } else {
21
- // TODO: check version as well
22
- console.warn(`Use already defined window.MisoClient (${window.MisoClient.version}).`);
23
- }
24
- var _default = window.MisoClient;
9
+ var _default = _client.default;
25
10
  exports.default = _default;
@@ -7,6 +7,7 @@ exports.default = void 0;
7
7
  var _commons = require("@miso.ai/commons");
8
8
  var _classes = _interopRequireDefault(require("../classes"));
9
9
  var _anonymous = _interopRequireDefault(require("./anonymous"));
10
+ var _urls = require("./urls");
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12
  class PluginRoot extends _commons.Registry {
12
13
  constructor(root) {
@@ -100,6 +101,7 @@ class PluginRoot extends _commons.Registry {
100
101
  }
101
102
  if (typeof instance.config === 'function') {
102
103
  instance.config(options);
104
+ this._events.emit('config', [instance, options]);
103
105
  } else {
104
106
  this._warn(`Attempt to pass options to plugin "${instance.id}", which offers no config() method.`);
105
107
  }
@@ -176,19 +178,25 @@ class PluginRoot extends _commons.Registry {
176
178
  throw new Error(`Cannot register plugin remotely: ${id}`);
177
179
  }
178
180
  async _registerStdRemotely(id) {
179
- // TODO: look up by manifest
180
- const pkgName = id.slice(4);
181
- const src = this._currentScript.src;
182
- const searchIndex = src.indexOf('?');
183
- const k = searchIndex < 0 ? src.length : searchIndex;
184
- const i = src.lastIndexOf('/', k) + 1;
185
- const j = src.indexOf('.', i);
186
- const ext = j < 0 ? '' : src.slice(j, k);
187
- const script = document.createElement('script');
188
- script.async = true;
189
- script.src = `${src.slice(0, i)}plugins/${pkgName}${ext}`;
190
- document.head.appendChild(script);
191
- await this.whenRegistered(id);
181
+ const {
182
+ version
183
+ } = this._root;
184
+ const request = version === 'dev' ? `plugin:${id}@dev:${MisoClient.uuid}` : `plugin:${id}@${version}`;
185
+
186
+ // check if such script already exists
187
+ if (!document.querySelector(`script[data-request="${request}"]`)) {
188
+ // skip if already exists
189
+ const script = document.createElement('script');
190
+ script.async = true;
191
+ script.src = (0, _urls.getPluginScriptUrl)(id, version, this._currentScript);
192
+ script.setAttribute('data-request', request);
193
+ document.head.appendChild(script);
194
+ // TODO: hook up error event
195
+ }
196
+
197
+ // TODO: fine tune
198
+ const Plugin = await new _commons.Resources().get(request);
199
+ !this.isRegistered(id) && this.register(Plugin);
192
200
  }
193
201
  }
194
202
 
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getPluginScriptUrl = getPluginScriptUrl;
7
+ function getPluginScriptUrl(id, version, currentScript) {
8
+ // TODO: look up by manifest
9
+ const pkgName = id.slice(4);
10
+ if (version === 'dev') {
11
+ const src = currentScript.src;
12
+ const searchIndex = src.indexOf('?');
13
+ const k = searchIndex < 0 ? src.length : searchIndex;
14
+ const i = src.lastIndexOf('/', k) + 1;
15
+ const j = src.indexOf('.', i);
16
+ const ext = j < 0 ? '' : src.slice(j, k); // .min.js or .js
17
+ return `${src.slice(0, i)}plugins/${pkgName}${ext}`;
18
+ } else {
19
+ return `https://cdn.jsdelivr.net/npm/@miso.ai/client-sdk@${version}/dist/umd/plugins/${pkgName}.min.js`;
20
+ }
21
+ }
@@ -4,5 +4,5 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _default = '1.7.6';
7
+ var _default = '1.8.0-beta.1';
8
8
  exports.default = _default;
package/dist/es/client.js CHANGED
@@ -1,9 +1,20 @@
1
- import { trimObj, Component } from '@miso.ai/commons';
2
- import { root, register } from './root';
1
+ import { trimObj, Component, uuidv4, defineValues } from '@miso.ai/commons';
2
+ import { root, register, init } from './root';
3
3
  import Api from './api';
4
4
  import Context from './context';
5
5
  import * as helpers from './utils';
6
6
  class MisoClient extends Component {
7
+ static attach() {
8
+ (window.MisoClients || (window.MisoClients = [])).push(MisoClient);
9
+ if (window.MisoClient) {
10
+ if (window.MisoClient !== MisoClient) {
11
+ // TODO: check version as well
12
+ console.warn(`Use already defined window.MisoClient (${window.MisoClient.version}).`);
13
+ }
14
+ return;
15
+ }
16
+ window.MisoClient = MisoClient;
17
+ }
7
18
  constructor(options) {
8
19
  super('client', root);
9
20
  this._config(options);
@@ -45,4 +56,7 @@ class MisoClient extends Component {
45
56
  }
46
57
  }
47
58
  MisoClient.helpers = helpers;
48
- export default MisoClient;
59
+ defineValues(MisoClient, {
60
+ uuid: uuidv4()
61
+ });
62
+ export default init(MisoClient);
package/dist/es/index.js CHANGED
@@ -1,17 +1,2 @@
1
1
  import MisoClient from './client';
2
- import { init } from './root';
3
- import cmd from './cmd';
4
- if (!window.MisoClient) {
5
- // gaurantee to execute init() only once globally (across different script sources)
6
- window.MisoClient = init(MisoClient);
7
-
8
- // kick off misodev execution
9
- cmd('misodev');
10
-
11
- // do misocmd with setTimeout, so they will be executed after plugins are installed.
12
- setTimeout(() => cmd('misocmd'));
13
- } else {
14
- // TODO: check version as well
15
- console.warn(`Use already defined window.MisoClient (${window.MisoClient.version}).`);
16
- }
17
- export default window.MisoClient;
2
+ export default MisoClient;
@@ -1,6 +1,7 @@
1
- import { delegateGetters, defineValues, Registry, Resolution } from '@miso.ai/commons';
1
+ import { delegateGetters, defineValues, Registry, Resolution, Resources, uuidv4 } from '@miso.ai/commons';
2
2
  import classes from '../classes';
3
3
  import AnonymousPlugin from './anonymous';
4
+ import { getPluginScriptUrl } from './urls';
4
5
  export default class PluginRoot extends Registry {
5
6
  constructor(root) {
6
7
  super('plugins', root, {
@@ -93,6 +94,7 @@ export default class PluginRoot extends Registry {
93
94
  }
94
95
  if (typeof instance.config === 'function') {
95
96
  instance.config(options);
97
+ this._events.emit('config', [instance, options]);
96
98
  } else {
97
99
  this._warn(`Attempt to pass options to plugin "${instance.id}", which offers no config() method.`);
98
100
  }
@@ -169,19 +171,25 @@ export default class PluginRoot extends Registry {
169
171
  throw new Error(`Cannot register plugin remotely: ${id}`);
170
172
  }
171
173
  async _registerStdRemotely(id) {
172
- // TODO: look up by manifest
173
- const pkgName = id.slice(4);
174
- const src = this._currentScript.src;
175
- const searchIndex = src.indexOf('?');
176
- const k = searchIndex < 0 ? src.length : searchIndex;
177
- const i = src.lastIndexOf('/', k) + 1;
178
- const j = src.indexOf('.', i);
179
- const ext = j < 0 ? '' : src.slice(j, k);
180
- const script = document.createElement('script');
181
- script.async = true;
182
- script.src = `${src.slice(0, i)}plugins/${pkgName}${ext}`;
183
- document.head.appendChild(script);
184
- await this.whenRegistered(id);
174
+ const {
175
+ version
176
+ } = this._root;
177
+ const request = version === 'dev' ? `plugin:${id}@dev:${MisoClient.uuid}` : `plugin:${id}@${version}`;
178
+
179
+ // check if such script already exists
180
+ if (!document.querySelector(`script[data-request="${request}"]`)) {
181
+ // skip if already exists
182
+ const script = document.createElement('script');
183
+ script.async = true;
184
+ script.src = getPluginScriptUrl(id, version, this._currentScript);
185
+ script.setAttribute('data-request', request);
186
+ document.head.appendChild(script);
187
+ // TODO: hook up error event
188
+ }
189
+
190
+ // TODO: fine tune
191
+ const Plugin = await new Resources().get(request);
192
+ !this.isRegistered(id) && this.register(Plugin);
185
193
  }
186
194
  }
187
195
 
@@ -0,0 +1,15 @@
1
+ export function getPluginScriptUrl(id, version, currentScript) {
2
+ // TODO: look up by manifest
3
+ const pkgName = id.slice(4);
4
+ if (version === 'dev') {
5
+ const src = currentScript.src;
6
+ const searchIndex = src.indexOf('?');
7
+ const k = searchIndex < 0 ? src.length : searchIndex;
8
+ const i = src.lastIndexOf('/', k) + 1;
9
+ const j = src.indexOf('.', i);
10
+ const ext = j < 0 ? '' : src.slice(j, k); // .min.js or .js
11
+ return `${src.slice(0, i)}plugins/${pkgName}${ext}`;
12
+ } else {
13
+ return `https://cdn.jsdelivr.net/npm/@miso.ai/client-sdk@${version}/dist/umd/plugins/${pkgName}.min.js`;
14
+ }
15
+ }
@@ -1 +1 @@
1
- export default '1.7.6';
1
+ export default '1.8.0-beta.1';
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "url": "https://github.com/MisoAI/miso-client-js-sdk/issues"
30
30
  },
31
31
  "dependencies": {
32
- "@miso.ai/commons": "1.7.6"
32
+ "@miso.ai/commons": "1.8.0-beta.1"
33
33
  },
34
- "version": "1.7.6"
34
+ "version": "1.8.0-beta.1"
35
35
  }