@miso.ai/client-sdk-core 1.7.6-beta.0 → 1.8.0-beta.0

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) {
@@ -176,19 +177,25 @@ class PluginRoot extends _commons.Registry {
176
177
  throw new Error(`Cannot register plugin remotely: ${id}`);
177
178
  }
178
179
  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);
180
+ const {
181
+ version
182
+ } = this._root;
183
+ const request = version === 'dev' ? `plugin:${id}@dev:${MisoClient.uuid}` : `plugin:${id}@${version}`;
184
+
185
+ // check if such script already exists
186
+ if (!document.querySelector(`script[data-request="${request}"]`)) {
187
+ // skip if already exists
188
+ const script = document.createElement('script');
189
+ script.async = true;
190
+ script.src = (0, _urls.getPluginScriptUrl)(id, version, this._currentScript);
191
+ script.setAttribute('data-request', request);
192
+ document.head.appendChild(script);
193
+ // TODO: hook up error event
194
+ }
195
+
196
+ // TODO: fine tune
197
+ const Plugin = await new _commons.Resources().get(request);
198
+ !this.isRegistered(id) && this.register(Plugin);
192
199
  }
193
200
  }
194
201
 
@@ -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-beta.0';
7
+ var _default = '1.8.0-beta.0';
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, {
@@ -169,19 +170,25 @@ export default class PluginRoot extends Registry {
169
170
  throw new Error(`Cannot register plugin remotely: ${id}`);
170
171
  }
171
172
  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);
173
+ const {
174
+ version
175
+ } = this._root;
176
+ const request = version === 'dev' ? `plugin:${id}@dev:${MisoClient.uuid}` : `plugin:${id}@${version}`;
177
+
178
+ // check if such script already exists
179
+ if (!document.querySelector(`script[data-request="${request}"]`)) {
180
+ // skip if already exists
181
+ const script = document.createElement('script');
182
+ script.async = true;
183
+ script.src = getPluginScriptUrl(id, version, this._currentScript);
184
+ script.setAttribute('data-request', request);
185
+ document.head.appendChild(script);
186
+ // TODO: hook up error event
187
+ }
188
+
189
+ // TODO: fine tune
190
+ const Plugin = await new Resources().get(request);
191
+ !this.isRegistered(id) && this.register(Plugin);
185
192
  }
186
193
  }
187
194
 
@@ -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-beta.0';
1
+ export default '1.8.0-beta.0';
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-beta.0"
32
+ "@miso.ai/commons": "1.8.0-beta.0"
33
33
  },
34
- "version": "1.7.6-beta.0"
34
+ "version": "1.8.0-beta.0"
35
35
  }